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

Collapse All | Expand All

(-)a/management/univention-management-console-module-diagnostic/umc/python/diagnostic/plugins/samba_tool_showrepl.py (-2 / +154 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 os
35
import ldap
36
import socket
37
38
try:
39
	import samba.param
40
	import samba.credentials
41
	from samba.dcerpc import drsuapi
42
	from samba import drs_utils
43
except ImportError:
44
	SAMBA_AVAILABLE = False
45
else:
46
	SAMBA_AVAILABLE = True
47
48
import univention.uldap
49
from univention.management.console.modules.diagnostic import Warning
50
51
from univention.lib.i18n import Translation
52
_ = Translation('univention-management-console-module-diagnostic').translate
53
54
title = _('Check Samba replication status for errors')
55
description = _('No errors found.'),
56
57
58
def is_service_active(service):
59
	lo = univention.uldap.getMachineConnection()
60
	raw_filter = '(&(univentionService=%s)(cn=%s))'
61
	filter_expr = ldap.filter.filter_format(raw_filter, (service, socket.gethostname()))
62
	for (dn, _attr) in lo.search(filter_expr, attr=['cn']):
63
		if dn is not None:
64
			return True
65
	return False
66
67
68
class DRSUAPI(object):
69
	def __init__(self, dc=None):
70
		(self.load_param, self.credentials) = self.samba_credentials()
71
		self.server = dc or self.netcmd_dnsname(self.load_param)
72
		drs_tuple = drs_utils.drsuapi_connect(self.server, self.load_param, self.credentials)
73
		(self.drsuapi, self.handle, _bind_supported_extensions) = drs_tuple
74
75
	@staticmethod
76
	def netcmd_dnsname(lp):
77
		'''return the full DNS name of our own host. Used as a default
78
		for hostname when running status queries'''
79
		return lp.get('netbios name').lower() + "." + lp.get('realm').lower()
80
81
	@staticmethod
82
	def samba_credentials():
83
		load_param = samba.param.LoadParm()
84
		load_param.set("debug level", "0")
85
		if os.getenv("SMB_CONF_PATH") is not None:
86
			load_param.load(os.getenv("SMB_CONF_PATH"))
87
		else:
88
			load_param.load_default()
89
		credentials = samba.credentials.Credentials()
90
		credentials.guess(load_param)
91
		if not credentials.authentication_requested():
92
			credentials.set_machine_account(load_param)
93
		return (load_param, credentials)
94
95
	def _replica_info(self, info_type):
96
		req1 = drsuapi.DsReplicaGetInfoRequest1()
97
		req1.info_type = info_type
98
		(info_type, info) = self.drsuapi.DsReplicaGetInfo(self.handle, 1, req1)
99
		return (info_type, info)
100
101
	def neighbours(self):
102
		(info_type, info) = self._replica_info(drsuapi.DRSUAPI_DS_REPLICA_INFO_NEIGHBORS)
103
		for neighbour in info.array:
104
			yield neighbour
105
106
		(info_type, info) = self._replica_info(drsuapi.DRSUAPI_DS_REPLICA_INFO_REPSTO)
107
		for neighbour in info.array:
108
			yield neighbour
109
110
	def replication_problems(self):
111
		for neighbour in self.neighbours():
112
			(ecode, estring) = neighbour.result_last_attempt
113
			if ecode != 0:
114
				yield ReplicationProblem(neighbour)
115
116
117
class ReplicationProblem(Exception):
118
	def __init__(self, neighbour):
119
		super(ReplicationProblem, self).__init__(neighbour)
120
		self.neighbour = neighbour
121
122
	def __str__(self):
123
		msg = _('In {nc!r}: error during DRS replication from {source}.')
124
		source = self._parse_ntds_dn(self.neighbour.source_dsa_obj_dn)
125
		return msg.format(nc=self.neighbour.naming_context_dn.encode(),
126
			source=source)
127
128
	@staticmethod
129
	def _parse_ntds_dn(dn):
130
		exploded = ldap.dn.str2dn(dn)
131
		if len(exploded) >= 5:
132
			(first, second, third, fourth, fifth) = exploded[:5]
133
			valid_ntds_dn = all((first[0][1] == 'NTDS Settings',
134
				third[0][1] == 'Servers', fifth[0][1] == 'Sites'))
135
			if valid_ntds_dn:
136
				return '{}/{}'.format(fourth[0][1], second[0][1])
137
		return dn
138
139
140
def run():
141
	if not is_service_active('Samba 4') or not SAMBA_AVAILABLE:
142
		return
143
144
	drs = DRSUAPI()
145
	problems = list(drs.replication_problems())
146
	if problems:
147
		ed = [_('`samba-tool drs showrepl` returned a problem with the replication.')]
148
		ed.extend(str(error) for error in problems)
149
		raise Warning(description='\n'.join(ed))
150
151
152
if __name__ == '__main__':
153
	from univention.management.console.modules.diagnostic import main
154
	main()
1
`samba_tool_showrepl.py` (po)
155
`samba_tool_showrepl.py` (po)
2
--
3
.../umc/python/diagnostic/de.po                      | 20 ++++++++++++++++++--
156
.../umc/python/diagnostic/de.po                      | 20 ++++++++++++++++++--
4
1 file changed, 18 insertions(+), 2 deletions(-)
157
1 file changed, 18 insertions(+), 2 deletions(-)
(-)a/management/univention-management-console-module-diagnostic/umc/python/diagnostic/de.po (-3 / +18 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-28 15:42+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/samba_tool_showrepl.py:54
31
msgid "Check Samba replication status for errors"
32
msgstr "Überprüfe den Samba Replikations Status"
33
30
#: umc/python/diagnostic/plugins/gateway.py:11
34
#: umc/python/diagnostic/plugins/gateway.py:11
31
msgid "Gateway is not reachable"
35
msgid "Gateway is not reachable"
32
msgstr "Gateway ist nicht erreichbar"
36
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 ""
53
msgstr ""
50
"Wenn diese Einstellungen richtig sind liegt das Problem im Gateway selbst:"
54
"Wenn diese Einstellungen richtig sind liegt das Problem im Gateway selbst:"
51
55
56
#: umc/python/diagnostic/plugins/samba_tool_showrepl.py:123
57
msgid "In {nc!r}: error during DRS replication from {source}."
58
msgstr "In {nc!r}: Fehler während der DRS Replikation von {source}."
59
52
#: umc/python/diagnostic/plugins/security_limits.py:19
60
#: umc/python/diagnostic/plugins/security_limits.py:19
53
#, python-brace-format
61
#, python-brace-format
54
msgid ""
62
msgid ""
 Lines 97-102   msgstr "" Link Here 
97
msgid "Nameserver(s) are not responsive"
105
msgid "Nameserver(s) are not responsive"
98
msgstr "Nameserver sind nicht ansprechbar"
106
msgstr "Nameserver sind nicht ansprechbar"
99
107
108
#: umc/python/diagnostic/plugins/samba_tool_showrepl.py:55
109
msgid "No errors found."
110
msgstr "Keine Fehler gefunden."
111
100
#: umc/python/diagnostic/plugins/package_status.py:11
112
#: umc/python/diagnostic/plugins/package_status.py:11
101
msgid "Package status corrupt"
113
msgid "Package status corrupt"
102
msgstr "Paketstatus korrupt"
114
msgstr "Paketstatus korrupt"
 Lines 260-265   msgstr "" Link Here 
260
"dass Authentifikations-Zugangsdaten (falls existierend) korrekt sind und die "
272
"dass Authentifikations-Zugangsdaten (falls existierend) korrekt sind und die "
261
"ACL's des Proxy-Servers nicht verbieten, Anfragen an %s zu stellen."
273
"ACL's des Proxy-Servers nicht verbieten, Anfragen an %s zu stellen."
262
274
275
#: umc/python/diagnostic/plugins/samba_tool_showrepl.py:147
276
msgid "`samba-tool drs showrepl` returned a problem with the replication."
277
msgstr "`samba-tool drs showrepl` gibt ein Problem mit der Replikation zurück."
278
263
#: umc/python/diagnostic/plugins/package_status.py:28
279
#: umc/python/diagnostic/plugins/package_status.py:28
264
msgid "some"
280
msgid "some"
265
msgstr "einigen"
281
msgstr "einigen"
266
- 

Return to bug 44881