samba-tool gpo: improve UNC parsing
authorDouglas Bagnall <douglas.bagnall@catalyst.net.nz>
Thu, 16 Jan 2020 01:12:02 +0000 (14:12 +1300)
committerJeremy Allison <jra@samba.org>
Thu, 16 Jan 2020 20:09:42 +0000 (20:09 +0000)
The "UNC doesn't start with \\\\ or //" message was unreachable due to
a logic error, and an UNC starting with \\ would have been split on
/ if there were enough /s in the string.

The unreachable exception was first noticed by Gerhard Lausser in a
github pull request (https://github.com/samba-team/samba/pull/123),
but that patch no longer applies with this more thorough rewrite.

Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Jeremy Allison <jra@samba.org>
python/samba/netcmd/gpo.py

index e9878c13570e399bb2ce7b3ad6e05e25fcd9a841..76ba9fa18a954779e0beb65f83cb07d206b0ca75 100644 (file)
@@ -235,15 +235,16 @@ def del_gpo_link(samdb, container_dn, gpo):
 
 def parse_unc(unc):
     '''Parse UNC string into a hostname, a service, and a filepath'''
-    if unc.startswith('\\\\') and unc.startswith('//'):
-        raise ValueError("UNC doesn't start with \\\\ or //")
-    tmp = unc[2:].split('/', 2)
-    if len(tmp) == 3:
-        return tmp
-    tmp = unc[2:].split('\\', 2)
-    if len(tmp) == 3:
-        return tmp
-    raise ValueError("Invalid UNC string: %s" % unc)
+    tmp = []
+    if unc.startswith('\\\\'):
+        tmp = unc[2:].split('\\', 2)
+    elif unc.startswith('//'):
+        tmp = unc[2:].split('/', 2)
+
+    if len(tmp) != 3:
+        raise ValueError("Invalid UNC string: %s" % unc)
+
+    return tmp
 
 
 def find_parser(name, flags=re.IGNORECASE):