]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s3:utils: Add support for parsing domain/UPN in username for smbget
authorAndreas Schneider <asn@samba.org>
Wed, 29 Mar 2023 06:48:12 +0000 (08:48 +0200)
committerAndrew Bartlett <abartlet@samba.org>
Wed, 5 Apr 2023 01:06:29 +0000 (01:06 +0000)
The smbget utility doesn't use the common command line parser, so it
doesn't support paring of DOMAIN/user or user@realm.

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

Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
selftest/knownfail.d/smbget_msdfs [deleted file]
source3/utils/smbget.c

diff --git a/selftest/knownfail.d/smbget_msdfs b/selftest/knownfail.d/smbget_msdfs
deleted file mode 100644 (file)
index 4c2b71b..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-^samba3.blackbox.smbget.msdfs.domain.fileserver
-^samba3.blackbox.smbget.msdfs.upn.fileserver
index 9463f333eb2c9366aeffc60fe7fb827c47e82ddc..dca5ded4a9c1c944324d12de4ffc10a2bce7eee8 100644 (file)
@@ -21,6 +21,7 @@
 #include "lib/cmdline/cmdline.h"
 #include "libsmbclient.h"
 #include "cmdline_contexts.h"
+#include "lib/param/param.h"
 
 static int columns = 0;
 
@@ -841,7 +842,7 @@ int main(int argc, char **argv)
                        .argInfo    = POPT_ARG_STRING,
                        .arg        = &opt.workgroup,
                        .val        = 'w',
-                       .descrip    = "Workgroup to use (optional)"
+                       .descrip    = "Workgroup/domain to use (optional)"
                },
                {
                        .longName   = "user",
@@ -992,6 +993,11 @@ int main(int argc, char **argv)
        }
        free(rcfile);
 
+       ok = lp_load_client(lp_default_path());
+       if (!ok) {
+               goto done;
+       }
+
 #ifdef SIGWINCH
        signal(SIGWINCH, change_columns);
 #endif
@@ -1014,7 +1020,8 @@ int main(int argc, char **argv)
                case 'e':
                        smb_encrypt = true;
                        break;
-               case 'U':
+               case 'U': {
+                       const char *separator = lp_winbind_separator();
                        opt.username_specified = true;
                        opt.username = talloc_strdup(frame, opt.username);
                        p = strchr(opt.username,'%');
@@ -1023,7 +1030,24 @@ int main(int argc, char **argv)
                                opt.password = p + 1;
                                opt.password_specified = true;
                        }
+
+                       /* UPN support */
+                       p = strchr(opt.username, '@');
+                       if (p != NULL && opt.workgroup == NULL) {
+                               *p = '\0';
+                               opt.workgroup = p + 1;
+                       }
+
+                       /* Domain support */
+                       p = strchr(opt.username, separator[0]);
+                       if (p != NULL && opt.workgroup == NULL) {
+                               *p = '\0';
+                               opt.workgroup = opt.username;
+                               opt.username = p + 1;
+                       }
+
                        break;
+               }
                case 'n':
                        opt.nonprompt = true;
                        break;