|
Packit Service |
a2ae7a |
(*
|
|
Packit Service |
a2ae7a |
Module: Ldif
|
|
Packit Service |
a2ae7a |
Parses the LDAP Data Interchange Format (LDIF)
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
Author: Dominic Cleal <dcleal@redhat.com>
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
About: Reference
|
|
Packit Service |
a2ae7a |
This lens tries to keep as close as possible to RFC2849
|
|
Packit Service |
a2ae7a |
<http://tools.ietf.org/html/rfc2849>
|
|
Packit Service |
a2ae7a |
and OpenLDAP's ldif(5)
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
About: Licence
|
|
Packit Service |
a2ae7a |
This file is licensed under the LGPLv2+, like the rest of Augeas.
|
|
Packit Service |
a2ae7a |
*)
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
module Ldif =
|
|
Packit Service |
a2ae7a |
autoload xfm
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(************************************************************************
|
|
Packit Service |
a2ae7a |
* Group: USEFUL PRIMITIVES
|
|
Packit Service |
a2ae7a |
************************************************************************)
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(* View: comment *)
|
|
Packit Service |
a2ae7a |
let comment = Util.comment_generic /#[ \t]*/ "# "
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(* View: empty
|
|
Packit Service |
a2ae7a |
Map empty lines, including empty comments *)
|
|
Packit Service |
a2ae7a |
let empty = [ del /#?[ \t]*\n/ "\n" ]
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(* View: eol
|
|
Packit Service |
a2ae7a |
Only eol, don't include whitespace *)
|
|
Packit Service |
a2ae7a |
let eol = Util.del_str "\n"
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(* View: sep_colon
|
|
Packit Service |
a2ae7a |
The separator for attributes and values *)
|
|
Packit Service |
a2ae7a |
let sep_colon = del /:[ \t]*/ ": "
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(* View: sep_base64
|
|
Packit Service |
a2ae7a |
The separator for attributes and base64 encoded values *)
|
|
Packit Service |
a2ae7a |
let sep_base64 = del /::[ \t]*/ ":: "
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(* View: sep_url
|
|
Packit Service |
a2ae7a |
The separator for attributes and URL-sourced values *)
|
|
Packit Service |
a2ae7a |
let sep_url = del /:<[ \t]*/ ":< "
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(* Variable: ldapoid_re
|
|
Packit Service |
a2ae7a |
Format of an LDAP OID from RFC 2251 *)
|
|
Packit Service |
a2ae7a |
let ldapoid_re = /[0-9][0-9\.]*/
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(* View: sep_modspec
|
|
Packit Service |
a2ae7a |
Separator between modify operations *)
|
|
Packit Service |
a2ae7a |
let sep_modspec = Util.del_str "-" . eol
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(************************************************************************
|
|
Packit Service |
a2ae7a |
* Group: BASIC ATTRIBUTES
|
|
Packit Service |
a2ae7a |
************************************************************************)
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(* Different types of values, all permitting continuation where the next line
|
|
Packit Service |
a2ae7a |
begins with whitespace *)
|
|
Packit Service |
a2ae7a |
let attr_safe_string =
|
|
Packit Service |
a2ae7a |
let line = /[^ \t\n:<][^\n]*/
|
|
Packit Service |
a2ae7a |
in let lines = line . (/\n[ \t]+[^ \t\n][^\n]*/)*
|
|
Packit Service |
a2ae7a |
in sep_colon . store lines
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
let attr_base64_string =
|
|
Packit Service |
a2ae7a |
let line = /[a-zA-Z0-9=+]+/
|
|
Packit Service |
a2ae7a |
in let lines = line . (/\n[ \t]+/ . line)*
|
|
Packit Service |
a2ae7a |
in sep_base64 . [ label "@base64" . store lines ]
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
let attr_url_string =
|
|
Packit Service |
a2ae7a |
let line = /[^ \t\n][^\n]*/
|
|
Packit Service |
a2ae7a |
in let lines = line . (/\n[ \t]+/ . line)*
|
|
Packit Service |
a2ae7a |
in sep_url . [ label "@url" . store lines ]
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
let attr_intflag = sep_colon . store /0|1/
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(* View: attr_version
|
|
Packit Service |
a2ae7a |
version-spec = "version:" FILL version-number *)
|
|
Packit Service |
a2ae7a |
let attr_version = Build.key_value_line "version" sep_colon (store /[0-9]+/)
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(* View: attr_dn
|
|
Packit Service |
a2ae7a |
dn-spec = "dn:" (FILL distinguishedName /
|
|
Packit Service |
a2ae7a |
":" FILL base64-distinguishedName) *)
|
|
Packit Service |
a2ae7a |
let attr_dn = del /dn/i "dn"
|
|
Packit Service |
a2ae7a |
. ( attr_safe_string | attr_base64_string )
|
|
Packit Service |
a2ae7a |
. eol
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(* View: attr_type
|
|
Packit Service |
a2ae7a |
AttributeType = ldap-oid / (ALPHA *(attr-type-chars)) *)
|
|
Packit Service |
a2ae7a |
let attr_type = ldapoid_re | /[a-zA-Z][a-zA-Z0-9-]*/
|
|
Packit Service |
a2ae7a |
- /dn/i
|
|
Packit Service |
a2ae7a |
- /changeType/i
|
|
Packit Service |
a2ae7a |
- /include/i
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(* View: attr_option
|
|
Packit Service |
a2ae7a |
options = option / (option ";" options) *)
|
|
Packit Service |
a2ae7a |
let attr_option = Util.del_str ";"
|
|
Packit Service |
a2ae7a |
. [ label "@option" . store /[a-zA-Z0-9-]+/ ]
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(* View: attr_description
|
|
Packit Service |
a2ae7a |
Attribute name, possibly with options *)
|
|
Packit Service |
a2ae7a |
let attr_description = key attr_type . attr_option*
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(* View: attr_val_spec
|
|
Packit Service |
a2ae7a |
Generic attribute with a value *)
|
|
Packit Service |
a2ae7a |
let attr_val_spec = [ attr_description
|
|
Packit Service |
a2ae7a |
. ( attr_safe_string
|
|
Packit Service |
a2ae7a |
| attr_base64_string
|
|
Packit Service |
a2ae7a |
| attr_url_string )
|
|
Packit Service |
a2ae7a |
. eol ]
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(* View: attr_changetype
|
|
Packit Service |
a2ae7a |
Parameters:
|
|
Packit Service |
a2ae7a |
t:regexp - value of changeType *)
|
|
Packit Service |
a2ae7a |
let attr_changetype (t:regexp) =
|
|
Packit Service |
a2ae7a |
key /changeType/i . sep_colon . store t . eol
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(* View: attr_modspec *)
|
|
Packit Service |
a2ae7a |
let attr_modspec = key /add|delete|replace/ . sep_colon . store attr_type
|
|
Packit Service |
a2ae7a |
. attr_option* . eol
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(* View: attr_dn_value
|
|
Packit Service |
a2ae7a |
Parses an attribute line with a DN on the RHS
|
|
Packit Service |
a2ae7a |
Parameters:
|
|
Packit Service |
a2ae7a |
k:regexp - match attribute name as key *)
|
|
Packit Service |
a2ae7a |
let attr_dn_value (k:regexp) =
|
|
Packit Service |
a2ae7a |
[ key k . ( attr_safe_string | attr_base64_string ) . eol ]
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(* View: sep_line *)
|
|
Packit Service |
a2ae7a |
let sep_line = empty | comment
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(* View: attr_include
|
|
Packit Service |
a2ae7a |
OpenLDAP extension, must be separated by blank lines *)
|
|
Packit Service |
a2ae7a |
let attr_include = eol . [ key "include" . sep_colon
|
|
Packit Service |
a2ae7a |
. store /[^ \t\n][^\n]*/ . eol . comment* . eol ]
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(* View: sep_record *)
|
|
Packit Service |
a2ae7a |
let sep_record = ( sep_line | attr_include )*
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(************************************************************************
|
|
Packit Service |
a2ae7a |
* Group: LDIF CONTENT RECORDS
|
|
Packit Service |
a2ae7a |
************************************************************************)
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(* View: ldif_attrval_record
|
|
Packit Service |
a2ae7a |
ldif-attrval-record = dn-spec SEP 1*attrval-spec *)
|
|
Packit Service |
a2ae7a |
let ldif_attrval_record = [ seq "record"
|
|
Packit Service |
a2ae7a |
. attr_dn
|
|
Packit Service |
a2ae7a |
. ( sep_line* . attr_val_spec )+ ]
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(* View: ldif_content
|
|
Packit Service |
a2ae7a |
ldif-content = version-spec 1*(1*SEP ldif-attrval-record) *)
|
|
Packit Service |
a2ae7a |
let ldif_content = [ label "@content"
|
|
Packit Service |
a2ae7a |
. ( sep_record . attr_version )?
|
|
Packit Service |
a2ae7a |
. ( sep_record . ldif_attrval_record )+
|
|
Packit Service |
a2ae7a |
. sep_record ]
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(************************************************************************
|
|
Packit Service |
a2ae7a |
* Group: LDIF CHANGE RECORDS
|
|
Packit Service |
a2ae7a |
************************************************************************)
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(* View: change_add
|
|
Packit Service |
a2ae7a |
change-add = "add" SEP 1*attrval-spec *)
|
|
Packit Service |
a2ae7a |
let change_add = [ attr_changetype "add" ] . ( sep_line* . attr_val_spec )+
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(* View: change_delete
|
|
Packit Service |
a2ae7a |
change-delete = "add" SEP 1*attrval-spec *)
|
|
Packit Service |
a2ae7a |
let change_delete = [ attr_changetype "delete" ]
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(* View: change_modspec
|
|
Packit Service |
a2ae7a |
change-modspec = add/delete/replace: AttributeDesc SEP *attrval-spec "-" *)
|
|
Packit Service |
a2ae7a |
let change_modspec = attr_modspec . ( sep_line* . attr_val_spec )*
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(* View: change_modify
|
|
Packit Service |
a2ae7a |
change-modify = "modify" SEP *mod-spec *)
|
|
Packit Service |
a2ae7a |
let change_modify = [ attr_changetype "modify" ]
|
|
Packit Service |
a2ae7a |
. ( sep_line* . [ change_modspec
|
|
Packit Service |
a2ae7a |
. sep_line* . sep_modspec ] )+
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(* View: change_modrdn
|
|
Packit Service |
a2ae7a |
("modrdn" / "moddn") SEP newrdn/newsuperior/deleteoldrdn *)
|
|
Packit Service |
a2ae7a |
let change_modrdn =
|
|
Packit Service |
a2ae7a |
let attr_deleteoldrdn = [ key "deleteoldrdn" . attr_intflag . eol ]
|
|
Packit Service |
a2ae7a |
in let attrs_modrdn = attr_dn_value "newrdn"
|
|
Packit Service |
a2ae7a |
| attr_dn_value "newsuperior"
|
|
Packit Service |
a2ae7a |
| attr_deleteoldrdn
|
|
Packit Service |
a2ae7a |
in [ attr_changetype /modr?dn/ ]
|
|
Packit Service |
a2ae7a |
. ( sep_line | attrs_modrdn )* . attrs_modrdn
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(* View: change_record
|
|
Packit Service |
a2ae7a |
changerecord = "changetype:" FILL (changeadd/delete/modify/moddn) *)
|
|
Packit Service |
a2ae7a |
let change_record = ( change_add | change_delete | change_modify
|
|
Packit Service |
a2ae7a |
| change_modrdn)
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(* View: change_control
|
|
Packit Service |
a2ae7a |
"control:" FILL ldap-oid 0*1(1*SPACE ("true" / "false")) 0*1(value-spec) *)
|
|
Packit Service |
a2ae7a |
let change_control =
|
|
Packit Service |
a2ae7a |
let attr_criticality = [ Util.del_ws_spc . label "criticality"
|
|
Packit Service |
a2ae7a |
. store /true|false/ ]
|
|
Packit Service |
a2ae7a |
in let attr_ctrlvalue = [ label "value" . (attr_safe_string
|
|
Packit Service |
a2ae7a |
| attr_base64_string
|
|
Packit Service |
a2ae7a |
| attr_url_string ) ]
|
|
Packit Service |
a2ae7a |
in [ key "control" . sep_colon . store ldapoid_re
|
|
Packit Service |
a2ae7a |
. attr_criticality? . attr_ctrlvalue? . eol ]
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(* View: ldif_change_record
|
|
Packit Service |
a2ae7a |
ldif-change-record = dn-spec SEP *control changerecord *)
|
|
Packit Service |
a2ae7a |
let ldif_change_record = [ seq "record" . attr_dn
|
|
Packit Service |
a2ae7a |
. ( ( sep_line | change_control )* . change_control )?
|
|
Packit Service |
a2ae7a |
. sep_line* . change_record ]
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(* View: ldif_changes
|
|
Packit Service |
a2ae7a |
ldif-changes = version-spec 1*(1*SEP ldif-change-record) *)
|
|
Packit Service |
a2ae7a |
let ldif_changes = [ label "@changes"
|
|
Packit Service |
a2ae7a |
. ( sep_record . attr_version )?
|
|
Packit Service |
a2ae7a |
. ( sep_record . ldif_change_record )+
|
|
Packit Service |
a2ae7a |
. sep_record ]
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(************************************************************************
|
|
Packit Service |
a2ae7a |
* Group: LENS
|
|
Packit Service |
a2ae7a |
************************************************************************)
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
(* View: lns *)
|
|
Packit Service |
a2ae7a |
let lns = sep_record | ldif_content | ldif_changes
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
let filter = incl "/etc/openldap/schema/*.ldif"
|
|
Packit Service |
a2ae7a |
|
|
Packit Service |
a2ae7a |
let xfm = transform lns filter
|