nwrap: Add (set|get|end)spent functions
authorAndreas Schneider <asn@samba.org>
Thu, 17 Sep 2015 08:38:49 +0000 (10:38 +0200)
committerMichael Adam <obnox@samba.org>
Mon, 11 Jan 2016 11:25:27 +0000 (12:25 +0100)
Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
lib/nss_wrapper/nss_wrapper.c

index 45a5d60ddc39e02498bfd8f74a9c85e77fc516cb..f24045df17d31c50ae0f4ed5e9f50ae8e703cff4 100644 (file)
@@ -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
  **********************************************************/