home *** CD-ROM | disk | FTP | other *** search
- /*
- * Last Edited: Tue Jul 10 18:21:59 1990 by bjs (Brian J. Smith) on lightning
- * Copyright (C) 1990 Brian J. Smith, This code may be modified without
- * any restrictions, all I request is that you send me updated copies.
- *
- * Please send updates to bjs@cis.ufl.edu
- *
- */
- /* Jun 12, Version 0.9: Completed getting uid and all gid's */
- /*
- * Jun 13, Version 1.0: Completed getting all gid's true names as listed in
- * the /etc/groups file or ypdatabase
- */
- /*
- * Jun 13, Version 1.01: Added tests for egid and euid and included SYSV
- * compiler directive so it won't bomb on SYSV machines (I hope)
- */
-
- #include <grp.h>
- #include <stdio.h>
- #include <pwd.h>
-
- extern int getuid();
- extern int getgid();
- extern int geteuid();
- extern int getegid();
- extern struct group *getgrent();
- extern struct group *getgrgid();
- extern struct passwd *getpwent();
-
- #ifndef SYSV
- #include <sys/param.h>
- extern int getgroups();
- #endif /* not SYSV */
-
- #ifdef SYSV
- #define NGROUPS 2 /* Max 2 gid and egid */
-
- int getgroups(ngr, gr)
- int ngr;
- int gr[];
- {
- if (ngr < 1) /* shouldn't happen */
- return (0);
- gr[0] = getgid();
- gr[1] = getegid();
- if (gr[1] != gr[0])
- return (2);
- else
- return(1);
- }
- #endif /* SYSV */
-
-
-
- main()
- {
- int id = 0;
- int uid = getuid();
- int gid = getgid();
- int euid = geteuid();
- int egid = getegid();
- int numgroups;
- int grouplist[NGROUPS];
- struct group *groupinfo;
- struct passwd *passinfo;
-
- passinfo = getpwuid(uid);
- groupinfo = getgrgid(gid);
- numgroups = getgroups(NGROUPS, grouplist);
- (void) fprintf(stdout, "uid=%d(%s) gid=%d(%s)", uid, passinfo->pw_name, gid, groupinfo->gr_name);
- if (uid != euid) {
- passinfo = getpwuid(euid);
- (void) fprintf(stdout, " euid=%d(%s)", euid, passinfo->pw_name);
- }
- if (gid != egid) {
- groupinfo = getgrgid(egid);
- (void) fprintf(stdout, " egid=%d(%s)", egid, groupinfo->gr_name);
- }
- if (numgroups != 0) {
- (void) fprintf(stdout, " groups=");
- for (id = 0; id != numgroups; id++) {
- groupinfo = getgrgid(grouplist[id]);
- (void) fprintf(stdout, "%d(%s) ", grouplist[id], groupinfo->gr_name);
- }
- }
- (void) fprintf(stdout, "\n");
- exit(0);
- }
-