(* an object oriented interface to ldap
Copyright (C) 2004 Eric Stokes, and The California State University
at Northridge
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
USA
*)
(** an object oriented ldap client interface *)
open Ldap_types
(** {2 Basic Data Types} *)
(** the type of an operation, eg. [("cn", ["foo";"bar"])] *)
type op = string * string list
type op_lst = op list
(** The policy the client should take when it encounteres a
referral. This is currently not used *)
type referral_policy = [ `FOLLOW | `RETURN ]
(** The change type of an ldapentry. This controls some aspects of
it's behavior *)
type changetype = [ `ADD | `DELETE | `MODDN | `MODIFY | `MODRDN ]
(** {2 Local Representation of LDAP Objects} *)
(** The base type of an ldap entry represented in memory. *)
class type ldapentry_t =
object
method add : op_lst -> unit
method attributes : string list
method changes : (Ldap_types.modify_optype * string * string list) list
method changetype : changetype
method delete : op_lst -> unit
method dn : string
method diff : ldapentry_t -> (modify_optype * string * string list) list
method exists : string -> bool
method flush_changes : unit
method get_value : string -> string list
method modify :
(Ldap_types.modify_optype * string * string list) list -> unit
method print : unit
method replace : op_lst -> unit
method set_changetype : changetype -> unit
method set_dn : string -> unit
end
(** this object represents a remote object within local memory. It
records all local changes made to it (if it's changetype is set to
`MODIFY), and can commit them to the server at a later time via
{!Ldap_ooclient.ldapcon.update_entry}. *)
class ldapentry :
object
(** add values to an attribute (or create a new attribute). Does
not change the server until you update *)
method add : op_lst -> unit
(** return a list of the type (name) of all the attributes present
on the object *)
method attributes : string list
(** return a list of changes made to the object in a the format of
a modify operation. For example, you can apply the changes to another
ldapentry object using the {!Ldap_ooclient.ldapentry.modify}
method *)
method changes : (Ldap_types.modify_optype * string * string list) list
(** return the changetype of the object *)
method changetype : changetype
(** delete attributes from the object, does not change the
directory until you update *)
method delete : op_lst -> unit
(** return the dn of the object *)
method dn : string
(** given an ldapentry, return the differences between the current
entry and the specified entry in the form of a modify
operation which would make the specified entry the same as the
current entry. *)
method diff : ldapentry_t -> (modify_optype * string * string list) list
(** query whether the attribute type (name) exists in the object *)
method exists : string -> bool
(** clear all accumulated changes *)
method flush_changes : unit
(** get the value of an attribute @raise Not_found If the
attribute does not exist. *)
method get_value : string -> string list
(** Apply modifications to object in memory, does not change the
database until you update using
{!Ldap_ooclient.ldapcon.update_entry} *)
method modify :
(Ldap_types.modify_optype * string * string list) list -> unit
(** @deprecated print an ldif like representation of the object to stdout, see
Ldif_oo for standards compliant ldif. Usefull for toplevel
sessions. *)
method print : unit
(** replace values in the object, does not change the database
until you call update *)
method replace : op_lst -> unit
(** set the changetype of the object *)
method set_changetype : changetype -> unit
(** set the dn of the object *)
method set_dn : string -> unit
end
(** {1 Miscallaneous} *)
(** toplevel formatter for ldapentry, prints the whole entry with a
nice structure. Each attribute is in the correct syntax to be
copied and pasted into a modify operation. *)
val format_entry :
< attributes : string list; dn : string;
get_value : string -> string list; .. > ->
unit
(** format lists of entries, in this case only print the dn *)
val format_entries :
< attributes : string list; dn : string;
get_value : string -> string list; .. > list ->
unit
(** The type of an ldap change record, used by extended LDIF *)
type changerec =
[`Modification of string * ((Ldap_types.modify_optype * string * string list) list)
| `Addition of ldapentry
| `Delete of string
| `Modrdn of string * int * string]
(** {0 Communication With {!Ldap_funclient}} *)
(** given a search_result_entry as returned by ldap_funclient, produce an
ldapentry containing either the entry, or the referral object *)
val to_entry :
[< `Entry of Ldap_types.search_result_entry | `Referral of string list ]
-> ldapentry
(** given an ldapentry as returned by ldapcon, or constructed manually,
produce a search_result_entry suitable for ldap_funclient, or
ldap_funserver. *)
val of_entry : ldapentry -> search_result_entry
(** {2 Interacting with LDAP Servers} *)
(** This class abstracts a connection to an LDAP server (or servers),
an instance will be connected to the server you specify and can be
used to perform operations on that server.
{0 Example}
[new ldapcon ~connect_timeout:5 ~version:3
["ldap://first.ldap.server";"ldap://second.ldap.server"]].
In addition to specifying multiple urls, if DNS names are given,
and those names are bound to multiple addresses, then all possible
addresses will be tried.
{0 Example}
[new ldapcon ["ldaps://rrldap.csun.edu"]]
is equivelant to
[new ldapcon ["ldap://130.166.1.30";"ldap://130.166.1.31";"ldap://130.166.1.32"]]
This means that if any host in the rr fails, the ldapcon will
transparently move on to the next host, and you will never know
the difference.
@raise LDAP_Failure All methods raise {!Ldap_types.LDAP_Failure} on error
@param connect_timeout Default [1], an integer which specifies how
long to wait for any given server in the list to respond before
trying the next one. After all the servers have been tried for
[connect_timeout] seconds [LDAP_Failure (`SERVER_DOWN, ...)] will
be raised.
@param referral_policy In a future version of ocamldap this will
be used to specify what you would like to do in the event of a
referral. Currently it does nothing and is ignored see
{!Ldap_ooclient.referral_policy}.
@param version The protocol version to use, the default is [3],
the other recognized value is [2].
*)
class ldapcon :
?connect_timeout:int ->
?referral_policy:[> `RETURN ] ->
?version:int ->
string list ->
object
(** {2 Authentication} *)
(** bind to the database using dn.
{0 Simple Bind Example}
[ldap#bind ~cred:"password" "cn=foo,ou=people,ou=auth,o=bar"]
To bind anonymously, omit ~cred, and leave dn blank eg.
{0 Example}
[ldap#bind ""]
@param cred The credentials to provide for binding. Default [""].
@param meth The method to use when binding See
{!Ldap_funclient.authmethod} the default is [`SIMPLE]. If
[`SASL] is used then [dn] and [~cred] Are interperted according
to the chosen SASL mechanism. SASL binds have not been tested
extensively. *)
method bind :
?cred:string -> ?meth:Ldap_funclient.authmethod -> string -> unit
(** Deauthenticate and close the connection to the server *)
method unbind : unit
(** {2 Searching} *)
(** Search the directory syncronously for an entry which matches the
search criteria.
{0 Example}
[ldap#search ~base:"dc=foo,dc=bar" ~attrs:["cn"] "uid=*"]
@param scope Default [`SUBTREE], defines the scope of the
search. see {!Ldap_types.search_scope}
@param attrs Default [[]] (means all attributes)
@param attrsonly Default [false] If true, asks the server to return
only the attribute names, not their values.
@param base Default [""], The search base, which is the dn of the
object from which you want to start your search. Only that
object, and it's children will be included in the
search. Further controlled by [~scope].
@param timelimit The time limit (in seconds) to allow the search
to run for. Default [0l], which means there is no user specified
time limit, the server may still impose one.
@param sizelimit The max number of entries to return from the
search (in number of entries) *)
method search :
?scope:Ldap_types.search_scope ->
?