From f58f1468345b585ea00680a3a08c19644d147d53 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 20 Oct 2006 07:44:09 +0000 Subject: r19422: Doh ! Put the krb5 user@realm code in the right place. Jeremy. (This used to be commit a31bbbaee1042143d750a29b8fcec4720bfdb374) --- source3/utils/net.c | 40 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) diff --git a/source3/utils/net.c b/source3/utils/net.c index a43fae5c80..a6fae57bc3 100644 --- a/source3/utils/net.c +++ b/source3/utils/net.c @@ -160,6 +160,7 @@ int net_run_function2(int argc, const char **argv, const char *whoami, /**************************************************************************** connect to \\server\service ****************************************************************************/ + NTSTATUS connect_to_service(struct cli_state **c, struct in_addr *server_ip, const char *server_name, const char *service_name, @@ -173,13 +174,13 @@ NTSTATUS connect_to_service(struct cli_state **c, struct in_addr *server_ip, opt_password = SMB_STRDUP(pass); } } - + nt_status = cli_full_connection(c, NULL, server_name, server_ip, opt_port, service_name, service_type, opt_user_name, opt_workgroup, opt_password, 0, Undefined, NULL); - + if (NT_STATUS_IS_OK(nt_status)) { return nt_status; } else { @@ -235,6 +236,24 @@ NTSTATUS connect_to_ipc_anonymous(struct cli_state **c, } } +/**************************************************************************** + Return malloced user@realm for krb5 login. +****************************************************************************/ + +static char *get_user_and_realm(const char *username) +{ + char *user_and_realm = NULL; + + if (strchr_m(username, '@')) { + user_and_realm = SMB_STRDUP(username); + } else { + if (asprintf(&user_and_realm, "%s@%s", username, lp_realm()) == -1) { + user_and_realm = NULL; + } + } + return user_and_realm; +} + /**************************************************************************** connect to \\server\ipc$ using KRB5 ****************************************************************************/ @@ -242,14 +261,29 @@ NTSTATUS connect_to_ipc_krb5(struct cli_state **c, struct in_addr *server_ip, const char *server_name) { NTSTATUS nt_status; + char *user_and_realm = NULL; + + if (!opt_password && !opt_machine_pass) { + char *pass = getpass("Password:"); + if (pass) { + opt_password = SMB_STRDUP(pass); + } + } + + user_and_realm = get_user_and_realm(opt_user_name); + if (!user_and_realm) { + return NT_STATUS_NO_MEMORY; + } nt_status = cli_full_connection(c, NULL, server_name, server_ip, opt_port, "IPC$", "IPC", - opt_user_name, opt_workgroup, + user_and_realm, opt_workgroup, opt_password, CLI_FULL_CONNECTION_USE_KERBEROS, Undefined, NULL); + SAFE_FREE(user_and_realm); + if (NT_STATUS_IS_OK(nt_status)) { return nt_status; } else { -- cgit