[SCM] Samba Shared Repository - branch master updated - release-4-0-0alpha7-1911-g2be289c

Günther Deschner gd at samba.org
Fri May 29 23:47:28 GMT 2009


The branch, master has been updated
       via  2be289c68da3a200dbeda2b8c00e74e4d8318693 (commit)
       via  62d1cd63758dea634defb4dc728febd247e49acd (commit)
      from  8db4917290a2a69b7e0179649a37777d11e72f9d (commit)

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


- Log -----------------------------------------------------------------
commit 2be289c68da3a200dbeda2b8c00e74e4d8318693
Author: Günther Deschner <gd at samba.org>
Date:   Fri May 29 09:21:11 2009 +0200

    nss_wrapper: add test_nwrap_membership to testsuite.
    
    Guenther

commit 62d1cd63758dea634defb4dc728febd247e49acd
Author: Günther Deschner <gd at samba.org>
Date:   Fri May 29 22:37:07 2009 +0200

    nss_wrapper: restructure parts of the testsuite.
    
    Guenther

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

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


Changeset truncated at 500 lines:

diff --git a/lib/nss_wrapper/testsuite.c b/lib/nss_wrapper/testsuite.c
index 2a9cfaa..4f37354 100644
--- a/lib/nss_wrapper/testsuite.c
+++ b/lib/nss_wrapper/testsuite.c
@@ -116,81 +116,193 @@ static bool test_nwrap_getgrgid(struct torture_context *tctx,
 	return grp ? true : false;
 }
 
