aboutsummaryrefslogtreecommitdiffstats
path: root/lualdap/doc/us/manual.html
blob: 50d3b60a5f44e4a1b92aec14717d3b53bddf6e01 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>

<head>
    <title>LuaLDAP: A Lua interface to the OpenLDAP library</title>
    <link rel="stylesheet" href="http://www.keplerproject.org/doc.css" type="text/css"/>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>

<body>

<div id="container">

<div id="product">
	<div id="product_logo"><a href="http://www.keplerproject.org">
		<img alt="LuaLDAP logo" width="128" height="128" src="lualdap.png"/>
	</a></div>
	<div id="product_name"><big><strong>LuaLDAP</strong></big></div>
	<div id="product_description">A Lua interface to the OpenLDAP library</div>
</div> <!-- id="product" -->

<div id="main">

<div id="navigation">
<h1>LuaLDAP</h1>
    <ul>
        <li><a href="index.html">Home</a>
            <ul>
                <li><a href="index.html#over">Overview</a></li>
                <li><a href="index.html#status">Status</a></li>
                <li><a href="index.html#download">Download</a></li>
                <li><a href="index.html#history">History</a></li>
                <li><a href="index.html#credits">Credits</a></li>
                <li><a href="index.html#contact">Contact us</a></li>
            </ul>
        </li>
        <li><strong>Manual</strong>
            <ul>
                <li><a href="manual.html#introduction">Introduction</a></li>
                <li><a href="manual.html#installation">Installation</a></li>
                <li><a href="manual.html#attributes">Attributes</a></li>
                <li><a href="manual.html#dn">DN</a></li>
                <li><a href="manual.html#initialization">Initialization</a></li>
                <li><a href="manual.html#connection">Connection</a></li>
                <li><a href="manual.html#examples">Examples</a></li>
            </ul>
        </li>
        <li><a href="license.html">License</a></li>
    </ul>
</div> <!-- id="navigation" -->

<div id="content">

<h2><a name="introduction"></a>Introduction</h2>

<p>LuaLDAP is a simple interface from Lua to an LDAP client (in
fact it is a bind to <a href="http://www.openldap.org">OpenLDAP</a>
client).</p>

<p>LuaLDAP defines one single global variable: a table called
<code>lualdap</code>. This table holds the functions used to create an
LDAP connection object.</p>

<p>A connection object offers methods to perform any operation on
the directory such as comparing values, adding new entries,
modifying attributes on existing entries, removing entries, and the
most common of all: searching. Entries are represented as Lua
tables; attributes are its fields. The attribute values can be
strings or tables of strings (used to represent multiple
values).</p>

<h2><a name="installation"></a>Installation</h2>

<p>LuaLDAP is a bind to the <a href=
"http://www.openldap.org">OpenLDAP</a> library, therefore it
depends on a previous installation of this library. You can
download OpenLDAP from the OpenLDAP <a href=
"http://www.openldap.org/software/download">download
page</a>.</p>

<p>LuaLDAP follows the <a href=
"http://www.keplerproject.org/compat/">package proposal</a> for Lua
5.1, therefore this package should be "installed". In other words,
if you are using Lua 5.0, the files <code>compat-5.1.c</code> and
<code>compat-5.1.h</code> must be used in the compilation and the file
<code>compat-5.1.lua</code> must be installed in the <code>LUA_PATH</code>.
If you are using Lua 5.1, nothing should be done.</p>

<p>If you are using the Windows pre-compiled version of LuaLDAP, refer
to <a href="http://www.keplerproject.org/compat/manual.html#configuration">
Compat-5.1 configuration</a> section about how to install
<code>lualdap.dll</code> properly. The file <code>libsasl.dll</code>
must also be copied to the directory that contains the Lua interpreter
(<code>lua50.exe</code>) or any other Lua host application
(a Kepler launcher for example).</p>

<h2><a name="attributes"></a>Representing attributes</h2>

<p>Many LDAP operations manage sets of attributes and values.
LuaLDAP provides a uniform way of representing them: using Lua
tables. A table of attributes is indexed by the name of the
attribute and its value can be a string (be careful: it can also be
a "binary string") or a list/table of values indexed by numbers
from 1 to <em>n</em>. Some operations have different approaches
that will be explained when necessary.</p>

<p>Follows a small example:</p>

