[PATCH 2/6] s4: Create torture test for samba utils.
Matthieu Patou
mat at matws.net
Sat Nov 7 03:19:19 MST 2009
Currently tested: getntacl / setntacl
---
.gitignore | 1 +
source4/torture/config.mk | 18 +++++
source4/torture/torture.c | 1 +
source4/torture/utils/acls.c | 149 +++++++++++++++++++++++++++++++++++++++++
source4/torture/utils/utils.c | 38 +++++++++++
5 files changed, 207 insertions(+), 0 deletions(-)
create mode 100644 source4/torture/utils/acls.c
create mode 100644 source4/torture/utils/utils.c
diff --git a/.gitignore b/.gitignore
index 13dd2d8..2660940 100644
--- a/.gitignore
+++ b/.gitignore
@@ -282,6 +282,7 @@ source4/st
source4/templates.ldb
source4/test-results
source4/tests
+source4/torture/utils/proto.h
source4/torture/auth/proto.h
source4/torture/basic/proto.h
source4/torture/ldap/proto.h
diff --git a/source4/torture/config.mk b/source4/torture/config.mk
index 00362b6..2fb59fe 100644
--- a/source4/torture/config.mk
+++ b/source4/torture/config.mk
@@ -40,6 +40,24 @@ TORTURE_BASIC_OBJ_FILES = $(addprefix $(torturesrcdir)/basic/, \
$(eval $(call proto_header_template,$(torturesrcdir)/basic/proto.h,$(TORTURE_BASIC_OBJ_FILES:.o=.c)))
#################################
+# Start SUBSYSTEM TORTURE_UTILS
+[MODULE::TORTURE_UTILS]
+OUTPUT_TYPE = MERGED_OBJ
+SUBSYSTEM = smbtorture
+INIT_FUNCTION = torture_utils_init
+PRIVATE_DEPENDENCIES = \
+ LIBCLI_SMB LIBCLI_LSA LIBCLI_SMB_COMPOSITE \
+ POPT_CREDENTIALS TORTURE_UTIL
+# End SUBSYSTEM TORTURE_UTILS
+#################################
+
+TORTURE_UTILS_OBJ_FILES = $(addprefix $(torturesrcdir)/utils/, \
+ utils.o \
+ acls.o)
+
+$(eval $(call proto_header_template,$(torturesrcdir)/utils/proto.h,$(TORTURE_UTILS_OBJ_FILES:.o=.c)))
+
+#################################
# Start SUBSYSTEM TORTURE_RAW
[MODULE::TORTURE_RAW]
OUTPUT_TYPE = MERGED_OBJ
diff --git a/source4/torture/torture.c b/source4/torture/torture.c
index 49a6a8c..9b8f1b7 100644
--- a/source4/torture/torture.c
+++ b/source4/torture/torture.c
@@ -64,6 +64,7 @@ _PUBLIC_ int torture_init(void)
extern NTSTATUS torture_net_init(void);
extern NTSTATUS torture_libnetapi_init(void);
extern NTSTATUS torture_raw_init(void);
+ extern NTSTATUS torture_utils_init(void);
extern NTSTATUS torture_unix_init(void);
extern NTSTATUS torture_winbind_init(void);
extern NTSTATUS torture_drs_init(void);
diff --git a/source4/torture/utils/acls.c b/source4/torture/utils/acls.c
new file mode 100644
index 0000000..237f0cc
--- /dev/null
+++ b/source4/torture/utils/acls.c
@@ -0,0 +1,149 @@
+/*
+ Unix SMB/CIFS implementation.
+
+ test acl tools
+
+ Copyright (C) Matthieu Patou 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 "system/filesys.h"
+#include "torture/torture.h"
+#include "libcli/libcli.h"
+#include "librpc/gen_ndr/xattr.h"
+#define BASEDIR "/tmp"
+
+static const char *refsddl = "O:S-1-5-21-2212615479-2695158682-2101375467-512G:S-1-5-21-2212615479-2695158682-2101375467-513"
+ "D:(A;OICI;0x001f01ff;;;S-1-5-21-2212615479-2695158682-2101375467-512)";
+/* Blob equivalent for refsddl */
+static const char blob[] = {
+ 0x01,0x00,0x01,0x00,0x00,0x00,0x02,0x00,0x01,0x00,0x04,0x80,0x1c,0x00,0x00,0x00,0x38,
+ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x54,0x00,0x00,0x00,0x01,0x05,0x00,0x00,0x00,0x00,
+ 0x00,0x05,0x15,0x00,0x00,0x00,0x37,0xd5,0xe1,0x83,0x9a,0xdb,0xa4,0xa0,0xeb,0x71,0x40,
+ 0x7d,0x00,0x02,0x00,0x00,0x01,0x05,0x00,0x00,0x00,0x00,0x00,0x05,0x15,0x00,0x00,0x00,
+ 0x37,0xd5,0xe1,0x83,0x9a,0xdb,0xa4,0xa0,0xeb,0x71,0x40,0x7d,0x01,0x02,0x00,0x00,0x02,
+ 0x00,0x2c,0x00,0x01,0x00,0x00,0x00,0x00,0x03,0x24,0x00,0xff,0x01,0x1f,0x00,0x01,0x05,
+ 0x00,0x00,0x00,0x00,0x00,0x05,0x15,0x00,0x00,0x00,0x37,0xd5,0xe1,0x83,0x9a,0xdb,0xa4,
+ 0xa0,0xeb,0x71,0x40,0x7d,0x00,0x02,0x00,0x00 };
+static int bloblen = 128;
+
+bool torture_getntacls(struct torture_context *tctx, struct smbcli_state *cli)
+{
+ bool ret = true;
+ long int l = random();
+ char *path_fname;
+ FILE *file;
+ FILE *pipe;
+ char buf[1024];
+ char *path_env;
+ char *new_path_env;
+ char *cmdline;
+ int fd;
+ int res;
+
+ memset(buf,0,1024);
+ asprintf(&path_fname, BASEDIR "/torture_acl%ld",l);
+ file = fopen(path_fname,"w");
+ if (file == NULL) {
+ return false;
+ }
+ fclose(file);
+ /* First write the blob directly into the security.NTACL attribute */
+ wrap_setxattr(path_fname, XATTR_NTACL_NAME, blob,bloblen, 0);
+ path_env = getenv("PATH");
+ asprintf(&new_path_env,"./bin:%s",path_env);
+ setenv("PATH",new_path_env,1);
+ asprintf(&cmdline,"getntacl --as-sddl %s",path_fname);
+
+ /* Then check that getntacl give the good result*/
+ pipe = popen(cmdline,"r");
+ fd = fileno(pipe);
+ res = read(fd,buf,1024);
+ if( res < 0 ) {
+ ret = false;
+ }
+ else {
+ if ( strncmp(buf,refsddl,strlen(refsddl)) != 0 )
+ ret = false;
+ }
+
+ pclose(pipe);
+ unlink(path_fname);
+ return ret;
+}
+
+bool torture_setntacls(struct torture_context *tctx, struct smbcli_state *cli)
+{
+ bool ret = true;
+ long int l = random();
+ char *path_fname;
+ FILE *file;
+ FILE *pipe;
+ char buf[1024];
+ char *path_env;
+ char *new_path_env;
+ char *cmdline;
+ pid_t pid;
+ char dest_blob[1024];
+ int dest_bloblen = 1024;
+ int fd;
+ int res;
+
+ memset(buf,0,1024);
+ asprintf(&path_fname, BASEDIR "/torture_acl%ld",l);
+ file = fopen(path_fname,"w");
+ if (file == NULL) {
+ return false;
+ }
+ fclose(file);
+
+ path_env = getenv("PATH");
+ asprintf(&new_path_env,"./bin:%s",path_env);
+ setenv("PATH",new_path_env,1);
+ asprintf(&cmdline,"setntacl \"%s\" %s",refsddl,path_fname);
+
+ pipe = popen(cmdline,"r");
+ fd = fileno(pipe);
+ res = read(fd,buf,1024);
+ if( res < 0 ) {
+ ret = false;
+ }
+ else {
+ if( buf[0] != '\0' ) {
+ ret = false;
+ }
+ else {
+ res = wrap_getxattr(path_fname,XATTR_NTACL_NAME,dest_blob,dest_bloblen);
+ if( res != bloblen ) {
+ ret = false;
+ }
+ else {
+ int i;
+ for(i=0;i<bloblen;i++) {
+ if( dest_blob[i] != blob[i] ) {
+ ret = false;
+ break;
+ }
+ }
+ }
+ }
+ }
+ pclose(pipe);
+
+
+ unlink(path_fname);
+ return ret;
+}
diff --git a/source4/torture/utils/utils.c b/source4/torture/utils/utils.c
new file mode 100644
index 0000000..3da199e
--- /dev/null
+++ b/source4/torture/utils/utils.c
@@ -0,0 +1,38 @@
+/*
+ Unix SMB/CIFS implementation.
+ Utils torture tester
+ Copyright (C) Matthieu Patou 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/util.h"
+#include "torture/smbtorture.h"
+#include "torture/utils/proto.h"
+
+NTSTATUS torture_utils_init(void)
+{
+ struct torture_suite *suite = torture_suite_create(
+ talloc_autofree_context(),
+ "UTILS");
+ /* UTILS tests */
+ torture_suite_add_simple_test(suite, "GETNTACL", torture_getntacls);
+ torture_suite_add_simple_test(suite, "SETNTACL", torture_setntacls);
+ suite->description = talloc_strdup(suite, "Tests for samba utils ");
+
+ torture_register_suite(suite);
+
+ return NT_STATUS_OK;
+}
--
1.6.3.3
--------------030605090705010801070303
Content-Type: text/x-patch;
name="0005-s4-Create-unit-tests-for-python-samba.xattr-module.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
filename*0="0005-s4-Create-unit-tests-for-python-samba.xattr-module.patc";
filename*1="h"
More information about the samba-technical
mailing list