about summary refs log tree commit diff
path: root/src/libnsss/nsss_unix_shadow_get.c
diff options
context:
space:
mode:
authorLaurent Bercot <ska-skaware@skarnet.org>2018-06-26 00:25:28 +0000
committerLaurent Bercot <ska-skaware@skarnet.org>2018-06-26 00:25:28 +0000
commit633445be1a9be37ae727c044417f5607706cf4ae (patch)
tree3c037459f5249e5c18ee5b9e41802c5964364f95 /src/libnsss/nsss_unix_shadow_get.c
downloadnsss-633445be1a9be37ae727c044417f5607706cf4ae.tar.gz
nsss-633445be1a9be37ae727c044417f5607706cf4ae.tar.xz
nsss-633445be1a9be37ae727c044417f5607706cf4ae.zip
Initial commit
Diffstat (limited to 'src/libnsss/nsss_unix_shadow_get.c')
-rw-r--r--src/libnsss/nsss_unix_shadow_get.c52
1 files changed, 52 insertions, 0 deletions
diff --git a/src/libnsss/nsss_unix_shadow_get.c b/src/libnsss/nsss_unix_shadow_get.c
new file mode 100644
index 0000000..0d87088
--- /dev/null
+++ b/src/libnsss/nsss_unix_shadow_get.c
@@ -0,0 +1,52 @@
+/* ISC license. */
+
+#include <pthread.h>
+#include <skalibs/types.h>
+#include <skalibs/skamisc.h>
+#include <nsss/shadow-def.h>
+#include <nsss/nsss-unix.h>
+#include "nsss-unix-internal.h"
+
+static inline int shadow_parseline (struct spwd *sp, char *s, size_t max)
+{
+  struct spwd sp2 ;
+  char *p ;
+  s[max-1] = 0 ;
+  if (!nsss_unix_field(&sp2.sp_namp, &s)) return 0 ;
+  if (!nsss_unix_field(&sp2.sp_pwdp, &s)) return 0 ;
+  if (!nsss_unix_field(&p, &s)) return 0 ;
+  if (!ulong0_scan(p, (unsigned long *)&sp2.sp_lstchg)) return 0 ;
+  if (!nsss_unix_field(&p, &s)) return 0 ;
+  if (!ulong0_scan(p, (unsigned long *)&sp2.sp_min)) return 0 ;
+  if (!nsss_unix_field(&p, &s)) return 0 ;
+  if (!ulong0_scan(p, (unsigned long *)&sp2.sp_max)) return 0 ;
+  if (!nsss_unix_field(&p, &s)) return 0 ;
+  if (!ulong0_scan(p, (unsigned long *)&sp2.sp_warn)) return 0 ;
+  if (!nsss_unix_field(&p, &s)) return 0 ;
+  if (!ulong0_scan(p, (unsigned long *)&sp2.sp_inact)) return 0 ;
+  if (!nsss_unix_field(&p, &s)) return 0 ;
+  if (!ulong0_scan(p, (unsigned long *)&sp2.sp_expire)) return 0 ;
+  if (!nsss_unix_field(&p, &s)) return 0 ;
+  if (!ulong0_scan(p, &sp2.sp_flag)) return 0 ;
+  *sp = sp2 ;
+  return 1 ;
+}
+
+int nsss_unix_shadow_get (nsss_unix_t *a, struct spwd *sp, 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 (shadow_parseline(sp, sa->s + base, sa->len - base)) break ;
+    sa->len = base ;
+  }
+  pthread_setcancelstate(cs, 0) ;
+  return 1 ;
+
+ err:
+  pthread_setcancelstate(cs, 0) ;
+  return 0 ;
+}