s3-talloc Change TALLOC_ARRAY() to talloc_array()
[samba.git] / source3 / torture / torture.c
index 6afa94b3b21e9421b9ba09c4a4b1610f2e52d0d5..0904f24356be8a4304c5c18a37fe7f6d96c7e384 100644 (file)
@@ -211,6 +211,8 @@ static bool cli_bad_session_request(int fd,
        uint8_t *inbuf;
        int err;
        bool ret = false;
+       uint8_t message_type;
+       uint8_t error;
 
        frame = talloc_stackframe();
 
@@ -262,8 +264,23 @@ static bool cli_bad_session_request(int fd,
                goto fail;
        }
 
-        if (CVAL(inbuf,0) != 0x82) {
-                /* This is the wrong place to put the error... JRA. */
+       message_type = CVAL(inbuf, 0);
+       if (message_type != 0x83) {
+               d_fprintf(stderr, "Expected msg type 0x83, got 0x%2.2x\n",
+                         message_type);
+               goto fail;
+        }
+
+       if (smb_len(inbuf) != 1) {
+               d_fprintf(stderr, "Expected smb_len 1, got %d\n",
+                         (int)smb_len(inbuf));
+               goto fail;
+        }
+
+       error = CVAL(inbuf, 4);
+       if (error !=  0x82) {
+               d_fprintf(stderr, "Expected error 0x82, got %d\n",
+                         (int)error);
                goto fail;
         }
 
@@ -273,42 +290,6 @@ fail:
         return ret;
 }
 
-static struct cli_state *open_bad_nbt_connection(void)
-{
-       struct nmb_name called, calling;
-       struct sockaddr_storage ss;
-       struct cli_state *c;
-       NTSTATUS status;
-
-       make_nmb_name(&calling, myname, 0x0);
-       make_nmb_name(&called , host, 0x20);
-
-        zero_sockaddr(&ss);
-
-       if (!(c = cli_initialise_ex(signing_state))) {
-               printf("Failed initialize cli_struct to connect with %s\n", host);
-               return NULL;
-       }
-
-       c->port = 139;
-
-       status = cli_connect(c, host, &ss);
-       if (!NT_STATUS_IS_OK(status)) {
-               printf("Failed to connect with %s. Error %s\n", host, nt_errstr(status) );
-               return NULL;
-       }
-
-       c->timeout = 4000; /* set a short timeout (4 seconds) */
-
-       if (!cli_bad_session_request(c->fd, &calling, &called)) {
-               printf("Failed to connect with %s. Error %s\n", host, nt_errstr(status) );
-               return NULL;
-       }
-
-       return c;
-}
-
-
 /* Insert a NULL at the first separator of the given path and return a pointer
  * to the remainder of the string.
  */
@@ -2906,15 +2887,37 @@ static bool run_negprot_nowait(int dummy)
 /* send smb negprot commands, not reading the response */
 static bool run_bad_nbt_session(int dummy)
 {
-       static struct cli_state *cli;
+       struct nmb_name called, calling;
+       struct sockaddr_storage ss;
+       NTSTATUS status;
+       int fd;
+       bool ret;
 
        printf("starting bad nbt session test\n");
 
-       if (!(cli = open_bad_nbt_connection())) {
-               return False;
+       make_nmb_name(&calling, myname, 0x0);
+       make_nmb_name(&called , host, 0x20);
+
+       if (!resolve_name(host, &ss, 0x20, true)) {
+               d_fprintf(stderr, "Could not resolve name %s\n", host);
+               return false;
+       }
+
+       status = open_socket_out(&ss, 139, 10000, &fd);
+       if (!NT_STATUS_IS_OK(status)) {
+               d_fprintf(stderr, "open_socket_out failed: %s\n",
+                         nt_errstr(status));
+               return false;
+       }
+
+       ret = cli_bad_session_request(fd, &calling, &called);
+       close(fd);
+       if (!ret) {
+               d_fprintf(stderr, "open_socket_out failed: %s\n",
+                         nt_errstr(status));
+               return false;
        }
 
-       cli_shutdown(cli);
        printf("finished bad nbt session test\n");
        return true;
 }
@@ -8201,7 +8204,7 @@ static bool run_local_wbclient(int dummy)
                goto fail;
        }
 
-       wb_ctx = TALLOC_ARRAY(ev, struct wb_context *, nprocs);
+       wb_ctx = talloc_array(ev, struct wb_context *, nprocs);
        if (wb_ctx == NULL) {
                goto fail;
        }