From 6eaa06ac53840f36a9c75650f21565828e8fbbd4 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 29 Jul 2002 09:23:01 +0000 Subject: A place to store common popt routines. (This used to be commit b5b64a4e90792000fc377a032cd5c7cb9918261b) --- source3/lib/popt_common.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 source3/lib/popt_common.c (limited to 'source3/lib/popt_common.c') diff --git a/source3/lib/popt_common.c b/source3/lib/popt_common.c new file mode 100644 index 0000000000..288cd41b27 --- /dev/null +++ b/source3/lib/popt_common.c @@ -0,0 +1,49 @@ +/* + Unix SMB/CIFS implementation. + Common popt routines + + Copyright (C) Tim Potter 2001,2002 + + 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" + +/* Handle -d,--debuglevel command line option */ + +static void debug_callback(poptContext con, + enum poptCallbackReason reason, + const struct poptOption *opt, + const char *arg, const void *data) +{ + extern BOOL AllowDebugChange; + + switch(opt->val) { + case 'd': + if (arg) { + DEBUGLEVEL = atoi(arg); + AllowDebugChange = False; + } + + break; + } +} + +struct poptOption popt_common_debug[] = { + { NULL, 0, POPT_ARG_CALLBACK, debug_callback }, + { "debuglevel", 'd', POPT_ARG_INT, NULL, 'd', "Set debug level", + "DEBUGLEVEL" }, + POPT_TABLEEND +}; -- cgit From 362f534fa1152e9fc3d195bd1200b4c5d3e037e2 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 29 Jul 2002 23:50:54 +0000 Subject: Our include popt is starting to get a bit old - fixed some compile problems here. Also fixed some non-constant initialisers in samsync. (This used to be commit 33bd7214736dafd5927d63af5f8510646b81e7df) --- source3/lib/popt_common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/popt_common.c') diff --git a/source3/lib/popt_common.c b/source3/lib/popt_common.c index 288cd41b27..a3d6af4fbc 100644 --- a/source3/lib/popt_common.c +++ b/source3/lib/popt_common.c @@ -45,5 +45,5 @@ struct poptOption popt_common_debug[] = { { NULL, 0, POPT_ARG_CALLBACK, debug_callback }, { "debuglevel", 'd', POPT_ARG_INT, NULL, 'd', "Set debug level", "DEBUGLEVEL" }, - POPT_TABLEEND + { 0 } }; -- cgit From a834a73e341059be154426390304a42e4a011f72 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Wed, 25 Sep 2002 15:19:00 +0000 Subject: sync'ing up for 3.0alpha20 release (This used to be commit 65e7b5273bb58802bf0c389b77f7fcae0a1f6139) --- source3/lib/popt_common.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/lib/popt_common.c') diff --git a/source3/lib/popt_common.c b/source3/lib/popt_common.c index a3d6af4fbc..bbc17cb704 100644 --- a/source3/lib/popt_common.c +++ b/source3/lib/popt_common.c @@ -33,7 +33,7 @@ static void debug_callback(poptContext con, switch(opt->val) { case 'd': if (arg) { - DEBUGLEVEL = atoi(arg); + debug_parse_levels(arg); AllowDebugChange = False; } @@ -43,7 +43,7 @@ static void debug_callback(poptContext con, struct poptOption popt_common_debug[] = { { NULL, 0, POPT_ARG_CALLBACK, debug_callback }, - { "debuglevel", 'd', POPT_ARG_INT, NULL, 'd', "Set debug level", + { "debuglevel", 'd', POPT_ARG_STRING, NULL, 'd', "Set debug level", "DEBUGLEVEL" }, { 0 } }; -- cgit From 3a53724d1cf9bf174c2d944e1b5a677283aed255 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 28 Oct 2002 19:44:11 +0000 Subject: Sync with HEAD (This used to be commit 4ae350671ef8aeae52995b3ca79e135cf444ae39) --- source3/lib/popt_common.c | 58 +++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 53 insertions(+), 5 deletions(-) (limited to 'source3/lib/popt_common.c') diff --git a/source3/lib/popt_common.c b/source3/lib/popt_common.c index bbc17cb704..21ee94d2e6 100644 --- a/source3/lib/popt_common.c +++ b/source3/lib/popt_common.c @@ -3,6 +3,7 @@ Common popt routines Copyright (C) Tim Potter 2001,2002 + Copyright (C) Jelmer Vernooij 2002 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 @@ -21,29 +22,76 @@ #include "includes.h" -/* Handle -d,--debuglevel command line option */ +/* Handle command line options: + * -d,--debuglevel + * -s,--configfile + * -O,--socket-options + */ -static void debug_callback(poptContext con, +extern pstring user_socket_options; +extern BOOL AllowDebugChange; +extern pstring global_myname; + +static void popt_common_callback(poptContext con, enum poptCallbackReason reason, const struct poptOption *opt, const char *arg, const void *data) { - extern BOOL AllowDebugChange; - switch(opt->val) { case 'd': if (arg) { debug_parse_levels(arg); AllowDebugChange = False; } + break; + case 'V': + printf( "Version %s\n", VERSION ); + exit(0); + break; + + case 'O': + pstrcpy(user_socket_options,arg); + break; + + case 's': + pstrcpy(dyn_CONFIGFILE, arg); + break; + + case 'n': + pstrcpy(global_myname,arg); + strupper(global_myname); break; } } struct poptOption popt_common_debug[] = { - { NULL, 0, POPT_ARG_CALLBACK, debug_callback }, + { NULL, 0, POPT_ARG_CALLBACK, popt_common_callback }, { "debuglevel", 'd', POPT_ARG_STRING, NULL, 'd', "Set debug level", "DEBUGLEVEL" }, { 0 } }; + +struct poptOption popt_common_configfile[] = { + { NULL, 0, POPT_ARG_CALLBACK, popt_common_callback }, + { "configfile", 's', POPT_ARG_STRING, NULL, 's', "Use alternative configuration file" }, + { 0 } +}; + +struct poptOption popt_common_socket_options[] = { + { NULL, 0, POPT_ARG_CALLBACK, popt_common_callback }, + {"socket-options", 'O', POPT_ARG_STRING, NULL, 'O', "socket options to use" }, + { 0 } +}; + +struct poptOption popt_common_version[] = { + { NULL, 0, POPT_ARG_CALLBACK, popt_common_callback }, + {"version", 'V', POPT_ARG_NONE, NULL, 'V', "Print version" }, + { 0 } +}; + +struct poptOption popt_common_netbios_name[] = { + { NULL, 0, POPT_ARG_CALLBACK, popt_common_callback }, + {"netbiosname", 'n', POPT_ARG_STRING, NULL, 'n', "Primary netbios name"}, + { 0 } +}; -- cgit From dc5297f413c40f04e1fdae719e29d949e3301091 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 9 Nov 2002 16:57:45 +0000 Subject: Sync with HEAD (This used to be commit 1a25dc776ddc36de9a214e023becff1ceb10290c) --- source3/lib/popt_common.c | 53 ++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 46 insertions(+), 7 deletions(-) (limited to 'source3/lib/popt_common.c') diff --git a/source3/lib/popt_common.c b/source3/lib/popt_common.c index 21ee94d2e6..aaec448762 100644 --- a/source3/lib/popt_common.c +++ b/source3/lib/popt_common.c @@ -23,9 +23,12 @@ #include "includes.h" /* Handle command line options: - * -d,--debuglevel - * -s,--configfile - * -O,--socket-options + * d,--debuglevel + * s,--configfile + * O,--socket-options + * V,--version + * l,--log-base + * n,--netbios-name */ extern pstring user_socket_options; @@ -37,6 +40,23 @@ static void popt_common_callback(poptContext con, const struct poptOption *opt, const char *arg, const void *data) { + pstring logfile; + const char *pname; + + /* Find out basename of current program */ + pname = strrchr_m(poptGetInvocationName(con),'/'); + + if (!pname) + pname = poptGetInvocationName(con); + else + pname++; + + if (reason == POPT_CALLBACK_REASON_PRE) { + pstr_sprintf(logfile, "%s/log.%s", dyn_LOGFILEBASE, pname); + lp_set_logfile(logfile); + return; + } + switch(opt->val) { case 'd': if (arg) { @@ -51,16 +71,29 @@ static void popt_common_callback(poptContext con, break; case 'O': - pstrcpy(user_socket_options,arg); + if (arg) { + pstrcpy(user_socket_options,arg); + } break; case 's': - pstrcpy(dyn_CONFIGFILE, arg); + if (arg) { + pstrcpy(dyn_CONFIGFILE, arg); + } break; case 'n': - pstrcpy(global_myname,arg); - strupper(global_myname); + if (arg) { + pstrcpy(global_myname,arg); + strupper(global_myname); + } + break; + + case 'l': + if (arg) { + pstr_sprintf(logfile, "%s/log.%s", arg, pname); + lp_set_logfile(logfile); + } break; } } @@ -95,3 +128,9 @@ struct poptOption popt_common_netbios_name[] = { {"netbiosname", 'n', POPT_ARG_STRING, NULL, 'n', "Primary netbios name"}, { 0 } }; + +struct poptOption popt_common_log_base[] = { + { NULL, 0, POPT_ARG_CALLBACK|POPT_CBFLAG_PRE, popt_common_callback }, + { "log-basename", 'l', POPT_ARG_STRING, NULL, 'l', "Basename for log/debug files"}, + { 0 } +}; -- cgit From 2f194322d419350f35a48dff750066894d68eccf Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 12 Nov 2002 23:20:50 +0000 Subject: Removed global_myworkgroup, global_myname, global_myscope. Added liberal dashes of const. This is a rather large check-in, some things may break. It does compile though :-). Jeremy. (This used to be commit f755711df8f74f9b8e8c1a2b0d07d02a931eeb89) --- source3/lib/popt_common.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'source3/lib/popt_common.c') diff --git a/source3/lib/popt_common.c b/source3/lib/popt_common.c index aaec448762..77c44f127a 100644 --- a/source3/lib/popt_common.c +++ b/source3/lib/popt_common.c @@ -33,7 +33,6 @@ extern pstring user_socket_options; extern BOOL AllowDebugChange; -extern pstring global_myname; static void popt_common_callback(poptContext con, enum poptCallbackReason reason, @@ -84,8 +83,7 @@ static void popt_common_callback(poptContext con, case 'n': if (arg) { - pstrcpy(global_myname,arg); - strupper(global_myname); + set_global_myname(arg); } break; -- cgit From 63cbbe26923b8f6bbed11428a3a218a88d17ffe7 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 14 Apr 2003 03:30:20 +0000 Subject: Merge Jelmer's popt updates from HEAD. (This used to be commit 98e84b3e83d2a365c818ea64f9418edb29d690f2) --- source3/lib/popt_common.c | 272 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 240 insertions(+), 32 deletions(-) (limited to 'source3/lib/popt_common.c') diff --git a/source3/lib/popt_common.c b/source3/lib/popt_common.c index 77c44f127a..6920ef4d5f 100644 --- a/source3/lib/popt_common.c +++ b/source3/lib/popt_common.c @@ -3,7 +3,7 @@ Common popt routines Copyright (C) Tim Potter 2001,2002 - Copyright (C) Jelmer Vernooij 2002 + Copyright (C) Jelmer Vernooij 2002,2003 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 @@ -23,17 +23,21 @@ #include "includes.h" /* Handle command line options: - * d,--debuglevel - * s,--configfile - * O,--socket-options - * V,--version - * l,--log-base - * n,--netbios-name + * -d,--debuglevel + * -s,--configfile + * -O,--socket-options + * -V,--version + * -l,--log-base + * -n,--netbios-name + * -W,--workgroup + * -i,--scope */ extern pstring user_socket_options; extern BOOL AllowDebugChange; +struct user_auth_info cmdline_auth_info; + static void popt_common_callback(poptContext con, enum poptCallbackReason reason, const struct poptOption *opt, @@ -93,42 +97,246 @@ static void popt_common_callback(poptContext con, lp_set_logfile(logfile); } break; + + case 'i': + if (arg) { + set_global_scope(arg); + } + break; + + case 'W': + if (arg) { + set_global_myworkgroup(arg); + } + break; } } -struct poptOption popt_common_debug[] = { +struct poptOption popt_common_connection[] = { { NULL, 0, POPT_ARG_CALLBACK, popt_common_callback }, - { "debuglevel", 'd', POPT_ARG_STRING, NULL, 'd', "Set debug level", - "DEBUGLEVEL" }, - { 0 } + { "socket-options", 'O', POPT_ARG_STRING, NULL, 'O', "socket options to use", + "SOCKETOPTIONS" }, + { "netbiosname", 'n', POPT_ARG_STRING, NULL, 'n', "Primary netbios name", "NETBIOSNAME" }, + { "workgroup", 'W', POPT_ARG_STRING, NULL, 'W', "Set the workgroup name", "WORKGROUP" }, + { "scope", 'i', POPT_ARG_STRING, NULL, 'i', "Use this Netbios scope", "SCOPE" }, + POPT_TABLEEND }; -struct poptOption popt_common_configfile[] = { - { NULL, 0, POPT_ARG_CALLBACK, popt_common_callback }, - { "configfile", 's', POPT_ARG_STRING, NULL, 's', "Use alternative configuration file" }, - { 0 } -}; - -struct poptOption popt_common_socket_options[] = { - { NULL, 0, POPT_ARG_CALLBACK, popt_common_callback }, - {"socket-options", 'O', POPT_ARG_STRING, NULL, 'O', "socket options to use" }, - { 0 } +struct poptOption popt_common_samba[] = { + { NULL, 0, POPT_ARG_CALLBACK|POPT_CBFLAG_PRE, popt_common_callback }, + { "debuglevel", 'd', POPT_ARG_STRING, NULL, 'd', "Set debug level", "DEBUGLEVEL" }, + { "configfile", 's', POPT_ARG_STRING, NULL, 's', "Use alternative configuration file", "CONFIGFILE" }, + { "log-basename", 'l', POPT_ARG_STRING, NULL, 'l', "Basename for log/debug files", "LOGFILEBASE" }, + { "version", 'V', POPT_ARG_NONE, NULL, 'V', "Print version" }, + POPT_TABLEEND }; struct poptOption popt_common_version[] = { { NULL, 0, POPT_ARG_CALLBACK, popt_common_callback }, - {"version", 'V', POPT_ARG_NONE, NULL, 'V', "Print version" }, - { 0 } + { "version", 'V', POPT_ARG_NONE, NULL, 'V', "Print version" }, + POPT_TABLEEND }; -struct poptOption popt_common_netbios_name[] = { - { NULL, 0, POPT_ARG_CALLBACK, popt_common_callback }, - {"netbiosname", 'n', POPT_ARG_STRING, NULL, 'n', "Primary netbios name"}, - { 0 } -}; -struct poptOption popt_common_log_base[] = { - { NULL, 0, POPT_ARG_CALLBACK|POPT_CBFLAG_PRE, popt_common_callback }, - { "log-basename", 'l', POPT_ARG_STRING, NULL, 'l', "Basename for log/debug files"}, - { 0 } + +/**************************************************************************** + * get a password from a a file or file descriptor + * exit on failure + * ****************************************************************************/ +static void get_password_file(struct user_auth_info *a) +{ + int fd = -1; + char *p; + BOOL close_it = False; + pstring spec; + char pass[128]; + + if ((p = getenv("PASSWD_FD")) != NULL) { + pstrcpy(spec, "descriptor "); + pstrcat(spec, p); + sscanf(p, "%d", &fd); + close_it = False; + } else if ((p = getenv("PASSWD_FILE")) != NULL) { + fd = sys_open(p, O_RDONLY, 0); + pstrcpy(spec, p); + if (fd < 0) { + fprintf(stderr, "Error opening PASSWD_FILE %s: %s\n", + spec, strerror(errno)); + exit(1); + } + close_it = True; + } + + for(p = pass, *p = '\0'; /* ensure that pass is null-terminated */ + p && p - pass < sizeof(pass);) { + switch (read(fd, p, 1)) { + case 1: + if (*p != '\n' && *p != '\0') { + *++p = '\0'; /* advance p, and null-terminate pass */ + break; + } + case 0: + if (p - pass) { + *p = '\0'; /* null-terminate it, just in case... */ + p = NULL; /* then force the loop condition to become false */ + break; + } else { + fprintf(stderr, "Error reading password from file %s: %s\n", + spec, "empty password\n"); + exit(1); + } + + default: + fprintf(stderr, "Error reading password from file %s: %s\n", + spec, strerror(errno)); + exit(1); + } + } + pstrcpy(a->password, pass); + if (close_it) + close(fd); +} + +static void get_credentials_file(const char *file, struct user_auth_info *info) +{ + XFILE *auth; + fstring buf; + uint16 len = 0; + char *ptr, *val, *param; + + if ((auth=x_fopen(file, O_RDONLY, 0)) == NULL) + { + /* fail if we can't open the credentials file */ + d_printf("ERROR: Unable to open credentials file!\n"); + exit(-1); + } + + while (!x_feof(auth)) + { + /* get a line from the file */ + if (!x_fgets(buf, sizeof(buf), auth)) + continue; + len = strlen(buf); + + if ((len) && (buf[len-1]=='\n')) + { + buf[len-1] = '\0'; + len--; + } + if (len == 0) + continue; + + /* break up the line into parameter & value. + * will need to eat a little whitespace possibly */ + param = buf; + if (!(ptr = strchr_m (buf, '='))) + continue; + + val = ptr+1; + *ptr = '\0'; + + /* eat leading white space */ + while ((*val!='\0') && ((*val==' ') || (*val=='\t'))) + val++; + + if (strwicmp("password", param) == 0) + { + pstrcpy(info->password, val); + info->got_pass = True; + } + else if (strwicmp("username", param) == 0) + pstrcpy(info->username, val); + else if (strwicmp("domain", param) == 0) + set_global_myworkgroup(val); + memset(buf, 0, sizeof(buf)); + } + x_fclose(auth); +} + +/* Handle command line options: + * -U,--user + * -A,--authentication-file + * -k,--use-kerberos + * -N,--no-pass + */ + + +static void popt_common_credentials_callback(poptContext con, + enum poptCallbackReason reason, + const struct poptOption *opt, + const char *arg, const void *data) +{ + char *p; + + if (reason == POPT_CALLBACK_REASON_PRE) { + cmdline_auth_info.use_kerberos = False; + cmdline_auth_info.got_pass = False; + pstrcpy(cmdline_auth_info.username, "GUEST"); + + if (getenv("LOGNAME"))pstrcpy(cmdline_auth_info.username,getenv("LOGNAME")); + + if (getenv("USER")) { + pstrcpy(cmdline_auth_info.username,getenv("USER")); + + if ((p = strchr_m(cmdline_auth_info.username,'%'))) { + *p = 0; + pstrcpy(cmdline_auth_info.password,p+1); + cmdline_auth_info.got_pass = True; + memset(strchr_m(getenv("USER"),'%')+1,'X',strlen(cmdline_auth_info.password)); + } + } + + if (getenv("PASSWD")) { + pstrcpy(cmdline_auth_info.password,getenv("PASSWD")); + cmdline_auth_info.got_pass = True; + } + + if (getenv("PASSWD_FD") || getenv("PASSWD_FILE")) { + get_password_file(&cmdline_auth_info); + cmdline_auth_info.got_pass = True; + } + + return; + } + + switch(opt->val) { + case 'U': + { + char *lp; + + pstrcpy(cmdline_auth_info.username,arg); + if ((lp=strchr_m(cmdline_auth_info.username,'%'))) { + *lp = 0; + pstrcpy(cmdline_auth_info.password,lp+1); + cmdline_auth_info.got_pass = True; + memset(strchr_m(arg,'%')+1,'X',strlen(cmdline_auth_info.password)); + } + } + break; + + case 'A': + get_credentials_file(arg, &cmdline_auth_info); + break; + + case 'k': +#ifndef HAVE_KRB5 + d_printf("No kerberos support compiled in\n"); + exit(1); +#else + cmdline_auth_info.use_kerberos = True; + cmdline_auth_info.got_pass = True; +#endif + break; + } +} + + + +struct poptOption popt_common_credentials[] = { + { NULL, 0, POPT_ARG_CALLBACK|POPT_CBFLAG_PRE, popt_common_credentials_callback }, + { "user", 'U', POPT_ARG_STRING, NULL, 'U', "Set the network username", "USERNAME" }, + { "no-pass", 'N', POPT_ARG_NONE, &cmdline_auth_info.got_pass, True, "Don't ask for a password" }, + { "kerberos", 'k', POPT_ARG_NONE, &cmdline_auth_info.use_kerberos, True, "Use kerberos (active directory) authentication" }, + { "authentication-file", 'A', POPT_ARG_STRING, NULL, 'A', "Get the credentials from a file", "FILE" }, + POPT_TABLEEND }; -- cgit From 1e07f860a469c6811abaa91911b319acc6a81877 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Wed, 2 Jul 2003 03:04:15 +0000 Subject: Fix poptOption definition for --no-pass and --kerberos options. The 'value' field for an option should be set to an identifier to use in a switch statement or zero if the the arg field is to be updated only. This fixes smbclient -k always prompting for a password which we don't need. (This used to be commit 0744e2dad372904a554019146ff6f6e31ca1b2d2) --- source3/lib/popt_common.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/lib/popt_common.c') diff --git a/source3/lib/popt_common.c b/source3/lib/popt_common.c index 6920ef4d5f..b8e77b2d9e 100644 --- a/source3/lib/popt_common.c +++ b/source3/lib/popt_common.c @@ -335,8 +335,8 @@ static void popt_common_credentials_callback(poptContext con, struct poptOption popt_common_credentials[] = { { NULL, 0, POPT_ARG_CALLBACK|POPT_CBFLAG_PRE, popt_common_credentials_callback }, { "user", 'U', POPT_ARG_STRING, NULL, 'U', "Set the network username", "USERNAME" }, - { "no-pass", 'N', POPT_ARG_NONE, &cmdline_auth_info.got_pass, True, "Don't ask for a password" }, - { "kerberos", 'k', POPT_ARG_NONE, &cmdline_auth_info.use_kerberos, True, "Use kerberos (active directory) authentication" }, + { "no-pass", 'N', POPT_ARG_NONE, &cmdline_auth_info.got_pass, 0, "Don't ask for a password" }, + { "kerberos", 'k', POPT_ARG_NONE, &cmdline_auth_info.use_kerberos, 'k', "Use kerberos (active directory) authentication" }, { "authentication-file", 'A', POPT_ARG_STRING, NULL, 'A', "Get the credentials from a file", "FILE" }, POPT_TABLEEND }; -- cgit From 29ca70cd34d3ba927ea1a9915ebd247f64965bd5 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 30 Jul 2003 23:49:29 +0000 Subject: Add a command line option (-S on|off|required) to enable signing on client connections. Overrides smb.conf parameter if set. Jeremy. (This used to be commit 879309671df6b530e0bff69559422a417da4a307) --- source3/lib/popt_common.c | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) (limited to 'source3/lib/popt_common.c') diff --git a/source3/lib/popt_common.c b/source3/lib/popt_common.c index b8e77b2d9e..af1cbcfe80 100644 --- a/source3/lib/popt_common.c +++ b/source3/lib/popt_common.c @@ -258,19 +258,21 @@ static void get_credentials_file(const char *file, struct user_auth_info *info) * -A,--authentication-file * -k,--use-kerberos * -N,--no-pass + * -S,--signing */ static void popt_common_credentials_callback(poptContext con, - enum poptCallbackReason reason, - const struct poptOption *opt, - const char *arg, const void *data) + enum poptCallbackReason reason, + const struct poptOption *opt, + const char *arg, const void *data) { char *p; if (reason == POPT_CALLBACK_REASON_PRE) { cmdline_auth_info.use_kerberos = False; cmdline_auth_info.got_pass = False; + cmdline_auth_info.signing_state = Undefined; pstrcpy(cmdline_auth_info.username, "GUEST"); if (getenv("LOGNAME"))pstrcpy(cmdline_auth_info.username,getenv("LOGNAME")); @@ -327,6 +329,22 @@ static void popt_common_credentials_callback(poptContext con, cmdline_auth_info.got_pass = True; #endif break; + + case 'S': + { + cmdline_auth_info.signing_state = -1; + if (strequal(arg, "off") || strequal(arg, "no") || strequal(arg, "false")) + cmdline_auth_info.signing_state = False; + else if (strequal(arg, "on") || strequal(arg, "yes") || strequal(arg, "true")) + cmdline_auth_info.signing_state = True; + else if (strequal(arg, "force") || strequal(arg, "required") || strequal(arg, "forced")) + cmdline_auth_info.signing_state = Required; + else { + fprintf(stderr, "Unknown signing option %s\n", arg ); + exit(1); + } + } + break; } } @@ -338,5 +356,6 @@ struct poptOption popt_common_credentials[] = { { "no-pass", 'N', POPT_ARG_NONE, &cmdline_auth_info.got_pass, 0, "Don't ask for a password" }, { "kerberos", 'k', POPT_ARG_NONE, &cmdline_auth_info.use_kerberos, 'k', "Use kerberos (active directory) authentication" }, { "authentication-file", 'A', POPT_ARG_STRING, NULL, 'A', "Get the credentials from a file", "FILE" }, + { "signing", 'S', POPT_ARG_STRING, NULL, 'S', "Set the client signing state", "on|off|required" }, POPT_TABLEEND }; -- cgit From 46e0d25b7f3e570daffe73bad5d883f617ea291e Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Tue, 12 Aug 2003 01:15:23 +0000 Subject: Fix client autonegotiate signing. Jeremy. (This used to be commit a4d2dd1d40f6b1322e69d430023aa89dac86fda3) --- source3/lib/popt_common.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source3/lib/popt_common.c') diff --git a/source3/lib/popt_common.c b/source3/lib/popt_common.c index af1cbcfe80..c120651550 100644 --- a/source3/lib/popt_common.c +++ b/source3/lib/popt_common.c @@ -335,7 +335,8 @@ static void popt_common_credentials_callback(poptContext con, cmdline_auth_info.signing_state = -1; if (strequal(arg, "off") || strequal(arg, "no") || strequal(arg, "false")) cmdline_auth_info.signing_state = False; - else if (strequal(arg, "on") || strequal(arg, "yes") || strequal(arg, "true")) + else if (strequal(arg, "on") || strequal(arg, "yes") || strequal(arg, "true") || + strequal(arg, "auto") ) cmdline_auth_info.signing_state = True; else if (strequal(arg, "force") || strequal(arg, "required") || strequal(arg, "forced")) cmdline_auth_info.signing_state = Required; -- cgit From 172766eea7a374e910ea91c857fcce45996783a2 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Thu, 14 Aug 2003 01:08:00 +0000 Subject: Change Samba to always use extended security for it's guest logins, (ie, NTLMSSP with "" username, NULL password), and add --machine-pass (-P) to all of Samba's clients. When connecting to an Active Directory DC, you must initiate the CIFS level session setup with Kerberos, not a guest login. If you don't, your machine account is demoted to NT4. Andrew Bartlett (This used to be commit 3547cb3def45a90f99f67829a533eac1ccba5e77) --- source3/lib/popt_common.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'source3/lib/popt_common.c') diff --git a/source3/lib/popt_common.c b/source3/lib/popt_common.c index c120651550..95a9a58b34 100644 --- a/source3/lib/popt_common.c +++ b/source3/lib/popt_common.c @@ -119,6 +119,7 @@ struct poptOption popt_common_connection[] = { { "netbiosname", 'n', POPT_ARG_STRING, NULL, 'n', "Primary netbios name", "NETBIOSNAME" }, { "workgroup", 'W', POPT_ARG_STRING, NULL, 'W', "Set the workgroup name", "WORKGROUP" }, { "scope", 'i', POPT_ARG_STRING, NULL, 'i', "Use this Netbios scope", "SCOPE" }, + POPT_TABLEEND }; @@ -259,6 +260,7 @@ static void get_credentials_file(const char *file, struct user_auth_info *info) * -k,--use-kerberos * -N,--no-pass * -S,--signing + * -P --machine-pass */ @@ -346,6 +348,33 @@ static void popt_common_credentials_callback(poptContext con, } } break; + case 'P': + { + char *opt_password = NULL; + /* it is very useful to be able to make ads queries as the + machine account for testing purposes and for domain leave */ + + if (!secrets_init()) { + d_printf("ERROR: Unable to open secrets database\n"); + exit(1); + } + + opt_password = secrets_fetch_machine_password(lp_workgroup(), NULL, NULL); + + if (!opt_password) { + d_printf("ERROR: Unable to fetch machine password\n"); + exit(1); + } + pstr_sprintf(cmdline_auth_info.username, "%s$", + global_myname()); + pstrcpy(cmdline_auth_info.password,opt_password); + SAFE_FREE(opt_password); + + /* machine accounts only work with kerberos */ + cmdline_auth_info.use_kerberos = True; + cmdline_auth_info.got_pass = True; + } + break; } } @@ -358,5 +387,6 @@ struct poptOption popt_common_credentials[] = { { "kerberos", 'k', POPT_ARG_NONE, &cmdline_auth_info.use_kerberos, 'k', "Use kerberos (active directory) authentication" }, { "authentication-file", 'A', POPT_ARG_STRING, NULL, 'A', "Get the credentials from a file", "FILE" }, { "signing", 'S', POPT_ARG_STRING, NULL, 'S', "Set the client signing state", "on|off|required" }, + {"machine-pass", 'P', POPT_ARG_NONE, NULL, 'P', "Use stored machine account password" }, POPT_TABLEEND }; -- cgit From 8bfe26b62db2e671b143d93a5428f8fb64a9df05 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Wed, 20 Aug 2003 17:13:38 +0000 Subject: metze's autogenerate patch for version.h (This used to be commit ae452e51b02672a56adf18aa7a7e365eeaba9272) --- source3/lib/popt_common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/popt_common.c') diff --git a/source3/lib/popt_common.c b/source3/lib/popt_common.c index 95a9a58b34..9a5a112022 100644 --- a/source3/lib/popt_common.c +++ b/source3/lib/popt_common.c @@ -69,7 +69,7 @@ static void popt_common_callback(poptContext con, break; case 'V': - printf( "Version %s\n", VERSION ); + printf( "Version %s\n", SAMBA_VERSION_STRING); exit(0); break; -- cgit From bfa1b2a8bdd785af576c8706e8f27e9448ef94b5 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 26 Mar 2004 15:40:06 +0000 Subject: source code fix for bug 1095 -- honor the '-l' option (This used to be commit ab48af6993b427f525c36aa0ffd57c612c100561) --- source3/lib/popt_common.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source3/lib/popt_common.c') diff --git a/source3/lib/popt_common.c b/source3/lib/popt_common.c index 9a5a112022..6c35213d43 100644 --- a/source3/lib/popt_common.c +++ b/source3/lib/popt_common.c @@ -35,6 +35,7 @@ extern pstring user_socket_options; extern BOOL AllowDebugChange; +extern BOOL override_logfile; struct user_auth_info cmdline_auth_info; @@ -95,6 +96,7 @@ static void popt_common_callback(poptContext con, if (arg) { pstr_sprintf(logfile, "%s/log.%s", arg, pname); lp_set_logfile(logfile); + override_logfile = True; } break; -- cgit From 90a6873b0570f2691ba8d8fd11154c856bdd4415 Mon Sep 17 00:00:00 2001 From: James Peach Date: Wed, 24 May 2006 04:02:14 +0000 Subject: r15848: Introduce commandline options to set the remainder of the parameters in dynconfig.c. This is mainly useful for test harness scripts, hence the lack of short options. (This used to be commit bf3b71c84595608d71e0f15a6158adacb295518e) --- source3/lib/popt_common.c | 154 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 143 insertions(+), 11 deletions(-) (limited to 'source3/lib/popt_common.c') diff --git a/source3/lib/popt_common.c b/source3/lib/popt_common.c index 6c35213d43..f842ae8011 100644 --- a/source3/lib/popt_common.c +++ b/source3/lib/popt_common.c @@ -4,6 +4,7 @@ Copyright (C) Tim Potter 2001,2002 Copyright (C) Jelmer Vernooij 2002,2003 + Copyright (C) James Peach 2006 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 @@ -39,11 +40,9 @@ extern BOOL override_logfile; struct user_auth_info cmdline_auth_info; -static void popt_common_callback(poptContext con, - enum poptCallbackReason reason, - const struct poptOption *opt, - const char *arg, const void *data) +static void set_logfile(poptContext con, const char * arg) { + pstring logfile; const char *pname; @@ -55,9 +54,19 @@ static void popt_common_callback(poptContext con, else pname++; + pstr_sprintf(logfile, "%s/log.%s", arg, pname); + lp_set_logfile(logfile); + override_logfile = True; +} + +static void popt_common_callback(poptContext con, + enum poptCallbackReason reason, + const struct poptOption *opt, + const char *arg, const void *data) +{ + if (reason == POPT_CALLBACK_REASON_PRE) { - pstr_sprintf(logfile, "%s/log.%s", dyn_LOGFILEBASE, pname); - lp_set_logfile(logfile); + set_logfile(con, dyn_LOGFILEBASE); return; } @@ -94,9 +103,8 @@ static void popt_common_callback(poptContext con, case 'l': if (arg) { - pstr_sprintf(logfile, "%s/log.%s", arg, pname); - lp_set_logfile(logfile); - override_logfile = True; + set_logfile(con, arg); + pstr_sprintf(dyn_LOGFILEBASE, "%s", arg); } break; @@ -128,8 +136,8 @@ struct poptOption popt_common_connection[] = { struct poptOption popt_common_samba[] = { { NULL, 0, POPT_ARG_CALLBACK|POPT_CBFLAG_PRE, popt_common_callback }, { "debuglevel", 'd', POPT_ARG_STRING, NULL, 'd', "Set debug level", "DEBUGLEVEL" }, - { "configfile", 's', POPT_ARG_STRING, NULL, 's', "Use alternative configuration file", "CONFIGFILE" }, - { "log-basename", 'l', POPT_ARG_STRING, NULL, 'l', "Basename for log/debug files", "LOGFILEBASE" }, + { "configfile", 's', POPT_ARG_STRING, NULL, 's', "Use alternate configuration file", "CONFIGFILE" }, + { "log-basename", 'l', POPT_ARG_STRING, NULL, 'l', "Base name for log files", "LOGFILEBASE" }, { "version", 'V', POPT_ARG_NONE, NULL, 'V', "Print version" }, POPT_TABLEEND }; @@ -141,6 +149,130 @@ struct poptOption popt_common_version[] = { }; +/* Handle command line options: + * --sbindir + * --bindir + * --swatdir + * --lmhostsfile + * --libdir + * --shlibext + * --lockdir + * --piddir + * --smb-passwd-file + * --private-dir + */ + +enum dyn_item{ + DYN_SBINDIR = 1, + DYN_BINDIR, + DYN_SWATDIR, + DYN_LMHOSTSFILE, + DYN_LIBDIR, + DYN_SHLIBEXT, + DYN_LOCKDIR, + DYN_PIDDIR, + DYN_SMB_PASSWD_FILE, + DYN_PRIVATE_DIR, +}; + + +static void popt_dynconfig_callback(poptContext con, + enum poptCallbackReason reason, + const struct poptOption *opt, + const char *arg, const void *data) +{ + + switch (opt->val) { + case DYN_SBINDIR: + if (arg) { + dyn_SBINDIR = SMB_STRDUP(arg); + } + break; + + case DYN_BINDIR: + if (arg) { + dyn_BINDIR = SMB_STRDUP(arg); + } + break; + + case DYN_SWATDIR: + if (arg) { + dyn_SWATDIR = SMB_STRDUP(arg); + } + break; + + case DYN_LMHOSTSFILE: + if (arg) { + pstrcpy(dyn_LMHOSTSFILE, arg); + } + break; + + case DYN_LIBDIR: + if (arg) { + pstrcpy(dyn_LIBDIR, arg); + } + break; + + case DYN_SHLIBEXT: + if (arg) { + fstrcpy(dyn_SHLIBEXT, arg); + } + break; + + case DYN_LOCKDIR: + if (arg) { + pstrcpy(dyn_LOCKDIR, arg); + } + break; + + case DYN_PIDDIR: + if (arg) { + pstrcpy(dyn_PIDDIR, arg); + } + break; + + case DYN_SMB_PASSWD_FILE: + if (arg) { + pstrcpy(dyn_SMB_PASSWD_FILE, arg); + } + break; + + case DYN_PRIVATE_DIR: + if (arg) { + pstrcpy(dyn_PRIVATE_DIR, arg); + } + break; + + } +} + +const struct poptOption popt_common_dynconfig[] = { + + { NULL, '\0', POPT_ARG_CALLBACK, popt_dynconfig_callback }, + + { "sbindir", '\0' , POPT_ARG_STRING, NULL, DYN_SBINDIR, + "Path to sbin directory", "SBINDIR" }, + { "bindir", '\0' , POPT_ARG_STRING, NULL, DYN_BINDIR, + "Path to bin directory", "BINDIR" }, + { "swatdir", '\0' , POPT_ARG_STRING, NULL, DYN_SWATDIR, + "Path to SWAT installation directory", "SWATDIR" }, + { "lmhostsfile", '\0' , POPT_ARG_STRING, NULL, DYN_LMHOSTSFILE, + "Path to lmhosts file", "LMHOSTSFILE" }, + { "libdir", '\0' , POPT_ARG_STRING, NULL, DYN_LIBDIR, + "Path to shared library directory", "LIBDIR" }, + { "shlibext", '\0' , POPT_ARG_STRING, NULL, DYN_SHLIBEXT, + "Shared library extension", "SHLIBEXT" }, + { "lockdir", '\0' , POPT_ARG_STRING, NULL, DYN_LOCKDIR, + "Path to lock file directory", "LOCKDIR" }, + { "piddir", '\0' , POPT_ARG_STRING, NULL, DYN_PIDDIR, + "Path to PID file directory", "PIDDIR" }, + { "smb-passwd-file", '\0' , POPT_ARG_STRING, NULL, DYN_SMB_PASSWD_FILE, + "Path to smbpasswd file", "SMB_PASSWD_FILE" }, + { "private-dir", '\0' , POPT_ARG_STRING, NULL, DYN_PRIVATE_DIR, + "Path to private data directory", "PRIVATE_DIR" }, + + POPT_TABLEEND +}; /**************************************************************************** * get a password from a a file or file descriptor -- cgit From fbd296f2f65d073af6f1c89a51dadabd172a5984 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Mon, 5 Jun 2006 13:00:24 +0000 Subject: r16046: Hmmm. I don't fully understand popt, but this is necessary for smbclient to show a prompt again :-) James, could you check that this is ok? I think this was part of your Revision 15848. Thanks, Volker (This used to be commit 91534146b4718206f0e2a7f456154a0497277dfd) --- source3/lib/popt_common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/popt_common.c') diff --git a/source3/lib/popt_common.c b/source3/lib/popt_common.c index f842ae8011..d29e171be0 100644 --- a/source3/lib/popt_common.c +++ b/source3/lib/popt_common.c @@ -56,7 +56,6 @@ static void set_logfile(poptContext con, const char * arg) pstr_sprintf(logfile, "%s/log.%s", arg, pname); lp_set_logfile(logfile); - override_logfile = True; } static void popt_common_callback(poptContext con, @@ -104,6 +103,7 @@ static void popt_common_callback(poptContext con, case 'l': if (arg) { set_logfile(con, arg); + override_logfile = True; pstr_sprintf(dyn_LOGFILEBASE, "%s", arg); } break; -- cgit From fbdcf2663b56007a438ac4f0d8d82436b1bfe688 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 11 Jul 2006 18:01:26 +0000 Subject: r16945: Sync trunk -> 3.0 for 3.0.24 code. Still need to do the upper layer directories but this is what everyone is waiting for.... Jeremy. (This used to be commit 9dafb7f48ca3e7af956b0a7d1720c2546fc4cfb8) --- source3/lib/popt_common.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'source3/lib/popt_common.c') diff --git a/source3/lib/popt_common.c b/source3/lib/popt_common.c index d29e171be0..0c0ed86dd1 100644 --- a/source3/lib/popt_common.c +++ b/source3/lib/popt_common.c @@ -123,7 +123,7 @@ static void popt_common_callback(poptContext con, } struct poptOption popt_common_connection[] = { - { NULL, 0, POPT_ARG_CALLBACK, popt_common_callback }, + { NULL, 0, POPT_ARG_CALLBACK, (void *)popt_common_callback }, { "socket-options", 'O', POPT_ARG_STRING, NULL, 'O', "socket options to use", "SOCKETOPTIONS" }, { "netbiosname", 'n', POPT_ARG_STRING, NULL, 'n', "Primary netbios name", "NETBIOSNAME" }, @@ -134,7 +134,7 @@ struct poptOption popt_common_connection[] = { }; struct poptOption popt_common_samba[] = { - { NULL, 0, POPT_ARG_CALLBACK|POPT_CBFLAG_PRE, popt_common_callback }, + { NULL, 0, POPT_ARG_CALLBACK|POPT_CBFLAG_PRE, (void *)popt_common_callback }, { "debuglevel", 'd', POPT_ARG_STRING, NULL, 'd', "Set debug level", "DEBUGLEVEL" }, { "configfile", 's', POPT_ARG_STRING, NULL, 's', "Use alternate configuration file", "CONFIGFILE" }, { "log-basename", 'l', POPT_ARG_STRING, NULL, 'l', "Base name for log files", "LOGFILEBASE" }, @@ -143,7 +143,7 @@ struct poptOption popt_common_samba[] = { }; struct poptOption popt_common_version[] = { - { NULL, 0, POPT_ARG_CALLBACK, popt_common_callback }, + { NULL, 0, POPT_ARG_CALLBACK, (void *)popt_common_callback }, { "version", 'V', POPT_ARG_NONE, NULL, 'V', "Print version" }, POPT_TABLEEND }; @@ -248,7 +248,7 @@ static void popt_dynconfig_callback(poptContext con, const struct poptOption popt_common_dynconfig[] = { - { NULL, '\0', POPT_ARG_CALLBACK, popt_dynconfig_callback }, + { NULL, '\0', POPT_ARG_CALLBACK, (void *)popt_dynconfig_callback }, { "sbindir", '\0' , POPT_ARG_STRING, NULL, DYN_SBINDIR, "Path to sbin directory", "SBINDIR" }, @@ -515,7 +515,7 @@ static void popt_common_credentials_callback(poptContext con, struct poptOption popt_common_credentials[] = { - { NULL, 0, POPT_ARG_CALLBACK|POPT_CBFLAG_PRE, popt_common_credentials_callback }, + { NULL, 0, POPT_ARG_CALLBACK|POPT_CBFLAG_PRE, (void *)popt_common_credentials_callback }, { "user", 'U', POPT_ARG_STRING, NULL, 'U', "Set the network username", "USERNAME" }, { "no-pass", 'N', POPT_ARG_NONE, &cmdline_auth_info.got_pass, 0, "Don't ask for a password" }, { "kerberos", 'k', POPT_ARG_NONE, &cmdline_auth_info.use_kerberos, 'k', "Use kerberos (active directory) authentication" }, -- cgit From d824b98f80ba186030cbb70b3a1e5daf80469ecd Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 9 Jul 2007 19:25:36 +0000 Subject: r23779: Change from v2 or later to v3 or later. Jeremy. (This used to be commit 407e6e695b8366369b7c76af1ff76869b45347b3) --- source3/lib/popt_common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/popt_common.c') diff --git a/source3/lib/popt_common.c b/source3/lib/popt_common.c index 0c0ed86dd1..39a55ad71c 100644 --- a/source3/lib/popt_common.c +++ b/source3/lib/popt_common.c @@ -8,7 +8,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, -- cgit From 5e54558c6dea67b56bbfaba5698f3a434d3dffb6 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 00:52:41 +0000 Subject: r23784: use the GPLv3 boilerplate as recommended by the FSF and the license text (This used to be commit b0132e94fc5fef936aa766fb99a306b3628e9f07) --- source3/lib/popt_common.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/lib/popt_common.c') diff --git a/source3/lib/popt_common.c b/source3/lib/popt_common.c index 39a55ad71c..efffd3c11b 100644 --- a/source3/lib/popt_common.c +++ b/source3/lib/popt_common.c @@ -17,8 +17,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 faab8dba02d364dccf341e0f6756b1bf625d3c5b Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Wed, 22 Aug 2007 11:55:48 +0000 Subject: r24618: move printing out the version string and exit() into the popt _POST processing. Now 'smbd -V --bla' complains about an unknown option metze (This used to be commit c115de4beac887442a73b4a85367d7b5fded68e6) --- source3/lib/popt_common.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'source3/lib/popt_common.c') diff --git a/source3/lib/popt_common.c b/source3/lib/popt_common.c index efffd3c11b..3be25b4363 100644 --- a/source3/lib/popt_common.c +++ b/source3/lib/popt_common.c @@ -57,6 +57,8 @@ static void set_logfile(poptContext con, const char * arg) lp_set_logfile(logfile); } +static BOOL PrintSambaVersionString; + static void popt_common_callback(poptContext con, enum poptCallbackReason reason, const struct poptOption *opt, @@ -68,6 +70,14 @@ static void popt_common_callback(poptContext con, return; } + if (reason == POPT_CALLBACK_REASON_POST) { + if (!PrintSambaVersionString) return; + + printf( "Version %s\n", SAMBA_VERSION_STRING); + exit(0); + return; + } + switch(opt->val) { case 'd': if (arg) { @@ -77,8 +87,7 @@ static void popt_common_callback(poptContext con, break; case 'V': - printf( "Version %s\n", SAMBA_VERSION_STRING); - exit(0); + PrintSambaVersionString = True; break; case 'O': @@ -133,7 +142,7 @@ struct poptOption popt_common_connection[] = { }; struct poptOption popt_common_samba[] = { - { NULL, 0, POPT_ARG_CALLBACK|POPT_CBFLAG_PRE, (void *)popt_common_callback }, + { NULL, 0, POPT_ARG_CALLBACK|POPT_CBFLAG_PRE|POPT_CBFLAG_POST, (void *)popt_common_callback }, { "debuglevel", 'd', POPT_ARG_STRING, NULL, 'd', "Set debug level", "DEBUGLEVEL" }, { "configfile", 's', POPT_ARG_STRING, NULL, 's', "Use alternate configuration file", "CONFIGFILE" }, { "log-basename", 'l', POPT_ARG_STRING, NULL, 'l', "Base name for log files", "LOGFILEBASE" }, -- cgit From 30191d1a5704ad2b158386b511558972d539ce47 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 18 Oct 2007 17:40:25 -0700 Subject: RIP BOOL. Convert BOOL -> bool. I found a few interesting bugs in various places whilst doing this (places that assumed BOOL == int). I also need to fix the Samba4 pidl generation (next checkin). Jeremy. (This used to be commit f35a266b3cbb3e5fa6a86be60f34fe340a3ca71f) --- source3/lib/popt_common.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source3/lib/popt_common.c') diff --git a/source3/lib/popt_common.c b/source3/lib/popt_common.c index 3be25b4363..ec05762cdf 100644 --- a/source3/lib/popt_common.c +++ b/source3/lib/popt_common.c @@ -34,8 +34,8 @@ */ extern pstring user_socket_options; -extern BOOL AllowDebugChange; -extern BOOL override_logfile; +extern bool AllowDebugChange; +extern bool override_logfile; struct user_auth_info cmdline_auth_info; @@ -57,7 +57,7 @@ static void set_logfile(poptContext con, const char * arg) lp_set_logfile(logfile); } -static BOOL PrintSambaVersionString; +static bool PrintSambaVersionString; static void popt_common_callback(poptContext con, enum poptCallbackReason reason, @@ -290,7 +290,7 @@ static void get_password_file(struct user_auth_info *a) { int fd = -1; char *p; - BOOL close_it = False; + bool close_it = False; pstring spec; char pass[128]; -- cgit From e63bcdd720d801df278ef84063c46144df087793 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Thu, 1 Nov 2007 18:13:00 +0100 Subject: Remove the silly "user_socket_options" global variable This is better done with a 'lp_do_parameter(-1, "socket options", ..); (This used to be commit 814bed029efa391e664ac432d0d68dfeab26381f) --- source3/lib/popt_common.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/lib/popt_common.c') diff --git a/source3/lib/popt_common.c b/source3/lib/popt_common.c index ec05762cdf..7cc066d667 100644 --- a/source3/lib/popt_common.c +++ b/source3/lib/popt_common.c @@ -33,7 +33,6 @@ * -i,--scope */ -extern pstring user_socket_options; extern bool AllowDebugChange; extern bool override_logfile; @@ -92,7 +91,7 @@ static void popt_common_callback(poptContext con, case 'O': if (arg) { - pstrcpy(user_socket_options,arg); + lp_do_parameter(-1, "socket options", arg); } break; -- cgit From 68be9a820059ee96dd26c527efd7c14e679d3f2c Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 15 Nov 2007 14:19:52 -0800 Subject: More pstring removal. This one was tricky. I had to add one horror (pstring_clean_name()) which will have to remain until I've removed all pstrings from the client code. Jeremy. (This used to be commit 1ea3ac80146b83c2522b69e7747c823366a2b47d) --- source3/lib/popt_common.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'source3/lib/popt_common.c') diff --git a/source3/lib/popt_common.c b/source3/lib/popt_common.c index 7cc066d667..dbb66b0ba5 100644 --- a/source3/lib/popt_common.c +++ b/source3/lib/popt_common.c @@ -41,19 +41,22 @@ struct user_auth_info cmdline_auth_info; static void set_logfile(poptContext con, const char * arg) { - pstring logfile; + char *logfile = NULL; const char *pname; - + /* Find out basename of current program */ pname = strrchr_m(poptGetInvocationName(con),'/'); if (!pname) pname = poptGetInvocationName(con); - else + else pname++; - pstr_sprintf(logfile, "%s/log.%s", arg, pname); + if (asprintf(&logfile, "%s/log.%s", arg, pname) < 0) { + return; + } lp_set_logfile(logfile); + SAFE_FREE(logfile); } static bool PrintSambaVersionString; @@ -285,22 +288,24 @@ const struct poptOption popt_common_dynconfig[] = { * get a password from a a file or file descriptor * exit on failure * ****************************************************************************/ + static void get_password_file(struct user_auth_info *a) { int fd = -1; char *p; bool close_it = False; - pstring spec; + char *spec = NULL; char pass[128]; if ((p = getenv("PASSWD_FD")) != NULL) { - pstrcpy(spec, "descriptor "); - pstrcat(spec, p); + if (asprintf(&spec, "descriptor %s", p) < 0) { + return; + } sscanf(p, "%d", &fd); - close_it = False; + close_it = false; } else if ((p = getenv("PASSWD_FILE")) != NULL) { fd = sys_open(p, O_RDONLY, 0); - pstrcpy(spec, p); + spec = SMB_STRDUP(p); if (fd < 0) { fprintf(stderr, "Error opening PASSWD_FILE %s: %s\n", spec, strerror(errno)); @@ -325,15 +330,18 @@ static void get_password_file(struct user_auth_info *a) } else { fprintf(stderr, "Error reading password from file %s: %s\n", spec, "empty password\n"); + SAFE_FREE(spec); exit(1); } default: fprintf(stderr, "Error reading password from file %s: %s\n", spec, strerror(errno)); + SAFE_FREE(spec); exit(1); } } + SAFE_FREE(spec); pstrcpy(a->password, pass); if (close_it) close(fd); -- cgit From 1b92ea5559bfa00016103508feac9a06ea4b66ae Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 6 Dec 2007 17:16:33 -0800 Subject: Remove pstrings from client/client.c by doing a large rewrite. Mostly compiles.... Jeremy. (This used to be commit c87f3eba9aa52f4ab25d77e2167262bf5c43b1a6) --- source3/lib/popt_common.c | 162 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 114 insertions(+), 48 deletions(-) (limited to 'source3/lib/popt_common.c') diff --git a/source3/lib/popt_common.c b/source3/lib/popt_common.c index dbb66b0ba5..e29929aac6 100644 --- a/source3/lib/popt_common.c +++ b/source3/lib/popt_common.c @@ -36,7 +36,57 @@ extern bool AllowDebugChange; extern bool override_logfile; -struct user_auth_info cmdline_auth_info; +static struct user_auth_info cmdline_auth_info; + +const char *get_cmdline_auth_info_username(void) +{ + if (!cmdline_auth_info.username) { + return ""; + } + return cmdline_auth_info.username; +} + +void set_cmdline_auth_info_username(const char *username) +{ + SAFE_FREE(cmdline_auth_info.username); + cmdline_auth_info.username = SMB_STRDUP(username); + if (!cmdline_auth_info.username) { + exit(ENOMEM); + } +} + +const char *get_cmdline_auth_info_password(void) +{ + if (!cmdline_auth_info.password) { + return ""; + } + return cmdline_auth_info.password; +} + +void set_cmdline_auth_info_password(const char *password) +{ + SAFE_FREE(cmdline_auth_info.password); + cmdline_auth_info.password = SMB_STRDUP(password); + if (!cmdline_auth_info.password) { + exit(ENOMEM); + } + cmdline_auth_info.got_pass = true; +} + +int get_cmdline_auth_info_signing_state(void) +{ + return cmdline_auth_info.signing_state; +} + +bool get_cmdline_auth_info_use_kerberos(void) +{ + return cmdline_auth_info.use_kerberos; +} + +bool get_cmdline_auth_info_got_pass(void) +{ + return cmdline_auth_info.got_pass; +} static void set_logfile(poptContext con, const char * arg) { @@ -100,7 +150,7 @@ static void popt_common_callback(poptContext con, case 's': if (arg) { - pstrcpy(dyn_CONFIGFILE, arg); + strlcpy(dyn_CONFIGFILE, arg,sizeof(dyn_CONFIGFILE)); } break; @@ -213,13 +263,13 @@ static void popt_dynconfig_callback(poptContext con, case DYN_LMHOSTSFILE: if (arg) { - pstrcpy(dyn_LMHOSTSFILE, arg); + strlcpy(dyn_LMHOSTSFILE, arg,sizeof(dyn_LMHOSTSFILE)); } break; case DYN_LIBDIR: if (arg) { - pstrcpy(dyn_LIBDIR, arg); + strlcpy(dyn_LIBDIR, arg,sizeof(dyn_LIBDIR)); } break; @@ -231,25 +281,25 @@ static void popt_dynconfig_callback(poptContext con, case DYN_LOCKDIR: if (arg) { - pstrcpy(dyn_LOCKDIR, arg); + strlcpy(dyn_LOCKDIR, arg,sizeof(dyn_LOCKDIR)); } break; case DYN_PIDDIR: if (arg) { - pstrcpy(dyn_PIDDIR, arg); + strlcpy(dyn_PIDDIR, arg,sizeof(dyn_PIDDIR)); } break; case DYN_SMB_PASSWD_FILE: if (arg) { - pstrcpy(dyn_SMB_PASSWD_FILE, arg); + strlcpy(dyn_SMB_PASSWD_FILE, arg,sizeof(dyn_SMB_PASSWD_FILE)); } break; case DYN_PRIVATE_DIR: if (arg) { - pstrcpy(dyn_PRIVATE_DIR, arg); + strlcpy(dyn_PRIVATE_DIR, arg, sizeof(dyn_PRIVATE_DIR)); } break; @@ -289,7 +339,7 @@ const struct poptOption popt_common_dynconfig[] = { * exit on failure * ****************************************************************************/ -static void get_password_file(struct user_auth_info *a) +static void get_password_file(void) { int fd = -1; char *p; @@ -342,12 +392,14 @@ static void get_password_file(struct user_auth_info *a) } } SAFE_FREE(spec); - pstrcpy(a->password, pass); - if (close_it) + + set_cmdline_auth_info_password(pass); + if (close_it) { close(fd); + } } -static void get_credentials_file(const char *file, struct user_auth_info *info) +static void get_credentials_file(const char *file, struct user_auth_info *info) { XFILE *auth; fstring buf; @@ -389,15 +441,22 @@ static void get_credentials_file(const char *file, struct user_auth_info *info) while ((*val!='\0') && ((*val==' ') || (*val=='\t'))) val++; - if (strwicmp("password", param) == 0) - { - pstrcpy(info->password, val); + if (strwicmp("password", param) == 0) { + SAFE_FREE(info->password); + info->password = SMB_STRDUP(val); + if (!info->password) { + exit(ENOMEM); + } info->got_pass = True; - } - else if (strwicmp("username", param) == 0) - pstrcpy(info->username, val); - else if (strwicmp("domain", param) == 0) + } else if (strwicmp("username", param) == 0) { + SAFE_FREE(info->username); + info->username = SMB_STRDUP(val); + if (!info->username) { + exit(ENOMEM); + } + } else if (strwicmp("domain", param) == 0) { set_global_myworkgroup(val); + } memset(buf, 0, sizeof(buf)); } x_fclose(auth); @@ -413,7 +472,7 @@ static void get_credentials_file(const char *file, struct user_auth_info *info) */ -static void popt_common_credentials_callback(poptContext con, +static void popt_common_credentials_callback(poptContext con, enum poptCallbackReason reason, const struct poptOption *opt, const char *arg, const void *data) @@ -424,24 +483,29 @@ static void popt_common_credentials_callback(poptContext con, cmdline_auth_info.use_kerberos = False; cmdline_auth_info.got_pass = False; cmdline_auth_info.signing_state = Undefined; - pstrcpy(cmdline_auth_info.username, "GUEST"); + set_cmdline_auth_info_username("GUEST"); - if (getenv("LOGNAME"))pstrcpy(cmdline_auth_info.username,getenv("LOGNAME")); + if (getenv("LOGNAME")) { + set_cmdline_auth_info_username(getenv("LOGNAME")); + } if (getenv("USER")) { - pstrcpy(cmdline_auth_info.username,getenv("USER")); + char *puser = SMB_STRDUP(getenv("USER")); + if (!puser) { + exit(ENOMEM); + } + set_cmdline_auth_info_username(puser); - if ((p = strchr_m(cmdline_auth_info.username,'%'))) { + if ((p = strchr_m(puser,'%'))) { *p = 0; - pstrcpy(cmdline_auth_info.password,p+1); - cmdline_auth_info.got_pass = True; + set_cmdline_auth_info_password(p+1); memset(strchr_m(getenv("USER"),'%')+1,'X',strlen(cmdline_auth_info.password)); } + SAFE_FREE(puser); } if (getenv("PASSWD")) { - pstrcpy(cmdline_auth_info.password,getenv("PASSWD")); - cmdline_auth_info.got_pass = True; + set_cmdline_auth_info_password(getenv("PASSWD")); } if (getenv("PASSWD_FD") || getenv("PASSWD_FILE")) { @@ -468,7 +532,7 @@ static void popt_common_credentials_callback(poptContext con, break; case 'A': - get_credentials_file(arg, &cmdline_auth_info); + get_credentials_file(arg); break; case 'k': @@ -476,22 +540,22 @@ static void popt_common_credentials_callback(poptContext con, d_printf("No kerberos support compiled in\n"); exit(1); #else - cmdline_auth_info.use_kerberos = True; - cmdline_auth_info.got_pass = True; + cmdline_auth_info.use_kerberos = true; + cmdline_auth_info.got_pass = true; #endif break; case 'S': { cmdline_auth_info.signing_state = -1; - if (strequal(arg, "off") || strequal(arg, "no") || strequal(arg, "false")) - cmdline_auth_info.signing_state = False; - else if (strequal(arg, "on") || strequal(arg, "yes") || strequal(arg, "true") || - strequal(arg, "auto") ) - cmdline_auth_info.signing_state = True; - else if (strequal(arg, "force") || strequal(arg, "required") || strequal(arg, "forced")) + if (strequal(arg, "off") || strequal(arg, "no") || strequal(arg, "false")) { + cmdline_auth_info.signing_state = false; + } else if (strequal(arg, "on") || strequal(arg, "yes") || strequal(arg, "true") || + strequal(arg, "auto")) { + cmdline_auth_info.signing_state = true; + } else if (strequal(arg, "force") || strequal(arg, "required") || strequal(arg, "forced")) { cmdline_auth_info.signing_state = Required; - else { + } else { fprintf(stderr, "Unknown signing option %s\n", arg ); exit(1); } @@ -500,35 +564,37 @@ static void popt_common_credentials_callback(poptContext con, case 'P': { char *opt_password = NULL; + char *pwd = NULL; + /* it is very useful to be able to make ads queries as the machine account for testing purposes and for domain leave */ - + if (!secrets_init()) { d_printf("ERROR: Unable to open secrets database\n"); exit(1); } - + opt_password = secrets_fetch_machine_password(lp_workgroup(), NULL, NULL); - + if (!opt_password) { d_printf("ERROR: Unable to fetch machine password\n"); exit(1); } - pstr_sprintf(cmdline_auth_info.username, "%s$", - global_myname()); - pstrcpy(cmdline_auth_info.password,opt_password); + if (asprintf(&pwd, "%s$", global_myname()) < 0) { + exit(ENOMEM); + } + set_cmdline_auth_info_username(pwd); + set_cmdline_auth_info_password(opt_password); + SAFE_FREE(pwd); SAFE_FREE(opt_password); /* machine accounts only work with kerberos */ - cmdline_auth_info.use_kerberos = True; - cmdline_auth_info.got_pass = True; + cmdline_auth_info.use_kerberos = true; } break; } } - - struct poptOption popt_common_credentials[] = { { NULL, 0, POPT_ARG_CALLBACK|POPT_CBFLAG_PRE, (void *)popt_common_credentials_callback }, { "user", 'U', POPT_ARG_STRING, NULL, 'U', "Set the network username", "USERNAME" }, -- cgit From c6f03521555e9634f120e1b21ad8cdeb36354d41 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 6 Dec 2007 17:22:57 -0800 Subject: Make cmdline_auth_info private to lib/popt_common.c. Provide accessor functions. Jeremy. (This used to be commit 420195dd3e8b1b6771ab8be8bc974edaafc0cf8f) --- source3/lib/popt_common.c | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) (limited to 'source3/lib/popt_common.c') diff --git a/source3/lib/popt_common.c b/source3/lib/popt_common.c index e29929aac6..d454a798ac 100644 --- a/source3/lib/popt_common.c +++ b/source3/lib/popt_common.c @@ -399,7 +399,7 @@ static void get_password_file(void) } } -static void get_credentials_file(const char *file, struct user_auth_info *info) +static void get_credentials_file(const char *file) { XFILE *auth; fstring buf; @@ -442,18 +442,9 @@ static void get_credentials_file(const char *file, struct user_auth_info *info) val++; if (strwicmp("password", param) == 0) { - SAFE_FREE(info->password); - info->password = SMB_STRDUP(val); - if (!info->password) { - exit(ENOMEM); - } - info->got_pass = True; + set_cmdline_auth_info_password(val); } else if (strwicmp("username", param) == 0) { - SAFE_FREE(info->username); - info->username = SMB_STRDUP(val); - if (!info->username) { - exit(ENOMEM); - } + set_cmdline_auth_info_username(val); } else if (strwicmp("domain", param) == 0) { set_global_myworkgroup(val); } @@ -509,8 +500,7 @@ static void popt_common_credentials_callback(poptContext con, } if (getenv("PASSWD_FD") || getenv("PASSWD_FILE")) { - get_password_file(&cmdline_auth_info); - cmdline_auth_info.got_pass = True; + get_password_file(); } return; -- cgit From 9fdf2d05867e5d6abd9099996b9e6c071bdbd0e7 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 6 Dec 2007 18:49:39 -0800 Subject: Get closer to building with smbmount. Move parameter line changes into lib/util.c Jeremy. (This used to be commit 6ac5d81655927ba8eabea35adaae5adfcbb821c9) --- source3/lib/popt_common.c | 102 +++++++++++----------------------------------- 1 file changed, 23 insertions(+), 79 deletions(-) (limited to 'source3/lib/popt_common.c') diff --git a/source3/lib/popt_common.c b/source3/lib/popt_common.c index d454a798ac..bd8410a958 100644 --- a/source3/lib/popt_common.c +++ b/source3/lib/popt_common.c @@ -36,58 +36,6 @@ extern bool AllowDebugChange; extern bool override_logfile; -static struct user_auth_info cmdline_auth_info; - -const char *get_cmdline_auth_info_username(void) -{ - if (!cmdline_auth_info.username) { - return ""; - } - return cmdline_auth_info.username; -} - -void set_cmdline_auth_info_username(const char *username) -{ - SAFE_FREE(cmdline_auth_info.username); - cmdline_auth_info.username = SMB_STRDUP(username); - if (!cmdline_auth_info.username) { - exit(ENOMEM); - } -} - -const char *get_cmdline_auth_info_password(void) -{ - if (!cmdline_auth_info.password) { - return ""; - } - return cmdline_auth_info.password; -} - -void set_cmdline_auth_info_password(const char *password) -{ - SAFE_FREE(cmdline_auth_info.password); - cmdline_auth_info.password = SMB_STRDUP(password); - if (!cmdline_auth_info.password) { - exit(ENOMEM); - } - cmdline_auth_info.got_pass = true; -} - -int get_cmdline_auth_info_signing_state(void) -{ - return cmdline_auth_info.signing_state; -} - -bool get_cmdline_auth_info_use_kerberos(void) -{ - return cmdline_auth_info.use_kerberos; -} - -bool get_cmdline_auth_info_got_pass(void) -{ - return cmdline_auth_info.got_pass; -} - static void set_logfile(poptContext con, const char * arg) { @@ -471,9 +419,6 @@ static void popt_common_credentials_callback(poptContext con, char *p; if (reason == POPT_CALLBACK_REASON_PRE) { - cmdline_auth_info.use_kerberos = False; - cmdline_auth_info.got_pass = False; - cmdline_auth_info.signing_state = Undefined; set_cmdline_auth_info_username("GUEST"); if (getenv("LOGNAME")) { @@ -488,9 +433,11 @@ static void popt_common_credentials_callback(poptContext con, set_cmdline_auth_info_username(puser); if ((p = strchr_m(puser,'%'))) { + size_t len; *p = 0; + len = strlen(p+1); set_cmdline_auth_info_password(p+1); - memset(strchr_m(getenv("USER"),'%')+1,'X',strlen(cmdline_auth_info.password)); + memset(strchr_m(getenv("USER"),'%')+1,'X',len); } SAFE_FREE(puser); } @@ -510,14 +457,19 @@ static void popt_common_credentials_callback(poptContext con, case 'U': { char *lp; + char *puser = SMB_STRDUP(arg); - pstrcpy(cmdline_auth_info.username,arg); - if ((lp=strchr_m(cmdline_auth_info.username,'%'))) { + if ((lp=strchr_m(puser,'%'))) { + size_t len; *lp = 0; - pstrcpy(cmdline_auth_info.password,lp+1); - cmdline_auth_info.got_pass = True; - memset(strchr_m(arg,'%')+1,'X',strlen(cmdline_auth_info.password)); + set_cmdline_auth_info_username(puser); + set_cmdline_auth_info_password(lp+1); + len = strlen(lp+1); + memset(strchr_m(arg,'%')+1,'X',len); + } else { + set_cmdline_auth_info_username(puser); } + SAFE_FREE(puser); } break; @@ -530,25 +482,14 @@ static void popt_common_credentials_callback(poptContext con, d_printf("No kerberos support compiled in\n"); exit(1); #else - cmdline_auth_info.use_kerberos = true; - cmdline_auth_info.got_pass = true; + set_cmdline_auth_info_use_krb5_ticket(); #endif break; case 'S': - { - cmdline_auth_info.signing_state = -1; - if (strequal(arg, "off") || strequal(arg, "no") || strequal(arg, "false")) { - cmdline_auth_info.signing_state = false; - } else if (strequal(arg, "on") || strequal(arg, "yes") || strequal(arg, "true") || - strequal(arg, "auto")) { - cmdline_auth_info.signing_state = true; - } else if (strequal(arg, "force") || strequal(arg, "required") || strequal(arg, "forced")) { - cmdline_auth_info.signing_state = Required; - } else { - fprintf(stderr, "Unknown signing option %s\n", arg ); - exit(1); - } + if (!set_cmdline_auth_info_signing_state(arg)) { + fprintf(stderr, "Unknown signing option %s\n", arg ); + exit(1); } break; case 'P': @@ -579,17 +520,20 @@ static void popt_common_credentials_callback(poptContext con, SAFE_FREE(opt_password); /* machine accounts only work with kerberos */ - cmdline_auth_info.use_kerberos = true; + set_cmdline_auth_info_use_krb5_ticket(); } break; + case 'N': + set_cmdline_auth_info_no_password(); + break; } } struct poptOption popt_common_credentials[] = { { NULL, 0, POPT_ARG_CALLBACK|POPT_CBFLAG_PRE, (void *)popt_common_credentials_callback }, { "user", 'U', POPT_ARG_STRING, NULL, 'U', "Set the network username", "USERNAME" }, - { "no-pass", 'N', POPT_ARG_NONE, &cmdline_auth_info.got_pass, 0, "Don't ask for a password" }, - { "kerberos", 'k', POPT_ARG_NONE, &cmdline_auth_info.use_kerberos, 'k', "Use kerberos (active directory) authentication" }, + { "no-pass", 'N', POPT_ARG_NONE, NULL, 0, "Don't ask for a password" }, + { "kerberos", 'k', POPT_ARG_NONE, NULL, 'k', "Use kerberos (active directory) authentication" }, { "authentication-file", 'A', POPT_ARG_STRING, NULL, 'A', "Get the credentials from a file", "FILE" }, { "signing", 'S', POPT_ARG_STRING, NULL, 'S', "Set the client signing state", "on|off|required" }, {"machine-pass", 'P', POPT_ARG_NONE, NULL, 'P', "Use stored machine account password" }, -- cgit From e7781bd20ff807019d5f7d116ea0eaf440889e9b Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 6 Dec 2007 19:06:34 -0800 Subject: Fix the '-N' option. Jeremy. (This used to be commit b91b61b54f02f11d80fc25b268faa354fcd1f6e0) --- source3/lib/popt_common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/popt_common.c') diff --git a/source3/lib/popt_common.c b/source3/lib/popt_common.c index bd8410a958..78d81fa530 100644 --- a/source3/lib/popt_common.c +++ b/source3/lib/popt_common.c @@ -532,7 +532,7 @@ static void popt_common_credentials_callback(poptContext con, struct poptOption popt_common_credentials[] = { { NULL, 0, POPT_ARG_CALLBACK|POPT_CBFLAG_PRE, (void *)popt_common_credentials_callback }, { "user", 'U', POPT_ARG_STRING, NULL, 'U', "Set the network username", "USERNAME" }, - { "no-pass", 'N', POPT_ARG_NONE, NULL, 0, "Don't ask for a password" }, + { "no-pass", 'N', POPT_ARG_NONE, NULL, 'N', "Don't ask for a password" }, { "kerberos", 'k', POPT_ARG_NONE, NULL, 'k', "Use kerberos (active directory) authentication" }, { "authentication-file", 'A', POPT_ARG_STRING, NULL, 'A', "Get the credentials from a file", "FILE" }, { "signing", 'S', POPT_ARG_STRING, NULL, 'S', "Set the client signing state", "on|off|required" }, -- cgit From 9e03d6117a2c3049bdb3e2a7226e7b91283bbc23 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 6 Dec 2007 19:15:56 -0800 Subject: *Really* fix the no password -N opt :-). Jeremy. (This used to be commit 187d8a94eae87a32432c7c295698517b6ae31523) --- source3/lib/popt_common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/popt_common.c') diff --git a/source3/lib/popt_common.c b/source3/lib/popt_common.c index 78d81fa530..99c26106af 100644 --- a/source3/lib/popt_common.c +++ b/source3/lib/popt_common.c @@ -524,7 +524,7 @@ static void popt_common_credentials_callback(poptContext con, } break; case 'N': - set_cmdline_auth_info_no_password(); + set_cmdline_auth_info_password(""); break; } } -- cgit From ade51769d5f7291f912893e5f959b651223a68c1 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 7 Dec 2007 12:43:10 -0800 Subject: We don't need P_GSTRING or P_UGSTRING anymore. Jeremy. (This used to be commit 78dc75600099b5b3b5a8ecffec747a227ff51d70) --- source3/lib/popt_common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/lib/popt_common.c') diff --git a/source3/lib/popt_common.c b/source3/lib/popt_common.c index 99c26106af..835eeaecc3 100644 --- a/source3/lib/popt_common.c +++ b/source3/lib/popt_common.c @@ -112,7 +112,7 @@ static void popt_common_callback(poptContext con, if (arg) { set_logfile(con, arg); override_logfile = True; - pstr_sprintf(dyn_LOGFILEBASE, "%s", arg); + snprintf(dyn_LOGFILEBASE, sizeof(dyn_LOGFILEBASE), "%s", arg); } break; -- cgit From 7faee02d0d351c5c039e8f1be7e82ce3a93cbe96 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 10 Dec 2007 11:30:37 -0800 Subject: Remove the char[1024] strings from dynconfig. Replace them with malloc'ing accessor functions. Should save a lot of static space :-). Jeremy. (This used to be commit 52dc5eaef2106015b3a8b659e818bdb15ad94b05) --- source3/lib/popt_common.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'source3/lib/popt_common.c') diff --git a/source3/lib/popt_common.c b/source3/lib/popt_common.c index 835eeaecc3..bc67a0fa28 100644 --- a/source3/lib/popt_common.c +++ b/source3/lib/popt_common.c @@ -66,7 +66,7 @@ static void popt_common_callback(poptContext con, { if (reason == POPT_CALLBACK_REASON_PRE) { - set_logfile(con, dyn_LOGFILEBASE); + set_logfile(con, get_dyn_LOGFILEBASE()); return; } @@ -98,7 +98,7 @@ static void popt_common_callback(poptContext con, case 's': if (arg) { - strlcpy(dyn_CONFIGFILE, arg,sizeof(dyn_CONFIGFILE)); + set_dyn_CONFIGFILE(arg); } break; @@ -112,7 +112,7 @@ static void popt_common_callback(poptContext con, if (arg) { set_logfile(con, arg); override_logfile = True; - snprintf(dyn_LOGFILEBASE, sizeof(dyn_LOGFILEBASE), "%s", arg); + set_dyn_LOGFILEBASE(arg); } break; @@ -193,61 +193,61 @@ static void popt_dynconfig_callback(poptContext con, switch (opt->val) { case DYN_SBINDIR: if (arg) { - dyn_SBINDIR = SMB_STRDUP(arg); + set_dyn_SBINDIR(arg); } break; case DYN_BINDIR: if (arg) { - dyn_BINDIR = SMB_STRDUP(arg); + set_dyn_BINDIR(arg); } break; case DYN_SWATDIR: if (arg) { - dyn_SWATDIR = SMB_STRDUP(arg); + set_dyn_SWATDIR(arg); } break; case DYN_LMHOSTSFILE: if (arg) { - strlcpy(dyn_LMHOSTSFILE, arg,sizeof(dyn_LMHOSTSFILE)); + set_dyn_LMHOSTSFILE(arg); } break; case DYN_LIBDIR: if (arg) { - strlcpy(dyn_LIBDIR, arg,sizeof(dyn_LIBDIR)); + set_dyn_LIBDIR(arg); } break; case DYN_SHLIBEXT: if (arg) { - fstrcpy(dyn_SHLIBEXT, arg); + set_dyn_SHLIBEXT(arg); } break; case DYN_LOCKDIR: if (arg) { - strlcpy(dyn_LOCKDIR, arg,sizeof(dyn_LOCKDIR)); + set_dyn_LOCKDIR(arg); } break; case DYN_PIDDIR: if (arg) { - strlcpy(dyn_PIDDIR, arg,sizeof(dyn_PIDDIR)); + set_dyn_PIDDIR(arg); } break; case DYN_SMB_PASSWD_FILE: if (arg) { - strlcpy(dyn_SMB_PASSWD_FILE, arg,sizeof(dyn_SMB_PASSWD_FILE)); + set_dyn_SMB_PASSWD_FILE(arg); } break; case DYN_PRIVATE_DIR: if (arg) { - strlcpy(dyn_PRIVATE_DIR, arg, sizeof(dyn_PRIVATE_DIR)); + set_dyn_PRIVATE_DIR(arg); } break; -- cgit From 16352dd60b359343520d3d613f92865bba8c9a2c Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 14 Dec 2007 19:36:14 +0100 Subject: add POPT_COMMON_CONFIGFILE which only provides --configfile (not -s) metze (This used to be commit af3392cc20942158ac9e0a533799c5904ff23347) --- source3/lib/popt_common.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'source3/lib/popt_common.c') diff --git a/source3/lib/popt_common.c b/source3/lib/popt_common.c index bc67a0fa28..b3a84a6f7c 100644 --- a/source3/lib/popt_common.c +++ b/source3/lib/popt_common.c @@ -150,6 +150,12 @@ struct poptOption popt_common_samba[] = { POPT_TABLEEND }; +struct poptOption popt_common_configfile[] = { + { NULL, 0, POPT_ARG_CALLBACK|POPT_CBFLAG_PRE|POPT_CBFLAG_POST, (void *)popt_common_callback }, + { "configfile", 0, POPT_ARG_STRING, NULL, 's', "Use alternate configuration file", "CONFIGFILE" }, + POPT_TABLEEND +}; + struct poptOption popt_common_version[] = { { NULL, 0, POPT_ARG_CALLBACK, (void *)popt_common_callback }, { "version", 'V', POPT_ARG_NONE, NULL, 'V', "Print version" }, -- cgit From 9baa97a46ebb92a5968ceba0fb5c2de51e6fa8f0 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 5 Jan 2008 00:23:35 -0800 Subject: Add general '-e' option to enable smb encryption on tools. Jeremy. (This used to be commit 757653966fc1384159bd2d57c5670cd8af0cae96) --- source3/lib/popt_common.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'source3/lib/popt_common.c') diff --git a/source3/lib/popt_common.c b/source3/lib/popt_common.c index b3a84a6f7c..5a9d39d181 100644 --- a/source3/lib/popt_common.c +++ b/source3/lib/popt_common.c @@ -414,6 +414,7 @@ static void get_credentials_file(const char *file) * -N,--no-pass * -S,--signing * -P --machine-pass + * -e --encrypt */ @@ -532,6 +533,10 @@ static void popt_common_credentials_callback(poptContext con, case 'N': set_cmdline_auth_info_password(""); break; + case 'e': + set_cmdline_auth_info_smb_encrypt(); + break; + } } @@ -543,5 +548,6 @@ struct poptOption popt_common_credentials[] = { { "authentication-file", 'A', POPT_ARG_STRING, NULL, 'A', "Get the credentials from a file", "FILE" }, { "signing", 'S', POPT_ARG_STRING, NULL, 'S', "Set the client signing state", "on|off|required" }, {"machine-pass", 'P', POPT_ARG_NONE, NULL, 'P', "Use stored machine account password" }, + {"encrypt", 'e', POPT_ARG_NONE, NULL, 'e', "Encrypt SMB transport (UNIX extended servers only)" }, POPT_TABLEEND }; -- cgit From 174100c30997e6ae70492528da998e30c1bfce60 Mon Sep 17 00:00:00 2001 From: Kai Blin Date: Mon, 4 Feb 2008 16:16:59 +0100 Subject: popt: Use SMB_CONF_PATH environment var if no other configfile is set. Now --configfile (or -s) will have precedence, if that's not given SMB_CONF_PATH is checked, otherwise the $(CONFIGDIR)/smb.conf default value is used. Thanks to Michael for his comments. (This used to be commit 92a9c6c56fa90aead3b7f4a07bf4f3973ba23555) --- source3/lib/popt_common.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'source3/lib/popt_common.c') diff --git a/source3/lib/popt_common.c b/source3/lib/popt_common.c index 5a9d39d181..7f7d23fa00 100644 --- a/source3/lib/popt_common.c +++ b/source3/lib/popt_common.c @@ -71,10 +71,19 @@ static void popt_common_callback(poptContext con, } if (reason == POPT_CALLBACK_REASON_POST) { - if (!PrintSambaVersionString) return; - printf( "Version %s\n", SAMBA_VERSION_STRING); - exit(0); + if (PrintSambaVersionString) { + printf( "Version %s\n", SAMBA_VERSION_STRING); + exit(0); + } + + if (is_default_dyn_CONFIGFILE()) { + if(getenv("SMB_CONF_PATH")) { + set_dyn_CONFIGFILE(getenv("SMB_CONF_PATH")); + } + } + + /* Further 'every Samba program must do this' hooks here. */ return; } -- cgit From fd9efee21d1ed8029032eefe356bcca6d06ae671 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 23 Mar 2008 15:56:41 +0100 Subject: Fix Coverity ID 436 (This used to be commit 9e0ee1ad4fe0f0e7dec0b6824ef234147d845b8d) --- source3/lib/popt_common.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'source3/lib/popt_common.c') diff --git a/source3/lib/popt_common.c b/source3/lib/popt_common.c index 7f7d23fa00..8f0f7c62bb 100644 --- a/source3/lib/popt_common.c +++ b/source3/lib/popt_common.c @@ -327,6 +327,11 @@ static void get_password_file(void) close_it = True; } + if (fd < 0) { + fprintf(stderr, "fd = %d, < 0\n", fd); + exit(1); + } + for(p = pass, *p = '\0'; /* ensure that pass is null-terminated */ p && p - pass < sizeof(pass);) { switch (read(fd, p, 1)) { -- cgit From 4d8836ab96889bcdc35e86bedffa6117f9c35095 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Mon, 5 May 2008 16:58:24 +0200 Subject: Fix client authentication with -P switch in client tools (Bug 5435). Guenther (This used to be commit d077ef64cd1d9bbaeb936566c2c70da508de829f) --- source3/lib/popt_common.c | 30 +----------------------------- 1 file changed, 1 insertion(+), 29 deletions(-) (limited to 'source3/lib/popt_common.c') diff --git a/source3/lib/popt_common.c b/source3/lib/popt_common.c index 8f0f7c62bb..25e41ab5f3 100644 --- a/source3/lib/popt_common.c +++ b/source3/lib/popt_common.c @@ -514,35 +514,7 @@ static void popt_common_credentials_callback(poptContext con, } break; case 'P': - { - char *opt_password = NULL; - char *pwd = NULL; - - /* it is very useful to be able to make ads queries as the - machine account for testing purposes and for domain leave */ - - if (!secrets_init()) { - d_printf("ERROR: Unable to open secrets database\n"); - exit(1); - } - - opt_password = secrets_fetch_machine_password(lp_workgroup(), NULL, NULL); - - if (!opt_password) { - d_printf("ERROR: Unable to fetch machine password\n"); - exit(1); - } - if (asprintf(&pwd, "%s$", global_myname()) < 0) { - exit(ENOMEM); - } - set_cmdline_auth_info_username(pwd); - set_cmdline_auth_info_password(opt_password); - SAFE_FREE(pwd); - SAFE_FREE(opt_password); - - /* machine accounts only work with kerberos */ - set_cmdline_auth_info_use_krb5_ticket(); - } + set_cmdline_auth_info_use_machine_account(); break; case 'N': set_cmdline_auth_info_password(""); -- cgit From dbac75b466831cade91dfad21a2bcbe4bd551b37 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Tue, 15 Jul 2008 11:26:11 +0200 Subject: popt: add a popt_common_debuglevel set of options providing -d|--debuglevel Michael (This used to be commit e7d08b673066a63aaa7ab54ac59566ae8a975672) --- source3/lib/popt_common.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'source3/lib/popt_common.c') diff --git a/source3/lib/popt_common.c b/source3/lib/popt_common.c index 25e41ab5f3..b151f22742 100644 --- a/source3/lib/popt_common.c +++ b/source3/lib/popt_common.c @@ -171,6 +171,12 @@ struct poptOption popt_common_version[] = { POPT_TABLEEND }; +struct poptOption popt_common_debuglevel[] = { + { NULL, 0, POPT_ARG_CALLBACK, (void *)popt_common_callback }, + { "debuglevel", 'd', POPT_ARG_STRING, NULL, 'd', "Set debug level", "DEBUGLEVEL" }, + POPT_TABLEEND +}; + /* Handle command line options: * --sbindir -- cgit From e5830726f48fe786c807c1102f0f44eb38c6749e Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Fri, 15 Aug 2008 00:45:57 +0200 Subject: popt: add support for setting MODULESDIR via popt_common_dynconfig. Michael (This used to be commit 81030e49ce344260d279a3112b13a21ce3520748) --- source3/lib/popt_common.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'source3/lib/popt_common.c') diff --git a/source3/lib/popt_common.c b/source3/lib/popt_common.c index b151f22742..8ceac26bf2 100644 --- a/source3/lib/popt_common.c +++ b/source3/lib/popt_common.c @@ -184,6 +184,7 @@ struct poptOption popt_common_debuglevel[] = { * --swatdir * --lmhostsfile * --libdir + * --modulesdir * --shlibext * --lockdir * --piddir @@ -197,6 +198,7 @@ enum dyn_item{ DYN_SWATDIR, DYN_LMHOSTSFILE, DYN_LIBDIR, + DYN_MODULESDIR, DYN_SHLIBEXT, DYN_LOCKDIR, DYN_PIDDIR, @@ -242,6 +244,12 @@ static void popt_dynconfig_callback(poptContext con, } break; + case DYN_MODULESDIR: + if (arg) { + set_dyn_MODULESDIR(arg); + } + break; + case DYN_SHLIBEXT: if (arg) { set_dyn_SHLIBEXT(arg); @@ -289,6 +297,8 @@ const struct poptOption popt_common_dynconfig[] = { "Path to lmhosts file", "LMHOSTSFILE" }, { "libdir", '\0' , POPT_ARG_STRING, NULL, DYN_LIBDIR, "Path to shared library directory", "LIBDIR" }, + { "modulesdir", '\0' , POPT_ARG_STRING, NULL, DYN_MODULESDIR, + "Path to shared modules directory", "MODULESDIR" }, { "shlibext", '\0' , POPT_ARG_STRING, NULL, DYN_SHLIBEXT, "Shared library extension", "SHLIBEXT" }, { "lockdir", '\0' , POPT_ARG_STRING, NULL, DYN_LOCKDIR, -- cgit