Author: mimir
Date: 2006-10-02 06:00:14 +0000 (Mon, 02 Oct 2006)
New Revision: 19025

WebSVN: 
http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=19025

Log:
- remove read-only and policy dependent fields and flags
- do not stop NET-API-USERMODIFY test when a single field fails
- add account flags to the fields tested
- separate "cleanup" step from closing domain at the end


rafal


Modified:
   branches/SAMBA_4_0/source/torture/libnet/libnet_user.c
   branches/SAMBA_4_0/source/torture/libnet/userman.c
   branches/SAMBA_4_0/source/torture/libnet/usertest.h


Changeset:
Modified: branches/SAMBA_4_0/source/torture/libnet/libnet_user.c
===================================================================
--- branches/SAMBA_4_0/source/torture/libnet/libnet_user.c      2006-10-02 
05:53:45 UTC (rev 19024)
+++ branches/SAMBA_4_0/source/torture/libnet/libnet_user.c      2006-10-02 
06:00:14 UTC (rev 19025)
@@ -343,11 +343,11 @@
                case account_name:
                        continue_if_field_set(r->in.account_name);
                        r->in.account_name = talloc_asprintf(mem_ctx, 
TEST_CHG_ACCOUNTNAME,
-                                                            (int)random());
+                                                            (int)(random() % 
100));
                        fldname = "account_name";
                        
                        /* update the test's user name in case it's about to 
change */
-                       *user_name = r->in.account_name;
+                       *user_name = talloc_strdup(mem_ctx, r->in.account_name);
                        break;
 
                case full_name:
@@ -406,41 +406,6 @@
                        fldname = "acct_expiry";
                        break;
 
-               case allow_password_change:
-                       continue_if_field_set(r->in.allow_password_change);
-                       now = timeval_add(&now, (random() % (31*24*60*60)), 0);
-                       r->in.allow_password_change = talloc_memdup(mem_ctx, 
&now, sizeof(now));
-                       fldname = "allow_password_change";
-                       break;
-
-               case force_password_change:
-                       continue_if_field_set(r->in.force_password_change);
-                       now = timeval_add(&now, (random() % (31*24*60*60)), 0);
-                       r->in.force_password_change = talloc_memdup(mem_ctx, 
&now, sizeof(now));
-                       fldname = "force_password_change";
-                       break;
-
-               case last_logon:
-                       continue_if_field_set(r->in.last_logon);
-                       now = timeval_add(&now, (random() % (31*24*60*60)), 0);
-                       r->in.last_logon = talloc_memdup(mem_ctx, &now, 
sizeof(now));
-                       fldname = "last_logon";
-                       break;
-
-               case last_logoff:
-                       continue_if_field_set(r->in.last_logoff);
-                       now = timeval_add(&now, (random() % (31*24*60*60)), 0);
-                       r->in.last_logoff = talloc_memdup(mem_ctx, &now, 
sizeof(now));
-                       fldname = "last_logoff";
-                       break;
-
-               case last_password_change:
-                       continue_if_field_set(r->in.last_password_change);
-                       now = timeval_add(&now, (random() % (31*24*60*60)), 0);
-                       r->in.last_password_change = talloc_memdup(mem_ctx, 
&now, sizeof(now));
-                       fldname = "last_password_change";
-                       break;
-
                default:
                        fldname = "unknown_field";
                }
@@ -455,6 +420,28 @@
 }
 
 
