r4777: added a smb_composite_sesssetup() async composite function. This
[gd/samba-autobuild/.git] / source4 / torture / raw / context.c
index 194d2de93ba14c2aa59243cbfebeaee361ba8c0d..4f1c6337eb9fa44ffc1135e50acb5f3e596bf3f5 100644 (file)
 */
 
 #include "includes.h"
+#include "libcli/raw/libcliraw.h"
+#include "librpc/gen_ndr/ndr_security.h"
+#include "libcli/composite/composite.h"
 
 #define BASEDIR "\\rawcontext"
 
 #define CHECK_STATUS(status, correct) do { \
        if (!NT_STATUS_EQUAL(status, correct)) { \
-               printf("(%d) Incorrect status %s - should be %s\n", \
-                      __LINE__, nt_errstr(status), nt_errstr(correct)); \
+               printf("(%s) Incorrect status %s - should be %s\n", \
+                      __location__, nt_errstr(status), nt_errstr(correct)); \
                ret = False; \
                goto done; \
        }} while (0)
 
 #define CHECK_VALUE(v, correct) do { \
        if ((v) != (correct)) { \
-               printf("(%d) Incorrect value %s=%d - should be %d\n", \
-                      __LINE__, #v, v, correct); \
+               printf("(%s) Incorrect value %s=%d - should be %d\n", \
+                      __location__, #v, v, correct); \
                ret = False; \
                goto done; \
        }} while (0)
 
 #define CHECK_NOT_VALUE(v, correct) do { \
        if ((v) == (correct)) { \
-               printf("(%d) Incorrect value %s=%d - should not be %d\n", \
-                      __LINE__, #v, v, correct); \
+               printf("(%s) Incorrect value %s=%d - should not be %d\n", \
+                      __location__, #v, v, correct); \
                ret = False; \
                goto done; \
        }} while (0)
@@ -59,19 +62,17 @@ static BOOL test_session(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        struct smbcli_session *session2;
        struct smbcli_session *session3;
        struct smbcli_tree *tree;
-       union smb_sesssetup setup;
+       struct smb_composite_sesssetup setup;
        union smb_open io;
        union smb_write wr;
        union smb_close cl;
        int fnum;
        const char *fname = BASEDIR "\\test.txt";
-       char c = 1;
+       uint8_t c = 1;
 
        printf("TESTING SESSION HANDLING\n");
 
-       if (smbcli_deltree(cli->tree, BASEDIR) == -1 ||
-           NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, BASEDIR))) {
-               printf("Unable to setup %s - %s\n", BASEDIR, smbcli_errstr(cli->tree));
+       if (!torture_setup_dir(cli, BASEDIR)) {
                return False;
        }
 
@@ -81,36 +82,32 @@ static BOOL test_session(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
 
        printf("create a second security context on the same transport\n");
        session = smbcli_session_init(cli->transport);
-       talloc_increase_ref_count(cli->transport);
 
-       setup.generic.level = RAW_SESSSETUP_GENERIC;
-       setup.generic.in.sesskey = cli->transport->negotiate.sesskey;
-       setup.generic.in.capabilities = cli->transport->negotiate.capabilities; /* ignored in secondary session setup, except by our libs, which care about the extended security bit */
-       setup.generic.in.password = password;
-       setup.generic.in.user = username;
-       setup.generic.in.domain = domain;
+       setup.in.sesskey = cli->transport->negotiate.sesskey;
+       setup.in.capabilities = cli->transport->negotiate.capabilities; /* ignored in secondary session setup, except by our libs, which care about the extended security bit */
+       setup.in.password = password;
+       setup.in.user = username;
+       setup.in.domain = domain;
 
-       status = smb_raw_session_setup(session, mem_ctx, &setup);
+       status = smb_composite_sesssetup(session, &setup);
        CHECK_STATUS(status, NT_STATUS_OK);
 
-       session->vuid = setup.generic.out.vuid;
+       session->vuid = setup.out.vuid;
 
        printf("create a third security context on the same transport, with vuid set\n");
        session2 = smbcli_session_init(cli->transport);
-       talloc_increase_ref_count(cli->transport);
 
        session2->vuid = session->vuid;
-       setup.generic.level = RAW_SESSSETUP_GENERIC;
-       setup.generic.in.sesskey = cli->transport->negotiate.sesskey;
-       setup.generic.in.capabilities = cli->transport->negotiate.capabilities; /* ignored in secondary session setup, except by our libs, which care about the extended security bit */
-       setup.generic.in.password = password;
-       setup.generic.in.user = username;
-       setup.generic.in.domain = domain;
-
-       status = smb_raw_session_setup(session2, mem_ctx, &setup);
+       setup.in.sesskey = cli->transport->negotiate.sesskey;
+       setup.in.capabilities = cli->transport->negotiate.capabilities; /* ignored in secondary session setup, except by our libs, which care about the extended security bit */
+       setup.in.password = password;
+       setup.in.user = username;
+       setup.in.domain = domain;
+
+       status = smb_composite_sesssetup(session2, &setup);
        CHECK_STATUS(status, NT_STATUS_OK);
 
-       session2->vuid = setup.generic.out.vuid;
+       session2->vuid = setup.out.vuid;
        printf("vuid1=%d vuid2=%d vuid3=%d\n", cli->session->vuid, session->vuid, session2->vuid);
        
        CHECK_NOT_VALUE(session->vuid, session2->vuid);
@@ -119,17 +116,15 @@ static BOOL test_session(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        if (cli->transport->negotiate.capabilities & CAP_EXTENDED_SECURITY) {
                printf("create a fourth security context on the same transport, without extended security\n");
                session3 = smbcli_session_init(cli->transport);
-               talloc_increase_ref_count(cli->transport);
 
                session3->vuid = session->vuid;
-               setup.generic.level = RAW_SESSSETUP_GENERIC;
-               setup.generic.in.sesskey = cli->transport->negotiate.sesskey;
-               setup.generic.in.capabilities = 0; /* force a non extended security login (should fail) */
-               setup.generic.in.password = password;
-               setup.generic.in.user = username;
-               setup.generic.in.domain = domain;
-
-               status = smb_raw_session_setup(session3, mem_ctx, &setup);
+               setup.in.sesskey = cli->transport->negotiate.sesskey;
+               setup.in.capabilities = 0; /* force a non extended security login (should fail) */
+               setup.in.password = password;
+               setup.in.user = username;
+               setup.in.domain = domain;
+
+               status = smb_composite_sesssetup(session3, &setup);
                CHECK_STATUS(status, NT_STATUS_ACCESS_DENIED);
 
                talloc_free(session3);
@@ -137,14 +132,13 @@ static BOOL test_session(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
                
        printf("use the same tree as the existing connection\n");
        tree = smbcli_tree_init(session);
-       talloc_increase_ref_count(session);
        tree->tid = cli->tree->tid;
 
        printf("create a file using the new vuid\n");
        io.generic.level = RAW_OPEN_NTCREATEX;
        io.ntcreatex.in.root_fid = 0;
        io.ntcreatex.in.flags = 0;
-       io.ntcreatex.in.access_mask = SEC_RIGHT_MAXIMUM_ALLOWED;
+       io.ntcreatex.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
        io.ntcreatex.in.create_options = 0;
        io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
        io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
@@ -190,8 +184,6 @@ static BOOL test_session(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        status = smb_raw_close(cli->tree, &cl);
        CHECK_STATUS(status, NT_STATUS_INVALID_HANDLE);
 
-       /* close down the new tree, which will also close the session
-          as the reference count will be 0 */
        talloc_free(tree);
        
 done:
@@ -214,13 +206,11 @@ static BOOL test_tree(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        union smb_close cl;
        int fnum;
        const char *fname = BASEDIR "\\test.txt";
-       char c = 1;
+       uint8_t c = 1;
 
        printf("TESTING TREE HANDLING\n");
 
-       if (smbcli_deltree(cli->tree, BASEDIR) == -1 ||
-           NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, BASEDIR))) {
-               printf("Unable to setup %s - %s\n", BASEDIR, smbcli_errstr(cli->tree));
+       if (!torture_setup_dir(cli, BASEDIR)) {
                return False;
        }
 
@@ -228,7 +218,6 @@ static BOOL test_tree(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        
        printf("create a second tree context on the same session\n");
        tree = smbcli_tree_init(cli->session);
-       talloc_increase_ref_count(cli->session);
 
        tcon.generic.level = RAW_TCON_TCONX;
        tcon.tconx.in.flags = 0;
@@ -238,7 +227,7 @@ static BOOL test_tree(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        status = smb_tree_connect(tree, mem_ctx, &tcon);
        CHECK_STATUS(status, NT_STATUS_OK);
 
-       tree->tid = tcon.tconx.out.cnum;
+       tree->tid = tcon.tconx.out.tid;
        printf("tid1=%d tid2=%d\n", cli->tree->tid, tree->tid);
 
        printf("try a tconx with a bad device type\n");
@@ -251,7 +240,7 @@ static BOOL test_tree(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        io.generic.level = RAW_OPEN_NTCREATEX;
        io.ntcreatex.in.root_fid = 0;
        io.ntcreatex.in.flags = 0;
-       io.ntcreatex.in.access_mask = SEC_RIGHT_MAXIMUM_ALLOWED;
+       io.ntcreatex.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
        io.ntcreatex.in.create_options = 0;
        io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
        io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
@@ -316,14 +305,12 @@ static BOOL test_pid(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        union smb_close cl;
        int fnum;
        const char *fname = BASEDIR "\\test.txt";
-       char c = 1;
+       uint8_t c = 1;
        uint16_t pid1, pid2;
 
        printf("TESTING PID HANDLING\n");
 
-       if (smbcli_deltree(cli->tree, BASEDIR) == -1 ||
-           NT_STATUS_IS_ERR(smbcli_mkdir(cli->tree, BASEDIR))) {
-               printf("Unable to setup %s - %s\n", BASEDIR, smbcli_errstr(cli->tree));
+       if (!torture_setup_dir(cli, BASEDIR)) {
                return False;
        }
 
@@ -338,7 +325,7 @@ static BOOL test_pid(struct smbcli_state *cli, TALLOC_CTX *mem_ctx)
        io.generic.level = RAW_OPEN_NTCREATEX;
        io.ntcreatex.in.root_fid = 0;
        io.ntcreatex.in.flags = 0;
-       io.ntcreatex.in.access_mask = SEC_RIGHT_MAXIMUM_ALLOWED;
+       io.ntcreatex.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
        io.ntcreatex.in.create_options = 0;
        io.ntcreatex.in.file_attr = FILE_ATTRIBUTE_NORMAL;
        io.ntcreatex.in.share_access = NTCREATEX_SHARE_ACCESS_READ | NTCREATEX_SHARE_ACCESS_WRITE;
@@ -407,12 +394,14 @@ done:
 /* 
    basic testing of session/tree context calls
 */
-BOOL torture_raw_context(int dummy)
+BOOL torture_raw_context(void)
 {
        struct smbcli_state *cli;
        BOOL ret = True;
        TALLOC_CTX *mem_ctx;
 
+       lp_set_cmdline("use spnego", "False");
+
        if (!torture_open_connection(&cli)) {
                return False;
        }