-
-static bool test_nwrap_passwd(struct torture_context *tctx)
+static bool test_nwrap_enum_passwd(struct torture_context *tctx,
+				   struct passwd **pwd_array_p,
+				   size_t *num_pwd_p)
 {
 	struct passwd *pwd;
-	const char **names = NULL;
-	uid_t *uids = NULL;
-	int num_names = 0;
-	size_t num_uids = 0;
-	int i;
+	struct passwd *pwd_array = NULL;
+	size_t num_pwd = 0;
 
 	torture_comment(tctx, "Testing setpwent\n");
 	setpwent();
 
-	while ((pwd = getpwent())) {
+	while ((pwd = getpwent()) != NULL) {
 		torture_comment(tctx, "Testing getpwent\n");
 
-		if (pwd) {
-			print_passwd(pwd);
-			add_string_to_array(tctx, pwd->pw_name, &names, &num_names);
-			add_uid_to_array_unique(tctx, pwd->pw_uid, &uids, &num_uids);
+		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");
+			pwd_array[num_pwd].pw_name = talloc_strdup(tctx, pwd->pw_name);
+			pwd_array[num_pwd].pw_uid = pwd->pw_uid;
+			pwd_array[num_pwd].pw_gid = pwd->pw_gid;
+			num_pwd++;
 		}
 	}
 
 	torture_comment(tctx, "Testing endpwent\n");
 	endpwent();
 
-	torture_assert_int_equal(tctx, num_names, num_uids, "invalid results");
+	if (pwd_array_p) {
+		*pwd_array_p = pwd_array;
+	}
+	if (num_pwd_p) {
+		*num_pwd_p = num_pwd;
+	}
+
+	return true;
+}
 
-	for (i=0; i < num_names; i++) {
-		torture_assert(tctx, test_nwrap_getpwnam(tctx, names[i]),
+static bool test_nwrap_passwd(struct torture_context *tctx)
+{
+	int i;
+	struct passwd *pwd;
+	size_t num_pwd;
+
+	torture_assert(tctx, test_nwrap_enum_passwd(tctx, &pwd, &num_pwd),
+						    "failed to enumerate passwd");
+
+	for (i=0; i < num_pwd; i++) {
+		torture_assert(tctx, test_nwrap_getpwnam(tctx, pwd[i].pw_name),
 			"failed to call getpwnam for enumerated user");
-		torture_assert(tctx, test_nwrap_getpwuid(tctx, uids[i]),
+		torture_assert(tctx, test_nwrap_getpwuid(tctx, pwd[i].pw_uid),
 			"failed to call getpwuid for enumerated user");
 	}
 
 	return true;
 }
 
-static bool test_nwrap_group(struct torture_context *tctx)
+static bool test_nwrap_enum_group(struct torture_context *tctx,
+				  struct group **grp_array_p,
+				  size_t *num_grp_p)
 {
 	struct group *grp;
-	const char **names = NULL;
-	gid_t *gids = NULL;
-	int num_names = 0;
-	size_t num_gids = 0;
-	int i;
+	struct group *grp_array = NULL;
+	size_t num_grp = 0;
 
 	torture_comment(tctx, "Testing setgrent\n");
 	setgrent();
 
-	do {
+	while ((grp = getgrent()) != NULL) {
 		torture_comment(tctx, "Testing getgrent\n");
-		grp = getgrent();
-		if (grp) {
-			print_group(grp);
-			add_string_to_array(tctx, grp->gr_name, &names, &num_names);
-			add_gid_to_array_unique(tctx, grp->gr_gid, &gids, &num_gids);
+
+		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");
+			grp_array[num_grp].gr_name = talloc_strdup(tctx, grp->gr_name);
+			grp_array[num_grp].gr_gid = grp->gr_gid;
+			num_grp++;
 		}
-	} while (grp);
+	}
 
 	torture_comment(tctx, "Testing endgrent\n");
 	endgrent();
 
-	torture_assert_int_equal(tctx, num_names, num_gids, "invalid results");
+	if (grp_array_p) {
+		*grp_array_p = grp_array;
+	}
+	if (num_grp_p) {
+		*num_grp_p = num_grp;
+	}
+
+
+	return true;
+}
 
-	for (i=0; i < num_names; i++) {
-		torture_assert(tctx, test_nwrap_getgrnam(tctx, names[i]),
+static bool test_nwrap_group(struct torture_context *tctx)
+{
+	int i;
+	struct group *grp;
+	size_t num_grp;
+
+	torture_assert(tctx, test_nwrap_enum_group(tctx, &grp, &num_grp),
+						   "failed to enumerate group");
+
+	for (i=0; i < num_grp; i++) {
+		torture_assert(tctx, test_nwrap_getgrnam(tctx, grp[i].gr_name),
 			"failed to call getgrnam for enumerated user");
-		torture_assert(tctx, test_nwrap_getgrgid(tctx, gids[i]),
+		torture_assert(tctx, test_nwrap_getgrgid(tctx, grp[i].gr_gid),
 			"failed to call getgrgid for enumerated user");
 	}
 
 	return true;
 }
 
+static bool test_nwrap_getgrouplist(struct torture_context *tctx,
+				    const char *user,
+				    gid_t gid,
+				    gid_t **gids_p,
+				    int *num_gids_p)
+{
+	int ret;
+	int num_groups = 0;
+	gid_t *groups = NULL;
+
+	torture_comment(tctx, "Testing getgrouplist: %s\n", user);
+
+	ret = getgrouplist(user, gid, NULL, &num_groups);
+	if (ret == -1 || num_groups != 0) {
+
+		groups = talloc_array(tctx, gid_t, num_groups);
+		torture_assert(tctx, groups, "out of memory\n");
+
+		ret = getgrouplist(user, gid, groups, &num_groups);
+	}
+
+	torture_assert(tctx, (ret != -1), "failed to call getgrouplist");
+
+	torture_comment(tctx, "%s is member in %d groups\n", user, num_groups);
+
+	if (gids_p) {
+		*gids_p = groups;
+	}
+	if (num_gids_p) {
+		*num_gids_p = num_groups;
+	}
+
+	return true;
+}
+
+static bool test_nwrap_membership(struct torture_context *tctx)
+{
+	const char *old_pwd = getenv("NSS_WRAPPER_PASSWD");
+	const char *old_group = getenv("NSS_WRAPPER_GROUP");
+	struct passwd *pwd;
+	size_t num_pwd;
+	int i;
+
+	if (!old_pwd || !old_group) {
+		torture_skip(tctx, "nothing to test\n");
+		return true;
+	}
+
+	torture_assert(tctx, test_nwrap_enum_passwd(tctx, &pwd, &num_pwd),
+						    "failed to enumerate passwd");
+
+	for (i=0; i < num_pwd; i++) {
+
+		int num_user_groups = 0;
+		gid_t *user_groups = NULL;
+		int g;
+
+		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;
+}
+
 static bool test_nwrap_env(struct torture_context *tctx)
 {
 	const char *old_pwd = getenv("NSS_WRAPPER_PASSWD");
@@ -214,6 +326,7 @@ 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, "env", test_nwrap_env);
+	torture_suite_add_simple_test(suite, "membership", test_nwrap_membership);
 
 	return suite;
 }


-- 
Samba Shared Repository


More information about the samba-cvs mailing list