Category : Network Files
Archive   : USERS.ZIP
Filename : USER.C

 
Output of file : USER.C contained in archive : USERS.ZIP

#define MSC 400
#include
#include
#include

#define LINElength 80

typedef struct userLIST
{
char *line;
char *nextline;
}userLIST;

WORD connectionID;
int loggedfg,allfg,usagefg;

main(argc,argv)
int argc;
char *argv[];
{
char objectName[48];
long objectID=-1;
int objectType;
int connectionNumber;
BYTE loginTime[7];
userLIST array,*arrayptr;

loggedfg=ParseCommand("/L",argc,argv);
allfg=ParseCommand("/A",argc,argv);
usagefg=ParseCommand("/U",argc,argv);
if(argc>1)
{
printf("\nUSER ID FULL NAME");
if(usagefg)
printf("%51s","Used Free");
printf("\n------- ---------");
if(usagefg)
printf("%51s","---- ----");
printf("\nWorking..........\r");
}
arrayptr=&array;
connectionID=GetPreferredConnectionID();
if(allfg)
{ /* list all users in user bindery */
strcpy(objectName,"****************************************");
while(name(arrayptr,objectName,&objectID)==SUCCESSFUL)
{
arrayptr->nextline=malloc(sizeof(userLIST));
arrayptr=(userLIST *) arrayptr->nextline;
}
}
else if(loggedfg) /* list logged-in users only */
{
for(connectionNumber=1;connectionNumber<=100;connectionNumber++)
if(GetConnectionInformation(connectionNumber,
objectName,
&objectType,
&objectID,
loginTime)==SUCCESSFUL)
if(objectType==0x0001)
{
objectID=-1;
if(name(arrayptr,objectName,&objectID)==SUCCESSFUL)
{
arrayptr->nextline=malloc(sizeof(userLIST));
arrayptr=(userLIST *) arrayptr->nextline;
}
}
}
else if(argc>1) /* list a specific user only */
{
strcpy(objectName,argv[1]);
if(name(arrayptr,argv[1],&objectID)==SUCCESSFUL)
{
arrayptr->nextline=malloc(sizeof(userLIST));
arrayptr=(userLIST *) arrayptr->nextline;
}
}
else
{
printf("\n\nÕÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ͸\n");
printf("³User Information Utility³\n");
printf("³By A. White 89/08/03³\n");
printf("ÔÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ;\n\n");
printf("Usage: user [user name] [/A] [/L] [/U]\n\n");
printf("Where: /A -list all user accounts\n");
printf(" /L -list logged-in users\n");
printf(" /U -display disk usage for users (time consuming)\n\n");

exit(0);
}
arrayptr->nextline=(userLIST *) NULL;
print(&array);
}

ParseCommand(search,argc,argv)
char *search;
int argc;
char *argv[];
{
int count=1,retval=0;
while(count {
strupr(argv[count]);
if(strcmp(search,argv[count])==0)
{
retval=1;
break;
}
count++;
}
return(retval);
}

print(linearray)
userLIST *linearray;
{
int count=0;
if(linearray->nextline!=(userLIST *) NULL)
sort(linearray);
while(linearray->nextline!=(userLIST *) NULL)
{
count++;
printf("%s\n",linearray->line);
linearray=(userLIST *) linearray->nextline;
}
printf("\n%03d user name(s) printed\n",count);
}

sort(linearray)
userLIST *linearray;
{
char **ptr1,**ptr2,*ptr3;
userLIST *arrayptr;
int swapfg=1;
while(swapfg)
{
arrayptr=linearray;
swapfg=0;
while(((userLIST *) arrayptr->nextline)->nextline!=(userLIST *) NULL)
{
ptr1=&arrayptr->line;
ptr2=&((userLIST *) arrayptr->nextline)->line;
if(strncmp(*ptr1,*ptr2,10)>0)
{
ptr3=*ptr1; /* swap strings */
*ptr1=*ptr2;
*ptr2=ptr3;
swapfg=1;
}
arrayptr=(userLIST *) arrayptr->nextline;
}
}
}

name(linearray,objectName,objectID)
userLIST *linearray;
long *objectID;
char *objectName;
{
char temp[80];
int foundObjectType;
char foundObjectName[48];
char objectHasProperties;
char objectSecurity;
char objectFlag;
BYTE identificationValue[128];
BYTE moreSegments;
BYTE propertyFlags;
int retval;
long kBytesUsed,kBytesNotUsed;
int restricted;

retval=ScanBinderyObject(objectName,
OT_USER,
objectID,
foundObjectName,
&foundObjectType,
&objectHasProperties,
&objectFlag,
&objectSecurity);
if(retval==SUCCESSFUL)
{
if(ReadPropertyValue(foundObjectName,
OT_USER,
"IDENTIFICATION",
1,
identificationValue,
&moreSegments,
&propertyFlags)!=SUCCESSFUL)
identificationValue[0]='\0';
linearray->line=malloc(LINElength);
sprintf(linearray->line,"%-14.14s %-40.40s ",foundObjectName,identificationValue);
if(usagefg && GetSpaceUsage(foundObjectName,&kBytesUsed,&kBytesNotUsed,&restricted)==SUCCESSFUL)
{
sprintf(temp,"%7ld K ",kBytesUsed);
strcat(linearray->line,temp);
if(restricted)
sprintf(temp,"%7ld K",kBytesNotUsed);
else
strcpy(temp," all");
strcat(linearray->line,temp);
}
}
return(retval);
}

GetSpaceUsage(objectName,kBytesUsed,kBytesNotUsed,restricted)
char *objectName;
long *kBytesUsed;
long *kBytesNotUsed;
int *restricted;
{
int retval;
long objectID;
long systemElapsedTime;
long unusedDiskBlocks;
char volumeName[16];
int volumeNumber;
WORD usedDirectories;
WORD usedBlocks;
WORD usedFiles;

if((retval=GetBinderyObjectID(objectName,OT_USER,&objectID))==SUCCESSFUL)
{
if((retval=GetBinderyObjectDiskSpaceLeft(connectionID,
objectID,
&systemElapsedTime,
&unusedDiskBlocks,
restricted))==SUCCESSFUL)
{
if((unusedDiskBlocks&0x7fff0000)==0x7fff0000)
{
unusedDiskBlocks=0;
*restricted=0;
}
else
*restricted=1;
*kBytesNotUsed=(long) (((double) unusedDiskBlocks)*4096.0/1000.0);
*kBytesUsed=0L;
volumeNumber=0;
while(GetDiskUtilization(objectID,
volumeNumber++,
&usedDirectories,
&usedFiles,
&usedBlocks)==SUCCESSFUL)
*kBytesUsed+=usedBlocks;
*kBytesUsed=(long) (((double) *kBytesUsed)*4096.0/1000.0);
}
}
return(retval);
}

dump_segment(dump,bytes)
unsigned char *dump;
int bytes;
{
int count=0,x;
while(count {
for(x=0;x<16 && count {
printf("%02X ",*(dump+count));
count++;
}
printf("\n");
}
while(getch()!=' ');
}