]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s4:libcli: pass struct smbcli_options to smbcli_sock_connect() instead of port strings
authorStefan Metzmacher <metze@samba.org>
Thu, 3 Apr 2025 06:35:40 +0000 (08:35 +0200)
committerStefan Metzmacher <metze@samba.org>
Fri, 18 Apr 2025 10:17:29 +0000 (10:17 +0000)
This allows us to build the ports array from options.transports.

Pair-Programmed-With: Ralph Boehme <slow@samba.org>

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Volker Lendecke <vl@samba.org>
source4/libcli/cliconnect.c
source4/libcli/raw/clisocket.c
source4/libcli/smb2/connect.c
source4/libcli/smb_composite/connect.c
source4/libcli/smb_composite/connect_nego.c

index 58118b086aaddf4228e9859ffcf9c28388d0a8ac..18633c961987480275b549b5f2beead5cd633feb 100644 (file)
@@ -46,7 +46,7 @@ bool smbcli_socket_connect(struct smbcli_state *cli, const char *server,
 
        status = smbcli_sock_connect(cli,
                                     NULL, /* host_addr */
-                                    ports,
+                                    &cli->options,
                                     server,
                                     resolve_ctx,
                                     ev_ctx,
index 0c53014fc3b012c19c89b60a72b1b3d2748162af..3c3f90364e2d56716f0df723bdb078aa8e347d99 100644 (file)
@@ -275,6 +275,7 @@ static NTSTATUS smbcli_transport_connect_recv(struct tevent_req *req)
 struct sock_connect_state {
        struct composite_context *ctx;
        const char *host_name;
+       struct smbcli_options options;
        int num_ports;
        uint16_t *ports;
        const char *socket_options;
@@ -318,7 +319,7 @@ static void smbcli_sock_connect_recv_conn(struct composite_context *ctx);
 
 struct composite_context *smbcli_sock_connect_send(TALLOC_CTX *mem_ctx,
                                                   const char *host_addr,
-                                                  const char **ports,
+                                                  const struct smbcli_options *options,
                                                   const char *host_name,
                                                   struct resolve_context *resolve_ctx,
                                                   struct tevent_context *event_ctx,
@@ -328,8 +329,9 @@ struct composite_context *smbcli_sock_connect_send(TALLOC_CTX *mem_ctx,
 {
        struct composite_context *result, *ctx;
        struct sock_connect_state *state;
+       const struct smb_transports *ts = NULL;
        NTSTATUS status;
-       int i;
+       uint8_t ti;
 
        result = talloc_zero(mem_ctx, struct composite_context);
        if (result == NULL) goto failed;
@@ -338,7 +340,7 @@ struct composite_context *smbcli_sock_connect_send(TALLOC_CTX *mem_ctx,
        result->event_ctx = event_ctx;
        if (result->event_ctx == NULL) goto failed;
 
-       state = talloc(result, struct sock_connect_state);
+       state = talloc_zero(result, struct sock_connect_state);
        if (state == NULL) goto failed;
        state->ctx = result;
        result->private_data = state;
@@ -346,11 +348,29 @@ struct composite_context *smbcli_sock_connect_send(TALLOC_CTX *mem_ctx,
        state->host_name = talloc_strdup(state, host_name);
        if (state->host_name == NULL) goto failed;
 
-       state->num_ports = str_list_length(ports);
-       state->ports = talloc_array(state, uint16_t, state->num_ports);
-       if (state->ports == NULL) goto failed;
-       for (i=0;ports[i];i++) {
-               state->ports[i] = atoi(ports[i]);
+       state->options = *options;
+       ts = &state->options.transports;
+
+       state->ports = talloc_array(state, uint16_t, ts->num_transports);
+       if (state->ports == NULL) {
+               goto failed;
+       }
+
+       for (ti = 0; ti < ts->num_transports; ti++) {
+               const struct smb_transport *t = &ts->transports[ti];
+
+               switch (t->type) {
+               case SMB_TRANSPORT_TYPE_NBT:
+               case SMB_TRANSPORT_TYPE_TCP:
+                       state->ports[state->num_ports] = t->port;
+                       state->num_ports += 1;
+                       break;
+               case SMB_TRANSPORT_TYPE_UNKNOWN:
+                       break;
+               }
+       }
+       if (state->num_ports == 0) {
+               goto failed;
        }
        state->socket_options = talloc_reference(state, socket_options);
 
@@ -441,7 +461,8 @@ NTSTATUS smbcli_sock_connect_recv(struct composite_context *c,
   sync version of the function
 */
 NTSTATUS smbcli_sock_connect(TALLOC_CTX *mem_ctx,
-                            const char *host_addr, const char **ports,
+                            const char *host_addr,
+                            const struct smbcli_options *options,
                             const char *host_name,
                             struct resolve_context *resolve_ctx,
                             struct tevent_context *event_ctx,
@@ -451,8 +472,8 @@ NTSTATUS smbcli_sock_connect(TALLOC_CTX *mem_ctx,
                             struct smbcli_socket **result)
 {
        struct composite_context *c =
-               smbcli_sock_connect_send(mem_ctx, host_addr, ports, host_name,
-                                        resolve_ctx,
+               smbcli_sock_connect_send(mem_ctx, host_addr, options,
+                                        host_name, resolve_ctx,
                                         event_ctx, socket_options,
                                         calling, called);
        return smbcli_sock_connect_recv(c, mem_ctx, result);
index 64b678654468372895fb86567bafad4d35180bea..6697051d61da5a4bbd1cb27c87f874ce076f62e6 100644 (file)
@@ -137,7 +137,7 @@ struct tevent_req *smb2_connect_send(TALLOC_CTX *mem_ctx,
                return req;
        }
 
-       creq = smbcli_sock_connect_send(state, NULL, state->ports,
+       creq = smbcli_sock_connect_send(state, NULL, &state->options,
                                        state->host, state->resolve_ctx,
                                        state->ev, state->socket_options,
                                        &state->calling,
index ad50ae0ac81fe5e180d8d31ec7466cf477c2309d..28704016b9479fe005977b5f918d93fca7606e14 100644 (file)
@@ -474,7 +474,7 @@ struct composite_context *smb_composite_connect_send(struct smb_composite_connec
 
        state->creq = smbcli_sock_connect_send(state, 
                                               NULL,
-                                              io->in.dest_ports,
+                                              &io->in.options,
                                               io->in.dest_host, 
                                               resolve_ctx, c->event_ctx, 
                                               io->in.socket_options,
index 7224dfa87946f8d3deffeb10f140a58b0894534e..b3a7f6daaaf6df5266e2b8d94a280ecfa5e73e41 100644 (file)
@@ -84,7 +84,7 @@ struct tevent_req *smb_connect_nego_send(TALLOC_CTX *mem_ctx,
 
        creq = smbcli_sock_connect_send(state,
                                        state->dest_address,
-                                       state->dest_ports,
+                                       &state->options,
                                        state->dest_hostname,
                                        state->resolve_ctx,
                                        state->ev,