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

(-)a/doc/errata/staging/univention-pam.yaml (+11 lines)
Line 0    Link Here 
1
product: ucs
2
release: "4.4"
3
version: [1]
4
scope: ucs_4.4-0-errata4.4-1
5
src: univention-pam
6
fix: 
7
desc: |
8
 This update addresses the following issue(s):
9
 * A locking mechanism for ldap-group-to-file.py has been implemented
10
   so that it is ensured the process only runs once at a time.
11
bug: [35173]
0
   Bug #35173: add locking for ldap-group-to-file
12
   Bug #35173: add locking for ldap-group-to-file
(-)a/base/univention-pam/debian/changelog (+6 lines)
 Lines 1-3    Link Here 
1
univention-pam (12.0.2-2) unstable; urgency=medium
2
3
  * Bug #35173: add locking for ldap-group-to-file
4
5
 -- Florian Best <best@univention.de>  Fri, 12 Jul 2019 15:59:01 +0200
6
1
univention-pam (12.0.2-1) unstable; urgency=medium
7
univention-pam (12.0.2-1) unstable; urgency=medium
2
8
3
  * Bug #47233: close ssh connection properly when shutting down
9
  * Bug #47233: close ssh connection properly when shutting down
(-)a/base/univention-pam/ldap-group-to-file.py (-8 / +37 lines)
 Lines 42-47   import tempfile Link Here 
42
import subprocess
42
import subprocess
43
43
44
44
45
LOCKFILE = '/var/run/ldap-group-to-file.pid'
46
47
45
def _get_members(lo, g, recursion_list, check_member=False):
48
def _get_members(lo, g, recursion_list, check_member=False):
46
	result = []
49
	result = []
47
	for m in g[1].get('uniqueMember', []):
50
	for m in g[1].get('uniqueMember', []):
 Lines 76-82   def _get_members(lo, g, recursion_list, check_member=False): Link Here 
76
			if 'univentionGroup' in member[1].get('objectClass', []):
79
			if 'univentionGroup' in member[1].get('objectClass', []):
77
				if member[0] not in recursion_list:
80
				if member[0] not in recursion_list:
78
					recursion_list.append(g[0])
81
					recursion_list.append(g[0])
79
					result += _get_members(lo, member, recursion_list, options.check_member)
82
					result += _get_members(lo, member, recursion_list, check_member)
80
				else:
83
				else:
81
					# Recursion !!!
84
					# Recursion !!!
82
					pass
85
					pass
 Lines 96-105   def _run_hooks(options): Link Here 
96
				p = subprocess.Popen(cmd, stdin=null, stdout=null, stderr=null, shell=False)
99
				p = subprocess.Popen(cmd, stdin=null, stdout=null, stderr=null, shell=False)
97
		_stdout, _stderr = p.communicate()
100
		_stdout, _stderr = p.communicate()
98
	elif options.verbose:
101
	elif options.verbose:
99
		print '%s does not exist' % HOOK_DIR
102
		print('%s does not exist' % HOOK_DIR)
100
103
101
104
102
if __name__ == '__main__':
105
def main():
103
	parser = optparse.OptionParser()
106
	parser = optparse.OptionParser()
104
	parser.add_option("--file", dest="file", default='/var/lib/extrausers/group', action="store", help="write result to the given file, default is /var/lib/extrausers/group")
107
	parser.add_option("--file", dest="file", default='/var/lib/extrausers/group', action="store", help="write result to the given file, default is /var/lib/extrausers/group")
105
	parser.add_option("--verbose", dest="verbose", default=False, action="store_true", help="verbose output")
108
	parser.add_option("--verbose", dest="verbose", default=False, action="store_true", help="verbose output")
 Lines 109-124   if __name__ == '__main__': Link Here 
109
	try:
112
	try:
110
		lo = univention.uldap.getMachineConnection(ldap_master=False)
113
		lo = univention.uldap.getMachineConnection(ldap_master=False)
111
	except ldap.SERVER_DOWN:
114
	except ldap.SERVER_DOWN:
112
		print "Abort: Can't contact LDAP server."
115
		print("Abort: Can't contact LDAP server.")
113
		sys.exit(1)
116
		sys.exit(1)
114
117
115
	result = []
118
	_lock()
119
	try:
120
		return doit(options, lo)
121
	finally:
122
		_release_lock()
123
124
125
def doit(options, lo):
116
	groups = lo.search('objectClass=univentionGroup', attr=['uniqueMember', 'cn', 'gidNumber'])
126
	groups = lo.search('objectClass=univentionGroup', attr=['uniqueMember', 'cn', 'gidNumber'])
117
	if options.verbose:
127
	if options.verbose:
118
		print 'Found %d ldap groups' % len(groups)
128
		print('Found %d ldap groups' % len(groups))
119
129
120
	if len(groups) < 1:
130
	if len(groups) < 1:
121
		print 'Abort: Did not found any LDAP group.'
131
		print('Abort: Did not found any LDAP group.')
122
		sys.exit(1)
132
		sys.exit(1)
123
133
124
	# Write to a temporary file
134
	# Write to a temporary file
 Lines 138-145   if __name__ == '__main__': Link Here 
138
	# Move the file
148
	# Move the file
139
	shutil.move(fdname, options.file)
149
	shutil.move(fdname, options.file)
140
	if options.verbose:
150
	if options.verbose:
141
		print 'The file %s was created.' % options.file
151
		print('The file %s was created.' % options.file)
142
152
143
	_run_hooks(options)
153
	_run_hooks(options)
144
154
145
	sys.exit(0)
155
	sys.exit(0)
156
157
158
def _lock():
159
	if os.path.exists(LOCKFILE):
160
		print('Process is locked by PID: %s' % (open(LOCKFILE).read()),)
161
		sys.exit(2)
162
	with open(LOCKFILE, 'w') as fd:
163
		fd.write(str(os.getpid()))
164
165
166
def _release_lock():
167
	try:
168
		os.remove(LOCKFILE)
169
	except EnvironmentError:
170
		pass
171
172
173
if __name__ == '__main__':
174
	main()

Return to bug 35173