View | Details | Raw Unified | Return to bug 44897 | Differences between
and this patch

Collapse All | Expand All

(-)a/management/univention-management-console-module-diagnostic/umc/python/diagnostic/plugins/inconsistent_policies.py (-2 / +184 lines)
Line 0    Link Here 
0
- 
1
#!/usr/bin/python2.7
2
# coding: utf-8
3
#
4
# Univention Management Console module:
5
#  System Diagnosis UMC module
6
#
7
# Copyright 2017 Univention GmbH
8
#
9
# http://www.univention.de/
10
#
11
# All rights reserved.
12
#
13
# The source code of this program is made available
14
# under the terms of the GNU Affero General Public License version 3
15
# (GNU AGPL V3) as published by the Free Software Foundation.
16
#
17
# Binary versions of this program provided by Univention to you as
18
# well as other copyrighted, protected or trademarked materials like
19
# Logos, graphics, fonts, specific documentations and configurations,
20
# cryptographic keys etc. are subject to a license agreement between
21
# you and Univention and not subject to the GNU AGPL V3.
22
#
23
# In the case you use this program under the terms of the GNU AGPL V3,
24
# the program is provided in the hope that it will be useful,
25
# but WITHOUT ANY WARRANTY; without even the implied warranty of
26
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27
# GNU Affero General Public License for more details.
28
#
29
# You should have received a copy of the GNU Affero General Public
30
# License with the Debian GNU/Linux or Univention distribution in file
31
# /usr/share/common-licenses/AGPL-3; if not, see
32
# <http://www.gnu.org/licenses/>.
33
34
import ldap
35
36
import univention.uldap
37
import univention.admin.uldap
38
import univention.admin.modules as udm_modules
39
from univention.management.console.modules.diagnostic import Warning
40
41
from univention.lib.i18n import Translation
42
_ = Translation('univention-management-console-module-diagnostic').translate
43
44
title = _('Check password policy inconsistencies')
45
description = _('No problems found.')
46
47
48
def fix_policies():
49
	for mismatch in check_policies():
50
		mismatch.fix()
51
	return run()
52
53
54
actions = {
55
	'fix_policies': fix_policies,
56
}
57
58
59
class PolicyMismatch(Exception):
60
	def __init__(self, policy, mismatches):
61
		super(PolicyMismatch, self).__init__(policy.dn)
62
		self.policy = policy
63
		self.mismatches = mismatches
64
65
	def __str__(self):
66
		msg = _('In policy {name!r} (see {{udm:policies/policy}}):')
67
		messages = [msg.format(name=self.policy.get('name'))]
68
		empty_tmpl = _('Attribute {attr} should be empty.')
69
		mismatch_tmpl = _('Attribute {attr} should have value {value}.')
70
		properties = udm_modules.get(self.policy.module).property_descriptions
71
72
		for (attr, value) in self.mismatches:
73
			template = empty_tmpl if value is None else mismatch_tmpl
74
			attr_desc = properties.get(attr).short_description
75
			messages.append(template.format(attr=attr_desc, value=value))
76
		return '\n'.join(messages)
77
78
	def module(self):
79
		return {
80
			'module': 'udm',
81
			'flavor': 'policies/policy',
82
			'props': {
83
				'openObject': {
84
					'objectDN': self.policy.dn,
85
					'objectType': 'policies/pwhistory'
86
				}
87
			}
88
		}
89
90
	def fix(self):
91
		for (attr, value) in self.mismatches:
92
			self.policy[attr] = value
93
		self.policy.modify()
94
95
96
def get_samba_domain(ldap_connection, position):
97
	module = udm_modules.get('settings/sambadomain')
98
	udm_modules.init(ldap_connection, position, module)
99
	for sambadomain in module.lookup(None, ldap_connection, ''):
100
		sambadomain.open()
101
		return sambadomain
102
103
104
def policy_used(ldap_connection, dn):
105
	filter_expr = ldap.filter.filter_format('(univentionPolicyReference=%s)', (dn,))
106
	search = ldap_connection.search(filter=filter_expr, sizelimit=3, attr=['dn'])
107
	return any(dn is not None for (dn, attr) in search)
