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' | al...@cs.warwick.ac.uk, al...@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 <al...@cs.warwick.ac.uk>
* Date: August 17th 1989
* Place: University of Warwick, Coventry, UK
*/
# include <stdio.h>
# include <sys/param.h>
# include <pwd.h>
# include <grp.h>
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
For those of you who can't remember where you keep .c files, here's the
one I use. It differs slightly in that it sorts the groups.
#!/usr/bin/perl
print "uid=$<";
print "($name)" if ($name) = getpwuid($<);
print " gid=", $( + 0;
print "($name)" if ($name) = getgrgid($();
if ($> != $<) {
print " euid=$>";
print "($name)" if ($name) = getpwuid($>);
}
if ($) != $() {
print " egid=", $) + 0;
print "($name)" if ($name) = getgrgid($));
}
@groups = split(' ',$();
shift(@groups);
for (@groups) {
$_ .= "($name)" if ($name) = getgrgid($_);
}
print " groups=", join(',',sort bynum @groups) if @groups;
print "\n";
sub bynum { $a - $b; }
No doubt Randal could write it shorter...
Larry
Well, OK, taking on the challenge, how about:
#!/usr/bin/perl
sub u { local($name)=getpwuid($_[0]); $name && "($name)";}
sub g { local($name)=getgrgid($_[0]); $name && "($name)";}
sub bynum { $a - $b; }
print "uid=$<",&u($<);
print " gid=", $(+0,&g($();
print " euid=$>",&u($>) if $> != $<;
print " egid=", $)+0,&g($)) if $) != $(;
@groups=split(' ',$(); shift(@groups);
print " groups=", join(',',sort bynum grep(($_ .= &g($_)) || 1, @groups))
unless $#groups < $[;
print "\n";
Something like that, Larry?
print pack('C25',grep($_ = 32 + y/ / /, split(/\n/, <<END)));
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
X
END
--
/=Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ==========\
| on contract to Intel's iWarp project, Beaverton, Oregon, USA, Sol III |
| mer...@iwarp.intel.com ...!any-MX-mailer-like-uunet!iwarp.intel.com!merlyn |
\=Cute Quote: "Welcome to Portland, Oregon, home of the California Raisins!"=/
That's not short. This is short: :-)
#!/usr/bin/perl
@n=('pwu','grg');sub n{local($n)=eval"get$n[$_[1]]id(\$_[0])";$n&&"($n)";}sub nm
{$a-$b;}@gr=split(' ',$();$g=shift(@gr);$\="\n";print"uid=$<",&n($<)," gid=",$g,
&n($(,1),(" euid=$>".&n($>))x($<!=$>),(" egid=".$)+0 .&n($),1))x($(!=$)),
(" groups=".join(',',sort nm grep(($_.=&n($_,1))||1,@gr)))x($#gr>=0);
Though I'll admit readability suffers slightly...
Larry
main() {
puts("Good God. What next - an Obfuscated Perl Contest??");
}
--
Jay Maynard, EMT-P, K5ZC, PP-ASEL | Never ascribe to malice that which can
j...@splut.conmicro.com (eieio)| adequately be explained by stupidity.
{attctc,bellcore}!texbell!splut!jay +----------------------------------------
"Klein bottle for sale. Inquire within." - Charles Hannum
main() {
cout << "That's what the signature scripts are, silly! ;-)\n";
}
--
Brandon S. Allbery (human), all...@NCoast.ORG (Inet), BALLBERY (MCI Mail)
ALLBERY (Delphi), uunet!cwjcc.cwru.edu!ncoast!allbery (UUCP), B.ALLBERY (GEnie)
BrandonA (A-Online) ("...and a partridge in a pear tree!" ;-)