da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin/***********************************************************************
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* This software is part of the ast package *
3e14f97f673e8a630f076077de35afdd43dc1587Roger A. Faulkner* Copyright (c) 1992-2010 AT&T Intellectual Property *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* and is licensed under the *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* Common Public License, Version 1.0 *
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin* by AT&T Intellectual Property *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* A copy of the License is available at *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* Information and Software Systems Research *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* AT&T Research *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* Florham Park NJ *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* Glenn Fowler <gsf@research.att.com> *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin* David Korn <dgk@research.att.com> *
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin***********************************************************************/
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * David Korn
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * Glenn Fowler
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * AT&T Research
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin"[-?\n@(#)$Id: id (AT&T Research) 2004-06-11 $\n]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin"[+NAME?id - return user identity]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin"[+DESCRIPTION?If no \auser\a operand is specified \bid\b writes user and "
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "group IDs and the corresponding user and group names of the "
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "invoking process to standard output. If the effective and "
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "real IDs do not match, both are written. Any supplementary "
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "groups the current process belongs to will also be written.]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin"[+?If a \auser\a operand is specified and the process has permission, "
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "the user and group IDs and any supplementary group IDs of the "
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "selected user will be written to standard output.]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin"[+?If any options are specified, then only a portion of the information "
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "is written.]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin"[n:name?Write the name instead of the numeric ID.]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin"[r:real?Writes real ID instead of the effective ID.]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin"[[a?This option is ignored.]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin"[g:group?Writes only the group ID.]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin"[u:user?Writes only the user ID.]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin"[G:groups?Writes only the supplementary group IDs.]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin"[s:fair-share?Writes fair share scheduler IDs and groups on systems that "
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "support fair share scheduling.]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin"\n[user]\n"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin"[+EXIT STATUS?]{"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "[+0?Successful completion.]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin "[+>0?An error occurred.]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin"[+SEE ALSO?\blogname\b(1), \bwho\b(1), \bgetgroups\b(2)]"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin#define isfsg(p) (!(p)->fs_id&&!(p)->fs_shares&&(!(p)->fs_passwd||!*(p)->fs_passwd))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinstatic void
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chingetfsids(Sfio_t* sp, const char* name, int flags, register int lastchar)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin register char* s;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin register char** p;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (flags > 0) x = 0;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin register char** q;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin register char* t;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin register int n;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin while (s = *q++)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (!(x = newof(0, char*, q - p, n)))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin s = (char*)(x + (q - p));
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin while (t = *p++)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin while (*s++ = *t++);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin while (s = *p++)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (x) free(x);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinstatic void
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinputid(Sfio_t* sp, int flags, const char* label, const char* name, long number)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chingetids(Sfio_t* sp, const char* name, register int flags)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin register int i;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin register int j;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin register int k;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * get supplemental groups if required
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin * first time
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin for (i = j = 0; i < ngroups; i++)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin gname = (grp = getgrgid(group)) ? grp->gr_name : (char*)0;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin fs_name = (fs = getfsgid(fs_id)) ? fs->fs_grp : (char*)0;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if ((flags & (U_FLAG|G_FLAG|S_FLAG)) == (U_FLAG|G_FLAG|S_FLAG))
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin while (s = *p++)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin else sfprintf(sp, "%u(%s)", grp->gr_gid, grp->gr_name);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin putid(sp, flags, " euid", (pw = getpwuid(euid)) ? pw->pw_name : (char*)0, euid);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin putid(sp, flags, " egid", (grp = getgrgid(egid)) ? grp->gr_name : (char*)0, egid);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin for (i = 0; i < ngroups; i++)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return(0);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if ((flags & N_FLAG) && gname) sfputr(sp, gname, '\n');
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin while (s = *p++)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin else if (ngroups > 0)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin for (i = 0;;)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if (++i >= ngroups) break;
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if ((flags & X_FLAG) && name) getfsids(sp, name, flags, 0);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin else if ((flags & N_FLAG) && fs_name) sfputr(sp, fs_name, '\n');
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin return(0);
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin register int n;