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

(-)a/ucs-school-old-homedirs/remove-old-homedirs.py (-10 / +6 lines)
Lines 29-35 Link Here
29
# /usr/share/common-licenses/AGPL-3; if not, see
29
# /usr/share/common-licenses/AGPL-3; if not, see
30
# <http://www.gnu.org/licenses/>.
30
# <http://www.gnu.org/licenses/>.
31
31
32
__package__ = ''  # workaround for PEP 366
32
from __future__ import absolute_import
33
import listener
33
import listener
34
import os
34
import os
35
import shutil
35
import shutil
Lines 53-58 Link Here
53
target_dir = listener.configRegistry.get("ucsschool/listener/oldhomedir/targetdir")
53
target_dir = listener.configRegistry.get("ucsschool/listener/oldhomedir/targetdir")
54
fs_types = listener.configRegistry.get("ucsschool/listener/oldhomedir/fs_types", DEFAUL_FS).split(":")
54
fs_types = listener.configRegistry.get("ucsschool/listener/oldhomedir/fs_types", DEFAUL_FS).split(":")
55
lo = None
55
lo = None
56
local_ous = []
56
57
57
58
58
def check_target_dir(dir):
59
def check_target_dir(dir):
Lines 141-156 def warn(msg): Link Here
141
	)
142
	)
142
143
143
144
144
def get_my_ous():
145
	"""find out which OUs this host is responsible for, returns list of strings"""
146
	return [s.name for s in School.get_all(lo)]
147
148
149
def prerun():
145
def prerun():
150
	global lo
146
	global lo, local_ous
151
	listener.setuid(0)
147
	listener.setuid(0)
152
	try:
148
	try:
153
		lo, po = getMachineConnection(ldap_master=False)
149
		lo, po = getMachineConnection(ldap_master=False)
150
		local_ous = [s.name for s in School.get_all(lo)]
154
	except LDAPError as exc:
151
	except LDAPError as exc:
155
		warn(str(exc))
152
		warn(str(exc))
156
		return
153
		return
Lines 164-175 def postrun(): Link Here
164
161
165
162
166
def handler(dn, new, old, command):
163
def handler(dn, new, old, command):
167
	my_ous = set(get_my_ous())
164
	users_ous = set(new.get("ucsschoolSchool", local_ous))
168
	users_ous = set(new.get("ucsschoolSchool", []))
169
165
170
	if (
166
	if (
171
		old and not new and not command == "r" or
167
		old and not new and not command == "r" or
172
		old and new and command == "m" and my_ous.isdisjoint(users_ous)
168
		old and new and command == "m" and local_ous.isdisjoint(users_ous)
173
	):
169
	):
174
		uid = old["uid"][0]
170
		uid = old["uid"][0]
175
171

Return to bug 41989