s3:popt_common: Reparse the username in popt_common_credentials_post()
authorAndreas Schneider <asn@samba.org>
Mon, 19 Jun 2017 12:50:33 +0000 (14:50 +0200)
committerAndreas Schneider <asn@cryptomilk.org>
Tue, 20 Jun 2017 08:39:15 +0000 (10:39 +0200)
When we parse the username in the options handling, the smb.conf file
has not been loaded yet. So we are not aware of a 'winbind separator'
set in the config file.

We need to read and set the username again in the post-processing of the
credentials.

https://bugzilla.samba.org/show_bug.cgi?id=12849

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
source3/lib/popt_common.c

index 1c1e3d7c9d43b2050c21cb2702cba7b911190859..65b6efeeb54794f1a2d3ec307ceb5e4be5bb9665 100644 (file)
@@ -247,6 +247,8 @@ void popt_common_credentials_set_delay_post(void)
 
 void popt_common_credentials_post(void)
 {
+       const char *username = NULL;
+
        if (get_cmdline_auth_info_use_machine_account(cmdline_auth_info) &&
            !set_cmdline_auth_info_machine_account_creds(cmdline_auth_info))
        {
@@ -256,6 +258,20 @@ void popt_common_credentials_post(void)
        }
 
        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
+        * didnn'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.
+        */
+       username = get_cmdline_auth_info_username(cmdline_auth_info);
+       if (username != NULL && username[0] != '\0') {
+               set_cmdline_auth_info_username(cmdline_auth_info, username);
+       }
 }
 
 static void popt_common_credentials_callback(poptContext con,