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,
220 const char *schemaHexGUID)
222 char *schema_entry = talloc_asprintf(mem_ctx,
223 "(%s%s%s", seperator, oid, seperator);
225 IF_NULL_FAIL_RET(schema_entry);
227 schema_entry = talloc_asprintf_append(schema_entry,
228 "NAME '%s'%s", name, seperator);
229 IF_NULL_FAIL_RET(schema_entry);
231 if (auxillary_classes) {
232 schema_entry = talloc_asprintf_append(schema_entry,
234 IF_NULL_FAIL_RET(schema_entry);
236 APPEND_ATTRS(auxillary_classes);
238 schema_entry = talloc_asprintf_append(schema_entry,
240 IF_NULL_FAIL_RET(schema_entry);
243 if (subClassOf && strcasecmp(subClassOf, name) != 0) {
244 schema_entry = talloc_asprintf_append(schema_entry,
245 "SUP %s%s", subClassOf, seperator);
246 IF_NULL_FAIL_RET(schema_entry);
249 switch (objectClassCategory) {
252 /* Dummy case for when used for printing ditContentRules */
255 * NOTE: this is an type 88 class
256 * e.g. 2.5.6.6 NAME 'person'
257 * but w2k3 gives STRUCTURAL here!
259 schema_entry = talloc_asprintf_append(schema_entry,
260 "STRUCTURAL%s", seperator);
261 IF_NULL_FAIL_RET(schema_entry);
264 schema_entry = talloc_asprintf_append(schema_entry,
265 "STRUCTURAL%s", seperator);
266 IF_NULL_FAIL_RET(schema_entry);
269 schema_entry = talloc_asprintf_append(schema_entry,
270 "ABSTRACT%s", seperator);
271 IF_NULL_FAIL_RET(schema_entry);
274 schema_entry = talloc_asprintf_append(schema_entry,
275 "AUXILIARY%s", seperator);
276 IF_NULL_FAIL_RET(schema_entry);
281 schema_entry = talloc_asprintf_append(schema_entry,
282 "MUST (%s", target == TARGET_AD_SCHEMA_SUBENTRY ? "" : " ");
283 IF_NULL_FAIL_RET(schema_entry);
287 schema_entry = talloc_asprintf_append(schema_entry,
289 IF_NULL_FAIL_RET(schema_entry);
293 schema_entry = talloc_asprintf_append(schema_entry,
294 "MAY (%s", target == TARGET_AD_SCHEMA_SUBENTRY ? "" : " ");
295 IF_NULL_FAIL_RET(schema_entry);
299 schema_entry = talloc_asprintf_append(schema_entry,
301 IF_NULL_FAIL_RET(schema_entry);
305 schema_entry = talloc_asprintf_append(schema_entry,
307 schemaHexGUID, seperator);
308 IF_NULL_FAIL_RET(schema_entry);
311 schema_entry = talloc_asprintf_append(schema_entry,
316 char *schema_class_to_description(TALLOC_CTX *mem_ctx, const struct dsdb_class *sclass)
318 char *schema_description;
319 TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
325 = schema_class_description(mem_ctx,
326 TARGET_AD_SCHEMA_SUBENTRY,
328 sclass->governsID_oid,
329 sclass->lDAPDisplayName,
332 sclass->objectClassCategory,
333 dsdb_attribute_list(tmp_ctx,
334 sclass, DSDB_SCHEMA_ALL_MUST),
335 dsdb_attribute_list(tmp_ctx,
336 sclass, DSDB_SCHEMA_ALL_MAY),
338 talloc_free(tmp_ctx);
339 return schema_description;
342 char *schema_class_to_dITContentRule(TALLOC_CTX *mem_ctx, const struct dsdb_class *sclass,
343 const struct dsdb_schema *schema)
346 char *schema_description;
347 const char **aux_class_list = NULL;
349 const char **must_attr_list = NULL;
350 const char **may_attr_list = NULL;
351 TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
352 const struct dsdb_class *aux_class;
357 aux_class_list = merge_attr_list(tmp_ctx, aux_class_list, sclass->systemAuxiliaryClass);
358 aux_class_list = merge_attr_list(tmp_ctx, aux_class_list, sclass->auxiliaryClass);
360 for (i=0; aux_class_list && aux_class_list[i]; i++) {
361 aux_class = dsdb_class_by_lDAPDisplayName(schema, aux_class_list[i]);
363 attrs = dsdb_attribute_list(mem_ctx, aux_class, DSDB_SCHEMA_ALL_MUST);
364 must_attr_list = merge_attr_list(mem_ctx, must_attr_list, attrs);
366 attrs = dsdb_attribute_list(mem_ctx, aux_class, DSDB_SCHEMA_ALL_MAY);
367 may_attr_list = merge_attr_list(mem_ctx, may_attr_list, attrs);
371 = schema_class_description(mem_ctx,
372 TARGET_AD_SCHEMA_SUBENTRY,
374 sclass->governsID_oid,
375 sclass->lDAPDisplayName,
376 (const char **)aux_class_list,
377 NULL, /* Must not specify a
382 -1, must_attr_list, may_attr_list,
384 talloc_free(tmp_ctx);
385 return schema_description;
388 char *schema_class_to_extendedInfo(TALLOC_CTX *mem_ctx, const struct dsdb_class *sclass)
390 char *schema_description = NULL;
391 TALLOC_CTX *tmp_ctx = talloc_new(mem_ctx);
397 = schema_class_description(mem_ctx,
398 TARGET_AD_SCHEMA_SUBENTRY,
400 sclass->governsID_oid,
401 sclass->lDAPDisplayName,
403 NULL, /* Must not specify a
409 GUID_hexstring(tmp_ctx, &sclass->schemaIDGUID));
410 talloc_free(tmp_ctx);
411 return schema_description;