From 272fbb1c9cc1e12d7480df9df2ecdbabb8fdb71a Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Sun, 6 Apr 2025 19:05:19 +0200 Subject: [PATCH] s3:libsmb: pass struct smb_transports to cli_cm_connect() and cli_cm_open() Signed-off-by: Stefan Metzmacher Reviewed-by: Volker Lendecke --- source3/client/client.c | 22 +++++++++++++++++----- source3/lib/netapi/cm.c | 5 ++++- source3/libsmb/clidfs.c | 16 +++++++++------- source3/libsmb/proto.h | 5 +++-- 4 files changed, 33 insertions(+), 15 deletions(-) diff --git a/source3/client/client.c b/source3/client/client.c index 797535024d5..a1991c1cd8c 100644 --- a/source3/client/client.c +++ b/source3/client/client.c @@ -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; diff --git a/source3/lib/netapi/cm.c b/source3/lib/netapi/cm.c index da63fd921e9..c7a3a0873d6 100644 --- a/source3/lib/netapi/cm.c +++ b/source3/lib/netapi/cm.c @@ -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; } diff --git a/source3/libsmb/clidfs.c b/source3/libsmb/clidfs.c index 8390171f3c8..69d49c243f8 100644 --- a/source3/libsmb/clidfs.c +++ b/source3/libsmb/clidfs.c @@ -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)) { diff --git a/source3/libsmb/proto.h b/source3/libsmb/proto.h index babd5f9dabf..f7903458a9a 100644 --- a/source3/libsmb/proto.h +++ b/source3/libsmb/proto.h @@ -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); -- 2.47.3