]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s3:libsmb: pass struct smb_transports to cli_connect_nb()
authorStefan Metzmacher <metze@samba.org>
Sun, 6 Apr 2025 17:05:19 +0000 (19:05 +0200)
committerStefan Metzmacher <metze@samba.org>
Fri, 18 Apr 2025 10:17:29 +0000 (10:17 +0000)
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Volker Lendecke <vl@samba.org>
source3/client/client.c
source3/libsmb/cliconnect.c
source3/libsmb/clidfs.c
source3/libsmb/libsmb_server.c
source3/libsmb/passchange.c
source3/libsmb/proto.h
source3/nmbd/nmbd_synclists.c
source3/torture/torture.c
source3/utils/net_rpc.c
source3/utils/net_time.c

index c15d9a9eb69120adec6dc7c0afc3fe7951100c30..797535024d53bee7ce4bb997d227c5ac6fa2b08f 100644 (file)
@@ -6367,6 +6367,8 @@ static int do_tar_op(const char *base_directory)
 static int do_message_op(struct cli_credentials *creds)
 {
        NTSTATUS status;
+       struct smb_transports ts =
+               smbsock_transports_from_port(port ? port : NBT_SMB_PORT);
 
        if (lp_disable_netbios()) {
                d_printf("NetBIOS over TCP disabled.\n");
@@ -6375,7 +6377,8 @@ static int do_message_op(struct cli_credentials *creds)
 
        status = cli_connect_nb(talloc_tos(),
                                desthost, have_ip ? &dest_ss : NULL,
-                               port ? port : NBT_SMB_PORT, name_type,
+                               &ts,
+                               name_type,
                                lp_netbios_name(),
                                SMB_SIGNING_OFF,
                                0,
index 52c02d064659c0d71e313d24c04ed3c7a9b63b6c..7df07e8489bd1be1c95b621bf9326725f981cce2 100644 (file)
@@ -2620,7 +2620,7 @@ static NTSTATUS cli_connect_nb_recv(struct tevent_req *req,
 NTSTATUS cli_connect_nb(TALLOC_CTX *mem_ctx,
                        const char *host,
                        const struct sockaddr_storage *dest_ss,
-                       uint16_t port,
+                       const struct smb_transports *transports,
                        int name_type,
                        const char *myname,
                        enum smb_signing_setting signing_state,
@@ -2630,13 +2630,12 @@ NTSTATUS cli_connect_nb(TALLOC_CTX *mem_ctx,
        struct tevent_context *ev;
        struct tevent_req *req;
        NTSTATUS status = NT_STATUS_NO_MEMORY;
-       struct smb_transports ts = smbsock_transports_from_port(port);
 
        ev = samba_tevent_context_init(mem_ctx);
        if (ev == NULL) {
                goto fail;
        }
-       req = cli_connect_nb_send(ev, ev, host, dest_ss, &ts, name_type,
+       req = cli_connect_nb_send(ev, ev, host, dest_ss, transports, name_type,
                                  myname, signing_state, flags);
        if (req == NULL) {
                goto fail;
index de8ac4dc1ea8f7343264b15328488d5e45d3a033..dc0dc405b8769c451cda9c3d51d3238d5265f7a5 100644 (file)
@@ -151,6 +151,7 @@ static NTSTATUS do_connect(TALLOC_CTX *ctx,
                cli_credentials_get_smb_encryption(creds);
        struct smb2_negotiate_contexts *in_contexts = NULL;
        struct smb2_negotiate_contexts *out_contexts = NULL;
+       struct smb_transports ts = smbsock_transports_from_port(port);
 
        if (encryption_state >= SMB_ENCRYPTION_DESIRED) {
                signing_state = SMB_SIGNING_REQUIRED;
@@ -186,7 +187,7 @@ static NTSTATUS do_connect(TALLOC_CTX *ctx,
        status = cli_connect_nb(NULL,
                                server,
                                dest_ss,
-                               port,
+                               &ts,
                                name_type,
                                NULL,
                                signing_state,
index 8808781d4107487dc15a46e355ac5f35353ee938..043f640601f110e40606e954f3fcda18f590ba41 100644 (file)
@@ -369,6 +369,11 @@ SMBC_server_internal(TALLOC_CTX *ctx,
        struct smbXcli_tcon *tcon = NULL;
        int signing_state = SMB_SIGNING_DEFAULT;
        struct cli_credentials *creds = NULL;
+       struct smb_transports ats = smbsock_transports_from_port(port);
+       uint8_t ati;
+       const struct smb_transports *ts = &ats;
+       struct smb_transports ots = { .num_transports = 0, };
+       struct smb_transports nts = { .num_transports = 0, };
 
        *in_cache = false;
 
@@ -377,6 +382,23 @@ SMBC_server_internal(TALLOC_CTX *ctx,
                return NULL;
        }
 
+       for (ati = 0; ati < ats.num_transports; ati++) {
+               const struct smb_transport *at =
+                       &ats.transports[ati];
+
+               if (at->type == SMB_TRANSPORT_TYPE_NBT) {
+                       struct smb_transport *nt =
+                               &nts.transports[nts.num_transports];
+                       *nt = *at;
+                       nts.num_transports += 1;
+               } else {
+                       struct smb_transport *ot =
+                               &ots.transports[ots.num_transports];
+                       *ot = *at;
+                       ots.num_transports += 1;
+               }
+       }
+
         /* Look for a cached connection */
         srv = SMBC_find_server(ctx, context, server, share,
                                pp_workgroup, pp_username, pp_password);
@@ -524,15 +546,17 @@ SMBC_server_internal(TALLOC_CTX *ctx,
                signing_state = SMB_SIGNING_REQUIRED;
        }
 
-       if (port == 0) {
+       if (nts.num_transports != 0 && ots.num_transports != 0) {
                if (share == NULL || *share == '\0' || is_ipc) {
                        /*
                         * Try 139 first for IPC$
                         */
+                       ts = &ots;
+
                        status = cli_connect_nb(NULL,
                                                server_n,
                                                NULL,
-                                               NBT_SMB_PORT,
+                                               &nts,
                                                0x20,
                                                smbc_getNetbiosName(context),
                                                signing_state,
@@ -548,7 +572,7 @@ SMBC_server_internal(TALLOC_CTX *ctx,
                status = cli_connect_nb(NULL,
                                        server_n,
                                        NULL,
-                                       port,
+                                       ts,
                                        0x20,
                                        smbc_getNetbiosName(context),
                                        signing_state,
index c4a82bfcd238a89849b398564a548348bc87fe72..eafad9a0423a405e38cac06883dac10fcb09edb3 100644 (file)
@@ -41,13 +41,16 @@ NTSTATUS remote_password_change(const char *remote_machine,
        NTSTATUS status;
        NTSTATUS result;
        bool pass_must_change = False;
+       struct smb_transports ts =
+               smb_transports_parse("client smb transports",
+                                    lp_client_smb_transports());
 
        *err_str = NULL;
 
        result = cli_connect_nb(talloc_tos(),
                                remote_machine,
                                NULL,
-                               0,
+                               &ts,
                                0x20,
                                NULL,
                                SMB_SIGNING_IPC_DEFAULT,
index 947afca9501dd1591371f91d682a7416e40f97a1..e3e92e6fcb55ce677ab1071bed119f6ff38fa132 100644 (file)
@@ -85,12 +85,13 @@ NTSTATUS cli_tdis(struct cli_state *cli);
 NTSTATUS cli_connect_nb(TALLOC_CTX *mem_ctx,
                        const char *host,
                        const struct sockaddr_storage *dest_ss,
-                       uint16_t port,
+                       const struct smb_transports *transports,
                        int name_type,
                        const char *myname,
                        enum smb_signing_setting signing_state,
                        int flags,
-                       struct cli_state **pcli);
+                       struct cli_state **pcli)
+       NONNULL(4) NONNULL(9);
 NTSTATUS cli_start_connection(TALLOC_CTX *mem_ctx,
                              struct cli_state **output_cli,
                              const char *my_name,
index 773ba7b3d2c4b5b7ba63325c4e60e1c9567d7d3c..0523a902af2cd1e0919f90e20a6b691ab2afe97b 100644 (file)
@@ -76,6 +76,8 @@ static void sync_child(char *name, int nm_type,
        struct cli_state *cli;
        uint32_t local_type = local ? SV_TYPE_LOCAL_LIST_ONLY : 0;
        struct sockaddr_storage ss;
+       const char *nbt[] = { "nbt", NULL, };
+       struct smb_transports ts = smb_transports_parse("forced-nbt", nbt);
        NTSTATUS status;
 
        /* W2K DMB's return empty browse lists on port 445. Use 139.
@@ -87,7 +89,7 @@ static void sync_child(char *name, int nm_type,
        status = cli_connect_nb(talloc_tos(),
                                name,
                                &ss,
-                               NBT_SMB_PORT,
+                               &ts,
                                nm_type,
                                get_local_machine_name(),
                                SMB_SIGNING_DEFAULT,
index 8bc4320eb4368be1b6dd9b6e41e0f08df6822f2d..83198eeed3c8872b1e0cfbbd5e34abfbe6fa6ae0 100644 (file)
@@ -142,6 +142,9 @@ static struct cli_state *open_nbt_connection(void)
        struct cli_state *c;
        NTSTATUS status;
        int flags = 0;
+       struct smb_transports ts =
+               smb_transports_parse("client smb transports",
+                                    lp_client_smb_transports());
 
        if (disable_spnego) {
                flags |= CLI_FULL_CONNECTION_DONT_SPNEGO;
@@ -162,7 +165,7 @@ static struct cli_state *open_nbt_connection(void)
        status = cli_connect_nb(NULL,
                                host,
                                NULL,
-                               port_to_use,
+                               &ts,
                                0x20,
                                myname,
                                signing_state,
@@ -16487,6 +16490,7 @@ static void usage(void)
                switch (opt) {
                case 'p':
                        port_to_use = atoi(optarg);
+                       lpcfg_set_cmdline(lp_ctx, "client smb transports", optarg);
                        break;
                case 's':
                        seed = atoi(optarg);
index 4afb22385afd524389a51dc36b3cbe9afeec802d..e2bf574f250137dfb62d4ce7a028845c796690e6 100644 (file)
@@ -7485,6 +7485,9 @@ bool net_rpc_check(struct net_context *c, unsigned flags)
        bool ret = false;
        struct sockaddr_storage server_ss;
        char *server_name = NULL;
+       struct smb_transports ts =
+               smb_transports_parse("client smb transports",
+                                    lp_client_smb_transports());
        NTSTATUS status;
 
        /* flags (i.e. server type) may depend on command */
@@ -7494,7 +7497,7 @@ bool net_rpc_check(struct net_context *c, unsigned flags)
        status = cli_connect_nb(c,
                                server_name,
                                &server_ss,
-                               0,
+                               &ts,
                                0x20,
                                lp_netbios_name(),
                                SMB_SIGNING_IPC_DEFAULT,
index 91614a11dc2105412fedc46173a67cdae70f7a65..5923c78cd29708889f266744bb975f7fa69297db 100644 (file)
@@ -32,12 +32,15 @@ static time_t cli_servertime(const char *host,
 {
        time_t ret = 0;
        struct cli_state *cli = NULL;
+       struct smb_transports ts =
+               smb_transports_parse("client smb transports",
+                                    lp_client_smb_transports());
        NTSTATUS status;
 
        status = cli_connect_nb(talloc_tos(),
                                host,
                                dest_ss,
-                               0,
+                               &ts,
                                0x20,
                                lp_netbios_name(),
                                SMB_SIGNING_DEFAULT,