From: Andreas Schneider Date: Wed, 13 Jan 2021 14:01:56 +0000 (+0100) Subject: s3:lib: Remove popt_samba3 X-Git-Tag: tevent-0.11.0~713 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c377845d27d4dcd7c1791e8b2b42b0f21c9d8bf3;p=thirdparty%2Fsamba.git s3:lib: Remove popt_samba3 _|_ | .-'''''-. .-' '-. .-' :::::_::::: '-. ___/ ==:...:::-:::...:== \___ /_____________________________\ ':'-._________________________.-'_ ':::\ @-,`-[-][-^-][-]-`,-@ / _| |_ '::| .-------------------. ||_ @ _| ::|=|* ___ _ ___ *|=|'.| | ':| |' ))_) )) ))_) '| |::.^| _:|=|' ((`\ (( (( '|=|::::::. _| || |' _ '| |:::::::. |_ |=|'2003 _( )_ 2021'|=|':::::. | || |' ( (_ ~ _) ) '| | ':::' |^||=|* ) (_) ( *|=| '::' | '-------------------' .::::' |_____________________.::::::' .'___________________.::::::'' |_______________.::::'':::''' .'_____________.::::::''::::'' .:::'''' .'::::' .:::::''':. .:::::' Signed-off-by: Andreas Schneider Reviewed-by: Andrew Bartlett --- diff --git a/source3/include/popt_common.h b/source3/include/popt_common.h deleted file mode 100644 index e001a5369b7..00000000000 --- a/source3/include/popt_common.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - Unix SMB/CIFS implementation. - Common popt arguments - Copyright (C) Jelmer Vernooij 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 - 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, - 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, see . -*/ - -#ifndef _POPT_COMMON_H -#define _POPT_COMMON_H - -#include - -/* Common popt structures */ -extern struct poptOption popt_common_samba[]; -extern struct poptOption popt_common_connection[]; -extern struct poptOption popt_common_configfile[]; -extern struct poptOption popt_common_version[]; -extern struct poptOption popt_common_credentials[]; -extern struct poptOption popt_common_debuglevel[]; -extern struct poptOption popt_common_option[]; -extern const struct poptOption popt_common_dynconfig[]; - -#ifndef POPT_TABLEEND -#define POPT_TABLEEND { NULL, '\0', 0, 0, 0, NULL, NULL } -#endif - -#define POPT_COMMON_SAMBA { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_samba, 0, "Common samba options:", NULL }, -#define POPT_COMMON_CONNECTION { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_connection, 0, "Connection options:", NULL }, -#define POPT_COMMON_VERSION { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_version, 0, "Common samba options:", NULL }, -#define POPT_COMMON_CONFIGFILE { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_configfile, 0, "Common samba config:", NULL }, -#define POPT_COMMON_DYNCONFIG { NULL, 0, POPT_ARG_INCLUDE_TABLE, \ - discard_const_p(poptOption, popt_common_dynconfig), 0, \ - "Build-time configuration overrides:", NULL }, -#define POPT_COMMON_DEBUGLEVEL { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_debuglevel, 0, "Common samba debugging:", NULL }, -#define POPT_COMMON_OPTION { NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_option, 0, "Common samba commandline config:", NULL }, - -#endif /* _POPT_COMMON_H */ diff --git a/source3/include/popt_common_cmdline.h b/source3/include/popt_common_cmdline.h deleted file mode 100644 index 21130cff071..00000000000 --- a/source3/include/popt_common_cmdline.h +++ /dev/null @@ -1,47 +0,0 @@ -/* - Unix SMB/CIFS implementation. - Common popt arguments - Copyright (C) Jelmer Vernooij 2003 - Copyright (C) Christof Schmitt 2018 - - 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 3 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, see . -*/ - - -#ifndef _POPT_COMMON_CREDENTIALS_H -#define _POPT_COMMON_CREDENTIALS_H - -#include "popt_common.h" - -extern struct poptOption popt_common_credentials[]; -#define POPT_COMMON_CREDENTIALS \ - { \ - NULL, \ - 0, \ - POPT_ARG_INCLUDE_TABLE, \ - popt_common_credentials, \ - 0, \ - "Authentication options:", \ - NULL \ - }, - -struct user_auth_info *popt_get_cmdline_auth_info(void); -void popt_free_cmdline_auth_info(void); - -void popt_common_credentials_set_ignore_missing_conf(void); -void popt_common_credentials_set_delay_post(void); -void popt_common_credentials_post(void); -void popt_burn_cmdline_password(int argc, char *argv[]); - -#endif diff --git a/source3/lib/popt_common.c b/source3/lib/popt_common.c deleted file mode 100644 index 772c85c5c91..00000000000 --- a/source3/lib/popt_common.c +++ /dev/null @@ -1,337 +0,0 @@ -/* - Unix SMB/CIFS implementation. - Common popt routines - - 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 - 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, - 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, see . -*/ - -#include "includes.h" -#include "popt_common.h" -#include "lib/param/param.h" - -/* Handle command line options: - * -d,--debuglevel - * -s,--configfile - * -O,--socket-options - * -V,--version - * -l,--log-basename - * -n,--netbios-name - * -W,--workgroup - * -i,--scope - */ - -enum {OPT_OPTION=1}; - -extern bool override_logfile; - -static void set_logfile(poptContext con, const char * arg) -{ - - char lfile[PATH_MAX]; - const char *pname; - int ret; - - /* Find out basename of current program */ - pname = strrchr_m(poptGetInvocationName(con), '/'); - if (pname == NULL) { - pname = poptGetInvocationName(con); - } else { - pname++; - } - - ret = snprintf(lfile, sizeof(lfile), "%s/log.%s", arg, pname); - if (ret >= sizeof(lfile)) { - return; - } - lp_set_logfile(lfile); -} - -static bool PrintSambaVersionString; - -static void popt_s3_talloc_log_fn(const char *message) -{ - DEBUG(0,("%s", message)); -} - -static void popt_common_callback(poptContext con, - enum poptCallbackReason reason, - const struct poptOption *opt, - const char *arg, const void *data) -{ - TALLOC_CTX *mem_ctx = talloc_new(NULL); - if (mem_ctx == NULL) { - exit(1); - } - - if (reason == POPT_CALLBACK_REASON_PRE) { - set_logfile(con, get_dyn_LOGFILEBASE()); - talloc_set_log_fn(popt_s3_talloc_log_fn); - talloc_set_abort_fn(smb_panic); - talloc_free(mem_ctx); - return; - } - - if (reason == POPT_CALLBACK_REASON_POST) { - - if (PrintSambaVersionString) { - printf( "Version %s\n", samba_version_string()); - talloc_free(mem_ctx); - exit(0); - } - - if (is_default_dyn_CONFIGFILE()) { - if (getenv("SMB_CONF_PATH")) { - set_dyn_CONFIGFILE(getenv("SMB_CONF_PATH")); - } - } - - if (override_logfile) { - const struct loadparm_substitution *lp_sub = - loadparm_s3_global_substitution(); - char *logfile = lp_logfile(mem_ctx, lp_sub); - if (logfile == NULL) { - talloc_free(mem_ctx); - exit(1); - } - setup_logging(logfile, DEBUG_FILE); - } - - /* Further 'every Samba program must do this' hooks here. */ - talloc_free(mem_ctx); - return; - } - - switch(opt->val) { - case OPT_OPTION: - { - struct loadparm_context *lp_ctx; - bool ok; - - lp_ctx = loadparm_init_s3(mem_ctx, loadparm_s3_helpers()); - if (lp_ctx == NULL) { - fprintf(stderr, "loadparm_init_s3() failed!\n"); - talloc_free(mem_ctx); - exit(1); - } - - ok = lpcfg_set_option(lp_ctx, arg); - if (!ok) { - fprintf(stderr, "Error setting option '%s'\n", arg); - talloc_free(mem_ctx); - exit(1); - } - break; - } - case 'd': - if (arg) { - lp_set_cmdline("log level", arg); - } - break; - - case 'V': - PrintSambaVersionString = True; - break; - - case 'O': - if (arg) { - lp_set_cmdline("socket options", arg); - } - break; - - case 's': - if (arg) { - set_dyn_CONFIGFILE(arg); - } - break; - - case 'n': - if (arg) { - lp_set_cmdline("netbios name", arg); - } - break; - - case 'l': - if (arg) { - set_logfile(con, arg); - override_logfile = True; - set_dyn_LOGFILEBASE(arg); - } - break; - - case 'i': - if (arg) { - lp_set_cmdline("netbios scope", arg); - } - break; - - case 'W': - if (arg) { - lp_set_cmdline("workgroup", arg); - } - break; - } - - talloc_free(mem_ctx); -} - -struct poptOption popt_common_connection[] = { - { - .argInfo = POPT_ARG_CALLBACK, - .arg = (void *)popt_common_callback, - }, - { - .longName = "socket-options", - .shortName = 'O', - .argInfo = POPT_ARG_STRING, - .val = 'O', - .descrip = "socket options to use", - .argDescrip = "SOCKETOPTIONS", - }, - { - .longName = "netbiosname", - .shortName = 'n', - .argInfo = POPT_ARG_STRING, - .val = 'n', - .descrip = "Primary netbios name", - .argDescrip = "NETBIOSNAME" - }, - { - .longName = "workgroup", - .shortName = 'W', - .argInfo = POPT_ARG_STRING, - .val = 'W', - .descrip = "Set the workgroup name", - .argDescrip = "WORKGROUP" - }, - { - .longName = "scope", - .shortName = 'i', - .argInfo = POPT_ARG_STRING, - .val = 'i', - .descrip = "Use this Netbios scope", - .argDescrip = "SCOPE" - }, - POPT_TABLEEND -}; - -struct poptOption popt_common_samba[] = { - { - .argInfo = POPT_ARG_CALLBACK|POPT_CBFLAG_PRE|POPT_CBFLAG_POST, - .arg = (void *)popt_common_callback, - }, - { - .longName = "debuglevel", - .shortName = 'd', - .argInfo = POPT_ARG_STRING, - .val = 'd', - .descrip = "Set debug level", - .argDescrip = "DEBUGLEVEL", - }, - { - .longName = "configfile", - .shortName = 's', - .argInfo = POPT_ARG_STRING, - .val = 's', - .descrip = "Use alternate configuration file", - .argDescrip = "CONFIGFILE", - }, - { - .longName = "log-basename", - .shortName = 'l', - .argInfo = POPT_ARG_STRING, - .val = 'l', - .descrip = "Base name for log files", - .argDescrip = "LOGFILEBASE", - }, - { - .longName = "version", - .shortName = 'V', - .argInfo = POPT_ARG_NONE, - .val = 'V', - .descrip = "Print version", - }, - { - .longName = "option", - .argInfo = POPT_ARG_STRING, - .val = OPT_OPTION, - .descrip = "Set smb.conf option from command line", - .argDescrip = "name=value", - }, - POPT_TABLEEND -}; - -struct poptOption popt_common_configfile[] = { - { - .argInfo = POPT_ARG_CALLBACK|POPT_CBFLAG_PRE|POPT_CBFLAG_POST, - .arg = (void *)popt_common_callback, - }, - { - .longName = "configfile", - .argInfo = POPT_ARG_STRING, - .val = 's', - .descrip = "Use alternate configuration file", - .argDescrip = "CONFIGFILE", - }, - POPT_TABLEEND -}; - -struct poptOption popt_common_version[] = { - { - .argInfo = POPT_ARG_CALLBACK|POPT_CBFLAG_POST, - .arg = (void *)popt_common_callback - }, - { - .longName = "version", - .shortName = 'V', - .argInfo = POPT_ARG_NONE, - .val = 'V', - .descrip = "Print version", - }, - POPT_TABLEEND -}; - -struct poptOption popt_common_debuglevel[] = { - { - .argInfo = POPT_ARG_CALLBACK, - .arg = (void *)popt_common_callback, - }, - { - .longName = "debuglevel", - .shortName = 'd', - .argInfo = POPT_ARG_STRING, - .val = 'd', - .descrip = "Set debug level", - .argDescrip = "DEBUGLEVEL", - }, - POPT_TABLEEND -}; - -struct poptOption popt_common_option[] = { - { - .argInfo = POPT_ARG_CALLBACK|POPT_CBFLAG_POST, - .arg = (void *)popt_common_callback, - }, - { - .longName = "option", - .argInfo = POPT_ARG_STRING, - .val = OPT_OPTION, - .descrip = "Set smb.conf option from command line", - .argDescrip = "name=value", - }, - POPT_TABLEEND -}; diff --git a/source3/lib/popt_common_cmdline.c b/source3/lib/popt_common_cmdline.c deleted file mode 100644 index 39a787510a3..00000000000 --- a/source3/lib/popt_common_cmdline.c +++ /dev/null @@ -1,292 +0,0 @@ -/* - Unix SMB/CIFS implementation. - Common popt routines only used by cmdline utils - - Copyright (C) Tim Potter 2001,2002 - Copyright (C) Jelmer Vernooij 2002,2003 - Copyright (C) James Peach 2006 - Copyright (C) Christof Schmitt 2018 - - 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 3 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, see . -*/ - -/* Handle command line options: - * -U,--user - * -A,--authentication-file - * -k,--use-kerberos - * -N,--no-pass - * -S,--signing - * -P --machine-pass - * -e --encrypt - * -C --use-ccache - */ - -#include "popt_common_cmdline.h" -#include "includes.h" -#include "auth_info.h" -#include "cmdline_contexts.h" - -static struct user_auth_info *cmdline_auth_info; - -struct user_auth_info *popt_get_cmdline_auth_info(void) -{ - return cmdline_auth_info; -} -void popt_free_cmdline_auth_info(void) -{ - TALLOC_FREE(cmdline_auth_info); -} - -static bool popt_common_credentials_ignore_missing_conf; -static bool popt_common_credentials_delay_post; - -void popt_common_credentials_set_ignore_missing_conf(void) -{ - popt_common_credentials_ignore_missing_conf = true; -} - -void popt_common_credentials_set_delay_post(void) -{ - popt_common_credentials_delay_post = true; -} - -void popt_common_credentials_post(void) -{ - if (get_cmdline_auth_info_use_machine_account(cmdline_auth_info) && - !set_cmdline_auth_info_machine_account_creds(cmdline_auth_info)) - { - fprintf(stderr, - "Failed to use machine account credentials\n"); - exit(1); - } - - set_cmdline_auth_info_getpass(cmdline_auth_info); - - /* - * When we set the username during the handling of the options passed to - * the binary we haven't loaded the config yet. This means that we - * didn't take the 'winbind separator' into account. - * - * The username might contain the domain name and thus it hasn't been - * correctly parsed yet. If we have a username we need to set it again - * to run the string parser for the username correctly. - */ - reset_cmdline_auth_info_username(cmdline_auth_info); -} - -static void popt_common_credentials_callback(poptContext con, - enum poptCallbackReason reason, - const struct poptOption *opt, - const char *arg, const void *data) -{ - if (reason == POPT_CALLBACK_REASON_PRE) { - struct user_auth_info *auth_info = - user_auth_info_init(NULL); - if (auth_info == NULL) { - fprintf(stderr, "user_auth_info_init() failed\n"); - exit(1); - } - cmdline_auth_info = auth_info; - return; - } - - if (reason == POPT_CALLBACK_REASON_POST) { - bool ok; - - ok = lp_load_client(get_dyn_CONFIGFILE()); - if (!ok) { - const char *pname = poptGetInvocationName(con); - - fprintf(stderr, "%s: Can't load %s - run testparm to debug it\n", - pname, get_dyn_CONFIGFILE()); - if (!popt_common_credentials_ignore_missing_conf) { - exit(1); - } - } - - load_interfaces(); - - set_cmdline_auth_info_guess(cmdline_auth_info); - - if (popt_common_credentials_delay_post) { - return; - } - - popt_common_credentials_post(); - return; - } - - switch(opt->val) { - case 'U': - set_cmdline_auth_info_username(cmdline_auth_info, arg); - break; - - case 'A': - set_cmdline_auth_info_from_file(cmdline_auth_info, arg); - break; - - case 'k': -#ifndef HAVE_KRB5 - d_printf("No kerberos support compiled in\n"); - exit(1); -#else - set_cmdline_auth_info_use_krb5_ticket(cmdline_auth_info); -#endif - break; - - case 'S': - if (!set_cmdline_auth_info_signing_state(cmdline_auth_info, - arg)) { - fprintf(stderr, "Unknown signing option %s\n", arg ); - exit(1); - } - break; - case 'P': - set_cmdline_auth_info_use_machine_account(cmdline_auth_info); - break; - case 'N': - set_cmdline_auth_info_password(cmdline_auth_info, ""); - break; - case 'e': - set_cmdline_auth_info_smb_encrypt(cmdline_auth_info); - break; - case 'C': - set_cmdline_auth_info_use_ccache(cmdline_auth_info, true); - break; - case 'H': - set_cmdline_auth_info_use_pw_nt_hash(cmdline_auth_info, true); - break; - } -} - -/** - * @brief Burn the commandline password. - * - * This function removes the password from the command line so we - * don't leak the password e.g. in 'ps aux'. - * - * It should be called after processing the options and you should pass down - * argv from main(). - * - * @param[in] argc The number of arguments. - * - * @param[in] argv[] The argument array we will find the array. - */ -void popt_burn_cmdline_password(int argc, char *argv[]) -{ - bool found = false; - char *p = NULL; - int i, ulen = 0; - - for (i = 0; i < argc; i++) { - p = argv[i]; - if (p == NULL) { - return; - } - - if (strncmp(p, "-U", 2) == 0) { - ulen = 2; - found = true; - } else if (strncmp(p, "--user", 6) == 0) { - ulen = 6; - found = true; - } - - if (found) { - if (strlen(p) == ulen) { - continue; - } - - p = strchr_m(p, '%'); - if (p != NULL) { - memset_s(p, strlen(p), '\0', strlen(p)); - } - found = false; - } - } -} - -struct poptOption popt_common_credentials[] = { - { - .argInfo = POPT_ARG_CALLBACK|POPT_CBFLAG_PRE|POPT_CBFLAG_POST, - .arg = (void *)popt_common_credentials_callback, - }, - { - .longName = "user", - .shortName = 'U', - .argInfo = POPT_ARG_STRING, - .val = 'U', - .descrip = "Set the network username", - .argDescrip = "USERNAME", - }, - { - .longName = "no-pass", - .shortName = 'N', - .argInfo = POPT_ARG_NONE, - .val = 'N', - .descrip = "Don't ask for a password", - }, - { - .longName = "kerberos", - .shortName = 'k', - .argInfo = POPT_ARG_NONE, - .val = 'k', - .descrip = "Use kerberos (active directory) authentication", - }, - { - .longName = "authentication-file", - .shortName = 'A', - .argInfo = POPT_ARG_STRING, - .val = 'A', - .descrip = "Get the credentials from a file", - .argDescrip = "FILE", - }, - { - .longName = "signing", - .shortName = 'S', - .argInfo = POPT_ARG_STRING, - .val = 'S', - .descrip = "Set the client signing state", - .argDescrip = "on|off|required", - }, - { - .longName = "machine-pass", - .shortName = 'P', - .argInfo = POPT_ARG_NONE, - .val = 'P', - .descrip = "Use stored machine account password", - }, - { - .longName = "encrypt", - .shortName = 'e', - .argInfo = POPT_ARG_NONE, - .val = 'e', - .descrip = "Encrypt SMB transport", - }, - { - .longName = "use-ccache", - .shortName = 'C', - .argInfo = POPT_ARG_NONE, - .val = 'C', - .descrip = "Use the winbind ccache for authentication", - }, - { - .longName = "pw-nt-hash", - .shortName = '\0', - .argInfo = POPT_ARG_NONE, - .val = 'H', - .descrip = "The supplied password is the NT hash", - }, - POPT_TABLEEND -}; diff --git a/source3/wscript_build b/source3/wscript_build index 5065f0212b2..04b99a22c87 100644 --- a/source3/wscript_build +++ b/source3/wscript_build @@ -267,16 +267,6 @@ bld.SAMBA3_SUBSYSTEM('REG_FULL', tdb-wrap3 ''') -bld.SAMBA3_LIBRARY('popt_samba3', - source='lib/popt_common.c', - deps='popt samba-util smbconf', - private_library=True) - -bld.SAMBA3_LIBRARY('popt_samba3_cmdline', - source='lib/popt_common_cmdline.c', - deps='popt_samba3 util_cmdline cmdline_contexts', - private_library=True) - bld.SAMBA3_LIBRARY('util_cmdline', source='lib/util_cmdline.c', deps='secrets3 samba-credentials cli_smb_common',