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

Collapse All | Expand All

(-)modules/univention/s4connector/__init__.py (-3 / +6 lines)
 Lines 31-37    Link Here 
31
# /usr/share/common-licenses/AGPL-3; if not, see
31
# /usr/share/common-licenses/AGPL-3; if not, see
32
# <http://www.gnu.org/licenses/>.
32
# <http://www.gnu.org/licenses/>.
33
33
34
import sys, codecs, base64, string, os, cPickle, types, random, traceback, copy, time
34
import sys, codecs, string, os, cPickle, types, random, traceback, copy, time
35
import ldap
35
import ldap
36
import pdb
36
import pdb
37
import univention_baseconfig
37
import univention_baseconfig
 Lines 41-46    Link Here 
41
import univention.admin.objects
41
import univention.admin.objects
42
import univention.debug2 as ud
42
import univention.debug2 as ud
43
import base64
43
import base64
44
from samba.ndr import ndr_unpack
45
from samba.dcerpc import misc
44
from signal import *
46
from signal import *
45
term_signal_caught = False
47
term_signal_caught = False
46
48
 Lines 623-629    Link Here 
623
		print traceback with ud.debug, level is i.e. ud.INFO
625
		print traceback with ud.debug, level is i.e. ud.INFO
624
		'''
626
		'''
625
		_d=ud.function('ldap._debug_traceback')
627
		_d=ud.function('ldap._debug_traceback')
626
		exc_info = sys.exc_info()
627
628
628
		ud.debug(ud.LDAP, level, text)
629
		ud.debug(ud.LDAP, level, text)
629
		ud.debug(ud.LDAP, level, traceback.format_exc())
630
		ud.debug(ud.LDAP, level, traceback.format_exc())
 Lines 1329-1335    Link Here 
1329
				pass
1330
				pass
1330
1331
1331
		try:
1332
		try:
1332
			guid = original_object.get('attributes').get('objectGUID')[0]
1333
			guid_unicode = original_object.get('attributes').get('objectGUID')[0]
1334
			guid_blob = guid_unicode.encode('ISO-8859-1')	## to compensate for __object_from_element
1335
			guid = str(ndr_unpack(misc.GUID, guid_blob))
1333
1336
1334
			object['changed_attributes'] = []
1337
			object['changed_attributes'] = []
1335
			if object['modtype'] == 'modify' and original_object:
1338
			if object['modtype'] == 'modify' and original_object:
(-)modules/univention/s4connector/s4/__init__.py (-1 / +1 lines)
 Lines 32-38    Link Here 
32
# <http://www.gnu.org/licenses/>.
32
# <http://www.gnu.org/licenses/>.
33
33
34
34
35
import string, ldap, sys, traceback, base64, time, pdb, os, copy, types
35
import string, ldap, sys, base64, time, pdb, os, copy, types
36
import array
36
import array
37
import univention.uldap
37
import univention.uldap
38
import univention.s4connector
38
import univention.s4connector
(-)modules/univention/s4connector/s4cache.py (-47 / +7 lines)
 Lines 41-62    Link Here 
41
def func_name():
41
def func_name():
42
	return inspect.currentframe().f_back.f_code.co_name
42
	return inspect.currentframe().f_back.f_code.co_name
43
43
44
def _is_base64(val):
45
	try:
46
		# It is not sufficient to run base64.decodestring to detect a base64 string.
47
		# When the ascii decode is not possible, it is not a base4 string.
48
		val.decode('ascii')
49
	except UnicodeDecodeError:
50
		return False
51
	try:
52
		# The string must be casted as str otherwise we saw something like this:
53
		#	11.02.2014 03:53:44,141 LDAP        (INFO): _is_base64 returns True for: Í8^Ml%'<U+0097>A²ôâ/! ^RÃ
54
		#	11.02.2014 03:53:44,142 LDAP        (WARNING): S4Cache: sqlite: near "<U+0097>A²ôâ": syntax error. SQL command was: [u"SELECT id FROM GUIDS WHERE guid='\xcd8\rl%'\x97A\xb2\xf4\xe2/! \x12\xc3';"
55
		base64.decodestring(str(val))
56
		return True
57
	except binascii.Error:
58
		return False
59
60
def _decode_base64(val):
44
def _decode_base64(val):
61
	return base64.decodestring(val)
45
	return base64.decodestring(val)
62
46
 Lines 63-86    Link Here 
63
def _encode_base64(val):
47
def _encode_base64(val):
64
	return base64.encodestring(val)
48
	return base64.encodestring(val)
65
49
66
def _encode_guid(guid):
67
	# guid may be unicode
68
69
	if _is_base64(guid):
70
		return guid
71
72
	if type(guid) == type(u''):
73
		return guid.encode('ISO-8859-1').encode('base64')
74
	else:
75
		return unicode(guid,'latin').encode('ISO-8859-1').encode('base64')
76
77
def _decode_guid(guid):
78
	try:
79
		return base64.decodestring(guid)
80
	except binascii.Error:
81
		return guid
82
83
84
class EntryDiff(object):
50
class EntryDiff(object):
85
	def __init__(self, old, new):
51
	def __init__(self, old, new):
86
		self.old = old
52
		self.old = old
 Lines 121-128    Link Here 
121
	def add_entry(self, guid, entry):
