r26644: Janitorial: Pass resolve_context explicitly to various SMB functions, should...
[jelmer/samba4-debian.git] / source / torture / unix / whoami.c
index 8322e57bd1ff58f0713a24de3491fcf99556993a..4477713bfedaef3a32f9cff26d48bd4a0c1ca0c8 100644 (file)
@@ -24,6 +24,8 @@
 #include "libcli/raw/interfaces.h"
 #include "lib/cmdline/popt_common.h"
 #include "auth/credentials/credentials.h"
+#include "param/param.h"
+#include "libcli/resolve/resolve.h"
 
 /* Size (in bytes) of the required fields in the SMBwhoami response. */
 #define WHOAMI_REQUIRED_SIZE   40
@@ -65,18 +67,20 @@ struct smb_whoami
        struct dom_sid ** sid_list;
 };
 
-static struct smbcli_state *connect_to_server(void *mem_ctx,
+static struct smbcli_state *connect_to_server(struct torture_context *tctx,
                struct cli_credentials *creds)
 {
        NTSTATUS status;
        struct smbcli_state *cli;
 
-       const char *host = lp_parm_string(-1, "torture", "host");
-       const char *share = lp_parm_string(-1, "torture", "share");
+       const char *host = torture_setting_string(tctx, "host", NULL);
+       const char *share = torture_setting_string(tctx, "share", NULL);
 
-       status = smbcli_full_connection(mem_ctx, &cli,
-                                       host, share, NULL,
-                                       creds, NULL);
+       status = smbcli_full_connection(tctx, &cli, host, 
+                                       lp_smb_ports(tctx->lp_ctx),
+                                       share, NULL,
+                                       creds, lp_resolve_context(tctx->lp_ctx),
+                                       NULL);
 
        if (!NT_STATUS_IS_OK(status)) {
                printf("failed to connect to //%s/%s: %s\n",
@@ -87,7 +91,7 @@ static struct smbcli_state *connect_to_server(void *mem_ctx,
        return cli;
 }
 
-static BOOL sid_parse(void *mem_ctx,
+static bool sid_parse(void *mem_ctx,
                struct torture_context *torture,
                DATA_BLOB *data, size_t *offset,
                struct dom_sid **psid)
@@ -125,10 +129,10 @@ static BOOL sid_parse(void *mem_ctx,
                (*offset) += 4;
        }
 
-       return True;
+       return true;
 }
 
-static BOOL smb_raw_query_posix_whoami(void *mem_ctx,
+static bool smb_raw_query_posix_whoami(void *mem_ctx,
                                struct torture_context *torture,
                                struct smbcli_state *cli,
                                struct smb_whoami *whoami,
@@ -204,7 +208,7 @@ static BOOL smb_raw_query_posix_whoami(void *mem_ctx,
                                "invalid SID count");
                torture_assert_int_equal(torture, whoami->num_sid_bytes, 0,
                                "invalid SID byte count");
-               return True;
+               return true;
        }
 
        if (whoami->num_gids != 0) {
@@ -232,7 +236,7 @@ static BOOL smb_raw_query_posix_whoami(void *mem_ctx,
        if (tp.out.data.length == offset) {
                torture_assert_int_equal(torture, whoami->num_sids, 0,
                                "invalid SID count");
-               return True;
+               return true;
        }
 
        /* All the remaining bytes must be the SID list. */
@@ -251,7 +255,7 @@ static BOOL smb_raw_query_posix_whoami(void *mem_ctx,
                        if (!sid_parse(mem_ctx, torture,
                                        &tp.out.data, &offset,
                                        &whoami->sid_list[i])) {
-                               return False;
+                               return false;
                        }
 
                }
@@ -261,37 +265,33 @@ static BOOL smb_raw_query_posix_whoami(void *mem_ctx,
        torture_assert_int_equal(torture, tp.out.data.length, offset,
                        "trailing garbage bytes");
 
-       return True;
+       return true;
 }
 
-BOOL torture_unix_whoami(struct torture_context *torture)
+bool torture_unix_whoami(struct torture_context *torture)
 {
        struct smbcli_state *cli;
        struct cli_credentials *anon_credentials;
        struct smb_whoami whoami;
-       void *mem_ctx;
 
-       mem_ctx = talloc_init("smb_query_posix_whoami");
-       torture_assert(torture, mem_ctx != NULL, "malloc failed");
-
-       if (!(cli = connect_to_server(mem_ctx, cmdline_credentials))) {
-               goto fail;
+       if (!(cli = connect_to_server(torture, cmdline_credentials))) {
+               return false;
        }
 
        /* Test basic authenticated mapping. */
        printf("calling SMB_QFS_POSIX_WHOAMI on an authenticated connection\n");
-       if (!smb_raw_query_posix_whoami(mem_ctx, torture,
+       if (!smb_raw_query_posix_whoami(torture, torture,
                                cli, &whoami, 0xFFFF)) {
                smbcli_tdis(cli);
-               goto fail;
+               return false;
        }
 
        /* Test that the server drops the UID and GID list. */
        printf("calling SMB_QFS_POSIX_WHOAMI with a small buffer\n");
-       if (!smb_raw_query_posix_whoami(mem_ctx, torture,
+       if (!smb_raw_query_posix_whoami(torture, torture,
                                cli, &whoami, 0x40)) {
                smbcli_tdis(cli);
-               goto fail;
+               return false;
        }
 
        torture_assert_int_equal(torture, whoami.num_gids, 0,
@@ -304,16 +304,16 @@ BOOL torture_unix_whoami(struct torture_context *torture)
        smbcli_tdis(cli);
 
        printf("calling SMB_QFS_POSIX_WHOAMI on an anonymous connection\n");
-       anon_credentials = cli_credentials_init_anon(mem_ctx);
+       anon_credentials = cli_credentials_init_anon(torture);
 
-       if (!(cli = connect_to_server(mem_ctx, anon_credentials))) {
-               goto fail;
+       if (!(cli = connect_to_server(torture, anon_credentials))) {
+               return false;
        }
 
-       if (!smb_raw_query_posix_whoami(mem_ctx, torture,
+       if (!smb_raw_query_posix_whoami(torture, torture,
                                cli, &whoami, 0xFFFF)) {
                smbcli_tdis(cli);
-               goto fail;
+               return false;
        }
 
        smbcli_tdis(cli);
@@ -330,13 +330,7 @@ BOOL torture_unix_whoami(struct torture_context *torture)
                printf("server does not support SMB_WHOAMI_GUEST flag\n");
        }
 
-       talloc_free(mem_ctx);
-       return True;
-
-fail:
-       talloc_free(mem_ctx);
-       return False;
-
+       return true;
 }
 
 /* vim: set sts=8 sw=8 : */