import time
import ldb
import samba.param
+import re
from samba import _glue
from samba._ldb import Ldb as _Ldb
return arcfour_crypt_blob(data, key)
+GUID_RE = re.compile(
+ "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}")
+
+GUID_MIXCASE_RE = re.compile(
+ "[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}",
+ flags = re.IGNORECASE)
+
+
+def string_is_guid(string, lower_case_only=False):
+ """Is the string an ordinary undecorated string GUID?
+
+ That is, like 12345678-abcd-1234-FEED-1234567890ab, and not like
+ variants which have surrounding curly brackets or lack hyphens.
+
+ If lower case_only is true, only lowercase hex characters are
+ accepted. This is tighter than we ever require, but matches what
+ we usually emit.
+ """
+ # Note: it is rightly tempting to use misc.GUID() here and catch
+ # the error, but misc.GUID is more forgiving than we want,
+ # allowing all kinds of weird variants.
+ if lower_case_only:
+ m = GUID_RE.fullmatch(string)
+ else:
+ m = GUID_MIXCASE_RE.fullmatch(string)
+
+ if m is None:
+ return False
+ return True
+
+
def enable_net_export_keytab():
"""This function modifies the samba.net.Net class to contain
an export_keytab() method."""