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(umc_instance):
49
	for mismatch in check_policies():
50
		mismatch.fix()
51
	return run(umc_instance)
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(_umc_instance):
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, 35 insertions(+), 1 deletion(-)
187
1 file changed, 35 insertions(+), 1 deletion(-)
(-)a/management/univention-management-console-module-diagnostic/umc/python/diagnostic/de.po (-2 / +35 lines)
 Lines 3-9   msgid "" Link Here 
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: packages@univention.de\n"
6
"POT-Creation-Date: 2017-08-01 15:41+0200\n"
6
"POT-Creation-Date: 2017-08-01 16:46+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 76-81   msgstr "Alle Nameserver Einträge sind in Ordnung." Link Here 
76
msgid "All shared folder ACLs are in sync with UDM."
76
msgid "All shared folder ACLs are in sync with UDM."
77
msgstr "Alle ACL Einträge der globalen IMAP Ordner stimmen mit UDM überein."
77
msgstr "Alle ACL Einträge der globalen IMAP Ordner stimmen mit UDM überein."
78
78
79
#: umc/python/diagnostic/plugins/inconsistent_policies.py:68
80
#, python-brace-format
81
msgid "Attribute {attr} should be empty."
82
msgstr "Attribut {attr} sollte nicht gesetzt sein."
83
84
#: umc/python/diagnostic/plugins/inconsistent_policies.py:69
85
#, python-brace-format
86
msgid "Attribute {attr} should have value {value}."
87
msgstr "Attribut {attr} sollte den Wert {value} haben."
88
79
#: umc/python/diagnostic/plugins/check_server_password.py:150
89
#: umc/python/diagnostic/plugins/check_server_password.py:150
80
msgid "Authentication against the local LDAP failed with the machine password."
90
msgid "Authentication against the local LDAP failed with the machine password."
81
msgstr ""
91
msgstr ""
 Lines 163-168   msgstr "Password für das Rechnerkonto testen" Link Here 
163
msgid "Check nameserver entries on DNS zones"
173
msgid "Check nameserver entries on DNS zones"
164
msgstr "Überprüfe die Nameserver Einträge der DNS Zonen"
174
msgstr "Überprüfe die Nameserver Einträge der DNS Zonen"
165
175
176
#: umc/python/diagnostic/plugins/inconsistent_policies.py:44
177
msgid "Check password policy inconsistencies"
178
msgstr "Überprüfe Password Richtlinien"
179
166
#: umc/python/diagnostic/plugins/check_update_sites.py:43
180
#: umc/python/diagnostic/plugins/check_update_sites.py:43
167
msgid "Check resolving repository servers"
181
msgid "Check resolving repository servers"
168
msgstr "Überprüfe DNS Auflösung der Repository Server"
182
msgstr "Überprüfe DNS Auflösung der Repository Server"
 Lines 209-214   msgstr "" Link Here 
209
msgid "Fix machine password"
223
msgid "Fix machine password"
210
msgstr "Korrigiere Password für das Rechnerkonto"
224
msgstr "Korrigiere Password für das Rechnerkonto"
211
225
226
#: umc/python/diagnostic/plugins/inconsistent_policies.py:172
227
msgid "Fix password policies"
228
msgstr "Berichtige Password Richtlinien"
229
212
#: umc/python/diagnostic/plugins/mail_acl_sync.py:316
230
#: umc/python/diagnostic/plugins/mail_acl_sync.py:316
213
msgid ""
231
msgid ""
214
"Found differences in the ACLs for IMAP shared folders between UDM and IMAP."
232
"Found differences in the ACLs for IMAP shared folders between UDM and IMAP."
 Lines 298-303   msgstr "In der Forward-Zone {name} (siehe {{{link}}}):" Link Here 
298
msgid "In mail folder {name} (see {{udm:mail/mail}}):"
316
msgid "In mail folder {name} (see {{udm:mail/mail}}):"
299
msgstr "Im globalen Mail Ordner {name} (siehe {{udm:mail/mail}}):"
317
msgstr "Im globalen Mail Ordner {name} (siehe {{udm:mail/mail}}):"
300
318
319
#: umc/python/diagnostic/plugins/inconsistent_policies.py:66
320
msgid "In policy {name!r} (see {{udm:policies/policy}}):"
321
msgstr "In der Richtlinie {name!r} (siehe {{udm:policies/policy}}):"
322
301
#: umc/python/diagnostic/plugins/check_nameservers.py:221
323
#: umc/python/diagnostic/plugins/check_nameservers.py:221
302
#, python-brace-format
324
#, python-brace-format
303
msgid "In reverse zone {name} (see {{{link}}}):"
325
msgid "In reverse zone {name} (see {{{link}}}):"
 Lines 397-402   msgstr "Keine Prolbleme mit der UDN Replikation gefunden." Link Here 
397
msgid "No problems found with modified UCR templates"
419
msgid "No problems found with modified UCR templates"
398
msgstr "Keine Probleme mit modifizierten UCR Vorlagen gefunden."
420
msgstr "Keine Probleme mit modifizierten UCR Vorlagen gefunden."
399
421
422
#: umc/python/diagnostic/plugins/inconsistent_policies.py:45
423
msgid "No problems found."
424
msgstr "Keine Probleme gefunden."
425
400
#: umc/python/diagnostic/plugins/check_update_sites.py:44
426
#: umc/python/diagnostic/plugins/check_update_sites.py:44
401
msgid "No problems were found while resolving update respositories."
427
msgid "No problems were found while resolving update respositories."
402
msgstr "Es wurden keine Probleme beim Auflösen der Repository-Server gefunden."
428
msgstr "Es wurden keine Probleme beim Auflösen der Repository-Server gefunden."
 Lines 679-684   msgstr "" Link Here 
679
"Der SSH Host-Key des entfernten Rechners hat sich geändert (vielleicht wurde "
705
"Der SSH Host-Key des entfernten Rechners hat sich geändert (vielleicht wurde "
680
"der Rechner neu installiert). "
706
"der Rechner neu installiert). "
681
707
708
#: umc/python/diagnostic/plugins/inconsistent_policies.py:169
709
msgid ""
710
"There are inconsistencies between the Univention policies and the Samba "
711
"settings."
712
msgstr ""
713
"Es gibt Widersprüche in den Univention Password Richtlinien und den Samba "
714
"Einstellungen."
715
682
#: umc/python/diagnostic/plugins/gateway.py:28
716
#: umc/python/diagnostic/plugins/gateway.py:28
683
msgid "There is no gateway configured."
717
msgid "There is no gateway configured."
684
msgstr "Es ist kein Gateway eingerichtet."
718
msgstr "Es ist kein Gateway eingerichtet."
685
- 

Return to bug 44897