aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLeonardo Godinho <godinho@luaforge.net>2007-03-13 22:07:33 +0000
committerLeonardo Godinho <godinho@luaforge.net>2007-03-13 22:07:33 +0000
commit76b50ffff9a28d8815f91debe9ca8a9d7a5de743 (patch)
treeacb514a068cf2c47f0dd2bf6ca8c46a1e580484c
parentVC 8 Makefile support (diff)
downloadlualdap-76b50ffff9a28d8815f91debe9ca8a9d7a5de743.tar.xz
lualdap-76b50ffff9a28d8815f91debe9ca8a9d7a5de743.zip
Added support to ADSI (WinLDAP).
Thanks to Mark Edgar for most of the hackish defines.
-rwxr-xr-xlualdap/Makefile4
-rwxr-xr-xlualdap/Makefile.win4
-rwxr-xr-xlualdap/config.win15
-rwxr-xr-xlualdap/doc/us/index.html18
-rwxr-xr-xlualdap/doc/us/manual.html18
-rwxr-xr-xlualdap/src/lualdap.c61
-rwxr-xr-xlualdap/src/open2winldap.h47
7 files changed, 118 insertions, 49 deletions
diff --git a/lualdap/Makefile b/lualdap/Makefile
index 4b9ee1c..6a4f06d 100755
--- a/lualdap/Makefile
+++ b/lualdap/Makefile
@@ -1,7 +1,7 @@
-# $Id: Makefile,v 1.29 2006-07-24 01:42:06 tomas Exp $
+# $Id: Makefile,v 1.30 2007-03-13 22:07:33 godinho Exp $
T= lualdap
-V= 1.0.2
+V= 1.1.0
CONFIG= ./config
include $(CONFIG)
diff --git a/lualdap/Makefile.win b/lualdap/Makefile.win
index dfb8559..78d23a4 100755
--- a/lualdap/Makefile.win
+++ b/lualdap/Makefile.win
@@ -1,5 +1,5 @@
T= lualdap
-V= 1.0.2
+V= 1.1.0
include config.win
@@ -12,7 +12,7 @@ lib: src\$(LIBNAME)
$(CC) /c /Fo$@ $(CFLAGS) $<
src\$(LIBNAME): $(OBJS)
- link /dll /def:src\$T.def /out:src\$(LIBNAME) $(OBJS) $(LUA_LIB) $(OPENLDAP_LIB)
+ link /dll /def:src\$T.def /out:src\$(LIBNAME) $(OBJS) $(LUA_LIB) $(LDAP_LIB)
install: src\$(LIBNAME)
IF NOT EXIST $(LUA_LIBDIR) mkdir $(LUA_LIBDIR)
diff --git a/lualdap/config.win b/lualdap/config.win
index bdb39aa..199ea25 100755
--- a/lualdap/config.win
+++ b/lualdap/config.win
@@ -1,21 +1,24 @@
# Installation directories
# System's libraries directory (where binary libraries are installed)
LUA_LIBDIR= e:\leonardo\dev\kepler1.1\lua511
+
# Lua includes directory
+#LDAP_INC= c:\dev\openldap-2.1.17_bin\include
LUA_INC= e:\leonardo\dev\kepler1.1\lua511\include
+
# Lua library
LUA_LIB= e:\leonardo\dev\kepler1.1\lua511\lua5.1.lib
-# OpenLDAP includes directory
-OPENLDAP_INC= e:\leonardo\dev\openldap-2.1.17_bin\include
-# OpenLDAP library
-OPENLDAP_LIB= e:\leonardo\dev\openldap-2.1.17_bin\DLLRelease\openldap.lib
+# LDAP library
+#LDAP_LIB= c:\dev\openldap-2.1.17_bin\DLLRelease\openldap.lib
+LDAP_LIB= Wldap32.lib
LIBNAME= $T.dll
# Compilation directives
WARN= /O2
-INCS= /I$(LUA_INC) /I$(OPENLDAP_INC)
-CFLAGS= $(WARN) $(INCS) -DWIN32
+INCS= /I$(LUA_INC)
+# CFLAGS should include -DWINLDAP to use native windows library instead of OpenLDAP
+CFLAGS= $(WARN) $(INCS) -DWIN32 -DWINLDAP
CC= cl
diff --git a/lualdap/doc/us/index.html b/lualdap/doc/us/index.html
index 9f45d30..5e5a010 100755
--- a/lualdap/doc/us/index.html
+++ b/lualdap/doc/us/index.html
@@ -3,7 +3,7 @@
<html>
<head>
- <title>LuaLDAP: A Lua interface to the OpenLDAP library</title>
+ <title>LuaLDAP: A Lua interface to an LDAP 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>
@@ -19,7 +19,7 @@
</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_description">A Lua interface to an LDAP library</div>
</div> <!-- id="product" -->
<div id="main">
@@ -65,7 +65,7 @@
<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>. It enables a Lua program to:</p>
+<a href="http://www.openldap.org">OpenLDAP</a> or to <a href="http://msdn2.microsoft.com/en-us/library/aa772161.aspx">ADSI</a>. It enables a Lua program to:</p>
<ul>
<li>Connect to an LDAP server;</li>
@@ -79,8 +79,8 @@ fact it is a bind to
<h2><a name="status"></a>Status</h2>
-<p>Current version is 1.0.2. It was developed for both Lua 5.0 and Lua 5.1, and
-<a href="http://www.openldap.org">OpenLDAP</a> 2.1.</p>
+<p>Current version is 1.1. It was developed for both Lua 5.0 and Lua 5.1, and both
+<a href="http://www.openldap.org">OpenLDAP</a> 2.1 or newer and <a href="http://msdn2.microsoft.com/en-us/library/aa772161.aspx">ADSI</a>.</p>
<h2><a name="download"></a>Download</h2>
@@ -94,8 +94,8 @@ LuaForge page.</p>
<h2><a name="history"></a>History</h2>
<dl class="history">
- <dt><strong>Version 1.0.2</strong> [?/?/2006]</dt>
- <dd>adapted to work on both Lua 5.0 and Lua 5.1.</dd>
+ <dt><strong>Version 1.1</strong> [?/?/2007]</dt>
+ <dd>adapted to work on both Lua 5.0 and Lua 5.1 and to work with ADSI on Windows.</dd>
<dt><strong>Version 1.0.1</strong> [04/Apr/2006]</dt>
<dd>Compatible with Compat-5.1 R5.</dd>
@@ -112,7 +112,7 @@ LuaForge page.</p>
<p>LuaLDAP was designed by Roberto Ierusalimschy, Andr&eacute;
Carregal and Tom&aacute;s Guisasola as part of the
<a href="http://www.keplerproject.org">Kepler Project</a>
-which holds its copyright. It was implemented by Tom&aacute;s Guisasola.</p>
+which holds its copyright. It was implemented by Tom&aacute;s Guisasola and Leonardo Godinho with contributions by Mark Edgar.</p>
<p>LuaLDAP development was sponsored by
<a href="http://www.fabricadigital.com.br">F&aacute;brica Digital</a> and FINEP.</p>
@@ -133,7 +133,7 @@ Comments are welcome!</p>
<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: index.html,v 1.33 2006-07-24 01:42:06 tomas Exp $</small></p>
+ <p><small>$Id: index.html,v 1.34 2007-03-13 22:07:33 godinho Exp $</small></p>
</div> <!-- id="about" -->
</div> <!-- id="container" -->
diff --git a/lualdap/doc/us/manual.html b/lualdap/doc/us/manual.html
index 2313334..d1c6a91 100755
--- a/lualdap/doc/us/manual.html
+++ b/lualdap/doc/us/manual.html
@@ -3,7 +3,7 @@
<html>
<head>
- <title>LuaLDAP: A Lua interface to the OpenLDAP library</title>
+ <title>LuaLDAP: A Lua interface to an LDAP 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>
@@ -17,7 +17,7 @@
<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_description">A Lua interface to an LDAP library</div>
</div> <!-- id="product" -->
<div id="main">
@@ -63,7 +63,7 @@
<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>
+client or <a href="http://msdn2.microsoft.com/en-us/library/aa772161.aspx">ADSI</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
@@ -78,12 +78,12 @@ strings or tables of strings (used to represent multiple
values).</p>
<p>LuaLDAP is a bind to the
-<a href="http://www.openldap.org">OpenLDAP</a> library and it
-depends on a previous installation of this library. You can
+<a href="http://www.openldap.org">OpenLDAP</a> library or to <a href="http://msdn2.microsoft.com/en-us/library/aa772161.aspx">ADSI</a> library and it
+depends on a previous installation of any of this libraries. You can
download OpenLDAP from the
<a href="http://www.openldap.org/software/download">OpenLDAP download</a>
-page.</p>
-
+page. ADSI is included on Windows 2000 or newer. Windows NT/Me/98/95
+requires an <a href="http://msdn2.microsoft.com/en-us/library/aa772161.aspx">Active Directory Client Extension</a></p>
<h2><a name="building"></a>Building</h2>
<p>
@@ -109,7 +109,7 @@ which is not obtained from the installed software.
<a href="http://www.lua.org/manual/5.1/manual.html#pdf-package.cpath">C path</a>.
Lua 5.0 users should install <a href="http://www.keplerproject.org/compat">Compat-5.1</a> also.</p>
-<p>Windows users can use the binary versions of LuaLDAP
+<p>Windows users of OpenLDAP 2.1 can use the binary versions of LuaLDAP
(<code>lualdap.dll</code>) and OpenLDAP
(<code>libsasl.dll</code>) available at
<a href="http://luaforge.net/projects/lualdap/files">LuaForge</a>.</p>
@@ -344,7 +344,7 @@ ld:delete ("mydn=newuser,ou=people,dc=ldp,dc=world")()
<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.31 2006-07-24 01:42:06 tomas Exp $</small></p>
+ <p><small>$Id: manual.html,v 1.32 2007-03-13 22:07:33 godinho Exp $</small></p>
</div> <!-- id="about" -->
</div> <!-- id="container" -->
diff --git a/lualdap/src/lualdap.c b/lualdap/src/lualdap.c
index dee1c34..87da68e 100755
--- a/lualdap/src/lualdap.c
+++ b/lualdap/src/lualdap.c
@@ -1,18 +1,23 @@
/*
** LuaLDAP
** See Copyright Notice in license.html
-** $Id: lualdap.c,v 1.46 2007-02-07 15:05:48 godinho Exp $
+** $Id: lualdap.c,v 1.47 2007-03-13 22:07:33 godinho Exp $
*/
#include <stdlib.h>
#include <string.h>
+
#ifdef WIN32
#include <Winsock2.h>
#else
#include <sys/time.h>
#endif
+#ifdef WINLDAP
+#include "open2winldap.h"
+#else
#include "ldap.h"
+#endif
#include "lua.h"
#include "lauxlib.h"
@@ -20,6 +25,15 @@
#include "compat-5.1.h"
#endif
+#ifdef WINLDAPAPI
+#define timeval l_timeval
+typedef ULONG ldap_int_t;
+typedef PCHAR ldap_pchar_t;
+#else
+typedef int ldap_int_t;
+typedef const char * ldap_pchar_t;
+#endif
+
#define LUALDAP_PREFIX "LuaLDAP: "
#define LUALDAP_TABLENAME "lualdap"
#define LUALDAP_CONNECTION_METATABLE "LuaLDAP connection"
@@ -426,7 +440,7 @@ static int result_message (lua_State *L) {
/*
** Push a function to process the LDAP result.
*/
-static int create_future (lua_State *L, int rc, int conn, int msgid, int code) {
+static int create_future (lua_State *L, ldap_int_t rc, int conn, ldap_int_t msgid, int code) {
if (rc != LDAP_SUCCESS)
return faildirect (L, ldap_err2string (rc));
lua_pushvalue (L, conn); /* push connection as #1 upvalue */
@@ -463,9 +477,9 @@ static int lualdap_close (lua_State *L) {
*/
static int lualdap_add (lua_State *L) {
conn_data *conn = getconnection (L);
- const char *dn = luaL_checkstring (L, 2);
+ ldap_pchar_t dn = (ldap_pchar_t) luaL_checkstring (L, 2);
attrs_data attrs;
- int rc, msgid;
+ ldap_int_t rc, msgid;
A_init (&attrs);
if (lua_istable (L, 3))
A_tab2mod (L, &attrs, 3, LUALDAP_MOD_ADD);
@@ -485,10 +499,10 @@ static int lualdap_add (lua_State *L) {
*/
static int lualdap_compare (lua_State *L) {
conn_data *conn = getconnection (L);
- const char *dn = luaL_checkstring (L, 2);
- const char *attr = luaL_checkstring (L, 3);
+ ldap_pchar_t dn = (ldap_pchar_t) luaL_checkstring (L, 2);
+ ldap_pchar_t attr = (ldap_pchar_t) luaL_checkstring (L, 3);
BerValue bvalue;
- int rc, msgid;
+ ldap_int_t rc, msgid;
bvalue.bv_val = (char *)luaL_checkstring (L, 4);
bvalue.bv_len = lua_strlen (L, 4);
rc = ldap_compare_ext (conn->ld, dn, attr, &bvalue, NULL, NULL, &msgid);
@@ -504,8 +518,8 @@ static int lualdap_compare (lua_State *L) {
*/
static int lualdap_delete (lua_State *L) {
conn_data *conn = getconnection (L);
- const char *dn = luaL_checkstring (L, 2);
- int rc, msgid;
+ ldap_pchar_t dn = (ldap_pchar_t) luaL_checkstring (L, 2);
+ ldap_int_t rc, msgid;
rc = ldap_delete_ext (conn->ld, dn, NULL, NULL, &msgid);
return create_future (L, rc, 1, msgid, LDAP_RES_DELETE);
}
@@ -539,9 +553,10 @@ static int op2code (const char *s) {
*/
static int lualdap_modify (lua_State *L) {
conn_data *conn = getconnection (L);
- const char *dn = luaL_checkstring (L, 2);
+ ldap_pchar_t dn = (ldap_pchar_t) luaL_checkstring (L, 2);
attrs_data attrs;
- int rc, msgid, param = 3;
+ ldap_int_t rc, msgid;
+ int param = 3;
A_init (&attrs);
while (lua_istable (L, param)) {
int op;
@@ -565,12 +580,12 @@ static int lualdap_modify (lua_State *L) {
*/
static int lualdap_rename (lua_State *L) {
conn_data *conn = getconnection (L);
- const char *dn = luaL_checkstring (L, 2);
- const char *rdn = luaL_checkstring (L, 3);
- const char *par = luaL_optlstring (L, 4, NULL, NULL);
+ ldap_pchar_t dn = (ldap_pchar_t) luaL_checkstring (L, 2);
+ ldap_pchar_t rdn = (ldap_pchar_t) luaL_checkstring (L, 3);
+ ldap_pchar_t par = (ldap_pchar_t) luaL_optlstring (L, 4, NULL, NULL);
const int del = luaL_optnumber (L, 5, 0);
- int msgid;
- int rc = ldap_rename (conn->ld, dn, rdn, par, del, NULL, NULL, &msgid);
+ ldap_int_t msgid;
+ ldap_int_t rc = ldap_rename (conn->ld, dn, rdn, par, del, NULL, NULL, &msgid);
return create_future (L, rc, 1, msgid, LDAP_RES_MODDN);
}
@@ -679,6 +694,8 @@ static int next_message (lua_State *L) {
ret = 2; /* two return values */
break;
}
+/*No reference to LDAP_RES_SEARCH_REFERENCE on MSDN. Maybe there is a replacement to it?*/
+#ifdef LDAP_RES_SEARCH_REFERENCE
case LDAP_RES_SEARCH_REFERENCE: {
LDAPMessage *ref = ldap_first_reference (conn->ld, msg);
push_dn (L, conn->ld, ref); /* is this supposed to work? */
@@ -686,6 +703,7 @@ static int next_message (lua_State *L) {
ret = 2; /* two return values */
break;
}
+#endif
case LDAP_RES_SEARCH_RESULT:
/* close search object to avoid reuse */
search_close (L, search);
@@ -788,7 +806,8 @@ static struct timeval *get_timeout_param (lua_State *L, struct timeval *st) {
*/
static int lualdap_search (lua_State *L) {
conn_data *conn = getconnection (L);
- const char *base, *filter;
+ ldap_pchar_t base;
+ ldap_pchar_t filter;
char *attrs[LUALDAP_MAX_ATTRS];
int scope, attrsonly, msgid, rc, sizelimit;
struct timeval st, *timeout;
@@ -799,8 +818,8 @@ static int lualdap_search (lua_State *L) {
return 2;
/* get other parameters */
attrsonly = booltabparam (L, "attrsonly", 0);
- base = strtabparam (L, "base", NULL);
- filter = strtabparam (L, "filter", NULL);
+ base = (ldap_pchar_t) strtabparam (L, "base", NULL);
+ filter = (ldap_pchar_t) strtabparam (L, "filter", NULL);
scope = string2scope (L, strtabparam (L, "scope", NULL));
sizelimit = longtabparam (L, "sizelimit", LDAP_NO_LIMIT);
timeout = get_timeout_param (L, &st);
@@ -915,8 +934,8 @@ static int lualdap_createmeta (lua_State *L) {
** @return #1 Userdata with connection structure.
*/
static int lualdap_open_simple (lua_State *L) {
- const char *host = luaL_checkstring (L, 1);
- const char *who = luaL_optstring (L, 2, NULL);
+ ldap_pchar_t host = (ldap_pchar_t) luaL_checkstring (L, 1);
+ ldap_pchar_t who = (ldap_pchar_t) luaL_optstring (L, 2, NULL);
const char *password = luaL_optstring (L, 3, NULL);
int use_tls = lua_toboolean (L, 4);
conn_data *conn = (conn_data *)lua_newuserdata (L, sizeof(conn_data));
diff --git a/lualdap/src/open2winldap.h b/lualdap/src/open2winldap.h
new file mode 100755
index 0000000..ad592d8
--- /dev/null
+++ b/lualdap/src/open2winldap.h
@@ -0,0 +1,47 @@
+#include <winldap.h>
+
+/* For some reason MSDN mentions LDAP_RES_MODDN, but not LDAP_RES_MODRDN. */
+#ifndef LDAP_RES_MODDN
+#define LDAP_RES_MODDN LDAP_RES_MODRDN
+#endif
+
+/* MSDN doesn't mention LDAP_OPT_SUCCESS, it uses LDAP_SUCCESS intead */
+#ifndef LDAP_OPT_SUCCESS
+#define LDAP_OPT_SUCCESS LDAP_SUCCESS
+#endif
+
+/* MSDN doesn't mention LDAP_SCOPE_DEFAULT, so default will be LDAP_SCOPE_SUBTREE */
+#ifndef LDAP_SCOPE_DEFAULT
+#define LDAP_SCOPE_DEFAULT LDAP_SCOPE_SUBTREE
+#endif
+
+/* MSDN doesn't mention this function at all. Unfortunately, LDAPMessage an opaque type. */
+#define ldap_msgtype(m) ((m)->lm_msgtype)
+
+#define ldap_first_message ldap_first_entry
+
+/* The WinLDAP API allows comparisons against either string or binary values */
+#undef ldap_compare_ext
+
+/* The WinLDAP API uses ULONG seconds instead of a struct timeval. */
+#undef ldap_search_ext
+
+/* The WinLDAP API has a different number of arguments for this */
+#undef ldap_start_tls_s
+
+#ifdef UNICODE
+#define ldap_compare_ext(ld,dn,a,v,sc,cc,msg) \
+ ldap_compare_extW(ld,dn,a,0,v,sc,cc,msg)
+#define ldap_search_ext(ld,base,scope,f,a,o,sc,cc,t,s,msg) \
+ ldap_search_extW(ld,base,scope,f,a,o,sc,cc,(t)?(t)->tv_sec:0,s,msg)
+#define ldap_start_tls_s(ld,sc,cc) \
+ ldap_start_tls_sW(ld,0,0,sc,cc)
+#else
+#define ldap_compare_ext(ld,dn,a,v,sc,cc,msg) \
+ ldap_compare_extA(ld,dn,a,0,v,sc,cc,msg)
+#define ldap_search_ext(ld,base,scope,f,a,o,sc,cc,t,s,msg) \
+ ldap_search_extA(ld,base,scope,f,a,o,sc,cc,(t)?(t)->tv_sec:0,s,msg)
+#define ldap_start_tls_s(ld,sc,cc) \
+ ldap_start_tls_sA(ld,0,0,sc,cc)
+#endif
+