The branch, master has been updated
       via  61cf117f86f803b839539db0f806c1c413f664de (commit)
       via  59ee0a1e8a35c1ced97e67a2c7bf5da67a55c2a0 (commit)
       via  af0b586c7452dd897e5d75c20ce5b929db86e34a (commit)
      from  c110e664af9449e8fac24f4ed6e973d98d4fd268 (commit)

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 61cf117f86f803b839539db0f806c1c413f664de
Author: Günther Deschner <g...@samba.org>
Date:   Fri Jun 5 00:33:14 2009 +0200

    nss_wrapper: add cross checking test to testsuite.
    
    Guenther

commit 59ee0a1e8a35c1ced97e67a2c7bf5da67a55c2a0
Author: Günther Deschner <g...@samba.org>
Date:   Thu Jun 4 23:57:43 2009 +0200

    nss_wrapper: add tests for getgrent_r to testsuite.
    
    Guenther

commit af0b586c7452dd897e5d75c20ce5b929db86e34a
Author: Günther Deschner <g...@samba.org>
Date:   Thu Jun 4 22:52:03 2009 +0200

    nss_wrapper: add tests for getpwent_r to testsuite.
    
    Guenther

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

Summary of changes:
 lib/nss_wrapper/testsuite.c |  362 +++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 362 insertions(+), 0 deletions(-)


Changeset truncated at 500 lines:

diff --git a/lib/nss_wrapper/testsuite.c b/lib/nss_wrapper/testsuite.c
index 57c61f6..e4047cf 100644
--- a/lib/nss_wrapper/testsuite.c
+++ b/lib/nss_wrapper/testsuite.c
@@ -72,6 +72,33 @@ static bool test_nwrap_getpwnam(struct torture_context *tctx,
        return pwd ? true : false;
 }
 
+static bool test_nwrap_getpwnam_r(struct torture_context *tctx,
+                                 const char *name,
+                                 struct passwd *pwd_p)
+{
+       struct passwd pwd, *pwdp;
+       char buffer[4096];
+       int ret;
+
+       torture_comment(tctx, "Testing getpwnam_r: %s\n", name);
+
+       ret = getpwnam_r(name, &pwd, buffer, sizeof(buffer), &pwdp);
+       if (ret != 0) {
+               if (ret != ENOENT) {
+                       torture_comment(tctx, "got %d return code\n", ret);
+               }
+               return false;
+       }
+
+       print_passwd(&pwd);
+
+       if (pwd_p) {
+               copy_passwd(tctx, &pwd, pwd_p);
+       }
+
+       return true;
+}
+
 static bool test_nwrap_getpwuid(struct torture_context *tctx,
                                uid_t uid,
                                struct passwd *pwd_p)
@@ -92,6 +119,34 @@ static bool test_nwrap_getpwuid(struct torture_context 
*tctx,
        return pwd ? true : false;
 }
 
+static bool test_nwrap_getpwuid_r(struct torture_context *tctx,
+                                 uid_t uid,
+                                 struct passwd *pwd_p)
+{
+       struct passwd pwd, *pwdp;
+       char buffer[4096];
+       int ret;
+
+       torture_comment(tctx, "Testing getpwuid_r: %lu\n", (unsigned long)uid);
+
+       ret = getpwuid_r(uid, &pwd, buffer, sizeof(buffer), &pwdp);
+       if (ret != 0) {
+               if (ret != ENOENT) {
+                       torture_comment(tctx, "got %d return code\n", ret);
+               }
+               return false;
+       }
+
+       print_passwd(&pwd);
+
+       if (pwd_p) {
+               copy_passwd(tctx, &pwd, pwd_p);
+       }
+
+       return true;
+}
+
+
 static bool copy_group(struct torture_context *tctx,
                       const struct group *grp,
                       struct group *g)
@@ -151,6 +206,34 @@ static bool test_nwrap_getgrnam(struct torture_context 
*tctx,
        return grp ? true : false;
 }
 
+static bool test_nwrap_getgrnam_r(struct torture_context *tctx,
+                                 const char *name,
+                                 struct group *grp_p)
+{
+       struct group grp, *grpp;
+       char buffer[4096];
+       int ret;
+
+       torture_comment(tctx, "Testing getgrnam_r: %s\n", name);
+
+       ret = getgrnam_r(name, &grp, buffer, sizeof(buffer), &grpp);
+       if (ret != 0) {
+               if (ret != ENOENT) {
+                       torture_comment(tctx, "got %d return code\n", ret);
+               }
+               return false;
+       }
+
+       print_group(&grp);
+
+       if (grp_p) {
+               copy_group(tctx, &grp, grp_p);
+       }
+
+       return true;
+}
+
+
 static bool test_nwrap_getgrgid(struct torture_context *tctx,
                                gid_t gid,
                                struct group *grp_p)
