mirror of
https://github.com/samba-team/samba.git
synced 2025-07-31 20:22:15 +03:00
Some more formatting fixes, move schema related functions from Ldb to Schema.
This commit is contained in:
@ -107,7 +107,7 @@ hashOverwrittenAtt = { "prefixMap": replace, "systemMayContain": replace,
|
|||||||
|
|
||||||
|
|
||||||
backlinked = []
|
backlinked = []
|
||||||
forwardlinked = {}
|
forwardlinked = set()
|
||||||
dn_syntax_att = []
|
dn_syntax_att = []
|
||||||
def define_what_to_log(opts):
|
def define_what_to_log(opts):
|
||||||
what = 0
|
what = 0
|
||||||
@ -223,7 +223,8 @@ def populate_links(samdb, schemadn):
|
|||||||
linkedAttHash = get_linked_attributes(Dn(samdb, str(schemadn)), samdb)
|
linkedAttHash = get_linked_attributes(Dn(samdb, str(schemadn)), samdb)
|
||||||
backlinked.extend(linkedAttHash.values())
|
backlinked.extend(linkedAttHash.values())
|
||||||
for t in linkedAttHash.keys():
|
for t in linkedAttHash.keys():
|
||||||
forwardlinked[t] = 1
|
forwardlinked.add(t)
|
||||||
|
|
||||||
|
|
||||||
def populate_dnsyntax(samdb, schemadn):
|
def populate_dnsyntax(samdb, schemadn):
|
||||||
"""Populate an array with all the attributes that have DN synthax
|
"""Populate an array with all the attributes that have DN synthax
|
||||||
@ -777,7 +778,7 @@ def update_present(ref_samdb, samdb, basedn, listPresent, usns, invocationid):
|
|||||||
if usns is not None:
|
if usns is not None:
|
||||||
# We have updated by provision usn information so let's exploit
|
# We have updated by provision usn information so let's exploit
|
||||||
# replMetadataProperties
|
# replMetadataProperties
|
||||||
if forwardlinked.has_key(att):
|
if att in forwardlinked:
|
||||||
handle_links(samdb, att, basedn, current[0]["dn"],
|
handle_links(samdb, att, basedn, current[0]["dn"],
|
||||||
current[0][att], reference[0][att], delta)
|
current[0][att], reference[0][att], delta)
|
||||||
|
|
||||||
@ -952,7 +953,7 @@ def update_partition(ref_samdb, samdb, basedn, names, schema, provisionUSNs):
|
|||||||
# a complete schema is needed as the insertion of attributes
|
# a complete schema is needed as the insertion of attributes
|
||||||
# and class is done against it
|
# and class is done against it
|
||||||
# and the schema is self validated
|
# and the schema is self validated
|
||||||
samdb.set_schema_from_ldb(schema.ldb)
|
samdb.set_schema(schema)
|
||||||
try:
|
try:
|
||||||
message(SIMPLE, "There are %d missing objects" % (len(listMissing)))
|
message(SIMPLE, "There are %d missing objects" % (len(listMissing)))
|
||||||
add_deletedobj_containers(ref_samdb, samdb, names)
|
add_deletedobj_containers(ref_samdb, samdb, names)
|
||||||
|
@ -133,7 +133,11 @@ class Ldb(_Ldb):
|
|||||||
return self.schema_format_value(attribute, values.pop())
|
return self.schema_format_value(attribute, values.pop())
|
||||||
|
|
||||||
def erase_users_computers(self, dn):
|
def erase_users_computers(self, dn):
|
||||||
"""Erases user and computer objects from our AD. This is needed since the 'samldb' module denies the deletion of primary groups. Therefore all groups shouldn't be primary somewhere anymore."""
|
"""Erases user and computer objects from our AD.
|
||||||
|
|
||||||
|
This is needed since the 'samldb' module denies the deletion of primary
|
||||||
|
groups. Therefore all groups shouldn't be primary somewhere anymore.
|
||||||
|
"""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
res = self.search(base=dn, scope=ldb.SCOPE_SUBTREE, attrs=[],
|
res = self.search(base=dn, scope=ldb.SCOPE_SUBTREE, attrs=[],
|
||||||
@ -192,7 +196,6 @@ class Ldb(_Ldb):
|
|||||||
|
|
||||||
def erase(self):
|
def erase(self):
|
||||||
"""Erase this ldb, removing all records."""
|
"""Erase this ldb, removing all records."""
|
||||||
|
|
||||||
self.erase_except_schema_controlled()
|
self.erase_except_schema_controlled()
|
||||||
|
|
||||||
# delete the specials
|
# delete the specials
|
||||||
@ -259,33 +262,17 @@ class Ldb(_Ldb):
|
|||||||
:param ldif: LDIF text.
|
:param ldif: LDIF text.
|
||||||
"""
|
"""
|
||||||
for changetype, msg in self.parse_ldif(ldif):
|
for changetype, msg in self.parse_ldif(ldif):
|
||||||
if (changetype == ldb.CHANGETYPE_ADD):
|
if changetype == ldb.CHANGETYPE_ADD:
|
||||||
self.add(msg, controls)
|
self.add(msg, controls)
|
||||||
else:
|
else:
|
||||||
self.modify(msg, controls)
|
self.modify(msg, controls)
|
||||||
|
|
||||||
def set_domain_sid(self, sid):
|
|
||||||
"""Change the domain SID used by this LDB.
|
|
||||||
|
|
||||||
:param sid: The new domain sid to use.
|
|
||||||
"""
|
|
||||||
dsdb.samdb_set_domain_sid(self, sid)
|
|
||||||
|
|
||||||
def domain_sid(self):
|
def domain_sid(self):
|
||||||
"""Read the domain SID used by this LDB.
|
"""Read the domain SID used by this LDB.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
dsdb.samdb_get_domain_sid(self)
|
dsdb.samdb_get_domain_sid(self)
|
||||||
|
|
||||||
def set_schema_from_ldif(self, pf, df):
|
|
||||||
dsdb.dsdb_set_schema_from_ldif(self, pf, df)
|
|
||||||
|
|
||||||
def set_schema_from_ldb(self, ldb):
|
|
||||||
dsdb.dsdb_set_schema_from_ldb(self, ldb)
|
|
||||||
|
|
||||||
def write_prefixes_from_schema(self):
|
|
||||||
dsdb.dsdb_write_prefixes_from_schema_to_ldb(self)
|
|
||||||
|
|
||||||
|
|
||||||
def substitute_var(text, values):
|
def substitute_var(text, values):
|
||||||
"""Substitute strings of the form ${NAME} in str, replacing
|
"""Substitute strings of the form ${NAME} in str, replacing
|
||||||
|
@ -976,7 +976,7 @@ def setup_samdb(path, setup_path, session_info, provision_backend, lp, names,
|
|||||||
logger.info("Pre-loading the Samba 4 and AD schema")
|
logger.info("Pre-loading the Samba 4 and AD schema")
|
||||||
|
|
||||||
# Load the schema from the one we computed earlier
|
# Load the schema from the one we computed earlier
|
||||||
samdb.set_schema_from_ldb(schema.ldb)
|
samdb.set_schema(schema)
|
||||||
|
|
||||||
# And now we can connect to the DB - the schema won't be loaded from the DB
|
# And now we can connect to the DB - the schema won't be loaded from the DB
|
||||||
samdb.connect(path)
|
samdb.connect(path)
|
||||||
|
@ -162,12 +162,9 @@ pwdLastSet: 0
|
|||||||
targetgroup = self.search(base=self.domain_dn(), scope=ldb.SCOPE_SUBTREE,
|
targetgroup = self.search(base=self.domain_dn(), scope=ldb.SCOPE_SUBTREE,
|
||||||
expression=groupfilter, attrs=[])
|
expression=groupfilter, attrs=[])
|
||||||
if len(targetgroup) == 0:
|
if len(targetgroup) == 0:
|
||||||
print('Unable to find group "%s"' % (groupname or expression))
|
raise Exception('Unable to find group "%s"' % groupname)
|
||||||
raise
|
|
||||||
assert(len(targetgroup) == 1)
|
assert(len(targetgroup) == 1)
|
||||||
|
|
||||||
self.delete(targetgroup[0].dn);
|
self.delete(targetgroup[0].dn);
|
||||||
|
|
||||||
except:
|
except:
|
||||||
self.transaction_cancel()
|
self.transaction_cancel()
|
||||||
raise
|
raise
|
||||||
@ -191,8 +188,7 @@ pwdLastSet: 0
|
|||||||
targetgroup = self.search(base=self.domain_dn(), scope=ldb.SCOPE_SUBTREE,
|
targetgroup = self.search(base=self.domain_dn(), scope=ldb.SCOPE_SUBTREE,
|
||||||
expression=groupfilter, attrs=['member'])
|
expression=groupfilter, attrs=['member'])
|
||||||
if len(targetgroup) == 0:
|
if len(targetgroup) == 0:
|
||||||
print('Unable to find group "%s"' % (groupname or expression))
|
raise Exception('Unable to find group "%s"' % groupname)
|
||||||
raise
|
|
||||||
assert(len(targetgroup) == 1)
|
assert(len(targetgroup) == 1)
|
||||||
|
|
||||||
modified = False
|
modified = False
|
||||||
@ -364,8 +360,7 @@ member: %s
|
|||||||
res = self.search(base=self.domain_dn(), scope=ldb.SCOPE_SUBTREE,
|
res = self.search(base=self.domain_dn(), scope=ldb.SCOPE_SUBTREE,
|
||||||
expression=filter, attrs=[])
|
expression=filter, attrs=[])
|
||||||
if len(res) == 0:
|
if len(res) == 0:
|
||||||
print('Unable to find user "%s"' % (username or filter))
|
raise Exception('Unable to find user "%s"' % (username or filter))
|
||||||
raise
|
|
||||||
assert(len(res) == 1)
|
assert(len(res) == 1)
|
||||||
user_dn = res[0].dn
|
user_dn = res[0].dn
|
||||||
|
|
||||||
@ -480,3 +475,12 @@ accountExpires: %u
|
|||||||
|
|
||||||
def load_partition_usn(self, base_dn):
|
def load_partition_usn(self, base_dn):
|
||||||
return dsdb.dsdb_load_partition_usn(self, base_dn)
|
return dsdb.dsdb_load_partition_usn(self, base_dn)
|
||||||
|
|
||||||
|
def set_schema(self, schema):
|
||||||
|
self.set_schema_from_ldb(schema.ldb)
|
||||||
|
|
||||||
|
def set_schema_from_ldb(self, ldb):
|
||||||
|
dsdb.dsdb_set_schema_from_ldb(self, ldb)
|
||||||
|
|
||||||
|
def write_prefixes_from_schema(self):
|
||||||
|
dsdb.dsdb_write_prefixes_from_schema_to_ldb(self)
|
||||||
|
@ -106,7 +106,10 @@ class Schema(object):
|
|||||||
|
|
||||||
# We don't actually add this ldif, just parse it
|
# We don't actually add this ldif, just parse it
|
||||||
prefixmap_ldif = "dn: cn=schema\nprefixMap:: %s\n\n" % self.prefixmap_data
|
prefixmap_ldif = "dn: cn=schema\nprefixMap:: %s\n\n" % self.prefixmap_data
|
||||||
self.ldb.set_schema_from_ldif(prefixmap_ldif, self.schema_data)
|
self.set_from_ldif(prefixmap_ldif, self.schema_data)
|
||||||
|
|
||||||
|
def set_from_ldif(self, pf, df):
|
||||||
|
dsdb.dsdb_set_schema_from_ldif(self.ldb, pf, df)
|
||||||
|
|
||||||
def write_to_tmp_ldb(self, schemadb_path):
|
def write_to_tmp_ldb(self, schemadb_path):
|
||||||
self.ldb.connect(url=schemadb_path)
|
self.ldb.connect(url=schemadb_path)
|
||||||
|
@ -38,6 +38,7 @@ from samba.provision import (ProvisionNames, provision_paths_from_lp,
|
|||||||
setsysvolacl)
|
setsysvolacl)
|
||||||
from samba.dcerpc import misc, security, xattr
|
from samba.dcerpc import misc, security, xattr
|
||||||
from samba.ndr import ndr_unpack
|
from samba.ndr import ndr_unpack
|
||||||
|
from samba.samdb import SamDB
|
||||||
|
|
||||||
# All the ldb related to registry are commented because the path for them is relative
|
# All the ldb related to registry are commented because the path for them is relative
|
||||||
# in the provisionPath object
|
# in the provisionPath object
|
||||||
@ -66,6 +67,7 @@ hashAttrNotCopied = { "dn": 1, "whenCreated": 1, "whenChanged": 1,
|
|||||||
"sAMAccountType":1 }
|
"sAMAccountType":1 }
|
||||||
|
|
||||||
class ProvisionLDB(object):
|
class ProvisionLDB(object):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.sam = None
|
self.sam = None
|
||||||
self.secrets = None
|
self.secrets = None
|
||||||
@ -155,7 +157,7 @@ def get_ldbs(paths, creds, session, lp):
|
|||||||
|
|
||||||
ldbs = ProvisionLDB()
|
ldbs = ProvisionLDB()
|
||||||
|
|
||||||
ldbs.sam = Ldb(paths.samdb, session_info=session, credentials=creds, lp=lp, options=["modules:samba_dsdb"])
|
ldbs.sam = SamDB(paths.samdb, session_info=session, credentials=creds, lp=lp, options=["modules:samba_dsdb"])
|
||||||
ldbs.secrets = Ldb(paths.secrets, session_info=session, credentials=creds, lp=lp)
|
ldbs.secrets = Ldb(paths.secrets, session_info=session, credentials=creds, lp=lp)
|
||||||
ldbs.idmap = Ldb(paths.idmapdb, session_info=session, credentials=creds, lp=lp)
|
ldbs.idmap = Ldb(paths.idmapdb, session_info=session, credentials=creds, lp=lp)
|
||||||
ldbs.privilege = Ldb(paths.privilege, session_info=session, credentials=creds, lp=lp)
|
ldbs.privilege = Ldb(paths.privilege, session_info=session, credentials=creds, lp=lp)
|
||||||
|
Reference in New Issue
Block a user