From 0f558c657b397ea914a34862fe5066411e35b9bb Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Tue, 1 May 2018 13:19:58 +1200 Subject: [PATCH] net: Add support for a credentials file Add support for the same -A authfile/--authentication-file authfile option that most of the other tools already do. Signed-off-by: Olly Betts --- docs-xml/manpages/net.8.xml | 1 + source3/utils/net.c | 25 +++++++++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/docs-xml/manpages/net.8.xml b/docs-xml/manpages/net.8.xml index 155c4fc7..3aa9a039 100644 --- a/docs-xml/manpages/net.8.xml +++ b/docs-xml/manpages/net.8.xml @@ -26,6 +26,7 @@ -w|--workgroup workgroup -W|--myworkgroup myworkgroup -U|--user user + -A|--authentication-file authfile -I|--ipaddress ip-address -p|--port port -n myname diff --git a/source3/utils/net.c b/source3/utils/net.c index 44daa608..ad7f501b 100644 --- a/source3/utils/net.c +++ b/source3/utils/net.c @@ -48,6 +48,7 @@ #include "../libcli/security/security.h" #include "passdb.h" #include "messages.h" +#include "auth/credentials/credentials.h" #ifdef WITH_FAKE_KASERVER #include "utils/net_afs.h" @@ -902,6 +903,26 @@ static struct functable net_func[] = { }; +static void get_credentials_file(struct net_context *c, + const char *file) +{ + struct cli_credentials *cred = cli_credentials_init(c); + + if (cred == NULL) { + d_printf("ERROR: Unable to allocate memory!\n"); + exit(-1); + } + + if (!cli_credentials_parse_file(cred, file, CRED_GUESS_FILE)) { + exit(-1); + } + + c->opt_user_name = cli_credentials_get_username(cred); + c->opt_user_specified = (c->opt_user_name != NULL); + c->opt_password = cli_credentials_get_password(cred); + c->opt_target_workgroup = cli_credentials_get_domain(cred); +} + /**************************************************************************** main program ****************************************************************************/ @@ -923,6 +944,7 @@ static struct functable net_func[] = { {"help", 'h', POPT_ARG_NONE, 0, 'h'}, {"workgroup", 'w', POPT_ARG_STRING, &c->opt_target_workgroup}, {"user", 'U', POPT_ARG_STRING, &c->opt_user_name, 'U'}, + {"authentication-file", 'A', POPT_ARG_STRING, &c->opt_user_name, 'A', "Get the credentials from a file", "FILE"}, {"ipaddress", 'I', POPT_ARG_STRING, 0,'I'}, {"port", 'p', POPT_ARG_INT, &c->opt_port}, {"myname", 'n', POPT_ARG_STRING, &c->opt_requester_name}, @@ -1023,6 +1045,9 @@ static struct functable net_func[] = { c->opt_password = p+1; } break; + case 'A': + get_credentials_file(c, c->opt_user_name); + break; default: d_fprintf(stderr, _("\nInvalid option %s: %s\n"), poptBadOption(pc, 0), poptStrerror(opt)); -- 2.17.0