s3-lib: Parse WORKGROUP\username in set_cmdline_auth_info_username()
authorAndreas Schneider <asn@samba.org>
Thu, 15 Sep 2016 10:08:24 +0000 (12:08 +0200)
committerStefan Metzmacher <metze@samba.org>
Sun, 25 Sep 2016 07:05:27 +0000 (09:05 +0200)
Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
source3/lib/util_cmdline.c

index d2381f03732fa1d3d72392f31948c29a7ac71d51..3ef1d09d027d1e1a4ef12be5aa7883645df80a54 100644 (file)
@@ -54,8 +54,49 @@ const char *get_cmdline_auth_info_username(const struct user_auth_info *auth_inf
 void set_cmdline_auth_info_username(struct user_auth_info *auth_info,
                                    const char *username)
 {
+       char *s;
+       char *p;
+       bool contains_domain = false;
+
+       s = talloc_strdup(auth_info, username);
+       if (s == NULL) {
+               exit(ENOMEM);
+       }
+
+       p = strchr_m(s, '\\');
+       if (p != NULL) {
+               contains_domain = true;
+       }
+       if (!contains_domain) {
+               p = strchr_m(s, '/');
+               if (p != NULL) {
+                       contains_domain = true;
+               }
+       }
+       if (!contains_domain) {
+               char sep = *lp_winbind_separator();
+
+               if (sep != '\0') {
+                       p = strchr_m(s, *lp_winbind_separator());
+                       if (p != NULL) {
+                               contains_domain = true;
+                       }
+               }
+       }
+
+       if (contains_domain) {
+               *p = '\0';
+               username = p + 1;
+
+               /* s is now the workgroup part */
+               set_cmdline_auth_info_domain(auth_info, s);
+       }
+
        TALLOC_FREE(auth_info->username);
        auth_info->username = talloc_strdup(auth_info, username);
+
+       TALLOC_FREE(s);
+
        if (!auth_info->username) {
                exit(ENOMEM);
        }