diff options
Diffstat (limited to 'do/ggrent')
-rw-r--r-- | do/ggrent | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/do/ggrent b/do/ggrent new file mode 100644 index 0000000000..bf4a918e47 --- /dev/null +++ b/do/ggrent @@ -0,0 +1,61 @@ +int +do_ggrent(which,gimme,arglast) +int which; +int gimme; +int *arglast; +{ +#ifdef I_GRP + register ARRAY *ary = stack; + register int sp = arglast[0]; + register char **elem; + register STR *TARG; + struct group *getgrnam(); + struct group *getgrgid(); + struct group *getgrent(); + struct group *grent; + + if (which == O_GGRNAM) { + char *name = str_get(ary->ary_array[sp+1]); + + grent = getgrnam(name); + } + else if (which == O_GGRGID) { + int gid = (int)str_gnum(ary->ary_array[sp+1]); + + grent = getgrgid(gid); + } + else + grent = getgrent(); + + if (gimme != G_ARRAY) { + astore(ary, ++sp, TARG = str_mortal(&str_undef)); + if (grent) { + if (which == O_GGRNAM) + str_numset(TARG, (double)grent->gr_gid); + else + str_set(TARG, grent->gr_name); + } + return sp; + } + + if (grent) { + (void)astore(ary, ++sp, TARG = str_mortal(&str_no)); + str_set(TARG, grent->gr_name); + (void)astore(ary, ++sp, TARG = str_mortal(&str_no)); + str_set(TARG, grent->gr_passwd); + (void)astore(ary, ++sp, TARG = str_mortal(&str_no)); + str_numset(TARG, (double)grent->gr_gid); + (void)astore(ary, ++sp, TARG = str_mortal(&str_no)); + for (elem = grent->gr_mem; *elem; elem++) { + str_cat(TARG, *elem); + if (elem[1]) + str_ncat(TARG," ",1); + } + } + + return sp; +#else + fatal("group routines not implemented"); +#endif +} + |