From 02075be0bbc2095073f8898350fded64a7c97c79 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 21 Mar 2005 02:08:38 +0000 Subject: r5917: First step in using the new cli_credentials structure. This patch puts support for it into popt_common, adds a few utility functions (in lib/credentials.c) and the callback functions for the command-line (lib/cmdline/credentials.c). Comments are welcome :-) (This used to be commit 1d49b57c50fe8c2683ea23e9df41ce8ad774db98) --- source4/lib/cmdline/credentials.c | 49 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 source4/lib/cmdline/credentials.c (limited to 'source4/lib/cmdline/credentials.c') diff --git a/source4/lib/cmdline/credentials.c b/source4/lib/cmdline/credentials.c new file mode 100644 index 0000000000..d827baed76 --- /dev/null +++ b/source4/lib/cmdline/credentials.c @@ -0,0 +1,49 @@ +/* + Unix SMB/CIFS implementation. + + Copyright (C) Jelmer Vernooij 2005 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" +#include "version.h" +#include "dynconfig.h" +#include "system/filesys.h" +#include "system/passwd.h" +#include "lib/cmdline/popt_common.h" + +static const char *cmdline_get_userpassword(struct cli_credentials *credentials) +{ + char *prompt; + char *ret; + + prompt = talloc_asprintf(NULL, "Password for [%s\\%s]:", + cli_credentials_get_domain(credentials), + cli_credentials_get_username(credentials)); + + ret = getpass(prompt); + + talloc_free(prompt); + return ret; +} + +void cli_credentials_set_cmdline_callbacks(struct cli_credentials *cred) +{ + if (cred->password_obtained <= CRED_CALLBACK) { + cred->password_cb = cmdline_get_userpassword; + cred->password_obtained = CRED_CALLBACK; + } +} -- cgit From 24186a80eb4887b5fb3e72e4b877b456cbe8e35f Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Mon, 29 Aug 2005 04:30:22 +0000 Subject: r9728: A *major* update to the credentials system, to incorporate the Kerberos CCACHE into the system. This again allows the use of the system ccache when no username is specified, and brings more code in common between gensec_krb5 and gensec_gssapi. It also has a side-effect that may (or may not) be expected: If there is a ccache, even if it is not used (perhaps the remote server didn't want kerberos), it will change the default username. Andrew Bartlett (This used to be commit 6202267f6ec1446d6bd11d1d37d05a977bc8d315) --- source4/lib/cmdline/credentials.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'source4/lib/cmdline/credentials.c') diff --git a/source4/lib/cmdline/credentials.c b/source4/lib/cmdline/credentials.c index d827baed76..7832e01e4b 100644 --- a/source4/lib/cmdline/credentials.c +++ b/source4/lib/cmdline/credentials.c @@ -29,14 +29,23 @@ static const char *cmdline_get_userpassword(struct cli_credentials *credentials) { char *prompt; char *ret; - - prompt = talloc_asprintf(NULL, "Password for [%s\\%s]:", - cli_credentials_get_domain(credentials), - cli_credentials_get_username(credentials)); + char *domain; + char *username; + TALLOC_CTX *mem_ctx = talloc_new(NULL); + + domain = cli_credentials_get_domain(credentials); + username = cli_credentials_get_username(credentials, mem_ctx); + if (domain && domain[0]) { + prompt = talloc_asprintf(mem_ctx, "Password for [%s\\%s]:", + domain, username); + } else { + prompt = talloc_asprintf(mem_ctx, "Password for [%s]:", + username); + } ret = getpass(prompt); - talloc_free(prompt); + talloc_free(mem_ctx); return ret; } -- cgit From 6f9b901fa0db18faae603db67d8d31e229d92c27 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Tue, 30 Aug 2005 01:19:41 +0000 Subject: r9772: Make credentials callbacks more consistant with the abstraction function interface used in the credentials code. Fix bug in ntlm_auth, where we would overwrite the PW specified as a first input. (Reported and chased by Kai Blin , bug #3040) Andrew Bartlett (This used to be commit 04af95bd31de39ad6aff349a4838dd77cb300034) --- source4/lib/cmdline/credentials.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) (limited to 'source4/lib/cmdline/credentials.c') diff --git a/source4/lib/cmdline/credentials.c b/source4/lib/cmdline/credentials.c index 7832e01e4b..f46a03b236 100644 --- a/source4/lib/cmdline/credentials.c +++ b/source4/lib/cmdline/credentials.c @@ -29,8 +29,8 @@ static const char *cmdline_get_userpassword(struct cli_credentials *credentials) { char *prompt; char *ret; - char *domain; - char *username; + const char *domain; + const char *username; TALLOC_CTX *mem_ctx = talloc_new(NULL); domain = cli_credentials_get_domain(credentials); @@ -51,8 +51,5 @@ static const char *cmdline_get_userpassword(struct cli_credentials *credentials) void cli_credentials_set_cmdline_callbacks(struct cli_credentials *cred) { - if (cred->password_obtained <= CRED_CALLBACK) { - cred->password_cb = cmdline_get_userpassword; - cred->password_obtained = CRED_CALLBACK; - } + cli_credentials_set_password_callback(cred, cmdline_get_userpassword); } -- cgit From d2a666acbe04f741387ff4351e3971b24f1c3b14 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 19 Sep 2005 13:26:07 +0000 Subject: r10316: More dynconfig fixes (This used to be commit 0963ab9c148772b961f17ec779213b0eb861e1dd) --- source4/lib/cmdline/credentials.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source4/lib/cmdline/credentials.c') diff --git a/source4/lib/cmdline/credentials.c b/source4/lib/cmdline/credentials.c index f46a03b236..f164663118 100644 --- a/source4/lib/cmdline/credentials.c +++ b/source4/lib/cmdline/credentials.c @@ -20,7 +20,6 @@ #include "includes.h" #include "version.h" -#include "dynconfig.h" #include "system/filesys.h" #include "system/passwd.h" #include "lib/cmdline/popt_common.h" -- cgit From 51cbc188df03f9ee38599fe5a87ec2608117a845 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Thu, 22 Sep 2005 01:50:58 +0000 Subject: r10402: Make the RPC-SAMLOGON test pass against Win2k3 SP0 again. I still have issues with Win2k3 SP1, and Samba4 doesn't pass it's own test for the moment, but I'm working on these issues :-) This required a change to the credentials API, so that the special case for NTLM logins using a principal was indeed handled as a special, not general case. Also don't set the realm from a ccache, as then it overrides --option=realm=. Andrew Bartlett (This used to be commit 194e8f07c0cb4685797c5a7a074577c62dfdebe3) --- source4/lib/cmdline/credentials.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source4/lib/cmdline/credentials.c') diff --git a/source4/lib/cmdline/credentials.c b/source4/lib/cmdline/credentials.c index f164663118..a3d4920e6d 100644 --- a/source4/lib/cmdline/credentials.c +++ b/source4/lib/cmdline/credentials.c @@ -32,8 +32,7 @@ static const char *cmdline_get_userpassword(struct cli_credentials *credentials) const char *username; TALLOC_CTX *mem_ctx = talloc_new(NULL); - domain = cli_credentials_get_domain(credentials); - username = cli_credentials_get_username(credentials, mem_ctx); + cli_credentials_get_ntlm_username_domain(credentials, mem_ctx, &username, &domain); if (domain && domain[0]) { prompt = talloc_asprintf(mem_ctx, "Password for [%s\\%s]:", domain, username); -- cgit From 46de306f13ec894c967a93121ac1b0847659cf01 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Sun, 18 Dec 2005 21:44:43 +0000 Subject: r12320: Add command-line processing hooks for simple bind DN, and password callback. We may change this in future. Andrew Bartlett (This used to be commit 5fec784d4795af0cf82d36766586ded134f62165) --- source4/lib/cmdline/credentials.c | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) (limited to 'source4/lib/cmdline/credentials.c') diff --git a/source4/lib/cmdline/credentials.c b/source4/lib/cmdline/credentials.c index a3d4920e6d..cb1ba5c963 100644 --- a/source4/lib/cmdline/credentials.c +++ b/source4/lib/cmdline/credentials.c @@ -32,13 +32,20 @@ static const char *cmdline_get_userpassword(struct cli_credentials *credentials) const char *username; TALLOC_CTX *mem_ctx = talloc_new(NULL); - cli_credentials_get_ntlm_username_domain(credentials, mem_ctx, &username, &domain); - if (domain && domain[0]) { - prompt = talloc_asprintf(mem_ctx, "Password for [%s\\%s]:", - domain, username); - } else { + const char *bind_dn = cli_credentials_get_bind_dn(credentials); + + if (bind_dn) { prompt = talloc_asprintf(mem_ctx, "Password for [%s]:", - username); + bind_dn); + } else { + cli_credentials_get_ntlm_username_domain(credentials, mem_ctx, &username, &domain); + if (domain && domain[0]) { + prompt = talloc_asprintf(mem_ctx, "Password for [%s\\%s]:", + domain, username); + } else { + prompt = talloc_asprintf(mem_ctx, "Password for [%s]:", + username); + } } ret = getpass(prompt); -- cgit From d4de4c2d210d2e8c9b5aedf70695594809ad6a0b Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 30 Dec 2005 13:16:54 +0000 Subject: r12608: Remove some unused #include lines. (This used to be commit 70e7449318aa0e9d2639c76730a7d1683b2f4981) --- source4/lib/cmdline/credentials.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'source4/lib/cmdline/credentials.c') diff --git a/source4/lib/cmdline/credentials.c b/source4/lib/cmdline/credentials.c index cb1ba5c963..b19cbf73c0 100644 --- a/source4/lib/cmdline/credentials.c +++ b/source4/lib/cmdline/credentials.c @@ -19,10 +19,7 @@ */ #include "includes.h" -#include "version.h" #include "system/filesys.h" -#include "system/passwd.h" -#include "lib/cmdline/popt_common.h" static const char *cmdline_get_userpassword(struct cli_credentials *credentials) { -- cgit From 3f16241a1d3243447d0244ebac05b447aec94df8 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Tue, 14 Mar 2006 01:29:56 +0000 Subject: r14363: Remove credentials.h from the global includes. (This used to be commit 98c4c3051391c6f89df5d133665f51bef66b1563) --- source4/lib/cmdline/credentials.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/lib/cmdline/credentials.c') diff --git a/source4/lib/cmdline/credentials.c b/source4/lib/cmdline/credentials.c index b19cbf73c0..b2ec67a72e 100644 --- a/source4/lib/cmdline/credentials.c +++ b/source4/lib/cmdline/credentials.c @@ -20,6 +20,7 @@ #include "includes.h" #include "system/filesys.h" +#include "auth/credentials/credentials.h" static const char *cmdline_get_userpassword(struct cli_credentials *credentials) { -- cgit From 1789976c172085569026e62bc563ff0ea017fe9d Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Wed, 3 May 2006 20:23:19 +0000 Subject: r15420: Add a new function to print a the 'unparsed' string format for usernames. This is used in the password prompt, and should be reversable by the parse string function. Also, don't look at the ccache, even for the guess code, if kerberos is disabled. Andrew Bartlett (This used to be commit 4c4b8e4b396ca44270a0456c732d3b9c3c34d69d) --- source4/lib/cmdline/credentials.c | 23 +++++------------------ 1 file changed, 5 insertions(+), 18 deletions(-) (limited to 'source4/lib/cmdline/credentials.c') diff --git a/source4/lib/cmdline/credentials.c b/source4/lib/cmdline/credentials.c index b2ec67a72e..3bf0a15677 100644 --- a/source4/lib/cmdline/credentials.c +++ b/source4/lib/cmdline/credentials.c @@ -24,27 +24,14 @@ static const char *cmdline_get_userpassword(struct cli_credentials *credentials) { - char *prompt; char *ret; - const char *domain; - const char *username; TALLOC_CTX *mem_ctx = talloc_new(NULL); - const char *bind_dn = cli_credentials_get_bind_dn(credentials); - - if (bind_dn) { - prompt = talloc_asprintf(mem_ctx, "Password for [%s]:", - bind_dn); - } else { - cli_credentials_get_ntlm_username_domain(credentials, mem_ctx, &username, &domain); - if (domain && domain[0]) { - prompt = talloc_asprintf(mem_ctx, "Password for [%s\\%s]:", - domain, username); - } else { - prompt = talloc_asprintf(mem_ctx, "Password for [%s]:", - username); - } - } + const char *prompt_name = cli_credentials_get_unparsed_name(credentials, mem_ctx); + const char *prompt; + + prompt = talloc_asprintf(mem_ctx, "Password for [%s]:", + prompt_name); ret = getpass(prompt); -- cgit From 0479a2f1cbae51fcd8dbdc3c148c808421fb4d25 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 02:07:03 +0000 Subject: r23792: convert Samba4 to GPLv3 There are still a few tidyups of old FSF addresses to come (in both s3 and s4). More commits soon. (This used to be commit fcf38a38ac691abd0fa51b89dc951a08e89fdafa) --- source4/lib/cmdline/credentials.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'source4/lib/cmdline/credentials.c') diff --git a/source4/lib/cmdline/credentials.c b/source4/lib/cmdline/credentials.c index 3bf0a15677..36e0504021 100644 --- a/source4/lib/cmdline/credentials.c +++ b/source4/lib/cmdline/credentials.c @@ -5,7 +5,7 @@ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -14,8 +14,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ #include "includes.h" -- cgit From 6131ff85d550b4c7b2f45e0860c5d90da61cc6b6 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 1 Sep 2007 20:25:24 +0000 Subject: r24868: Don't use callbacks for prompting when stdout is not a tty. (This used to be commit 9b02a39c156862f9e9258dcdb9b8b86715022fc1) --- source4/lib/cmdline/credentials.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'source4/lib/cmdline/credentials.c') diff --git a/source4/lib/cmdline/credentials.c b/source4/lib/cmdline/credentials.c index 36e0504021..2e5c6fd94a 100644 --- a/source4/lib/cmdline/credentials.c +++ b/source4/lib/cmdline/credentials.c @@ -38,7 +38,12 @@ static const char *cmdline_get_userpassword(struct cli_credentials *credentials) return ret; } -void cli_credentials_set_cmdline_callbacks(struct cli_credentials *cred) +bool cli_credentials_set_cmdline_callbacks(struct cli_credentials *cred) { - cli_credentials_set_password_callback(cred, cmdline_get_userpassword); + if (isatty(fileno(stdout))) { + cli_credentials_set_password_callback(cred, cmdline_get_userpassword); + return true; + } + + return false; } -- cgit