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_switch_shadow_read.c | |
download | nsss-633445be1a9be37ae727c044417f5607706cf4ae.tar.gz nsss-633445be1a9be37ae727c044417f5607706cf4ae.tar.xz nsss-633445be1a9be37ae727c044417f5607706cf4ae.zip |
Initial commit
Diffstat (limited to 'src/libnsss/nsss_switch_shadow_read.c')
-rw-r--r-- | src/libnsss/nsss_switch_shadow_read.c | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/src/libnsss/nsss_switch_shadow_read.c b/src/libnsss/nsss_switch_shadow_read.c new file mode 100644 index 0000000..1806c6d --- /dev/null +++ b/src/libnsss/nsss_switch_shadow_read.c @@ -0,0 +1,56 @@ +/* ISC license. */ + +#include <stdint.h> +#include <string.h> +#include <errno.h> +#include <skalibs/posixplz.h> +#include <skalibs/uint32.h> +#include <skalibs/uint64.h> +#include <skalibs/error.h> +#include <skalibs/stralloc.h> +#include <skalibs/unix-timed.h> +#include <nsss/shadow-def.h> +#include "nsss-switch-internal.h" + +/* + Expects: + 8 bytes sp_lstchg + 8 bytes sp_min + 8 bytes sp_max + 8 bytes sp_warn + 8 bytes sp_inact + 8 bytes sp_expire + 8 bytes sp_flag + 4 bytes total length of strings (including \0's) + \0-terminated sp_namp + \0-terminated sp_pwdp +*/ + +int nsss_switch_shadow_read (buffer *b, struct spwd *sp, stralloc *sa, tain_t const *deadline, tain_t *stamp) +{ + struct spwd sptmp ; + uint64_t x ; + uint32_t total, len ; + char *p ; + char buf[60] ; + if (!buffer_timed_get(b, buf, 60, deadline, stamp)) return 0 ; + uint64_unpack_big(buf, &x) ; sptmp.sp_lstchg = x ; + uint64_unpack_big(buf + 8, &x) ; sptmp.sp_min = x ; + uint64_unpack_big(buf + 16, &x) ; sptmp.sp_max = x ; + uint64_unpack_big(buf + 24, &x) ; sptmp.sp_warn = x ; + uint64_unpack_big(buf + 32, &x) ; sptmp.sp_inact = x ; + uint64_unpack_big(buf + 40, &x) ; sptmp.sp_expire = x ; + uint64_unpack_big(buf + 48, &x) ; sptmp.sp_flag = x ; + uint32_unpack_big(buf + 56, &total) ; + if (!stralloc_readyplus(sa, total)) return 0 ; + if (!buffer_timed_get(b, sa->s + sa->len, total, deadline, stamp)) return 0 ; + if (sa->s[sa->len + total - 1]) return (errno = EPROTO, 0) ; + p = sa->s + sa->len ; len = total ; + sptmp.sp_namp = p ; x = strnlen(p, len) + 1 ; p += x ; len -= x ; + if (!len) return (errno = EPROTO, 0) ; + sptmp.sp_pwdp = p ; x = strnlen(p, len) + 1 ; p += x ; len -= x ; + if (len) return (errno = EPROTO, 0) ; + sa->len += total ; + *sp = sptmp ; + return 1 ; +} |