s3: Convert cli_dfs_get_referral to cli_trans
authorVolker Lendecke <vl@samba.org>
Thu, 11 Nov 2010 13:54:25 +0000 (14:54 +0100)
committerVolker Lendecke <vlendec@samba.org>
Thu, 11 Nov 2010 16:16:24 +0000 (16:16 +0000)
source3/include/proto.h
source3/libsmb/clidfs.c

index 38c5a6d8fab2d6b1aefd8812a3608dcddc1fc849..10468be312caab4b2d3ab8e5484e7a0cb03bf2a3 100644 (file)
@@ -1689,7 +1689,7 @@ struct cli_state *cli_cm_open(TALLOC_CTX *ctx,
                                int port,
                                int name_type);
 void cli_cm_display(const struct cli_state *c);
-bool cli_dfs_get_referral(TALLOC_CTX *ctx,
+NTSTATUS cli_dfs_get_referral(TALLOC_CTX *ctx,
                        struct cli_state *cli,
                        const char *path,
                        struct client_dfs_referral **refs,
index 97c1e0407cc8a367d14dfcbd9a946c27ee63f10b..1c879884fe1ca6cbea9ed1c946ff33856e6de0a6 100644 (file)
@@ -618,7 +618,7 @@ static bool cli_dfs_check_error(struct cli_state *cli, NTSTATUS expected,
  Get the dfs referral link.
 ********************************************************************/
 
-bool cli_dfs_get_referral(TALLOC_CTX *ctx,
+NTSTATUS cli_dfs_get_referral(TALLOC_CTX *ctx,
                        struct cli_state *cli,
                        const char *path,
                        struct client_dfs_referral **refs,
@@ -627,9 +627,9 @@ bool cli_dfs_get_referral(TALLOC_CTX *ctx,
 {
        unsigned int data_len = 0;
        unsigned int param_len = 0;
-       uint16 setup = TRANSACT2_GET_DFS_REFERRAL;
-       char *param = NULL;
-       char *rparam=NULL, *rdata=NULL;
+       uint16 setup[1];
+       uint8_t *param = NULL;
+       uint8_t *rdata = NULL;
        char *p;
        char *endp;
        size_t pathlen = 2*(strlen(path)+1);
@@ -638,43 +638,42 @@ bool cli_dfs_get_referral(TALLOC_CTX *ctx,
        uint16_t consumed_ucs;
        uint16 num_referrals;
        struct client_dfs_referral *referrals = NULL;
-       bool ret = false;
+       NTSTATUS status;
 
        *num_refs = 0;
        *refs = NULL;
 
-       param = SMB_MALLOC_ARRAY(char, 2+pathlen+2);
+       SSVAL(setup, 0, TRANSACT2_GET_DFS_REFERRAL);
+
+       param = SMB_MALLOC_ARRAY(uint8_t, 2+pathlen+2);
        if (!param) {
+               status = NT_STATUS_NO_MEMORY;
                goto out;
        }
        SSVAL(param, 0, 0x03);  /* max referral level */
-       p = &param[2];
+       p = (char *)(&param[2]);
 
        path_ucs = (smb_ucs2_t *)p;
        p += clistr_push(cli, p, path, pathlen, STR_TERMINATE);
        param_len = PTR_DIFF(p, param);
 
-       if (!cli_send_trans(cli, SMBtrans2,
-                       NULL,                        /* name */
-                       -1, 0,                          /* fid, flags */
-                       &setup, 1, 0,                   /* setup, length, max */
-                       param, param_len, 2,            /* param, length, max */
-                       NULL, 0, cli->max_xmit /* data, length, max */
-                       )) {
-               goto out;
-       }
-
-       if (!cli_receive_trans(cli, SMBtrans2,
-               &rparam, &param_len,
-               &rdata, &data_len)) {
+       status = cli_trans(talloc_tos(), cli, SMBtrans2,
+                          NULL, 0xffff, 0, 0,
+                          setup, 1, 0,
+                          param, param_len, 2,
+                          NULL, 0, cli->max_xmit,
+                          NULL,
+                          NULL, 0, NULL, /* rsetup */
+                          NULL, 0, NULL,
+                          &rdata, 4, &data_len);
+       if (!NT_STATUS_IS_OK(status)) {
                goto out;
        }
-
        if (data_len < 4) {
                goto out;
        }
 
-       endp = rdata + data_len;
+       endp = (char *)rdata + data_len;
 
        consumed_ucs  = SVAL(rdata, 0);
        num_referrals = SVAL(rdata, 2);
@@ -714,7 +713,7 @@ bool cli_dfs_get_referral(TALLOC_CTX *ctx,
                }
                /* start at the referrals array */
 
-               p = rdata+8;
+               p = (char *)rdata+8;
                for (i=0; i<num_referrals && p < endp; i++) {
                        if (p + 18 > endp) {
                                goto out;
@@ -750,8 +749,6 @@ bool cli_dfs_get_referral(TALLOC_CTX *ctx,
                }
        }
 
-       ret = true;
-
        *num_refs = num_referrals;
        *refs = referrals;
 
@@ -759,9 +756,8 @@ bool cli_dfs_get_referral(TALLOC_CTX *ctx,
 
        TALLOC_FREE(consumed_path);
        SAFE_FREE(param);
-       SAFE_FREE(rdata);
-       SAFE_FREE(rparam);
-       return ret;
+       TALLOC_FREE(rdata);
+       return status;
 }
 
 /********************************************************************
@@ -867,8 +863,9 @@ bool cli_resolve_path(TALLOC_CTX *ctx,
                return false;
        }
 
-       if (!cli_dfs_get_referral(ctx, cli_ipc, dfs_path, &refs,
-                       &num_refs, &consumed) || !num_refs) {
+       status = cli_dfs_get_referral(ctx, cli_ipc, dfs_path, &refs,
+                                     &num_refs, &consumed);
+       if (!NT_STATUS_IS_OK(status) || !num_refs) {
                return false;
        }
 
@@ -1054,7 +1051,9 @@ bool cli_check_msdfs_proxy(TALLOC_CTX *ctx,
                }
        }
 
-       res = cli_dfs_get_referral(ctx, cli, fullpath, &refs, &num_refs, &consumed);
+       status = cli_dfs_get_referral(ctx, cli, fullpath, &refs,
+                                     &num_refs, &consumed);
+       res = NT_STATUS_IS_OK(status);
 
        status = cli_tdis(cli);
        if (!NT_STATUS_IS_OK(status)) {