1 /*        $NetBSD: ldap_schema.h,v 1.3 2021/08/14 16:14:55 christos Exp $       */
2 
3 /* $OpenLDAP$ */
4 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5  *
6  * Copyright 1998-2021 The OpenLDAP Foundation.
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted only as authorized by the OpenLDAP
11  * Public License.
12  *
13  * A copy of this license is available in file LICENSE in the
14  * top-level directory of the distribution or, alternatively, at
15  * <http://www.OpenLDAP.org/license.html>.
16  */
17 
18 /* ldap-schema.h - Header for basic schema handling functions that can be
19  *                  used by both clients and servers.
20  * these routines should be renamed ldap_x_...
21  */
22 
23 #ifndef _LDAP_SCHEMA_H
24 #define _LDAP_SCHEMA_H 1
25 
26 #include <ldap_cdefs.h>
27 
28 LDAP_BEGIN_DECL
29 
30 /* Codes for parsing errors */
31 
32 #define LDAP_SCHERR_OUTOFMEM            1
33 #define LDAP_SCHERR_UNEXPTOKEN                    2
34 #define LDAP_SCHERR_NOLEFTPAREN                   3
35 #define LDAP_SCHERR_NORIGHTPAREN        4
36 #define LDAP_SCHERR_NODIGIT                       5
37 #define LDAP_SCHERR_BADNAME                       6
38 #define LDAP_SCHERR_BADDESC                       7
39 #define LDAP_SCHERR_BADSUP                        8
40 #define LDAP_SCHERR_DUPOPT                        9
41 #define LDAP_SCHERR_EMPTY                         10
42 #define LDAP_SCHERR_MISSING                       11
43 #define LDAP_SCHERR_OUT_OF_ORDER        12
44 
45 typedef struct ldap_schema_extension_item {
46           char *lsei_name;
47           char **lsei_values;
48 } LDAPSchemaExtensionItem;
49 
50 typedef struct ldap_syntax {
51           char *syn_oid;                /* REQUIRED */
52           char **syn_names;   /* OPTIONAL */
53           char *syn_desc;               /* OPTIONAL */
54           LDAPSchemaExtensionItem **syn_extensions; /* OPTIONAL */
55 } LDAPSyntax;
56 
57 typedef struct ldap_matchingrule {
58           char *mr_oid;                 /* REQUIRED */
59           char **mr_names;    /* OPTIONAL */
60           char *mr_desc;                /* OPTIONAL */
61           int  mr_obsolete;   /* OPTIONAL */
62           char *mr_syntax_oid;          /* REQUIRED */
63           LDAPSchemaExtensionItem **mr_extensions; /* OPTIONAL */
64 } LDAPMatchingRule;
65 
66 typedef struct ldap_matchingruleuse {
67           char *mru_oid;                /* REQUIRED */
68           char **mru_names;   /* OPTIONAL */
69           char *mru_desc;               /* OPTIONAL */
70           int  mru_obsolete;  /* OPTIONAL */
71           char **mru_applies_oids;      /* REQUIRED */
72           LDAPSchemaExtensionItem **mru_extensions; /* OPTIONAL */
73 } LDAPMatchingRuleUse;
74 
75 typedef struct ldap_attributetype {
76           char *at_oid;                 /* REQUIRED */
77           char **at_names;    /* OPTIONAL */
78           char *at_desc;                /* OPTIONAL */
79           int  at_obsolete;   /* 0=no, 1=yes */
80           char *at_sup_oid;   /* OPTIONAL */
81           char *at_equality_oid;        /* OPTIONAL */
82           char *at_ordering_oid;        /* OPTIONAL */
83           char *at_substr_oid;          /* OPTIONAL */
84           char *at_syntax_oid;          /* OPTIONAL */
85           int  at_syntax_len; /* OPTIONAL */
86           int  at_single_value;         /* 0=no, 1=yes */
87           int  at_collective; /* 0=no, 1=yes */
88           int  at_no_user_mod;          /* 0=no, 1=yes */
89           int  at_usage;                /* 0=userApplications, 1=directoryOperation,
90                                            2=distributedOperation, 3=dSAOperation */
91           LDAPSchemaExtensionItem **at_extensions; /* OPTIONAL */
92 } LDAPAttributeType;
93 
94 typedef struct ldap_objectclass {
95           char *oc_oid;                 /* REQUIRED */
96           char **oc_names;    /* OPTIONAL */
97           char *oc_desc;                /* OPTIONAL */
98           int  oc_obsolete;   /* 0=no, 1=yes */
99           char **oc_sup_oids; /* OPTIONAL */
100           int  oc_kind;                 /* 0=ABSTRACT, 1=STRUCTURAL, 2=AUXILIARY */
101           char **oc_at_oids_must;       /* OPTIONAL */
102           char **oc_at_oids_may;        /* OPTIONAL */
103           LDAPSchemaExtensionItem **oc_extensions; /* OPTIONAL */
104 } LDAPObjectClass;
105 
106 typedef struct ldap_contentrule {
107           char *cr_oid;                 /* REQUIRED */
108           char **cr_names;    /* OPTIONAL */
109           char *cr_desc;                /* OPTIONAL */
110           char **cr_sup_oids; /* OPTIONAL */
111           int  cr_obsolete;   /* 0=no, 1=yes */
112           char **cr_oc_oids_aux;        /* OPTIONAL */
113           char **cr_at_oids_must;       /* OPTIONAL */
114           char **cr_at_oids_may;        /* OPTIONAL */
115           char **cr_at_oids_not;        /* OPTIONAL */
116           LDAPSchemaExtensionItem **cr_extensions; /* OPTIONAL */
117 } LDAPContentRule;
118 
119 typedef struct ldap_nameform {
120           char *nf_oid;                 /* REQUIRED */
121           char **nf_names;    /* OPTIONAL */
122           char *nf_desc;                /* OPTIONAL */
123           int  nf_obsolete;   /* 0=no, 1=yes */
124           char *nf_objectclass;         /* REQUIRED */
125           char **nf_at_oids_must;       /* REQUIRED */
126           char **nf_at_oids_may;        /* OPTIONAL */
127           LDAPSchemaExtensionItem **nf_extensions; /* OPTIONAL */
128 } LDAPNameForm;
129 
130 typedef struct ldap_structurerule {
131           int sr_ruleid;                /* REQUIRED */
132           char **sr_names;    /* OPTIONAL */
133           char *sr_desc;                /* OPTIONAL */
134           int  sr_obsolete;   /* 0=no, 1=yes */
135           char *sr_nameform;  /* REQUIRED */
136           int sr_nsup_ruleids;/* number of sr_sup_ruleids */
137           int *sr_sup_ruleids;/* OPTIONAL */
138           LDAPSchemaExtensionItem **sr_extensions; /* OPTIONAL */
139 } LDAPStructureRule;
140 
141 /*
142  * Misc macros
143  */
144 #define LDAP_SCHEMA_NO                                      0
145 #define LDAP_SCHEMA_YES                                     1
146 
147 #define LDAP_SCHEMA_USER_APPLICATIONS             0
148 #define LDAP_SCHEMA_DIRECTORY_OPERATION           1
149 #define LDAP_SCHEMA_DISTRIBUTED_OPERATION         2
150 #define LDAP_SCHEMA_DSA_OPERATION                 3
151 
152 #define LDAP_SCHEMA_ABSTRACT                      0
153 #define LDAP_SCHEMA_STRUCTURAL                              1
154 #define LDAP_SCHEMA_AUXILIARY                     2
155 
156 
157 /*
158  * Flags that control how liberal the parsing routines are.
159  */
160 #define LDAP_SCHEMA_ALLOW_NONE                    0x00U /* Strict parsing               */
161 #define LDAP_SCHEMA_ALLOW_NO_OID        0x01U /* Allow missing oid            */
162 #define LDAP_SCHEMA_ALLOW_QUOTED        0x02U /* Allow bogus extra quotes     */
163 #define LDAP_SCHEMA_ALLOW_DESCR                   0x04U /* Allow descr instead of OID   */
164 #define LDAP_SCHEMA_ALLOW_DESCR_PREFIX  0x08U /* Allow descr as OID prefix    */
165 #define LDAP_SCHEMA_ALLOW_OID_MACRO     0x10U /* Allow OID macros in slapd    */
166 #define LDAP_SCHEMA_ALLOW_OUT_OF_ORDER_FIELDS 0x20U /* Allow fields in most any order */
167 #define LDAP_SCHEMA_ALLOW_ALL           0x3fU /* Be very liberal in parsing   */
168 #define   LDAP_SCHEMA_SKIP                        0x80U /* Don't malloc any result      */
169 
170 
171 LDAP_F( LDAP_CONST char * )
172 ldap_syntax2name LDAP_P((
173           LDAPSyntax * syn ));
174 
175 LDAP_F( LDAP_CONST char * )
176 ldap_matchingrule2name LDAP_P((
177           LDAPMatchingRule * mr ));
178 
179 LDAP_F( LDAP_CONST char * )
180 ldap_matchingruleuse2name LDAP_P((
181           LDAPMatchingRuleUse * mru ));
182 
183 LDAP_F( LDAP_CONST char * )
184 ldap_attributetype2name LDAP_P((
185           LDAPAttributeType * at ));
186 
187 LDAP_F( LDAP_CONST char * )
188 ldap_objectclass2name LDAP_P((
189           LDAPObjectClass * oc ));
190 
191 LDAP_F( LDAP_CONST char * )
192 ldap_contentrule2name LDAP_P((
193           LDAPContentRule * cr ));
194 
195 LDAP_F( LDAP_CONST char * )
196 ldap_nameform2name LDAP_P((
197           LDAPNameForm * nf ));
198 
199 LDAP_F( LDAP_CONST char * )
200 ldap_structurerule2name LDAP_P((
201           LDAPStructureRule * sr ));
202 
203 LDAP_F( void )
204 ldap_syntax_free LDAP_P((
205           LDAPSyntax * syn ));
206 
207 LDAP_F( void )
208 ldap_matchingrule_free LDAP_P((
209           LDAPMatchingRule * mr ));
210 
211 LDAP_F( void )
212 ldap_matchingruleuse_free LDAP_P((
213           LDAPMatchingRuleUse * mr ));
214 
215 LDAP_F( void )
216 ldap_attributetype_free LDAP_P((
217           LDAPAttributeType * at ));
218 
219 LDAP_F( void )
220 ldap_objectclass_free LDAP_P((
221           LDAPObjectClass * oc ));
222 
223 LDAP_F( void )
224 ldap_contentrule_free LDAP_P((
225           LDAPContentRule * cr ));
226 
227 LDAP_F( void )
228 ldap_nameform_free LDAP_P((
229           LDAPNameForm * nf ));
230 
231 LDAP_F( void )
232 ldap_structurerule_free LDAP_P((
233           LDAPStructureRule * sr ));
234 
235 LDAP_F( LDAPStructureRule * )
236 ldap_str2structurerule LDAP_P((
237           LDAP_CONST char * s,
238           int * code,
239           LDAP_CONST char ** errp,
240           LDAP_CONST unsigned flags ));
241 
242 LDAP_F( LDAPNameForm * )
243 ldap_str2nameform LDAP_P((
244           LDAP_CONST char * s,
245           int * code,
246           LDAP_CONST char ** errp,
247           LDAP_CONST unsigned flags ));
248 
249 LDAP_F( LDAPContentRule * )
250 ldap_str2contentrule LDAP_P((
251           LDAP_CONST char * s,
252           int * code,
253           LDAP_CONST char ** errp,
254           LDAP_CONST unsigned flags ));
255 
256 LDAP_F( LDAPObjectClass * )
257 ldap_str2objectclass LDAP_P((
258           LDAP_CONST char * s,
259           int * code,
260           LDAP_CONST char ** errp,
261           LDAP_CONST unsigned flags ));
262 
263 LDAP_F( LDAPAttributeType * )
264 ldap_str2attributetype LDAP_P((
265           LDAP_CONST char * s,
266           int * code,
267           LDAP_CONST char ** errp,
268           LDAP_CONST unsigned flags ));
269 
270 LDAP_F( LDAPSyntax * )
271 ldap_str2syntax LDAP_P((
272           LDAP_CONST char * s,
273           int * code,
274           LDAP_CONST char ** errp,
275           LDAP_CONST unsigned flags ));
276 
277 LDAP_F( LDAPMatchingRule * )
278 ldap_str2matchingrule LDAP_P((
279           LDAP_CONST char * s,
280           int * code,
281           LDAP_CONST char ** errp,
282           LDAP_CONST unsigned flags ));
283 
284 LDAP_F( LDAPMatchingRuleUse * )
285 ldap_str2matchingruleuse LDAP_P((
286           LDAP_CONST char * s,
287           int * code,
288           LDAP_CONST char ** errp,
289           LDAP_CONST unsigned flags ));
290 
291 LDAP_F( char * )
292 ldap_structurerule2str LDAP_P((
293           LDAPStructureRule * sr ));
294 
295 LDAP_F( struct berval * )
296 ldap_structurerule2bv LDAP_P((
297           LDAPStructureRule * sr, struct berval *bv ));
298 
299 LDAP_F( char * )
300 ldap_nameform2str LDAP_P((
301           LDAPNameForm * nf ));
302 
303 LDAP_F( struct berval * )
304 ldap_nameform2bv LDAP_P((
305           LDAPNameForm * nf, struct berval *bv ));
306 
307 LDAP_F( char * )
308 ldap_contentrule2str LDAP_P((
309           LDAPContentRule * cr ));
310 
311 LDAP_F( struct berval * )
312 ldap_contentrule2bv LDAP_P((
313           LDAPContentRule * cr, struct berval *bv ));
314 
315 LDAP_F( char * )
316 ldap_objectclass2str LDAP_P((
317           LDAPObjectClass * oc ));
318 
319 LDAP_F( struct berval * )
320 ldap_objectclass2bv LDAP_P((
321           LDAPObjectClass * oc, struct berval *bv ));
322 
323 LDAP_F( char * )
324 ldap_attributetype2str LDAP_P((
325           LDAPAttributeType * at ));
326 
327 LDAP_F( struct berval * )
328 ldap_attributetype2bv LDAP_P((
329           LDAPAttributeType * at, struct berval *bv ));
330 
331 LDAP_F( char * )
332 ldap_syntax2str LDAP_P((
333           LDAPSyntax * syn ));
334 
335 LDAP_F( struct berval * )
336 ldap_syntax2bv LDAP_P((
337           LDAPSyntax * syn, struct berval *bv ));
338 
339 LDAP_F( char * )
340 ldap_matchingrule2str LDAP_P((
341           LDAPMatchingRule * mr ));
342 
343 LDAP_F( struct berval * )
344 ldap_matchingrule2bv LDAP_P((
345           LDAPMatchingRule * mr, struct berval *bv ));
346 
347 LDAP_F( char * )
348 ldap_matchingruleuse2str LDAP_P((
349           LDAPMatchingRuleUse * mru ));
350 
351 LDAP_F( struct berval * )
352 ldap_matchingruleuse2bv LDAP_P((
353           LDAPMatchingRuleUse * mru, struct berval *bv ));
354 
355 LDAP_F( char * )
356 ldap_scherr2str LDAP_P((
357           int code )) LDAP_GCCATTR((const));
358 
359 LDAP_END_DECL
360 
361 #endif
362 
363