r20407: the oMObjectClass values are not padded to 10 bytes!
[kai/samba-autobuild/.git] / source4 / dsdb / schema / schema_syntax.c
1 /* 
2    Unix SMB/CIFS mplementation.
3    DSDB schema syntaxes
4    
5    Copyright (C) Stefan Metzmacher 2006
6     
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (at your option) any later version.
11    
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16    
17    You should have received a copy of the GNU General Public License
18    along with this program; if not, write to the Free Software
19    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20    
21 */
22 #include "includes.h"
23 #include "dsdb/samdb/samdb.h"
24
25 #define OMOBJECTCLASS(val) { .length = sizeof(val) - 1, .data = discard_const_p(uint8_t, val) }
26
27 static const struct dsdb_syntax dsdb_syntaxes[] = {
28         {
29                 .name                   = "Boolean",
30                 .ldap_oid               = "1.3.6.1.4.1.1466.115.121.1.7",
31                 .oMSyntax               = 1,
32                 .attributeSyntax_oid    = "2.5.5.8",
33         },{
34                 .name                   = "Integer",
35                 .ldap_oid               = "1.3.6.1.4.1.1466.115.121.1.27",
36                 .oMSyntax               = 2,
37                 .attributeSyntax_oid    = "2.5.5.9",
38         },{
39                 .name                   = "String(Octet)",
40                 .ldap_oid               = "1.3.6.1.4.1.1466.115.121.1.40",
41                 .oMSyntax               = 4,
42                 .attributeSyntax_oid    = "2.5.5.10",
43         },{
44                 .name                   = "String(Sid)",
45                 .ldap_oid               = "1.3.6.1.4.1.1466.115.121.1.40",
46                 .oMSyntax               = 4,
47                 .attributeSyntax_oid    = "2.5.5.17",
48         },{
49                 .name                   = "String(Object-Identifier)",
50                 .ldap_oid               = "1.3.6.1.4.1.1466.115.121.1.38",
51                 .oMSyntax               = 6,
52                 .attributeSyntax_oid    = "2.5.5.2",
53         },{
54                 .name                   = "Enumeration",
55                 .ldap_oid               = "1.3.6.1.4.1.1466.115.121.1.27",
56                 .oMSyntax               = 10,
57                 .attributeSyntax_oid    = "2.5.5.9",
58         },{
59                 .name                   = "String(Numeric)",
60                 .ldap_oid               = "1.3.6.1.4.1.1466.115.121.1.36",
61                 .oMSyntax               = 18,
62                 .attributeSyntax_oid    = "2.5.5.6",
63         },{
64                 .name                   = "String(Printable)",
65                 .ldap_oid               = "1.3.6.1.4.1.1466.115.121.1.44",
66                 .oMSyntax               = 19,
67                 .attributeSyntax_oid    = "2.5.5.5",
68         },{
69                 .name                   = "String(Teletex)",
70                 .ldap_oid               = "1.2.840.113556.1.4.905",
71                 .oMSyntax               = 20,
72                 .attributeSyntax_oid    = "2.5.5.4",
73         },{
74                 .name                   = "String(IA5)",
75                 .ldap_oid               = "1.3.6.1.4.1.1466.115.121.1.26",
76                 .oMSyntax               = 22,
77                 .attributeSyntax_oid    = "2.5.5.5",
78         },{
79                 .name                   = "String(UTC-Time)",
80                 .ldap_oid               = "1.3.6.1.4.1.1466.115.121.1.53",
81                 .oMSyntax               = 23,
82                 .attributeSyntax_oid    = "2.5.5.11",
83         },{
84                 .name                   = "String(Generalized-Time)",
85                 .ldap_oid               = "1.3.6.1.4.1.1466.115.121.1.24",
86                 .oMSyntax               = 24,
87                 .attributeSyntax_oid    = "2.5.5.11",
88         },{
89                 .name                   = "String(Case Sensitive)",
90                 .ldap_oid               = "1.2.840.113556.1.4.1362",
91                 .oMSyntax               = 27,
92                 .attributeSyntax_oid    = "2.5.5.3",
93         },{
94                 .name                   = "String(Unicode)",
95                 .ldap_oid               = "1.3.6.1.4.1.1466.115.121.1.15",
96                 .oMSyntax               = 64,
97                 .attributeSyntax_oid    = "2.5.5.12",
98         },{
99                 .name                   = "Interval/LargeInteger",
100                 .ldap_oid               = "1.2.840.113556.1.4.906",
101                 .oMSyntax               = 65,
102                 .attributeSyntax_oid    = "2.5.5.16",
103         },{
104                 .name                   = "String(NT-Sec-Desc)",
105                 .ldap_oid               = "1.2.840.113556.1.4.907",
106                 .oMSyntax               = 66,
107                 .attributeSyntax_oid    = "2.5.5.15",
108         },{
109                 .name                   = "Object(DS-DN)",
110                 .ldap_oid               = "1.3.6.1.4.1.1466.115.121.1.12",
111                 .oMSyntax               = 127,
112                 .oMObjectClass          = OMOBJECTCLASS("\x2b\x0c\x02\x87\x73\x1c\x00\x85\x4a"),
113                 .attributeSyntax_oid    = "2.5.5.1",
114         },{
115                 .name                   = "Object(DN-Binary)",
116                 .ldap_oid               = "1.2.840.113556.1.4.903",
117                 .oMSyntax               = 127,
118                 .oMObjectClass          = OMOBJECTCLASS("\x2a\x86\x48\x86\xf7\x14\x01\x01\x01\x0b"),
119                 .attributeSyntax_oid    = "2.5.5.7",
120         },{
121                 .name                   = "Object(OR-Name)",
122                 .ldap_oid               = "1.2.840.113556.1.4.1221",
123                 .oMSyntax               = 127,
124                 .oMObjectClass          = OMOBJECTCLASS("\x56\x06\x01\x02\x05\x0b\x1D"),
125                 .attributeSyntax_oid    = "2.5.5.7",
126         },{
127                 .name                   = "Object(Replica-Link)",
128                 .ldap_oid               = "1.3.6.1.4.1.1466.115.121.1.40",
129                 .oMSyntax               = 127,
130                 .oMObjectClass          = OMOBJECTCLASS("\x2a\x86\x48\x86\xf7\x14\x01\x01\x01\x06"),
131                 .attributeSyntax_oid    = "2.5.5.10",
132         },{
133                 .ldap_oid               = "1.3.6.1.4.1.1466.115.121.1.43",
134                 .oMSyntax               = 127,
135                 .oMObjectClass          = OMOBJECTCLASS("\x2b\x0c\x02\x87\x73\x1c\x00\x85\x5c"),
136                 .attributeSyntax_oid    = "2.5.5.13",
137                 .name                   = "Object(Presentation-Address)",
138         },{
139                 .name                   = "Object(Access-Point)",
140                 .ldap_oid               = "1.3.6.1.4.1.1466.115.121.1.2",
141                 .oMSyntax               = 127,
142                 .oMObjectClass          = OMOBJECTCLASS("\x2b\x0c\x02\x87\x73\x1c\x00\x85\x3e"),
143                 .attributeSyntax_oid    = "2.5.5.14",
144         },{
145                 .name                   = "Object(DN-String)",
146                 .ldap_oid               = "1.2.840.113556.1.4.904",
147                 .oMSyntax               = 127,
148                 .oMObjectClass          = OMOBJECTCLASS("\x2a\x86\x48\x86\xf7\x14\x01\x01\x01\x0c"),
149                 .attributeSyntax_oid    = "2.5.5.14",
150         }
151 };
152
153 const struct dsdb_syntax *dsdb_syntax_for_attribute(const struct dsdb_attribute *attr)
154 {
155         uint32_t i;
156
157         for (i=0; i < ARRAY_SIZE(dsdb_syntaxes); i++) {
158                 if (attr->oMSyntax != dsdb_syntaxes[i].oMSyntax) continue;
159
160                 if (attr->oMObjectClass.length != dsdb_syntaxes[i].oMObjectClass.length) continue;
161
162                 if (attr->oMObjectClass.length) {
163                         int ret;
164                         ret = memcmp(attr->oMObjectClass.data,
165                                      dsdb_syntaxes[i].oMObjectClass.data,
166                                      attr->oMObjectClass.length);
167                         if (ret != 0) continue;
168                 }
169
170                 if (strcmp(attr->attributeSyntax_oid, dsdb_syntaxes[i].attributeSyntax_oid) != 0) continue;
171
172                 return &dsdb_syntaxes[i];
173         }
174
175         return NULL;
176 }