s3: Make cli_cm_open return NTSTATUS
authorVolker Lendecke <vl@samba.org>
Sun, 3 Jul 2011 17:59:37 +0000 (19:59 +0200)
committerVolker Lendecke <vlendec@samba.org>
Sun, 3 Jul 2011 21:57:53 +0000 (23:57 +0200)
Autobuild-User: Volker Lendecke <vlendec@samba.org>
Autobuild-Date: Sun Jul  3 23:57:53 CEST 2011 on sn-devel-104

source3/client/client.c
source3/lib/netapi/cm.c
source3/libsmb/clidfs.c
source3/libsmb/proto.h

index 94c7e98ab329ba2457b6b9e2bd7c4e09eecc00e9..bc653d5ec725d5e70c2f68de99ae88fc1f826bb1 100644 (file)
@@ -4466,12 +4466,15 @@ static int process_command_string(const char *cmd_in)
        /* establish the connection if not already */
 
        if (!cli) {
-               cli = cli_cm_open(talloc_tos(), NULL,
-                               have_ip ? dest_ss_str : desthost,
-                               service, auth_info,
-                               true, smb_encrypt,
-                               max_protocol, port, name_type);
-               if (!cli) {
+               NTSTATUS status;
+
+               status = cli_cm_open(talloc_tos(), NULL,
+                                    have_ip ? dest_ss_str : desthost,
+                                    service, auth_info,
+                                    true, smb_encrypt,
+                                    max_protocol, port, name_type,
+                                    &cli);
+               if (!NT_STATUS_IS_OK(status)) {
                        return 1;
                }
        }
@@ -4938,12 +4941,13 @@ static int process_stdin(void)
 static int process(const char *base_directory)
 {
        int rc = 0;
+       NTSTATUS status;
 
-       cli = cli_cm_open(talloc_tos(), NULL,
-                       have_ip ? dest_ss_str : desthost,
-                       service, auth_info, true, smb_encrypt,
-                       max_protocol, port, name_type);
-       if (!cli) {
+       status = cli_cm_open(talloc_tos(), NULL,
+                            have_ip ? dest_ss_str : desthost,
+                            service, auth_info, true, smb_encrypt,
+                            max_protocol, port, name_type, &cli);
+       if (!NT_STATUS_IS_OK(status)) {
                return 1;
        }
 
@@ -4971,11 +4975,15 @@ static int process(const char *base_directory)
 
 static int do_host_query(const char *query_host)
 {
-       cli = cli_cm_open(talloc_tos(), NULL,
-                       have_ip ? dest_ss_str : query_host, "IPC$", auth_info, true, smb_encrypt,
-                       max_protocol, port, name_type);
-       if (!cli)
+       NTSTATUS status;
+
+       status = cli_cm_open(talloc_tos(), NULL,
+                            have_ip ? dest_ss_str : query_host,
+                            "IPC$", auth_info, true, smb_encrypt,
+                            max_protocol, port, name_type, &cli);
+       if (!NT_STATUS_IS_OK(status)) {
                return 1;
+       }
 
        browse_host(true);
 
@@ -4997,10 +5005,13 @@ static int do_host_query(const char *query_host)
                   else but port 139... */
 
                cli_shutdown(cli);
-               cli = cli_cm_open(talloc_tos(), NULL,
-                               have_ip ? dest_ss_str : query_host, "IPC$",
-                               auth_info, true, smb_encrypt,
-                               max_protocol, 139, name_type);
+               status = cli_cm_open(talloc_tos(), NULL,
+                                    have_ip ? dest_ss_str : query_host,
+                                    "IPC$", auth_info, true, smb_encrypt,
+                                    max_protocol, 139, name_type, &cli);
+               if (!NT_STATUS_IS_OK(status)) {
+                       cli = NULL;
+               }
        }
 
        if (cli == NULL) {
@@ -5025,12 +5036,15 @@ static int do_tar_op(const char *base_directory)
 
        /* do we already have a connection? */
        if (!cli) {
-               cli = cli_cm_open(talloc_tos(), NULL,
-                       have_ip ? dest_ss_str : desthost,
-                       service, auth_info, true, smb_encrypt,
-                       max_protocol, port, name_type);
-               if (!cli)
+               NTSTATUS status;
+
+               status = cli_cm_open(talloc_tos(), NULL,
+                                    have_ip ? dest_ss_str : desthost,
+                                    service, auth_info, true, smb_encrypt,
+                                    max_protocol, port, name_type, &cli);
+               if (!NT_STATUS_IS_OK(status)) {
                        return 1;
+               }
        }
 
        recurse=true;
index 47ccf8bb7a32fe137a636038eff08f1cb1b2ef50..d41a5caf5a519b13cb1e204b73099c0a8756618a 100644 (file)
@@ -67,6 +67,7 @@ static WERROR libnetapi_open_ipc_connection(struct libnetapi_ctx *ctx,
        struct user_auth_info *auth_info = NULL;
        struct cli_state *cli_ipc = NULL;
        struct client_ipc_connection *p;
+       NTSTATUS status;
 
        if (!ctx || !pp || !server_name) {
                return WERR_INVALID_PARAM;
@@ -103,16 +104,18 @@ static WERROR libnetapi_open_ipc_connection(struct libnetapi_ctx *ctx,
                set_cmdline_auth_info_use_ccache(auth_info, true);
        }
 
-       cli_ipc = cli_cm_open(ctx, NULL,
-                               server_name, "IPC$",
-                               auth_info,
-                               false, false,
-                               PROTOCOL_NT1,
-                               0, 0x20);
-       if (cli_ipc) {
+       status = cli_cm_open(ctx, NULL,
+                            server_name, "IPC$",
+                            auth_info,
+                            false, false,
+                            PROTOCOL_NT1,
+                            0, 0x20, &cli_ipc);
+       if (NT_STATUS_IS_OK(status)) {
                cli_set_username(cli_ipc, ctx->username);
                cli_set_password(cli_ipc, ctx->password);
                cli_set_domain(cli_ipc, ctx->workgroup);
+       } else {
+               cli_ipc = NULL;
        }
        TALLOC_FREE(auth_info);
 
index da4150dee9176fbba458702edbaf34a7bf430385..bb08b22c8dcb4747325ede655eb558d778718038 100644 (file)
@@ -343,7 +343,7 @@ static struct cli_state *cli_cm_find(struct cli_state *cli,
  Open a client connection to a \\server\share.
 ****************************************************************************/
 
-struct cli_state *cli_cm_open(TALLOC_CTX *ctx,
+NTSTATUS cli_cm_open(TALLOC_CTX *ctx,
                                struct cli_state *referring_cli,
                                const char *server,
                                const char *share,
@@ -352,14 +352,16 @@ struct cli_state *cli_cm_open(TALLOC_CTX *ctx,
                                bool force_encrypt,
                                int max_protocol,
                                int port,
-                               int name_type)
+                               int name_type,
+                               struct cli_state **pcli)
 {
        /* Try to reuse an existing connection in this list. */
        struct cli_state *c = cli_cm_find(referring_cli, server, share);
        NTSTATUS status;
 
        if (c) {
-               return c;
+               *pcli = c;
+               return NT_STATUS_OK;
        }
 
        if (auth_info == NULL) {
@@ -368,7 +370,7 @@ struct cli_state *cli_cm_open(TALLOC_CTX *ctx,
                d_printf("cli_cm_open() Unable to open connection [\\%s\\%s] "
                        "without auth info\n",
                        server, share );
-               return NULL;
+               return NT_STATUS_INVALID_PARAMETER;
        }
 
        status = cli_cm_connect(ctx,
@@ -383,9 +385,10 @@ struct cli_state *cli_cm_open(TALLOC_CTX *ctx,
                                name_type,
                                &c);
        if (!NT_STATUS_IS_OK(status)) {
-               return NULL;
+               return status;
        }
-       return c;
+       *pcli = c;
+       return NT_STATUS_OK;
 }
 
 /****************************************************************************
@@ -829,16 +832,18 @@ bool cli_resolve_path(TALLOC_CTX *ctx,
 
        /* Check for the referral. */
 
-       if (!(cli_ipc = cli_cm_open(ctx,
-                               rootcli,
-                               rootcli->desthost,
-                               "IPC$",
-                               dfs_auth_info,
-                               false,
-                               (rootcli->trans_enc_state != NULL),
-                               rootcli->protocol,
-                               0,
-                               0x20))) {
+       status = cli_cm_open(ctx,
+                            rootcli,
+                            rootcli->desthost,
+                            "IPC$",
+                            dfs_auth_info,
+                            false,
+                            (rootcli->trans_enc_state != NULL),
+                            rootcli->protocol,
+                            0,
+                            0x20,
+                            &cli_ipc);
+       if (!NT_STATUS_IS_OK(status)) {
                return false;
        }
 
@@ -879,15 +884,17 @@ bool cli_resolve_path(TALLOC_CTX *ctx,
         */
 
        /* Open the connection to the target server & share */
-       if ((*targetcli = cli_cm_open(ctx, rootcli,
-                                       server,
-                                       share,
-                                       dfs_auth_info,
-                                       false,
-                                       (rootcli->trans_enc_state != NULL),
-                                       rootcli->protocol,
-                                       0,
-                                       0x20)) == NULL) {
+       status = cli_cm_open(ctx, rootcli,
+                            server,
+                            share,
+                            dfs_auth_info,
+                            false,
+                            (rootcli->trans_enc_state != NULL),
+                            rootcli->protocol,
+                            0,
+                            0x20,
+                            targetcli);
+       if (!NT_STATUS_IS_OK(status)) {
                d_printf("Unable to follow dfs referral [\\%s\\%s]\n",
                        server, share );
                return false;
index 89b1ecd9b661f06837f0c5403a2954b83d072772..1caf0f904a5006142062b11d2e14fe5aa07c278c 100644 (file)
@@ -113,7 +113,7 @@ NTSTATUS cli_cm_force_encryption(struct cli_state *c,
                        const char *password,
                        const char *domain,
                        const char *sharename);
-struct cli_state *cli_cm_open(TALLOC_CTX *ctx,
+NTSTATUS cli_cm_open(TALLOC_CTX *ctx,
                                struct cli_state *referring_cli,
                                const char *server,
                                const char *share,
@@ -122,7 +122,8 @@ struct cli_state *cli_cm_open(TALLOC_CTX *ctx,
                                bool force_encrypt,
                                int max_protocol,
                                int port,
-                               int name_type);
+                               int name_type,
+                               struct cli_state **pcli);
 void cli_cm_display(const struct cli_state *c);
 struct client_dfs_referral;
 NTSTATUS cli_dfs_get_referral(TALLOC_CTX *ctx,