@@ -171,6 +254,33 @@ static bool test_nwrap_getgrgid(struct torture_context 
*tctx,
        return grp ? true : false;
 }
 
+static bool test_nwrap_getgrgid_r(struct torture_context *tctx,
+                                 gid_t gid,
+                                 struct group *grp_p)
+{
+       struct group grp, *grpp;
+       char buffer[4096];
+       int ret;
+
+       torture_comment(tctx, "Testing getgrgid_r: %lu\n", (unsigned long)gid);
+
+       ret = getgrgid_r(gid, &grp, buffer, sizeof(buffer), &grpp);
+       if (ret != 0) {
+               if (ret != ENOENT) {
+                       torture_comment(tctx, "got %d return code\n", ret);
+               }
+               return false;
+       }
+
+       print_group(&grp);
+
+       if (grp_p) {
+               copy_group(tctx, &grp, grp_p);
+       }
+
+       return true;
+}
+
 static bool test_nwrap_enum_passwd(struct torture_context *tctx,
                                   struct passwd **pwd_array_p,
                                   size_t *num_pwd_p)
@@ -207,6 +317,51 @@ static bool test_nwrap_enum_passwd(struct torture_context 
*tctx,
        return true;
 }
 
+static bool test_nwrap_enum_r_passwd(struct torture_context *tctx,
+                                    struct passwd **pwd_array_p,
+                                    size_t *num_pwd_p)
+{
+       struct passwd pwd, *pwdp;
+       struct passwd *pwd_array = NULL;
+       size_t num_pwd = 0;
+       char buffer[4096];
+       int ret;
+
+       torture_comment(tctx, "Testing setpwent\n");
+       setpwent();
+
+       while (1) {
+               torture_comment(tctx, "Testing getpwent_r\n");
+
+               ret = getpwent_r(&pwd, buffer, sizeof(buffer), &pwdp);
+               if (ret != 0) {
+                       if (ret != ENOENT) {
+                               torture_comment(tctx, "got %d return code\n", 
ret);
+                       }
+                       break;
+               }
+               print_passwd(&pwd);
+               if (pwd_array_p && num_pwd_p) {
+                       pwd_array = talloc_realloc(tctx, pwd_array, struct 
passwd, num_pwd+1);
+                       torture_assert(tctx, pwd_array, "out of memory");
+                       copy_passwd(tctx, &pwd, &pwd_array[num_pwd]);
+                       num_pwd++;
+               }
+       }
+
+       torture_comment(tctx, "Testing endpwent\n");
+       endpwent();
+
+       if (pwd_array_p) {
+               *pwd_array_p = pwd_array;
+       }
+       if (num_pwd_p) {
+               *num_pwd_p = num_pwd;
+       }
+
+       return true;
+}
+
 static bool torture_assert_passwd_equal(struct torture_context *tctx,
                                        const struct passwd *p1,
                                        const struct passwd *p2,
@@ -248,6 +403,66 @@ static bool test_nwrap_passwd(struct torture_context *tctx)
        return true;
 }
 
