diff options
author | Laurent Bercot <ska-skaware@skarnet.org> | 2018-06-26 00:25:28 +0000 |
---|---|---|
committer | Laurent Bercot <ska-skaware@skarnet.org> | 2018-06-26 00:25:28 +0000 |
commit | 633445be1a9be37ae727c044417f5607706cf4ae (patch) | |
tree | 3c037459f5249e5c18ee5b9e41802c5964364f95 /src/libnsss/nsss_unix_pwd_get.c | |
download | nsss-633445be1a9be37ae727c044417f5607706cf4ae.tar.gz nsss-633445be1a9be37ae727c044417f5607706cf4ae.tar.xz nsss-633445be1a9be37ae727c044417f5607706cf4ae.zip |
Initial commit
Diffstat (limited to 'src/libnsss/nsss_unix_pwd_get.c')
-rw-r--r-- | src/libnsss/nsss_unix_pwd_get.c | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/src/libnsss/nsss_unix_pwd_get.c b/src/libnsss/nsss_unix_pwd_get.c new file mode 100644 index 0000000..b0c1200 --- /dev/null +++ b/src/libnsss/nsss_unix_pwd_get.c @@ -0,0 +1,45 @@ +/* ISC license. */ + +#include <pthread.h> +#include <skalibs/types.h> +#include <skalibs/skamisc.h> +#include <nsss/pwd-def.h> +#include <nsss/nsss-unix.h> +#include "nsss-unix-internal.h" + +static inline int pwd_parseline (struct passwd *pw, char *s, size_t max) +{ + struct passwd pw2 ; + char *p ; + s[max-1] = 0 ; + if (!nsss_unix_field(&pw2.pw_name, &s)) return 0 ; + if (!nsss_unix_field(&pw2.pw_passwd, &s)) return 0 ; + if (!nsss_unix_field(&p, &s)) return 0 ; + if (!uid0_scan(p, &pw2.pw_uid)) return 0 ; + if (!nsss_unix_field(&p, &s)) return 0 ; + if (!gid0_scan(p, &pw2.pw_gid)) return 0 ; + if (!nsss_unix_field(&pw2.pw_gecos, &s)) return 0 ; + if (!nsss_unix_field(&pw2.pw_dir, &s)) return 0 ; + pw2.pw_shell = s ; + *pw = pw2 ; + return 1 ; +} + +int nsss_unix_pwd_get (nsss_unix_t *a, struct passwd *pw, stralloc *sa) +{ + int cs ; + pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &cs) ; + for (;;) + { + size_t base = sa->len ; + if (skagetln_loose(&a->b, sa, '\n') <= 0) goto err ; + if (pwd_parseline(pw, sa->s + base, sa->len - base)) break ; + sa->len = base ; + } + pthread_setcancelstate(cs, 0) ; + return 1 ; + + err: + pthread_setcancelstate(cs, 0) ; + return 0 ; +} |