Make cli_negprot return NTSTATUS instead of bool
authorVolker Lendecke <vl@samba.org>
Thu, 11 Sep 2008 16:57:49 +0000 (18:57 +0200)
committerVolker Lendecke <vl@samba.org>
Fri, 19 Dec 2008 09:28:30 +0000 (10:28 +0100)
13 files changed:
source3/auth/auth_server.c
source3/include/proto.h
source3/libsmb/cliconnect.c
source3/libsmb/clidfs.c
source3/libsmb/libsmb_server.c
source3/libsmb/passchange.c
source3/nmbd/nmbd_synclists.c
source3/torture/locktest.c
source3/torture/masktest.c
source3/torture/torture.c
source3/utils/net_rpc.c
source3/utils/net_time.c
source3/winbindd/winbindd_cm.c

index e74e3f5b3bf89810a0279b8fb337ad06017ca712..466c4bf129ffa7932d8f1bab03a77307a8c5acc1 100644 (file)
@@ -38,6 +38,7 @@ static struct cli_state *server_cryptkey(TALLOC_CTX *mem_ctx)
        char *pserver = NULL;
        bool connected_ok = False;
        struct named_mutex *mutex = NULL;
+       NTSTATUS status;
 
        if (!(cli = cli_initialise()))
                return NULL;
