2 * Copyright (c) 2020 Andreas Schneider <asn@samba.org>
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #include "lib/param/param.h"
20 #include "dynconfig/dynconfig.h"
21 #include "auth/gensec/gensec.h"
22 #include "libcli/smb/smb_util.h"
23 #include "cmdline_private.h"
24 #include "lib/util/util_process.h"
26 #include <samba/version.h>
28 static TALLOC_CTX
*cmdline_mem_ctx
;
29 static struct loadparm_context
*cmdline_lp_ctx
;
30 static struct cli_credentials
*cmdline_creds
;
31 static samba_cmdline_load_config cmdline_load_config_fn
;
32 static struct samba_cmdline_daemon_cfg cmdline_daemon_cfg
;
34 static NTSTATUS (*cli_credentials_set_machine_account_fn
)(
35 struct cli_credentials
*cred
,
36 struct loadparm_context
*lp_ctx
) =
37 cli_credentials_set_machine_account
;
40 bool samba_cmdline_set_talloc_ctx(TALLOC_CTX
*mem_ctx
)
42 if (cmdline_mem_ctx
!= NULL
) {
46 cmdline_mem_ctx
= mem_ctx
;
50 TALLOC_CTX
*samba_cmdline_get_talloc_ctx(void)
52 return cmdline_mem_ctx
;
55 static void _samba_cmdline_talloc_log(const char *message
)
60 bool samba_cmdline_init_common(TALLOC_CTX
*mem_ctx
)
64 ok
= samba_cmdline_set_talloc_ctx(mem_ctx
);
69 cmdline_daemon_cfg
= (struct samba_cmdline_daemon_cfg
) {
76 * Log to stderr by default.
77 * This can be changed to stdout using the option: --debug-stdout
79 setup_logging(getprogname(), DEBUG_DEFAULT_STDERR
);
81 talloc_set_log_fn(_samba_cmdline_talloc_log
);
82 talloc_set_abort_fn(smb_panic
);
87 bool samba_cmdline_set_load_config_fn(samba_cmdline_load_config fn
)
89 cmdline_load_config_fn
= fn
;
94 bool samba_cmdline_set_lp_ctx(struct loadparm_context
*lp_ctx
)
99 cmdline_lp_ctx
= lp_ctx
;
104 struct loadparm_context
*samba_cmdline_get_lp_ctx(void)
106 return cmdline_lp_ctx
;
109 bool samba_cmdline_set_creds(struct cli_credentials
*creds
)
115 TALLOC_FREE(cmdline_creds
);
116 cmdline_creds
= creds
;
121 struct cli_credentials
*samba_cmdline_get_creds(void)
123 return cmdline_creds
;
126 struct samba_cmdline_daemon_cfg
*samba_cmdline_get_daemon_cfg(void)
128 return &cmdline_daemon_cfg
;
131 void samba_cmdline_set_machine_account_fn(
132 NTSTATUS (*fn
) (struct cli_credentials
*cred
,
133 struct loadparm_context
*lp_ctx
))
135 cli_credentials_set_machine_account_fn
= fn
;
138 bool samba_cmdline_burn(int argc
, char *argv
[])
142 bool is_user
= false;
147 for (i
= 0; i
< argc
; i
++) {
154 * Take care that this list must be in longest-match
157 if (strncmp(p
, "-U", 2) == 0) {
161 } else if (strncmp(p
, "--user", 6) == 0) {
165 } else if (strncmp(p
, "--password2", 11) == 0) {
168 } else if (strncmp(p
, "--password", 10) == 0) {
171 } else if (strncmp(p
, "--newpassword", 13) == 0) {
179 if (strlen(p
) == ulen
) {
184 q
= strchr_m(p
, '%');
192 memset_s(p
, strlen(p
), '\0', strlen(p
));
201 static bool is_popt_table_end(const struct poptOption
*o
)
203 if (o
->longName
== NULL
&&
208 o
->descrip
== NULL
&&
209 o
->argDescrip
== NULL
) {
216 static void find_duplicates(const struct poptOption
*needle
,
217 const struct poptOption
*haystack
,
221 !is_popt_table_end(haystack
);
223 switch (haystack
->argInfo
) {
224 case POPT_ARG_INCLUDE_TABLE
:
225 if (haystack
->arg
!= NULL
) {
226 find_duplicates(needle
, haystack
->arg
, count
);
231 if (needle
->shortName
!= 0 &&
232 needle
->shortName
== haystack
->shortName
) {
237 if (needle
->longName
!= NULL
&&
238 haystack
->longName
!= NULL
&&
239 strequal(needle
->longName
, haystack
->longName
)) {
252 static bool cmdline_sanity_checker(const struct poptOption
*current_opts
,
253 const struct poptOption
*full_opts
)
255 const struct poptOption
*o
= current_opts
;
258 !is_popt_table_end(o
);
262 switch (o
->argInfo
) {
263 case POPT_ARG_INCLUDE_TABLE
:
264 if (o
->arg
!= NULL
) {
265 ok
= cmdline_sanity_checker(o
->arg
, full_opts
);
273 if (o
->longName
!= NULL
|| o
->shortName
!= 0) {
276 find_duplicates(o
, full_opts
, &count
);
278 DBG_ERR("Duplicate option '--%s|-%c' "
295 bool samba_cmdline_sanity_check(const struct poptOption
*opts
)
297 return cmdline_sanity_checker(opts
, opts
);
300 poptContext
samba_popt_get_context(const char * name
,
301 int argc
, const char ** argv
,
302 const struct poptOption
* options
,
308 ok
= samba_cmdline_sanity_check(options
);
313 process_save_binary_name(name
);
314 return poptGetContext(name
, argc
, argv
, options
, flags
);
317 /**********************************************************
319 **********************************************************/
321 static bool log_to_file
;
323 static bool set_logfile(TALLOC_CTX
*mem_ctx
,
324 struct loadparm_context
*lp_ctx
,
325 const char *log_basename
,
326 const char *process_name
,
330 char *new_logfile
= talloc_asprintf(mem_ctx
,
334 if (new_logfile
== NULL
) {
339 ok
= lpcfg_set_cmdline(lp_ctx
,
343 ok
= lpcfg_do_global_parameter(lp_ctx
,
349 "Failed to set log to %s\n",
351 TALLOC_FREE(new_logfile
);
354 debug_set_logfile(new_logfile
);
355 TALLOC_FREE(new_logfile
);
360 static void popt_samba_callback(poptContext popt_ctx
,
361 enum poptCallbackReason reason
,
362 const struct poptOption
*opt
,
363 const char *arg
, const void *data
)
365 TALLOC_CTX
*mem_ctx
= samba_cmdline_get_talloc_ctx();
366 struct loadparm_context
*lp_ctx
= samba_cmdline_get_lp_ctx();
367 const char *pname
= NULL
;
370 /* Find out basename of current program */
371 pname
= getprogname();
373 if (reason
== POPT_CALLBACK_REASON_PRE
) {
374 if (lp_ctx
== NULL
) {
376 "Command line parsing not initialized!\n");
379 ok
= set_logfile(mem_ctx
,
381 get_dyn_LOGFILEBASE(),
386 "Failed to set log file for %s\n",
393 if (reason
== POPT_CALLBACK_REASON_POST
) {
394 ok
= cmdline_load_config_fn();
397 "%s - Failed to load config file!\n",
403 const struct loadparm_substitution
*lp_sub
=
404 lpcfg_noop_substitution();
405 char *logfile
= NULL
;
407 logfile
= lpcfg_logfile(lp_ctx
, lp_sub
, mem_ctx
);
408 if (logfile
== NULL
) {
410 "Failed to setup logging to file!");
413 debug_set_logfile(logfile
);
414 setup_logging(logfile
, DEBUG_FILE
);
415 TALLOC_FREE(logfile
);
422 case OPT_LEAK_REPORT
:
423 talloc_enable_leak_report();
425 case OPT_LEAK_REPORT_FULL
:
426 talloc_enable_leak_report_full();
430 ok
= lpcfg_set_option(lp_ctx
, arg
);
432 fprintf(stderr
, "Error setting option '%s'\n", arg
);
439 ok
= lpcfg_set_cmdline(lp_ctx
, "log level", arg
);
442 "Failed to set debug level to: %s\n",
448 case OPT_DEBUG_STDOUT
:
449 setup_logging(pname
, DEBUG_STDOUT
);
453 set_dyn_CONFIGFILE(arg
);
458 ok
= set_logfile(mem_ctx
, lp_ctx
, arg
, pname
, true);
461 "Failed to set log file for %s\n",
467 set_dyn_LOGFILEBASE(arg
);
473 static struct poptOption popt_common_debug
[] = {
475 .argInfo
= POPT_ARG_CALLBACK
|POPT_CBFLAG_PRE
|POPT_CBFLAG_POST
,
476 .arg
= (void *)popt_samba_callback
,
479 .longName
= "debuglevel",
481 .argInfo
= POPT_ARG_STRING
,
483 .descrip
= "Set debug level",
484 .argDescrip
= "DEBUGLEVEL",
487 .longName
= "debug-stdout",
488 .argInfo
= POPT_ARG_NONE
,
489 .val
= OPT_DEBUG_STDOUT
,
490 .descrip
= "Send debug output to standard output",
495 static struct poptOption popt_common_option
[] = {
497 .argInfo
= POPT_ARG_CALLBACK
|POPT_CBFLAG_PRE
|POPT_CBFLAG_POST
,
498 .arg
= (void *)popt_samba_callback
,
501 .longName
= "option",
502 .argInfo
= POPT_ARG_STRING
,
504 .descrip
= "Set smb.conf option from command line",
505 .argDescrip
= "name=value",
510 static struct poptOption popt_common_config
[] = {
512 .argInfo
= POPT_ARG_CALLBACK
|POPT_CBFLAG_PRE
|POPT_CBFLAG_POST
,
513 .arg
= (void *)popt_samba_callback
,
516 .longName
= "configfile",
517 .argInfo
= POPT_ARG_STRING
,
518 .val
= OPT_CONFIGFILE
,
519 .descrip
= "Use alternative configuration file",
520 .argDescrip
= "CONFIGFILE",
525 static struct poptOption popt_common_samba
[] = {
527 .argInfo
= POPT_ARG_CALLBACK
|POPT_CBFLAG_PRE
|POPT_CBFLAG_POST
,
528 .arg
= (void *)popt_samba_callback
,
531 .longName
= "debuglevel",
533 .argInfo
= POPT_ARG_STRING
,
535 .descrip
= "Set debug level",
536 .argDescrip
= "DEBUGLEVEL",
539 .longName
= "debug-stdout",
540 .argInfo
= POPT_ARG_NONE
,
541 .val
= OPT_DEBUG_STDOUT
,
542 .descrip
= "Send debug output to standard output",
545 .longName
= "configfile",
547 .argInfo
= POPT_ARG_STRING
,
548 .val
= OPT_CONFIGFILE
,
549 .descrip
= "Use alternative configuration file",
550 .argDescrip
= "CONFIGFILE",
553 .longName
= "option",
554 .argInfo
= POPT_ARG_STRING
,
556 .descrip
= "Set smb.conf option from command line",
557 .argDescrip
= "name=value",
560 .longName
= "log-basename",
562 .argInfo
= POPT_ARG_STRING
,
564 .descrip
= "Basename for log/debug files",
565 .argDescrip
= "LOGFILEBASE",
568 .longName
= "leak-report",
569 .argInfo
= POPT_ARG_NONE
,
570 .val
= OPT_LEAK_REPORT
,
571 .descrip
= "enable talloc leak reporting on exit",
574 .longName
= "leak-report-full",
575 .argInfo
= POPT_ARG_NONE
,
576 .val
= OPT_LEAK_REPORT_FULL
,
577 .descrip
= "enable full talloc leak reporting on exit",
582 static struct poptOption popt_common_samba_ldb
[] = {
584 .argInfo
= POPT_ARG_CALLBACK
|POPT_CBFLAG_PRE
|POPT_CBFLAG_POST
,
585 .arg
= (void *)popt_samba_callback
,
588 .longName
= "debuglevel",
590 .argInfo
= POPT_ARG_STRING
,
592 .descrip
= "Set debug level",
593 .argDescrip
= "DEBUGLEVEL",
596 .longName
= "debug-stdout",
597 .argInfo
= POPT_ARG_NONE
,
598 .val
= OPT_DEBUG_STDOUT
,
599 .descrip
= "Send debug output to standard output",
602 .longName
= "configfile",
603 .argInfo
= POPT_ARG_STRING
,
604 .val
= OPT_CONFIGFILE
,
605 .descrip
= "Use alternative configuration file",
606 .argDescrip
= "CONFIGFILE",
609 .longName
= "option",
610 .argInfo
= POPT_ARG_STRING
,
612 .descrip
= "Set smb.conf option from command line",
613 .argDescrip
= "name=value",
616 .longName
= "log-basename",
618 .argInfo
= POPT_ARG_STRING
,
620 .descrip
= "Basename for log/debug files",
621 .argDescrip
= "LOGFILEBASE",
624 .longName
= "leak-report",
625 .argInfo
= POPT_ARG_NONE
,
626 .val
= OPT_LEAK_REPORT
,
627 .descrip
= "enable talloc leak reporting on exit",
630 .longName
= "leak-report-full",
631 .argInfo
= POPT_ARG_NONE
,
632 .val
= OPT_LEAK_REPORT_FULL
,
633 .descrip
= "enable full talloc leak reporting on exit",
638 /**********************************************************
640 **********************************************************/
642 static void popt_connection_callback(poptContext popt_ctx
,
643 enum poptCallbackReason reason
,
644 const struct poptOption
*opt
,
648 struct loadparm_context
*lp_ctx
= cmdline_lp_ctx
;
650 if (reason
== POPT_CALLBACK_REASON_PRE
) {
651 if (lp_ctx
== NULL
) {
653 "Command line parsing not initialized!\n");
662 lpcfg_set_cmdline(lp_ctx
, "socket options", arg
);
667 lpcfg_set_cmdline(lp_ctx
, "name resolve order", arg
);
672 lpcfg_set_cmdline(lp_ctx
, "client max protocol", arg
);
675 case OPT_NETBIOS_SCOPE
:
677 lpcfg_set_cmdline(lp_ctx
, "netbios scope", arg
);
682 lpcfg_set_cmdline(lp_ctx
, "netbios name", arg
);
687 lpcfg_set_cmdline(lp_ctx
, "workgroup", arg
);
692 lpcfg_set_cmdline(lp_ctx
, "realm", arg
);
698 static struct poptOption popt_common_connection
[] = {
700 .argInfo
= POPT_ARG_CALLBACK
|POPT_CBFLAG_PRE
,
701 .arg
= (void *)popt_connection_callback
,
704 .longName
= "name-resolve",
706 .argInfo
= POPT_ARG_STRING
,
708 .descrip
= "Use these name resolution services only",
709 .argDescrip
= "NAME-RESOLVE-ORDER",
712 .longName
= "socket-options",
714 .argInfo
= POPT_ARG_STRING
,
716 .descrip
= "socket options to use",
717 .argDescrip
= "SOCKETOPTIONS",
720 .longName
= "max-protocol",
722 .argInfo
= POPT_ARG_STRING
,
724 .descrip
= "Set max protocol level",
725 .argDescrip
= "MAXPROTOCOL",
728 .longName
= "netbiosname",
730 .argInfo
= POPT_ARG_STRING
,
732 .descrip
= "Primary netbios name",
733 .argDescrip
= "NETBIOSNAME",
736 .longName
= "netbios-scope",
737 .argInfo
= POPT_ARG_STRING
,
738 .val
= OPT_NETBIOS_SCOPE
,
739 .descrip
= "Use this Netbios scope",
740 .argDescrip
= "SCOPE",
743 .longName
= "workgroup",
745 .argInfo
= POPT_ARG_STRING
,
747 .descrip
= "Set the workgroup name",
748 .argDescrip
= "WORKGROUP",
752 .argInfo
= POPT_ARG_STRING
,
754 .descrip
= "Set the realm name",
755 .argDescrip
= "REALM",
760 /**********************************************************
762 **********************************************************/
764 static bool skip_password_callback
;
765 static bool machine_account_pending
;
767 static void popt_common_credentials_callback(poptContext popt_ctx
,
768 enum poptCallbackReason reason
,
769 const struct poptOption
*opt
,
773 struct loadparm_context
*lp_ctx
= samba_cmdline_get_lp_ctx();
774 struct cli_credentials
*creds
= samba_cmdline_get_creds();
777 if (reason
== POPT_CALLBACK_REASON_PRE
) {
780 "Command line parsing not initialized!\n");
786 if (reason
== POPT_CALLBACK_REASON_POST
) {
787 const char *username
= NULL
;
788 enum credentials_obtained username_obtained
=
790 enum credentials_obtained password_obtained
=
794 * This calls cli_credentials_set_conf() to get the defaults
795 * form smb.conf and set the winbind separator.
797 * Just warn that we can't read the smb.conf. There might not be
798 * one available or we want to ignore it.
800 ok
= cli_credentials_guess(creds
, lp_ctx
);
803 "Unable to read defaults from smb.conf\n");
806 (void)cli_credentials_get_password_and_obtained(creds
,
808 if (!skip_password_callback
&&
809 password_obtained
< CRED_CALLBACK
) {
810 ok
= cli_credentials_set_cmdline_callbacks(creds
);
813 "Failed to set cmdline password "
819 if (machine_account_pending
) {
822 status
= cli_credentials_set_machine_account_fn(
824 if (!NT_STATUS_IS_OK(status
)) {
826 "Failed to set machine account: %s\n",
833 * When we set the username during the handling of the options
834 * passed to the binary we haven't loaded the config yet. This
835 * means that we didn't take the 'winbind separator' into
838 * The username might contain the domain name and thus it
839 * hasn't been correctly parsed yet. If we have a username we
840 * need to set it again to run the string parser for the
841 * username correctly.
844 cli_credentials_get_username_and_obtained(
845 creds
, &username_obtained
);
846 if (username_obtained
== CRED_SPECIFIED
&&
847 username
!= NULL
&& username
[0] != '\0') {
848 cli_credentials_parse_string(creds
,
859 cli_credentials_parse_string(creds
,
866 ok
= cli_credentials_set_password(creds
,
871 "Failed to set password!\n");
875 skip_password_callback
= true;
879 cli_credentials_set_password_will_be_nt_hash(creds
, true);
883 ok
= cli_credentials_parse_file(creds
,
888 "Failed to set parse authentication file!\n");
891 skip_password_callback
= true;
895 ok
= cli_credentials_set_password(creds
,
900 "Failed to set password!\n");
903 skip_password_callback
= true;
907 * Later, after this is all over, get the machine account
908 * details from the secrets.(l|t)db.
910 machine_account_pending
= true;
912 case OPT_SIMPLE_BIND_DN
:
914 ok
= cli_credentials_set_bind_dn(creds
, arg
);
917 "Failed to set bind DN!\n");
922 case OPT_USE_KERBEROS
: {
923 int32_t use_kerberos
= INT_MIN
;
927 "--use-kerberos=desired|required|off: "
928 "Missing argument\n");
932 use_kerberos
= lpcfg_parse_enum_vals("client use kerberos",
934 if (use_kerberos
== INT_MIN
) {
937 "--use-kerberos=desired|required|off: "
938 "Invalid argument\n");
942 ok
= cli_credentials_set_kerberos_state(creds
,
947 "Failed to set Kerberos state to %s!\n", arg
);
952 case OPT_USE_KERBEROS_CCACHE
: {
953 const char *error_string
= NULL
;
958 "Failed to parse --use-krb5-ccache=CCACHE: "
959 "Missing argument\n");
963 ok
= cli_credentials_set_kerberos_state(creds
,
964 CRED_USE_KERBEROS_REQUIRED
,
968 "Failed to set Kerberos state to %s!\n", arg
);
972 rc
= cli_credentials_set_ccache(creds
,
979 "Error reading krb5 credentials cache: '%s'"
986 skip_password_callback
= true;
989 case OPT_USE_WINBIND_CCACHE
:
991 uint32_t gensec_features
;
993 gensec_features
= cli_credentials_get_gensec_features(creds
);
994 gensec_features
|= GENSEC_FEATURE_NTLM_CCACHE
;
996 ok
= cli_credentials_set_gensec_features(creds
,
1001 "Failed to set gensec feature!\n");
1005 skip_password_callback
= true;
1008 case OPT_CLIENT_PROTECTION
: {
1009 uint32_t gensec_features
;
1010 enum smb_signing_setting signing_state
=
1012 enum smb_encryption_setting encryption_state
=
1018 "--client-protection=sign|encrypt|off: "
1019 "Missing argument\n");
1024 cli_credentials_get_gensec_features(
1027 if (strequal(arg
, "off")) {
1029 ~(GENSEC_FEATURE_SIGN
|GENSEC_FEATURE_SEAL
);
1031 signing_state
= SMB_SIGNING_OFF
;
1032 encryption_state
= SMB_ENCRYPTION_OFF
;
1033 } else if (strequal(arg
, "sign")) {
1034 gensec_features
|= GENSEC_FEATURE_SIGN
;
1036 signing_state
= SMB_SIGNING_REQUIRED
;
1037 encryption_state
= SMB_ENCRYPTION_OFF
;
1038 } else if (strequal(arg
, "encrypt")) {
1039 gensec_features
|= GENSEC_FEATURE_SEAL
;
1041 signing_state
= SMB_SIGNING_REQUIRED
;
1042 encryption_state
= SMB_ENCRYPTION_REQUIRED
;
1045 "Failed to parse --client-protection\n");
1049 ok
= cli_credentials_set_gensec_features(creds
,
1054 "Failed to set gensec feature!\n");
1058 ok
= cli_credentials_set_smb_signing(creds
,
1063 "Failed to set smb signing!\n");
1067 ok
= cli_credentials_set_smb_encryption(creds
,
1072 "Failed to set smb encryption!\n");
1080 static struct poptOption popt_common_credentials
[] = {
1082 .argInfo
= POPT_ARG_CALLBACK
|POPT_CBFLAG_PRE
|POPT_CBFLAG_POST
,
1083 .arg
= (void *)popt_common_credentials_callback
,
1088 .argInfo
= POPT_ARG_STRING
,
1090 .descrip
= "Set the network username",
1091 .argDescrip
= "[DOMAIN/]USERNAME[%PASSWORD]",
1094 .longName
= "no-pass",
1096 .argInfo
= POPT_ARG_NONE
,
1098 .descrip
= "Don't ask for a password",
1101 .longName
= "password",
1102 .argInfo
= POPT_ARG_STRING
,
1103 .val
= OPT_PASSWORD
,
1104 .descrip
= "Password",
1107 .longName
= "pw-nt-hash",
1108 .argInfo
= POPT_ARG_NONE
,
1110 .descrip
= "The supplied password is the NT hash",
1113 .longName
= "authentication-file",
1115 .argInfo
= POPT_ARG_STRING
,
1117 .descrip
= "Get the credentials from a file",
1118 .argDescrip
= "FILE",
1121 .longName
= "machine-pass",
1123 .argInfo
= POPT_ARG_NONE
,
1125 .descrip
= "Use stored machine account password",
1128 .longName
= "simple-bind-dn",
1129 .argInfo
= POPT_ARG_STRING
,
1130 .val
= OPT_SIMPLE_BIND_DN
,
1131 .descrip
= "DN to use for a simple bind",
1135 .longName
= "use-kerberos",
1136 .argInfo
= POPT_ARG_STRING
,
1137 .val
= OPT_USE_KERBEROS
,
1138 .descrip
= "Use Kerberos authentication",
1139 .argDescrip
= "desired|required|off",
1142 .longName
= "use-krb5-ccache",
1143 .argInfo
= POPT_ARG_STRING
,
1144 .val
= OPT_USE_KERBEROS_CCACHE
,
1145 .descrip
= "Credentials cache location for Kerberos",
1146 .argDescrip
= "CCACHE",
1149 .longName
= "use-winbind-ccache",
1150 .argInfo
= POPT_ARG_NONE
,
1151 .val
= OPT_USE_WINBIND_CCACHE
,
1152 .descrip
= "Use the winbind ccache for authentication",
1155 .longName
= "client-protection",
1156 .argInfo
= POPT_ARG_STRING
,
1157 .val
= OPT_CLIENT_PROTECTION
,
1158 .descrip
= "Configure used protection for client connections",
1159 .argDescrip
= "sign|encrypt|off",
1164 /**********************************************************
1166 **********************************************************/
1168 static void popt_version_callback(poptContext ctx
,
1169 enum poptCallbackReason reason
,
1170 const struct poptOption
*opt
,
1176 printf("Version %s\n", SAMBA_VERSION_STRING
);
1181 static struct poptOption popt_common_version
[] = {
1183 .argInfo
= POPT_ARG_CALLBACK
,
1184 .arg
= (void *)popt_version_callback
,
1187 .longName
= "version",
1189 .argInfo
= POPT_ARG_NONE
,
1191 .descrip
= "Print version",
1196 /**********************************************************
1198 **********************************************************/
1200 static void popt_daemon_callback(poptContext ctx
,
1201 enum poptCallbackReason reason
,
1202 const struct poptOption
*opt
,
1208 cmdline_daemon_cfg
.daemon
= true;
1210 case OPT_INTERACTIVE
:
1211 cmdline_daemon_cfg
.interactive
= true;
1212 cmdline_daemon_cfg
.fork
= false;
1215 cmdline_daemon_cfg
.fork
= false;
1217 case OPT_NO_PROCESS_GROUP
:
1218 cmdline_daemon_cfg
.no_process_group
= true;
1223 static struct poptOption popt_common_daemon
[] = {
1225 .argInfo
= POPT_ARG_CALLBACK
,
1226 .arg
= (void *)popt_daemon_callback
1229 .longName
= "daemon",
1231 .argInfo
= POPT_ARG_NONE
,
1234 .descrip
= "Become a daemon (default)" ,
1237 .longName
= "interactive",
1239 .argInfo
= POPT_ARG_NONE
,
1241 .val
= OPT_INTERACTIVE
,
1242 .descrip
= "Run interactive (not a daemon) and log to stdout",
1245 .longName
= "foreground",
1247 .argInfo
= POPT_ARG_NONE
,
1250 .descrip
= "Run daemon in foreground (for daemontools, etc.)",
1253 .longName
= "no-process-group",
1255 .argInfo
= POPT_ARG_NONE
,
1257 .val
= OPT_NO_PROCESS_GROUP
,
1258 .descrip
= "Don't create a new process group" ,
1263 /**********************************************************
1265 **********************************************************/
1267 static void popt_legacy_s3_callback(poptContext ctx
,
1268 enum poptCallbackReason reason
,
1269 const struct poptOption
*opt
,
1273 struct cli_credentials
*creds
= samba_cmdline_get_creds();
1279 "WARNING: The option -k|--kerberos is deprecated!\n");
1281 ok
= cli_credentials_set_kerberos_state(creds
,
1282 CRED_USE_KERBEROS_REQUIRED
,
1286 "Failed to set Kerberos state to %s!\n", arg
);
1290 skip_password_callback
= true;
1295 /* We allow '-k yes' too. */
1296 static struct poptOption popt_legacy_s3
[] = {
1298 .argInfo
= POPT_ARG_CALLBACK
,
1299 .arg
= (void *)popt_legacy_s3_callback
,
1302 .longName
= "kerberos",
1304 .argInfo
= POPT_ARG_NONE
,
1306 .descrip
= "DEPRECATED: Migrate to --use-kerberos",
1311 /**********************************************************
1313 **********************************************************/
1315 static void popt_legacy_s4_callback(poptContext ctx
,
1316 enum poptCallbackReason reason
,
1317 const struct poptOption
*opt
,
1321 struct cli_credentials
*creds
= samba_cmdline_get_creds();
1326 enum credentials_use_kerberos use_kerberos
=
1327 CRED_USE_KERBEROS_REQUIRED
;
1330 "WARNING: The option -k|--kerberos is deprecated!\n");
1333 if (strcasecmp_m(arg
, "yes") == 0) {
1334 use_kerberos
= CRED_USE_KERBEROS_REQUIRED
;
1335 } else if (strcasecmp_m(arg
, "no") == 0) {
1336 use_kerberos
= CRED_USE_KERBEROS_DISABLED
;
1339 "Error parsing -k %s. Should be "
1346 ok
= cli_credentials_set_kerberos_state(creds
,
1351 "Failed to set Kerberos state to %s!\n", arg
);
1360 static struct poptOption popt_legacy_s4
[] = {
1362 .argInfo
= POPT_ARG_CALLBACK
,
1363 .arg
= (void *)popt_legacy_s4_callback
,
1366 .longName
= "kerberos",
1368 .argInfo
= POPT_ARG_STRING
,
1370 .descrip
= "DEPRECATED: Migrate to --use-kerberos",
1375 struct poptOption
*samba_cmdline_get_popt(enum smb_cmdline_popt_options opt
)
1378 case SAMBA_CMDLINE_POPT_OPT_DEBUG_ONLY
:
1379 return popt_common_debug
;
1381 case SAMBA_CMDLINE_POPT_OPT_OPTION_ONLY
:
1382 return popt_common_option
;
1384 case SAMBA_CMDLINE_POPT_OPT_CONFIG_ONLY
:
1385 return popt_common_config
;
1387 case SAMBA_CMDLINE_POPT_OPT_SAMBA
:
1388 return popt_common_samba
;
1390 case SAMBA_CMDLINE_POPT_OPT_CONNECTION
:
1391 return popt_common_connection
;
1393 case SAMBA_CMDLINE_POPT_OPT_CREDENTIALS
:
1394 return popt_common_credentials
;
1396 case SAMBA_CMDLINE_POPT_OPT_VERSION
:
1397 return popt_common_version
;
1399 case SAMBA_CMDLINE_POPT_OPT_DAEMON
:
1400 return popt_common_daemon
;
1402 case SAMBA_CMDLINE_POPT_OPT_SAMBA_LDB
:
1403 return popt_common_samba_ldb
;
1405 case SAMBA_CMDLINE_POPT_OPT_LEGACY_S3
:
1406 return popt_legacy_s3
;
1408 case SAMBA_CMDLINE_POPT_OPT_LEGACY_S4
:
1409 return popt_legacy_s4
;