summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorGünther Deschner <gd@samba.org>2007-07-19 13:07:22 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 12:28:50 -0500
commit7d3e5834ec441b371ec65595ed810011deee74d3 (patch)
treef087738f529ea360fad59dfe849ffc98546f0377 /source3
parent16443996b51f56b3c788d4f15e85ec0911a807b7 (diff)
downloadsamba-7d3e5834ec441b371ec65595ed810011deee74d3.tar.gz
samba-7d3e5834ec441b371ec65595ed810011deee74d3.tar.bz2
samba-7d3e5834ec441b371ec65595ed810011deee74d3.zip
r23968: Harmonize net's password prompts.
Guenther (This used to be commit 7e2fb14d6e4f58fe6645b7e7468f925c21cb4c9d)
Diffstat (limited to 'source3')
-rw-r--r--source3/utils/net.c44
-rw-r--r--source3/utils/net_ads.c7
2 files changed, 35 insertions, 16 deletions
diff --git a/source3/utils/net.c b/source3/utils/net.c
index 08df0b34f1..5a4568e033 100644
--- a/source3/utils/net.c
+++ b/source3/utils/net.c
@@ -168,11 +168,9 @@ NTSTATUS connect_to_service(struct cli_state **c, struct in_addr *server_ip,
{
NTSTATUS nt_status;
- if (!opt_password && !opt_machine_pass) {
- char *pass = getpass("Password:");
- if (pass) {
- opt_password = SMB_STRDUP(pass);
- }
+ opt_password = net_prompt_pass(opt_user_name);
+ if (!opt_password) {
+ return NT_STATUS_NO_MEMORY;
}
nt_status = cli_full_connection(c, NULL, server_name,
@@ -180,7 +178,6 @@ NTSTATUS connect_to_service(struct cli_state **c, struct in_addr *server_ip,
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 {
@@ -267,11 +264,9 @@ NTSTATUS connect_to_ipc_krb5(struct cli_state **c,
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);
- }
+ opt_password = net_prompt_pass(opt_user_name);
+ if (!opt_password) {
+ return NT_STATUS_NO_MEMORY;
}
user_and_realm = get_user_and_realm(opt_user_name);
@@ -834,6 +829,33 @@ static int net_maxrid(int argc, const char **argv)
return 0;
}
+/****************************************************************************
+****************************************************************************/
+
+const char *net_prompt_pass(const char *user)
+{
+ char *prompt = NULL;
+ const char *pass = NULL;
+
+ if (opt_password) {
+ return opt_password;
+ }
+
+ if (opt_machine_pass) {
+ return NULL;
+ }
+
+ asprintf(&prompt, "Enter %s's password:", user);
+ if (!prompt) {
+ return NULL;
+ }
+
+ pass = getpass(prompt);
+ SAFE_FREE(prompt);
+
+ return pass;
+}
+
/* main function table */
static struct functable net_func[] = {
{"RPC", net_rpc},
diff --git a/source3/utils/net_ads.c b/source3/utils/net_ads.c
index d4dfbb6a2b..71217b5137 100644
--- a/source3/utils/net_ads.c
+++ b/source3/utils/net_ads.c
@@ -244,14 +244,11 @@ retry_connect:
retry:
if (!opt_password && need_password && !opt_machine_pass) {
- char *prompt = NULL;
- asprintf(&prompt,"%s's password: ", opt_user_name);
- if (!prompt) {
+ opt_password = net_prompt_pass(opt_user_name);
+ if (!opt_password) {
ads_destroy(&ads);
return ADS_ERROR(LDAP_NO_MEMORY);
}
- opt_password = getpass(prompt);
- free(prompt);
}
if (opt_password) {