rpc_client: Simplify rpc_pipe_bind_step_one_done()
authorVolker Lendecke <vl@samba.org>
Thu, 29 Jul 2021 06:55:45 +0000 (08:55 +0200)
committerJeremy Allison <jra@samba.org>
Fri, 6 Aug 2021 17:22:30 +0000 (17:22 +0000)
With just one case handled specially in a switch statement and the
rest being default:, a simple if-statement can reduce indentation.

Best viewed with "git show -b".

I wonder if the second "if (pauth->auth_type == DCERPC_AUTH_TYPE_NONE)"
leads to reachable code, this should have been taken care of already
further up. But for now I did the 1:1 translation of existing code.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
source3/rpc_client/cli_pipe.c

index 4ed74ae52b02a90c4c8937d9c13a60b6653b8189..7b6c3a05674a2bb42799da976e089a57af2107be 100644 (file)
@@ -1964,91 +1964,82 @@ static void rpc_pipe_bind_step_one_done(struct tevent_req *subreq)
 
        state->cli->max_xmit_frag = pkt->u.bind_ack.max_xmit_frag;
 
-       switch(pauth->auth_type) {
-
-       case DCERPC_AUTH_TYPE_NONE:
+       if (pauth->auth_type == DCERPC_AUTH_TYPE_NONE) {
                /* Bind complete. */
                tevent_req_done(req);
                return;
+       }
 
-       default:
-               if (pkt->auth_length == 0) {
-                       tevent_req_nterror(req, NT_STATUS_RPC_PROTOCOL_ERROR);
-                       return;
-               }
-
-               /* get auth credentials */
-               status = dcerpc_pull_auth_trailer(pkt, talloc_tos(),
-                                                 &pkt->u.bind_ack.auth_info,
-                                                 &auth, NULL, true);
-               if (!NT_STATUS_IS_OK(status)) {
-                       DEBUG(0, ("Failed to pull dcerpc auth: %s.\n",
-                                 nt_errstr(status)));
-                       tevent_req_nterror(req, status);
-                       return;
-               }
+       if (pkt->auth_length == 0) {
+               tevent_req_nterror(req, NT_STATUS_RPC_PROTOCOL_ERROR);
+               return;
+       }
 
-               if (auth.auth_type != pauth->auth_type) {
-                       DEBUG(0, (__location__ " Auth type %u mismatch expected %u.\n",
-                                 auth.auth_type, pauth->auth_type));
-                       tevent_req_nterror(req, NT_STATUS_RPC_PROTOCOL_ERROR);
-                       return;
-               }
+       /* get auth credentials */
+       status = dcerpc_pull_auth_trailer(pkt, talloc_tos(),
+                                         &pkt->u.bind_ack.auth_info,
+                                         &auth, NULL, true);
+       if (!NT_STATUS_IS_OK(status)) {
+               DEBUG(0, ("Failed to pull dcerpc auth: %s.\n",
+                         nt_errstr(status)));
+               tevent_req_nterror(req, status);
+               return;
+       }
 
-               if (auth.auth_level != pauth->auth_level) {
-                       DEBUG(0, (__location__ " Auth level %u mismatch expected %u.\n",
-                                 auth.auth_level, pauth->auth_level));
-                       tevent_req_nterror(req, NT_STATUS_RPC_PROTOCOL_ERROR);
-                       return;
-               }
+       if (auth.auth_type != pauth->auth_type) {
+               DBG_ERR("Auth type %u mismatch expected %u.\n",
+                       auth.auth_type, pauth->auth_type);
+               tevent_req_nterror(req, NT_STATUS_RPC_PROTOCOL_ERROR);
+               return;
+       }
 
-               if (auth.auth_context_id != pauth->auth_context_id) {
-                       DEBUG(0, (__location__ " Auth context id %u mismatch expected %u.\n",
-                                 (unsigned)auth.auth_context_id,
-                                 (unsigned)pauth->auth_context_id));
-                       tevent_req_nterror(req, NT_STATUS_RPC_PROTOCOL_ERROR);
-                       return;
-               }
+       if (auth.auth_level != pauth->auth_level) {
+               DBG_ERR("Auth level %u mismatch expected %u.\n",
+                       auth.auth_level, pauth->auth_level);
+               tevent_req_nterror(req, NT_STATUS_RPC_PROTOCOL_ERROR);
+               return;
+       }
 
-               break;
+       if (auth.auth_context_id != pauth->auth_context_id) {
+               DBG_ERR("Auth context id %"PRIu32" mismatch "
+                       "expected %"PRIu32".\n",
+                       auth.auth_context_id,
+                       pauth->auth_context_id);
+               tevent_req_nterror(req, NT_STATUS_RPC_PROTOCOL_ERROR);
+               return;
        }
 
        /*
         * For authenticated binds we may need to do 3 or 4 leg binds.
         */
 
-       switch(pauth->auth_type) {
-
-       case DCERPC_AUTH_TYPE_NONE:
+       if (pauth->auth_type == DCERPC_AUTH_TYPE_NONE) {
                /* Bind complete. */
                tevent_req_done(req);
                return;
+       }
 
-       default:
-               gensec_security = pauth->auth_ctx;
-
-
-               status = gensec_update(gensec_security, state,
-                                      auth.credentials, &auth_token);
-               if (NT_STATUS_EQUAL(status,
-                                   NT_STATUS_MORE_PROCESSING_REQUIRED)) {
-                       status = rpc_bind_next_send(req, state,
-                                                       &auth_token);
-               } else if (NT_STATUS_IS_OK(status)) {
-                       if (pauth->hdr_signing) {
-                               gensec_want_feature(gensec_security,
-                                                   GENSEC_FEATURE_SIGN_PKT_HEADER);
-                       }
+       gensec_security = pauth->auth_ctx;
 
-                       if (auth_token.length == 0) {
-                               /* Bind complete. */
-                               tevent_req_done(req);
-                               return;
-                       }
-                       status = rpc_bind_finish_send(req, state,
-                                                       &auth_token);
+       status = gensec_update(gensec_security, state,
+                              auth.credentials, &auth_token);
+       if (NT_STATUS_EQUAL(status,
+                           NT_STATUS_MORE_PROCESSING_REQUIRED)) {
+               status = rpc_bind_next_send(req, state,
+                                           &auth_token);
+       } else if (NT_STATUS_IS_OK(status)) {
+               if (pauth->hdr_signing) {
+                       gensec_want_feature(gensec_security,
+                                           GENSEC_FEATURE_SIGN_PKT_HEADER);
                }
-               break;
+
+               if (auth_token.length == 0) {
+                       /* Bind complete. */
+                       tevent_req_done(req);
+                       return;
+               }
+               status = rpc_bind_finish_send(req, state,
+                                             &auth_token);
        }
 
        if (!NT_STATUS_IS_OK(status)) {