summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2013-04-29 15:30:39 +0200
committerJeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com>2013-05-04 13:49:07 +0100
commit507515dd994483b997a49dc0208680108f560510 (patch)
tree2682b0a5b127fa47be18d1831245e6583fc31837
parent6a7a997f1984dca045113aed4995606ce1b128ec (diff)
downloadpykolab-507515dd994483b997a49dc0208680108f560510.tar.gz
Handle objectSid binary blobs to be a unique_attribute attribute name
-rw-r--r--pykolab/utils.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/pykolab/utils.py b/pykolab/utils.py
index 2ba5c89..57617a7 100644
--- a/pykolab/utils.py
+++ b/pykolab/utils.py
@@ -21,6 +21,7 @@ import getpass
import grp
import os
import pwd
+import struct
import sys
import pykolab
@@ -271,16 +272,22 @@ def normalize(_object):
if type(_object[key]) == list:
if _object[key] == None:
continue
+
if len(_object[key]) == 1:
result[key.lower()] = ''.join(_object[key])
else:
result[key.lower()] = _object[key]
+
else:
if _object[key] == None:
continue
+
# What the heck?
result[key.lower()] = _object[key]
+ if result.has_key('objectsid') and not result['objectsid'][0] == "S":
+ result['objectsid'] = sid_to_string(result['objectsid'])
+
if result.has_key('sn'):
result['surname'] = result['sn'].replace(' ', '')
@@ -385,6 +392,24 @@ def pop_empty_from_list(_input_list):
if not item == '':
_output_list.append(item)
+def sid_to_string(sid):
+ srl = ord(sid[0])
+ number_sub_id = ord(sid[1])
+ iav = struct.unpack('!Q', '\x00\x00' + sid[2:8])[0]
+
+ sub_ids = []
+
+ for i in range(number_sub_id):
+ sub_ids.append(struct.unpack('<I',sid[8+4*i:12+4*i])[0])
+
+ result = 'S-%d-%d-%s' % (
+ srl,
+ iav,
+ '-'.join([str(s) for s in sub_ids]),
+ )
+
+ return result
+
def standard_root_dn(domain):
return 'dc=%s' % (',dc='.join(domain.split('.')))