108
109
110
def get_pw_policies(ldap_connection, position):
111
	module = udm_modules.get('policies/pwhistory')
112
	udm_modules.init(ldap_connection, position, module)
113
	for policy in module.lookup(None, ldap_connection, ''):
114
		if policy_used(ldap_connection, policy.dn):
115
			policy.open()
116
			yield policy
117
118
119
def to_days(unix_time_interval, default_unit='seconds'):
120
	if unix_time_interval is None:
121
		return None
122
123
	try:
124
		(value, unit) = unix_time_interval
125
	except ValueError:
126
		(value, unit) = (unix_time_interval, default_unit)
127
128
	try:
129
		as_int = int(value)
130
	except ValueError:
131
		as_int = 0
132
133
	if unit == 'days':
134
		return str(as_int)
135
	elif unit == 'hours':
136
		return str(as_int / 24)
137
	elif unit == 'minutes':
138
		return str(as_int / (24 * 60))
139
	return str(as_int / (24 * 60 * 60))
140
141
142
def policy_mismatch(samba_domain, pw_policy):
143
	def compare(policy_attr, domain_attr, convert=lambda x: x):
144
		(policy_value, domain_value) = (pw_policy.get(policy_attr), samba_domain.get(domain_attr))
145
		converted_domain_value = convert(domain_value)
146
		if policy_value != converted_domain_value:
147
			yield (policy_attr, converted_domain_value)
148
149
	for result in compare('length', 'passwordHistory'):
150
		yield result
151
	for result in compare('pwLength', 'passwordLength'):
152
		yield result
153
	for result in compare('expiryInterval', 'maxPasswordAge', to_days):
154
		yield result
155
156
157
def check_policies():
158
	(ldap_connection, position) = univention.admin.uldap.getAdminConnection()
159
	samba_domain = get_samba_domain(ldap_connection, position)
160
	for policy in get_pw_policies(ldap_connection, position):
161
		mismatch = list(policy_mismatch(samba_domain, policy))
162
		if mismatch:
163
			yield PolicyMismatch(policy, mismatch)
164
165
166
def run():
167
	univention.admin.modules.update()
168
	problems = list(check_policies())
169
	error = _('There are inconsistencies between the Univention policies and the Samba settings.')
170
	buttons = [{
171
		'action': 'fix_policies',
172
		'label': _('Fix password policies'),
173
	}]
174
175
	if problems:
176
		ed = [error, '']
177
		ed.extend(str(error) for error in problems)
178
		umc_modules = [e.module() for e in problems]
179
		raise Warning(description='\n'.join(ed), umc_modules=umc_modules, buttons=buttons)
180
181
182
if __name__ == '__main__':
183
	from univention.management.console.modules.diagnostic import main
184
	main()
1
`inconsistent_policies.py` (po)
185
`inconsistent_policies.py` (po)
2
--
3
.../umc/python/diagnostic/de.po                    | 36 ++++++++++++++++++++--
186
.../umc/python/diagnostic/de.po                    | 36 ++++++++++++++++++++--
4
1 file changed, 34 insertions(+), 2 deletions(-)
187
1 file changed, 34 insertions(+), 2 deletions(-)
(-)a/management/univention-management-console-module-diagnostic/umc/python/diagnostic/de.po (-3 / +34 lines)
 Lines 2-9    Link Here 
2
msgid ""
2
msgid ""
3
msgstr ""
3
msgstr ""
4
"Project-Id-Version: univention-management-console-module-diagnostic\n"
4
"Project-Id-Version: univention-management-console-module-diagnostic\n"
5
"Report-Msgid-Bugs-To: packages@univention.de\n"
5
"Report-Msgid-Bugs-To: \n"
6
"POT-Creation-Date: 2016-01-14 12:19+0100\n"
6
"POT-Creation-Date: 2017-06-29 14:47+0200\n"
7
"PO-Revision-Date: \n"
7
"PO-Revision-Date: \n"
8
"Last-Translator: Univention GmbH <packages@univention.de>\n"
8
"Last-Translator: Univention GmbH <packages@univention.de>\n"
9
"Language-Team: Univention GmbH <packages@univention.de>\n"
9
"Language-Team: Univention GmbH <packages@univention.de>\n"
 Lines 27-32   msgstr "" Link Here 
