home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Beijing Paradise BBS Backup
/
PARADISE.ISO
/
software
/
BBSDOORW
/
NETCLB35.ZIP
/
NETCLB35.EXE
/
EXAMPLES
/
TLIST.C
< prev
next >
Wrap
C/C++ Source or Header
|
1996-01-03
|
7KB
|
213 lines
/***************************************************************************/
/* File: TLIST.C */
/* */
/* Function: Output all trustee paths of all currently logged in */
/* users, or of the specified user. */
/* */
/* Usage: tlist <user> */
/* */
/* Functions Called: GetConnectionInformation */
/* GetBinderyObjectID */
/* ReadPropertyValue */
/* GetBinderyObjectName */
/* ScanBinderyObjectTrusteePaths */
/* GetPreferredConnectionID */
/* GetDefaultConnectionID */
/* GetPrimaryConnectionID */
/* SetPreferredConnectionID */
/* ISShellLoaded */
/* */
/***************************************************************************/
#include <sys\types.h>
#include <sys\stat.h>
#include <io.h>
#include <errno.h>
#include <conio.h>
#include <dos.h>
#ifndef TURBOC
#include <search.h>
#endif
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <fcntl.h>
#include "netware.h"
void get_paths(long id);
void set_rights(char mask,char *rights);
void get_ident(int object_type,char *object_name,char *ident);
void main(int argc,char *argv[])
{
int r;
char uname[OBJECT_LENGTH];
long uid;
int segment;
nw_long *o_ptr;
int count;
long gid;
int ot;
char on[OBJECT_LENGTH];
byte ltime[7];
char ident[128];
char pvalue[128];
byte pmoresegments;
byte pflag;
int thisserver,prefserver;
if (argc>2)
{
printf("Too many parameters supplied\n");
exit(1);
}
else
if (IsShellLoaded() != SUCCESS)
{
printf("*** No netware shell loaded ***\n");
exit(255);
}
if ((prefserver = GetPreferredConnectionID()) == 0)
{
if ((thisserver = GetDefaultConnectionID()) == 0)
thisserver = GetPrimaryConnectionID();
SetPreferredConnectionID( thisserver );
}
else
thisserver = prefserver;
if (argc == 2)
strcpy(uname,argv[1]);
else
{
/* No user name supplied - so get current connection */
r=GetConnectionInformation((word)GetConnectionNumber(),
uname,&ot,&uid,ltime);
if (r != SUCCESS)
{
printf("Failed getting connection user: %d\n",r);
if (thisserver != prefserver) /* reset preferred server */
SetPreferredConnectionID( prefserver );
exit(4);
}
}
if((r=GetBinderyObjectID(USER,uname,&uid)) == SUCCESS)
{
get_ident(USER,uname,ident);
printf("User: %s %s\n",uname,ident);
get_paths(uid);
/* search out all groups */
pmoresegments=0xff;
for(segment=1;
((r==SUCCESS)&&(pmoresegments != 0));
segment++)
{
r=ReadPropertyValue(USER,uname,GROUPS_IN,segment,
pvalue,&pmoresegments,&pflag);
if (r==0xec)
{
r=SUCCESS;
pmoresegments = 0;
}
else
if (r != SUCCESS)
{
printf("ReadPropertyValue failed: %02.2x\n",r);
if (thisserver != prefserver) /* reset preferred server */
SetPreferredConnectionID( prefserver );
exit(2);
}
else
{
o_ptr=(nw_long *)&pvalue[0];
gid=-1L;
for(count=0;
((count<32) && (r==SUCCESS) && (gid != 0));count++)
if ((gid=ConvertNWLongToLong(o_ptr++)) != 0)
{
r=GetBinderyObjectName(gid,&ot,on);
if (r==SUCCESS)
{
get_ident(USER_GROUP,on,ident);
printf(" Group: %-32.32s %s\n",on,ident);
get_paths(gid);
}
}
}
}
}
if(r != SUCCESS)
{
printf("Failed res:%02.2x\n",r);
if (thisserver != prefserver) /* reset preferred server */
SetPreferredConnectionID( prefserver );
exit(3);
}
if (thisserver != prefserver) /* reset preferred server */
SetPreferredConnectionID( prefserver );
exit(0);
}
void get_paths(long id)
{
int volume,r=SUCCESS;
int sequence=0;
char mask;
char path[DIR_PATH_LENGTH];
char m[9];
for(volume=0;(volume<32)&&(r==SUCCESS);volume++)
{
while (r==SUCCESS)
{
r=ScanBinderyObjectTrusteePaths(id,(byte)volume,
&sequence,&mask,path);
if (r==SUCCESS)
{
set_rights(mask,m);
printf(" [%s] %s\n",m,path);
}
}
if (r==NO_MORE_PATHS)
r=SUCCESS;
}
}
static char all_masks[]={RT_READ,RT_WRITE,RT_OPEN,RT_CREATE,
RT_DELETE,RT_OWNERSHIP,RT_SEARCH,RT_MODIFY};
static char all_rights[]="rwocdpsm";
void set_rights(char mask,char *rights)
{
int i;
for(i=0;i<8;i++)
if((mask & all_masks[i]) == 0)
*rights++=' ';
else
*rights++=all_rights[i];
*rights=0x00;
}
void get_ident(int object_type,char *object_name,char *ident)
{
char pvalue[128];
byte pmoresegments;
byte pflag;
if(ReadPropertyValue(object_type,object_name,
IDENT,1,pvalue,&pmoresegments,&pflag) != SUCCESS)
*ident='\0';
else
strcpy(ident,pvalue);
}