|
|
|
1 |
#!/usr/bin/python2.6 |
2 |
# -*- coding: utf-8 -*- |
3 |
# |
4 |
# Univention S4 Connector |
5 |
# groupType |
6 |
# |
7 |
# Copyright 2013 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 univention.debug2 as ud |
35 |
|
36 |
S4_GROUP_GLOBAL="-2147483646" |
37 |
S4_GROUP_LOCAL="-2147483644" |
38 |
S4_GROUP_BUILTIN="-2147483643" |
39 |
S4_GROUP_UNIVERSAL="-2147483640" |
40 |
|
41 |
UCS_GROUP_DOMAIN='2' |
42 |
UCS_GROUP_LOCAL='3' |
43 |
UCS_GROUP_WELLL_KNOWN='5' |
44 |
|
45 |
UCS_GROUPS = [ UCS_GROUP_DOMAIN, UCS_GROUP_LOCAL, UCS_GROUP_WELLL_KNOWN ] |
46 |
|
47 |
GROUP_LIST_GLOBAL = [ S4_GROUP_GLOBAL, S4_GROUP_UNIVERSAL, UCS_GROUP_DOMAIN ] |
48 |
GROUP_LIST_LOCAL = [ S4_GROUP_LOCAL, UCS_GROUP_LOCAL ] |
49 |
GROUP_LIST_BUILTIN = [ S4_GROUP_BUILTIN, UCS_GROUP_WELLL_KNOWN ] |
50 |
|
51 |
def _is_list(val): |
52 |
return isinstance(val, list) |
53 |
|
54 |
def compare(group_type1, group_type2): |
55 |
if _is_list(group_type1): |
56 |
group_type1 = group_type1[0] |
57 |
if _is_list(group_type2): |
58 |
group_type2 = group_type2[0] |
59 |
|
60 |
if group_type1 in GROUP_LIST_GLOBAL and group_type2 in GROUP_LIST_GLOBAL: |
61 |
return True |
62 |
if group_type1 in GROUP_LIST_LOCAL and group_type2 in GROUP_LIST_LOCAL: |
63 |
return True |
64 |
if group_type1 in GROUP_LIST_BUILTIN and group_type2 in GROUP_LIST_BUILTIN: |
65 |
return True |
66 |
|
67 |
return False |
68 |
|
69 |
def s4_to_ucs_mapping(s4connector, key, s4_object): |
70 |
ud.debug(ud.LDAP, ud.INFO, 'group_type: s4_to_ucs_mapping') |
71 |
|
72 |
# check if the UCS object already exists and don't change the |
73 |
# group type in this case |
74 |
ucs_object = s4connector.get_ucs_ldap_object(s4_object['dn']) |
75 |
if ucs_object: |
76 |
ud.debug(ud.LDAP, ud.INFO, 'group_type: object exists already, use the old sambaGroupType') |
77 |
return ucs_object.get('sambaGroupType') |
78 |
|
79 |
group_type = s4_object['attributes']['groupType'][0] |
80 |
ud.debug(ud.LDAP, ud.INFO, 'group_type: sid type: %s' % group_type) |
81 |
|
82 |
if group_type in [S4_GROUP_GLOBAL, S4_GROUP_UNIVERSAL]: |
83 |
return [UCS_GROUP_DOMAIN] |
84 |
if group_type == S4_GROUP_LOCAL: |
85 |
return [UCS_GROUP_LOCAL] |
86 |
if group_type == S4_GROUP_BUILTIN: |
87 |
return [UCS_GROUP_WELLL_KNOWN] |
88 |
|
89 |
# Use the default |
90 |
return [UCS_GROUP_DOMAIN] |
91 |
|
92 |
def ucs_to_s4_mapping(s4connector, key, ucs_object): |
93 |
ud.debug(ud.LDAP, ud.INFO, 'group_type: ucs_to_s4_mapping') |
94 |
|
95 |
group_type = ucs_object['attributes'].get('sambaGroupType', [])[0] |
96 |
ud.debug(ud.LDAP, ud.INFO, 'group_type: ucs type: %s' % group_type) |
97 |
|
98 |
# It is not possible to create a local or builtin group |
99 |
return [S4_GROUP_GLOBAL] |
100 |
|
101 |
#if group_type == UCS_GROUP_DOMAIN: |
102 |
# return [S4_GROUP_GLOBAL] |
103 |
#if group_type == UCS_GROUP_LOCAL: |
104 |
# return [S4_GROUP_LOCAL] |
105 |
#if group_type == UCS_GROUP_WELLL_KNOWN: |
106 |
# return [S4_GROUP_BUILTIN] |
107 |
# |
108 |
#return [S4_GROUP_GLOBAL] |