home *** CD-ROM | disk | FTP | other *** search
- /* History:
- 5/3/91 DJB modified to print something sensible under !HAVE_UCRED
- 5/1/91 DJB baseline public domain
- */
-
- /*
-
- char *printucred(uc,style,ruids,tags,uns) struct ucred *uc; int style;
- int ruids; int tags; int uns; prints uc in a variety of styles.
-
- style is not yet officially defined. XXX this whole interface
-
- If ruids is 0, the effective uid is printed, and the real uid is printed
- if different. If ruids is 1, only the effective uid is printed. If ruids
- is 2, only the real uid is printed.
-
- If tags is 1, information is tagged with inline labels. If tags is 0, it
- is assumed that labels are placed at the top of columns.
-
- If uns is 1, uids are printed as usernames if possible. If uns is 0,
- uids are always printed as uids.
-
- */
-
- #include <stdio.h>
- #include <strings.h>
- #include "structucred.h"
- #include "printucred.h"
- #include "username.h"
- #include "groupname.h"
- #include "confhaveucred.h"
- /* XXX: should provide for string group names! */
-
- static char result[50 + NGROUPS * 8];
- /* XXX: assumes uids and gids are at most 8 (really 5) characters */
- /* XXX: assumes uids and gids are short */
- /* XXX: string representation? */
- /* XXX: under newer Suns, auid? audit? label? */
-
- char *printucred(uc,style,ruids,tags,uns)
- struct ucred *uc;
- int style;
- int ruids;
- int tags;
- int uns;
- {
- int i;
- char *t;
- unsigned gid;
- unsigned rgid;
- unsigned uid;
- unsigned ruid;
- unsigned puid;
-
- #ifdef HAVE_UCRED
- uid = uc->cr_uid;
- ruid = uc->cr_ruid;
- #else
- uid = uc->uid;
- ruid = uc->uid;
- #endif
- puid = (ruids == 2) ? ruid : uid;
- if (uns)
- {
- char *pun;
- uid2username(puid,&pun); /* XXX: care about return value? */
- if (style == 1)
- sprintf(result,"%s%8s",tags ? "uid " : "",pun);
- else
- sprintf(result,"%s%s",tags ? "uid " : "",pun);
- }
- else
- if (style == 1)
- sprintf(result,"%s%5u",tags ? "uid " : "",puid);
- else
- sprintf(result,"%s%u",tags ? "uid " : "",puid);
- t = result + strlen(result);
- if (!ruids && (uid != ruid))
- {
- if (uns)
- {
- char *pun;
- uid2username(ruid,&pun); /* XXX: care about return value? */
- if (style == 1)
- sprintf(t,"/%8u",ruid);
- else
- sprintf(t,"/%u",ruid);
- }
- else
- if (style == 1)
- sprintf(t,"/%5u",ruid);
- else
- sprintf(t,"/%u",ruid);
- t += strlen(t);
- }
- if (style == 1 && !ruids && (uid == ruid))
- {
- if (uns) { sprintf(t," "); t += 9; }
- else { sprintf(t," "); t += 6; }
- }
- if (style == 2)
- {
- sprintf(t," ");
- t = result + (tags ? 4 : 0) + (!ruids ? 6 : 0) + 5 + (uns ? 6 : 0);
- *t = 0;
- }
- #ifdef HAVE_UCRED /*XXX*/
- if (style == 3)
- {
- gid = (unsigned short) uc->cr_gid;
- rgid = (unsigned short) uc->cr_rgid;
- sprintf(t," %s%u",tags ? "gid " : "",gid); t += strlen(t);
- if (gid != rgid)
- {
- sprintf(t,"/%u",rgid); t += strlen(t);
- }
- for (i = 0;i < NGROUPS;++i)
- {
- register short g;
- g = uc->cr_groups[i];
- if (g == -1)
- break; /* XXX: is this right? */
- if (g != gid && g != rgid)
- sprintf(t," %u",(unsigned) (unsigned short) g);
- t += strlen(t);
- if (!g)
- break; /* XXX: is this right? */
- }
- }
- #endif
- return result;
- }
-