summaryrefslogtreecommitdiff
path: root/source4/scripting/python
diff options
context:
space:
mode:
authorMatthieu Patou <mat@matws.net>2009-11-22 19:50:31 +0300
committerAndrew Bartlett <abartlet@samba.org>2010-01-21 07:11:15 +1300
commit9b70979bc9b39d8dd5bc7752951f855d2dd87294 (patch)
treec5a33434cafe106829153bc266d079972ab34e25 /source4/scripting/python
parent028c9b1c154ce9b5d7876df76b04aba1f976d1a2 (diff)
downloadsamba-9b70979bc9b39d8dd5bc7752951f855d2dd87294.tar.gz
samba-9b70979bc9b39d8dd5bc7752951f855d2dd87294.tar.bz2
samba-9b70979bc9b39d8dd5bc7752951f855d2dd87294.zip
s4: Make unixid optional
Make unixid optional, if value not supplied next id from id pool will be used. Create a function to get next id in id pool.
Diffstat (limited to 'source4/scripting/python')
-rw-r--r--source4/scripting/python/samba/idmap.py28
1 files changed, 26 insertions, 2 deletions
diff --git a/source4/scripting/python/samba/idmap.py b/source4/scripting/python/samba/idmap.py
index ad209f42de..c0b20bd257 100644
--- a/source4/scripting/python/samba/idmap.py
+++ b/source4/scripting/python/samba/idmap.py
@@ -22,6 +22,7 @@
__docformat__ = "restructuredText"
+import ldb
import samba
class IDmapDB(samba.Ldb):
@@ -50,12 +51,35 @@ class IDmapDB(samba.Ldb):
super(IDmapDB, self).connect(url=self.lp.private_path(url), flags=flags,
options=options)
- def setup_name_mapping(self, sid, type, unixid):
+
+ def increment_xid(self):
+ """Increment xidNumber, if not present it create and assign it to the lowerBound
+
+ :return xid can that be used for SID/unixid mapping
+ """
+ res=self.search(expression="dn=CN=CONFIG",base="", scope=ldb.SCOPE_SUBTREE)
+ id=res[0].get("xidNumber")
+ flag=ldb.FLAG_MOD_REPLACE
+ if id == None:
+ id=res[0].get("lowerBound")
+ flag = ldb.FLAG_MOD_ADD
+ newid = int(str(id)) + 1
+ msg = ldb.Message()
+ msg.dn = ldb.Dn(self,"CN=CONFIG")
+ msg["xidNumber"] = ldb.MessageElement(str(newid),flag,"xidNumber")
+ self.modify(msg)
+
+ return id
+
+
+ def setup_name_mapping(self, sid, type, unixid=None):
"""Setup a mapping between a sam name and a unix name.
:param sid: SID of the NT-side of the mapping.
- :param unixname: Unix name to map to.
+ :param unixname: Unix id to map to, if none supplied the next one will be selected
"""
+ if unixid == None:
+ unixid = self.increment_xid()
type_string = ""
if type == self.TYPE_UID:
type_string = "ID_TYPE_UID"