The branch, master has been updated
       via  962cf22 nwrap: Use snprintf() instead of strcpy()
       via  79f1b29 tests: Add testing for BSD 'struct passwd' members
       via  7df4b1c nwrap: Support FreeBSD 'struct passwd' members
      from  03018f8 Bump version to 1.1.2

https://git.samba.org/?p=nss_wrapper.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 962cf22a01f07008bb80711f48afaafc9b3bc087
Author: Andreas Schneider <[email protected]>
Date:   Wed Mar 16 18:13:00 2016 +0100

    nwrap: Use snprintf() instead of strcpy()
    
    Signed-off-by: Andreas Schneider <[email protected]>
    Reviewed-by: Jeremy Allison <[email protected]>

commit 79f1b29e5daafbb6e624bbee3700ce07e39f72fd
Author: Andreas Schneider <[email protected]>
Date:   Thu Jan 21 13:51:08 2016 +0100

    tests: Add testing for BSD 'struct passwd' members
    
    Signed-off-by: Andreas Schneider <[email protected]>
    Reviewed-by: Jeremy Allison <[email protected]>

commit 7df4b1c2bcc2fc96d1203c6814472fe77c9c82a0
Author: Andreas Schneider <[email protected]>
Date:   Thu Jan 21 13:47:27 2016 +0100

    nwrap: Support FreeBSD 'struct passwd' members
    
    Signed-off-by: Andreas Schneider <[email protected]>
    Reviewed-by: Jeremy Allison <[email protected]>

-----------------------------------------------------------------------

Summary of changes:
 ConfigureChecks.cmake |  3 +++
 config.h.cmake        |  4 ++++
 src/nss_wrapper.c     | 34 ++++++++++++++++++++++++++++++++--
 tests/testsuite.c     | 12 ++++++++++++
 4 files changed, 51 insertions(+), 2 deletions(-)


Changeset truncated at 500 lines:

