from ldb import SCOPE_SUBTREE, SCOPE_ONELEVEL
import os
-def get_schema_descriptor(domain_sid):
+def get_schema_descriptor(domain_sid, name_map={}):
sddl = "O:SAG:SAD:AI(OA;;CR;e12b56b6-0a95-11d1-adbb-00c04fd8d5cd;;SA)" \
"(OA;;CR;1131f6aa-9c07-11d1-f79f-00c04fc2dcd2;;ED)" \
"(OA;;CR;1131f6ab-9c07-11d1-f79f-00c04fc2dcd2;;ED)" \
class Schema(object):
- def __init__(self, setup_path, domain_sid, invocationid=None, schemadn=None,
+ def __init__(self, domain_sid, invocationid=None, schemadn=None,
files=None, override_prefixmap=None, additional_prefixmap=None):
+ from samba.provision import setup_path
+
"""Load schema for the SamDB from the AD schema files and
samba4_schema.ldif
:param samdb: Load a schema into a SamDB.
- :param setup_path: Setup path function.
:param schemadn: DN of the schema
Returns the schema data loaded, to avoid double-parsing when then
"""
self.schemadn = schemadn
- # We need to have the am_rodc=False just to keep some warnings quiet - this isn't a real SAM, so it's meaningless.
+ # We need to have the am_rodc=False just to keep some warnings quiet -
+ # this isn't a real SAM, so it's meaningless.
self.ldb = SamDB(global_schema=False, am_rodc=False)
if invocationid is not None:
self.ldb.set_invocation_id(invocationid)
self.prefixmap_data = b64encode(self.prefixmap_data)
# We don't actually add this ldif, just parse it
- prefixmap_ldif = "dn: cn=schema\nprefixMap:: %s\n\n" % self.prefixmap_data
- self.set_from_ldif(prefixmap_ldif, self.schema_data)
+ prefixmap_ldif = "dn: %s\nprefixMap:: %s\n\n" % (self.schemadn, self.prefixmap_data)
+ self.set_from_ldif(prefixmap_ldif, self.schema_data, self.schemadn)
- def set_from_ldif(self, pf, df):
- dsdb._dsdb_set_schema_from_ldif(self.ldb, pf, df)
+ def set_from_ldif(self, pf, df, dn):
+ dsdb._dsdb_set_schema_from_ldif(self.ldb, pf, df, dn)
def write_to_tmp_ldb(self, schemadb_path):
self.ldb.connect(url=schemadb_path)
return dsdb._dsdb_convert_schema_to_openldap(self.ldb, target, mapping)
-# Return a hash with the forward attribute as a key and the back as the value
+# Return a hash with the forward attribute as a key and the back as the value
def get_linked_attributes(schemadn,schemaldb):
attrs = ["linkID", "lDAPDisplayName"]
res = schemaldb.search(expression="(&(linkID=*)(!(linkID:1.2.840.113556.1.4.803:=1))(objectclass=attributeSchema)(attributeSyntax=2.5.5.1))", base=schemadn, scope=SCOPE_ONELEVEL, attrs=attrs)
attributes = {}
for i in range (0, len(res)):
expression = "(&(objectclass=attributeSchema)(linkID=%d)(attributeSyntax=2.5.5.1))" % (int(res[i]["linkID"][0])+1)
- target = schemaldb.searchone(basedn=schemadn,
- expression=expression,
- attribute="lDAPDisplayName",
+ target = schemaldb.searchone(basedn=schemadn,
+ expression=expression,
+ attribute="lDAPDisplayName",
scope=SCOPE_SUBTREE)
if target is not None:
attributes[str(res[i]["lDAPDisplayName"])]=str(target)
return attributes
-def ldb_with_schema(setup_dir=None,
- schemadn="cn=schema,cn=configuration,dc=example,dc=com",
- domainsid=None,
- override_prefixmap=None):
+def ldb_with_schema(schemadn="cn=schema,cn=configuration,dc=example,dc=com",
+ domainsid=None,
+ override_prefixmap=None):
"""Load schema for the SamDB from the AD schema files and samba4_schema.ldif
- :param setup_dir: Setup path
:param schemadn: DN of the schema
:param serverdn: DN of the server
operate without a remote or local schema.
"""
- def setup_path(file):
- return os.path.join(setup_dir, file)
-
if domainsid is None:
domainsid = security.random_sid()
else:
domainsid = security.dom_sid(domainsid)
- return Schema(setup_path, domainsid, schemadn=schemadn,
+ return Schema(domainsid, schemadn=schemadn,
override_prefixmap=override_prefixmap)