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"
24 #define IF_NULL_FAIL_RET(x) do { \
31 char *schema_attribute_description(TALLOC_CTX
*mem_ctx
,
32 enum dsdb_schema_convert_target target
,
33 const char *seperator
,
37 const char *substring
,
39 bool single_value
, bool operational
)
41 char *schema_entry
= talloc_asprintf(mem_ctx
,
42 "(%s%s%s", seperator
, oid
, seperator
);
44 schema_entry
= talloc_asprintf_append(schema_entry
,
45 "NAME '%s'%s", name
, seperator
);
46 IF_NULL_FAIL_RET(schema_entry
);
49 schema_entry
= talloc_asprintf_append(schema_entry
,
50 "EQUALITY %s%s", equality
, seperator
);
51 IF_NULL_FAIL_RET(schema_entry
);
54 schema_entry
= talloc_asprintf_append(schema_entry
,
55 "SUBSTR %s%s", substring
, seperator
);
56 IF_NULL_FAIL_RET(schema_entry
);
59 schema_entry
= talloc_asprintf_append(schema_entry
,
60 "SYNTAX %s%s", syntax
, seperator
);
61 IF_NULL_FAIL_RET(schema_entry
);
64 schema_entry
= talloc_asprintf_append(schema_entry
,
65 "SINGLE-VALUE%s", seperator
);
66 IF_NULL_FAIL_RET(schema_entry
);
70 schema_entry
= talloc_asprintf_append(schema_entry
,
71 "NO-USER-MODIFICATION%s", seperator
);
72 IF_NULL_FAIL_RET(schema_entry
);
75 schema_entry
= talloc_asprintf_append(schema_entry
,
80 char *schema_attribute_to_description(TALLOC_CTX
*mem_ctx
, const struct dsdb_attribute
*attribute
)
82 char *schema_description
;
83 const char *syntax
= attribute
->syntax
->ldap_oid
;
84 TALLOC_CTX
*tmp_ctx
= talloc_new(mem_ctx
);
90 = schema_attribute_description(mem_ctx
,
91 TARGET_AD_SCHEMA_SUBENTRY
,
93 attribute
->attributeID_oid
,
94 attribute
->lDAPDisplayName
,
95 NULL
, NULL
, talloc_asprintf(tmp_ctx
, "'%s'", syntax
),
96 attribute
->isSingleValued
,
97 attribute
->systemOnly
);
99 return schema_description
;
102 #define APPEND_ATTRS(attributes) \
105 for (k=0; attributes && attributes[k]; k++) { \
106 const char *attr_name = attributes[k]; \
108 schema_entry = talloc_asprintf_append(schema_entry, \
111 IF_NULL_FAIL_RET(schema_entry); \
112 if (attributes[k+1]) { \
113 IF_NULL_FAIL_RET(schema_entry); \
114 if (target == TARGET_OPENLDAP && ((k+1)%5 == 0)) { \
115 schema_entry = talloc_asprintf_append(schema_entry, \
116 "$%s ", seperator); \
117 IF_NULL_FAIL_RET(schema_entry); \
119 schema_entry = talloc_asprintf_append(schema_entry, \
127 /* Print a schema class or dITContentRule as a string.
129 * To print a scheam class, specify objectClassCategory but not auxillary_classes
130 * To print a dITContentRule, specify auxillary_classes but set objectClassCategory == -1
134 char *schema_class_description(TALLOC_CTX
*mem_ctx
,
135 enum dsdb_schema_convert_target target
,
136 const char *seperator
,
139 const char **auxillary_classes
,
140 const char *subClassOf
,
141 int objectClassCategory
,
145 char *schema_entry
= talloc_asprintf(mem_ctx
,
146 "(%s%s%s", seperator
, oid
, seperator
);
148 IF_NULL_FAIL_RET(schema_entry
);
150 schema_entry
= talloc_asprintf_append(schema_entry
,
151 "NAME '%s'%s", name
, seperator
);
152 IF_NULL_FAIL_RET(schema_entry
);
154 if (auxillary_classes
) {
155 schema_entry
= talloc_asprintf_append(schema_entry
,
157 IF_NULL_FAIL_RET(schema_entry
);
159 APPEND_ATTRS(auxillary_classes
);
161 schema_entry
= talloc_asprintf_append(schema_entry
,
163 IF_NULL_FAIL_RET(schema_entry
);
166 if (subClassOf
&& strcasecmp(subClassOf
, name
) != 0) {
167 schema_entry
= talloc_asprintf_append(schema_entry
,
168 "SUP %s%s", subClassOf
, seperator
);
169 IF_NULL_FAIL_RET(schema_entry
);
172 switch (objectClassCategory
) {
175 /* Dummy case for when used for printing ditContentRules */
178 * NOTE: this is an type 88 class
179 * e.g. 2.5.6.6 NAME 'person'
180 * but w2k3 gives STRUCTURAL here!
182 schema_entry
= talloc_asprintf_append(schema_entry
,
183 "STRUCTURAL%s", seperator
);
184 IF_NULL_FAIL_RET(schema_entry
);
187 schema_entry
= talloc_asprintf_append(schema_entry
,
188 "STRUCTURAL%s", seperator
);
189 IF_NULL_FAIL_RET(schema_entry
);
192 schema_entry
= talloc_asprintf_append(schema_entry
,
193 "ABSTRACT%s", seperator
);
194 IF_NULL_FAIL_RET(schema_entry
);
197 schema_entry
= talloc_asprintf_append(schema_entry
,
198 "AUXILIARY%s", seperator
);
199 IF_NULL_FAIL_RET(schema_entry
);
204 schema_entry
= talloc_asprintf_append(schema_entry
,
205 "MUST (%s", target
== TARGET_AD_SCHEMA_SUBENTRY
? "" : " ");
206 IF_NULL_FAIL_RET(schema_entry
);
210 schema_entry
= talloc_asprintf_append(schema_entry
,
212 IF_NULL_FAIL_RET(schema_entry
);
216 schema_entry
= talloc_asprintf_append(schema_entry
,
217 "MAY (%s", target
== TARGET_AD_SCHEMA_SUBENTRY
? "" : " ");
218 IF_NULL_FAIL_RET(schema_entry
);
222 schema_entry
= talloc_asprintf_append(schema_entry
,
224 IF_NULL_FAIL_RET(schema_entry
);
227 schema_entry
= talloc_asprintf_append(schema_entry
,
232 char *schema_class_to_description(TALLOC_CTX
*mem_ctx
, const struct dsdb_class
*class)
234 char *schema_description
;
235 TALLOC_CTX
*tmp_ctx
= talloc_new(mem_ctx
);
241 = schema_class_description(mem_ctx
,
242 TARGET_AD_SCHEMA_SUBENTRY
,
244 class->governsID_oid
,
245 class->lDAPDisplayName
,
248 class->objectClassCategory
,
249 dsdb_attribute_list(tmp_ctx
,
250 class, DSDB_SCHEMA_ALL_MUST
),
251 dsdb_attribute_list(tmp_ctx
,
252 class, DSDB_SCHEMA_ALL_MAY
));
253 talloc_free(tmp_ctx
);
254 return schema_description
;
256 char *schema_class_to_dITContentRule(TALLOC_CTX
*mem_ctx
, const struct dsdb_class
*class,
257 const struct dsdb_schema
*schema
)
260 char *schema_description
;
261 char **aux_class_list
= NULL
;
263 char **must_attr_list
= NULL
;
264 char **may_attr_list
= NULL
;
265 TALLOC_CTX
*tmp_ctx
= talloc_new(mem_ctx
);
266 const struct dsdb_class
*aux_class
;
271 aux_class_list
= merge_attr_list(tmp_ctx
, aux_class_list
, class->systemAuxiliaryClass
);
272 aux_class_list
= merge_attr_list(tmp_ctx
, aux_class_list
, class->auxiliaryClass
);
274 for (i
=0; aux_class_list
&& aux_class_list
[i
]; i
++) {
275 aux_class
= dsdb_class_by_lDAPDisplayName(schema
, aux_class_list
[i
]);
277 attrs
= dsdb_attribute_list(mem_ctx
, aux_class
, DSDB_SCHEMA_ALL_MUST
);
278 must_attr_list
= merge_attr_list(mem_ctx
, must_attr_list
, attrs
);
280 attrs
= dsdb_attribute_list(mem_ctx
, aux_class
, DSDB_SCHEMA_ALL_MAY
);
281 may_attr_list
= merge_attr_list(mem_ctx
, may_attr_list
, attrs
);
285 = schema_class_description(mem_ctx
,
286 TARGET_AD_SCHEMA_SUBENTRY
,
288 class->governsID_oid
,
289 class->lDAPDisplayName
,
290 (const char **)aux_class_list
,
291 NULL
, /* Must not specify a
296 -1, must_attr_list
, may_attr_list
);
297 talloc_free(tmp_ctx
);
298 return schema_description
;