
<!DOCTYPE html><html><head>
<title>ldap - LDAP client</title>
<style type="text/css"><!--
    HTML {
	background: 	#FFFFFF;
	color: 		black;
    }
    BODY {
	background: 	#FFFFFF;
	color:	 	black;
    }
    DIV.doctools {
	margin-left:	10%;
	margin-right:	10%;
    }
    DIV.doctools H1,DIV.doctools H2 {
	margin-left:	-5%;
    }
    H1, H2, H3, H4 {
	margin-top: 	1em;
	font-family:	sans-serif;
	font-size:	large;
	color:		#005A9C;
	background: 	transparent;
	text-align:		left;
    }
    H1.doctools_title {
	text-align: center;
    }
    UL,OL {
	margin-right: 0em;
	margin-top: 3pt;
	margin-bottom: 3pt;
    }
    UL LI {
	list-style: disc;
    }
    OL LI {
	list-style: decimal;
    }
    DT {
	padding-top: 	1ex;
    }
    UL.doctools_toc,UL.doctools_toc UL, UL.doctools_toc UL UL {
	font:		normal 12pt/14pt sans-serif;
	list-style:	none;
    }
    LI.doctools_section, LI.doctools_subsection {
	list-style: 	none;
	margin-left: 	0em;
	text-indent:	0em;
	padding: 	0em;
    }
    PRE {
	display: 	block;
	font-family:	monospace;
	white-space:	pre;
	margin:		0%;
	padding-top:	0.5ex;
	padding-bottom:	0.5ex;
	padding-left:	1ex;
	padding-right:	1ex;
	width:		100%;
    }
    PRE.doctools_example {
	color: 		black;
	background: 	#f5dcb3;
	border:		1px solid black;
    }
    UL.doctools_requirements LI, UL.doctools_syntax LI {
	list-style: 	none;
	margin-left: 	0em;
	text-indent:	0em;
	padding:	0em;
    }
    DIV.doctools_synopsis {
	color: 		black;
	background: 	#80ffff;
	border:		1px solid black;
	font-family:	serif;
	margin-top: 	1em;
	margin-bottom: 	1em;
    }
    UL.doctools_syntax {
	margin-top: 	1em;
	border-top:	1px solid black;
    }
    UL.doctools_requirements {
	margin-bottom: 	1em;
	border-bottom:	1px solid black;
    }
--></style>
</head>
<!-- Generated from file 'ldap.man' by tcllib/doctools with format 'html'
   -->
<!-- Copyright &amp;copy; 2004 Andreas Kupries &amp;lt;andreas_kupries@users.sourceforge.net&amp;gt;   -- Copyright &amp;copy; 2004 Jochen Loewer &amp;lt;loewerj@web.de&amp;gt;   -- Copyright &amp;copy; 2006 Michael Schlenker &amp;lt;mic42@users.sourceforge.net&amp;gt;
   -->
<!-- ldap.n
   -->
<body><hr> [
   <a href="../../../../../../../../home">Tcllib Home</a>
| <a href="../../../../toc.html">Main Table Of Contents</a>
| <a href="../../../toc.html">Table Of Contents</a>
| <a href="../../../../index.html">Keyword Index</a>
| <a href="../../../../toc0.html">Categories</a>
| <a href="../../../../toc1.html">Modules</a>
| <a href="../../../../toc2.html">Applications</a>
 ] <hr>