+static bool test_nwrap_passwd_r(struct torture_context *tctx)
+{
+       int i;
+       struct passwd *pwd, pwd1, pwd2;
+       size_t num_pwd;
+
+       torture_assert(tctx, test_nwrap_enum_r_passwd(tctx, &pwd, &num_pwd),
+                                                     "failed to enumerate 
passwd");
+
+       for (i=0; i < num_pwd; i++) {
+               torture_assert(tctx, test_nwrap_getpwnam_r(tctx, 
pwd[i].pw_name, &pwd1),
+                       "failed to call getpwnam_r for enumerated user");
+               torture_assert_passwd_equal(tctx, &pwd[i], &pwd1,
+                       "getpwent_r and getpwnam_r gave different results");
+               torture_assert(tctx, test_nwrap_getpwuid_r(tctx, pwd[i].pw_uid, 
&pwd2),
+                       "failed to call getpwuid_r for enumerated user");
+               torture_assert_passwd_equal(tctx, &pwd[i], &pwd2,
+                       "getpwent_r and getpwuid_r gave different results");
+               torture_assert_passwd_equal(tctx, &pwd1, &pwd2,
+                       "getpwnam_r and getpwuid_r gave different results");
+       }
+
+       return true;
+}
+
+static bool test_nwrap_passwd_r_cross(struct torture_context *tctx)
+{
+       int i;
+       struct passwd *pwd, pwd1, pwd2, pwd3, pwd4;
+       size_t num_pwd;
+
+       torture_assert(tctx, test_nwrap_enum_r_passwd(tctx, &pwd, &num_pwd),
+                                                     "failed to enumerate 
passwd");
+
+       for (i=0; i < num_pwd; i++) {
+               torture_assert(tctx, test_nwrap_getpwnam_r(tctx, 
pwd[i].pw_name, &pwd1),
+                       "failed to call getpwnam_r for enumerated user");
+               torture_assert_passwd_equal(tctx, &pwd[i], &pwd1,
+                       "getpwent_r and getpwnam_r gave different results");
+               torture_assert(tctx, test_nwrap_getpwuid_r(tctx, pwd[i].pw_uid, 
&pwd2),
+                       "failed to call getpwuid_r for enumerated user");
+               torture_assert_passwd_equal(tctx, &pwd[i], &pwd2,
+                       "getpwent_r and getpwuid_r gave different results");
+               torture_assert_passwd_equal(tctx, &pwd1, &pwd2,
+                       "getpwnam_r and getpwuid_r gave different results");
+               torture_assert(tctx, test_nwrap_getpwnam(tctx, pwd[i].pw_name, 
&pwd3),
+                       "failed to call getpwnam for enumerated user");
+               torture_assert_passwd_equal(tctx, &pwd[i], &pwd3,
+                       "getpwent_r and getpwnam gave different results");
+               torture_assert(tctx, test_nwrap_getpwuid(tctx, pwd[i].pw_uid, 
&pwd4),
+                       "failed to call getpwuid for enumerated user");
+               torture_assert_passwd_equal(tctx, &pwd[i], &pwd4,
+                       "getpwent_r and getpwuid gave different results");
+               torture_assert_passwd_equal(tctx, &pwd3, &pwd4,
+                       "getpwnam and getpwuid gave different results");
+       }
+
+       return true;
+}
+
 static bool test_nwrap_enum_group(struct torture_context *tctx,
                                  struct group **grp_array_p,
                                  size_t *num_grp_p)
@@ -284,6 +499,51 @@ static bool test_nwrap_enum_group(struct torture_context 
*tctx,
        return true;
 }
 
+static bool test_nwrap_enum_r_group(struct torture_context *tctx,
+                                   struct group **grp_array_p,
+                                   size_t *num_grp_p)
+{
+       struct group grp, *grpp;
+       struct group *grp_array = NULL;
+       size_t num_grp = 0;
+       char buffer[4096];
+       int ret;
+
+       torture_comment(tctx, "Testing setgrent\n");
+       setgrent();
+
+       while (1) {
+               torture_comment(tctx, "Testing getgrent_r\n");
+
+               ret = getgrent_r(&grp, buffer, sizeof(buffer), &grpp);
+               if (ret != 0) {
+                       if (ret != ENOENT) {
+                               torture_comment(tctx, "got %d return code\n", 
ret);
+                       }
+                       break;
+               }
+               print_group(&grp);
+               if (grp_array_p && num_grp_p) {
+                       grp_array = talloc_realloc(tctx, grp_array, struct 
group, num_grp+1);
+                       torture_assert(tctx, grp_array, "out of memory");
+                       copy_group(tctx, &grp, &grp_array[num_grp]);
+                       num_grp++;
+               }
+       }
+
+       torture_comment(tctx, "Testing endgrent\n");
+       endgrent();
+
+       if (grp_array_p) {
+               *grp_array_p = grp_array;
+       }
+       if (num_grp_p) {
+               *num_grp_p = num_grp;
+       }
+
+       return true;
+}
+
 static bool torture_assert_group_equal(struct torture_context *tctx,
                                       const struct group *g1,
                                       const struct group *g2,
@@ -334,6 +594,66 @@ static bool test_nwrap_group(struct torture_context *tctx)
        return true;
 }
 
+static bool test_nwrap_group_r(struct torture_context *tctx)
+{
+       int i;
+       struct group *grp, grp1, grp2;
+       size_t num_grp;
+
+       torture_assert(tctx, test_nwrap_enum_r_group(tctx, &grp, &num_grp),
+                                                    "failed to enumerate 
group");
+
+       for (i=0; i < num_grp; i++) {
+               torture_assert(tctx, test_nwrap_getgrnam_r(tctx, 
grp[i].gr_name, &grp1),
+                       "failed to call getgrnam_r for enumerated user");
+               torture_assert_group_equal(tctx, &grp[i], &grp1,
+                       "getgrent_r and getgrnam_r gave different results");
+               torture_assert(tctx, test_nwrap_getgrgid_r(tctx, grp[i].gr_gid, 
&grp2),
+                       "failed to call getgrgid_r for enumerated user");
+               torture_assert_group_equal(tctx, &grp[i], &grp2,
+                       "getgrent_r and getgrgid_r gave different results");
+               torture_assert_group_equal(tctx, &grp1, &grp2,
+                       "getgrnam_r and getgrgid_r gave different results");
+       }
+
+       return true;
+}
+
+static bool test_nwrap_group_r_cross(struct torture_context *tctx)
+{
+       int i;
+       struct group *grp, grp1, grp2, grp3, grp4;
+       size_t num_grp;
+
+       torture_assert(tctx, test_nwrap_enum_r_group(tctx, &grp, &num_grp),
+                                                    "failed to enumerate 
group");
+
+       for (i=0; i < num_grp; i++) {
+               torture_assert(tctx, test_nwrap_getgrnam_r(tctx, 
grp[i].gr_name, &grp1),
+                       "failed to call getgrnam_r for enumerated user");
+               torture_assert_group_equal(tctx, &grp[i], &grp1,
+                       "getgrent_r and getgrnam_r gave different results");
+               torture_assert(tctx, test_nwrap_getgrgid_r(tctx, grp[i].gr_gid, 
&grp2),
+                       "failed to call getgrgid_r for enumerated user");
+               torture_assert_group_equal(tctx, &grp[i], &grp2,
+                       "getgrent_r and getgrgid_r gave different results");
+               torture_assert_group_equal(tctx, &grp1, &grp2,
+                       "getgrnam_r and getgrgid_r gave different results");
+               torture_assert(tctx, test_nwrap_getgrnam(tctx, grp[i].gr_name, 
&grp3),
+                       "failed to call getgrnam for enumerated user");
+               torture_assert_group_equal(tctx, &grp[i], &grp3,
+                       "getgrent_r and getgrnam gave different results");
+               torture_assert(tctx, test_nwrap_getgrgid(tctx, grp[i].gr_gid, 
&grp4),
+                       "failed to call getgrgid for enumerated user");
+               torture_assert_group_equal(tctx, &grp[i], &grp4,
+                       "getgrent_r and getgrgid gave different results");
+               torture_assert_group_equal(tctx, &grp3, &grp4,
+                       "getgrnam and getgrgid gave different results");
+       }
+
+       return true;
+}
+
 static bool test_nwrap_getgrouplist(struct torture_context *tctx,
                                    const char *user,
                                    gid_t gid,
@@ -489,11 +809,53 @@ static bool test_nwrap_enumeration(struct torture_context 
*tctx)
        return true;
 }
 
+static bool test_nwrap_reentrant_enumeration(struct torture_context *tctx)
+{
+       const char *old_pwd = getenv("NSS_WRAPPER_PASSWD");
+       const char *old_group = getenv("NSS_WRAPPER_GROUP");
+
+       if (!old_pwd || !old_group) {
+               torture_skip(tctx, "nothing to test\n");
+               return true;
+       }
+
+       torture_comment(tctx, "Testing re-entrant calls\n");
+
+       torture_assert(tctx, test_nwrap_passwd_r(tctx),
+                       "failed to test users");
+       torture_assert(tctx, test_nwrap_group_r(tctx),
+                       "failed to test groups");
+
+       return true;
+}
+
+static bool test_nwrap_reentrant_enumeration_crosschecks(struct 
torture_context *tctx)
+{
+       const char *old_pwd = getenv("NSS_WRAPPER_PASSWD");
+       const char *old_group = getenv("NSS_WRAPPER_GROUP");
+
+       if (!old_pwd || !old_group) {
+               torture_skip(tctx, "nothing to test\n");
+               return true;
+       }
+
+       torture_comment(tctx, "Testing re-entrant calls with cross checks\n");
+
+       torture_assert(tctx, test_nwrap_passwd_r_cross(tctx),
+                       "failed to test users");
+       torture_assert(tctx, test_nwrap_group_r_cross(tctx),
+                       "failed to test groups");
+
+       return true;
+}
+
 struct torture_suite *torture_local_nss_wrapper(TALLOC_CTX *mem_ctx)
 {
        struct torture_suite *suite = torture_suite_create(mem_ctx, 
"NSS-WRAPPER");
 
        torture_suite_add_simple_test(suite, "enumeration", 
test_nwrap_enumeration);
+       torture_suite_add_simple_test(suite, "reentrant enumeration", 
test_nwrap_reentrant_enumeration);
+       torture_suite_add_simple_test(suite, "reentrant enumeration 
crosschecks", test_nwrap_reentrant_enumeration_crosschecks);
        torture_suite_add_simple_test(suite, "membership", 
test_nwrap_membership);
 
        return suite;


-- 
Samba Shared Repository

Reply via email to