nwrap: Add support for getspnam()
authorAndreas Schneider <asn@samba.org>
Thu, 17 Sep 2015 08:39:15 +0000 (10:39 +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 f24045df17d31c50ae0f4ed5e9f50ae8e703cff4..ca57dfbc6fa685757d0b0d76d94956d71bebb8ca 100644 (file)
@@ -2569,6 +2569,31 @@ static void nwrap_files_endspent(void)
        nwrap_sp_global.idx = 0;
 }
 
+static struct spwd *nwrap_files_getspnam(const char *name)
+{
+       int i;
+
+       NWRAP_LOG(NWRAP_LOG_DEBUG, "Lookup user %s in files", name);
+
+       nwrap_files_cache_reload(nwrap_sp_global.cache);
+
+       for (i=0; i<nwrap_sp_global.num; i++) {
+               if (strcmp(nwrap_sp_global.list[i].sp_namp, name) == 0) {
+                       NWRAP_LOG(NWRAP_LOG_DEBUG, "user[%s] found", name);
+                       return &nwrap_sp_global.list[i];
+               }
+               NWRAP_LOG(NWRAP_LOG_DEBUG,
+                         "user[%s] does not match [%s]",
+                         name,
+                         nwrap_sp_global.list[i].sp_namp);
+       }
+
+       NWRAP_LOG(NWRAP_LOG_DEBUG, "user[%s] not found\n", name);
+
+       errno = ENOENT;
+       return NULL;
+}
+
 /* misc functions */
 static int nwrap_files_initgroups(struct nwrap_backend *b,
                                  const char *user,
@@ -4088,6 +4113,20 @@ void endspent(void)
        nwrap_endspent();
 }
 
+static struct spwd *nwrap_getspnam(const char *name)
+{
+       return nwrap_files_getspnam(name);
+}
+
+struct spwd *getspnam(const char *name)
+{
+       if (!nss_wrapper_shadow_enabled()) {
+               return NULL;
+       }
+
+       return nwrap_getspnam(name);
+}
+
 /**********************************************************
  * NETDB
  **********************************************************/