r21668: Add SMB_QFS_POSIX_WHOAMI to trans2.h so it's easy to find. Add
authorJames Peach <jpeach@samba.org>
Fri, 2 Mar 2007 23:24:27 +0000 (23:24 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 19:49:07 +0000 (14:49 -0500)
convenience API to create an anonymous credential. Don't clobber
cmdline_credentials in the UNIX-WHOAMI test.
(This used to be commit 73cea4e0c66f57057ed12b07bbb94b4e783ba6bf)

source4/auth/credentials/credentials.c
source4/libcli/raw/trans2.h
source4/torture/rpc/srvsvc.c
source4/torture/unix/whoami.c

index 38bd701b7684666397b89afd72b373ea0f6144a0..6f740d95c30ac52dab92230c0202f59a7d3f545a 100644 (file)
@@ -68,6 +68,21 @@ struct cli_credentials *cli_credentials_init(TALLOC_CTX *mem_ctx)
        return cred;
 }
 
+/**
+ * Create a new anonymous credential
+ * @param mem_ctx TALLOC_CTX parent for credentials structure 
+ */
+struct cli_credentials *cli_credentials_init_anon(TALLOC_CTX *mem_ctx) 
+{
+       struct cli_credentials *anon_credentials;
+
+       anon_credentials = cli_credentials_init(mem_ctx);
+       cli_credentials_set_conf(anon_credentials);
+       cli_credentials_set_anonymous(anon_credentials);
+
+       return anon_credentials;
+}
+
 void cli_credentials_set_kerberos_state(struct cli_credentials *creds, 
                                        enum credentials_use_kerberos use_kerberos)
 {
index a3f6e28a2afafd7561191bb6512b5e3ffd0592bf..bdc5bb216846c3e830bb17372134ca5744764460 100644 (file)
@@ -74,6 +74,7 @@ Found 4 aliased levels
 #define SMB_QFS_ATTRIBUTE_INFO                         0x105
 #define SMB_QFS_UNIX_INFO                              0x200
 #define SMB_QFS_POSIX_INFO                             0x201
+#define SMB_QFS_POSIX_WHOAMI                           0x202
 #define SMB_QFS_VOLUME_INFORMATION                     1001
 #define SMB_QFS_SIZE_INFORMATION                       1003
 #define SMB_QFS_DEVICE_INFORMATION                     1004
index f024d1d2abe594960d9e9050ee3d944fa2c397a9..274f266ea0973a9c32b0c164bed2cbb5e76e25dd 100644 (file)
@@ -1125,9 +1125,7 @@ BOOL torture_rpc_srvsvc(struct torture_context *torture)
                return False;
        }
 
-       anon_credentials = cli_credentials_init(mem_ctx);
-       cli_credentials_set_conf(anon_credentials);
-       cli_credentials_set_anonymous(anon_credentials);
+       anon_credentials = cli_credentials_init_anon(mem_ctx);
 
        status = dcerpc_pipe_connect(mem_ctx, 
                                     &p, binding, &dcerpc_table_srvsvc,
index 25f9b11beead6f42e4cc7cc3d66fbc2ecba8537a..4e846ffdcc68d7e2eb50d71fdeb9c67f36cb335b 100644 (file)
@@ -26,8 +26,6 @@
 #include "lib/cmdline/popt_common.h"
 #include "auth/credentials/credentials.h"
 
-#define SMB_QUERY_POSIX_WHOAMI     0x202
-
 /* Size (in bytes) of the required fields in the SMBwhoami response. */
 #define WHOAMI_REQUIRED_SIZE   40
 
@@ -68,7 +66,8 @@ 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(void *mem_ctx,
+               struct cli_credentials *creds)
 {
        NTSTATUS status;
        struct smbcli_state *cli;
@@ -78,7 +77,7 @@ static struct smbcli_state *connect_to_server(void *mem_ctx)
 
        status = smbcli_full_connection(mem_ctx, &cli,
                                        host, share, NULL,
-                                       cmdline_credentials, NULL);
+                                       creds, NULL);
 
        if (!NT_STATUS_IS_OK(status)) {
                printf("failed to connect to //%s/%s: %s\n",
@@ -154,13 +153,13 @@ static BOOL smb_raw_query_posix_whoami(void *mem_ctx,
        tp.in.max_data = (uint16_t)max_data;
        tp.in.setup = &setup;
        tp.in.trans_name = NULL;
-       SSVAL(&info_level, 0, SMB_QUERY_POSIX_WHOAMI);
+       SSVAL(&info_level, 0, SMB_QFS_POSIX_WHOAMI);
        tp.in.params = data_blob_talloc(mem_ctx, &info_level, 2);
        tp.in.data = data_blob_talloc(mem_ctx, NULL, 0);
 
        status = smb_raw_trans2(cli->tree, mem_ctx, &tp);
        torture_assert_ntstatus_equal(torture, status, NT_STATUS_OK,
-                       "doing SMB_QUERY_POSIX_WHOAMI");
+                       "doing SMB_QFS_POSIX_WHOAMI");
 
        /* Make sure we got back all the required fields. */
        torture_assert(torture, tp.out.params.length == 0,
@@ -269,18 +268,19 @@ static BOOL smb_raw_query_posix_whoami(void *mem_ctx,
 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))) {
+       if (!(cli = connect_to_server(mem_ctx, cmdline_credentials))) {
                goto fail;
        }
 
        /* Test basic authenticated mapping. */
-       printf("calling SMB_QUERY_POSIX_WHOAMI on an authenticated connection\n");
+       printf("calling SMB_QFS_POSIX_WHOAMI on an authenticated connection\n");
        if (!smb_raw_query_posix_whoami(mem_ctx, torture,
                                cli, &whoami, 0xFFFF)) {
                smbcli_tdis(cli);
@@ -288,7 +288,7 @@ BOOL torture_unix_whoami(struct torture_context *torture)
        }
 
        /* Test that the server drops the UID and GID list. */
-       printf("calling SMB_QUERY_POSIX_WHOAMI with a small buffer\n");
+       printf("calling SMB_QFS_POSIX_WHOAMI with a small buffer\n");
        if (!smb_raw_query_posix_whoami(mem_ctx, torture,
                                cli, &whoami, 0x40)) {
                smbcli_tdis(cli);
@@ -303,13 +303,14 @@ BOOL torture_unix_whoami(struct torture_context *torture)
                        "invalid SID bytes count");
 
        smbcli_tdis(cli);
-       cli_credentials_set_anonymous(cmdline_credentials);
 
-       if (!(cli = connect_to_server(mem_ctx))) {
+       printf("calling SMB_QFS_POSIX_WHOAMI on an anonymous connection\n");
+       anon_credentials = cli_credentials_init_anon(mem_ctx);
+
+       if (!(cli = connect_to_server(mem_ctx, anon_credentials))) {
                goto fail;
        }
 
-       printf("calling SMB_QUERY_POSIX_WHOAMI on an anonymous connection\n");
        if (!smb_raw_query_posix_whoami(mem_ctx, torture,
                                cli, &whoami, 0xFFFF)) {
                smbcli_tdis(cli);