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

(-)univention-ad-connector-password-read.orig/connectorpwdread.init.sh (+34 lines)
Line 0    Link Here 
1
#!/bin/sh
2
3
eval "$(univention-config-registry shell)"
4
5
CONFIGBASENAME="connectorpwdread"
6
7
univention-config-registry set  "$CONFIGBASENAME"/ad/autostart?"$connector_ad_autostart" \
8
                                "$CONFIGBASENAME"/ad/ldap/base?"$connector_ad_ldap_base" \
9
                                "$CONFIGBASENAME"/ad/ldap/binddn?"$connector_ad_ldap_binddn" \
10
                                "$CONFIGBASENAME"/ad/ldap/bindpw?"$connector_ad_ldap_bindpw" \
11
                                "$CONFIGBASENAME"/ad/ldap/certificate?"$connector_ad_ldap_certificate" \
12
                                "$CONFIGBASENAME"/ad/ldap/host?"$connector_ad_ldap_host" \
13
                                "$CONFIGBASENAME"/ad/mapping/kerberosdomain?"$connector_ad_mapping_kerberosdomain" \
14
                                "$CONFIGBASENAME"/ad/mapping/language?"$connector_ad_mapping_language" \
15
                                "$CONFIGBASENAME"/ad/ldap/port?"$connector_ad_ldap_port" \
16
                                "$CONFIGBASENAME"/ad/ldap/ssl?"$connector_ad_ldap_ssl" \
17
                                "$CONFIGBASENAME"/ad/listener/dir?"/var/lib/univention-$CONFIGBASENAME/ad" \
18
                                "$CONFIGBASENAME"/ad/mapping/group/language?"$connector_ad_mapping_group_language" \
19
                                "$CONFIGBASENAME"/ad/mapping/group/primarymail?"$connector_ad_mapping_group_primarymail" \
20
                                "$CONFIGBASENAME"/ad/mapping/group/win2000/description?false \
21
                                "$CONFIGBASENAME"/ad/mapping/syncmode?read \
22
                                "$CONFIGBASENAME"/ad/mapping/user/primarymail?false \
23
                                "$CONFIGBASENAME"/ad/mapping/user/win2000/description?false \
24
                                "$CONFIGBASENAME"/ad/poll/sleep?5 \
25
                                "$CONFIGBASENAME"/ad/retryrejected?10 \
26
                                "$CONFIGBASENAME"/debug/function?0 \
27
                                "$CONFIGBASENAME"/debug/level?1 \
28
                                "$CONFIGBASENAME"/password/service/encoding?iso8859-15