<div class="doctools">
<h1 class="doctools_title">ldap(n) 1.9.2 tcllib &quot;LDAP client&quot;</h1>
<div id="name" class="doctools_section"><h2><a name="name">Name</a></h2>
<p>ldap - LDAP client</p>
</div>
<div id="toc" class="doctools_section"><h2><a name="toc">Table Of Contents</a></h2>
<ul class="doctools_toc">
<li class="doctools_section"><a href="#toc">Table Of Contents</a></li>
<li class="doctools_section"><a href="#synopsis">Synopsis</a></li>
<li class="doctools_section"><a href="#section1">Description</a></li>
<li class="doctools_section"><a href="#section2">TLS Security Considerations</a></li>
<li class="doctools_section"><a href="#section3">COMMANDS</a></li>
<li class="doctools_section"><a href="#section4">EXAMPLES</a></li>
<li class="doctools_section"><a href="#section5">Bugs, Ideas, Feedback</a></li>
<li class="doctools_section"><a href="#keywords">Keywords</a></li>
<li class="doctools_section"><a href="#category">Category</a></li>
<li class="doctools_section"><a href="#copyright">Copyright</a></li>
</ul>
</div>
<div id="synopsis" class="doctools_section"><h2><a name="synopsis">Synopsis</a></h2>
<div class="doctools_synopsis">
<ul class="doctools_requirements">
<li>package require <b class="pkgname">Tcl 8.4</b></li>
<li>package require <b class="pkgname">ldap <span class="opt">?1.9.2?</span></b></li>
</ul>
<ul class="doctools_syntax">
<li><a href="#1"><b class="cmd">::ldap::connect</b> <i class="arg">host</i> <span class="opt">?<i class="arg">port</i>?</span></a></li>
<li><a href="#2"><b class="cmd">::ldap::secure_connect</b> <i class="arg">host</i> <span class="opt">?<i class="arg">port</i>?</span> <span class="opt">?<i class="arg">verify_cert</i>?</span> <span class="opt">?<i class="arg">sni_servername</i>?</span></a></li>
<li><a href="#3"><b class="cmd">::ldap::disconnect</b> <i class="arg">handle</i></a></li>
<li><a href="#4"><b class="cmd">::ldap::starttls</b> <i class="arg">handle</i> <span class="opt">?<i class="arg">cafile</i>?</span> <span class="opt">?<i class="arg">certfile</i>?</span> <span class="opt">?<i class="arg">keyfile</i>?</span> <span class="opt">?<i class="arg">verify_cert</i>?</span> <span class="opt">?<i class="arg">sni_servername</i>?</span></a></li>
<li><a href="#5"><b class="cmd">::ldap::bind</b> <i class="arg">handle</i> <span class="opt">?<i class="arg">name</i>?</span> <span class="opt">?<i class="arg">password</i>?</span></a></li>
<li><a href="#6"><b class="cmd">::ldap::bindSASL</b> <i class="arg">handle</i> <span class="opt">?<i class="arg">name</i>?</span> <span class="opt">?<i class="arg">password</i>?</span></a></li>
<li><a href="#7"><b class="cmd">::ldap::unbind</b> <i class="arg">handle</i></a></li>
<li><a href="#8"><b class="cmd">::ldap::search</b> <i class="arg">handle</i> <i class="arg">baseObject</i> <i class="arg">filterString</i> <i class="arg">attributes</i> <i class="arg">options</i></a></li>
<li><a href="#9"><b class="cmd">::ldap::searchInit</b> <i class="arg">handle</i> <i class="arg">baseObject</i> <i class="arg">filterString</i> <i class="arg">attributes</i> <i class="arg">options</i></a></li>
<li><a href="#10"><b class="cmd">::ldap::searchNext</b> <i class="arg">handle</i></a></li>
<li><a href="#11"><b class="cmd">::ldap::searchEnd</b> <i class="arg">handle</i></a></li>
<li><a href="#12"><b class="cmd">::ldap::modify</b> <i class="arg">handle</i> <i class="arg">dn</i> <i class="arg">attrValToReplace</i> <span class="opt">?<i class="arg">attrToDelete</i>?</span> <span class="opt">?<i class="arg">attrValToAdd</i>?</span></a></li>
<li><a href="#13"><b class="cmd">::ldap::modifyMulti</b> <i class="arg">handle</i> <i class="arg">dn</i> <i class="arg">attrValToReplace</i> <span class="opt">?<i class="arg">attrValToDelete</i>?</span> <span class="opt">?<i class="arg">attrValToAdd</i>?</span></a></li>
<li><a href="#14"><b class="cmd">::ldap::add</b> <i class="arg">handle</i> <i class="arg">dn</i> <i class="arg">attrValueTuples</i></a></li>
<li><a href="#15"><b class="cmd">::ldap::addMulti</b> <i class="arg">handle</i> <i class="arg">dn</i> <i class="arg">attrValueTuples</i></a></li>
<li><a href="#16"><b class="cmd">::ldap::delete</b> <i class="arg">handle</i> <i class="arg">dn</i></a></li>
<li><a href="#17"><b class="cmd">::ldap::modifyDN</b> <i class="arg">handle</i> <i class="arg">dn</i> <i class="arg">newrdn</i> <span class="opt">?<i class="arg">deleteOld</i>?</span> <span class="opt">?<i class="arg">newSuperior</i>?</span></a></li>
<li><a href="#18"><b class="cmd">::ldap::info</b> <b class="cmd"><a href="../../../../index.html#ip">ip</a></b> <i class="arg">handle</i></a></li>
<li><a href="#19"><b class="cmd">::ldap::info</b> <b class="cmd">bound</b> <i class="arg">handle</i></a></li>
<li><a href="#20"><b class="cmd">::ldap::info</b> <b class="cmd">bounduser</b> <i class="arg">handle</i></a></li>
<li><a href="#21"><b class="cmd">::ldap::info</b> <b class="cmd">connections</b></a></li>
<li><a href="#22"><b class="cmd">::ldap::info</b> <b class="cmd"><a href="../../../../index.html#tls">tls</a></b> <i class="arg">handle</i></a></li>
<li><a href="#23"><b class="cmd">::ldap::info</b> <b class="cmd">saslmechanisms</b> <i class="arg">handle</i></a></li>
<li><a href="#24"><b class="cmd">::ldap::info</b> <b class="cmd"><a href="../control/control.html">control</a></b> <i class="arg">handle</i></a></li>
<li><a href="#25"><b class="cmd">::ldap::info</b> <b class="cmd">extensions</b> <i class="arg">extensions</i></a></li>
<li><a href="#26"><b class="cmd">::ldap::info</b> <b class="cmd">whoami</b> <i class="arg">handle</i></a></li>
</ul>
</div>
</div>
<div id="section1" class="doctools_section"><h2><a name="section1">Description</a></h2>
<p>The <b class="package">ldap</b> package provides a Tcl-only client library
for the LDAPv3 protocol as specified in
RFC 4511 (<a href="http://www.rfc-editor.org/rfc/rfc4511.txt">http://www.rfc-editor.org/rfc/rfc4511.txt</a>).
It works by opening the standard (or secure) LDAP socket on the
server, and then providing a Tcl API to access the LDAP protocol
commands.  All server errors are returned as Tcl errors (thrown) which
must be caught with the Tcl <b class="cmd">catch</b> command.</p>
</div>
<div id="section2" class="doctools_section"><h2><a name="section2">TLS Security Considerations</a></h2>
<p>This package uses the <b class="package"><a href="../../../../index.html#tls">TLS</a></b> package to handle the
security for <b class="const">https</b> urls and other socket connections.</p>
<p>Policy decisions like the set of protocols to support and what
ciphers to use are not the responsibility of <b class="package"><a href="../../../../index.html#tls">TLS</a></b>, nor of
this package itself however.
Such decisions are the responsibility of whichever application is
using the package, and are likely influenced by the set of servers
the application will talk to as well.</p>
<p>For example, in light of the recent
<a href="http://googleonlinesecurity.blogspot.co.uk/2014/10/this-poodle-bites-exploiting-ssl-30.html">POODLE attack</a> discovered by Google many servers will disable support
for the SSLv3 protocol.
To handle this change the applications using <b class="package"><a href="../../../../index.html#tls">TLS</a></b> must be
patched, and not this package, nor <b class="package"><a href="../../../../index.html#tls">TLS</a></b> itself.
Such a patch may be as simple as generally activating <b class="const">tls1</b>
support, as shown in the example below.</p>
<pre class="doctools_example">
    package require tls
    tls::init -tls1 1 ;# forcibly activate support for the TLS1 protocol
    ... your own application code ...
</pre>
</div>
<div id="section3" class="doctools_section"><h2><a name="section3">COMMANDS</a></h2>
<dl class="doctools_definitions">
<dt><a name="1"><b class="cmd">::ldap::connect</b> <i class="arg">host</i> <span class="opt">?<i class="arg">port</i>?</span></a></dt>
<dd><p>Opens a LDAPv3 connection to the specified <i class="arg">host</i>, at the given
<i class="arg">port</i>, and returns a token for the connection. This token is the
<i class="arg">handle</i> argument for all other commands. If no <i class="arg">port</i> is
specified it will default to <b class="const">389</b>.</p>
<p>The command blocks until the connection has been established, or
establishment definitely failed.</p></dd>
<dt><a name="2"><b class="cmd">::ldap::secure_connect</b> <i class="arg">host</i> <span class="opt">?<i class="arg">port</i>?</span> <span class="opt">?<i class="arg">verify_cert</i>?</span> <span class="opt">?<i class="arg">sni_servername</i>?</span></a></dt>
<dd><p>Like <b class="cmd">::ldap::connect</b>, except that the created connection is
secured by SSL. The port defaults to <b class="const">636</b>.  This command
depends on the availability of the package <b class="package"><a href="../../../../index.html#tls">TLS</a></b>, which is a
SSL binding for Tcl. If <b class="package"><a href="../../../../index.html#tls">TLS</a></b> is not available, then this
command will fail.</p>
<p>The command blocks until the connection has been established, or
establishment definitely failed.</p>
<p>If <i class="arg">verify_cert</i> is set to 1, the default, this checks the server certificate against
the known hosts. If <i class="arg">sni_servername</i> is set, the given hostname is used as the 
hostname for Server Name Indication in the TLS handshake.</p>
<p>Use <b class="cmd">::tls::init</b> to setup defaults for trusted certificates.</p>
<pre class="doctools_example">
    tls::init -cadir /etc/ssl/certs/ca-certificates.crt
</pre>
<p>TLS supports different protocol levels. In common use are the versions 1.0, 1.1 and 1.2.
By default all those versions are offered. If you need to modify the acceptable
protocols, you can change the ::ldap::tlsProtocols list.</p></dd>
<dt><a name="3"><b class="cmd">::ldap::disconnect</b> <i class="arg">handle</i></a></dt>
<dd><p>Closes the ldap connection refered to by the token
<i class="arg">handle</i>. Returns the empty string as its result.</p></dd>
<dt><a name="4"><b class="cmd">::ldap::starttls</b> <i class="arg">handle</i> <span class="opt">?<i class="arg">cafile</i>?</span> <span class="opt">?<i class="arg">certfile</i>?</span> <span class="opt">?<i class="arg">keyfile</i>?</span> <span class="opt">?<i class="arg">verify_cert</i>?</span> <span class="opt">?<i class="arg">sni_servername</i>?</span></a></dt>
<dd><p>Start TLS negotiation on the connection denoted by <i class="arg">handle</i>.
You need to set at least the <i class="arg">cafile</i> argument to a file with trusted certificates, if <i class="arg">verify_cert</i> is 1, which is the default.
The <i class="arg">sni_servername</i> can be used to signal a different hostname during the TLS handshake.
The announced protocols are determined in the same way as <b class="cmd">::ldap::secure_connect</b>.
You can specify a TLS client certificate with the <i class="arg">certfile</i> and <i class="arg">keyfile</i> options.</p></dd>
<dt><a name="5"><b class="cmd">::ldap::bind</b> <i class="arg">handle</i> <span class="opt">?<i class="arg">name</i>?</span> <span class="opt">?<i class="arg">password</i>?</span></a></dt>
<dd><p>This command authenticates the ldap connection refered to by the token
in <i class="arg">handle</i>, with a user name and associated password. It blocks
until a response from the ldap server arrives. Its result is the empty
string.
Both <i class="arg">name</i> and <i class="arg">passwd</i> default to the empty string if they
are not specified.
By leaving out <i class="arg">name</i> and <i class="arg">passwd</i> you can make an anonymous bind to
the ldap server.
You can issue <b class="cmd">::ldap::bind</b> again to bind with different credentials.</p></dd>
<dt><a name="6"><b class="cmd">::ldap::bindSASL</b> <i class="arg">handle</i> <span class="opt">?<i class="arg">name</i>?</span> <span class="opt">?<i class="arg">password</i>?</span></a></dt>
<dd><p>This command uses SASL authentication mechanisms to do a multistage bind.
Its otherwise identical to the standard <b class="cmd">::ldap::bind</b>.
This feature is currently experimental and subject to change. See the documentation
for the <b class="package"><a href="../sasl/sasl.html">SASL</a></b> and the &quot;<b class="file">SASL.txt</b>&quot; in the tcllib CVS repository for
details how to setup and use SASL with openldap.</p></dd>
<dt><a name="7"><b class="cmd">::ldap::unbind</b> <i class="arg">handle</i></a></dt>
<dd><p>This command asks the ldap server to release the last bind done for
the connection refered to by the token in <i class="arg">handle</i>.
The <i class="arg">handle</i> is invalid after the unbind, as the server closes the connection.
So this is effectivly just a more polite disconnect operation.</p></dd>
<dt><a name="8"><b class="cmd">::ldap::search</b> <i class="arg">handle</i> <i class="arg">baseObject</i> <i class="arg">filterString</i> <i class="arg">attributes</i> <i class="arg">options</i></a></dt>
<dd><p>This command performs a LDAP search below the <i class="arg">baseObject</i> tree
using a complex LDAP search expression <i class="arg">filterString</i> and returns
the specified <i class="arg">attributes</i> of all matching objects (DNs). If the
list of <i class="arg">attributes</i> was empty all attributes are returned. The
command blocks until it has received all results.
The valid <i class="arg">options</i> are identical to the options listed for <b class="cmd">::ldap::searchInit</b>.</p>
<p>An example of a search expression is</p>
<pre class="doctools_example">
    set filterString &quot;|(cn=Linus*)(sn=Torvalds*)&quot;
</pre>
<p>The return value of the command is a list of nested dictionaries. The
first level keys are object identifiers (DNs), second levels keys are
attribute names. In other words, it is in the form</p>
<pre class="doctools_example">
    {dn1 {attr1 {val11 val12 ...} attr2 {val21...} ...}} {dn2 {a1 {v11 ...} ...}} ...
</pre>
</dd>
<dt><a name="9"><b class="cmd">::ldap::searchInit</b> <i class="arg">handle</i> <i class="arg">baseObject</i> <i class="arg">filterString</i> <i class="arg">attributes</i> <i class="arg">options</i></a></dt>
<dd><p>This command initiates a LDAP search below the <i class="arg">baseObject</i> tree
using a complex LDAP search expression <i class="arg">filterString</i>.
The search gets the specified <i class="arg">attributes</i> of all matching objects (DNs).
The command itself just starts the search, to retrieve the actual results, use
<b class="cmd">::ldap::searchNext</b>.
A search can be terminated at any time by
<b class="cmd">::ldap::searchEnd</b>. This informs the server that no further results should be sent by sending and ABANDON message
and cleans up the internal state of the search.
Only one <b class="cmd">::ldap::search</b> can be active at a given time, this
includes the introspection commands <b class="cmd">::ldap::info saslmechanisms</b>, <b class="cmd">ldap::info control</b> and
<b class="cmd">ldap::info extensions</b>, which invoke a search internally.
Error responses from the server due to wrong arguments or similar things are returned
with the first <b class="cmd">::ldap::searchNext</b> call and should be checked and dealed with there.
If the list of requested <i class="arg">attributes</i> is empty all attributes will be returned.
The parameter <i class="arg">options</i> specifies the options to be used in the search,
and has the following format:</p>
<pre class="doctools_example">
    {-option1 value1 -option2 value2 ... }
</pre>
<p>Following options are available:</p>
<dl class="doctools_options">
<dt><b class="option">-scope</b> base one sub</dt>
<dd><p>Control the scope of the search to be one of <b class="const">base</b>, <b class="const">one</b>, or <b class="const">sub</b>,  to  specify  a  base
object,  one-level or  subtree  search.   The  default is <b class="const">sub</b>.</p></dd>
<dt><b class="option">-derefaliases</b> never search find always</dt>
<dd><p>Control how aliases dereferencing is done.  Should be one of <b class="const">never</b>, <b class="const">always</b>, <b class="const">search</b>,  or  <b class="const">find</b>  to
specify that aliases are never dereferenced, always dereferenced, dereferenced when searching, or
dereferenced only when locating the base object for the search.
The default is to never dereference aliases.</p></dd>
<dt><b class="option">-sizelimit</b> num</dt>
<dd><p>Determines the maximum number of entries to return in a search. If specified as
0 no limit is enforced. The server may enforce a configuration dependent sizelimit,
which may be lower than the one given by this option. The default is 0, no limit.</p></dd>
<dt><b class="option">-timelimit</b> seconds</dt>
<dd><p>Asks the server to use a timelimit of <i class="arg">seconds</i> for the search. Zero means no
limit. The default is 0, no limit.</p></dd>
<dt><b class="option">-attrsonly</b> boolean</dt>
<dd><p>If set to 1 only the attribute names but not the values will be present in the search result.
The default is to retrieve attribute names and values.</p></dd>
<dt><b class="option">-referencevar</b> varname</dt>
<dd><p>If set the search result reference LDAPURIs, if any, are returned in the given variable.
The caller can than decide to follow those references and query other LDAP servers for
further results.</p></dd>
</dl></dd>
<dt><a name="10"><b class="cmd">::ldap::searchNext</b> <i class="arg">handle</i></a></dt>
<dd><p>This command returns the next entry from a LDAP search initiated
by <b class="cmd">::ldap::searchInit</b>. It returns only after a new result is received
or when no further results are available, but takes care to keep
the event loop alive.
The returned entry is a list with
two elements: the first is the DN of the entry, the second is the
list of attributes and values, under the format:</p>
<pre class="doctools_example">
    dn {attr1 {val11 val12 ...} attr2 {val21...} ...}
</pre>
<p>The <b class="cmd">::ldap::searchNext</b> command returns an empty list at the
end of the search.</p></dd>
<dt><a name="11"><b class="cmd">::ldap::searchEnd</b> <i class="arg">handle</i></a></dt>
<dd><p>This command terminates a LDAP search initiated
by <b class="cmd">::ldap::searchInit</b>. It also cleans up
the internal state so a new search can be initiated.
If the client has not yet received all results, the client
sends an ABANDON message to inform the server that no
further results for the previous search should to be sent.</p></dd>
<dt><a name="12"><b class="cmd">::ldap::modify</b> <i class="arg">handle</i> <i class="arg">dn</i> <i class="arg">attrValToReplace</i> <span class="opt">?<i class="arg">attrToDelete</i>?</span> <span class="opt">?<i class="arg">attrValToAdd</i>?</span></a></dt>
<dd><p>This command modifies the object <i class="arg">dn</i> on the ldap server we are
connected to via <i class="arg">handle</i>. It replaces attributes with new values,
deletes attributes, and adds new attributes with new values.
All arguments are dictionaries mapping attribute names to values. The
optional arguments default to the empty dictionary, which means that
no attributes will be deleted nor added.</p>
<dl class="doctools_arguments">
<dt>dictionary <i class="arg">attrValToReplace</i> (in)</dt>
<dd><p>No attributes will be changed if this argument is empty. The
dictionary contains the new attributes and their values. They
<em>replace all</em> attributes known to the object.</p></dd>
<dt>dictionary <i class="arg">attrToDelete</i> (in)</dt>
<dd><p>No attributes will be deleted if this argument is empty. The
dictionary values are restrictions on the deletion. An attribute
listed here will be deleted if and only if its current value at the
server matches the value specified in the dictionary, or if the value
in the dictionary is the empty string.</p></dd>
<dt>dictionary <i class="arg">attrValToAdd</i> (in)</dt>
<dd><p>No attributes will be added if this argument is empty. The dictionary
values are the values for the new attributes.</p></dd>
</dl>
<p>The command blocks until all modifications have completed. Its result
is the empty string.</p></dd>
<dt><a name="13"><b class="cmd">::ldap::modifyMulti</b> <i class="arg">handle</i> <i class="arg">dn</i> <i class="arg">attrValToReplace</i> <span class="opt">?<i class="arg">attrValToDelete</i>?</span> <span class="opt">?<i class="arg">attrValToAdd</i>?</span></a></dt>
<dd><p>This command modifies the object <i class="arg">dn</i> on the ldap server we are
connected to via <i class="arg">handle</i>. It replaces attributes with new values,
deletes attributes, and adds new attributes with new values.
All arguments are lists with the format:</p>
<pre class="doctools_example">
    attr1 {val11 val12 ...} attr2 {val21...} ...
</pre>
<p>where each value list may be empty for deleting all attributes.
The optional arguments default to empty lists of attributes to
delete and to add.</p>
<dl class="doctools_arguments">
<dt>list <i class="arg">attrValToReplace</i> (in)</dt>
<dd><p>No attributes will be changed if this argument is empty. The
dictionary contains the new attributes and their values. They
<em>replace all</em> attributes known to the object.</p></dd>
<dt>list <i class="arg">attrValToDelete</i> (in)</dt>
<dd><p>No attributes will be deleted if this argument is empty. If no
value is specified, the whole set of values for an attribute
will be deleted.</p></dd>
<dt>list <i class="arg">attrValToAdd</i> (in)</dt>
<dd><p>No attributes will be added if this argument is empty.</p></dd>
</dl>
<p>The command blocks until all modifications have completed. Its result
is the empty string.</p></dd>
<dt><a name="14"><b class="cmd">::ldap::add</b> <i class="arg">handle</i> <i class="arg">dn</i> <i class="arg">attrValueTuples</i></a></dt>
<dd><p>This command creates a new object using the specified <i class="arg">dn</i>. The
attributes of the new object are set to the values in the list
<i class="arg">attrValueTuples</i>.
Multiple valuated attributes may be specified using multiple tuples.
The command blocks until the operation has completed. Its result
is the empty string.</p></dd>
<dt><a name="15"><b class="cmd">::ldap::addMulti</b> <i class="arg">handle</i> <i class="arg">dn</i> <i class="arg">attrValueTuples</i></a></dt>
<dd><p>This command is the preferred one to create
a new object using the specified <i class="arg">dn</i>. The
attributes of the new object are set to the values in the dictionary
<i class="arg">attrValueTuples</i> (which is keyed by the attribute names).
Each tuple is a list containing multiple values.
The command blocks until the operation has completed. Its result
is the empty string.</p></dd>
<dt><a name="16"><b class="cmd">::ldap::delete</b> <i class="arg">handle</i> <i class="arg">dn</i></a></dt>
<dd><p>This command removes the object specified by <i class="arg">dn</i>, and all its
attributes from the server.
The command blocks until the operation has completed. Its result
is the empty string.</p></dd>
<dt><a name="17"><b class="cmd">::ldap::modifyDN</b> <i class="arg">handle</i> <i class="arg">dn</i> <i class="arg">newrdn</i> <span class="opt">?<i class="arg">deleteOld</i>?</span> <span class="opt">?<i class="arg">newSuperior</i>?</span></a></dt>
<dd><p>This command moves or copies the object specified by <i class="arg">dn</i>
to a new location in the tree of object. This location is
specified by <i class="arg">newrdn</i>, a <em>relative</em> designation,
or by <i class="arg">newrdn</i> and <i class="arg">newSuperior</i>, a <em>absolute</em> designation.
The optional argument <i class="arg">deleteOld</i> defaults to <b class="const">true</b>,
i.e. a move operation. If <i class="arg">deleteOld</i> is not set, then the
operation will create a copy of <i class="arg">dn</i> in the new location.
The optional argument <i class="arg">newSuperior</i> defaults an empty string,
meaning that the object must not be relocated in another branch of
the tree. If this argument is given, the argument <i class="arg">deleteOld</i>
must be specified also.
The command blocks until the operation has completed. Its result
is the empty string.</p></dd>
<dt><a name="18"><b class="cmd">::ldap::info</b> <b class="cmd"><a href="../../../../index.html#ip">ip</a></b> <i class="arg">handle</i></a></dt>
<dd><p>This command returns the IP address of the remote LDAP server the handle is connected to.</p></dd>
<dt><a name="19"><b class="cmd">::ldap::info</b> <b class="cmd">bound</b> <i class="arg">handle</i></a></dt>
<dd><p>This command returns 1 if a handle has successfully completed a <b class="cmd">::ldap::bind</b>.
If no bind was done or it failed, a 0 is returned.</p></dd>
<dt><a name="20"><b class="cmd">::ldap::info</b> <b class="cmd">bounduser</b> <i class="arg">handle</i></a></dt>
<dd><p>This command returns the username used in the bind operation if a handle has successfully completed a <b class="cmd">::ldap::bind</b>.
If no bound was done or it failed, an empty string is returned.</p></dd>
<dt><a name="21"><b class="cmd">::ldap::info</b> <b class="cmd">connections</b></a></dt>
<dd><p>This command returns all currently existing ldap connection handles.</p></dd>
<dt><a name="22"><b class="cmd">::ldap::info</b> <b class="cmd"><a href="../../../../index.html#tls">tls</a></b> <i class="arg">handle</i></a></dt>
<dd><p>This command returns 1 if the ldap connection <i class="arg">handle</i> used TLS/SSL for
connection via <b class="cmd">ldap::secure_connect</b> or completed <b class="cmd">ldap::starttls</b>, 0 otherwise.</p></dd>
<dt><a name="23"><b class="cmd">::ldap::info</b> <b class="cmd">saslmechanisms</b> <i class="arg">handle</i></a></dt>
<dd><p>Return the supported SASL mechanisms advertised by the server. Only valid in a
bound state (anonymous or other).</p></dd>
<dt><a name="24"><b class="cmd">::ldap::info</b> <b class="cmd"><a href="../control/control.html">control</a></b> <i class="arg">handle</i></a></dt>
<dd><p>Return the supported controls advertised by the server as a list of OIDs. Only valid in a bound state.
This is currently experimental and subject to change.</p></dd>
<dt><a name="25"><b class="cmd">::ldap::info</b> <b class="cmd">extensions</b> <i class="arg">extensions</i></a></dt>
<dd><p>Returns the supported LDAP extensions as list of OIDs. Only valid in a bound state.
This is currently experimental and subject to change.</p></dd>
<dt><a name="26"><b class="cmd">::ldap::info</b> <b class="cmd">whoami</b> <i class="arg">handle</i></a></dt>
<dd><p>Returns authzId for the current connection. This implements the RFC 4532
protocol extension.</p></dd>
</dl>
</div>
<div id="section4" class="doctools_section"><h2><a name="section4">EXAMPLES</a></h2>
<p>A small example, extracted from the test application coming with this
code.</p>
<pre class="doctools_example">
    package require ldap
    # Connect, bind, add a new object, modify it in various ways
    set handle [ldap::connect localhost 9009]
    set dn &quot;cn=Manager, o=University of Michigan, c=US&quot;
    set pw secret
    ldap::bind $handle $dn $pw
    set dn &quot;cn=Test User,ou=People,o=University of Michigan,c=US&quot;
    ldap::add $handle $dn {
	objectClass     OpenLDAPperson
	cn              {Test User}
	mail            test.user@google.com
	uid             testuid
	sn              User
	telephoneNumber +31415926535
	telephoneNumber +27182818285
    }
    set dn &quot;cn=Another User,ou=People,o=University of Michigan,c=US&quot;
    ldap::addMulti $handle $dn {
	objectClass     {OpenLDAPperson}
	cn              {{Anotther User}}
	mail            {test.user@google.com}
	uid             {testuid}
	sn              {User}
	telephoneNumber {+31415926535 +27182818285}
    }
    # Replace all attributes
    ldap::modify $handle $dn [list drink icetea uid JOLO]
    # Add some more
    ldap::modify $handle $dn {} {} [list drink water  drink orangeJuice pager &quot;+1 313 555 7671&quot;]
    # Delete
    ldap::modify $handle $dn {} [list drink water  pager &quot;&quot;]
    # Move
    ldap::modifyDN $handle $dn &quot;cn=Tester&quot;
    # Kill the test object, and shut the connection down.
    set dn &quot;cn=Tester,ou=People,o=University of Michigan,c=US&quot;
    ldap::delete $handle $dn
    ldap::unbind     $handle
    ldap::disconnect $handle
</pre>
<p>And a another example, a simple query, and processing the
results.</p>
<pre class="doctools_example">
    package require ldap
    set handle [ldap::connect ldap.acme.com 389]
    ldap::bind $handle
    set results [ldap::search $handle &quot;o=acme,dc=com&quot; &quot;(uid=jdoe)&quot; {}]
    foreach result $results {
	foreach {object attributes} $result break
	# The processing here is similar to what 'parray' does.
	# I.e. finding the longest attribute name and then
	# generating properly aligned output listing all attributes
	# and their values.
	set width 0
	set sortedAttribs {}
	foreach {type values} $attributes {
	    if {[string length $type] &gt; $width} {
		set width [string length $type]
	    }
	    lappend sortedAttribs [list $type $values]
	}
	puts &quot;object='$object'&quot;
	foreach sortedAttrib  $sortedAttribs {
	    foreach {type values} $sortedAttrib break
	    foreach value $values {
		regsub -all &quot;\[\x01-\x1f\]&quot; $value ? value
		puts [format &quot;  %-${width}s %s&quot; $type $value]
	    }
	}
	puts &quot;&quot;
    }
    ldap::unbind $handle
    ldap::disconnect $handle
</pre>
</div>
<div id="section5" class="doctools_section"><h2><a name="section5">Bugs, Ideas, Feedback</a></h2>
<p>This document, and the package it describes, will undoubtedly contain
bugs and other problems.
Please report such in the category <em>ldap</em> of the
<a href="http://core.tcl.tk/tcllib/reportlist">Tcllib Trackers</a>.
Please also report any ideas for enhancements you may have for either
package and/or documentation.</p>
<p>When proposing code changes, please provide <em>unified diffs</em>,
i.e the output of <b class="const">diff -u</b>.</p>
<p>Note further that <em>attachments</em> are strongly preferred over
inlined patches. Attachments can be made by going to the <b class="const">Edit</b>
form of the ticket immediately after its creation, and then using the
left-most button in the secondary navigation bar.</p>
</div>
<div id="keywords" class="doctools_section"><h2><a name="keywords">Keywords</a></h2>
<p><a href="../../../../index.html#directory_access">directory access</a>, <a href="../../../../index.html#internet">internet</a>, <a href="../../../../index.html#ldap">ldap</a>, <a href="../../../../index.html#ldap_client">ldap client</a>, <a href="../../../../index.html#protocol">protocol</a>, <a href="../../../../index.html#rfc_2251">rfc 2251</a>, <a href="../../../../index.html#rfc_4511">rfc 4511</a>, <a href="../../../../index.html#x_500">x.500</a></p>
</div>
<div id="category" class="doctools_section"><h2><a name="category">Category</a></h2>
<p>Networking</p>
</div>
<div id="copyright" class="doctools_section"><h2><a name="copyright">Copyright</a></h2>
<p>Copyright &copy; 2004 Andreas Kupries &lt;andreas_kupries@users.sourceforge.net&gt;<br>
Copyright &copy; 2004 Jochen Loewer &lt;loewerj@web.de&gt;<br>
Copyright &copy; 2006 Michael Schlenker &lt;mic42@users.sourceforge.net&gt;</p>
</div>
</div></body></html>
