From 76b50ffff9a28d8815f91debe9ca8a9d7a5de743 Mon Sep 17 00:00:00 2001 From: Leonardo Godinho Date: Tue, 13 Mar 2007 22:07:33 +0000 Subject: Added support to ADSI (WinLDAP). Thanks to Mark Edgar for most of the hackish defines. --- lualdap/Makefile | 4 +-- lualdap/Makefile.win | 4 +-- lualdap/config.win | 15 +++++++----- lualdap/doc/us/index.html | 18 +++++++------- lualdap/doc/us/manual.html | 18 +++++++------- lualdap/src/lualdap.c | 61 ++++++++++++++++++++++++++++++---------------- lualdap/src/open2winldap.h | 47 +++++++++++++++++++++++++++++++++++ 7 files changed, 118 insertions(+), 49 deletions(-) create mode 100755 lualdap/src/open2winldap.h (limited to 'lualdap') 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 @@ - LuaLDAP: A Lua interface to the OpenLDAP library + LuaLDAP: A Lua interface to an LDAP library @@ -19,7 +19,7 @@
LuaLDAP
-
A Lua interface to the OpenLDAP library
+
A Lua interface to an LDAP library
@@ -65,7 +65,7 @@

LuaLDAP is a simple interface from Lua to an LDAP client, in fact it is a bind to -OpenLDAP. It enables a Lua program to:

+OpenLDAP or to ADSI. It enables a Lua program to:

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 @@ - LuaLDAP: A Lua interface to the OpenLDAP library + LuaLDAP: A Lua interface to an LDAP library @@ -17,7 +17,7 @@ LuaLDAP logo
LuaLDAP
-
A Lua interface to the OpenLDAP library
+
A Lua interface to an LDAP library
@@ -63,7 +63,7 @@

LuaLDAP is a simple interface from Lua to an LDAP client, in fact it is a bind to OpenLDAP -client.

+client or ADSI client

LuaLDAP defines one single global variable: a table called lualdap. This table holds the functions used to create an @@ -78,12 +78,12 @@ strings or tables of strings (used to represent multiple values).

LuaLDAP is a bind to the -OpenLDAP library and it -depends on a previous installation of this library. You can +OpenLDAP library or to ADSI library and it +depends on a previous installation of any of this libraries. You can download OpenLDAP from the OpenLDAP download -page.

- +page. ADSI is included on Windows 2000 or newer. Windows NT/Me/98/95 +requires an Active Directory Client Extension

Building

@@ -109,7 +109,7 @@ which is not obtained from the installed software. C path. Lua 5.0 users should install Compat-5.1 also.

-

Windows users can use the binary versions of LuaLDAP +

Windows users of OpenLDAP 2.1 can use the binary versions of LuaLDAP (lualdap.dll) and OpenLDAP (libsasl.dll) available at LuaForge.

@@ -344,7 +344,7 @@ ld:delete ("mydn=newuser,ou=people,dc=ldp,dc=world")()

Valid XHTML 1.0!

-

$Id: manual.html,v 1.31 2006-07-24 01:42:06 tomas Exp $

+

$Id: manual.html,v 1.32 2007-03-13 22:07:33 godinho Exp $

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 #include + #ifdef WIN32 #include #else #include #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 + +/* 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 + -- cgit v1.2.3-59-g8ed1b