]> git.sur5r.net Git - openldap/blob - doc/guide/admin/schema.sdf
Minor fixes including those from ITS#1283
[openldap] / doc / guide / admin / schema.sdf
1 # $OpenLDAP$
2 # Copyright 1999-2000, The OpenLDAP Foundation, All Rights Reserved.
3 # COPYING RESTRICTIONS APPLY, see COPYRIGHT.
4
5 H1: Schema Specification
6
7 This chapter describes how to extend the schema used by {{slapd}}(8).
8 The first section, {{SECT:Distributed Schema Files}} details optional
9 schema definitions provided in the distribution and where to obtain
10 other definitions.
11 The second section, {{SECT:Extending Schema}}, details how to define
12 new schema items.
13 !if 0
14 The third section, {{SECT:Transferring Schema}} details how you can
15 export schema definitions from an LDAPv3 server and transform it
16 to {{slapd.conf}}(5) format.
17 !endif
18
19 H2: Distributed Schema Files
20
21 OpenLDAP is distributed with a set of schema specifications for
22 your use.  Each set is defined in a file suitable for inclusion
23 (using the {{EX:include}} directive) in your {{slapd.conf}}(5)
24 file.  These schema files are normally installed in the
25 {{F:/usr/local/etc/openldap/schema}} directory.
26
27 !block table; colaligns="LR"; coltags="F,N"; align=Center; \
28         title="Table 6.1: Provided Schema Specifications"
29 File                    Description
30 core.schema             OpenLDAP {{core}} (required)
31 cosine.schema           Cosine and Internet X.500 (useful)
32 inetorgperson.schema    InetOrgPerson (useful)
33 misc.schema             Assorted (experimental)
34 nadf.schema             North American Directory Forum (FYI)
35 nis.schema              Network Information Services (FYI)
36 openldap.schema         OpenLDAP Project (experimental)
37 !endblock
38
39 To use any of these schema files, you only need to include the
40 desired file in the global definitions portion of your
41 {{slapd.conf}}(5) file.  For example:
42
43 >       # include schema
44 >       include /usr/local/etc/openldap/schema/core.schema
45 >       include /usr/local/etc/openldap/schema/cosine.schema
46 >       include /usr/local/etc/openldap/schema/inetorgperson.schema
47
48 Additional files may be available.  Please consult the OpenLDAP
49 FAQ ({{URL:http://www.openldap.org/faq/}}).
50
51 Note: You should not modify any of the schema items defined
52 in provided files.
53
54 H2: Extending Schema
55
56 Schema used by {{slapd}}(8) may be extended to support additional
57 syntaxes, matching rules, attribute types, and object classes.
58 This chapter details how to add attribute types and object classes
59 using the syntaxes and matching rules already supported by slapd.
60 slapd can also be extended to support additional syntaxes
61 and matching rules, but this requires some programming and hence
62 is not discussed here.
63
64 There are five steps to defining new schema:
65 ^       obtain Object Identifer
66 +       choose a name prefix
67 +       create local schema file
68 +       define custom attribute types (if necessary)
69 +       define custom object classes
70
71 H3: Object Identifiers
72
73 Each schema element is identified by a globally unique
74 {{TERM[expand]OID}} (OID).  OIDs are also used to identify
75 other objects.
76 They are commonly found in protocols described by {{TERM:ASN.1}}.  In
77 particular, they are heavily used by the {{TERM[expand]SNMP}} (SNMP).
78 As OIDs are hierarchical, your organization
79 can obtain one OID and branch it as needed.  For example,
80 if your organization were assigned OID {{EX:1.1}}, you could branch
81 the tree as follows:
82
83 !block table; colaligns="LR"; coltags="EX,N"; align=Center; \
84         title="Table 6.2: Example OID hierarchy"
85 OID             Assignment
86 1.1             Organization's OID
87 1.1.1           SNMP Elements
88 1.1.2           LDAP Elements
89 1.1.2.1         AttributeTypes
90 1.1.2.1.1       myAttribute
91 1.1.2.2         ObjectClasses
92 1.1.2.2.1       myObjectClass
93 !endblock
94
95 You are, of course, free to design a hierarchy suitable to your
96 organizational needs under your organization's OID.  No matter
97 what hierarchy you choose, you should maintain a registry of
98 assignments you make.  This can be a simple flat file or a
99 something more sophisticated such as the {{OpenLDAP OID Registry}}
100 ({{URL:http://www.openldap.org/faq/index.cgi?file=197}}).
101
102 For more information about Object Identifers (and a listing
103 service) see {{URL:http://www.alvestrand.no/harald/objectid/}}.
104
105 .{{Under no circumstances should you use a fictious OID!}} 
106
107 To obtain a fully registered OID at {{no cost}}, apply for
108 an OID under {{ORG[expand]IANA}} (IANA) maintained
109 {{Private Enterprise}} arch.  Any private enterprise (organization)
110 may request an OID to be assigned under this arch.  Just fill
111 out the {{ORG:IANA}} form at {{URL: http://www.iana.org/cgi-bin/enterprise.pl}}
112 and your official OID will be sent to you usually within a few days.
113 Your base OID will be something like {{EX:1.3.6.1.4.1.X}} were {{EX:X}}
114 is an integer.
115
116 Note: Don't let the "MIB/SNMP" statement on the IANA page confuse you.
117 OIDs obtained using this form may be used for any purpose including
118 identifying LDAP schema elements.
119
120
121 H3: Name Prefix
122
123 In addition to assigning a unique object identifier to each schema
124 element, you should provide a least one textual name for each
125 element.  The name should be both descriptive and not likely
126 to clash with names of other schema elements.  In particular,
127 any name you choose should not clash with present or future
128 Standard Track names.
129
130 To reduce (but not eliminate) the potential for name clashes,
131 the convention is to prefix names of non-Standard Track with
132 a few letters to localize the changes to your organization.
133 The smaller the organization, the longer your prefix should
134 be.
135
136 In the examples below, we have choosen a short prefix '{{EX:my}}'
137 (to save space).  Such a short prefix would only be suitable for
138 a very large, global organization.  For a small, local organization,
139 we recommend something like '{{EX:deFirm}}' (German company) or
140 '{{EX:comExample}}' (elements associated with organization associated
141 with {{EX:example.com}}).
142
143
144 H3: Local schema file
145
146 The {{EX:objectclass}} and {{EX:attributeTypes}} configuration file
147 directives can be used to define schema rules on entries in the
148 directory.  It is customary to create a file to contain definitions
149 of your custom schema items.  We recommend you create a file
150 {{F:local.schema}} in {{F:/usr/local/etc/openldap/schema/local.schema}}
151 and then include this file in your {{slapd.conf}}(5) file immediately
152 after other schema {{EX:include}} directives.
153
154 >       # include schema
155 >       include /usr/local/etc/openldap/schema/core.schema
156 >       include /usr/local/etc/openldap/schema/cosine.schema
157 >       include /usr/local/etc/openldap/schema/inetorgperson.schema
158 >       # include local schema
159 >       include /usr/local/etc/openldap/schema/local.schema
160
161
162 H3: Attribute Type Specification
163
164 The {{attributetype}} directive is used to define a new attribute
165 type.  The directive uses the same Attribute Type Description
166 (as defined in {{REF:RFC2252}}) used by the attributeTypes
167 attribute found in the subschema subentry, e.g.:
168
169 E:      attributetype <{{REF:RFC2252}} Attribute Type Description>
170
171 where Attribute Type Description is defined by the following
172 {{TERM:BNF}}:
173
174 >      AttributeTypeDescription = "(" whsp
175 >            numericoid whsp              ; AttributeType identifier
176 >          [ "NAME" qdescrs ]             ; name used in AttributeType
177 >          [ "DESC" qdstring ]            ; description
178 >          [ "OBSOLETE" whsp ]
179 >          [ "SUP" woid ]                 ; derived from this other
180 >                                         ; AttributeType
181 >          [ "EQUALITY" woid              ; Matching Rule name
182 >          [ "ORDERING" woid              ; Matching Rule name
183 >          [ "SUBSTR" woid ]              ; Matching Rule name
184 >          [ "SYNTAX" whsp noidlen whsp ] ; see section 4.3
185 >          [ "SINGLE-VALUE" whsp ]        ; default multi-valued
186 >          [ "COLLECTIVE" whsp ]          ; default not collective
187 >          [ "NO-USER-MODIFICATION" whsp ]; default user modifiable
188 >          [ "USAGE" whsp AttributeUsage ]; default userApplications
189 >          whsp ")"
190 >
191 >      AttributeUsage =
192 >          "userApplications"     /
193 >          "directoryOperation"   /
194 >          "distributedOperation" / ; DSA-shared
195 >          "dSAOperation"          ; DSA-specific, value depends on server
196 >
197
198 where whsp is a space ('{{EX: }}'), numericoid is a globally unique
199 OID in dotted-decimal form (e.g. {{EX:1.2.3}}), qdescrs is one or more
200 names, woid is either the name or OID, and noidlen is an optional length
201 specifier (e.g {{EX:{10}}}).
202
203 For example, the attribute types {{EX:name}} and {{EX:cn}} are defined
204 in {{F:core.schema}} as:
205
206 >       attributeType ( 2.5.4.41 NAME 'name'
207 >               EQUALITY caseIgnoreMatch
208 >               SUBSTR caseIgnoreSubstringsMatch
209 >               SYNTAX 1.3.6.1.4.1.1466.115.121.1.15{32768} )
210 >       attributeType ( 2.5.4.3 NAME
211 >               ( 'cn' $ 'commonName' ) SUP name )
212
213 Notice that each defines the attribute's OID and descriptive
214 names.  Each name is an alias for the OID.  {{slapd}}(8) returns
215 the first listed name when returning results.
216
217 The first attribute, {{EX:name}}, has a syntax of {{EX:directoryString}}
218 (a UTF-8 encoded Unicode string) with a recommend maximun length.
219 Note that syntaxes are specified by OID.  In addition, the equality
220 and substring matching uses case ignore rules.  Below are tables 
221 listing commonly used supported syntax and matching rules.
222
223 !block table; align=Center; coltags="EX,EX,N"; \
224         title="Table 6.3: Supported Syntaxes"
225 Name                    OID                             Description
226 binary                  1.3.6.1.4.1.1466.115.121.1.5    BER/DER data
227 boolean                 1.3.6.1.4.1.1466.115.121.1.7    boolean value
228 distinguishedName       1.3.6.1.4.1.1466.115.121.1.12   DN
229 directoryString         1.3.6.1.4.1.1466.115.121.1.15   UTF-8 string
230 IA5String               1.3.6.1.4.1.1466.115.121.1.26   ASCII string
231 Integer                 1.3.6.1.4.1.1466.115.121.1.27   integer
232 Name and Optional UID   1.3.6.1.4.1.1466.115.121.1.34   DN plus UID
233 Numeric String          1.3.6.1.4.1.1466.115.121.1.36   numeric string
234 OID                     1.3.6.1.4.1.1466.115.121.1.38   object identifier
235 Octet String            1.3.6.1.4.1.1466.115.121.1.40   arbitary octets
236 Printable String        1.3.6.1.4.1.1466.115.121.1.44   printable string
237 !endblock
238
239
240
241 !block table; align=Center; coltags="EX,N"; \
242         title="Table 6.4: Supported Matching Rules"
243 Name                            Type            Description
244 booleanMatch                    equality        boolean
245 objectIdentiferMatch            equality        OID
246 distinguishedNameMatch          equality        DN
247 uniqueMemberMatch               equality        DN with optional UID
248 numericStringMatch              equality        numerical
249 numericStringOrderingMatch      ordering        numerical
250 numericStringSubstringsMatch    substrings      numerical
251 caseIgnoreMatch                 equality        case insensitive, space insensitive
252 caseIgnoreOrderingMatch         ordering        case insensitive, space insensitive
253 caseIgnoreSubstringsMatch       substrings      case insensitive, space insensitive
254 caseExactMatch                  equality        case sensitive, space insensitive
255 caseExactOrderingMatch          ordering        case sensitive, space insensitive
256 caseExactSubstringsMatch        substrings      case sensitive, space insensitive
257 caseIgnoreIA5Match              equality        case insensitive, space insensitive
258 caseIgnoreIA5OrderingMatch      ordering        case insensitive, space insensitive
259 caseIgnoreIA5SubstringsMatch    substrings      case insensitive, space insensitive
260 caseExactIA5Match               equality        case sensitive, space insensitive
261 caseExactIA5OrderingMatch       ordering        case sensitive, space insensitive
262 caseExactIA5SubstringsMatch     substrings      case sensitive, space insensitive
263 !endblock
264
265 The second attribute, {{EX:cn}}, is a subtype of {{EX:name}} hence
266 it inherits the syntax, matching rules, and usage of {{EX:name}}.
267 {{EX:commonName}} is an alternative name.
268
269 Neither attribute is restricted to a single value and both are
270 meant for usage by user applications.  You likely won't need to
271 specify other parameters such as {{EX:OBSOLETE}}.
272
273 The following subsections provide a couple of examples.
274
275
276 H4: myUniqueName
277
278 Many organizations maintain a single unique name for each user.
279 Though one could use {{EX:displayName}} ({{REF:RFC2798}}), this
280 attribute is really meant to be controlled by the user, not the
281 organization.  We could just copy the definition of {{EX:displayName}}
282 from {{F:inetorgperson.schema}} and replace the OID, name, and
283 description, e.g:
284
285 >       attributetype ( 1.1.2.1.1 NAME 'myUniqueName'
286 >               DESC 'unique name with my organization' 
287 >               EQUALITY caseIgnoreMatch
288 >               SUBSTR caseIgnoreSubstringsMatch
289 >               SYNTAX 1.3.6.1.4.1.1466.115.121.1.15
290 >               SINGLE-VALUE )
291
292 However, if we want this name to be included in
293 {{EX:name}} assertions [e.g. {{EX:(name=*Jane*)}}], the attribute
294 could alternatively be defined as a subtype of {{EX:name}}, e.g.:
295
296 >       attributetype ( 1.1.2.1.1 NAME 'myUniqueName'
297 >               DESC 'unique name with my organization' 
298 >               SUP name )
299
300
301 H4: myPhoto
302
303 Many organizations maintain a photo of each each user.  A
304 {{EX:myPhoto}} attribute type could be defined to hold a photo.
305 Of course, one could use just use {{EX:jpegPhoto}} ({{REF:RFC2798}})
306 (or a subtype) to hold the photo.  However, you can only do
307 this if the photo is in {{JPEG File Interchange Format}}.
308 Alternatively, an attribute type which uses the {{Octet String}}
309 syntax can be defined, e.g.:
310
311 >       attributetype ( 1.1.2.1.2 NAME 'myPhoto'
312 >               DESC 'a photo (application defined format)' 
313 >               SYNTAX 1.3.6.1.4.1.1466.115.121.1.40
314 >               SINGLE-VALUE )
315
316 As noted in the description, LDAP has no knowledge of the
317 format of the photo.  It's assumed that all applications
318 accessing this attribute agree on the handling of values.
319
320 If you wanted to support multiple photo formats, you could define
321 a separate attribute type for each format, prefix the photo
322 with some typing information, or describe the value using
323 {{TERM:ASN.1}} and use the {{EX:;binary}} transfer option.
324
325 Another alternative is for the attribute to hold a {{TERM:URI}}
326 pointing to the photo.  You can model such an attribute after
327 {{EX:labeledURI}} ({{REF:RFC2079}}).
328
329
330 H3: Object Class Specification
331
332 The {{objectclasses}} directive is used to define a new object
333 class.  The directive uses the same Object Class Description
334 (as defined in {{REF:RFC2252}}) used by the objectClasses
335 attribute found in the subschema subentry, e.g.:
336
337 E:      objectclass <{{REF:RFC2252}} Object Class Description>
338
339 where Object Class Description is defined by the following
340 {{TERM:BNF}}:
341
342 >       ObjectClassDescription = "(" whsp
343 >               numericoid whsp      ; ObjectClass identifier
344 >               [ "NAME" qdescrs ]
345 >               [ "DESC" qdstring ]
346 >               [ "OBSOLETE" whsp ]
347 >               [ "SUP" oids ]       ; Superior ObjectClasses
348 >               [ ( "ABSTRACT" / "STRUCTURAL" / "AUXILIARY" ) whsp ]
349 >                       ; default structural
350 >               [ "MUST" oids ]      ; AttributeTypes
351 >               [ "MAY" oids ]       ; AttributeTypes
352 >               whsp ")"
353
354 where whsp is a space ('{{EX: }}'), numericoid is a globally unique
355 OID in numeric form (e.g. {{EX:1.2.3}}), qdescrs is one or more
356 names, and oids is one or more names and/or OIDs.
357
358
359 H4: myPhotoObject
360
361 To define an {{auxiliary}} object class which allows
362 myPhoto to be added to any existing entry.
363
364 >       objectclass ( 1.1.2.2.1 NAME 'myPhotoObject'
365 >               DESC 'mixin myPhoto'
366 >               AUXILIARY
367 >               MAY myPhoto )
368
369
370 H4: myPerson
371
372 If your organization would like have a private {{structural}}
373 object class to instantiate users, you can subclass one of
374 the existing person classes, such as {{EX:inetOrgPerson}}
375 ({{REF:RFC2798}}), and add any additional attributes which
376 you desire.
377
378 >       objectclass ( 1.1.2.2.2 NAME 'myPerson'
379 >               DESC 'my person'
380 >               SUP inetOrgPerson
381 >               MUST ( 'myUniqueName' $ 'givenName' )
382 >               MAY 'myPhoto' )
383
384 The object class inherits the required/allowed attribute
385 types of {{EX:inetOrgPerson}} but requires {{EX:myUniqueName}}
386 and {{EX:givenName}} and allows {{EX:myPhoto}}.
387
388 !if 0
389 H2: Transferring Schema
390
391 Since the {{slapd.conf}}(5) schema directives use {{REF:RFC2252}}
392 format values, you can extract schema elements published by
393 any LDAPv3 server and easily construct directives for use with
394 {{slapd}}(8).
395
396 LDAPv3 servers publish schema elements in special {{subschema}}
397 entries (or subentries).  {{slapd}}(8) publishes a single subschema
398 entry normally named {{EX:cn=Subschema}}.  In a server which
399 supports a single subschema subentry, the DN of the subschema
400 subenty can usually be found by examining the value of the
401 {{EX:subschemaSubentry}} attribute type in the {{root DSE}}.
402 Other servers may publish multiple subschema entries.  These
403 can be located by examining the {{EX:subschemaSubentry}} attribute
404 contained in the entry at the root of each administrative context.
405
406 To obtain the schema from a subschema subentry, you can use
407 ldapsearch(1) as follows (replace the search base as needed):
408
409 >       ldapsearch -LLL -x -b "cn=Subschema" -s base "(objectclass=subschema)" attributeTypes objectClasses
410
411 This will return {{TERM:LDIF}} output containing many type/value
412 pairs.  The following is an abbreviated example:
413
414 >       dn: cn=Subschema
415 >       attributeTypes: ( 1.1.2.1.1 NAME 'myUniqueName' DESC 'unique name wi
416 >        th my organization' EQUALITY caseIgnoreMatch SUBSTR caseIgnoreSubst
417 >        ringsMatch SYNTAX 1.3.6.1.4.1.1466.115.121.1.15 SINGLE-VALUE )
418 >       attributeTypes: ( 1.1.2.1.2 NAME 'myPhoto' DESC 'a photo (applicatio
419 >        n defined format)' SYNTAX 1.3.6.1.4.1.1466.115.121.1.40
420 >       objectClasses: ( 1.1.2.2.2 NAME 'myPerson' DESC 'my person' SUP inet
421 >        OrgPerson MUST ( 'myUniqueName' $ 'givenName' ) MAY 'myPhoto' )
422
423 Capture the output of the search in a file and then edit the file:
424
425 + to contain only desired type/value pairs
426 ^ join LDIF continuation lines
427 ^ replace attribute type with directive name
428 (e.g. {{EX:s/attributeTypes:/attributeType/}} and
429 {{EX:s/objectClasses:/objectClass/}}).
430 ^ continue long directives over multiple lines
431
432 For the three type/value pairs in our example, the edit should
433 result in a file with contains of:
434
435 >       attributetype ( 1.1.2.1.1 NAME 'myUniqueName'
436 >               DESC 'unique name with my organization' 
437 >               EQUALITY caseIgnoreMatch
438 >               SUBSTR caseIgnoreSubstringsMatch
439 >               SYNTAX 1.3.6.1.4.1.1466.115.121.1.15
440 >               SINGLE-VALUE )
441 >       attributeType ( 1.1.2.1.2 NAME 'myPhoto'
442 >               DESC 'a photo (application defined format)'
443 >               SYNTAX 1.3.6.1.4.1.1466.115.121.1.40
444 >       objectClass ( 1.1.2.2.2 NAME 'myPerson'
445 >               DESC 'my person'
446 >               SUP inetOrgPerson
447 >               MUST ( 'myUniqueName' $ 'givenName' )
448 >               MAY 'myPhoto' )
449
450 Save in an appropriately named file (e.g. {{F:my.schema}}).
451 You may now include this file in your {{slapd.conf}}(8) file.
452 !endif