nss_wrapper: refactor test_nwrap_membership_user() in testsuite.
authorGünther Deschner <gd@samba.org>
Tue, 2 Jun 2009 10:24:43 +0000 (12:24 +0200)
committerGünther Deschner <gd@samba.org>
Thu, 4 Jun 2009 08:30:44 +0000 (10:30 +0200)
Guenther

lib/nss_wrapper/testsuite.c

index d63e7363ca3adf53384b93aee7359ef3dd2f532d..a98c141e3e53e3559ed6afa0fc64f32e168d59d0 100644 (file)
@@ -297,6 +297,28 @@ static bool test_nwrap_getgrouplist(struct torture_context *tctx,
        return true;
 }
 
+static bool test_nwrap_membership_user(struct torture_context *tctx,
+                                      const struct passwd *pwd)
+{
+       int num_user_groups = 0;
+       gid_t *user_groups = NULL;
+       int g;
+
+       torture_assert(tctx, test_nwrap_getgrouplist(tctx,
+                                                    pwd->pw_name,
+                                                    pwd->pw_gid,
+                                                    &user_groups,
+                                                    &num_user_groups),
+                                                    "failed to test getgrouplist");
+
+       for (g=0; g < num_user_groups; g++) {
+               torture_assert(tctx, test_nwrap_getgrgid(tctx, user_groups[g]),
+                       "failed to find the group the user is a member of");
+       }
+
+       return true;
+}
+
 static bool test_nwrap_membership(struct torture_context *tctx)
 {
        const char *old_pwd = getenv("NSS_WRAPPER_PASSWD");
@@ -315,21 +337,9 @@ static bool test_nwrap_membership(struct torture_context *tctx)
 
        for (i=0; i < num_pwd; i++) {
 
-               int num_user_groups = 0;
-               gid_t *user_groups = NULL;
-               int g;
+               torture_assert(tctx, test_nwrap_membership_user(tctx, &pwd[i]),
+                       "failde to test membership for user");
 
-               torture_assert(tctx, test_nwrap_getgrouplist(tctx,
-                                                            pwd[i].pw_name,
-                                                            pwd[i].pw_gid,
-                                                            &user_groups,
-                                                            &num_user_groups),
-                                                            "failed to test getgrouplist");
-
-               for (g=0; g < num_user_groups; g++) {
-                       torture_assert(tctx, test_nwrap_getgrgid(tctx, user_groups[g]),
-                               "failed to find the group the user is a member of");
-               }
        }
 
        return true;