summaryrefslogtreecommitdiff
path: root/source4
diff options
context:
space:
mode:
authorRafal Szczesniak <mimir@samba.org>2006-09-19 19:15:36 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 14:19:01 -0500
commita76d3734aeb1a948de32ef8271c0363bd54eb593 (patch)
tree669877a2f565ba49444b2ae0eb5ae636a4ae887b /source4
parent3394bb23fd9c7c7b9d388be414143d0fffdb2593 (diff)
downloadsamba-a76d3734aeb1a948de32ef8271c0363bd54eb593.tar.gz
samba-a76d3734aeb1a948de32ef8271c0363bd54eb593.tar.bz2
samba-a76d3734aeb1a948de32ef8271c0363bd54eb593.zip
r18683: NET-USERMOD test changed to be able to perform multiple simultaneous
changes. Also, some common definitions for user mod tests have been put into a separate file. rafal (This used to be commit 0040c087481be68d44a0b59744be5c5e569fd8a4)
Diffstat (limited to 'source4')
-rw-r--r--source4/torture/libnet/libnet_user.c30
-rw-r--r--source4/torture/libnet/userman.c249
-rw-r--r--source4/torture/libnet/usertest.h20
3 files changed, 207 insertions, 92 deletions
diff --git a/source4/torture/libnet/libnet_user.c b/source4/torture/libnet/libnet_user.c
index e70060b8c9..10522d21c1 100644
--- a/source4/torture/libnet/libnet_user.c
+++ b/source4/torture/libnet/libnet_user.c
@@ -26,10 +26,9 @@
#include "librpc/gen_ndr/ndr_samr_c.h"
#include "torture/torture.h"
#include "torture/rpc/rpc.h"
+#include "torture/libnet/usertest.h"
-#define TEST_USERNAME "libnetusertest"
-
static BOOL test_cleanup(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
struct policy_handle *domain_handle, const char *username)
{
@@ -318,25 +317,8 @@ done:
Generate testing set of random changes
*/
-#define TEST_CHG_ACCOUNTNAME "newlibnetusertest%02d"
-#define TEST_CHG_DESCRIPTION "Sample description %ld"
-#define TEST_CHG_FULLNAME "First%04x Last%04x"
-#define TEST_CHG_COMMENT "Comment[%04lu%04lu]"
-#define TEST_CHG_PROFILEPATH "\\\\srv%04ld\\profile%02u\\prof"
-
-#define continue_if_field_set(field) \
- if (field != 0) { \
- i--; \
- continue; \
- }
-
-const int fields_num = 15;
-enum test_fields { none = 0, account_name, full_name, description, home_directory, home_drive,
- comment, logon_script, profile_path, acct_expiry, allow_password_change,
- force_password_change, last_logon, last_logoff, last_password_change };
-
-static void set_test_changes(TALLOC_CTX *mem_ctx, struct libnet_ModifyUser *r, int num_changes,
- char **user_name, enum test_fields req_change)
+void set_test_changes(TALLOC_CTX *mem_ctx, struct libnet_ModifyUser *r, int num_changes,
+ char **user_name, enum test_fields req_change)
{
const char* logon_scripts[] = { "start_login.cmd", "login.bat", "start.cmd" };
const char* home_dirs[] = { "\\\\srv\\home", "\\\\homesrv\\home\\user", "\\\\pdcsrv\\domain" };
@@ -349,10 +331,10 @@ static void set_test_changes(TALLOC_CTX *mem_ctx, struct libnet_ModifyUser *r, i
printf("Fields to change: [");
- for (i = 0; i < num_changes && i < fields_num; i++) {
+ for (i = 0; i < num_changes && i < FIELDS_NUM; i++) {
const char *fldname;
- testfld = (req_change == none) ? (random() % fields_num) : req_change;
+ testfld = (req_change == none) ? (random() % FIELDS_NUM) : req_change;
/* get one in case we hit time field this time */
gettimeofday(&now, NULL);
@@ -525,7 +507,7 @@ BOOL torture_modifyuser(struct torture_context *torture)
printf("Testing change of all fields - each single one in turn\n");
- for (fld = 1; fld < fields_num; fld++) {
+ for (fld = 1; fld < FIELDS_NUM; fld++) {
ZERO_STRUCT(req);
req.in.domain_name = lp_workgroup();
req.in.user_name = name;
diff --git a/source4/torture/libnet/userman.c b/source4/torture/libnet/userman.c
index 73aada2384..57f2f5b111 100644
--- a/source4/torture/libnet/userman.c
+++ b/source4/torture/libnet/userman.c
@@ -21,11 +21,10 @@
#include "includes.h"
#include "torture/rpc/rpc.h"
+#include "torture/libnet/usertest.h"
#include "libnet/libnet.h"
#include "librpc/gen_ndr/ndr_samr_c.h"
-#define TEST_USERNAME "libnetusermantest"
-
static BOOL test_opendomain(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
struct policy_handle *handle, struct lsa_String *domname)
@@ -255,18 +254,164 @@ static BOOL test_createuser(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
}
-static BOOL test_userdel(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
- struct policy_handle *handle, const char *username)
+static BOOL test_usermod(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
+ struct policy_handle *handle, int num_changes,
+ char **username)
{
+ const char* logon_scripts[] = { "start_login.cmd", "login.bat", "start.cmd" };
+ const char* home_dirs[] = { "\\\\srv\\home", "\\\\homesrv\\home\\user", "\\\\pdcsrv\\domain" };
+ const char* home_drives[] = { "H:", "z:", "I:", "J:", "n:" };
+ const char *homedir, *homedrive, *logonscript;
+
NTSTATUS status;
- struct libnet_rpc_userdel user;
-
- user.in.domain_handle = *handle;
- user.in.username = username;
-
- status = libnet_rpc_userdel(p, mem_ctx, &user);
+ struct libnet_rpc_usermod mod;
+ struct timeval now;
+ enum test_fields testfld;
+ int i;
+
+ ZERO_STRUCT(mod);
+ srandom((unsigned)time(NULL));
+
+ mod.in.username = talloc_strdup(mem_ctx, *username);
+ mod.in.domain_handle = *handle;
+
+ printf("modifying user (%d simultaneous change(s))\n", num_changes);
+
+ printf("fields to change: [");
+
+ for (i = 0; i < num_changes && i < FIELDS_NUM; i++) {
+ const char *fldname;
+
+ testfld = random() % FIELDS_NUM;
+
+ gettimeofday(&now, NULL);
+
+ switch (testfld) {
+ case account_name:
+ continue_if_field_set(mod.in.change.account_name);
+ mod.in.change.account_name = talloc_asprintf(mem_ctx, TEST_CHG_ACCOUNTNAME,
+ (int)random());
+ mod.in.change.fields |= USERMOD_FIELD_ACCOUNT_NAME;
+ fldname = "account_name";
+ *username = talloc_strdup(mem_ctx, mod.in.change.account_name);
+ break;
+
+ case full_name:
+ continue_if_field_set(mod.in.change.full_name);
+ mod.in.change.full_name = talloc_asprintf(mem_ctx, TEST_CHG_FULLNAME,
+ (int)random(), (int)random());
+ mod.in.change.fields |= USERMOD_FIELD_FULL_NAME;
+ fldname = "full_name";
+ break;
+
+ case description:
+ continue_if_field_set(mod.in.change.description);
+ mod.in.change.description = talloc_asprintf(mem_ctx, TEST_CHG_DESCRIPTION,
+ random());
+ mod.in.change.fields |= USERMOD_FIELD_DESCRIPTION;
+ fldname = "description";
+ break;
+
+ case home_directory:
+ continue_if_field_set(mod.in.change.home_directory);
+ homedir = home_dirs[random() % (sizeof(home_dirs)/sizeof(char*))];
+ mod.in.change.home_directory = talloc_strdup(mem_ctx, homedir);
+ mod.in.change.fields |= USERMOD_FIELD_HOME_DIRECTORY;
+ fldname = "home directory";
+ break;
+
+ case home_drive:
+ continue_if_field_set(mod.in.change.home_drive);
+ homedrive = home_drives[random() % (sizeof(home_drives)/sizeof(char*))];
+ mod.in.change.home_drive = talloc_strdup(mem_ctx, homedrive);
+ mod.in.change.fields |= USERMOD_FIELD_HOME_DRIVE;
+ fldname = "home drive";
+ break;
+
+ case comment:
+ continue_if_field_set(mod.in.change.comment);
+ mod.in.change.comment = talloc_asprintf(mem_ctx, TEST_CHG_COMMENT,
+ random(), random());
+ mod.in.change.fields |= USERMOD_FIELD_COMMENT;
+ fldname = "comment";
+ break;
+
+ case logon_script:
+ continue_if_field_set(mod.in.change.logon_script);
+ logonscript = logon_scripts[random() % (sizeof(logon_scripts)/sizeof(char*))];
+ mod.in.change.logon_script = talloc_strdup(mem_ctx, logonscript);
+ mod.in.change.fields |= USERMOD_FIELD_LOGON_SCRIPT;
+ fldname = "logon script";
+ break;
+
+ case profile_path:
+ continue_if_field_set(mod.in.change.profile_path);
+ mod.in.change.profile_path = talloc_asprintf(mem_ctx, TEST_CHG_PROFILEPATH,
+ (long int)random(), (unsigned int)random());
+ mod.in.change.fields |= USERMOD_FIELD_PROFILE_PATH;
+ fldname = "profile path";
+ break;
+
+ case acct_expiry:
+ continue_if_field_set(mod.in.change.acct_expiry);
+ now = timeval_add(&now, (random() % (31*24*60*60)), 0);
+ mod.in.change.acct_expiry = talloc_memdup(mem_ctx, &now, sizeof(now));
+ mod.in.change.fields |= USERMOD_FIELD_ACCT_EXPIRY;
+ fldname = "acct_expiry";
+ break;
+
+ case allow_password_change:
+ continue_if_field_set(mod.in.change.allow_password_change);
+ now = timeval_add(&now, (random() % (31*24*60*60)), 0);
+ mod.in.change.allow_password_change = talloc_memdup(mem_ctx, &now, sizeof(now));
+ mod.in.change.fields |= USERMOD_FIELD_ALLOW_PASS_CHG;
+ fldname = "allow_password_change";
+ break;
+
+ case force_password_change:
+ continue_if_field_set(mod.in.change.force_password_change);
+ now = timeval_add(&now, (random() % (31*24*60*60)), 0);
+ mod.in.change.force_password_change = talloc_memdup(mem_ctx, &now, sizeof(now));
+ mod.in.change.fields |= USERMOD_FIELD_FORCE_PASS_CHG;
+ fldname = "force_password_change";
+ break;
+
+ case last_logon:
+ continue_if_field_set(mod.in.change.last_logon);
+ now = timeval_add(&now, (random() % (31*24*60*60)), 0);
+ mod.in.change.last_logon = talloc_memdup(mem_ctx, &now, sizeof(now));
+ mod.in.change.fields |= USERMOD_FIELD_LAST_LOGON;
+ fldname = "last_logon";
+ break;
+
+ case last_logoff:
+ continue_if_field_set(mod.in.change.last_logoff);
+ now = timeval_add(&now, (random() % (31*24*60*60)), 0);
+ mod.in.change.last_logoff = talloc_memdup(mem_ctx, &now, sizeof(now));
+ mod.in.change.fields |= USERMOD_FIELD_LAST_LOGOFF;
+ fldname = "last_logoff";
+ break;
+
+ case last_password_change:
+ continue_if_field_set(mod.in.change.last_password_change);
+ now = timeval_add(&now, (random() % (31*24*60*60)), 0);
+ mod.in.change.last_password_change = talloc_memdup(mem_ctx, &now, sizeof(now));
+ mod.in.change.fields |= USERMOD_FIELD_LAST_PASS_CHG;
+ fldname = "last_password_change";
+ break;
+
+ default:
+ fldname = "unknown_field";
+ break;
+ }
+
+ printf(((i < num_changes - 1) ? "%s," : "%s"), fldname);
+ }
+ printf("]\n");
+
+ status = libnet_rpc_usermod(p, mem_ctx, &mod);
if (!NT_STATUS_IS_OK(status)) {
- printf("Failed to call sync libnet_rpc_userdel - %s\n", nt_errstr(status));
+ printf("Failed to call sync libnet_rpc_usermd - %s\n", nt_errstr(status));
return False;
}
@@ -274,22 +419,18 @@ static BOOL test_userdel(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
}
-static BOOL test_usermod(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
- struct policy_handle *handle, const char *username,
- struct usermod_change *change)
+static BOOL test_userdel(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx,
+ struct policy_handle *handle, const char *username)
{
NTSTATUS status;
- struct libnet_rpc_usermod user;
+ struct libnet_rpc_userdel user;
user.in.domain_handle = *handle;
user.in.username = username;
- user.in.change = *change;
-
- printf("modifying user\n");
-
- status = libnet_rpc_usermod(p, mem_ctx, &user);
+
+ status = libnet_rpc_userdel(p, mem_ctx, &user);
if (!NT_STATUS_IS_OK(status)) {
- printf("Failed to call sync libnet_rpc_usermod - %s\n", nt_errstr(status));
+ printf("Failed to call sync libnet_rpc_userdel - %s\n", nt_errstr(status));
return False;
}
@@ -407,46 +548,9 @@ BOOL torture_usermod(struct torture_context *torture)
struct dcerpc_pipe *p;
struct policy_handle h;
struct lsa_String domain_name;
- const char *name = TEST_USERNAME;
+ char *name;
TALLOC_CTX *mem_ctx;
BOOL ret = True;
- int i;
-
- struct timeval expiry = { 12345, 67890 };
- struct timeval allow = { 67890, 12345 };
- struct timeval force = { 33333, 55444 };
-
- struct usermod_change changes[] = {
- {
- .fields = USERMOD_FIELD_ACCOUNT_NAME,
- .account_name = "changed",
- },{
- .fields = USERMOD_FIELD_FULL_NAME,
- .full_name = "Testing full account name",
- },{
- .fields = USERMOD_FIELD_DESCRIPTION,
- .description = "Description of tested account",
- },{
- .fields = USERMOD_FIELD_COMMENT,
- .comment = "Comment for the tested account",
- },{
- .fields = USERMOD_FIELD_LOGON_SCRIPT,
- .logon_script = "test_logon.cmd",
- },{
- .fields = USERMOD_FIELD_PROFILE_PATH,
- .profile_path = "\\\\TESTSRV\\profiles\\test",
- },{
- .fields = USERMOD_FIELD_ACCT_EXPIRY,
- .acct_expiry = &expiry,
- },{
- .fields = USERMOD_FIELD_ALLOW_PASS_CHG,
- .allow_password_change = &allow,
- },{
- .fields = USERMOD_FIELD_FORCE_PASS_CHG,
- .force_password_change = &force,
- .acct_flags = ACB_NORMAL,/* TODO: why is this needed here? */
- }
- };
mem_ctx = talloc_init("test_userdel");
binding = lp_parm_string(-1, "torture", "binding");
@@ -456,10 +560,12 @@ BOOL torture_usermod(struct torture_context *torture)
&dcerpc_table_samr);
if (!NT_STATUS_IS_OK(status)) {
- return False;
+ ret = False;
+ goto done;
}
domain_name.string = lp_workgroup();
+ name = talloc_strdup(mem_ctx, TEST_USERNAME);
if (!test_opendomain(p, mem_ctx, &h, &domain_name)) {
ret = False;
@@ -471,15 +577,22 @@ BOOL torture_usermod(struct torture_context *torture)
goto done;
}
- for (i = 0; i < (sizeof(changes)/sizeof(struct usermod_change)); i++) {
- if (!test_usermod(p, mem_ctx, &h, name, &changes[i])) {
- ret = False;
- goto done;
- }
+ /* single change */
+ if (!test_usermod(p, mem_ctx, &h, 1, &name)) {
+ ret = False;
+ goto done;
+ }
- if (changes[i].fields & USERMOD_FIELD_ACCOUNT_NAME) {
- name = talloc_strdup(mem_ctx, changes[i].account_name);
- }
+ /* double change */
+ if (!test_usermod(p, mem_ctx, &h, 2, &name)) {
+ ret = False;
+ goto done;
+ }
+
+ /* triple change */
+ if (!test_usermod(p, mem_ctx, &h, 3, &name)) {
+ ret = False;
+ goto done;
}
if (!test_cleanup(p, mem_ctx, &h, name)) {
diff --git a/source4/torture/libnet/usertest.h b/source4/torture/libnet/usertest.h
new file mode 100644
index 0000000000..6244d39501
--- /dev/null
+++ b/source4/torture/libnet/usertest.h
@@ -0,0 +1,20 @@
+#define TEST_USERNAME "libnetusertest"
+
+#define continue_if_field_set(field) \
+ if (field != 0) { \
+ i--; \
+ continue; \
+ }
+
+
+#define FIELDS_NUM 15
+enum test_fields { none = 0, account_name, full_name, description, home_directory, home_drive,
+ comment, logon_script, profile_path, acct_expiry, allow_password_change,
+ force_password_change, last_logon, last_logoff, last_password_change };
+
+
+#define TEST_CHG_ACCOUNTNAME "newlibnetusertest%02d"
+#define TEST_CHG_DESCRIPTION "Sample description %ld"
+#define TEST_CHG_FULLNAME "First%04x Last%04x"
+#define TEST_CHG_COMMENT "Comment[%04lu%04lu]"
+#define TEST_CHG_PROFILEPATH "\\\\srv%04ld\\profile%02u\\prof"