29
30
mkdir -p /etc/univention/"$CONFIGBASENAME"/ad
31
cp -a /etc/univention/connector/ad/mapping /etc/univention/"$CONFIGBASENAME"/ad/
32
sed -i "s|@%@connector/ad/|@%@$CONFIGBASENAME/ad/|g;s|'connector/ad/|'$CONFIGBASENAME/ad/|g" /etc/univention/"$CONFIGBASENAME"/ad/mapping
33
34
exit 0
(-)univention-ad-connector-password-read.orig/debian/changelog (+52 lines)
Line 0    Link Here 
1
univention-ad-connector-password-read (1.0.5-2) unstable; urgency=low
2
3
  * Fixed typo (Ticket #2011032410000222)
4
5
 -- Stefan Gohmann <gohmann@univention.de>  Fri, 01 Apr 2011 16:19:10 +0200
6
7
univention-ad-connector-password-read (1.0.5-1) unstable; urgency=low
8
9
  * Re-initialize the ldap connection to UCS because in some customer
10
    environments (write mode) the AD connector is modified to connect
11
    against the ldap/server/name instead of ldap/master
12
    (Ticket #2011032410000222)
13
14
 -- Stefan Gohmann <gohmann@univention.de>  Fri, 01 Apr 2011 16:04:32 +0200
15
16
univention-ad-connector-password-read (1.0.4-1) unstable; urgency=low
17
18
  * Replace all ucr variables in the new mapping file
19
    (Ticket #2011032410000222)
20
21
 -- Stefan Gohmann <gohmann@univention.de>  Thu, 31 Mar 2011 14:45:47 +0200
22
23
univention-ad-connector-password-read (1.0.3-1) unstable; urgency=low
24
25
  * Fixed typo in postinst for connector_ad_mapping_group_language
26
    (Ticket #2011032410000222)
27
28
 -- Stefan Gohmann <gohmann@univention.de>  Wed, 30 Mar 2011 19:58:17 +0200
29
30
univention-ad-connector-password-read (1.0.2-1) unstable; urgency=low
31
32
  * Fixed excepetion error (Ticket #2011032410000222)
33
  * Sleep for poll_sleep interval if the AD server is not available
34
    (Ticket #2011032410000222)
35
36
 -- Stefan Gohmann <gohmann@univention.de>  Wed, 30 Mar 2011 11:08:12 +0200
37
38
univention-ad-connector-password-read (1.0.1-1) unstable; urgency=low
39
40
  * Removed unused debug code
41
  * Added an exception handling if the user does not exist in UCS, this
42
    is possible because the AD connector is normally in write mode
43
  (Ticket #2011032410000222)
44
45
 -- Stefan Gohmann <gohmann@univention.de>  Wed, 30 Mar 2011 07:46:43 +0200
46
47
univention-ad-connector-password-read (1.0.0-1) unstable; urgency=low
48
49
  * Initial Release (Ticket #2011032410000222)
50
51
 -- Stefan Gohmann <gohmann@univention.de>  Tue, 29 Mar 2011 06:43:39 +0200
52
(-)univention-ad-connector-password-read.orig/debian/compat (+1 lines)
Line 0    Link Here 
1
7
(-)univention-ad-connector-password-read.orig/debian/control (+22 lines)
Line 0    Link Here 
1
Source: univention-ad-connector-password-read
2
Section: univention
3
Priority: optional
4
Maintainer: Univention GmbH <packages@univention.de>
5
Standards-Version: 3.5.5
6
Build-Depends: debhelper (>> 7), univention-config-dev
7
8
Package: univention-ad-connector-password-read
9
Architecture: all
10
Depends: univention-directory-manager-tools,
11
 univention-ad-connector,
12
 ${misc:Depends}
13
Description: Synchronize password only from AD to UCS
14
 This package contains a daemon wich synchronize the password from AD to
15
 UCS. This is useful if the ad connector is configured in write mode (UCS
16
 -> AD) and only the password must be synchronized back from AD to UCS.
17
 This package requires a configured AD connector.
18
 This package is part of Univention Corporate Server (UCS), an
19
 integrated, directory driven solution for managing corporate
20
 environments. For more information about UCS, refer to:
21
 http://www.univention.de/
22
(-)univention-ad-connector-password-read.orig/debian/copyright (+28 lines)
Line 0    Link Here 
1
Copyright 2010-2011 Univention GmbH
2
3
http://www.univention.de/
4
5
All rights reserved.
6
7
The source code of the software contained in this package
8
as well as the source package itself are made available
9
under the terms of the GNU Affero General Public License version 3
10
(GNU AGPL V3) as published by the Free Software Foundation.
11
12
Binary versions of this package provided by Univention to you as
13
well as other copyrighted, protected or trademarked materials like
14
Logos, graphics, fonts, specific documentations and configurations,
15
cryptographic keys etc. are subject to a license agreement between
16
you and Univention and not subject to the GNU AGPL V3.
17
18
In the case you use the software under the terms of the GNU AGPL V3,
19
the program is provided in the hope that it will be useful,
20
but WITHOUT ANY WARRANTY; without even the implied warranty of
21
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22
GNU Affero General Public License for more details.
23
24
You should have received a copy of the GNU Affero General Public
25
License with the Debian GNU/Linux or Univention distribution in file
26
/usr/share/common-licenses/AGPL-3; if not, see
27
<http://www.gnu.org/licenses/>.
28
(-)univention-ad-connector-password-read.orig/debian/rules (+42 lines)
Line 0    Link Here 
1
#!/usr/bin/make -f
2
#
3
# univention-ad-connector-password-read
4
#  debhelper script for the debian package
5
#
6
# Copyright 2010-2011 Univention GmbH
7
#
8
# http://www.univention.de/
9
#
10
# All rights reserved.
11
#
12
# The source code of this program is made available
13
# under the terms of the GNU Affero General Public License version 3
14
# (GNU AGPL V3) as published by the Free Software Foundation.
15
#
16
# Binary versions of this program provided by Univention to you as
17
# well as other copyrighted, protected or trademarked materials like
18
# Logos, graphics, fonts, specific documentations and configurations,
19
# cryptographic keys etc. are subject to a license agreement between
20
# you and Univention and not subject to the GNU AGPL V3.
21
#
22
# In the case you use this program under the terms of the GNU AGPL V3,
23
# the program is provided in the hope that it will be useful,
24
# but WITHOUT ANY WARRANTY; without even the implied warranty of
25
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26
# GNU Affero General Public License for more details.
27
#
28
# You should have received a copy of the GNU Affero General Public
29
# License with the Debian GNU/Linux or Univention distribution in file
30
# /usr/share/common-licenses/AGPL-3; if not, see
31
# <http://www.gnu.org/licenses/>.
32
33
override_dh_auto_install:
34
	univention-install-config-registry
35
	dh_auto_install
36
37
override_dh_auto_build:
38
	dh_auto_build
39
%:
40
	dh $@
41
42
(-)univention-ad-connector-password-read.orig/debian/univention-ad-connector-password-read.init (+73 lines)
Line 0    Link Here 
1
#!/bin/sh
2
#
3
# Univention AD Connector
4
#  init script of ad connector password read
5
#
6
# Copyright 2004-2011 Univention GmbH
7
#
8
# http://www.univention.de/
9
#
10
# All rights reserved.
11
#
12
# The source code of this program is made available
13
# under the terms of the GNU Affero General Public License version 3
14
# (GNU AGPL V3) as published by the Free Software Foundation.
15
#
16
# Binary versions of this program provided by Univention to you as
17
# well as other copyrighted, protected or trademarked materials like
18
# Logos, graphics, fonts, specific documentations and configurations,
19
# cryptographic keys etc. are subject to a license agreement between
20
# you and Univention and not subject to the GNU AGPL V3.
21
#
22
# In the case you use this program under the terms of the GNU AGPL V3,
23
# the program is provided in the hope that it will be useful,
24
# but WITHOUT ANY WARRANTY; without even the implied warranty of
25
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26
# GNU Affero General Public License for more details.
27
#
28
# You should have received a copy of the GNU Affero General Public
29
# License with the Debian GNU/Linux or Univention distribution in file
30
# /usr/share/common-licenses/AGPL-3; if not, see
31
# <http://www.gnu.org/licenses/>.
32
33
CONFIGBASENAME="connectorpwdread"
34
ADCONNECTORPID="/var/run/univention-ad-$CONFIGBASENAME"
35
36
. /lib/lsb/init-functions
37
38
case "$1" in
39
	start)
40
		# check ucr autostart setting
41
		if [ -f "/usr/share/univention-config-registry/init-autostart.lib" ]; then
42
			source "/usr/share/univention-config-registry/init-autostart.lib"
43
			check_autostart ad-$CONFIGBASENAME $CONFIGBASENAME/ad/autostart
44
		fi	
45
		log_action_msg "Starting univention-ad-connector daemon"
46
		cat /etc/univention/${CONFIGBASENAME}/ad/mapping | univention-config-registry filter --encode-utf8 >/etc/univention/${CONFIGBASENAME}/ad/mapping.py
47
		start-stop-daemon --start --quiet --pidfile "$ADCONNECTORPID" -a /usr/sbin/univention-ad-connector-password-read -- --configbase "$CONFIGBASENAME"
48
		log_action_end_msg 0
49
		;;
50
	stop)
51
		log_action_msg "Stopping univention-ad-connector daemon"
52
		start-stop-daemon --stop --retry TERM/300/KILL --quiet --pidfile "$ADCONNECTORPID" -a /usr/sbin/univention-ad-connector-password-read
53
		log_action_end_msg 0
54
		;;
55
	restart|force-reload)
56
		$0 stop
57
		sleep 1
58
		$0 start
59
		;;
60
	crestart)
61
		ADCONNECTOR=`cat $ADCONNECTORPID 2>/dev/null`
62
		if [ -n "$ADCONNECTOR" ]; then
63
			pgrep -s "$ADCONNECTOR" -f "connector-password-read" && $0 restart
64
		    ps xaw | grep connector-password-read | grep -q "$ADCONNECTOR" >/dev/null && $0 restart
65
		fi
66
		;;
67
	*)
68
		echo "Usage: /etc/init.d/univention-ad-connector {start|stop|restart|crestart|force-reload}"
69
		exit 1
70
		;;
71
esac
72
73
(-)univention-ad-connector-password-read.orig/debian/univention-ad-connector-password-read.install (+1 lines)
Line 0    Link Here 
1
univention-ad-connector-password-read usr/sbin/
(-)univention-ad-connector-password-read.orig/debian/univention-ad-connector-password-read.postinst (+83 lines)
Line 0    Link Here 
1
#!/bin/sh
2
#
3
# Univention AD Connector
4
#  postinst script of the ad connector package
5
#
6
# Copyright 2004-2010 Univention GmbH
7
#
8
# http://www.univention.de/
9
#
10
# All rights reserved.
11
#
12
# The source code of this program is made available
13
# under the terms of the GNU Affero General Public License version 3
14
# (GNU AGPL V3) as published by the Free Software Foundation.
15
#
16
# Binary versions of this program provided by Univention to you as
17
# well as other copyrighted, protected or trademarked materials like
18
# Logos, graphics, fonts, specific documentations and configurations,
19
# cryptographic keys etc. are subject to a license agreement between
20
# you and Univention and not subject to the GNU AGPL V3.
21
#
22
# In the case you use this program under the terms of the GNU AGPL V3,
23
# the program is provided in the hope that it will be useful,
24
# but WITHOUT ANY WARRANTY; without even the implied warranty of
25
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26
# GNU Affero General Public License for more details.
27
#
28
# You should have received a copy of the GNU Affero General Public
29
# License with the Debian GNU/Linux or Univention distribution in file
30
# /usr/share/common-licenses/AGPL-3; if not, see
31
# <http://www.gnu.org/licenses/>.
32
33
eval "$(ucr shell)"
34
35
CONFIGBASENAME="connectorpwdread"
36
37
createLogfile () {
38
	if [ ! -e $1 ] ; then
39
		touch $1
40
		chown $2 $1
41
		chmod $3 $1
42
	fi
43
}
44
45
createLogfile "/var/log/univention/${CONFIGBASENAME}.log" "root:adm" 640
46
createLogfile "/var/log/univention/${CONFIGBASENAME}-status.log" "root:adm" 640
47
48
if [ "$1" = "configure" ] && [ -z "$2" ]; then
49
	if [ ! -e /etc/univention/"$CONFIGBASENAME" ]; then
50
51
		univention-config-registry set	"$CONFIGBASENAME"/ad/autostart?"$connector_ad_autostart" \
52
										"$CONFIGBASENAME"/ad/ldap/base?"$connector_ad_ldap_base" \
53
										"$CONFIGBASENAME"/ad/ldap/binddn?"$connector_ad_ldap_binddn" \
54
										"$CONFIGBASENAME"/ad/ldap/bindpw?"$connector_ad_ldap_bindpw" \
55
										"$CONFIGBASENAME"/ad/ldap/certificate?"$connector_ad_ldap_certificate" \
56
										"$CONFIGBASENAME"/ad/ldap/host?"$connector_ad_ldap_host" \
57
										"$CONFIGBASENAME"/ad/mapping/kerberosdomain?"$connector_ad_mapping_kerberosdomain" \
58
										"$CONFIGBASENAME"/ad/mapping/language?"$connector_ad_mapping_language" \
59
										"$CONFIGBASENAME"/ad/ldap/port?"$connector_ad_ldap_port" \
60
										"$CONFIGBASENAME"/ad/ldap/ssl?"$connector_ad_ldap_ssl" \
61
										"$CONFIGBASENAME"/ad/listener/dir?"/var/lib/univention-$CONFIGBASENAME/ad" \
62
										"$CONFIGBASENAME"/ad/mapping/group/language?"$connector_ad_mapping_group_language" \
63
										"$CONFIGBASENAME"/ad/mapping/group/primarymail?"$connector_ad_mapping_group_primarymail" \
64
										"$CONFIGBASENAME"/ad/mapping/group/win2000/description?false \
65
										"$CONFIGBASENAME"/ad/mapping/syncmode?read \
66
										"$CONFIGBASENAME"/ad/mapping/user/primarymail?false \
67
										"$CONFIGBASENAME"/ad/mapping/user/win2000/description?false \
68
										"$CONFIGBASENAME"/ad/poll/sleep?5 \
69
										"$CONFIGBASENAME"/ad/retryrejected?10 \
70
										"$CONFIGBASENAME"/debug/function?0 \
71
										"$CONFIGBASENAME"/debug/level?1 \
72
										"$CONFIGBASENAME"/password/service/encoding?iso8859-15
73
		
74
		mkdir -p /etc/univention/"$CONFIGBASENAME"/ad
75
		cp -a /etc/univention/connector/ad/mapping /etc/univention/"$CONFIGBASENAME"/ad/
76
		sed -i "s|@%@connector/ad/|@%@$CONFIGBASENAME/ad/|g;s|'connector/ad/|'$CONFIGBASENAME/ad/|g" /etc/univention/"$CONFIGBASENAME"/ad/mapping
77
	fi
78
    
79
fi
80
81
#DEBHELPER#
82
83
exit 0
(-)univention-ad-connector-password-read.orig/univention-ad-connector-password-read (+445 lines)
Line 0    Link Here 
1
#!/usr/bin/python2.4
2
# -*- coding: utf-8 -*-
3
#
4
# Univention AD Connector Password Sync
5
#
6
# Copyright 2004-2011 Univention GmbH
7
#
8
# http://www.univention.de/
9
#
10
# All rights reserved.
11
#
12
# The source code of this program is made available
13
# under the terms of the GNU Affero General Public License version 3
14
# (GNU AGPL V3) as published by the Free Software Foundation.
15
#
16
# Binary versions of this program provided by Univention to you as
17
# well as other copyrighted, protected or trademarked materials like
18
# Logos, graphics, fonts, specific documentations and configurations,
19
# cryptographic keys etc. are subject to a license agreement between
20
# you and Univention and not subject to the GNU AGPL V3.
21
#
22
# In the case you use this program under the terms of the GNU AGPL V3,
23
# the program is provided in the hope that it will be useful,
24
# but WITHOUT ANY WARRANTY; without even the implied warranty of
25
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26
# GNU Affero General Public License for more details.
27
#
28
# You should have received a copy of the GNU Affero General Public
29
# License with the Debian GNU/Linux or Univention distribution in file
30
# /usr/share/common-licenses/AGPL-3; if not, see
31
# <http://www.gnu.org/licenses/>.
32
33
import sys, string, os, time, signal, shutil
34
import base64, pdb, copy, types
35
from optparse import OptionParser
36
37
import ldap, traceback
38
import univention
39
import univention.connector
40
import univention.connector.ad
41
import univention.uldap
42
import univention.admin.uldap
43
import univention.admin.modules
44
import univention.admin.objects
45
import univention.debug2 as ud
46
import univention.admin.uexceptions
47
48
from univention.connector.ad import ad
49
50
import univention_baseconfig
51
52
from ldap.controls import LDAPControl
53
54
# parse commandline options
55
56
parser = OptionParser()
57
parser.add_option("--configbasename", dest="configbasename",
58
                  help="", metavar="CONFIGBASENAME", default="connector")
59
(options, args) = parser.parse_args()
60
61
CONFIGBASENAME = "connector"
62
if options.configbasename:
63
	CONFIGBASENAME = options.configbasename
64
STATUSLOGFILE = "/var/log/univention/%s-status.log" % CONFIGBASENAME
65
66
sys.path=['/etc/univention/%s/ad/' % CONFIGBASENAME]+sys.path
67
68
import mapping
69
70
def daemon():
71
	try:
72
		pid = os.fork()
73
	except OSError, e:
74
		print 'Daemon Mode Error: %s' % e.strerror
75
76
	if (pid == 0):
77
		os.setsid()
78
		signal.signal(signal.SIGHUP, signal.SIG_IGN)
79
		try:
80
			pid = os.fork()
81
		except OSError, e:
82
			print 'Daemon Mode Error: %s' % e.strerror
83
		if (pid == 0):
84
			os.chdir("/")
85
			os.umask(0)
86
		else:
87
			pf=open('/var/run/univention-ad-%s' % CONFIGBASENAME, 'w+')
88
			pf.write(str(pid))
89
			pf.close()
90
			os._exit(0)
91
	else:
92
		os._exit(0)
93
94
	try:
95
		maxfd = os.sysconf("SC_OPEN_MAX")
96
	except (AttributeError, ValueError):
97
		maxfd = 256       # default maximum
98
99
	for fd in range(0, maxfd):
100
		try:
101
			os.close(fd)
102
		except OSError:   # ERROR (ignore)
103
			pass
104
105
	os.open("/dev/null", os.O_RDONLY)
106
	os.open("/dev/null", os.O_RDWR)
107
	os.open("/dev/null", os.O_RDWR)
108
109
110
def connect():
111
112
	daemon()
113
114
	f=open(STATUSLOGFILE, 'w+')
115
	sys.stdout=f
116
	print time.ctime()
117
118
	baseConfig=univention_baseconfig.baseConfig()
119
	baseConfig.load()
120
121
	if not baseConfig.has_key('%s/ad/ldap/host' % CONFIGBASENAME):
122
		print '%s/ad/ldap/host not set' % CONFIGBASENAME
123
		f.close()
124
		sys.exit(1)
125
	if not baseConfig.has_key('%s/ad/ldap/port' % CONFIGBASENAME):
126
		print '%s/ad/ldap/port not set' % CONFIGBASENAME
127
		f.close()
128
		sys.exit(1)
129
	if not baseConfig.has_key('%s/ad/ldap/base' % CONFIGBASENAME):
130
		print '%s/ad/ldap/base not set' % CONFIGBASENAME
131
		f.close()
132
		sys.exit(1)
133
	if not baseConfig.has_key('%s/ad/ldap/binddn' % CONFIGBASENAME):
134
		print '%s/ad/ldap/binddn not set' % CONFIGBASENAME
135
		f.close()
136
		sys.exit(1)
137
	if not baseConfig.has_key('%s/ad/ldap/bindpw' % CONFIGBASENAME):
138
		print '%s/ad/ldap/bindpw not set' % CONFIGBASENAME
139
		f.close()
140
		sys.exit(1)
141
142
	if not baseConfig.has_key('%s/ad/ldap/certificate' % CONFIGBASENAME) and not (baseConfig.has_key('%s/ad/ldap/ssl' % CONFIGBASENAME) and baseConfig['%s/ad/ldap/ssl' % CONFIGBASENAME] == 'no') :
143
		print '%s/ad/ldap/certificate not set' % CONFIGBASENAME
144
		f.close()
145
		sys.exit(1)
146
147
	if baseConfig.is_true('%s/ad/ldap/ssl' % CONFIGBASENAME, True) or baseConfig.is_true('%s/ad/ldap/ldaps' % CONFIGBASENAME, False):
148
		# create a new CAcert file, which contains the UCS CA and the AD CA,
149
		# see Bug #17768 for details
150
		#  https://forge.univention.org/bugzilla/show_bug.cgi?id=17768
151
		new_ca_filename = '/var/cache/univention-ad-connector/CAcert-%s.pem' % CONFIGBASENAME
152
		new_ca = open(new_ca_filename, 'w')
153
154
		ca = open('/etc/univention/ssl/ucsCA/CAcert.pem', 'r')
155
		new_ca.write(string.join(ca.readlines(),''))
156
		ca.close()
157
158
		ca = open(baseConfig['%s/ad/ldap/certificate' % CONFIGBASENAME])
159
		new_ca.write(string.join(ca.readlines(),''))
160
		ca.close()
161
162
		new_ca.close()
163
		
164
		ldap.set_option( ldap.OPT_X_TLS_CACERTFILE, new_ca_filename )
165
	
166
167
	if not baseConfig.has_key('%s/ad/listener/dir' % CONFIGBASENAME):
168
		print '%s/ad/listener/dir not set' % CONFIGBASENAME
169
		f.close()
170
		sys.exit(1)
171
172
	if not baseConfig.has_key('%s/ad/retryrejected' % CONFIGBASENAME):
173
		baseconfig_retry_rejected=10
174
	else:
175
		baseconfig_retry_rejected=baseConfig['%s/ad/retryrejected' % CONFIGBASENAME]
176
177
	ad_ldap_bindpw=open(baseConfig['%s/ad/ldap/bindpw' % CONFIGBASENAME]).read()
178
	if ad_ldap_bindpw[-1] == '\n':
179
		ad_ldap_bindpw=ad_ldap_bindpw[0:-1]
180
	
181
	poll_sleep=int(baseConfig['%s/ad/poll/sleep' % CONFIGBASENAME])
182
	ad_init=None
183
	while not ad_init:
184
		try:
185
			ad_pwd=adpwd(	CONFIGBASENAME,
186
						mapping.ad_mapping,
187
						baseConfig,
188
						baseConfig['%s/ad/ldap/host' % CONFIGBASENAME],
189
						baseConfig['%s/ad/ldap/port' % CONFIGBASENAME],
190
						baseConfig['%s/ad/ldap/base' % CONFIGBASENAME],
191
						baseConfig['%s/ad/ldap/binddn' % CONFIGBASENAME],
192
						ad_ldap_bindpw,
193
						baseConfig['%s/ad/ldap/certificate' % CONFIGBASENAME],
194
						baseConfig['%s/ad/listener/dir' % CONFIGBASENAME])
195
			ad_init=True
196
		except ldap.SERVER_DOWN:
197
			print "Warning: Can't initialize LDAP-Connections, wait..."
198
			sys.stdout.flush()
199
			time.sleep(poll_sleep)
200
			pass
201
202
203
	ad_init=None
204
205
	while not ad_init:
206
		try:
207
			ad_pwd.initialize()
208
			ad_init=True
209
		except ldap.SERVER_DOWN:
210
			time.sleep(poll_sleep)
211
			pass
212
213
	f.close()
214
	retry_rejected=0
215
	connected = True
216
	while connected:
217
		f=open(STATUSLOGFILE, 'w+')
218
		sys.stdout=f
219
		print time.ctime()
220
		# Poll for changes
221
		change_counter=1
222
		while change_counter != 0:
223
			sys.stdout.flush()
224
			try:
225
				change_counter=ad_pwd.poll()
226
			except ldap.SERVER_DOWN:
227
				print "Can't contact LDAP server during ad-poll, sync not possible."
228
				connected = False
229
 				sys.stdout.flush()
230
				time.sleep(poll_sleep)
231
232
			if change_counter > 0:
233
				retry_rejected=0
234
235
		if str(retry_rejected) == baseconfig_retry_rejected:
236
			ad_pwd.ad.resync_rejected()
237
			retry_rejected=0
238
		else:
239
			retry_rejected+=1
240
241
		print '- sleep %s seconds (%s/%s until resync) -'%(poll_sleep, retry_rejected, baseconfig_retry_rejected)
242
		sys.stdout.flush()
243
		time.sleep(poll_sleep)
244
		f.close()
245
	ad_pwd.ad.close_debug()
246
247
class adpwd:
248
	def __init__(self, CONFIGBASENAME, property, baseConfig, ad_ldap_host, ad_ldap_port, ad_ldap_base, ad_ldap_binddn, ad_ldap_bindpw, ad_ldap_certificate, listener_dir):
249
		self.ad = ad(CONFIGBASENAME, property, baseConfig, ad_ldap_host, ad_ldap_port, ad_ldap_base, ad_ldap_binddn, ad_ldap_bindpw, ad_ldap_certificate, listener_dir)
250
251
		bindpw=open('/etc/ldap.secret').read()
252
		if bindpw[-1] == '\n':
253
			bindpw=bindpw[0:-1]
254
255
		self.ad.lo=univention.admin.uldap.access(host=baseConfig['ldap/master'], base=baseConfig['ldap/base'], binddn='cn=admin,'+baseConfig['ldap/base'], bindpw=bindpw, start_tls=2)
256
257
		# load UCS Modules
258
		self.ad.modules={}
259
		for key in self.ad.property.keys():
260
			if self.ad.property[key].ucs_module:
261
				self.ad.modules[key]=univention.admin.modules.get(self.ad.property[key].ucs_module)
262
			else:
263
				self.ad.modules[key]=None
264
265
	def initialize(self):
266
		_d=ud.function('ldap.initialize')
267
268
269
		print "--------------------------------------"
270
		print "Initialize sync from AD"
271
		self.ad.resync_rejected()
272
		if self.ad._get_lastUSN() == 0: # we startup new
273
			ud.debug(ud.LDAP, ud.INFO, "initialize AD: last USN is 0, sync all")
274
			# query highest USN in LDAP
275
			highestCommittedUSN = self.ad._ad__get_highestCommittedUSN()
276
277
			# poll for all objects without deleted objects
278
			polled=self.poll(show_deleted=False)
279
280
			# compare highest USN from poll with highest before poll, if the last changes deletes
281
			# the highest USN from poll is to low
282
			self.ad._set_lastUSN(max(highestCommittedUSN,self._get_lastUSN()))
283
			ud.debug(ud.LDAP, ud.INFO, "initialize AD: sync of all objects finished, lastUSN is %d", self.ad._ad__get_highestCommittedUSN())
284
		else:
285
			polled=self.poll()		
286
		print "--------------------------------------"
287
288
	def poll(self, show_deleted=True):
289
		'''
290
		poll for changes in AD
291
		'''
292
		_d=ud.function('ldap.poll')
293
		# search from last_usn for changes
294
		change_count = 0
295
		changes = []
296
		try:
297
			# call private methode
298
			changes = self.ad._ad__search_ad_changes(show_deleted=show_deleted)
299
		except (ldap.SERVER_DOWN, SystemExit):
300
			raise		
301
		except: # FIXME: which exception is to be caught?
302
			self._debug_traceback(ud.WARN,"Exception during search_ad_changes")
303
304
		print "--------------------------------------"
305
		print "try to sync %s changes from AD" % len(changes)
306
		print "done:",
307
		sys.stdout.flush()
308
		done_counter = 0
309
		object = None
310
311
		for element in changes:
312
			try:
313
				if element[0] == 'None': # referrals
314
					continue
315
				old_element = copy.deepcopy(element)
316
				object = self.ad._ad__object_from_element(element)
317
			except: # FIXME: which exception is to be caught?
318
				#ud.debug(ud.LDAP, ud.ERROR, "Exception during poll/object-mapping, tried to map element: %s" % old_element[0])
319
				#ud.debug(ud.LDAP, ud.ERROR, "This object will not be synced again!")
320
				# debug-trace may lead to a segfault here :(
321
				self._debug_traceback(ud.ERROR,"Exception during poll/object-mapping, object will not be synced again!")
322
				
323
			if object:
324
				property_key = self.ad._ad__identify(object)
325
				if property_key:
326
					
327
					if self.ad._ignore_object(property_key,object):
328
						# call private methode
329
						self.ad._ad__update_lastUSN(object)
330
						done_counter += 1
331
						print "%s"%done_counter,
332
						continue
333
334
					sync_successfull = False
335
					try:
336
						ud.debug(ud.LDAP, ud.INFO, "Sync object (%s) property_key: %s" % (object['dn'], property_key))
337
						if property_key == 'user' and object['modtype'] == 'modify':
338
							if not self.ad._ignore_object(property_key,object):
339
								property_ucs = self.ad._ad__identify(object)
340
								object_ucs = self.ad._object_mapping(property_key,object)
341
342
								try:
343
									univention.connector.ad.password.password_sync(self.ad, property_key, object_ucs)
344
								except univention.admin.uexceptions.noObject:
345
									# This is possible if the user does not exist in UCS (the main AD connector is in write mode)
346
									ud.debug(ud.LDAP, ud.INFO, "Object (%s) was not found in UCS (ignore)" % (object['dn']))
347
									pass
348
								sync_successfull = True
349
							else:
350
								sync_successfull = True
351
						else:
352
							sync_successfull = True
353
					except (ldap.SERVER_DOWN, SystemExit):
354
						raise
355
					except univention.admin.uexceptions.ldapError, msg:
356
						ud.debug(ud.LDAP, ud.INFO, "Exception during poll with message (1) %s"%msg)
357
						if msg == "Can't contact LDAP server":
358
							raise ldap.SERVER_DOWN
359
						else:
360
							self._debug_traceback(ud.WARN,"Exception during poll/sync_to_ucs")
361
					except univention.admin.uexceptions.ldapError, msg:
362
						ud.debug(ud.LDAP, ud.INFO, "Exception during poll with message (2) %s"%msg)
363
						if msg == "Can't contact LDAP server":
364
							raise ldap.SERVER_DOWN
365
						else:
366
							self._debug_traceback(ud.WARN,"Exception during poll")
367
					except: # FIXME: which exception is to be caught?
368
						self.ad._debug_traceback(ud.WARN, "Exception during poll/sync_to_ucs")
369
370
371
372
					if not sync_successfull:
373
						ud.debug(ud.LDAP, ud.WARN,
374
											   "sync to ucs was not successfull, save rejected")
375
						ud.debug(ud.LDAP, ud.WARN,
376
											   "object was: %s"%object['dn'])
377
378
					if sync_successfull:
379
						change_count+=1
380
						# call private methode
381
						self.ad._ad__update_lastUSN(object)
382
						try:
383
							GUID = old_element[1]['objectGUID'][0]
384
							self.ad._set_DN_for_GUID(GUID,old_element[0])
385
						except (ldap.SERVER_DOWN, SystemExit):
386
							raise
387
						except: # FIXME: which exception is to be caught?
388
							self._debug_traceback(ud.WARN,
389
									      "Exception during set_DN_for_GUID")
390
391
					else:
392
						self.ad.save_rejected(object)
393
				else:
394
					# call private methode
395
					self.ad._ad__update_lastUSN(object)
396
397
				done_counter += 1
398
				print "%s"%done_counter,
399
			else:
400
				done_counter += 1
401
				print "(%s)"%done_counter,
402
			sys.stdout.flush()
403
				
404
		print ""
405
406
		# return number of synced objects
407
		rejected = self.ad._list_rejected()
408
		if rejected:
409
			print "Changes from AD:  %s (%s saved rejected)" % (change_count, len(rejected))
410
		else:
411
			print "Changes from AD:  %s (%s saved rejected)" % (change_count, '0')
412
		print "--------------------------------------"
413
		sys.stdout.flush()
414
		return change_count
415
416
417
def main():
418
	while True:
419
		try:
420
			connect()
421
		except SystemExit:
422
			raise
423
		except:
424
			f=open(STATUSLOGFILE, 'w+')
425
			sys.stdout=f
426
			print time.ctime()
427
			
428
			text = ''
429
			exc_info = sys.exc_info()
430
			lines = apply(traceback.format_exception, exc_info)
431
			text = text + '\n'
432
			for line in lines:
433
				text += line
434
			print " --- connect failed, failure was: ---"
435
			print text
436
			print " ---     retry in 30 seconds      ---"
437
			sys.stdout.flush()
438
			time.sleep(30)
439
440
			f.close()
441
442
443
if __name__ == "__main__":
444
	main()
445

Return to bug 22653