Path: utzoo!attcan!uunet!mcsun!ukc!warwick!csrxj From: csrxj@warwick.ac.uk (Mr N W Holloway) Newsgroups: alt.sources Subject: Version of id(1). Message-ID: <426@clover.warwick.ac.uk> Date: 1 Mar 90 13:34:32 GMT Reply-To: alfie@cs.warwick.ac.uk (Nick Holloway) Organization: Computer Science, Warwick University, UK Lines: 102 I saw a request somewhere for a program like the SysV id(1). I got used to it under SunOS, and so I wrote this one to use on our BSD machines. As far as I can tell, they act identically - though I can't check this, since I do not have access to source. The only area they may differ is if the user or group name can not be determined. There is no man page - the program is very simple, it justs prints out info on your real & effective user & group id, and your current group access list. Example (mythical) outputs are: uid=0(root) gid=0(wheel) groups=0(wheel),1(daemon) uid=1074(alfie) gid=1(general) euid=1(daemon) groups=1(general) To compile, no magic flags needed, just "cc -o id id.c". -- Nick Holloway | `O O' | alfie@cs.warwick.ac.uk, alfie@warwick.UUCP, [aka `Alfie'] | // ^ \\ | ..!uunet!mcsun!ukc!warwick!alfie #! /bin/sh # This is a shell archive, meaning: # 1. Remove everything above the #! /bin/sh line. # 2. Save the resulting text in a file. # 3. Execute the file with /bin/sh (not csh) to create the files: # id.c # This archive created: Thu Mar 1 13:15:51 1990 export PATH; PATH=/bin:$PATH if test -f 'id.c' then echo shar: will not over-write existing file "'id.c'" else cat << \SHAR_EOF > 'id.c' /* My own version of `id' for those systems that do not support it * Displays uid, gid, euid, egid (if different to real), and groups * * Author: Nick Holloway * Date: August 17th 1989 * Place: University of Warwick, Coventry, UK */ # include # include # include # include main () { int uid, euid; /* real and effective user-id */ int gid, egid; /* real and effective group-id */ int gidset [ NGROUPS ]; /* current group access list */ int ng, i; /* number of groups, index var */ struct passwd *pwd; /* used to retrieve user name */ struct group *grp; /* used to retrieve group name */ /* --- collect information --- */ uid = getuid (); gid = getgid (); euid = geteuid (); egid = getegid (); ng = getgroups ( sizeof ( gidset ), gidset ); /* --- print real user-id --- */ (void) printf ( "uid=%d", uid ); if ( ( pwd = getpwuid ( uid ) ) != NULL ) (void) printf ( "(%s)", pwd->pw_name ); /* --- print real group-id --- */ (void) printf ( " gid=%d", gid ); if ( ( grp = getgrgid ( gid ) ) != NULL ) (void) printf ( "(%s)", grp->gr_name ); /* --- print effective user-id (if different to real) --- */ if ( euid != uid ) { (void) printf ( " euid=%d", euid ); if ( ( pwd = getpwuid ( euid ) ) != NULL ) (void) printf ( "(%s)", pwd->pw_name ); } /* --- print effective group-id (if different to real) --- */ if ( egid != gid ) { (void) printf ( " egid=%d", egid ); if ( ( grp = getgrgid ( egid ) ) != NULL ) (void) printf ( "(%s)", grp->gr_name ); } /* --- print current group access list --- */ if ( ng > 0 ) { (void) fputs ( " groups=", stdout ); for ( i = 0; i < ng; i++ ) { if ( i != 0 ) (void) putc ( ',', stdout ); (void) printf ( "%d", gidset [ i ] ); if ( ( grp = getgrgid ( gidset [ i ] ) ) != NULL ) (void) printf ( "(%s)", grp->gr_name ); } } (void) putc ( '\n', stdout ); } SHAR_EOF fi # end of overwriting check # End of shell archive exit 0