Author: vlendec
Date: 2005-11-22 20:55:59 +0000 (Tue, 22 Nov 2005)
New Revision: 11868

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

Log:
Get the wks and user accounts from a file.

Abartlet, please don't break this again, it's too darn useful for
near-realistic load tests on an RPC infrastructure and can be quite easily
expanded to more weird things a workstation might do during a login.

Yes, I promise I will document this test, but this must wait until the
weekend.

I might add simulating a profile download quite soon, we have the information
available from the info3.

Thanks,

Volker

Modified:
   branches/SAMBA_4_0/source/torture/rpc/xplogin.c


Changeset:
Modified: branches/SAMBA_4_0/source/torture/rpc/xplogin.c
===================================================================
--- branches/SAMBA_4_0/source/torture/rpc/xplogin.c     2005-11-22 20:48:56 UTC 
(rev 11867)
+++ branches/SAMBA_4_0/source/torture/rpc/xplogin.c     2005-11-22 20:55:59 UTC 
(rev 11868)
@@ -1460,6 +1460,8 @@
        cli_credentials_set_conf(state->wks_creds);
        cli_credentials_set_domain(state->wks_creds, wks_domain,
                                   CRED_SPECIFIED);
+       cli_credentials_set_workstation(state->wks_creds, wks_name,
+                                       CRED_SPECIFIED);
        cli_credentials_set_username(state->wks_creds,
                                     talloc_asprintf(state, "%s$", wks_name),
                                     CRED_SPECIFIED);
@@ -1477,6 +1479,8 @@
        if (state->conn.in.credentials == NULL) goto failed;
        cli_credentials_set_conf(state->conn.in.credentials);
        cli_credentials_set_anonymous(state->conn.in.credentials);
+       cli_credentials_set_workstation(state->conn.in.credentials, wks_name,
+                                       CRED_SPECIFIED);
        state->conn.in.fallback_to_anonymous = False;
        state->conn.in.workgroup = wks_domain;
 
@@ -1759,6 +1763,100 @@
        *count += 1;
 }
 
+struct pwdentry {
+       const char *domain;
+       const char *name;
+       const char *pass;
+};
+
+static BOOL read_pwd_file(TALLOC_CTX *mem_ctx,
+                         const char *fname, int *numlines,
+                         struct pwdentry ***result)
+{
+       char **lines;
+       int i;
+
+       lines = file_lines_load(fname, numlines, mem_ctx);
+       if (lines == NULL) {
+               DEBUG(0, ("Could not load file %s: %s\n",
+                         fname, strerror(errno)));
+               return False;
+       }
+
+       if (*numlines == 0) {
+               DEBUG(0, ("no entries in file %s\n", fname));
+               return False;
+       }
+
+       *result = talloc_array(mem_ctx, struct pwdentry *, *numlines);
+       if (*result == NULL) {
+               DEBUG(0, ("talloc failed\n"));
+               return False;
+       }
+
+       for (i=0; i<(*numlines); i++) {
+               char *p, *q;
+               (*result)[i] = talloc_zero(*result, struct pwdentry);
+               if ((*result)[i] == NULL) {
+                       DEBUG(0, ("talloc failed\n"));
+                       return False;
+               }
+
+               p = lines[i];
+               q = strchr(p, '\\');
+               if (q != NULL) {
+                       *q = '\0';
+                       (*result)[i]->domain = lines[i];
+                       p = q+1;
+               } else {
+                       (*result)[i]->domain = lp_workgroup();
+               }
+
+               q = strchr(p, '%');
+               if (q == NULL) {
+                       DEBUG(0, ("Invalid entry: %s\n", q));
+                       return False;
+               }
+
+               *q = '\0';
+               (*result)[i]->name = p;
+               (*result)[i]->pass = q+1;
+       }
+
+       return True;
+}
+
+#if 0
+/* Stolen from testjoin.c for easy mass-joining */p
+static BOOL joinme(int i)
+{
+       TALLOC_CTX *mem_ctx;
+       struct test_join *join_ctx;
+       struct cli_credentials *machine_credentials;
+       const char *machine_password;
+       const char *name;
+
+       mem_ctx = talloc_init("torture_rpc_netlogon");
+
+       name = talloc_asprintf(mem_ctx, "wks%3d", i);
+
+       join_ctx = torture_join_domain(name, ACB_WSTRUST, 
+                                      &machine_credentials);
+       if (!join_ctx) {
+               talloc_free(mem_ctx);
+               printf("Failed to join as BDC\n");
+               return False;
+       }
+
+       machine_password = cli_credentials_get_password(machine_credentials);
+
+       printf("%s%%%s\n", name, machine_password);
+
+       talloc_free(mem_ctx);
+       return True;
+}
+#endif
+
 BOOL torture_rpc_login(void)
 {
        TALLOC_CTX *mem_ctx;
@@ -1768,13 +1866,42 @@
        int i, num_events;
        int num_finished = 0;
        struct composite_context **ctx;
+       struct pwdentry **wks_list;
+       struct pwdentry **user_list;
+       int num_wks = 0;
+       int num_user = 0;
 
+#if 0
+       for (i=0; i<torture_numops; i++) {
+               if (!joinme(i)) {
+                       DEBUG(0, ("join %d failed\n", i));
+                       return False;
+               }
+       }
+
+       return False;
+#endif
+       
        mem_ctx = talloc_init("rpc_login");
        if (mem_ctx == NULL) {
                DEBUG(0, ("talloc_init failed\n"));
                return False;
        }
 
+       if (!read_pwd_file(mem_ctx, "wks.pwd", &num_wks, &wks_list)) {
+               return False;
+       }
+
+       if (torture_numops > num_wks) {
+               DEBUG(0, ("more workstations (%d) than ops (%d) needed\n",
+                         num_wks, torture_numops));
+               return False;
+       }
+
+       if (!read_pwd_file(mem_ctx, "user.pwd", &num_user, &user_list)) {
+               return False;
+       }
+
        event_ctx = event_context_init(mem_ctx);
        if (event_ctx == NULL) {
                DEBUG(0, ("event_context_init failed\n"));
@@ -1789,6 +1916,9 @@
        }
 
        for (i=0; i<torture_numops; i++) {
+               int wks_idx = random() % num_wks;
+               int user_idx = random() % num_user;
+               DEBUG(3, ("random indices: wks %d, user %d\n", wks_idx, 
user_idx));
                ctx[i] = xp_login_send(
                        mem_ctx, timeval_set(0, i*lp_parm_int(-1, "torture",
                                                              "timeout", 0)),
@@ -1796,14 +1926,23 @@
                        lp_parm_string(-1, "torture", "host"),
                        lp_parm_string(-1, "torture", "host"),
                        lp_workgroup(),
-                       lp_netbios_name(), "5,eEp_D2",
-                       lp_workgroup(), "vl", "asdf");
+                       wks_list[wks_idx]->name,
+                       wks_list[wks_idx]->pass,
+                       user_list[user_idx]->domain,
+                       user_list[user_idx]->name,
+                       user_list[user_idx]->pass);
                if (ctx[i] == NULL) {
                        DEBUG(0, ("xp_login_send failed\n"));
                        goto done;
                }
                ctx[i]->async.fn = xp_login_done;
                ctx[i]->async.private_data = &num_finished;
+
+               /* Avoid duplicate usage of workstation accounts. They would
+                * conflict if multiple reqchal/auth2/schannel-binds cross
+                * each other */
+               wks_list[wks_idx] = wks_list[num_wks-1];
+               num_wks -= 1;
        }
 
        num_events = 0;

Reply via email to