]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s3:libsmb: pass struct smb_transports to cli_cm_connect() and cli_cm_open()
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/lib/netapi/cm.c
source3/libsmb/clidfs.c
source3/libsmb/proto.h

index 797535024d53bee7ce4bb997d227c5ac6fa2b08f..a1991c1cd8c9916185038812d80f68925bbb0aef 100644 (file)
@@ -5783,6 +5783,7 @@ static int process_command_string(const char *cmd_in)
        char *cmd = talloc_strdup(ctx, cmd_in);
        int rc = 0;
        struct cli_credentials *creds = samba_cmdline_get_creds();
+       struct smb_transports ts = smbsock_transports_from_port(port);
 
        if (!cmd) {
                return 1;
@@ -5796,7 +5797,8 @@ static int process_command_string(const char *cmd_in)
                                     desthost,
                                     service,
                                     creds,
-                                    have_ip ? &dest_ss : NULL, port,
+                                    have_ip ? &dest_ss : NULL,
+                                    &ts,
                                     name_type,
                                     &cli);
                if (!NT_STATUS_IS_OK(status)) {
@@ -6208,12 +6210,14 @@ static int process(const char *base_directory)
        int rc = 0;
        NTSTATUS status;
        struct cli_credentials *creds = samba_cmdline_get_creds();
+       struct smb_transports ts = smbsock_transports_from_port(port);
 
        status = cli_cm_open(talloc_tos(), NULL,
                             desthost,
                             service,
                             creds,
-                            have_ip ? &dest_ss : NULL, port,
+                            have_ip ? &dest_ss : NULL,
+                            &ts,
                             name_type, &cli);
        if (!NT_STATUS_IS_OK(status)) {
                return 1;
@@ -6248,12 +6252,14 @@ static int do_host_query(struct loadparm_context *lp_ctx,
 {
        NTSTATUS status;
        struct cli_credentials *creds = samba_cmdline_get_creds();
+       struct smb_transports ts = smbsock_transports_from_port(port);
 
        status = cli_cm_open(talloc_tos(), NULL,
                             query_host,
                             "IPC$",
                             creds,
-                            have_ip ? &dest_ss : NULL, port,
+                            have_ip ? &dest_ss : NULL,
+                            &ts,
                             name_type, &cli);
        if (!NT_STATUS_IS_OK(status)) {
                return 1;
@@ -6287,6 +6293,9 @@ static int do_host_query(struct loadparm_context *lp_ctx,
        if (port != NBT_SMB_PORT ||
            smbXcli_conn_protocol(cli->conn) > PROTOCOL_NT1)
        {
+               const char *nbt[] = { "nbt", NULL, };
+               struct smb_transports nbt_ts = smb_transports_parse("forced-nbt",
+                                                                   nbt);
                /*
                 * Workgroups simply don't make sense over anything
                 * else but port 139 and SMB1.
@@ -6299,7 +6308,8 @@ static int do_host_query(struct loadparm_context *lp_ctx,
                                     query_host,
                                     "IPC$",
                                     creds,
-                                    have_ip ? &dest_ss : NULL, NBT_SMB_PORT,
+                                    have_ip ? &dest_ss : NULL,
+                                    &nbt_ts,
                                     name_type, &cli);
                if (!NT_STATUS_IS_OK(status)) {
                        d_printf("Unable to connect with SMB1 "
@@ -6325,6 +6335,7 @@ static int do_tar_op(const char *base_directory)
        struct tar *tar_ctx = tar_get_ctx();
        int ret = 0;
        struct cli_credentials *creds = samba_cmdline_get_creds();
+       struct smb_transports ts = smbsock_transports_from_port(port);
 
        /* do we already have a connection? */
        if (!cli) {
@@ -6334,7 +6345,8 @@ static int do_tar_op(const char *base_directory)
                                     desthost,
                                     service,
                                     creds,
-                                    have_ip ? &dest_ss : NULL, port,
+                                    have_ip ? &dest_ss : NULL,
+                                    &ts,
                                     name_type, &cli);
                if (!NT_STATUS_IS_OK(status)) {
             ret = 1;
index da63fd921e92042a660636b93356b642ddc2b0d9..c7a3a0873d68c1fedabf8960f1e4413024270613 100644 (file)
@@ -73,6 +73,9 @@ static WERROR libnetapi_open_ipc_connection(struct libnetapi_ctx *ctx,
        const char *password = NULL;
        NET_API_STATUS rc;
        enum credentials_use_kerberos krb5_state;
+       struct smb_transports ts =
+               smb_transports_parse("client smb transports",
+                                    lp_client_smb_transports());
 
        if (!ctx || !pp || !server_name) {
                return WERR_INVALID_PARAMETER;
@@ -113,7 +116,7 @@ static WERROR libnetapi_open_ipc_connection(struct libnetapi_ctx *ctx,
        status = cli_cm_open(ctx, NULL,
                             server_name, "IPC$",
                             ctx->creds,
-                            NULL, 0, 0x20, &cli_ipc);
+                            NULL, &ts, 0x20, &cli_ipc);
        if (!NT_STATUS_IS_OK(status)) {
                cli_ipc = NULL;
        }
index 8390171f3c8db9f73a66925e118ce70284ed7b50..69d49c243f8c0ae003b745f393f13c5d6e8702f3 100644 (file)
@@ -340,17 +340,16 @@ static NTSTATUS cli_cm_connect(TALLOC_CTX *ctx,
                               const char *share,
                               struct cli_credentials *creds,
                               const struct sockaddr_storage *dest_ss,
-                              int port,
+                              const struct smb_transports *transports,
                               int name_type,
                               struct cli_state **pcli)
 {
        struct cli_state *cli = NULL;
        NTSTATUS status;
-       struct smb_transports ts = smbsock_transports_from_port(port);
 
        status = do_connect(ctx, server, share,
                                creds,
-                               dest_ss, &ts, name_type, &cli);
+                               dest_ss, transports, name_type, &cli);
 
        if (!NT_STATUS_IS_OK(status)) {
                return status;
@@ -434,7 +433,7 @@ NTSTATUS cli_cm_open(TALLOC_CTX *ctx,
                     const char *share,
                     struct cli_credentials *creds,
                     const struct sockaddr_storage *dest_ss,
-                    int port,
+                    const struct smb_transports *transports,
                     int name_type,
                     struct cli_state **pcli)
 {
@@ -462,7 +461,7 @@ NTSTATUS cli_cm_open(TALLOC_CTX *ctx,
                                share,
                                creds,
                                dest_ss,
-                               port,
+                               transports,
                                name_type,
                                &c);
        if (!NT_STATUS_IS_OK(status)) {
@@ -950,6 +949,9 @@ NTSTATUS cli_resolve_path(TALLOC_CTX *ctx,
        struct cli_dfs_path_split *dfs_refs = NULL;
        bool ok;
        bool is_already_dfs = false;
+       struct smb_transports ts =
+               smb_transports_parse("client smb transports",
+                                    lp_client_smb_transports());
 
        if ( !rootcli || !path || !targetcli ) {
                return NT_STATUS_INVALID_PARAMETER;
@@ -1040,7 +1042,7 @@ NTSTATUS cli_resolve_path(TALLOC_CTX *ctx,
                             "IPC$",
                             creds,
                             NULL, /* dest_ss not needed, we reuse the transport */
-                            0,
+                            &ts,
                             0x20,
                             &cli_ipc);
        if (!NT_STATUS_IS_OK(status)) {
@@ -1096,7 +1098,7 @@ NTSTATUS cli_resolve_path(TALLOC_CTX *ctx,
                                dfs_refs[count].share,
                                creds,
                                NULL, /* dest_ss */
-                               0, /* port */
+                               &ts,
                                0x20,
                                targetcli);
                if (!NT_STATUS_IS_OK(status)) {
index babd5f9dabf17778b28558aeb38f972546f6b0b4..f7903458a9a3bd4d0263ed423559388aae9844bb 100644 (file)
@@ -139,9 +139,10 @@ NTSTATUS cli_cm_open(TALLOC_CTX *ctx,
                     const char *share,
                     struct cli_credentials *creds,
                     const struct sockaddr_storage *dest_ss,
-                    int port,
+                    const struct smb_transports *transports,
                     int name_type,
-                    struct cli_state **pcli);
+                    struct cli_state **pcli)
+       NONNULL(7) NONNULL(9);
 void cli_cm_display(struct cli_state *c);
 struct client_dfs_referral;
 bool cli_dfs_is_already_full_path(struct cli_state *cli, const char *path);