87
	def add_entry(self, guid, entry):
122
		_d = ud.function('S4Cache.%s' % func_name())
88
		_d = ud.function('S4Cache.%s' % func_name())
123
89
124
		guid = _encode_guid(guid).strip()
125
126
		if not self._guid_exists(guid):
90
		if not self._guid_exists(guid):
127
			self._add_entry(guid, entry)
91
			self._add_entry(guid, entry)
128
		else:
92
		else:
 Lines 148-155    Link Here 
148
112
149
		entry = {}
113
		entry = {}
150
114
151
		guid = _encode_guid(guid)
152
153
		guid_id = self._get_guid_id(guid)
115
		guid_id = self._get_guid_id(guid)
154
116
155
		if not guid_id:
117
		if not guid_id:
 Lines 157-163    Link Here 
157
119
158
		sql_commands = [
120
		sql_commands = [
159
			"SELECT ATTRIBUTES.attribute,data.value from data \
121
			"SELECT ATTRIBUTES.attribute,data.value from data \
160
					inner join ATTRIBUTES ON data.attribute_id=attributes.id where guid_id = %s;" % (guid_id)
122
					inner join ATTRIBUTES ON data.attribute_id=attributes.id where guid_id = %s;" % (guid_id,)
161
		]
123
		]
162
124
163
		rows = self.__execute_sql_commands(sql_commands, fetch_result=True)
125
		rows = self.__execute_sql_commands(sql_commands, fetch_result=True)
 Lines 175-182    Link Here 
175
	def remove_entry(self, guid):
137
	def remove_entry(self, guid):
176
		_d = ud.function('S4Cache.%s' % func_name())
138
		_d = ud.function('S4Cache.%s' % func_name())
177
139
178
		guid = _encode_guid(guid)
179
180
		guid_id = self._get_guid_id(guid)
140
		guid_id = self._get_guid_id(guid)
181
141
182
		if not guid_id:
142
		if not guid_id:
 Lines 183-190    Link Here 
183
			return None
143
			return None
184
144
185
		sql_commands = [
145
		sql_commands = [
186
			"DELETE FROM data WHERE guid_id = '%(guid_id)s';" % ({'guid_id': guid_id}),
146
			"DELETE FROM data WHERE guid_id = '%(guid_id)s';" % {'guid_id': guid_id},
187
			"DELETE FROM guids WHERE id = '%(guid_id)s';" % ({'guid_id': guid_id})
147
			"DELETE FROM guids WHERE id = '%(guid_id)s';" % {'guid_id': guid_id}
188
		]
148
		]
189
149
190
		self.__execute_sql_commands(sql_commands, fetch_result=False)
150
		self.__execute_sql_commands(sql_commands, fetch_result=False)
 Lines 237-243    Link Here 
237
		_d = ud.function('S4Cache.%s' % func_name())
197
		_d = ud.function('S4Cache.%s' % func_name())
238
198
239
		sql_commands = [
199
		sql_commands = [
240
			"SELECT id FROM GUIDS WHERE guid='%s';" % (_encode_guid(guid).strip())
200
			"SELECT id FROM GUIDS WHERE guid='%s';" % (guid,)
241
		]
201
		]
242
202
243
		rows = self.__execute_sql_commands(sql_commands, fetch_result=True)
203
		rows = self.__execute_sql_commands(sql_commands, fetch_result=True)
 Lines 252-258    Link Here 
252
		_d = ud.function('S4Cache.%s' % func_name())
212
		_d = ud.function('S4Cache.%s' % func_name())
253
213
254
		sql_commands = [
214
		sql_commands = [
255
			"INSERT INTO GUIDS(guid) VALUES('%s');" % (_encode_guid(guid).strip())
215
			"INSERT INTO GUIDS(guid) VALUES('%s');" % (guid,)
256
		]
216
		]
257
217
258
		rows = self.__execute_sql_commands(sql_commands, fetch_result=False)
218
		rows = self.__execute_sql_commands(sql_commands, fetch_result=False)
 Lines 262-268    Link Here 
262
		_d = ud.function('S4Cache.%s' % func_name())
222
		_d = ud.function('S4Cache.%s' % func_name())
263
223
264
		sql_commands = [
224
		sql_commands = [
265
			"SELECT id FROM ATTRIBUTES WHERE attribute='%s';" % (attr)
225
			"SELECT id FROM ATTRIBUTES WHERE attribute='%s';" % (attr,)
266
		]
226
		]
267
227
268
		rows = self.__execute_sql_commands(sql_commands, fetch_result=True)
228
		rows = self.__execute_sql_commands(sql_commands, fetch_result=True)
 Lines 282-288    Link Here 
282
		_d = ud.function('S4Cache.%s' % func_name())
242
		_d = ud.function('S4Cache.%s' % func_name())
283
243
284
		sql_commands = [
244
		sql_commands = [
285
			"INSERT INTO ATTRIBUTES(attribute) VALUES('%s');" % (attr)
245
			"INSERT INTO ATTRIBUTES(attribute) VALUES('%s');" % (attr,)
286
		]
246
		]
287
247
288
		self.__execute_sql_commands(sql_commands, fetch_result=False)
248
		self.__execute_sql_commands(sql_commands, fetch_result=False)

Return to bug 33621