diff options
Diffstat (limited to 'src/uidgid.c')
-rw-r--r-- | src/uidgid.c | 45 |
1 files changed, 39 insertions, 6 deletions
diff --git a/src/uidgid.c b/src/uidgid.c index 720d2ff..718d7a9 100644 --- a/src/uidgid.c +++ b/src/uidgid.c @@ -3,20 +3,56 @@ #include <grp.h> #include "uidgid.h" #include "str.h" +#include "scan.h" -unsigned int uidgid_get(struct uidgid *u, char *ug, unsigned int dogrp) { +/* user */ +unsigned int uidgid_get(struct uidgid *u, char *ug) { + struct passwd *pwd =0; + + if (! (pwd =getpwnam(ug))) return(0); + u->gid[0] =pwd->pw_gid; u->gids =1; + u->uid =pwd->pw_uid; + return(1); +} + +/* uid:gid[:gid[:gid]...] */ +unsigned int uidgids_set(struct uidgid *u, char *ug) { + unsigned long id; + int i; + + if (*(ug +=scan_ulong(ug, &id)) != ':') return(0); + u->uid =(uid_t)id; + ++ug; + for (i =0; i < 60; ++i, ++ug) { + ug +=scan_ulong(ug, &id); + u->gid[i] =(gid_t)id; + if (*ug != ':') { ++i; break; } + } + u->gid[i] =0; + u->gids =i; + if (*ug) return(0); + return(1); +} + +/* [:]user[:group[:group]...] */ +unsigned int uidgids_get(struct uidgid *u, char *ug) { char *g =0; struct passwd *pwd =0; struct group *gr =0; int i, d =0; - if (dogrp) + if (*ug == ':') return(uidgids_set(u, ug +1)); if (ug[(d =str_chr(ug, ':'))] == ':') { ug[d] =0; g =ug +d +1; } if (! (pwd =getpwnam(ug))) { if (g) ug[d] =':'; return(0); } - if (g) { + u->uid =pwd->pw_uid; + if (! g) { + u->gid[0] =pwd->pw_gid; + u->gids =1; + return(1); + } ug[d] =':'; for (i =0; i < 60; ++i) { if (g[(d =str_chr(g, ':'))] == ':') { @@ -34,8 +70,5 @@ unsigned int uidgid_get(struct uidgid *u, char *ug, unsigned int dogrp) { } u->gid[i] =0; u->gids =i; - } - if (! g) { u->gid[0] =pwd->pw_gid; u->gids =1; } - u->uid =pwd->pw_uid; return(1); } |