@@ -49,7 +50,6 @@ static struct cli_state *server_cryptkey(TALLOC_CTX *mem_ctx)
        p = pserver;
 
         while(next_token_talloc(mem_ctx, &p, &desthost, LIST_SEP)) {
-               NTSTATUS status;
 
                desthost = talloc_sub_basic(mem_ctx,
                                current_user_info.smb_name,
@@ -112,9 +112,12 @@ static struct cli_state *server_cryptkey(TALLOC_CTX *mem_ctx)
 
        DEBUG(3,("got session\n"));
 
-       if (!cli_negprot(cli)) {
+       status = cli_negprot(cli);
+
+       if (!NT_STATUS_IS_OK(status)) {
                TALLOC_FREE(mutex);
-               DEBUG(1,("%s rejected the negprot\n",desthost));
+               DEBUG(1, ("%s rejected the negprot: %s\n",
+                         desthost, nt_errstr(status)));
                cli_shutdown(cli);
                return NULL;
        }
index 536855c66ee086c1af3971d89efa7288b027ae97..8ec15da5d841f4da9c172bb753cddc89c5aa1e91 100644 (file)
@@ -2365,7 +2365,7 @@ bool cli_send_tconX(struct cli_state *cli,
                    const char *share, const char *dev, const char *pass, int passlen);
 bool cli_tdis(struct cli_state *cli);
 void cli_negprot_sendsync(struct cli_state *cli);
-bool cli_negprot(struct cli_state *cli);
+NTSTATUS cli_negprot(struct cli_state *cli);
 bool cli_session_request(struct cli_state *cli,
                         struct nmb_name *calling, struct nmb_name *called);
 NTSTATUS cli_connect(struct cli_state *cli,
index f7950823a7151cc9fa1e156205ec5fa9eccd9af3..f34b38106a9561745ee01736c8b20d6c8bee6b5f 100644 (file)
@@ -1241,7 +1241,7 @@ void cli_negprot_sendsync(struct cli_state *cli)
  Send a negprot command.
 ****************************************************************************/
 
-bool cli_negprot(struct cli_state *cli)
+NTSTATUS cli_negprot(struct cli_state *cli)
 {
        char *p;
        int numprots;
@@ -1279,21 +1279,25 @@ bool cli_negprot(struct cli_state *cli)
        SCVAL(smb_buf(cli->outbuf),0,2);
 
        cli_send_smb(cli);
-       if (!cli_receive_smb(cli))
-               return False;
+       if (!cli_receive_smb(cli)) {
+               return NT_STATUS_UNEXPECTED_IO_ERROR;
+       }
 
        show_msg(cli->inbuf);
 
-       if (cli_is_error(cli) ||
-           ((int)SVAL(cli->inbuf,smb_vwv0) >= numprots)) {
-               return(False);
+       if (cli_is_error(cli)) {
+               return cli_nt_error(cli);
+       }
+
+       if ((int)SVAL(cli->inbuf,smb_vwv0) >= numprots) {
+               return NT_STATUS_INVALID_NETWORK_RESPONSE;
        }
 
        cli->protocol = prots[SVAL(cli->inbuf,smb_vwv0)].prot;  
 
        if ((cli->protocol < PROTOCOL_NT1) && cli->sign_info.mandatory_signing) {
                DEBUG(0,("cli_negprot: SMB signing is mandatory and the selected protocol level doesn't support it.\n"));
-               return False;
+               return NT_STATUS_ACCESS_DENIED;
        }
 
        if (cli->protocol >= PROTOCOL_NT1) {    
@@ -1331,7 +1335,7 @@ bool cli_negprot(struct cli_state *cli)
                        /* Fail if server says signing is mandatory and we don't want to support it. */
                        if (!cli->sign_info.allow_smb_signing) {
                                DEBUG(0,("cli_negprot: SMB signing is mandatory and we have disabled it.\n"));
-                               return False;
+                               return NT_STATUS_ACCESS_DENIED;
                        }
                        cli->sign_info.negotiated_smb_signing = True;
                        cli->sign_info.mandatory_signing = True;
@@ -1339,7 +1343,7 @@ bool cli_negprot(struct cli_state *cli)
                        /* Fail if client says signing is mandatory and the server doesn't support it. */
                        if (!(cli->sec_mode & NEGOTIATE_SECURITY_SIGNATURES_ENABLED)) {
                                DEBUG(1,("cli_negprot: SMB signing is mandatory and the server doesn't support it.\n"));
-                               return False;
+                               return NT_STATUS_ACCESS_DENIED;
                        }
                        cli->sign_info.negotiated_smb_signing = True;
                        cli->sign_info.mandatory_signing = True;
@@ -1381,7 +1385,7 @@ bool cli_negprot(struct cli_state *cli)
        if (getenv("CLI_FORCE_ASCII"))
                cli->capabilities &= ~CAP_UNICODE;
 
-       return True;
+       return NT_STATUS_OK;
 }
 
 /****************************************************************************
@@ -1667,12 +1671,9 @@ again:
                cli->fallback_after_kerberos = true;
        }
 
-       if (!cli_negprot(cli)) {
-               DEBUG(1,("failed negprot\n"));
-               nt_status = cli_nt_error(cli);
-               if (NT_STATUS_IS_OK(nt_status)) {
-                       nt_status = NT_STATUS_UNSUCCESSFUL;
-               }
+       nt_status = cli_negprot(cli);
+       if (!NT_STATUS_IS_OK(nt_status)) {
+               DEBUG(1, ("failed negprot: %s\n", nt_errstr(nt_status)));
                cli_shutdown(cli);
                return nt_status;
        }
index f0ac39fed0582e435d0c3e5e724c7c891bcd2fb5..4597e63c98f4243a8c8f192c921564e3b5e62653 100644 (file)
@@ -195,8 +195,11 @@ static struct cli_state *do_connect(TALLOC_CTX *ctx,
 
        DEBUG(4,(" session request ok\n"));
 
-       if (!cli_negprot(c)) {
-               d_printf("protocol negotiation failed\n");
+       status = cli_negprot(c);
+
+       if (!NT_STATUS_IS_OK(status)) {
+               d_printf("protocol negotiation failed: %s\n",
+                        nt_errstr(status));
                cli_shutdown(c);
                return NULL;
        }
index 5e37871deb10cf4bfec8abe240c8250309ae2f2b..f4714346d1d98c0027fc87f8ca7599877e6dc223 100644 (file)
@@ -433,7 +433,9 @@ again:
 
        DEBUG(4,(" session request ok\n"));
 
-       if (!cli_negprot(c)) {
+       status = cli_negprot(c);
+
+       if (!NT_STATUS_IS_OK(status)) {
                cli_shutdown(c);
                errno = ETIMEDOUT;
                return NULL;
index 4c76234e0c048174dbc0b4071d746ef4e5c338ff..2746a4681e379d21d98fe95facac47a092b1affb 100644 (file)
@@ -71,10 +71,12 @@ NTSTATUS remote_password_change(const char *remote_machine, const char *user_nam
 
        cli->protocol = PROTOCOL_NT1;
 
-       if (!cli_negprot(cli)) {
+       result = cli_negprot(cli);
+
+       if (!NT_STATUS_IS_OK(result)) {
                asprintf(err_str, "machine %s rejected the negotiate "
                         "protocol. Error was : %s.\n",        
-                        remote_machine, cli_errstr(cli) );
+                        remote_machine, nt_errstr(result));
                result = cli_nt_error(cli);
                cli_shutdown(cli);
                return result;
index 5a2f5c46b4b296b640f45ed2351f2a26f9495c26..9e09060f2781ee108a32f855c22ad45b4ddd1ba0 100644 (file)
@@ -100,7 +100,8 @@ static void sync_child(char *name, int nm_type,
                return;
        }
 
-       if (!cli_negprot(cli)) {
+       status = cli_negprot(cli);
+       if (!NT_STATUS_IS_OK(status)) {
                cli_shutdown(cli);
                return;
        }
index 247c9abcc18463fe0ea3623498bed35e24004b4d..1bff95f4f3a950176511a74cf1d19fcdb4e933e3 100644 (file)
@@ -212,8 +212,10 @@ static struct cli_state *connect_one(char *share, int snum)
 
        DEBUG(4,(" session request ok\n"));
 
-       if (!cli_negprot(c)) {
-               DEBUG(0,("protocol negotiation failed\n"));
+       status = cli_negprot(c);
+       if (!NT_STATUS_IS_OK(status)) {
+               DEBUG(0, ("protocol negotiation failed: %s\n",
+                         nt_errstr(status)));
                cli_shutdown(c);
                return NULL;
        }
index 8fea15877f14922a3008fc579640fcd2eb443f45..2c3bda1d436a2155613210cf014aef22cb1ce649 100644 (file)
@@ -212,8 +212,10 @@ static struct cli_state *connect_one(char *share)
 
        DEBUG(4,(" session request ok\n"));
 
-       if (!cli_negprot(c)) {
-               DEBUG(0,("protocol negotiation failed\n"));
+       status = cli_negprot(c);
+       if (!NT_STATUS_IS_OK(status)) {
+               DEBUG(0, ("protocol negotiation failed: %s\n",
+                         nt_errstr(status)));
                cli_shutdown(c);
                return NULL;
        }
index 601cfb94382d008a4cf65a4a6928de4ce76ab711..5584c22a8fa987daebd685deaa008085ca98d9fa 100644 (file)
@@ -4726,6 +4726,7 @@ static bool run_error_map_extract(int dummy) {
        
        static struct cli_state *c_dos;
        static struct cli_state *c_nt;
+       NTSTATUS status;
 
        uint32 error;
 
@@ -4744,8 +4745,11 @@ static bool run_error_map_extract(int dummy) {
 
        c_nt->use_spnego = False;
 
-       if (!cli_negprot(c_nt)) {
-               printf("%s rejected the NT-error negprot (%s)\n",host, cli_errstr(c_nt));
+       status = cli_negprot(c_nt);
+
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("%s rejected the NT-error negprot (%s)\n", host,
+                      nt_errstr(status));
                cli_shutdown(c_nt);
                return False;
        }
@@ -4765,8 +4769,10 @@ static bool run_error_map_extract(int dummy) {
        c_dos->use_spnego = False;
        c_dos->force_dos_errors = True;
 
-       if (!cli_negprot(c_dos)) {
-               printf("%s rejected the DOS-error negprot (%s)\n",host, cli_errstr(c_dos));
+       status = cli_negprot(c_dos);
+       if (!NT_STATUS_IS_OK(status)) {
+               printf("%s rejected the DOS-error negprot (%s)\n", host,
+                      nt_errstr(status));
                cli_shutdown(c_dos);
                return False;
        }
@@ -4839,9 +4845,10 @@ static bool run_sesssetup_bench(int dummy)
                return false;
        }
 
-       if (!cli_negprot(c)) {
+       status = cli_negprot(c);
+       if (!NT_STATUS_IS_OK(status)) {
                printf("%s rejected the NT-error negprot (%s)\n", host,
-                      cli_errstr(c));
+                      nt_errstr(status));
                cli_shutdown(c);
                return false;
        }
index f69d3f9012eb529b2770f29830a9ded93b94c0a5..5c83b590c1496fe62bb300e3ce31d95e9a594746 100644 (file)
@@ -6326,7 +6326,8 @@ bool net_rpc_check(struct net_context *c, unsigned flags)
        if (!attempt_netbios_session_request(&cli, global_myname(),
                                             server_name, &server_ss))
                goto done;
-       if (!cli_negprot(cli))
+       status = cli_negprot(cli);
+       if (!NT_STATUS_IS_OK(status))
                goto done;
        if (cli->protocol < PROTOCOL_NT1)
                goto done;
index f569538faca20af6d33832d3988e7c4dac66501d..8be9ed922cf4f2fd3250f466853c556eb53f760c 100644 (file)
@@ -51,8 +51,10 @@ static time_t cli_servertime(const char *host, struct sockaddr_storage *pss, int
                fprintf(stderr,"Session request failed\n");
                goto done;
        }
-       if (!cli_negprot(cli)) {
-               fprintf(stderr,"Protocol negotiation failed\n");
+       status = cli_negprot(cli);
+       if (!NT_STATUS_IS_OK(status)) {
+               fprintf(stderr, "Protocol negotiation failed: %s\n",
+                       nt_errstr(status));
                goto done;
        }
 
index 5f592fc6b7785b0d75533c2717c7d0e248e9026a..3135b6a2a3e31693ee6d785b7991b2c9b2b09f7e 100644 (file)
@@ -831,9 +831,10 @@ static NTSTATUS cm_prepare_connection(const struct winbindd_domain *domain,
 
        cli_setup_signing_state(*cli, Undefined);
 
-       if (!cli_negprot(*cli)) {
-               DEBUG(1, ("cli_negprot failed\n"));
-               result = NT_STATUS_UNSUCCESSFUL;
+       result = cli_negprot(*cli);
+
+       if (!NT_STATUS_IS_OK(result)) {
+               DEBUG(1, ("cli_negprot failed: %s\n", nt_errstr(result)));
                goto done;
        }