View | Details | Raw Unified | Return to bug 42819
Collapse All | Expand All

(-)/usr/lib/univention-directory-listener/system/samba4-idmap.py (-2 / +13 lines)
 Lines 43-48    Link Here 
43
from samba.idmap import IDmapDB
43
from samba.idmap import IDmapDB
44
from samba.auth import system_session
44
from samba.auth import system_session
45
from samba.param import LoadParm
45
from samba.param import LoadParm
46
from samba.provision import setup_idmapdb
46
47
47
name = 'samba4-idmap'
48
name = 'samba4-idmap'
48
description = 'Update local IDmap entries'
49
description = 'Update local IDmap entries'
 Lines 94-112    Link Here 
94
95
95
__SPECIAL_SIDS = set(__SPECIAL_ACCOUNT_SIDS.values())
96
__SPECIAL_SIDS = set(__SPECIAL_ACCOUNT_SIDS.values())
96
97
98
__IDMAP = None
99
97
100
98
def open_idmap():
101
def open_idmap():
102
	if __IDMAP:
103
		return __IDMAP
104
99
	global lp
105
	global lp
106
107
	idmap_ldb = '/var/lib/samba/private/idmap.ldb'
100
	listener.setuid(0)
108
	listener.setuid(0)
101
	try:
109
	try:
102
		idmap = IDmapDB('/var/lib/samba/private/idmap.ldb', session_info=system_session(), lp=lp)
110
		if not os.path.exists(idmap_ldb):
111
			setup_idmapdb(idmap_ldb, session_info=system_session(), lp=lp)
112
		__IDMAP = IDmapDB(idmap_ldb, session_info=system_session(), lp=lp)
103
	except ldb.LdbError:
113
	except ldb.LdbError:
104
		univention.debug.debug(univention.debug.LISTENER, univention.debug.ERROR, "%s: /var/lib/samba/private/idmap.ldb could not be opened" % name)
114
		univention.debug.debug(univention.debug.LISTENER, univention.debug.ERROR, "%s: /var/lib/samba/private/idmap.ldb could not be opened" % name)
105
		raise
115
		raise
106
	finally:
116
	finally:
107
		listener.unsetuid()
117
		listener.unsetuid()
108
118
109
	return idmap
119
	return __IDMAP
110
120
111
121
112
def rename_or_modify_idmap_entry(old_sambaSID, new_sambaSID, xidNumber, type_string, idmap=None):
122
def rename_or_modify_idmap_entry(old_sambaSID, new_sambaSID, xidNumber, type_string, idmap=None):
 Lines 235-240    Link Here 
235
			idmap_ldb_backup = '%s_%d' % (idmap_ldb, time.time())
245
			idmap_ldb_backup = '%s_%d' % (idmap_ldb, time.time())
236
			univention.debug.debug(univention.debug.LISTENER, univention.debug.PROCESS, 'Move %s to %s' % (idmap_ldb, idmap_ldb_backup))
246
			univention.debug.debug(univention.debug.LISTENER, univention.debug.PROCESS, 'Move %s to %s' % (idmap_ldb, idmap_ldb_backup))
237
			os.rename(idmap_ldb, idmap_ldb_backup)
247
			os.rename(idmap_ldb, idmap_ldb_backup)
248
			setup_idmapdb(idmap_ldb, session_info=system_session(), lp=lp)
238
		finally:
249
		finally:
239
			listener.unsetuid()
250
			listener.unsetuid()
240
251

Return to bug 42819