home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
rtsi.com
/
2014.01.www.rtsi.com.tar
/
www.rtsi.com
/
OS9
/
OSK
/
TELECOM
/
stg_v4.lzh
/
users.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-11-11
|
3KB
|
172 lines
/*
* users (list users)
*
* StG-Net (c) 1989 StG Computers Inc
* Unauthorized Reproduction Prohibited
*
* 89/08/29 DCG modified for new lib
*/
#include <stdio.h>
#include "stgnet.h"
#include "pwd.h"
struct passwd *pw;
char *VER="V4.0a";
char *help[]=
{
"users {-uihnapcmrvl} - selective list of users/machines",
" options can be specified in any combination",
" default options: -runc",
" -u - UserName",
" -i - Decimal Id #",
" -h - Hex Id #",
" -n - Real Name",
/* " -a - Address",
" -p - Phone",
" -c - Computer",
" -m - forces list to machines only",
" -r - forces list to real users only",
" -v - forces list to non-verified users",
*/
" -l - forces no labels",0
};
char *opts="uihnapcmrvl";
int optsw[11]={1,1,0,1,0,0,0,0,1,0,0};
char *lbl[]={"UserName","Usr #","Usr #","Real Name","Address","Phone #","Computer"};
int len[]={8,11,11,40,40,40,40};
char *bar="============================================================";
char spec[80];
int i,w,n,q;
char *p;
main(argc,argv)
char **argv;
{
openerr(*argv,0,LOG_STGNET);
if (*++argv && **argv=='-')
{
if (*(*argv+1)=='?')
{
argv=help;
while (*argv)
{
strcpy(b,*argv);
strcat(b,"\n");
writeln(2,b,80);
argv++;
}
STGVER;
exit(1);
}
for (i=0;i<10;i++) optsw[i]=0;
p=*argv;
while (*++p)
{
for (i=0;i<10 && *(opts+i)!=*p;i++);
if (i==10)
{
*(p+1)=0;
writeln(2,stringf(b,"Unknown option: %s\n",p),80);
}
optsw[i]++;
}
if (optsw[7]==0 && optsw[8]==0) optsw[7]=optsw[8]=1;
}
n=w=0;
for (i=0;i<7;i++)
{
if (!optsw[i]) continue;
if (i>2) n++;
w+=len[i]+1;
}
if (w>79)
{
w-=79;
q=w/n;
for (i=0;i<7;i++)
{
if (!optsw[i]) continue;
if (i<3) continue;
if (--n)
{
len[i]-=q;
w-=q;
}
else
len[i]-=w;
}
}
*b=0;
for (i=0;i<7;i++)
{
if (!optsw[i]) continue;
sprintf(spec,"%%-%d.%ds ",len[i],len[i]);
sprintf(b+strlen(b),spec,lbl[i]);
}
if (!optsw[10])
{
strcat(b,"\n");
writeln(1,b,BUFSIZ);
}
*b=0;
for (i=0;i<7;i++)
{
if (!optsw[i]) continue;
sprintf(spec,"%%-%d.%ds ",len[i],len[i]);
sprintf(b+strlen(b),spec,bar);
}
if (!optsw[10])
{
strcat(b,"\n");
writeln(1,b,BUFSIZ);
}
setpwent();
while (pw=getpwent())
{
/*
if (chrser(pwd.op,'N'))
{
if (!optsw[7]) continue;
}
else
{
if (!optsw[8]) continue;
}
if (optsw[9] && !chrser(pwd.op,'V')) continue;
*/
*b=0;
for (i=0;i<7;i++)
{
if (!optsw[i]) continue;
sprintf(spec,"%%-%d.%ds ",len[i],len[i]);
switch (i)
{
case 0: sprintf(b+strlen(b),spec,pw->pw_name); break;
case 1: sprintf(b+strlen(b),"%5d.%-5d ",(pw->pw_uid&0xFFFF0000)>>16,pw->pw_uid&0xFFFF); break;
case 2: sprintf(b+strlen(b),"$%04X.$%04X ",(pw->pw_uid&0xFFFF0000)>>16,pw->pw_uid&0xFFFF); break;
case 3: sprintf(b+strlen(b),spec,pw->pw_gecos); break;
case 4: sprintf(b+strlen(b),spec,""); break;
case 5: sprintf(b+strlen(b),spec,""); break;
case 6: sprintf(b+strlen(b),spec,""); break;
default: exit(190);
}
}
strcat(b,"\n");
writeln(1,b,BUFSIZ);
}
endpwent();
}