TODO tests s3:popt_common: implement -k [yes|no] as alternative to just -k
authorStefan Metzmacher <metze@samba.org>
Tue, 21 Mar 2017 14:14:33 +0000 (15:14 +0100)
committerStefan Metzmacher <metze@samba.org>
Tue, 29 Oct 2019 13:33:03 +0000 (14:33 +0100)
WAS c66b95456e5bf7dc5684b17d51b1e83ebfef2c6e

source3/lib/popt_common_cmdline.c

index 39a787510a32e8155d786bcc34abf85f5a2a5e5a..438866302064505072534e4db25834b751c58d1d 100644 (file)
@@ -24,7 +24,7 @@
 /* Handle command line options:
  *             -U,--user
  *             -A,--authentication-file
- *             -k,--use-kerberos
+ *             -k,--kerberos[=yes|no]
  *             -N,--no-pass
  *             -S,--signing
  *             -P --machine-pass
@@ -90,6 +90,8 @@ static void popt_common_credentials_callback(poptContext con,
                                        const struct poptOption *opt,
                                        const char *arg, const void *data)
 {
+       bool use_kerberos = false;
+
        if (reason == POPT_CALLBACK_REASON_PRE) {
                struct user_auth_info *auth_info =
                                user_auth_info_init(NULL);
@@ -137,12 +139,25 @@ static void popt_common_credentials_callback(poptContext con,
                break;
 
        case 'k':
+               /* Force us to only use kerberos */
+               if (arg) {
+                       if (!set_boolean(arg, &use_kerberos)) {
+                               fprintf(stderr, "Error parsing -k %s. Should be "
+                                       "-k [yes|no]\n", arg);
+                               exit(1);
+                               break;
+                       }
+               }
+
+               if (use_kerberos) {
 #ifndef HAVE_KRB5
-               d_printf("No kerberos support compiled in\n");
-               exit(1);
-#else
-               set_cmdline_auth_info_use_krb5_ticket(cmdline_auth_info);
+                       d_printf("No kerberos support compiled in\n");
+                       exit(1);
 #endif
+                       set_cmdline_auth_info_use_krb5_ticket(cmdline_auth_info);
+               } else {
+                       set_cmdline_auth_info_use_kerberos(cmdline_auth_info, false);
+               }
                break;
 
        case 'S':
@@ -242,7 +257,7 @@ struct poptOption popt_common_credentials[] = {
                .shortName  = 'k',
                .argInfo    = POPT_ARG_NONE,
                .val        = 'k',
-               .descrip    = "Use kerberos (active directory) authentication",
+               .descrip    = "Use kerberos (active directory) authentication, -k [yes|no]",
        },
        {
                .longName   = "authentication-file",