<pre class="example">
entry = {
    an_attribute = "a value",
    other_attribute = {
        "first value of other attribute",
        "another value of other attribute",
    },
}
</pre>

Attribute names cannot contain zeroes (<code>'\0'</code>)

<h2><a name="dn"></a>Distinguished names</h2>

<p>The distinguished name (DN) is the term used to identify an
entry on the directory information tree. It is formed by the
relative distinguished name (RDN) of the entry and the
distinguished name of its parent. LuaLDAP will always use a string
to represent the DN of any entry.</p>

<p>A more precise definition can be found on the LDAP
documentation. A list of some of these files can be found in
section <a href="#related_docs">Related documentation</a>.</p>

<h2><a name="initialization"></a>Initialization functions</h2>

<p>LuaLDAP provides a single way to connect to an LDAP server:</p>

<dl>
    <dt><strong><code>lualdap.open_simple (hostname, who, password,
    usetls)</code></strong></dt>
    <dd>Initializes a session with an LDAP server. This function requires a
    hostname, accordingly to the <a href="#related_docs">C LDAP API</a>
    definition (<em>"hostname contains a space-separated list of
    hostnames or dotted strings representing the IP address of hosts
    running an LDAP server to connect to. Each hostname in the list MAY
    include a port number which is separated from the host itself with
    a colon (:) character."</em>). The argument <code>who</code> should be
    the <a href="#dn">distinguished name</a> of the entry that has the
    password to be checked against the third argument,
    <code>password</code>. The optional argument <code>usetls</code> is a
    Boolean flag indicating if Transport Layer Security (TLS) should be
    used.<br/>
    Returns a connection object or <code>nil</code> followed by an error
    string.</dd>
</dl>

<h2><a name="connection"></a>Connection objects</h2>

<p>A connection object offers methods which implement LDAP
operations. Almost all of them need a <a href="#dn">distinguished
name</a> to identify the entry on which the operation will be
executed.</p>

<p>These methods execute asynchronous operations and return a
function that should be called to obtain the result(s). These
functions will return <code>true</code> indicating success of the
operation; the only exception is the function <code>compare</code>
which can return either <code>true</code> or <code>false</code>
(which is the result of the comparison) on a successful operation.</p>

<p>There are two types of errors: <em>API errors</em>, such as
wrong parameters, absent connection etc.; and <em>LDAP errors</em>,
such as mal-formed DN, unknown attribute etc. API errors will raise
a Lua error, while LDAP errors will be reported by the
function/method returning <code>nil</code> followed by the error
message provided by the OpenLDAP client.</p>

<p>A connection object can be created by calling the <a href=
"#initialization">Initialization function</a>.</p>

<h4>Methods</h4>

<dl>
    <dt><strong><code>conn:add (distinguished_name,
    table_of_attributes)</code></strong></dt>
    <dd>Adds a new entry to the directory with the given attributes and
    values. <a name="conn_close"></a></dd>
	
    <dt><strong><code>conn:close()</code></strong></dt>
    <dd>Closes the connection <code>conn</code>.</dd>
	
    <dt><strong><code>conn:compare (distinguished_name, attribute,
    value)</code></strong></dt>
    <dd>Compares a value against an entry.</dd>
	
    <dt><strong><code>conn:delete (distinguished_name)</code></strong></dt>
    <dd>Deletes an entry from the directory.</dd>
	
    <dt><strong><code>conn:modify (distinguished_name,
    table_of_operations*)</code></strong></dt>
    <dd>Changes values of attributes in the given entry. The tables of
    operations are <a href="#attributes">table of attributes</a> but
    with the value on index <code>1</code> indicating the operation to be
    performed. The valid operations are: 
    <ul>
        <li><strong><code>'+'</code></strong> to add the values to the attributes</li>
        <li><strong><code>'-'</code></strong> to delete the values of the attributes</li>
        <li><strong><code>'='</code></strong> to replace the values of the attributes</li>
    </ul>
    All tables of operations given as arguments will be joined together
    to perform a single LDAP modify operation.</dd>

    <dt><strong><code>conn:rename (distinguished_name, new_relative_dn,
    new_parent)</code></strong></dt>
    <dd>Changes entry names (i.e. change its <a href="#dn">distinguished
    name</a>).</dd>
	
    <dt><strong><code>conn:search (table_of_search_parameters)</code></strong></dt>
    <dd>Performs a search operation on the directory. The parameters are
    described below:<br/><br/>
    <dl>
        <dt><strong><code>attrs</code></strong></dt>
		<dd>a string or a list of attribute names to
        be retrieved (default is to retrieve all attributes).</dd>
		
        <dt><strong><code>attrsonly</code></strong></dt>
		<dd>a Boolean value that must be either
        <em>false</em> (default) if both attribute names and values are to be
        retrieved, or <em>true</em> if only names are wanted.</dd>
		
        <dt><strong><code>base</code></strong></dt>
		<dd>The <a href="#dn">distinguished name</a>
        of the entry at which to start the search.</d>
		
        <dt><strong><code>filter</code></strong></dt>
		<dd>A string representing the search filter
        as described in <a href="http://www.ietf.org/rfc/rfc2254.txt">The
        String Representation of LDAP Search Filters (RFC 2254)</a>.</dd>
		
        <dt><strong><code>scope</code></strong></dt>
		<dd>A string indicating the scope of the
        search. The valid strings are: "base", "onelevel" and "subtree".
        The empty string ("") and <code>nil</code> will be treated as the
        default scope.</dd>
		
        <dt><strong><code>sizelimit</code></strong></dt>
		<dd>The maximum number of entries to
        return (default is no limit).</dd>
		
        <dt><strong><code>timeout</code></strong></dt>
		<dd>The timeout in seconds (default is no
        timeout). The precision is microseconds.</dd>
    </dl>
	<br/>
    The search method will return a <em>search iterator</em> which is a
    function that requires no arguments. The search iterator is used to
    get the search result and will return a string representing the <a
    href="#dn">distinguished name</a> and a <a href="#attributes">table
    of attributes</a> as returned by the search request.</dd>
</dl>

<h2><a name="examples"></a>Example</h2>

<p>Below is a small sample code displaying the basic use of the
library.</p>

<pre class="example">
require "lualdap"

ld = assert (lualdap.open_simple ("ldap.server",
                "mydn=manoeljoaquim,ou=people,dc=ldap,dc=world",
                "mysecurepassword"))

for dn, attribs in ld:search { base = "ou=people,dc=ldap,dc=world" } do
    io.write (string.format ("\t[%s]\n", dn))
    for name, values in pairs (attribs) do
        io.write ("["..name.."] : ")
        if type (values) == "string" then
            io.write (values)
        elseif type (values) == "table" then
            local n = table.getn(values)
            for i = 1, (n-1) do
                io.write (values[i]..",")
            end
            io.write (values[n])
        end
        io.write ("\n")
    end
end

ld:add ("mydn=newuser,ou=people,dc=ldap,dc=world", {
    objectClass = { "", "", },
    mydn = "newuser",
    abc = "qwerty",
    tel = { "123456758", "98765432", },
    givenName = "New User",
})()

ld:modify {"mydn=newuser,ou=people,dc=ldp,dc=world",
    { '=', givenName = "New", cn = "New", sn = "User", },
    { '+', o = { "University", "College", },
           mail = "newuser@university.edu", },
    { '-', abc = true, tel = "123456758", },
    { '+', tel = "13579113", },
}()

ld:delete ("mydn=newuser,ou=people,dc=ldp,dc=world")()

</pre>

<h2><a name="related_docs"></a>Related documentation</h2>

<ul>
    <li><a href="http://www.ietf.org/rfc/rfc2251.txt">Lightweight
    Directory Access Protocol (v3)</a></li>
    <li><a href="http://www.ietf.org/rfc/rfc3377.txt">LDAPv3 Technical
    Specification</a></li>
    <li><a href="http://www.ietf.org/rfc/rfc2254.txt">The String
    Representation of LDAP Search Filters (RFC 2254)</a></li>
    <li><a href=
    "http://www.ietf.org/proceedings/01aug/I-D/draft-ietf-ldapext-ldap-c-api-05.txt">
    The C LDAP Application Program Interface</a></li>
</ul>

</div> <!-- id="content" -->

</div> <!-- id="main" -->

<div id="about">
	<p><a href="http://validator.w3.org/check?uri=referer"><img src="http://www.w3.org/Icons/valid-xhtml10" alt="Valid XHTML 1.0!" height="31" width="88" /></a></p>
	<p><small>
	$Id: manual.html,v 1.23 2005-05-24 22:10:15 carregal Exp $
	</small></p>
</div> <!-- id="about" -->

</div> <!-- id="container" -->
</body>
</html>