s4:libcli: Return NTSTATUS errors for smb_composite_connect_send()
authorAndreas Schneider <asn@samba.org>
Thu, 13 Aug 2020 14:16:55 +0000 (16:16 +0200)
committerAndreas Schneider <asn@cryptomilk.org>
Wed, 19 Aug 2020 16:22:43 +0000 (16:22 +0000)
Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
source4/libcli/smb_composite/connect.c

index 582d43ef1730d4f29767f1b215537a2062400da9..ad50ae0ac81fe5e180d8d31ec7466cf477c2309d 100644 (file)
@@ -420,15 +420,25 @@ struct composite_context *smb_composite_connect_send(struct smb_composite_connec
        struct connect_state *state;
 
        c = talloc_zero(mem_ctx, struct composite_context);
-       if (c == NULL) goto failed;
-
-       c->event_ctx = event_ctx;
-       if (c->event_ctx == NULL) goto failed;
+       if (c == NULL) {
+               goto nomem;
+       }
 
        state = talloc_zero(c, struct connect_state);
-       if (state == NULL) goto failed;
+       if (state == NULL) {
+               goto nomem;
+       }
+
+       c->event_ctx = event_ctx;
+       if (c->event_ctx == NULL) {
+               composite_error(c, NT_STATUS_INVALID_PARAMETER_MIX);
+               return c;
+       }
 
-       if (io->in.gensec_settings == NULL) goto failed;
+       if (io->in.gensec_settings == NULL) {
+               composite_error(c, NT_STATUS_INVALID_PARAMETER_MIX);
+               return c;
+       }
        state->io = io;
 
        c->state = COMPOSITE_STATE_IN_PROGRESS;
@@ -449,12 +459,14 @@ struct composite_context *smb_composite_connect_send(struct smb_composite_connec
                                                   &io->in.options,
                                                   &state->transport);
                if (!NT_STATUS_IS_OK(status)) {
-                       goto failed;
+                       composite_error(c, status);
+                       return c;
                }
 
                status = connect_send_session(c, io);
                if (!NT_STATUS_IS_OK(status)) {
-                       goto failed;
+                       composite_error(c, status);
+                       return c;
                }
 
                return c;
@@ -468,15 +480,18 @@ struct composite_context *smb_composite_connect_send(struct smb_composite_connec
                                               io->in.socket_options,
                                               &state->calling,
                                               &state->called);
-       if (state->creq == NULL) goto failed;
+       if (state->creq == NULL) {
+               composite_error(c, NT_STATUS_NO_MEMORY);
+               return c;
+       }
 
        state->stage = CONNECT_SOCKET;
        state->creq->async.private_data = c;
        state->creq->async.fn = composite_handler;
 
        return c;
-failed:
-       talloc_free(c);
+nomem:
+       TALLOC_FREE(c);
        return NULL;
 }
 
@@ -506,5 +521,8 @@ NTSTATUS smb_composite_connect(struct smb_composite_connect *io, TALLOC_CTX *mem
                               struct tevent_context *ev)
 {
        struct composite_context *c = smb_composite_connect_send(io, mem_ctx, resolve_ctx, ev);
+       if (c == NULL) {
+               return NT_STATUS_NO_MEMORY;
+       }
        return smb_composite_connect_recv(c, mem_ctx);
 }