2 Unix SMB/CIFS mplementation.
5 Copyright (C) Stefan Metzmacher 2006
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.
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.
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.
24 #include "dsdb/samdb/samdb.h"
25 #include "lib/util/dlinklist.h"
27 #define _PREFIX(uint32, oid) {uint32,oid,sizeof(oid)}
32 } prefix_mappings[] = {
33 _PREFIX(0x00000000, "2.5.4."),
34 _PREFIX(0x00010000, "2.5.6."),
35 _PREFIX(0x00020000, "1.2.840.113556.1.2."),
36 _PREFIX(0x00030000, "1.2.840.113556.1.3."),
37 _PREFIX(0x00080000, "2.5.5."),
38 _PREFIX(0x00090000, "1.2.840.113556.1.4."),
39 _PREFIX(0x000A0000, "1.2.840.113556.1.5."),
40 _PREFIX(0x00140000, "2.16.840.1.113730.3."),
41 _PREFIX(0x00150000, "0.9.2342.19200300.100.1."),
42 _PREFIX(0x00160000, "2.16.840.1.113730.3.1."),
43 _PREFIX(0x00170000, "1.2.840.113556.1.5.7000."),
44 _PREFIX(0x001A0000, "2.5.20."),
45 _PREFIX(0x001C0000, "2.16.840.1.113730.3.2."),
46 _PREFIX(0x001D0000, "1.3.6.1.4.1.250.1."),
47 _PREFIX(0x001F0000, "0.9.2342.19200300.100.4."),
50 WERROR dsdb_map_oid2int(const char *in, uint32_t *out)
54 for (i=0; i < ARRAY_SIZE(prefix_mappings); i++) {
59 if (strncmp(prefix_mappings[i].oid, in, prefix_mappings[i].oid_len - 1) != 0) {
63 val_str = in + prefix_mappings[i].oid_len - 1;
67 if (val_str[0] == '\0') {
68 return WERR_INVALID_PARAM;
71 val = strtoul(val_str, &end_str, 10);
72 if (end_str[0] != '\0') {
73 return WERR_INVALID_PARAM;
74 } else if (val > 0xFFFF) {
75 return WERR_INVALID_PARAM;
78 *out = prefix_mappings[i].uint32 | val;
82 return WERR_DS_NO_MSDS_INTID;
85 WERROR dsdb_map_int2oid(uint32_t in, TALLOC_CTX *mem_ctx, const char **out)
89 for (i=0; i < ARRAY_SIZE(prefix_mappings); i++) {
91 if (prefix_mappings[i].uint32 != (in & 0xFFFF0000)) {
95 val = talloc_asprintf(mem_ctx, "%s%u",
96 prefix_mappings[i].oid,
98 W_ERROR_HAVE_NO_MEMORY(val);
104 return WERR_DS_NO_MSDS_INTID;
107 #define GET_STRING_LDB(msg, p, elem, strict) do { \
108 (p)->elem = samdb_result_string(msg, #elem, NULL);\
109 if (strict && (p)->elem == NULL) { \
110 d_printf("%s: %s == NULL\n", __location__, #elem); \
111 return WERR_INVALID_PARAM; \
113 (void)talloc_steal(p, (p)->elem); \
116 #define GET_BOOL_LDB(msg, p, elem, strict) do { \
118 str = samdb_result_string(msg, #elem, NULL);\
121 d_printf("%s: %s == NULL\n", __location__, #elem); \
122 return WERR_INVALID_PARAM; \
126 } else if (strcasecmp("TRUE", str) == 0) { \
128 } else if (strcasecmp("FALSE", str) == 0) { \
131 d_printf("%s: %s == %s\n", __location__, #elem, str); \
132 return WERR_INVALID_PARAM; \
136 #define GET_UINT32_LDB(msg, p, elem) do { \
137 (p)->elem = samdb_result_uint(msg, #elem, 0);\
140 #define GET_GUID_LDB(msg, p, elem) do { \
141 (p)->elem = samdb_result_guid(msg, #elem);\
144 #define GET_BLOB_LDB(msg, p, elem, attr) do { \
145 const struct ldb_val *_val;\
146 _val = ldb_msg_find_ldb_val(msg, attr);\
149 (void)talloc_steal(p, (p)->elem.data);\
151 ZERO_STRUCT((p)->elem);\
155 WERROR dsdb_attribute_from_ldb(struct ldb_message *msg, TALLOC_CTX *mem_ctx, struct dsdb_attribute *attr)
159 GET_STRING_LDB(msg, attr, cn, True);
160 GET_STRING_LDB(msg, attr, lDAPDisplayName, True);
161 GET_STRING_LDB(msg, attr, attributeID_oid, True);
162 status = dsdb_map_oid2int(attr->attributeID_oid, &attr->attributeID_id);
163 W_ERROR_NOT_OK_RETURN(status);
164 GET_GUID_LDB(msg, attr, schemaIDGUID);
165 GET_UINT32_LDB(msg, attr, mAPIID);
167 GET_GUID_LDB(msg, attr, attributeSecurityGUID);
169 GET_UINT32_LDB(msg, attr, searchFlags);
170 GET_UINT32_LDB(msg, attr, systemFlags);
171 GET_BOOL_LDB(msg, attr, isMemberOfPartialAttributeSet, False);
172 GET_UINT32_LDB(msg, attr, linkID);
174 GET_STRING_LDB(msg, attr, attributeSyntax_oid, True);
175 status = dsdb_map_oid2int(attr->attributeSyntax_oid, &attr->attributeSyntax_id);
176 W_ERROR_NOT_OK_RETURN(status);
177 GET_UINT32_LDB(msg, attr, oMSyntax);
178 GET_BLOB_LDB(msg, attr, oMObjectClass, "oMObjectClass");
180 GET_BOOL_LDB(msg, attr, isSingleValued, True);
181 GET_UINT32_LDB(msg, attr, rangeLower);
182 GET_UINT32_LDB(msg, attr, rangeUpper);
183 GET_BOOL_LDB(msg, attr, extendedCharsAllowed, False);
185 GET_UINT32_LDB(msg, attr, schemaFlagsEx);
186 GET_BLOB_LDB(msg, attr, msDs_Schema_Extensions, "msDs-Schema-Extensions");
188 GET_BOOL_LDB(msg, attr, showInAdvancedViewOnly, False);
189 GET_STRING_LDB(msg, attr, adminDisplayName, True);
190 GET_STRING_LDB(msg, attr, adminDescription, True);
191 GET_STRING_LDB(msg, attr, classDisplayName, True);
192 GET_BOOL_LDB(msg, attr, isEphemeral, False);
193 GET_BOOL_LDB(msg, attr, isDefunct, False);
194 GET_BOOL_LDB(msg, attr, systemOnly, False);
199 WERROR dsdb_class_from_ldb(struct ldb_message *msg, TALLOC_CTX *mem_ctx, struct dsdb_class *obj)
203 GET_STRING_LDB(msg, obj, cn, True);
204 GET_STRING_LDB(msg, obj, lDAPDisplayName, True);
205 GET_STRING_LDB(msg, obj, governsID_oid, True);
206 status = dsdb_map_oid2int(obj->governsID_oid, &obj->governsID_id);
207 W_ERROR_NOT_OK_RETURN(status);
208 GET_GUID_LDB(msg, obj, schemaIDGUID);
210 GET_UINT32_LDB(msg, obj, objectClassCategory);
211 GET_STRING_LDB(msg, obj, rDNAttID, True);
212 GET_STRING_LDB(msg, obj, defaultObjectCategory, True);
214 GET_STRING_LDB(msg, obj, subClassOf, True);
216 GET_STRING_LDB(msg, obj, systemAuxiliaryClass, False);
217 obj->systemPossSuperiors= NULL;
218 obj->systemMustContain = NULL;
219 obj->systemMayContain = NULL;
221 GET_STRING_LDB(msg, obj, auxiliaryClass, False);
222 obj->possSuperiors = NULL;
223 obj->mustContain = NULL;
224 obj->mayContain = NULL;
226 GET_STRING_LDB(msg, obj, defaultSecurityDescriptor, False);
228 GET_UINT32_LDB(msg, obj, schemaFlagsEx);
229 GET_BLOB_LDB(msg, obj, msDs_Schema_Extensions, "msDs-Schema-Extensions");
231 GET_BOOL_LDB(msg, obj, showInAdvancedViewOnly, False);
232 GET_STRING_LDB(msg, obj, adminDisplayName, True);
233 GET_STRING_LDB(msg, obj, adminDescription, True);
234 GET_STRING_LDB(msg, obj, classDisplayName, True);
235 GET_BOOL_LDB(msg, obj, defaultHidingValue, True);
236 GET_BOOL_LDB(msg, obj, isDefunct, False);
237 GET_BOOL_LDB(msg, obj, systemOnly, False);