+#define TEST_STR_FLD(fld) \
+       if (!strequal(req.in.fld, user_req.out.fld)) { \
+               printf("failed to change '%s'\n", #fld); \
+               ret = False; \
+               goto cleanup; \
+       }
+
+#define TEST_TIME_FLD(fld) \
+       if (timeval_compare(req.in.fld, user_req.out.fld)) { \
+               printf("failed to change '%s'\n", #fld); \
+               ret = False; \
+               goto cleanup; \
+       }
+
+#define TEST_NUM_FLD(fld) \
+       if (req.in.fld != user_req.out.fld) { \
+               printf("failed to change '%s'\n", #fld); \
+               ret = False; \
+               goto cleanup; \
+       }
+
+
 BOOL torture_modifyuser(struct torture_context *torture)
 {
        NTSTATUS status;
@@ -467,6 +454,7 @@
        char *name;
        struct libnet_context *ctx;
        struct libnet_ModifyUser req;
+       struct libnet_UserInfo user_req;
        int fld;
        BOOL ret = True;
 
@@ -507,7 +495,7 @@
 
        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 - 1; fld++) {
                ZERO_STRUCT(req);
                req.in.domain_name = lp_workgroup();
                req.in.user_name = name;
@@ -517,11 +505,45 @@
                status = libnet_ModifyUser(ctx, mem_ctx, &req);
                if (!NT_STATUS_IS_OK(status)) {
                        printf("libnet_ModifyUser call failed: %s\n", 
nt_errstr(status));
-                       talloc_free(mem_ctx);
                        ret = False;
-                       goto done;
+                       continue;
                }
 
+               ZERO_STRUCT(user_req);
+               user_req.in.domain_name = lp_workgroup();
+               user_req.in.user_name = name;
+
+               status = libnet_UserInfo(ctx, mem_ctx, &user_req);
+               if (!NT_STATUS_IS_OK(status)) {
+                       printf("libnet_UserInfo call failed: %s\n", 
nt_errstr(status));
+                       continue;
+               }
+
+               switch (fld) {
+               case account_name: TEST_STR_FLD(account_name);
+                       break;
+               case full_name: TEST_STR_FLD(full_name);
+                       break;
+               case comment: TEST_STR_FLD(comment);
+                       break;
+               case description: TEST_STR_FLD(description);
+                       break;
+               case home_directory: TEST_STR_FLD(home_directory);
+                       break;
+               case home_drive: TEST_STR_FLD(home_drive);
+                       break;
+               case logon_script: TEST_STR_FLD(logon_script);
+                       break;
+               case profile_path: TEST_STR_FLD(profile_path);
+                       break;
+               case acct_expiry: TEST_TIME_FLD(acct_expiry);
+                       break;
+               case acct_flags: TEST_NUM_FLD(acct_flags);
+                       break;
+               default:
+                       break;
+               }
+
                if (fld == account_name) {
                        /* restore original testing username - it's useful when 
test fails
                           because it prevents from problems with recreating 
account */
@@ -538,10 +560,11 @@
                                goto done;
                        }
                        
-                       name = TEST_USERNAME;
+                       name = talloc_strdup(mem_ctx, TEST_USERNAME);
                }
        }
 
+cleanup:
        if (!test_cleanup(ctx->samr.pipe, mem_ctx, &ctx->samr.handle, name)) {
                printf("cleanup failed\n");
                ret = False;

Modified: branches/SAMBA_4_0/source/torture/libnet/userman.c
===================================================================
--- branches/SAMBA_4_0/source/torture/libnet/userman.c  2006-10-02 05:53:45 UTC 
(rev 19024)
+++ branches/SAMBA_4_0/source/torture/libnet/userman.c  2006-10-02 06:00:14 UTC 
(rev 19025)
@@ -262,6 +262,9 @@
        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;
+       const uint32_t flags[] = { (ACB_DISABLED | ACB_NORMAL),
+                                  (ACB_NORMAL | ACB_PWNOEXP),
+                                  (ACB_NORMAL | ACB_PW_EXPIRED) };
 
        NTSTATUS status;
        struct timeval now;
@@ -278,10 +281,10 @@
 
        printf("fields to change: [");
 
-       for (i = 0; i < num_changes && i < FIELDS_NUM; i++) {
+       for (i = 0; i < num_changes && i < FIELDS_NUM - 1; i++) {
                const char *fldname;
 
-               testfld = random() % (FIELDS_NUM - 1);
+               testfld = (random() % (FIELDS_NUM - 1)) + 1;
 
                gettimeofday(&now, NULL);
 
@@ -359,46 +362,13 @@
                        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";
+               case acct_flags:
+                       continue_if_field_set(mod->in.change.acct_flags);
+                       mod->in.change.acct_flags = flags[random() % 
(sizeof(flags)/sizeof(uint32_t))];
+                       mod->in.change.fields |= USERMOD_FIELD_ACCT_EXPIRY;
+                       fldname = "acct_flags";
                        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 = talloc_asprintf(mem_ctx, "unknown_field 
(%d)", testfld);
                        break;
@@ -500,11 +470,6 @@
        CMP_LSA_STRING_FLD(home_directory, USERMOD_FIELD_HOME_DIRECTORY);
        CMP_LSA_STRING_FLD(home_drive, USERMOD_FIELD_HOME_DRIVE);
        CMP_TIME_FLD(acct_expiry, USERMOD_FIELD_ACCT_EXPIRY);
-       CMP_TIME_FLD(allow_password_change, USERMOD_FIELD_ALLOW_PASS_CHG);
-       CMP_TIME_FLD(force_password_change, USERMOD_FIELD_FORCE_PASS_CHG);
-       CMP_TIME_FLD(last_logon, USERMOD_FIELD_LAST_LOGON);
-       CMP_TIME_FLD(last_logoff, USERMOD_FIELD_LAST_LOGOFF);
-       CMP_TIME_FLD(last_password_change, USERMOD_FIELD_LAST_PASS_CHG);
        CMP_NUM_FLD(acct_flags, USERMOD_FIELD_ACCT_FLAGS)
 
        return True;
@@ -650,21 +615,22 @@
                ret = False;
                goto done;
        }
-
-       for (i = 1; i < 8; i++) {
+       
+       for (i = 1; i < FIELDS_NUM; i++) {
                struct libnet_rpc_usermod m;
 
                if (!test_usermod(p, mem_ctx, &h, i, &m, &name)) {
                        ret = False;
-                       goto done;
+                       goto cleanup;
                }
 
                if (!test_compare(p, mem_ctx, &h, &m, name)) {
                        ret = False;
-                       goto done;
+                       goto cleanup;
                }
        }
        
+cleanup:       
        if (!test_cleanup(p, mem_ctx, &h, name)) {
                ret = False;
                goto done;

Modified: branches/SAMBA_4_0/source/torture/libnet/usertest.h
===================================================================
--- branches/SAMBA_4_0/source/torture/libnet/usertest.h 2006-10-02 05:53:45 UTC 
(rev 19024)
+++ branches/SAMBA_4_0/source/torture/libnet/usertest.h 2006-10-02 06:00:14 UTC 
(rev 19025)
@@ -27,10 +27,9 @@
        }
 
 
-#define FIELDS_NUM 15
+#define FIELDS_NUM 11
 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 };
+                  comment, logon_script, profile_path, acct_expiry, acct_flags 
};
 
 
 #define TEST_CHG_ACCOUNTNAME   "newlibnetusertest%02d"

Reply via email to