diff --git a/ConfigureChecks.cmake b/ConfigureChecks.cmake
index 1b6ba01..462b166 100644
--- a/ConfigureChecks.cmake
+++ b/ConfigureChecks.cmake
@@ -191,6 +191,9 @@ check_prototype_definition(getnameinfo
 
 # STRUCT MEMBERS
 check_struct_has_member("struct sockaddr" sa_len "sys/socket.h netinet/in.h" 
HAVE_STRUCT_SOCKADDR_SA_LEN)
+check_struct_has_member("struct passwd" pw_class "pwd.h" 
HAVE_STRUCT_PASSWD_PW_CLASS)
+check_struct_has_member("struct passwd" pw_change "pwd.h" 
HAVE_STRUCT_PASSWD_PW_CHANGE)
+check_struct_has_member("struct passwd" pw_expire "pwd.h" 
HAVE_STRUCT_PASSWD_PW_EXPIRE)
 
 # IPV6
 check_c_source_compiles("
diff --git a/config.h.cmake b/config.h.cmake
index f00c2a4..75c92ed 100644
--- a/config.h.cmake
+++ b/config.h.cmake
@@ -86,6 +86,10 @@
 #cmakedefine HAVE_LINUX_GETNAMEINFO_UNSIGNED 1
 
 #cmakedefine HAVE_STRUCT_SOCKADDR_SA_LEN 1
+#cmakedefine HAVE_STRUCT_PASSWD_PW_CLASS 1
+#cmakedefine HAVE_STRUCT_PASSWD_PW_CHANGE 1
+#cmakedefine HAVE_STRUCT_PASSWD_PW_EXPIRE 1
+
 #cmakedefine HAVE_IPV6 1
 
 #cmakedefine HAVE_ATTRIBUTE_PRINTF_FORMAT 1
diff --git a/src/nss_wrapper.c b/src/nss_wrapper.c
index c4f1b33..82581b1 100644
--- a/src/nss_wrapper.c
+++ b/src/nss_wrapper.c
@@ -154,6 +154,14 @@ typedef nss_status_t NSS_STATUS;
 #define SAFE_FREE(x) do { if ((x) != NULL) {free(x); (x)=NULL;} } while(0)
 #endif
 
+#ifndef discard_const
+#define discard_const(ptr) ((void *)((uintptr_t)(ptr)))
+#endif
+
+#ifndef discard_const_p
+#define discard_const_p(type, ptr) ((type *)discard_const(ptr))
+#endif
+
 #ifdef HAVE_IPV6
 #define NWRAP_INET_ADDRSTRLEN INET6_ADDRSTRLEN
 #else
@@ -1963,6 +1971,28 @@ static bool nwrap_pw_parse_line(struct nwrap_cache 
*nwrap, char *line)
 
        NWRAP_LOG(NWRAP_LOG_TRACE, "gid[%u]\n", pw->pw_gid);
 
+#ifdef HAVE_STRUCT_PASSWD_PW_CLASS
+       pw->pw_class = discard_const_p(char, "");
+
+       NWRAP_LOG(NWRAP_LOG_TRACE, "class[%s]", pw->pw_class);
+#endif /* HAVE_STRUCT_PASSWD_PW_CLASS */
+
+#ifdef HAVE_STRUCT_PASSWD_PW_CHANGE
+       pw->pw_change = 0;
+
+       NWRAP_LOG(NWRAP_LOG_TRACE,
+                 "change[%lu]",
+                 (unsigned long)pw->pw_change);
+#endif /* HAVE_STRUCT_PASSWD_PW_CHANGE */
+
+#ifdef HAVE_STRUCT_PASSWD_PW_EXPIRE
+       pw->pw_expire = 0;
+
+       NWRAP_LOG(NWRAP_LOG_TRACE,
+                 "expire[%lu]",
+                 (unsigned long)pw->pw_expire);
+#endif /* HAVE_STRUCT_PASSWD_PW_EXPIRE */
+
        /* gecos */
        p = strchr(c, ':');
        if (!p) {
@@ -5421,7 +5451,7 @@ static int nwrap_getnameinfo(const struct sockaddr *sa, 
socklen_t salen,
                if (he != NULL && he->h_name != NULL) {
                        if (strlen(he->h_name) >= hostlen)
                                return EAI_OVERFLOW;
-                       strcpy(host, he->h_name);
+                       snprintf(host, hostlen, "%s", he->h_name);
                        if (flags & NI_NOFQDN)
                                host[strcspn(host, ".")] = '\0';
                } else {
@@ -5439,7 +5469,7 @@ static int nwrap_getnameinfo(const struct sockaddr *sa, 
socklen_t salen,
                if (service != NULL) {
                        if (strlen(service->s_name) >= servlen)
                                return EAI_OVERFLOW;
-                       strcpy(serv, service->s_name);
+                       snprintf(serv, servlen, "%s", service->s_name);
                } else {
                        if (snprintf(serv, servlen, "%u", port) >= (int) 
servlen)
                                return EAI_OVERFLOW;
diff --git a/tests/testsuite.c b/tests/testsuite.c
index ee35189..dccdb97 100644
--- a/tests/testsuite.c
+++ b/tests/testsuite.c
@@ -75,6 +75,15 @@ static bool copy_passwd(const struct passwd *pwd, struct 
passwd *p)
        p->pw_passwd    = strdup(pwd->pw_passwd);
        p->pw_uid       = pwd->pw_uid;
        p->pw_gid       = pwd->pw_gid;
+#ifdef HAVE_STRUCT_PASSWD_PW_CLASS
+       p->pw_class     = strdup(pwd->pw_class);
+#endif
+#ifdef HAVE_STRUCT_PASSWD_PW_CHANGE
+       p->pw_change    = pwd->pw_change;
+#endif
+#ifdef HAVE_STRUCT_PASSWD_PW_EXPIRE
+       p->pw_expire    = pwd->pw_expire;
+#endif
        p->pw_gecos     = strdup(pwd->pw_gecos);
        p->pw_dir       = strdup(pwd->pw_dir);
        p->pw_shell     = strdup(pwd->pw_shell);
@@ -86,6 +95,9 @@ static void free_passwd(struct passwd *p)
 {
        SAFE_FREE(p->pw_name);
        SAFE_FREE(p->pw_passwd);
+#ifdef HAVE_STRUCT_PASSWD_PW_CLASS
+       SAFE_FREE(p->pw_class);
+#endif
        SAFE_FREE(p->pw_gecos);
        SAFE_FREE(p->pw_dir);
        SAFE_FREE(p->pw_shell);


-- 
NSS Wrapper Repository

Reply via email to