The branch, master has been updated via 8dd1faaa2992851f6852ba7ea4498445af5faadd (commit) from 153a837bd61338c0b912c43458900224de0654f7 (commit)
http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master - Log ----------------------------------------------------------------- commit 8dd1faaa2992851f6852ba7ea4498445af5faadd Author: Jeremy Allison <j...@samba.org> Date: Tue Mar 17 14:53:06 2009 -0700 Remove the global "struct cm_cred_struct" and associated calls, make callers pass in a struct user_auth_info * instead. This commit causes smbc_set_credentials() to print out a message telling callers to use smbc_set_credentials_with_fallback() instead, as smbc_set_credentials() has a broken API (no SMBCCTX * pointer). No more global variables used in the connection manager API for client dfs calls. Jeremy. ----------------------------------------------------------------------- Summary of changes: source3/client/client.c | 78 ++++++++++---------- source3/include/libsmb_internal.h | 6 ++ source3/include/popt_common.h | 1 + source3/include/proto.h | 15 ++--- source3/lib/netapi/cm.c | 32 ++++---- source3/lib/util.c | 40 ++++++++++ source3/libsmb/clidfs.c | 143 ++++++++++++------------------------ source3/libsmb/libsmb_context.c | 59 +++++++++------- source3/libsmb/libsmb_dir.c | 37 ++++++---- source3/libsmb/libsmb_file.c | 35 ++++++---- source3/libsmb/libsmb_stat.c | 5 +- source3/libsmb/libsmb_xattr.c | 37 +++++----- source3/rpcclient/rpcclient.c | 7 +-- source3/utils/net_rpc.c | 2 +- source3/utils/smbcacls.c | 7 +-- source3/utils/smbcquotas.c | 7 +-- source3/utils/smbtree.c | 7 +-- 17 files changed, 262 insertions(+), 256 deletions(-) Changeset truncated at 500 lines: diff --git a/source3/client/client.c b/source3/client/client.c index 6491f39..a6f31bc 100644 --- a/source3/client/client.c +++ b/source3/client/client.c @@ -103,6 +103,9 @@ struct cli_state *cli; static char CLI_DIRSEP_CHAR = '\\'; static char CLI_DIRSEP_STR[] = { '\\', '\0' }; +/* Authentication for client connections. */ +struct user_auth_info *auth_info; + /* Accessor functions for directory paths. */ static char *fileselection; static const char *client_get_fileselection(void) @@ -299,7 +302,7 @@ static int do_dskattr(void) char *targetpath = NULL; TALLOC_CTX *ctx = talloc_tos(); - if ( !cli_resolve_path(ctx, "", cli, client_get_cur_dir(), &targetcli, &targetpath)) { + if ( !cli_resolve_path(ctx, "", auth_info, cli, client_get_cur_dir(), &targetcli, &targetpath)) { d_printf("Error in dskattr: %s\n", cli_errstr(cli)); return 1; } @@ -393,7 +396,7 @@ static int do_cd(const char *new_dir) new_cd = clean_name(ctx, new_cd); client_set_cur_dir(new_cd); - if ( !cli_resolve_path(ctx, "", cli, new_cd, &targetcli, &targetpath)) { + if ( !cli_resolve_path(ctx, "", auth_info, cli, new_cd, &targetcli, &targetpath)) { d_printf("cd %s: %s\n", new_cd, cli_errstr(cli)); client_set_cur_dir(saved_dir); goto out; @@ -819,7 +822,7 @@ void do_list(const char *mask, /* check for dfs */ - if ( !cli_resolve_path(ctx, "", cli, head, &targetcli, &targetpath ) ) { + if ( !cli_resolve_path(ctx, "", auth_info, cli, head, &targetcli, &targetpath ) ) { d_printf("do_list: [%s] %s\n", head, cli_errstr(cli)); remove_do_list_queue_head(); continue; @@ -852,7 +855,7 @@ void do_list(const char *mask, } } else { /* check for dfs */ - if (cli_resolve_path(ctx, "", cli, mask, &targetcli, &targetpath)) { + if (cli_resolve_path(ctx, "", auth_info, cli, mask, &targetcli, &targetpath)) { if (cli_list(targetcli, targetpath, attribute, do_list_helper, NULL) == -1) { d_printf("%s listing %s\n", cli_errstr(targetcli), targetpath); @@ -1018,7 +1021,7 @@ static int do_get(const char *rname, const char *lname_in, bool reget) strlower_m(lname); } - if (!cli_resolve_path(ctx, "", cli, rname, &targetcli, &targetname ) ) { + if (!cli_resolve_path(ctx, "", auth_info, cli, rname, &targetcli, &targetname ) ) { d_printf("Failed to open %s: %s\n", rname, cli_errstr(cli)); return 1; } @@ -1381,7 +1384,7 @@ static bool do_mkdir(const char *name) struct cli_state *targetcli; char *targetname = NULL; - if (!cli_resolve_path(ctx, "", cli, name, &targetcli, &targetname)) { + if (!cli_resolve_path(ctx, "", auth_info, cli, name, &targetcli, &targetname)) { d_printf("mkdir %s: %s\n", name, cli_errstr(cli)); return false; } @@ -1464,7 +1467,7 @@ static int cmd_mkdir(void) return 1; } - if (!cli_resolve_path(ctx, "", cli, mask, &targetcli, &targetname)) { + if (!cli_resolve_path(ctx, "", auth_info, cli, mask, &targetcli, &targetname)) { return 1; } @@ -1625,7 +1628,7 @@ static int do_put(const char *rname, const char *lname, bool reput) struct push_state state; NTSTATUS status; - if (!cli_resolve_path(ctx, "", cli, rname, &targetcli, &targetname)) { + if (!cli_resolve_path(ctx, "", auth_info, cli, rname, &targetcli, &targetname)) { d_printf("Failed to open %s: %s\n", rname, cli_errstr(cli)); return 1; } @@ -2183,7 +2186,7 @@ static int cmd_wdel(void) return 1; } - if (!cli_resolve_path(ctx, "", cli, mask, &targetcli, &targetname)) { + if (!cli_resolve_path(ctx, "", auth_info, cli, mask, &targetcli, &targetname)) { d_printf("cmd_wdel %s: %s\n", mask, cli_errstr(cli)); return 1; } @@ -2218,7 +2221,7 @@ static int cmd_open(void) return 1; } - if (!cli_resolve_path(ctx, "", cli, mask, &targetcli, &targetname)) { + if (!cli_resolve_path(ctx, "", auth_info, cli, mask, &targetcli, &targetname)) { d_printf("open %s: %s\n", mask, cli_errstr(cli)); return 1; } @@ -2311,7 +2314,7 @@ static int cmd_posix_open(void) } mode = (mode_t)strtol(buf, (char **)NULL, 8); - if (!cli_resolve_path(ctx, "", cli, mask, &targetcli, &targetname)) { + if (!cli_resolve_path(ctx, "", auth_info, cli, mask, &targetcli, &targetname)) { d_printf("posix_open %s: %s\n", mask, cli_errstr(cli)); return 1; } @@ -2359,7 +2362,7 @@ static int cmd_posix_mkdir(void) } mode = (mode_t)strtol(buf, (char **)NULL, 8); - if (!cli_resolve_path(ctx, "", cli, mask, &targetcli, &targetname)) { + if (!cli_resolve_path(ctx, "", auth_info, cli, mask, &targetcli, &targetname)) { d_printf("posix_mkdir %s: %s\n", mask, cli_errstr(cli)); return 1; } @@ -2393,7 +2396,7 @@ static int cmd_posix_unlink(void) return 1; } - if (!cli_resolve_path(ctx, "", cli, mask, &targetcli, &targetname)) { + if (!cli_resolve_path(ctx, "", auth_info, cli, mask, &targetcli, &targetname)) { d_printf("posix_unlink %s: %s\n", mask, cli_errstr(cli)); return 1; } @@ -2427,7 +2430,7 @@ static int cmd_posix_rmdir(void) return 1; } - if (!cli_resolve_path(ctx, "", cli, mask, &targetcli, &targetname)) { + if (!cli_resolve_path(ctx, "", auth_info, cli, mask, &targetcli, &targetname)) { d_printf("posix_rmdir %s: %s\n", mask, cli_errstr(cli)); return 1; } @@ -2667,7 +2670,7 @@ static int cmd_rmdir(void) return 1; } - if (!cli_resolve_path(ctx, "", cli, mask, &targetcli, &targetname)) { + if (!cli_resolve_path(ctx, "", auth_info, cli, mask, &targetcli, &targetname)) { d_printf("rmdir %s: %s\n", mask, cli_errstr(cli)); return 1; } @@ -2714,7 +2717,7 @@ static int cmd_link(void) return 1; } - if (!cli_resolve_path(ctx, "", cli, oldname, &targetcli, &targetname)) { + if (!cli_resolve_path(ctx, "", auth_info, cli, oldname, &targetcli, &targetname)) { d_printf("link %s: %s\n", oldname, cli_errstr(cli)); return 1; } @@ -2765,7 +2768,7 @@ static int cmd_symlink(void) return 1; } - if (!cli_resolve_path(ctx, "", cli, oldname, &targetcli, &targetname)) { + if (!cli_resolve_path(ctx, "", auth_info, cli, oldname, &targetcli, &targetname)) { d_printf("link %s: %s\n", oldname, cli_errstr(cli)); return 1; } @@ -2813,7 +2816,7 @@ static int cmd_chmod(void) mode = (mode_t)strtol(buf, NULL, 8); - if (!cli_resolve_path(ctx, "", cli, src, &targetcli, &targetname)) { + if (!cli_resolve_path(ctx, "", auth_info, cli, src, &targetcli, &targetname)) { d_printf("chmod %s: %s\n", src, cli_errstr(cli)); return 1; } @@ -2966,7 +2969,7 @@ static int cmd_getfacl(void) return 1; } - if (!cli_resolve_path(ctx, "", cli, src, &targetcli, &targetname)) { + if (!cli_resolve_path(ctx, "", auth_info, cli, src, &targetcli, &targetname)) { d_printf("stat %s: %s\n", src, cli_errstr(cli)); return 1; } @@ -3132,7 +3135,7 @@ static int cmd_stat(void) return 1; } - if (!cli_resolve_path(ctx, "", cli, src, &targetcli, &targetname)) { + if (!cli_resolve_path(ctx, "", auth_info, cli, src, &targetcli, &targetname)) { d_printf("stat %s: %s\n", src, cli_errstr(cli)); return 1; } @@ -3233,7 +3236,7 @@ static int cmd_chown(void) if (!src) { return 1; } - if (!cli_resolve_path(ctx, "", cli, src, &targetcli, &targetname) ) { + if (!cli_resolve_path(ctx, "", auth_info, cli, src, &targetcli, &targetname) ) { d_printf("chown %s: %s\n", src, cli_errstr(cli)); return 1; } @@ -3287,12 +3290,12 @@ static int cmd_rename(void) return 1; } - if (!cli_resolve_path(ctx, "", cli, src, &targetcli, &targetsrc)) { + if (!cli_resolve_path(ctx, "", auth_info, cli, src, &targetcli, &targetsrc)) { d_printf("rename %s: %s\n", src, cli_errstr(cli)); return 1; } - if (!cli_resolve_path(ctx, "", cli, dest, &targetcli, &targetdest)) { + if (!cli_resolve_path(ctx, "", auth_info, cli, dest, &targetcli, &targetdest)) { d_printf("rename %s: %s\n", dest, cli_errstr(cli)); return 1; } @@ -3362,7 +3365,7 @@ static int cmd_hardlink(void) return 1; } - if (!cli_resolve_path(ctx, "", cli, src, &targetcli, &targetname)) { + if (!cli_resolve_path(ctx, "", auth_info, cli, src, &targetcli, &targetname)) { d_printf("hardlink %s: %s\n", src, cli_errstr(cli)); return 1; } @@ -3829,7 +3832,7 @@ static int cmd_show_connect( void ) struct cli_state *targetcli; char *targetpath; - if (!cli_resolve_path(ctx, "", cli, client_get_cur_dir(), + if (!cli_resolve_path(ctx, "", auth_info, cli, client_get_cur_dir(), &targetcli, &targetpath ) ) { d_printf("showconnect %s: %s\n", cur_dir, cli_errstr(cli)); return 1; @@ -4051,7 +4054,8 @@ static int process_command_string(const char *cmd_in) if (!cli) { cli = cli_cm_open(talloc_tos(), NULL, have_ip ? dest_ss_str : desthost, - service, true, smb_encrypt, + service, auth_info, + true, smb_encrypt, max_protocol, port, name_type); if (!cli) { return 1; @@ -4220,7 +4224,7 @@ static char **remote_completion(const char *text, int len) goto cleanup; } - if (!cli_resolve_path(ctx, "", cli, dirmask, &targetcli, &targetpath)) { + if (!cli_resolve_path(ctx, "", auth_info, cli, dirmask, &targetcli, &targetpath)) { goto cleanup; } if (cli_list(targetcli, targetpath, aDIR | aSYSTEM | aHIDDEN, @@ -4517,7 +4521,7 @@ static int process(const char *base_directory) cli = cli_cm_open(talloc_tos(), NULL, have_ip ? dest_ss_str : desthost, - service, true, smb_encrypt, + service, auth_info, true, smb_encrypt, max_protocol, port, name_type); if (!cli) { return 1; @@ -4550,7 +4554,7 @@ static int do_host_query(const char *query_host) struct sockaddr_storage ss; cli = cli_cm_open(talloc_tos(), NULL, - query_host, "IPC$", true, smb_encrypt, + query_host, "IPC$", auth_info, true, smb_encrypt, max_protocol, port, name_type); if (!cli) return 1; @@ -4570,7 +4574,7 @@ static int do_host_query(const char *query_host) cli_shutdown(cli); cli = cli_cm_open(talloc_tos(), NULL, - query_host, "IPC$", true, smb_encrypt, + query_host, "IPC$", auth_info, true, smb_encrypt, max_protocol, 139, name_type); } @@ -4598,7 +4602,7 @@ static int do_tar_op(const char *base_directory) if (!cli) { cli = cli_cm_open(talloc_tos(), NULL, have_ip ? dest_ss_str : desthost, - service, true, smb_encrypt, + service, auth_info, true, smb_encrypt, max_protocol, port, name_type); if (!cli) return 1; @@ -4625,7 +4629,7 @@ static int do_tar_op(const char *base_directory) Handle a message operation. ****************************************************************************/ -static int do_message_op(struct user_auth_info *auth_info) +static int do_message_op(struct user_auth_info *a_info) { struct sockaddr_storage ss; struct nmb_name called, calling; @@ -4667,7 +4671,7 @@ static int do_message_op(struct user_auth_info *auth_info) return 1; } - send_message(get_cmdline_auth_info_username(auth_info)); + send_message(get_cmdline_auth_info_username(a_info)); cli_shutdown(cli); return 0; @@ -4714,7 +4718,6 @@ static int do_message_op(struct user_auth_info *auth_info) POPT_TABLEEND }; TALLOC_CTX *frame = talloc_stackframe(); - struct user_auth_info *auth_info; if (!client_set_cur_dir("\\")) { exit(ENOMEM); @@ -4970,12 +4973,11 @@ static int do_message_op(struct user_auth_info *auth_info) poptFreeContext(pc); - /* Store the username and password for dfs support */ - - cli_cm_set_credentials(auth_info); - DEBUG(3,("Client started (version %s).\n", samba_version_string())); + /* Ensure we have a password (or equivalent). */ + set_cmdline_auth_info_getpass(auth_info); + if (tar_type) { if (cmdstr) process_command_string(cmdstr); diff --git a/source3/include/libsmb_internal.h b/source3/include/libsmb_internal.h index 166685c..e28c853 100644 --- a/source3/include/libsmb_internal.h +++ b/source3/include/libsmb_internal.h @@ -181,6 +181,12 @@ struct SMBC_internal_data { */ bool case_sensitive; + /* + * Auth info needed for DFS traversal. + */ + + struct user_auth_info *auth_info; + struct smbc_server_cache * server_cache; /* POSIX emulation functions */ diff --git a/source3/include/popt_common.h b/source3/include/popt_common.h index bbd013a..ae8378f 100644 --- a/source3/include/popt_common.h +++ b/source3/include/popt_common.h @@ -53,6 +53,7 @@ struct user_auth_info { int signing_state; bool smb_encrypt; bool use_machine_account; + bool fallback_after_kerberos; }; #endif /* _POPT_COMMON_H */ diff --git a/source3/include/proto.h b/source3/include/proto.h index ce0372f..d3db1e8 100644 --- a/source3/include/proto.h +++ b/source3/include/proto.h @@ -1084,6 +1084,9 @@ int get_cmdline_auth_info_signing_state(const struct user_auth_info *auth_info); void set_cmdline_auth_info_use_kerberos(struct user_auth_info *auth_info, bool b); bool get_cmdline_auth_info_use_kerberos(const struct user_auth_info *auth_info); +void set_cmdline_auth_info_fallback_after_kerberos(struct user_auth_info *auth_info, + bool b); +bool get_cmdline_auth_info_fallback_after_kerberos(const struct user_auth_info *auth_info); void set_cmdline_auth_info_use_krb5_ticket(struct user_auth_info *auth_info); void set_cmdline_auth_info_smb_encrypt(struct user_auth_info *auth_info); void set_cmdline_auth_info_use_machine_account(struct user_auth_info *auth_info); @@ -1093,6 +1096,7 @@ bool get_cmdline_auth_info_use_machine_account(const struct user_auth_info *auth struct user_auth_info *get_cmdline_auth_info_copy(TALLOC_CTX *mem_ctx, const struct user_auth_info *info); bool set_cmdline_auth_info_machine_account_creds(struct user_auth_info *auth_info); +void set_cmdline_auth_info_getpass(struct user_auth_info *auth_info); bool add_gid_to_array_unique(TALLOC_CTX *mem_ctx, gid_t gid, gid_t **gids, size_t *num_gids); bool file_exist_stat(const char *fname,SMB_STRUCT_STAT *sbuf); @@ -2359,21 +2363,13 @@ struct cli_state *cli_cm_open(TALLOC_CTX *ctx, struct cli_state *referring_cli, const char *server, const char *share, + const struct user_auth_info *auth_info, bool show_hdr, bool force_encrypt, int max_protocol, int port, int name_type); void cli_cm_display(const struct cli_state *c); -void cli_cm_set_credentials(struct user_auth_info *auth_info); -void cli_cm_set_port(int port_number); -void cli_cm_set_dest_name_type(int type); -void cli_cm_set_signing_state(int state); -void cli_cm_set_username(const char *username); -void cli_cm_set_password(const char *newpass); -void cli_cm_set_use_kerberos(void); -void cli_cm_set_fallback_after_kerberos(void); -void cli_cm_set_dest_ss(struct sockaddr_storage *pss); bool cli_dfs_get_referral(TALLOC_CTX *ctx, struct cli_state *cli, const char *path, @@ -2382,6 +2378,7 @@ bool cli_dfs_get_referral(TALLOC_CTX *ctx, uint16 *consumed); bool cli_resolve_path(TALLOC_CTX *ctx, const char *mountpt, + const struct user_auth_info *dfs_auth_info, struct cli_state *rootcli, const char *path, struct cli_state **targetcli, diff --git a/source3/lib/netapi/cm.c b/source3/lib/netapi/cm.c index 43ebed6..b676ae6 100644 --- a/source3/lib/netapi/cm.c +++ b/source3/lib/netapi/cm.c @@ -29,36 +29,36 @@ static WERROR libnetapi_open_ipc_connection(struct libnetapi_ctx *ctx, const char *server_name, struct cli_state **cli) { + struct user_auth_info *auth_info = NULL; struct cli_state *cli_ipc = NULL; if (!ctx || !cli || !server_name) { return WERR_INVALID_PARAM; } - cli_cm_set_signing_state(Undefined); - - if (ctx->use_kerberos) { - cli_cm_set_use_kerberos(); - } - - if (ctx->password) { - cli_cm_set_password(ctx->password); - } - if (ctx->username) { - cli_cm_set_username(ctx->username); + auth_info = user_auth_info_init(NULL); + if (!auth_info) { + return WERR_NOMEM; } + auth_info->signing_state = Undefined; + set_cmdline_auth_info_use_kerberos(auth_info, ctx->use_kerberos); + set_cmdline_auth_info_password(auth_info, ctx->password); + set_cmdline_auth_info_username(auth_info, ctx->username); if (ctx->username && ctx->username[0] && ctx->password && ctx->password[0] && ctx->use_kerberos) { - cli_cm_set_fallback_after_kerberos(); + set_cmdline_auth_info_fallback_after_kerberos(auth_info, true); } cli_ipc = cli_cm_open(ctx, NULL, - server_name, "IPC$", - false, false, - PROTOCOL_NT1, - 0, 0x20); + server_name, "IPC$", + auth_info, + false, false, + PROTOCOL_NT1, + 0, 0x20); + TALLOC_FREE(auth_info); + if (!cli_ipc) { libnetapi_set_error_string(ctx, "Failed to connect to IPC$ share on %s", server_name); diff --git a/source3/lib/util.c b/source3/lib/util.c index 613cc1e..80a807d 100644 --- a/source3/lib/util.c +++ b/source3/lib/util.c @@ -320,6 +320,9 @@ void set_cmdline_auth_info_password(struct user_auth_info *auth_info, const char *password) { TALLOC_FREE(auth_info->password); + if (password == NULL) { + password = ""; + } auth_info->password = talloc_strdup(auth_info, password); if (!auth_info->password) { exit(ENOMEM); @@ -362,6 +365,17 @@ bool get_cmdline_auth_info_use_kerberos(const struct user_auth_info *auth_info) return auth_info->use_kerberos; } +void set_cmdline_auth_info_fallback_after_kerberos(struct user_auth_info *auth_info, + bool b) +{ + auth_info->fallback_after_kerberos = b; +} + +bool get_cmdline_auth_info_fallback_after_kerberos(const struct user_auth_info *auth_info) +{ + return auth_info->fallback_after_kerberos; +} -- Samba Shared Repository