3 Parses the LDAP Data Interchange Format (LDIF)
5 Author: Dominic Cleal <dcleal@redhat.com>
8 This lens tries to keep as close as possible to RFC2849
9 <http://tools.ietf.org/html/rfc2849>
10 and OpenLDAP's ldif(5)
13 This file is licensed under the LGPLv2+, like the rest of Augeas.
19 (************************************************************************
20 * Group: USEFUL PRIMITIVES
21 ************************************************************************)
24 let comment = Util.comment_generic /#[ \t]*/ "# "
27 Map empty lines, including empty comments *)
28 let empty = [ del /#?[ \t]*\n/ "\n" ]
31 Only eol, don't include whitespace *)
32 let eol = Util.del_str "\n"
35 The separator for attributes and values *)
36 let sep_colon = del /:[ \t]*/ ": "
39 The separator for attributes and base64 encoded values *)
40 let sep_base64 = del /::[ \t]*/ ":: "
43 The separator for attributes and URL-sourced values *)
44 let sep_url = del /:<[ \t]*/ ":< "
46 (* Variable: ldapoid_re
47 Format of an LDAP OID from RFC 2251 *)
48 let ldapoid_re = /[0-9][0-9\.]*/
51 Separator between modify operations *)
52 let sep_modspec = Util.del_str "-" . eol
54 (************************************************************************
55 * Group: BASIC ATTRIBUTES
56 ************************************************************************)
58 (* Different types of values, all permitting continuation where the next line
59 begins with whitespace *)
60 let attr_safe_string =
61 let line = /[^ \t\n:<][^\n]*/
62 in let lines = line . (/\n[ \t]+[^ \t\n][^\n]*/)*
63 in sep_colon . store lines
65 let attr_base64_string =
66 let line = /[a-zA-Z0-9=+]+/
67 in let lines = line . (/\n[ \t]+/ . line)*
68 in sep_base64 . [ label "@base64" . store lines ]
71 let line = /[^ \t\n][^\n]*/
72 in let lines = line . (/\n[ \t]+/ . line)*
73 in sep_url . [ label "@url" . store lines ]
75 let attr_intflag = sep_colon . store /0|1/
78 version-spec = "version:" FILL version-number *)
79 let attr_version = Build.key_value_line "version" sep_colon (store /[0-9]+/)
82 dn-spec = "dn:" (FILL distinguishedName /
83 ":" FILL base64-distinguishedName) *)
84 let attr_dn = del /dn/i "dn"
85 . ( attr_safe_string | attr_base64_string )
89 AttributeType = ldap-oid / (ALPHA *(attr-type-chars)) *)
90 let attr_type = ldapoid_re | /[a-zA-Z][a-zA-Z0-9-]*/
96 options = option / (option ";" options) *)
97 let attr_option = Util.del_str ";"
98 . [ label "@option" . store /[a-zA-Z0-9-]+/ ]
100 (* View: attr_description
101 Attribute name, possibly with options *)
102 let attr_description = key attr_type . attr_option*
104 (* View: attr_val_spec
105 Generic attribute with a value *)
106 let attr_val_spec = [ attr_description
112 (* View: attr_changetype
114 t:regexp - value of changeType *)
115 let attr_changetype (t:regexp) =
116 key /changeType/i . sep_colon . store t . eol
118 (* View: attr_modspec *)
119 let attr_modspec = key /add|delete|replace/ . sep_colon . store attr_type
122 (* View: attr_dn_value
123 Parses an attribute line with a DN on the RHS
125 k:regexp - match attribute name as key *)
126 let attr_dn_value (k:regexp) =
127 [ key k . ( attr_safe_string | attr_base64_string ) . eol ]
130 let sep_line = empty | comment
132 (* View: attr_include
133 OpenLDAP extension, must be separated by blank lines *)
134 let attr_include = eol . [ key "include" . sep_colon
135 . store /[^ \t\n][^\n]*/ . eol . comment* . eol ]
137 (* View: sep_record *)
138 let sep_record = ( sep_line | attr_include )*
140 (************************************************************************
141 * Group: LDIF CONTENT RECORDS
142 ************************************************************************)
144 (* View: ldif_attrval_record
145 ldif-attrval-record = dn-spec SEP 1*attrval-spec *)
146 let ldif_attrval_record = [ seq "record"
148 . ( sep_line* . attr_val_spec )+ ]
150 (* View: ldif_content
151 ldif-content = version-spec 1*(1*SEP ldif-attrval-record) *)
152 let ldif_content = [ label "@content"
153 . ( sep_record . attr_version )?
154 . ( sep_record . ldif_attrval_record )+
157 (************************************************************************
158 * Group: LDIF CHANGE RECORDS
159 ************************************************************************)
162 change-add = "add" SEP 1*attrval-spec *)
163 let change_add = [ attr_changetype "add" ] . ( sep_line* . attr_val_spec )+
165 (* View: change_delete
166 change-delete = "add" SEP 1*attrval-spec *)
167 let change_delete = [ attr_changetype "delete" ]
169 (* View: change_modspec
170 change-modspec = add/delete/replace: AttributeDesc SEP *attrval-spec "-" *)
171 let change_modspec = attr_modspec . ( sep_line* . attr_val_spec )*
173 (* View: change_modify
174 change-modify = "modify" SEP *mod-spec *)
175 let change_modify = [ attr_changetype "modify" ]
176 . ( sep_line* . [ change_modspec
177 . sep_line* . sep_modspec ] )+
179 (* View: change_modrdn
180 ("modrdn" / "moddn") SEP newrdn/newsuperior/deleteoldrdn *)
182 let attr_deleteoldrdn = [ key "deleteoldrdn" . attr_intflag . eol ]
183 in let attrs_modrdn = attr_dn_value "newrdn"
184 | attr_dn_value "newsuperior"
186 in [ attr_changetype /modr?dn/ ]
187 . ( sep_line | attrs_modrdn )* . attrs_modrdn
189 (* View: change_record
190 changerecord = "changetype:" FILL (changeadd/delete/modify/moddn) *)
191 let change_record = ( change_add | change_delete | change_modify
194 (* View: change_control
195 "control:" FILL ldap-oid 0*1(1*SPACE ("true" / "false")) 0*1(value-spec) *)
197 let attr_criticality = [ Util.del_ws_spc . label "criticality"
198 . store /true|false/ ]
199 in let attr_ctrlvalue = [ label "value" . (attr_safe_string
201 | attr_url_string ) ]
202 in [ key "control" . sep_colon . store ldapoid_re
203 . attr_criticality? . attr_ctrlvalue? . eol ]
205 (* View: ldif_change_record
206 ldif-change-record = dn-spec SEP *control changerecord *)
207 let ldif_change_record = [ seq "record" . attr_dn
208 . ( ( sep_line | change_control )* . change_control )?
209 . sep_line* . change_record ]
211 (* View: ldif_changes
212 ldif-changes = version-spec 1*(1*SEP ldif-change-record) *)
213 let ldif_changes = [ label "@changes"
214 . ( sep_record . attr_version )?
215 . ( sep_record . ldif_change_record )+
218 (************************************************************************
220 ************************************************************************)
223 let lns = sep_record | ldif_content | ldif_changes
225 let filter = incl "/etc/openldap/schema/*.ldif"
227 let xfm = transform lns filter