2 Unix SMB/CIFS mplementation.
3 Print schema info into string format
5 Copyright (C) Andrew Bartlett 2006-2008
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 3 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, see <http://www.gnu.org/licenses/>.
22 #include "dsdb/samdb/samdb.h"
23 #include "librpc/ndr/libndr.h"
25 #define IF_NULL_FAIL_RET(x) do { \
32 char *schema_attribute_description(TALLOC_CTX *mem_ctx,
33 enum dsdb_schema_convert_target target,
34 const char *seperator,
38 const char *substring,
40 bool single_value, bool operational,
41 uint32_t *range_lower,
42 uint32_t *range_upper,
43 const char *property_guid,
44 const char *property_set_guid,
45 bool indexed, bool system_only)
47 char *schema_entry = talloc_asprintf(mem_ctx,
48 "(%s%s%s", seperator, oid, seperator);
50 schema_entry = talloc_asprintf_append(schema_entry,
51 "NAME '%s'%s", name, seperator);
52 IF_NULL_FAIL_RET(schema_entry);
55 schema_entry = talloc_asprintf_append(schema_entry,
56 "EQUALITY %s%s", equality, seperator);
57 IF_NULL_FAIL_RET(schema_entry);
60 schema_entry = talloc_asprintf_append(schema_entry,
61 "SUBSTR %s%s", substring, seperator);
62 IF_NULL_FAIL_RET(schema_entry);
66 schema_entry = talloc_asprintf_append(schema_entry,
67 "SYNTAX %s%s", syntax, seperator);
68 IF_NULL_FAIL_RET(schema_entry);
72 schema_entry = talloc_asprintf_append(schema_entry,
73 "SINGLE-VALUE%s", seperator);
74 IF_NULL_FAIL_RET(schema_entry);
78 schema_entry = talloc_asprintf_append(schema_entry,
79 "NO-USER-MODIFICATION%s", seperator);
80 IF_NULL_FAIL_RET(schema_entry);
84 schema_entry = talloc_asprintf_append(schema_entry,
86 *range_lower, seperator);
87 IF_NULL_FAIL_RET(schema_entry);
91 schema_entry = talloc_asprintf_append(schema_entry,
93 *range_upper, seperator);
94 IF_NULL_FAIL_RET(schema_entry);
98 schema_entry = talloc_asprintf_append(schema_entry,
99 "PROPERTY-GUID '%s'%s",
100 property_guid, seperator);
101 IF_NULL_FAIL_RET(schema_entry);
104 if (property_set_guid) {
105 schema_entry = talloc_asprintf_append(schema_entry,
106 "PROPERTY-SET-GUID '%s'%s",
107 property_set_guid, seperator);
108 IF_NULL_FAIL_RET(schema_entry);
112 schema_entry = talloc_asprintf_append(schema_entry,
113 "INDEXED%s", seperator);
114 IF_NULL_FAIL_RET(schema_entry);
118 schema_entry = talloc_asprintf_append(schema_entry,
119 "SYSTEM-ONLY%s", seperator);
120 IF_NULL_FAIL_RET(schema_entry);
123 schema_entry = talloc_asprintf_append(schema_entry,
128 char *schema_attribute_to_description(TALLOC_CTX *mem_ctx, const struct dsdb_attribute *attribute)
130 char *schema_description;
131 const char *syntax = attribute->syntax->ldap_oid;
132 TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
138 = schema_attribute_description(mem_ctx,
139 TARGET_AD_SCHEMA_SUBENTRY,
141 attribute->attributeID_oid,
142 attribute->lDAPDisplayName,
143 NULL, NULL, talloc_asprintf(tmp_ctx, "'%s'", syntax),
144 attribute->isSingleValued,
145 attribute->systemOnly,/* TODO: is this correct? */
146 NULL, NULL, NULL, NULL,
148 talloc_free(tmp_ctx);
149 return schema_description;
152 char *schema_attribute_to_extendedInfo(TALLOC_CTX *mem_ctx, const struct dsdb_attribute *attribute)
154 char *schema_description;
155 TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
161 = schema_attribute_description(mem_ctx,
162 TARGET_AD_SCHEMA_SUBENTRY,
164 attribute->attributeID_oid,
165 attribute->lDAPDisplayName,
168 attribute->rangeLower,
169 attribute->rangeUpper,
170 GUID_hexstring(tmp_ctx, &attribute->schemaIDGUID),
171 GUID_hexstring(tmp_ctx, &attribute->attributeSecurityGUID),
172 (attribute->searchFlags & SEARCH_FLAG_ATTINDEX),
173 attribute->systemOnly);
174 talloc_free(tmp_ctx);
175 return schema_description;
178 #define APPEND_ATTRS(attributes) \
181 for (k=0; attributes && attributes[k]; k++) { \
182 const char *attr_name = attributes[k]; \
184 schema_entry = talloc_asprintf_append(schema_entry, \
187 IF_NULL_FAIL_RET(schema_entry); \
188 if (attributes[k+1]) { \
189 IF_NULL_FAIL_RET(schema_entry); \
190 if (target == TARGET_OPENLDAP && ((k+1)%5 == 0)) { \
191 schema_entry = talloc_asprintf_append(schema_entry, \
192 "$%s ", seperator); \
193 IF_NULL_FAIL_RET(schema_entry); \
195 schema_entry = talloc_asprintf_append(schema_entry, \
203 /* Print a schema class or dITContentRule as a string.
205 * To print a scheam class, specify objectClassCategory but not auxillary_classes
206 * To print a dITContentRule, specify auxillary_classes but set objectClassCategory == -1
210 char *schema_class_description(TALLOC_CTX *mem_ctx,
211 enum dsdb_schema_convert_target target,
212 const char *seperator,
215 const char **auxillary_classes,
216 const char *subClassOf,
217 int objectClassCategory,
221 char *schema_entry = talloc_asprintf(mem_ctx,
222 "(%s%s%s", seperator, oid, seperator);
224 IF_NULL_FAIL_RET(schema_entry);
226 schema_entry = talloc_asprintf_append(schema_entry,
227 "NAME '%s'%s", name, seperator);
228 IF_NULL_FAIL_RET(schema_entry);
230 if (auxillary_classes) {
231 schema_entry = talloc_asprintf_append(schema_entry,
233 IF_NULL_FAIL_RET(schema_entry);
235 APPEND_ATTRS(auxillary_classes);
237 schema_entry = talloc_asprintf_append(schema_entry,
239 IF_NULL_FAIL_RET(schema_entry);
242 if (subClassOf && strcasecmp(subClassOf, name) != 0) {
243 schema_entry = talloc_asprintf_append(schema_entry,
244 "SUP %s%s", subClassOf, seperator);
245 IF_NULL_FAIL_RET(schema_entry);
248 switch (objectClassCategory) {
251 /* Dummy case for when used for printing ditContentRules */
254 * NOTE: this is an type 88 class
255 * e.g. 2.5.6.6 NAME 'person'
256 * but w2k3 gives STRUCTURAL here!
258 schema_entry = talloc_asprintf_append(schema_entry,
259 "STRUCTURAL%s", seperator);
260 IF_NULL_FAIL_RET(schema_entry);
263 schema_entry = talloc_asprintf_append(schema_entry,
264 "STRUCTURAL%s", seperator);
265 IF_NULL_FAIL_RET(schema_entry);
268 schema_entry = talloc_asprintf_append(schema_entry,
269 "ABSTRACT%s", seperator);
270 IF_NULL_FAIL_RET(schema_entry);
273 schema_entry = talloc_asprintf_append(schema_entry,
274 "AUXILIARY%s", seperator);
275 IF_NULL_FAIL_RET(schema_entry);
280 schema_entry = talloc_asprintf_append(schema_entry,
281 "MUST (%s", target == TARGET_AD_SCHEMA_SUBENTRY ? "" : " ");
282 IF_NULL_FAIL_RET(schema_entry);
286 schema_entry = talloc_asprintf_append(schema_entry,
288 IF_NULL_FAIL_RET(schema_entry);
292 schema_entry = talloc_asprintf_append(schema_entry,
293 "MAY (%s", target == TARGET_AD_SCHEMA_SUBENTRY ? "" : " ");
294 IF_NULL_FAIL_RET(schema_entry);
298 schema_entry = talloc_asprintf_append(schema_entry,
300 IF_NULL_FAIL_RET(schema_entry);
303 schema_entry = talloc_asprintf_append(schema_entry,
308 char *schema_class_to_description(TALLOC_CTX *mem_ctx, const struct dsdb_class *class)
310 char *schema_description;
311 TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
317 = schema_class_description(mem_ctx,
318 TARGET_AD_SCHEMA_SUBENTRY,
320 class->governsID_oid,
321 class->lDAPDisplayName,
324 class->objectClassCategory,
325 dsdb_attribute_list(tmp_ctx,
326 class, DSDB_SCHEMA_ALL_MUST),
327 dsdb_attribute_list(tmp_ctx,
328 class, DSDB_SCHEMA_ALL_MAY));
329 talloc_free(tmp_ctx);
330 return schema_description;
332 char *schema_class_to_dITContentRule(TALLOC_CTX *mem_ctx, const struct dsdb_class *class,
333 const struct dsdb_schema *schema)
336 char *schema_description;
337 char **aux_class_list = NULL;
339 char **must_attr_list = NULL;
340 char **may_attr_list = NULL;
341 TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
342 const struct dsdb_class *aux_class;
347 aux_class_list = merge_attr_list(tmp_ctx, aux_class_list, class->systemAuxiliaryClass);
348 aux_class_list = merge_attr_list(tmp_ctx, aux_class_list, class->auxiliaryClass);
350 for (i=0; aux_class_list && aux_class_list[i]; i++) {
351 aux_class = dsdb_class_by_lDAPDisplayName(schema, aux_class_list[i]);
353 attrs = dsdb_attribute_list(mem_ctx, aux_class, DSDB_SCHEMA_ALL_MUST);
354 must_attr_list = merge_attr_list(mem_ctx, must_attr_list, attrs);
356 attrs = dsdb_attribute_list(mem_ctx, aux_class, DSDB_SCHEMA_ALL_MAY);
357 may_attr_list = merge_attr_list(mem_ctx, may_attr_list, attrs);
361 = schema_class_description(mem_ctx,
362 TARGET_AD_SCHEMA_SUBENTRY,
364 class->governsID_oid,
365 class->lDAPDisplayName,
366 (const char **)aux_class_list,
367 NULL, /* Must not specify a
372 -1, must_attr_list, may_attr_list);
373 talloc_free(tmp_ctx);
374 return schema_description;