27
msgid "Adjust to suggested limits"
27
msgid "Adjust to suggested limits"
28
msgstr "An vorgeschlagene Limits anpassen"
28
msgstr "An vorgeschlagene Limits anpassen"
29
29
30
#: umc/python/diagnostic/plugins/inconsistent_policies.py:69
31
msgid "Attribute {attr} should be empty."
32
msgstr "Attribut {attr} sollte nicht gesetzt sein."
33
34
#: umc/python/diagnostic/plugins/inconsistent_policies.py:70
35
msgid "Attribute {attr} should have value {value}."
36
msgstr "Attribut {attr} sollte den Wert {value} haben."
37
38
#: umc/python/diagnostic/plugins/inconsistent_policies.py:44
39
msgid "Check password policy inconsistencies"
40
msgstr "Überprüfe Password Richtlinien"
41
42
#: umc/python/diagnostic/plugins/inconsistent_policies.py:171
43
msgid "Fix password policies"
44
msgstr "Berichtige Password Richtlinien"
45
30
#: umc/python/diagnostic/plugins/gateway.py:11
46
#: umc/python/diagnostic/plugins/gateway.py:11
31
msgid "Gateway is not reachable"
47
msgid "Gateway is not reachable"
32
msgstr "Gateway ist nicht erreichbar"
48
msgstr "Gateway ist nicht erreichbar"
 Lines 49-54   msgid "If these settings are correct the problem relies in the gateway itself:" Link Here 
49
msgstr ""
65
msgstr ""
50
"Wenn diese Einstellungen richtig sind liegt das Problem im Gateway selbst:"
66
"Wenn diese Einstellungen richtig sind liegt das Problem im Gateway selbst:"
51
67
68
#: umc/python/diagnostic/plugins/inconsistent_policies.py:66
69
msgid "In policy {name!r} (see {{udm:policies/policy}}):"
70
msgstr "In der Richtlinie {name!r} (siehe {{udm:policies/policy}}):"
71
52
#: umc/python/diagnostic/plugins/security_limits.py:19
72
#: umc/python/diagnostic/plugins/security_limits.py:19
53
#, python-brace-format
73
#, python-brace-format
54
msgid ""
74
msgid ""
 Lines 97-102   msgstr "" Link Here 
97
msgid "Nameserver(s) are not responsive"
117
msgid "Nameserver(s) are not responsive"
98
msgstr "Nameserver sind nicht ansprechbar"
118
msgstr "Nameserver sind nicht ansprechbar"
99
119
120
#: umc/python/diagnostic/plugins/inconsistent_policies.py:45
121
msgid "No problems found."
122
msgstr "Keine Probleme gefunden."
123
100
#: umc/python/diagnostic/plugins/package_status.py:11
124
#: umc/python/diagnostic/plugins/package_status.py:11
101
msgid "Package status corrupt"
125
msgid "Package status corrupt"
102
msgstr "Paketstatus korrupt"
126
msgstr "Paketstatus korrupt"
 Lines 231-236   msgstr "" Link Here 
231
"Der SSH Host-Key des entfernten Rechners hat sich geändert (vielleicht wurde "
255
"Der SSH Host-Key des entfernten Rechners hat sich geändert (vielleicht wurde "
232
"der Rechner neu installiert). "
256
"der Rechner neu installiert). "
233
257
258
#: umc/python/diagnostic/plugins/inconsistent_policies.py:168
259
msgid ""
260
"There are inconsistencies between the Univention policies and the Samba "
261
"settings."
262
msgstr ""
263
"Es gibt Widersprüche in den Univention Password Richtlinien und den Samba "
264
"Einstellungen."
265
234
#: umc/python/diagnostic/plugins/proxy.py:16
266
#: umc/python/diagnostic/plugins/proxy.py:16
235
msgid ""
267
msgid ""
236
"There was an error using the proxy server. The {setup:network} can be used "
268
"There was an error using the proxy server. The {setup:network} can be used "
237
- 

Return to bug 44897