diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/nsssd/nsssd-switch.c | 83 | ||||
-rwxr-xr-x[l---------] | src/tests/test-nsssd-switch.baseline | 8 | ||||
-rw-r--r--[l---------] | src/tests/test-nsssd-switch.c | 84 | ||||
-rwxr-xr-x | src/tests/test-nsssd-switch.wrapper | 6 | ||||
-rwxr-xr-x | src/tests/test-switch.wrapper | 6 |
5 files changed, 175 insertions, 12 deletions
diff --git a/src/nsssd/nsssd-switch.c b/src/nsssd/nsssd-switch.c index 4906728..de670a7 100644 --- a/src/nsssd/nsssd-switch.c +++ b/src/nsssd/nsssd-switch.c @@ -18,7 +18,7 @@ #define USAGE "nsssd-switch bitfield1 backend1... \"\" bitfield2 backend2... \"\"" #define dieusage() strerr_dieusage(100, USAGE) -#define MAX_BACKENDS 16 +#define MAX_BACKENDS 8 static tain tto = TAIN_INFINITE_RELATIVE ; static stralloc storagesa = STRALLOC_ZERO ; @@ -148,6 +148,11 @@ int nsssd_pwd_rewind (void *handle) } tain_add_g(&deadline, &tto) ; if (nsss_switch_pwd_rewind_g(&a->tab[i].handle, &deadline)) return 1 ; + if (errno == ETIMEDOUT) + { + nsss_switch_end(&a->tab[i].handle, NSSS_SWITCH_PWD | NSSS_SWITCH_GRP | NSSS_SWITCH_SHADOW) ; + a->tab[i].failed = 1 ; + } if (a->tab[i].flags & 2) return 0 ; } return 0 ; @@ -168,6 +173,11 @@ int nsssd_pwd_get (void *handle, struct passwd *pw) storagesa.len = 0 ; errno = 0 ; if (nsss_switch_pwd_get_g(&a->tab[i].handle, pw, &storagesa, &deadline)) return 1 ; + if (errno == ETIMEDOUT) + { + nsss_switch_end(&a->tab[i].handle, NSSS_SWITCH_PWD | NSSS_SWITCH_GRP | NSSS_SWITCH_SHADOW) ; + a->tab[i].failed = 1 ; + } if (a->tab[i].flags & (errno ? 2 : 4)) return 0 ; } return 0 ; @@ -188,6 +198,11 @@ int nsssd_pwd_getbyuid (void *handle, struct passwd *pw, uid_t uid) storagesa.len = 0 ; errno = 0 ; if (nsss_switch_pwd_getbyuid_g(&a->tab[i].handle, pw, &storagesa, uid, &deadline)) return 1 ; + if (errno == ETIMEDOUT) + { + nsss_switch_end(&a->tab[i].handle, NSSS_SWITCH_PWD | NSSS_SWITCH_GRP | NSSS_SWITCH_SHADOW) ; + a->tab[i].failed = 1 ; + } if (a->tab[i].flags & (errno ? 2 : 4)) return 0 ; } return 0 ; @@ -208,6 +223,11 @@ int nsssd_pwd_getbyname (void *handle, struct passwd *pw, char const *name) storagesa.len = 0 ; errno = 0 ; if (nsss_switch_pwd_getbyname_g(&a->tab[i].handle, pw, &storagesa, name, &deadline)) return 1 ; + if (errno == ETIMEDOUT) + { + nsss_switch_end(&a->tab[i].handle, NSSS_SWITCH_PWD | NSSS_SWITCH_GRP | NSSS_SWITCH_SHADOW) ; + a->tab[i].failed = 1 ; + } if (a->tab[i].flags & (errno ? 2 : 4)) return 0 ; } return 0 ; @@ -225,7 +245,12 @@ void nsssd_pwd_end (void *handle) else continue ; } tain_add_g(&deadline, &tto) ; - nsss_switch_pwd_end_g(&a->tab[i].handle, &deadline) ; + if (nsss_switch_pwd_end_g(&a->tab[i].handle, &deadline)) continue ; + if (errno == ETIMEDOUT) + { + nsss_switch_end(&a->tab[i].handle, NSSS_SWITCH_PWD | NSSS_SWITCH_GRP | NSSS_SWITCH_SHADOW) ; + a->tab[i].failed = 1 ; + } } } @@ -248,6 +273,11 @@ int nsssd_grp_rewind (void *handle) } tain_add_g(&deadline, &tto) ; if (nsss_switch_grp_rewind_g(&a->tab[i].handle, &deadline)) return 1 ; + if (errno == ETIMEDOUT) + { + nsss_switch_end(&a->tab[i].handle, NSSS_SWITCH_PWD | NSSS_SWITCH_GRP | NSSS_SWITCH_SHADOW) ; + a->tab[i].failed = 1 ; + } if (a->tab[i].flags & 2) return 0 ; } return 0 ; @@ -269,6 +299,11 @@ int nsssd_grp_get (void *handle, struct group *gr) genalloc_setlen(char *, &storagega, 0) ; errno = 0 ; if (nsss_switch_grp_get_g(&a->tab[i].handle, gr, &storagesa, &storagega, &deadline)) return 1 ; + if (errno == ETIMEDOUT) + { + nsss_switch_end(&a->tab[i].handle, NSSS_SWITCH_PWD | NSSS_SWITCH_GRP | NSSS_SWITCH_SHADOW) ; + a->tab[i].failed = 1 ; + } if (a->tab[i].flags & (errno ? 2 : 4)) return 0 ; } return 0 ; @@ -290,6 +325,11 @@ int nsssd_grp_getbygid (void *handle, struct group *gr, gid_t gid) genalloc_setlen(char *, &storagega, 0) ; errno = 0 ; if (nsss_switch_grp_getbygid_g(&a->tab[i].handle, gr, &storagesa, &storagega, gid, &deadline)) return 1 ; + if (errno == ETIMEDOUT) + { + nsss_switch_end(&a->tab[i].handle, NSSS_SWITCH_PWD | NSSS_SWITCH_GRP | NSSS_SWITCH_SHADOW) ; + a->tab[i].failed = 1 ; + } if (a->tab[i].flags & (errno ? 2 : 4)) return 0 ; } return 0 ; @@ -311,6 +351,11 @@ int nsssd_grp_getbyname (void *handle, struct group *gr, char const *name) genalloc_setlen(char *, &storagega, 0) ; errno = 0 ; if (nsss_switch_grp_getbyname_g(&a->tab[i].handle, gr, &storagesa, &storagega, name, &deadline)) return 1 ; + if (errno == ETIMEDOUT) + { + nsss_switch_end(&a->tab[i].handle, NSSS_SWITCH_PWD | NSSS_SWITCH_GRP | NSSS_SWITCH_SHADOW) ; + a->tab[i].failed = 1 ; + } if (a->tab[i].flags & (errno ? 2 : 4)) return 0 ; } return 0 ; @@ -331,6 +376,11 @@ int nsssd_grp_getlist (void *handle, char const *user, gid_t *gids, size_t n, si storagesa.len = 0 ; errno = 0 ; if (nsss_switch_grp_getlist_g(&a->tab[i].handle, user, gids, n, r, &storagesa, &deadline)) return 1 ; + if (errno == ETIMEDOUT) + { + nsss_switch_end(&a->tab[i].handle, NSSS_SWITCH_PWD | NSSS_SWITCH_GRP | NSSS_SWITCH_SHADOW) ; + a->tab[i].failed = 1 ; + } if (a->tab[i].flags & (errno ? 2 : 4)) return 0 ; } return 0 ; @@ -348,7 +398,12 @@ void nsssd_grp_end (void *handle) else continue ; } tain_add_g(&deadline, &tto) ; - nsss_switch_grp_end_g(&a->tab[i].handle, &deadline) ; + if (nsss_switch_grp_end_g(&a->tab[i].handle, &deadline)) continue ; + if (errno == ETIMEDOUT) + { + nsss_switch_end(&a->tab[i].handle, NSSS_SWITCH_PWD | NSSS_SWITCH_GRP | NSSS_SWITCH_SHADOW) ; + a->tab[i].failed = 1 ; + } } } @@ -371,6 +426,11 @@ int nsssd_shadow_rewind (void *handle) } tain_add_g(&deadline, &tto) ; if (nsss_switch_shadow_rewind_g(&a->tab[i].handle, &deadline)) return 1 ; + if (errno == ETIMEDOUT) + { + nsss_switch_end(&a->tab[i].handle, NSSS_SWITCH_PWD | NSSS_SWITCH_GRP | NSSS_SWITCH_SHADOW) ; + a->tab[i].failed = 1 ; + } if (a->tab[i].flags & 2) return 0 ; } return 0 ; @@ -391,6 +451,11 @@ int nsssd_shadow_get (void *handle, struct spwd *sp) storagesa.len = 0 ; errno = 0 ; if (nsss_switch_shadow_get_g(&a->tab[i].handle, sp, &storagesa, &deadline)) return 1 ; + if (errno == ETIMEDOUT) + { + nsss_switch_end(&a->tab[i].handle, NSSS_SWITCH_PWD | NSSS_SWITCH_GRP | NSSS_SWITCH_SHADOW) ; + a->tab[i].failed = 1 ; + } if (a->tab[i].flags & (errno ? 2 : 4)) return 0 ; } return 0 ; @@ -411,6 +476,11 @@ int nsssd_shadow_getbyname (void *handle, struct spwd *sp, char const *name) storagesa.len = 0 ; errno = 0 ; if (nsss_switch_shadow_getbyname_g(&a->tab[i].handle, sp, &storagesa, name, &deadline)) return 1 ; + if (errno == ETIMEDOUT) + { + nsss_switch_end(&a->tab[i].handle, NSSS_SWITCH_PWD | NSSS_SWITCH_GRP | NSSS_SWITCH_SHADOW) ; + a->tab[i].failed = 1 ; + } if (a->tab[i].flags & (errno ? 2 : 4)) return 0 ; } return 0 ; @@ -428,7 +498,12 @@ void nsssd_shadow_end (void *handle) else continue ; } tain_add_g(&deadline, &tto) ; - nsss_switch_pwd_end_g(&a->tab[i].handle, &deadline) ; + if (nsss_switch_pwd_end_g(&a->tab[i].handle, &deadline)) continue ; + if (errno == ETIMEDOUT) + { + nsss_switch_end(&a->tab[i].handle, NSSS_SWITCH_PWD | NSSS_SWITCH_GRP | NSSS_SWITCH_SHADOW) ; + a->tab[i].failed = 1 ; + } } } diff --git a/src/tests/test-nsssd-switch.baseline b/src/tests/test-nsssd-switch.baseline index 28f1c7a..31fba7e 120000..100755 --- a/src/tests/test-nsssd-switch.baseline +++ b/src/tests/test-nsssd-switch.baseline @@ -1 +1,7 @@ -test-switch.baseline
\ No newline at end of file +#!/bin/sh -e + +cat /etc/passwd +echo +id -u root +echo +cat /etc/group diff --git a/src/tests/test-nsssd-switch.c b/src/tests/test-nsssd-switch.c index 08323c4..e4289e4 120000..100644 --- a/src/tests/test-nsssd-switch.c +++ b/src/tests/test-nsssd-switch.c @@ -1 +1,83 @@ -test-switch.c
\ No newline at end of file +/* ISC license. */ + +#include <errno.h> +#include <skalibs/buffer.h> +#include <skalibs/strerr2.h> +#include <skalibs/stralloc.h> +#include <skalibs/genalloc.h> +#include <skalibs/lolstdio.h> +#include <skalibs/tai.h> +#include <nsss/pwd-def.h> +#include <nsss/grp-def.h> +#include <nsss/nsss-switch.h> + +#define S "./.test-nsssd-switch-socket" + +int main (void) +{ + nsss_switch_t a = NSSS_SWITCH_ZERO ; + stralloc sa = STRALLOC_ZERO ; + genalloc ga = GENALLOC_ZERO ; + tain deadline ; + PROG = "test-nsssd-switch" ; + tain_now_set_stopwatch_g() ; + tain_from_millisecs(&deadline, 10000) ; + tain_add_g(&deadline, &deadline) ; + + if (!nsss_switch_start_g(&a, NSSS_SWITCH_PWD, S, &deadline)) + strerr_diefu1sys(111, "nsss_switch_start") ; + + for (;;) + { + struct passwd pw ; + errno = 0 ; + if (!nsss_switch_pwd_get_g(&a, &pw, &sa, &deadline)) break ; + lolprintf("%s:%s:%d:%d:%s:%s:%s\n", pw.pw_name, pw.pw_passwd, (int)pw.pw_uid, (int)pw.pw_gid, pw.pw_gecos, pw.pw_dir, pw.pw_shell) ; + sa.len = 0 ; + } + if (errno) + strerr_diefu1sys(111, "nsss_switch_pwd_get") ; + if (!nsss_switch_pwd_end_g(&a, &deadline)) + strerr_diefu1sys(111, "nsss_switch_pwd_end") ; + lolprintf("\n") ; + + { + struct passwd pw ; + if (!nsss_switch_pwd_getbyname_g(&a, &pw, &sa, "root", &deadline)) + strerr_diefu1sys(111, "nsss_switch_pwd_getbyname") ; + lolprintf("%u\n\n", (unsigned int)pw.pw_uid) ; + sa.len = 0 ; + } + + if (!nsss_switch_start_g(&a, NSSS_SWITCH_GRP, S, &deadline)) + strerr_diefu1sys(111, "nsss_switch_start") ; + nsss_switch_end(&a, NSSS_SWITCH_PWD) ; + buffer_flush(buffer_1) ; + + for (;;) + { + struct group gr ; + char **p ; + errno = 0 ; + if (!nsss_switch_grp_get_g(&a, &gr, &sa, &ga, &deadline)) break ; + p = gr.gr_mem ; + lolprintf("%s:%s:%d:", gr.gr_name, gr.gr_passwd, (int)gr.gr_gid) ; + buffer_flush(buffer_1) ; + if (*p) + { + while (*p) lolprintf("%s,", *p++) ; + buffer_unput(buffer_1, 1) ; + } + buffer_put(buffer_1, "\n", 1) ; + sa.len = 0 ; + genalloc_setlen(char *, &ga, 0) ; + } + if (errno) + strerr_diefu1sys(111, "nsss_switch_grp_get") ; + if (!nsss_switch_grp_end_g(&a, &deadline)) + strerr_diefu1sys(111, "nsss_switch_grp_end") ; + nsss_switch_end(&a, NSSS_SWITCH_GRP) ; + + buffer_flush(buffer_1) ; + return 0 ; +} diff --git a/src/tests/test-nsssd-switch.wrapper b/src/tests/test-nsssd-switch.wrapper index 8e05937..509bf18 100755 --- a/src/tests/test-nsssd-switch.wrapper +++ b/src/tests/test-nsssd-switch.wrapper @@ -1,13 +1,13 @@ #!/bin/sh -e -S=./.test-switch-socket -F=./.test-switch-fifo +S=./.test-nsssd-switch-socket +F=./.test-nsssd-switch-fifo pid=0 cleanup () { kill $pid - rm -f $S + rm -f ${S} ${S}.lock } mkfifo $F diff --git a/src/tests/test-switch.wrapper b/src/tests/test-switch.wrapper index 5117400..387595f 100755 --- a/src/tests/test-switch.wrapper +++ b/src/tests/test-switch.wrapper @@ -1,4 +1,4 @@ -#!/bin/sh -e +#!/bin/sh -ex S=./.test-switch-socket F=./.test-switch-fifo @@ -7,13 +7,13 @@ pid=0 cleanup () { kill $pid - rm -f $S + rm -f ${S} ${S}.lock } mkfifo $F head -n 1 < $F >/dev/null & pid=$! -s6-ipcserver -1 -- $S ./nsssd-unix > $F & +s6-ipcserver -1 -- ${S} ./nsssd-unix > $F & wait $pid pid=$! rm -f $F |