r4973: Add a RAP scanner to smbtorture. win2k has call numbers 0-215 although
[samba.git] / source4 / torture / torture.c
index cc960b6ec70d6780d529b3a8fdf34c97cd57d54a..e41e1835371ad77a0b18f2cd6cf89edb83c5b862 100644 (file)
@@ -44,12 +44,15 @@ BOOL torture_showall = False;
 
 static struct smbcli_state *open_nbt_connection(void)
 {
-       struct nmb_name called, calling;
+       struct nbt_name called, calling;
        struct smbcli_state *cli;
        const char *host = lp_parm_string(-1, "torture", "host");
 
-       make_nmb_name(&calling, lp_netbios_name(), 0x0);
-       choose_called_name(&called, host, 0x20);
+       calling.name = lp_netbios_name();
+       calling.type = NBT_NAME_CLIENT;
+       calling.scope = NULL;
+
+       nbt_choose_called_name(NULL, &called, host, NBT_NAME_SERVER);
 
        cli = smbcli_state_init(NULL);
        if (!cli) {
@@ -62,26 +65,10 @@ static struct smbcli_state *open_nbt_connection(void)
                return cli;
        }
 
-       cli->transport->socket->timeout = 120000; /* set a really long timeout (2 minutes) */
-
        if (!smbcli_transport_establish(cli, &calling, &called)) {
-               /*
-                * Well, that failed, try *SMBSERVER ... 
-                * However, we must reconnect as well ...
-                */
-               if (!smbcli_socket_connect(cli, host)) {
-                       printf("Failed to connect with %s\n", host);
-                       return False;
-               }
-
-               make_nmb_name(&called, "*SMBSERVER", 0x20);
-               if (!smbcli_transport_establish(cli, &calling, &called)) {
-                       printf("%s rejected the session\n",host);
-                       printf("We tried with a called name of %s & %s\n",
-                               host, "*SMBSERVER");
-                       smbcli_shutdown(cli);
-                       return NULL;
-               }
+               printf("%s rejected the session\n",host);
+               smbcli_shutdown(cli);
+               return NULL;
        }
 
        return cli;
@@ -91,8 +78,6 @@ BOOL torture_open_connection_share(struct smbcli_state **c,
                                   const char *hostname, 
                                   const char *sharename)
 {
-       BOOL retry;
-       int flags = 0;
        NTSTATUS status;
        const char *username = lp_parm_string(-1, "torture", "username");
        const char *userdomain = lp_parm_string(-1, "torture", "userdomain");
@@ -100,10 +85,10 @@ BOOL torture_open_connection_share(struct smbcli_state **c,
 
        status = smbcli_full_connection(NULL,
                                        c, lp_netbios_name(),
-                                       hostname, NULL, 
-                                       sharename, "?????", 
+                                       hostname, 
+                                       sharename, NULL,
                                        username, username[0]?userdomain:"",
-                                       password, flags, &retry);
+                                       password);
        if (!NT_STATUS_IS_OK(status)) {
                printf("Failed to open connection - %s\n", nt_errstr(status));
                return False;
@@ -111,7 +96,6 @@ BOOL torture_open_connection_share(struct smbcli_state **c,
 
        (*c)->transport->options.use_oplocks = use_oplocks;
        (*c)->transport->options.use_level2_oplocks = use_level_II_oplocks;
-       (*c)->transport->socket->timeout = 120000;
 
        return True;
 }
@@ -281,7 +265,7 @@ static BOOL rw_torture(struct smbcli_state *c)
 
 
        for (i=0;i<torture_numops;i++) {
-               uint_t n = (uint_t)sys_random()%10;
+               uint_t n = (uint_t)random()%10;
                if (i % 10 == 0) {
                        printf("%d\r", i); fflush(stdout);
                }
@@ -375,7 +359,7 @@ static BOOL rw_torture3(struct smbcli_state *c, const char *lockfname)
 
        for (i = 0; i < sizeof(buf); i += sizeof(uint32_t))
        {
-               SIVAL(buf, i, sys_random());
+               SIVAL(buf, i, random());
        }
 
        if (procnum == 0)
@@ -415,7 +399,7 @@ static BOOL rw_torture3(struct smbcli_state *c, const char *lockfname)
 
                if (procnum == 0)
                {
-                       sent = ((uint_t)sys_random()%(20))+ 1;
+                       sent = ((uint_t)random()%(20))+ 1;
                        if (sent > sizeof(buf) - count)
                        {
                                sent = sizeof(buf) - count;
@@ -496,7 +480,7 @@ static BOOL rw_torture2(struct smbcli_state *c1, struct smbcli_state *c2)
 
        for (i=0;i<torture_numops;i++)
        {
-               size_t buf_size = ((uint_t)sys_random()%(sizeof(buf)-1))+ 1;
+               size_t buf_size = ((uint_t)random()%(sizeof(buf)-1))+ 1;
                if (i % 10 == 0) {
                        printf("%d\r", i); fflush(stdout);
                }
@@ -748,8 +732,6 @@ static BOOL tcon_devtest(struct smbcli_state *cli,
 static BOOL run_tcon_devtype_test(void)
 {
        struct smbcli_state *cli1 = NULL;
-       BOOL retry;
-       int flags = 0;
        NTSTATUS status;
        BOOL ret = True;
        const char *host = lp_parm_string(-1, "torture", "host");
@@ -760,10 +742,10 @@ static BOOL run_tcon_devtype_test(void)
        
        status = smbcli_full_connection(NULL,
                                        &cli1, lp_netbios_name(),
-                                       host, NULL, 
-                                       share, "?????",
+                                       host, 
+                                       share, NULL,
                                        username, userdomain,
-                                       password, flags, &retry);
+                                       password);
 
        if (!NT_STATUS_IS_OK(status)) {
                printf("could not open connection\n");
@@ -1057,7 +1039,7 @@ static BOOL run_negprot_nowait(void)
        for (i=0;i<10000;i++) {
                struct smbcli_request *req;
                time_t t1 = time(NULL);
-               req = smb_negprot_send(cli->transport, PROTOCOL_NT1);
+               req = smb_raw_negotiate_send(cli->transport, PROTOCOL_NT1);
                while (req->state == SMBCLI_REQUEST_SEND && time(NULL) < t1+5) {
                        smbcli_transport_process(cli->transport);
                }
@@ -2158,30 +2140,6 @@ BOOL torture_chkpath_test(void)
 }
 
 
-/*
-  parse a //server/share type UNC name
-*/
-static BOOL parse_unc(const char *unc_name, char **hostname, char **sharename)
-{
-       char *p;
-
-       if (strncmp(unc_name, "//", 2)) {
-               return False;
-       }
-
-       *hostname = strdup(&unc_name[2]);
-       p = strchr_m(&(*hostname)[2],'/');
-       if (!p) {
-               return False;
-       }
-       *p = 0;
-       *sharename = strdup(p+1);
-
-       return True;
-}
-
-
-
 static void sigcont(int sig)
 {
 }
@@ -2237,10 +2195,10 @@ double torture_create_procs(BOOL (*fn)(struct smbcli_state *, int), BOOL *result
                procnum = i;
                if (fork() == 0) {
                        char *myname;
-                       char *hostname=NULL, *sharename;
+                       const char *hostname=NULL, *sharename;
 
                        pid_t mypid = getpid();
-                       sys_srandom(((int)mypid) ^ ((int)time(NULL)));
+                       srandom(((int)mypid) ^ ((int)time(NULL)));
 
                        asprintf(&myname, "CLIENT%d", i);
                        lp_set_cmdline("netbios name", myname);
@@ -2248,8 +2206,8 @@ double torture_create_procs(BOOL (*fn)(struct smbcli_state *, int), BOOL *result
 
 
                        if (unc_list) {
-                               if (!parse_unc(unc_list[i % num_unc_names],
-                                              &hostname, &sharename)) {
+                               if (!smbcli_parse_unc(unc_list[i % num_unc_names],
+                                                     NULL, &hostname, &sharename)) {
                                        printf("Failed to parse UNC name %s\n",
                                               unc_list[i % num_unc_names]);
                                        exit(1);
@@ -2422,6 +2380,7 @@ static struct {
        {"SCAN-CASETABLE", torture_casetable, 0},
        {"SCAN-PIPE_NUMBER", run_pipe_number, 0},
        {"SCAN-IOCTL",  torture_ioctl_test, 0},
+       {"SCAN-RAP",  torture_rap_scan, 0},
 
        /* rpc testers */
         {"RPC-LSA", torture_rpc_lsa, 0},
@@ -2463,6 +2422,7 @@ static struct {
        {"LOCAL-MESSAGING", torture_local_messaging, 0},
        {"LOCAL-BINDING", torture_local_binding_string, 0},
        {"LOCAL-IDTREE", torture_local_idtree, 0},
+       {"LOCAL-SOCKET", torture_local_socket, 0},
 
        /* ldap testers */
        {"LDAP-BASIC", torture_ldap_basic, 0},
@@ -2749,9 +2709,9 @@ static BOOL is_binding_string(const char *binding_string)
                lp_set_cmdline("torture:binding", argv_new[1]);
        } else {
                char *binding = NULL;
-               char *host = NULL, *share = NULL;
+               const char *host = NULL, *share = NULL;
 
-               if (!parse_unc(argv_new[1], &host, &share)) {
+               if (!smbcli_parse_unc(argv_new[1], NULL, &host, &share)) {
                        d_printf("Invalid option: %s is not a valid torture target (share or binding string)\n\n", argv_new[1]);
                        usage(pc);
                }