[SCM] Samba Shared Repository - branch master updated -
release-4-0-0alpha7-2023-g8def5cb
Günther Deschner
gd at samba.org
Thu Jun 4 08:39:37 GMT 2009
The branch, master has been updated
via 8def5cb352fbc79c112227375100361124d5ba7a (commit)
via dc9b7056674910f469ba97ad67944a08b388ab6a (commit)
via c49f6b7bc6b7a958123a7821ade1648875d8419e (commit)
via 911624567ab464b8570c1580dae055a5fdc5587a (commit)
from a12b8571fe3da55968715a4c36dd9ea77f13b335 (commit)
http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master
- Log -----------------------------------------------------------------
commit 8def5cb352fbc79c112227375100361124d5ba7a
Author: Günther Deschner <gd at samba.org>
Date: Wed Jun 3 21:09:52 2009 +0200
nss_wrapper: more coherence tests for group membership.
Guenther
commit dc9b7056674910f469ba97ad67944a08b388ab6a
Author: Günther Deschner <gd at samba.org>
Date: Wed Jun 3 14:31:20 2009 +0200
nss_wrapper: add coherency tests for get{gr,pw}{nam,id}.
Guenther
commit c49f6b7bc6b7a958123a7821ade1648875d8419e
Author: Günther Deschner <gd at samba.org>
Date: Tue Jun 2 12:24:43 2009 +0200
nss_wrapper: refactor test_nwrap_membership_user() in testsuite.
Guenther
commit 911624567ab464b8570c1580dae055a5fdc5587a
Author: Günther Deschner <gd at samba.org>
Date: Tue Jun 2 12:20:54 2009 +0200
nss_wrapper: make full talloced copies of struct passwd and group in testsuite.
Guenther
-----------------------------------------------------------------------
Summary of changes:
lib/nss_wrapper/testsuite.c | 218 +++++++++++++++++++++++++++++++++++++------
1 files changed, 189 insertions(+), 29 deletions(-)
Changeset truncated at 500 lines:
diff --git a/lib/nss_wrapper/testsuite.c b/lib/nss_wrapper/testsuite.c
index 4f37354..e3ba5bf 100644
--- a/lib/nss_wrapper/testsuite.c
+++ b/lib/nss_wrapper/testsuite.c
@@ -24,6 +24,21 @@
#include "lib/replace/system/passwd.h"
#include "lib/nss_wrapper/nss_wrapper.h"
+static bool copy_passwd(struct torture_context *tctx,
+ const struct passwd *pwd,
+ struct passwd *p)
+{
+ p->pw_name = talloc_strdup(tctx, pwd->pw_name);
+ p->pw_passwd = talloc_strdup(tctx, pwd->pw_passwd);
+ p->pw_uid = pwd->pw_uid;
+ p->pw_gid = pwd->pw_gid;
+ p->pw_gecos = talloc_strdup(tctx, pwd->pw_gecos);
+ p->pw_dir = talloc_strdup(tctx, pwd->pw_dir);
+ p->pw_shell = talloc_strdup(tctx, pwd->pw_shell);
+
+ return true;
+}
+
static void print_passwd(struct passwd *pwd)
{
printf("%s:%s:%lu:%lu:%s:%s:%s\n",
@@ -38,7 +53,8 @@ static void print_passwd(struct passwd *pwd)
static bool test_nwrap_getpwnam(struct torture_context *tctx,
- const char *name)
+ const char *name,
+ struct passwd *pwd_p)
{
struct passwd *pwd;
@@ -49,11 +65,16 @@ static bool test_nwrap_getpwnam(struct torture_context *tctx,
print_passwd(pwd);
}
+ if (pwd_p) {
+ copy_passwd(tctx, pwd, pwd_p);
+ }
+
return pwd ? true : false;
}
static bool test_nwrap_getpwuid(struct torture_context *tctx,
- uid_t uid)
+ uid_t uid,
+ struct passwd *pwd_p)
{
struct passwd *pwd;
@@ -64,9 +85,33 @@ static bool test_nwrap_getpwuid(struct torture_context *tctx,
print_passwd(pwd);
}
+ if (pwd_p) {
+ copy_passwd(tctx, pwd, pwd_p);
+ }
+
return pwd ? true : false;
}
+static bool copy_group(struct torture_context *tctx,
+ const struct group *grp,
+ struct group *g)
+{
+ int i;
+
+ g->gr_name = talloc_strdup(tctx, grp->gr_name);
+ g->gr_passwd = talloc_strdup(tctx, grp->gr_passwd);
+ g->gr_gid = grp->gr_gid;
+ g->gr_mem = NULL;
+
+ for (i=0; grp->gr_mem && grp->gr_mem[i]; i++) {
+ g->gr_mem = talloc_realloc(tctx, g->gr_mem, char *, i + 2);
+ g->gr_mem[i] = talloc_strdup(g->gr_mem, grp->gr_mem[i]);
+ g->gr_mem[i+1] = NULL;
+ }
+
+ return true;
+}
+
static void print_group(struct group *grp)
{
int i;
@@ -87,7 +132,8 @@ static void print_group(struct group *grp)
}
static bool test_nwrap_getgrnam(struct torture_context *tctx,
- const char *name)
+ const char *name,
+ struct group *grp_p)
{
struct group *grp;
@@ -98,11 +144,16 @@ static bool test_nwrap_getgrnam(struct torture_context *tctx,
print_group(grp);
}
+ if (grp_p) {
+ copy_group(tctx, grp, grp_p);
+ }
+
return grp ? true : false;
}
static bool test_nwrap_getgrgid(struct torture_context *tctx,
- gid_t gid)
+ gid_t gid,
+ struct group *grp_p)
{
struct group *grp;
@@ -113,6 +164,10 @@ static bool test_nwrap_getgrgid(struct torture_context *tctx,
print_group(grp);
}
+ if (grp_p) {
+ copy_group(tctx, grp, grp_p);
+ }
+
return grp ? true : false;
}
@@ -134,9 +189,7 @@ static bool test_nwrap_enum_passwd(struct torture_context *tctx,
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;
+ copy_passwd(tctx, pwd, &pwd_array[num_pwd]);
num_pwd++;
}
}
@@ -154,20 +207,38 @@ static bool test_nwrap_enum_passwd(struct torture_context *tctx,
return true;
}
+static bool torture_assert_passwd_equal(struct torture_context *tctx,
+ const struct passwd *p1,
+ const struct passwd *p2,
+ const char *comment)
+{
+ torture_assert_str_equal(tctx, p1->pw_name, p2->pw_name, comment);
+ torture_assert_str_equal(tctx, p1->pw_passwd, p2->pw_passwd, comment);
+ torture_assert_int_equal(tctx, p1->pw_uid, p2->pw_uid, comment);
+ torture_assert_int_equal(tctx, p1->pw_gid, p2->pw_gid, comment);
+ torture_assert_str_equal(tctx, p1->pw_gecos, p2->pw_gecos, comment);
+ torture_assert_str_equal(tctx, p1->pw_dir, p2->pw_dir, comment);
+ torture_assert_str_equal(tctx, p1->pw_shell, p2->pw_shell, comment);
+
+ return true;
+}
+
static bool test_nwrap_passwd(struct torture_context *tctx)
{
int i;
- struct passwd *pwd;
+ struct passwd *pwd, pwd1, pwd2;
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),
+ torture_assert(tctx, test_nwrap_getpwnam(tctx, pwd[i].pw_name, &pwd1),
"failed to call getpwnam for enumerated user");
- torture_assert(tctx, test_nwrap_getpwuid(tctx, pwd[i].pw_uid),
+ torture_assert(tctx, test_nwrap_getpwuid(tctx, pwd[i].pw_uid, &pwd2),
"failed to call getpwuid for enumerated user");
+ torture_assert_passwd_equal(tctx, &pwd1, &pwd2,
+ "getpwnam and getpwuid gave different results");
}
return true;
@@ -191,8 +262,7 @@ static bool test_nwrap_enum_group(struct torture_context *tctx,
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;
+ copy_group(tctx, grp, &grp_array[num_grp]);
num_grp++;
}
}
@@ -207,6 +277,30 @@ static bool test_nwrap_enum_group(struct torture_context *tctx,
*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,
+ const char *comment)
+{
+ int i;
+ torture_assert_str_equal(tctx, g1->gr_name, g2->gr_name, comment);
+ torture_assert_str_equal(tctx, g1->gr_passwd, g2->gr_passwd, comment);
+ torture_assert_int_equal(tctx, g1->gr_gid, g2->gr_gid, comment);
+ if (g1->gr_mem && !g2->gr_mem) {
+ return false;
+ }
+ if (!g1->gr_mem && g2->gr_mem) {
+ return false;
+ }
+ if (!g1->gr_mem && !g2->gr_mem) {
+ return true;
+ }
+ for (i=0; g1->gr_mem[i] && g2->gr_mem[i]; i++) {
+ torture_assert_str_equal(tctx, g1->gr_mem[i], g2->gr_mem[i], comment);
+ }
return true;
}
@@ -214,17 +308,19 @@ static bool test_nwrap_enum_group(struct torture_context *tctx,
static bool test_nwrap_group(struct torture_context *tctx)
{
int i;
- struct group *grp;
+ struct group *grp, grp1, grp2;
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),
+ torture_assert(tctx, test_nwrap_getgrnam(tctx, grp[i].gr_name, &grp1),
"failed to call getgrnam for enumerated user");
- torture_assert(tctx, test_nwrap_getgrgid(tctx, grp[i].gr_gid),
+ torture_assert(tctx, test_nwrap_getgrgid(tctx, grp[i].gr_gid, &grp2),
"failed to call getgrgid for enumerated user");
+ torture_assert_group_equal(tctx, &grp1, &grp2,
+ "getgrnam and getgrgid gave different results");
}
return true;
@@ -265,12 +361,86 @@ static bool test_nwrap_getgrouplist(struct torture_context *tctx,
return true;
}
+static bool test_nwrap_user_in_group(struct torture_context *tctx,
+ const struct passwd *pwd,
+ const struct group *grp)
+{
+ int i;
+
+ for (i=0; grp->gr_mem && grp->gr_mem[i] != NULL; i++) {
+ if (strequal(grp->gr_mem[i], pwd->pw_name)) {
+ return true;
+ }
+ }
+
+ return false;
+}
+
+static bool test_nwrap_membership_user(struct torture_context *tctx,
+ const struct passwd *pwd,
+ struct group *grp_array,
+ size_t num_grp)
+{
+ int num_user_groups = 0;
+ int num_user_groups_from_enum = 0;
+ gid_t *user_groups = NULL;
+ int g, i;
+ bool primary_group_had_user_member = false;
+
+ 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], NULL),
+ "failed to find the group the user is a member of");
+ }
+
+
+ for (i=0; i < num_grp; i++) {
+
+ struct group grp = grp_array[i];
+
+ if (test_nwrap_user_in_group(tctx, pwd, &grp)) {
+
+ struct group current_grp;
+ num_user_groups_from_enum++;
+
+ torture_assert(tctx, test_nwrap_getgrnam(tctx, grp.gr_name, ¤t_grp),
+ "failed to find the group the user is a member of");
+
+ if (current_grp.gr_gid == pwd->pw_gid) {
+ torture_comment(tctx, "primary group %s of user %s lists user as member\n",
+ current_grp.gr_name,
+ pwd->pw_name);
+ primary_group_had_user_member = true;
+ }
+
+ continue;
+ }
+ }
+
+ if (!primary_group_had_user_member) {
+ num_user_groups_from_enum++;
+ }
+
+ torture_assert_int_equal(tctx, num_user_groups, num_user_groups_from_enum,
+ "getgrouplist and real inspection of grouplist gave different results\n");
+
+ 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;
+ struct group *grp;
+ size_t num_grp;
int i;
if (!old_pwd || !old_group) {
@@ -280,24 +450,14 @@ static bool test_nwrap_membership(struct torture_context *tctx)
torture_assert(tctx, test_nwrap_enum_passwd(tctx, &pwd, &num_pwd),
"failed to enumerate passwd");
+ torture_assert(tctx, test_nwrap_enum_group(tctx, &grp, &num_grp),
+ "failed to enumerate group");
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], grp, num_grp),
+ "failed 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;
--
Samba Shared Repository
More information about the samba-cvs
mailing list