Bump to 1.14.1
[platform/upstream/augeas.git] / lenses / ldif.aug
1 (*
2 Module: Ldif
3   Parses the LDAP Data Interchange Format (LDIF)
4
5 Author: Dominic Cleal <dcleal@redhat.com>
6
7 About: Reference
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)
11
12 About: Licence
13   This file is licensed under the LGPLv2+, like the rest of Augeas.
14 *)
15
16 module Ldif =
17 autoload xfm
18
19 (************************************************************************
20  * Group:                 USEFUL PRIMITIVES
21  ************************************************************************)
22
23 (* View: comment *)
24 let comment = Util.comment_generic /#[ \t]*/ "# "
25
26 (* View: empty
27     Map empty lines, including empty comments *)
28 let empty   = [ del /#?[ \t]*\n/ "\n" ]
29
30 (* View: eol
31     Only eol, don't include whitespace *)
32 let eol     = Util.del_str "\n"
33
34 (* View: sep_colon
35     The separator for attributes and values *)
36 let sep_colon  = del /:[ \t]*/ ": "
37
38 (* View: sep_base64
39     The separator for attributes and base64 encoded values *)
40 let sep_base64 = del /::[ \t]*/ ":: "
41
42 (* View: sep_url
43     The separator for attributes and URL-sourced values *)
44 let sep_url    = del /:<[ \t]*/ ":< "
45
46 (* Variable: ldapoid_re
47     Format of an LDAP OID from RFC 2251 *)
48 let ldapoid_re = /[0-9][0-9\.]*/
49
50 (* View: sep_modspec
51     Separator between modify operations *)
52 let sep_modspec = Util.del_str "-" . eol
53
54 (************************************************************************
55  * Group:                     BASIC ATTRIBUTES
56  ************************************************************************)
57
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
64
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 ]
69
70 let attr_url_string =
71      let line  = /[^ \t\n][^\n]*/
72   in let lines = line . (/\n[ \t]+/ . line)*
73   in sep_url . [ label "@url" . store lines ]
74
75 let attr_intflag = sep_colon  . store /0|1/
76
77 (* View: attr_version
78     version-spec = "version:" FILL version-number *)
79 let attr_version = Build.key_value_line "version" sep_colon (store /[0-9]+/)
80
81 (* View: attr_dn
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 )
86               . eol
87
88 (* View: attr_type
89     AttributeType = ldap-oid / (ALPHA *(attr-type-chars)) *)
90 let attr_type = ldapoid_re | /[a-zA-Z][a-zA-Z0-9-]*/
91                                - /dn/i
92                                - /changeType/i
93                                - /include/i
94
95 (* View: attr_option
96     options = option / (option ";" options) *)
97 let attr_option  = Util.del_str ";"
98                    . [ label "@option" . store /[a-zA-Z0-9-]+/ ]
99
100 (* View: attr_description
101     Attribute name, possibly with options *)
102 let attr_description = key attr_type . attr_option*
103
104 (* View: attr_val_spec
105     Generic attribute with a value *)
106 let attr_val_spec = [ attr_description
107                       . ( attr_safe_string
108                           | attr_base64_string
109                           | attr_url_string )
110                       . eol ]
111
112 (* View: attr_changetype
113     Parameters:
114      t:regexp - value of changeType *)
115 let attr_changetype (t:regexp) =
116   key /changeType/i . sep_colon . store t . eol
117
118 (* View: attr_modspec *)
119 let attr_modspec = key /add|delete|replace/ . sep_colon . store attr_type
120                      . attr_option* . eol
121
122 (* View: attr_dn_value
123     Parses an attribute line with a DN on the RHS
124     Parameters:
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 ]
128
129 (* View: sep_line *)
130 let sep_line   = empty | comment
131
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 ]
136
137 (* View: sep_record *)
138 let sep_record = ( sep_line | attr_include )*
139
140 (************************************************************************
141  * Group:                     LDIF CONTENT RECORDS
142  ************************************************************************)
143
144 (* View: ldif_attrval_record
145     ldif-attrval-record = dn-spec SEP 1*attrval-spec *)
146 let ldif_attrval_record = [ seq "record"
147                             . attr_dn
148                             . ( sep_line* . attr_val_spec )+ ]
149
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 )+
155                      . sep_record ]
156
157 (************************************************************************
158  * Group:                     LDIF CHANGE RECORDS
159  ************************************************************************)
160
161 (* View: change_add
162     change-add = "add" SEP 1*attrval-spec *)
163 let change_add = [ attr_changetype "add" ] . ( sep_line* . attr_val_spec )+
164
165 (* View: change_delete
166     change-delete = "add" SEP 1*attrval-spec *)
167 let change_delete = [ attr_changetype "delete" ]
168
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 )*
172
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 ] )+
178
179 (* View: change_modrdn
180     ("modrdn" / "moddn") SEP newrdn/newsuperior/deleteoldrdn *)
181 let change_modrdn =
182      let attr_deleteoldrdn = [ key "deleteoldrdn" . attr_intflag . eol ]
183   in let attrs_modrdn = attr_dn_value "newrdn"
184                         | attr_dn_value "newsuperior"
185                         | attr_deleteoldrdn
186   in [ attr_changetype /modr?dn/ ]
187      . ( sep_line | attrs_modrdn )* . attrs_modrdn
188
189 (* View: change_record
190     changerecord = "changetype:" FILL (changeadd/delete/modify/moddn) *)
191 let change_record = ( change_add | change_delete | change_modify
192                       | change_modrdn)
193
194 (* View: change_control
195     "control:" FILL ldap-oid 0*1(1*SPACE ("true" / "false")) 0*1(value-spec) *)
196 let change_control =
197      let attr_criticality = [ Util.del_ws_spc . label "criticality"
198                               . store /true|false/ ]
199   in let attr_ctrlvalue   = [ label "value" . (attr_safe_string
200                               | attr_base64_string
201                               | attr_url_string ) ]
202   in [ key "control" . sep_colon . store ldapoid_re
203        . attr_criticality? . attr_ctrlvalue? . eol ]
204
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 ]
210
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 )+
216                      . sep_record ]
217
218 (************************************************************************
219  * Group:                     LENS
220  ************************************************************************)
221
222 (* View: lns *)
223 let lns = sep_record | ldif_content | ldif_changes
224
225 let filter = incl "/etc/openldap/schema/*.ldif"
226
227 let xfm = transform lns filter