From: Andreas Schneider Date: Thu, 17 Sep 2015 08:38:49 +0000 (+0200) Subject: nwrap: Add (set|get|end)spent functions X-Git-Url: http://git.samba.org/?a=commitdiff_plain;h=608fa2063a498bea66df1fb0c1336a2a649986b2;p=obnox%2Fsamba%2Fsamba-obnox.git nwrap: Add (set|get|end)spent functions Signed-off-by: Andreas Schneider Reviewed-by: Michael Adam --- diff --git a/lib/nss_wrapper/nss_wrapper.c b/lib/nss_wrapper/nss_wrapper.c index 45a5d60ddc3..f24045df17d 100644 --- a/lib/nss_wrapper/nss_wrapper.c +++ b/lib/nss_wrapper/nss_wrapper.c @@ -2536,6 +2536,39 @@ static void nwrap_files_endpwent(struct nwrap_backend *b) nwrap_pw_global.idx = 0; } +/* shadow */ +static void nwrap_files_setspent(void) +{ + nwrap_sp_global.idx = 0; +} + +static struct spwd *nwrap_files_getspent(void) +{ + struct spwd *sp; + + if (nwrap_sp_global.idx == 0) { + nwrap_files_cache_reload(nwrap_sp_global.cache); + } + + if (nwrap_sp_global.idx >= nwrap_sp_global.num) { + errno = ENOENT; + return NULL; + } + + sp = &nwrap_sp_global.list[nwrap_sp_global.idx++]; + + NWRAP_LOG(NWRAP_LOG_DEBUG, + "return user[%s]", + sp->sp_namp); + + return sp; +} + +static void nwrap_files_endspent(void) +{ + nwrap_sp_global.idx = 0; +} + /* misc functions */ static int nwrap_files_initgroups(struct nwrap_backend *b, const char *user, @@ -4009,6 +4042,52 @@ int getgrouplist(const char *user, gid_t group, gid_t *groups, int *ngroups) } #endif +/********************************************************** + * SHADOW + **********************************************************/ + +static void nwrap_setspent(void) +{ + nwrap_files_setspent(); +} + +void setspent(void) +{ + if (!nss_wrapper_shadow_enabled()) { + return; + } + + nwrap_setspent(); +} + +static struct spwd *nwrap_getspent(void) +{ + return nwrap_files_getspent(); +} + +struct spwd *getspent(void) +{ + if (!nss_wrapper_shadow_enabled()) { + return NULL; + } + + return nwrap_getspent(); +} + +static void nwrap_endspent(void) +{ + nwrap_files_endspent(); +} + +void endspent(void) +{ + if (!nss_wrapper_shadow_enabled()) { + return; + } + + nwrap_endspent(); +} + /********************************************************** * NETDB **********************************************************/