[SCM] Samba Shared Repository - branch master updated -
release-4-0-0alpha7-1889-g7b8d30d
Günther Deschner
gd at samba.org
Fri May 29 12:16:09 GMT 2009
The branch, master has been updated
via 7b8d30d1bb6403183dceaaff987a8a96700bb942 (commit)
via 36fc0b961f32d6fd978f293731a5e2cb01a6154f (commit)
via bff54b90c353920ba058cc53a6cc0464f0939424 (commit)
from 12496ea5aba3a53691ca74f12192f489d7831592 (commit)
http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master
- Log -----------------------------------------------------------------
commit 7b8d30d1bb6403183dceaaff987a8a96700bb942
Author: Günther Deschner <gd at samba.org>
Date: Thu May 28 16:14:18 2009 +0200
s3-selftest: enable LOCAL-NSS-WRAPPER test against samba 3.
Guenther
commit 36fc0b961f32d6fd978f293731a5e2cb01a6154f
Author: Günther Deschner <gd at samba.org>
Date: Thu May 28 16:13:33 2009 +0200
s4-smbtorture: add a very basic NSS-WRAPPER testsuite.
Guenther
commit bff54b90c353920ba058cc53a6cc0464f0939424
Author: Günther Deschner <gd at samba.org>
Date: Thu May 28 16:08:04 2009 +0200
util: move add_gid_to_array_unique to toplevel and add add_uid_to_array_unique.
Guenther
-----------------------------------------------------------------------
Summary of changes:
lib/nss_wrapper/testsuite.c | 219 +++++++++++++++++++++++++++++++++
lib/util/config.mk | 3 +-
lib/util/util.h | 12 ++
lib/util/util_id.c | 88 +++++++++++++
source3/Makefile.in | 2 +-
source3/include/proto.h | 2 -
source3/lib/util.c | 33 -----
source3/passdb/pdb_interface.c | 20 ---
source3/script/tests/test_posix_s3.sh | 4 +-
source4/torture/local/config.mk | 4 +-
source4/torture/local/local.c | 1 +
11 files changed, 329 insertions(+), 59 deletions(-)
create mode 100644 lib/nss_wrapper/testsuite.c
create mode 100644 lib/util/util_id.c
Changeset truncated at 500 lines:
diff --git a/lib/nss_wrapper/testsuite.c b/lib/nss_wrapper/testsuite.c
new file mode 100644
index 0000000..2a9cfaa
--- /dev/null
+++ b/lib/nss_wrapper/testsuite.c
@@ -0,0 +1,219 @@
+/*
+ Unix SMB/CIFS implementation.
+
+ local testing of the nss wrapper
+
+ Copyright (C) Guenther Deschner 2009
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "includes.h"
+#include "torture/torture.h"
+#include "lib/replace/system/passwd.h"
+#include "lib/nss_wrapper/nss_wrapper.h"
+
+static void print_passwd(struct passwd *pwd)
+{
+ printf("%s:%s:%lu:%lu:%s:%s:%s\n",
+ pwd->pw_name,
+ pwd->pw_passwd,
+ (unsigned long)pwd->pw_uid,
+ (unsigned long)pwd->pw_gid,
+ pwd->pw_gecos,
+ pwd->pw_dir,
+ pwd->pw_shell);
+}
+
+
+static bool test_nwrap_getpwnam(struct torture_context *tctx,
+ const char *name)
+{
+ struct passwd *pwd;
+
+ torture_comment(tctx, "Testing getpwnam: %s\n", name);
+
+ pwd = getpwnam(name);
+ if (pwd) {
+ print_passwd(pwd);
+ }
+
+ return pwd ? true : false;
+}
+
+static bool test_nwrap_getpwuid(struct torture_context *tctx,
+ uid_t uid)
+{
+ struct passwd *pwd;
+
+ torture_comment(tctx, "Testing getpwuid: %lu\n", (unsigned long)uid);
+
+ pwd = getpwuid(uid);
+ if (pwd) {
+ print_passwd(pwd);
+ }
+
+ return pwd ? true : false;
+}
+
+static void print_group(struct group *grp)
+{
+ int i;
+ printf("%s:%s:%lu:",
+ grp->gr_name,
+ grp->gr_passwd,
+ (unsigned long)grp->gr_gid);
+
+ if (!grp->gr_mem[0]) {
+ printf("\n");
+ return;
+ }
+
+ for (i=0; grp->gr_mem[i+1]; i++) {
+ printf("%s,", grp->gr_mem[i]);
+ }
+ printf("%s\n", grp->gr_mem[i]);
+}
+
+static bool test_nwrap_getgrnam(struct torture_context *tctx,
+ const char *name)
+{
+ struct group *grp;
+
+ torture_comment(tctx, "Testing getgrnam: %s\n", name);
+
+ grp = getgrnam(name);
+ if (grp) {
+ print_group(grp);
+ }
+
+ return grp ? true : false;
+}
+
+static bool test_nwrap_getgrgid(struct torture_context *tctx,
+ gid_t gid)
+{
+ struct group *grp;
+
+ torture_comment(tctx, "Testing getgrgid: %lu\n", (unsigned long)gid);
+
+ grp = getgrgid(gid);
+ if (grp) {
+ print_group(grp);
+ }
+
+ return grp ? true : false;
+}
+
+
+static bool test_nwrap_passwd(struct torture_context *tctx)
+{
+ struct passwd *pwd;
+ const char **names = NULL;
+ uid_t *uids = NULL;
+ int num_names = 0;
+ size_t num_uids = 0;
+ int i;
+
+ torture_comment(tctx, "Testing setpwent\n");
+ setpwent();
+
+ while ((pwd = getpwent())) {
+ 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);
+ }
+ }
+
+ torture_comment(tctx, "Testing endpwent\n");
+ endpwent();
+
+ torture_assert_int_equal(tctx, num_names, num_uids, "invalid results");
+
+ for (i=0; i < num_names; i++) {
+ torture_assert(tctx, test_nwrap_getpwnam(tctx, names[i]),
+ "failed to call getpwnam for enumerated user");
+ torture_assert(tctx, test_nwrap_getpwuid(tctx, uids[i]),
+ "failed to call getpwuid for enumerated user");
+ }
+
+ return true;
+}
+
+static bool test_nwrap_group(struct torture_context *tctx)
+{
+ struct group *grp;
+ const char **names = NULL;
+ gid_t *gids = NULL;
+ int num_names = 0;
+ size_t num_gids = 0;
+ int i;
+
+ torture_comment(tctx, "Testing setgrent\n");
+ setgrent();
+
+ do {
+ 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);
+ }
+ } while (grp);
+
+ torture_comment(tctx, "Testing endgrent\n");
+ endgrent();
+
+ torture_assert_int_equal(tctx, num_names, num_gids, "invalid results");
+
+ for (i=0; i < num_names; i++) {
+ torture_assert(tctx, test_nwrap_getgrnam(tctx, names[i]),
+ "failed to call getgrnam for enumerated user");
+ torture_assert(tctx, test_nwrap_getgrgid(tctx, gids[i]),
+ "failed to call getgrgid for enumerated user");
+ }
+
+ return true;
+}
+
+static bool test_nwrap_env(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_assert(tctx, test_nwrap_passwd(tctx),
+ "failed to test users");
+ torture_assert(tctx, test_nwrap_group(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, "env", test_nwrap_env);
+
+ return suite;
+}
diff --git a/lib/util/config.mk b/lib/util/config.mk
index 1b620d1..3ae8a22 100644
--- a/lib/util/config.mk
+++ b/lib/util/config.mk
@@ -28,7 +28,8 @@ LIBSAMBA-UTIL_OBJ_FILES = $(addprefix $(libutilsrcdir)/, \
rbtree.o \
talloc_stack.o \
smb_threads.o \
- params.o)
+ params.o \
+ util_id.o)
PUBLIC_HEADERS += $(addprefix $(libutilsrcdir)/, util.h \
dlinklist.h \
diff --git a/lib/util/util.h b/lib/util/util.h
index dab5ff9..20050d2 100644
--- a/lib/util/util.h
+++ b/lib/util/util.h
@@ -817,4 +817,16 @@ bool unmap_file(void *start, size_t size);
void print_asc(int level, const uint8_t *buf,int len);
+/**
+ * Add an id to an array of ids.
+ *
+ * num should be a pointer to an integer that holds the current
+ * number of elements in ids. It will be updated by this function.
+ */
+
+bool add_uid_to_array_unique(TALLOC_CTX *mem_ctx, uid_t uid,
+ uid_t **uids, size_t *num_uids);
+bool add_gid_to_array_unique(TALLOC_CTX *mem_ctx, gid_t gid,
+ gid_t **gids, size_t *num_gids);
+
#endif /* _SAMBA_UTIL_H_ */
diff --git a/lib/util/util_id.c b/lib/util/util_id.c
new file mode 100644
index 0000000..8744ce4
--- /dev/null
+++ b/lib/util/util_id.c
@@ -0,0 +1,88 @@
+/*
+ Unix SMB/CIFS implementation.
+
+ Helper routines for uid and gid arrays
+
+ Copyright (C) Guenther Deschner 2009
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 3 of the License, or
+ (at your option) any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "includes.h"
+
+/****************************************************************************
+ Add a gid to an array of gids if it's not already there.
+****************************************************************************/
+
+bool add_gid_to_array_unique(TALLOC_CTX *mem_ctx, gid_t gid,
+ gid_t **gids, size_t *num_gids)
+{
+ int i;
+
+ if ((*num_gids != 0) && (*gids == NULL)) {
+ /*
+ * A former call to this routine has failed to allocate memory
+ */
+ return false;
+ }
+
+ for (i=0; i<*num_gids; i++) {
+ if ((*gids)[i] == gid) {
+ return true;
+ }
+ }
+
+ *gids = talloc_realloc(mem_ctx, *gids, gid_t, *num_gids+1);
+ if (*gids == NULL) {
+ *num_gids = 0;
+ return false;
+ }
+
+ (*gids)[*num_gids] = gid;
+ *num_gids += 1;
+ return true;
+}
+
+/****************************************************************************
+ Add a uid to an array of uids if it's not already there.
+****************************************************************************/
+
+bool add_uid_to_array_unique(TALLOC_CTX *mem_ctx, uid_t uid,
+ uid_t **uids, size_t *num_uids)
+{
+ int i;
+
+ if ((*num_uids != 0) && (*uids == NULL)) {
+ /*
+ * A former call to this routine has failed to allocate memory
+ */
+ return false;
+ }
+
+ for (i=0; i<*num_uids; i++) {
+ if ((*uids)[i] == uid) {
+ return true;
+ }
+ }
+
+ *uids = talloc_realloc(mem_ctx, *uids, uid_t, *num_uids+1);
+ if (*uids == NULL) {
+ *num_uids = 0;
+ return false;
+ }
+
+ (*uids)[*num_uids] = uid;
+ *num_uids += 1;
+ return true;
+}
diff --git a/source3/Makefile.in b/source3/Makefile.in
index c7514a0..72fce60 100644
--- a/source3/Makefile.in
+++ b/source3/Makefile.in
@@ -355,7 +355,7 @@ UTIL_OBJ = ../lib/util/rbtree.o ../lib/util/signal.o ../lib/util/time.o \
../lib/util/genrand.o ../lib/util/util_net.o \
../lib/util/become_daemon.o ../lib/util/system.o \
../lib/util/tevent_unix.o ../lib/util/tevent_ntstatus.o \
- ../lib/util/smb_threads.o
+ ../lib/util/smb_threads.o ../lib/util/util_id.o
CRYPTO_OBJ = ../lib/crypto/crc32.o ../lib/crypto/md5.o \
../lib/crypto/hmacmd5.o ../lib/crypto/arcfour.o \
diff --git a/source3/include/proto.h b/source3/include/proto.h
index 4713bd7..7d297f6 100644
--- a/source3/include/proto.h
+++ b/source3/include/proto.h
@@ -1088,8 +1088,6 @@ struct user_auth_info *get_cmdline_auth_info_copy(TALLOC_CTX *mem_ctx,
const struct user_auth_info *info);
bool set_cmdline_auth_info_machine_account_creds(struct user_auth_info *auth_info);
void set_cmdline_auth_info_getpass(struct user_auth_info *auth_info);
-bool add_gid_to_array_unique(TALLOC_CTX *mem_ctx, gid_t gid,
- gid_t **gids, size_t *num_gids);
bool file_exist_stat(const char *fname,SMB_STRUCT_STAT *sbuf);
bool socket_exist(const char *fname);
bool directory_exist_stat(char *dname,SMB_STRUCT_STAT *st);
diff --git a/source3/lib/util.c b/source3/lib/util.c
index 8e67ede..b85f29e 100644
--- a/source3/lib/util.c
+++ b/source3/lib/util.c
@@ -495,39 +495,6 @@ void set_cmdline_auth_info_getpass(struct user_auth_info *auth_info)
TALLOC_FREE(frame);
}
-/****************************************************************************
- Add a gid to an array of gids if it's not already there.
-****************************************************************************/
-
-bool add_gid_to_array_unique(TALLOC_CTX *mem_ctx, gid_t gid,
- gid_t **gids, size_t *num_gids)
-{
- int i;
-
- if ((*num_gids != 0) && (*gids == NULL)) {
- /*
- * A former call to this routine has failed to allocate memory
- */
- return False;
- }
-
- for (i=0; i<*num_gids; i++) {
- if ((*gids)[i] == gid) {
- return True;
- }
- }
-
- *gids = TALLOC_REALLOC_ARRAY(mem_ctx, *gids, gid_t, *num_gids+1);
- if (*gids == NULL) {
- *num_gids = 0;
- return False;
- }
-
- (*gids)[*num_gids] = gid;
- *num_gids += 1;
- return True;
-}
-
/*******************************************************************
Check if a file exists - call vfs_file_exist for samba files.
********************************************************************/
diff --git a/source3/passdb/pdb_interface.c b/source3/passdb/pdb_interface.c
index b4e1bd4..b69e415 100644
--- a/source3/passdb/pdb_interface.c
+++ b/source3/passdb/pdb_interface.c
@@ -1330,26 +1330,6 @@ static bool pdb_default_sid_to_id(struct pdb_methods *methods,
return ret;
}
-static bool add_uid_to_array_unique(TALLOC_CTX *mem_ctx,
- uid_t uid, uid_t **pp_uids, size_t *p_num)
-{
- size_t i;
-
- for (i=0; i<*p_num; i++) {
- if ((*pp_uids)[i] == uid)
- return True;
- }
-
- *pp_uids = TALLOC_REALLOC_ARRAY(mem_ctx, *pp_uids, uid_t, *p_num+1);
-
- if (*pp_uids == NULL)
- return False;
-
- (*pp_uids)[*p_num] = uid;
- *p_num += 1;
- return True;
-}
-
static bool get_memberuids(TALLOC_CTX *mem_ctx, gid_t gid, uid_t **pp_uids, size_t *p_num)
{
struct group *grp;
diff --git a/source3/script/tests/test_posix_s3.sh b/source3/script/tests/test_posix_s3.sh
index 0bcf369..83593dd 100755
--- a/source3/script/tests/test_posix_s3.sh
+++ b/source3/script/tests/test_posix_s3.sh
@@ -45,12 +45,14 @@ rpc="$rpc RPC-LSA-GETUSER RPC-LSA-LOOKUPSIDS RPC-LSA-LOOKUPNAMES"
rpc="$rpc RPC-SAMR-USERS RPC-SAMR-USERS-PRIVILEGES RPC-SAMR-PASSWORDS RPC-SAMR-PASSWORDS-PWDLASTSET RPC-SAMR-LARGE-DC RPC-JOIN"
rpc="$rpc RPC-SCHANNEL RPC-SCHANNEL2 RPC-BENCH-SCHANNEL1"
+local="LOCAL-NSS-WRAPPER"
+
# NOTE: to enable the UNIX-WHOAMI test, we need to change the default share
# config to allow guest access. I'm not sure whether this would break other
# tests, so leaving it alone for now -- jpeach
unix="UNIX-INFO2"
-tests="$base $raw $rpc $unix"
+tests="$base $raw $rpc $unix $local"
if test "x$POSIX_SUBTESTS" != "x" ; then
tests="$POSIX_SUBTESTS"
diff --git a/source4/torture/local/config.mk b/source4/torture/local/config.mk
index 5c8c1d5..28599e4 100644
--- a/source4/torture/local/config.mk
+++ b/source4/torture/local/config.mk
@@ -17,7 +17,8 @@ PRIVATE_DEPENDENCIES = \
TORTURE_LIBCRYPTO \
share \
torture_registry \
- PROVISION
+ PROVISION \
+ NSS_WRAPPER
# End SUBSYSTEM TORTURE_LOCAL
#################################
@@ -34,6 +35,7 @@ TORTURE_LOCAL_OBJ_FILES = \
$(torturesrcdir)/../../lib/util/tests/idtree.o \
$(torturesrcdir)/../lib/socket/testsuite.o \
$(torturesrcdir)/../../lib/socket_wrapper/testsuite.o \
+ $(torturesrcdir)/../../lib/nss_wrapper/testsuite.o \
$(torturesrcdir)/../libcli/resolve/testsuite.o \
$(torturesrcdir)/../../lib/util/tests/strlist.o \
$(torturesrcdir)/../../lib/util/tests/str.o \
diff --git a/source4/torture/local/local.c b/source4/torture/local/local.c
index a1b100e..73ee366 100644
--- a/source4/torture/local/local.c
--
Samba Shared Repository
More information about the samba-cvs
mailing list