pax_global_header00006660000000000000000000000064117462630110014513gustar00rootroot0000000000000052 comment=eaac494a5055a69d0f776c2f5f302623d8963603 lua-ldap-1.1.0-1-geeac494/000077500000000000000000000000001174626301100146525ustar00rootroot00000000000000lua-ldap-1.1.0-1-geeac494/Makefile000066400000000000000000000011741174626301100163150ustar00rootroot00000000000000# $Id: Makefile,v 1.30 2007-03-13 22:07:33 godinho Exp $ T= lualdap V= 1.1.0 CONFIG= ./config include $(CONFIG) ifeq "$(LUA_VERSION_NUM)" "500" COMPAT_O= $(COMPAT_DIR)/compat-5.1.o endif OBJS= src/lualdap.o $(COMPAT_O) src/$(LIBNAME): $(OBJS) export MACOSX_DEPLOYMENT_TARGET="10.3"; $(CC) $(CFLAGS) $(LIB_OPTION) -o src/$(LIBNAME) $(OBJS) $(OPENLDAP_LIB) $(COMPAT_DIR)/compat-5.1.o: $(COMPAT_DIR)/compat-5.1.c $(CC) -c $(CFLAGS) -o $@ $(COMPAT_DIR)/compat-5.1.c install: src/$(LIBNAME) mkdir -p $(LUA_LIBDIR) cp src/$(LIBNAME) $(LUA_LIBDIR) cd $(LUA_LIBDIR); ln -f -s $(LIBNAME) $T.so clean: rm -f $(OBJS) src/$(LIBNAME) lua-ldap-1.1.0-1-geeac494/Makefile.win000066400000000000000000000006471174626301100171150ustar00rootroot00000000000000T= lualdap V= 1.1.0 include config.win SRCS= src\$T.c OBJS= src\$T.obj lib: src\$(LIBNAME) .c.obj: $(CC) /c /Fo$@ $(CFLAGS) $< src\$(LIBNAME): $(OBJS) 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) copy src\$(LIBNAME) $(LUA_LIBDIR) clean: del src\$(LIBNAME) $(OBJS) src\$T.lib src\$T.exp lua-ldap-1.1.0-1-geeac494/README000066400000000000000000000020351174626301100155320ustar00rootroot00000000000000LuaLDAP (http://www.keplerproject.org/lualdap/) LuaLDAP is a simple interface from Lua to an LDAP client, in fact it is a bind to OpenLDAP or to ADSI. It enables a Lua program to: * Connect to an LDAP server; * Execute any operation (search, add, compare, delete, modify and rename); * Retrieve entries and references of the search result. LuaLDAP is free software and uses the same license as Lua 5.1. Current version is 1.1. It was developed for both Lua 5.0 and Lua 5.1, and both OpenLDAP 2.1 or newer and ADSI. Files in the distribution: /doc/us/*.html -- Documentation /src/* -- Source files /tests/* -- Test files /vc6/* -- Build files for MS Visual C 6 (deprecated) Makefile -- Makefile for Unix systems config -- Configurations to build on Unix systems Makefile.win -- Makefile for Windows systens with MS Visual C 8 config.win -- Configurations to build on Windows systems README -- This file $Id: README,v 1.7 2007-12-14 15:14:54 carregal Exp $ lua-ldap-1.1.0-1-geeac494/config000066400000000000000000000015461174626301100160500ustar00rootroot00000000000000# Installation directories # System's libraries directory (where binary libraries are installed) LUA_LIBDIR= /usr/local/lib/lua/5.0 # Lua includes directory LUA_INC= /usr/local/include # OpenLDAP includes directory OPENLDAP_INC= /usr/local/include # OpenLDAP library (an optional directory can be specified with -L) OPENLDAP_LIB= -lldap # OS dependent LIB_OPTION= -shared #for Linux #LIB_OPTION= -bundle -undefined dynamic_lookup #for MacOS X # Lua version number (first and second digits of target version) LUA_VERSION_NUM= 500 LIBNAME= $T.so.$V COMPAT_DIR= ../compat/src # Compilation parameters WARN= -O2 -Wall -fPIC -W -Waggregate-return -Wcast-align -Wmissing-prototypes -Wnested-externs -Wshadow -Wwrite-strings -ansi INCS= -I$(LUA_INC) -I$(OPENLDAP_INC) -I$(COMPAT_DIR) CFLAGS= $(WARN) $(INCS) CC= gcc # $Id: config,v 1.5 2006-07-24 01:42:06 tomas Exp $ lua-ldap-1.1.0-1-geeac494/config.win000066400000000000000000000012611174626301100166360ustar00rootroot00000000000000# Installation directories # System's libraries directory (where binary libraries are installed) LUA_LIBDIR= c:\lua5.1 # Lua includes directory LUA_INC= c:\lua5.1\include # OpenLDAP requires extra include. Comment this line if using ADSI (WinLDAP) #LDAP_INC=/IC:\openldap-2.1.17_bin\include # Lua library LUA_LIB= c:\lua5.1\lua5.1.lib # LDAP library #LDAP_LIB= C:\openldap-2.1.17_bin\DLLRelease\openldap.lib LDAP_LIB= Wldap32.lib LIBNAME= $T.dll # Compilation directives WARN= /O2 INCS= /I$(LUA_INC) $(LDAP_INC) # CFLAGS should include -DWINLDAP to use native windows library instead of OpenLDAP #CFLAGS= $(WARN) $(INCS) -DWIN32 CFLAGS= $(WARN) $(INCS) -DWIN32 -DWINLDAP CC= cl lua-ldap-1.1.0-1-geeac494/doc/000077500000000000000000000000001174626301100154175ustar00rootroot00000000000000lua-ldap-1.1.0-1-geeac494/doc/us/000077500000000000000000000000001174626301100160465ustar00rootroot00000000000000lua-ldap-1.1.0-1-geeac494/doc/us/index.html000066400000000000000000000125311174626301100200450ustar00rootroot00000000000000 LuaLDAP: A Lua interface to an LDAP library
LuaLDAP
A Lua interface to an LDAP library

Overview

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

  • Connect to an LDAP server;
  • Execute any operation (search, add, compare, delete, modify and rename);
  • Retrieve entries and references of the search result.

LuaLDAP is free software and uses the same license as Lua 5.1.

Status

Current version is 1.1. It was developed for both Lua 5.0 and Lua 5.1, and both OpenLDAP 2.1 or newer and ADSI.

Download

LuaLDAP can be downloaded in source code from the LuaForge page. If you are using LuaBinaries a Windows binary version of LuaLDAP can be found at the same LuaForge page.

History

Version 1.1 [14/Dec/2007]
Adapted to work on both Lua 5.0 and Lua 5.1 and to work with ADSI (WinLDAP). Thanks to Mark Edgar.
Version 1.0.1 [04/Apr/2006]
Compatible with Compat-5.1 R5.
Version 1.0 [10/Jun/2005]
Version 1.0 Alpha [10/Dec/2003]

Credits

LuaLDAP was designed by Roberto Ierusalimschy, André Carregal and Tomás Guisasola as part of the Kepler Project which holds its copyright. It was implemented by Tomás Guisasola and Leonardo Godinho with contributions by Mark Edgar.

LuaLDAP development was sponsored by Fábrica Digital and FINEP.

Contact us

For further information please contact us. Comments are welcome!

You can also reach other Kepler developers and users on the Kepler Project mailing list.

Valid XHTML 1.0!

$Id: index.html,v 1.37 2007-12-14 17:06:57 carregal Exp $

lua-ldap-1.1.0-1-geeac494/doc/us/license.html000066400000000000000000000116641174626301100203660ustar00rootroot00000000000000 LuaLDAP: license
LuaLDAP
A Lua interface to the OpenLDAP library

License

LuaLDAP is free software: it can be used for both academic and commercial purposes at absolutely no cost. There are no royalties or GNU-like "copyleft" restrictions. LuaLDAP qualifies as Open Source software. Its licenses are compatible with GPL. LuaLDAP is not in the public domain and the Kepler Project keep its copyright. The legal details are below.

The spirit of the license is that you are free to use LuaLDAP for any purpose at no cost without having to ask us. The only requirement is that if you do use LuaLDAP, then you should give us credit by including the appropriate copyright notice somewhere in your product or its documentation.

The LuaLDAP library is designed and implemented by Roberto Ierusalimschy, André Carregal and Tomás Guisasola. The implementation is not derived from licensed software.


Copyright © 2003-2007 The Kepler Project.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Valid XHTML 1.0!

$Id: license.html,v 1.11 2007-12-14 16:46:15 carregal Exp $

lua-ldap-1.1.0-1-geeac494/doc/us/lualdap.png000066400000000000000000000172741174626301100202110ustar00rootroot00000000000000PNG  IHDRL\;IDATxi\SW -}  PZ8u:vt:tZG[[mG,\Q@QDvKd'p;$fLs=<9 Ao#o00 ~ H*d2CGD? TQqss1111ttH$P(&&&}}}EEE7n4ttbv b8;;OvP(̛7vqqq%%%"H$:3Ǐ^~}|||;Db N.D"&)Jsrr&X,Dx.|>/ H"X[[3 d25//HJJbN̨Ri]]]{{;ޓO&IR"r=GGG)By%LP(t:d_O>}ZYYMd2А`xX$33# (\.gX<H$Ϟ=+//߸q#D{"`ddWv d2d͈cccr'))I$/JJ: |"#p8T E-]dbDxss3DˋABd2laa7hCCC Ox< &G&9S'zzxSvw.^xU11 P!] X,6Z[[O8:::&&&^pnaܾ}{hhL&j___2,HB!ʙaΜ9 T*ʕ+X,=::eZMkEȉ26RDDDM?~`$&&t #l[qWVsފܹgܷLMUVZXXMvA0((hll E"666 ,ݻwx61_BBgqO__ qqtEr}krM,[ Ǐ+>MBLvڵa*gaa1}~AŌ{55}px3$ pJ.;A,+ˁ׀#B\N͛7ݺu Ϟ8QKJ-aԨ>>33p@d2.\`0fscT@`GhhG켼`GL_QQa moッ|@*J02--IVV$''*A#.cHX$(=/^466::: s +++KKK?zNk訨UIIӧ]CC/hF!!aaffڴu&&DR2uԌ (??޾3 22u*/E*yE#Xp;hVo]|={{3G]piGGUVpcoo`jkke2D }UiS:B{wWZ)HlmpB?`0T&{孭uuu[liii9}tZZK`` bdgkzkfr/wɓUj1~Ӧn"""|||$INNNdd9s( J]`-CJJ:-:m[N{;WtjJghJU5R'z)`XtӳM x{{044AЛoxݻoS:CI~󩩷FF45fK~;U"FR8--.5x<^, dee"6;ee]Lf:s :y?c?18.S?`w_5 |`0,-- ***Νf+6nbgN+Ԕ4wr`Xޗ/4 0%kըJ4 jooɑJ111nnnrZMev>szFUs~{ɓ1FFŲ?ޱcehj-;xpž}A0<}Ȇ >|ᡲMJYYu}T0U K߻Eǩ*9΍7d2{mũdo_|5GfbcQ "{;ujj><<ٳp46PH$B166^v*>2fؐ:O `cc=XLQQd/rhr@_nkkFFKSTU~[o5Qp2PXaa>JyxyGLj^>Y1122Zt}U9|d|\Iё:A ҃y333SM;M=pJq8SxQϮV Y?ظS="WzUg?^ucc*T*?}N4iϞQ蟧{ccVY"H(Y+*jkk+PU]~HݣS-v&,G*U7WzI_-zY)*jW\kgg~U6-EGK$2$ MM'O:upv@a05;ROiizϋuԺlh`gg׫3:*z]xAX,G#w[tkqC)C{1hFKPؑڪ>$!'f#0033ۼy3P(5zT8ڵ4Btd_J??6&F4]?&oT,9TP)/)HM~% heeU@?gX~4̈[++{JJ0PAk4<]8fmAEE|pW ,VEvOu׏Q5&GF¿z<3@*M ^^ B$ Z/]bUVh~K rMMMaG@qq-n{00%.^P B45%$]B(ݾU'JJJT* QBE}rpppppꮮd2 v pO:rLư:KeR'DAD!̵C@HLLD_7Kid2F3" Z5@|.` P cgȏ >1K*oxOl7H~QQ d"ؘ}jOI@ hhhTp<@ 닮|=F aolHM <|x+{ H::~;r_|Ɖ)u~A5r9{{y|dbF3t)1(y  X (.ؘ<V{NS|}NtP'Ν@ pSG4ȨBgwp0C3>P||ߖO` c曟ʖ.u@iMasSOq!oL59'' y~Vs+-T81AFF-Ԕ`loc0~D`h4 xy![ <|PQĤ-4QU *tAMO,m^h :)sRllLLKM :q Inntnn TJGG&$ImmԃSIJgFj˜9ۖ@ۈ* 9{y>&AD\]Wd\4'.7m%Ni=4./)P> lsD{{d<ZD^2Q=xU팙qjeNY'a5z4Kأiԃj(";AXc kI1~P36w.EU169xp%ݻnU'uVUh77fd۟L͞=u^+|{NKAp]|y!z[[銋 ^xJ|GG7:'@kQټɜ;W;9J4[\ ]Rm{wkߖw2OO-[\ S;w2gH65W.e2K#D"263&pB33",/(ґ;NJM]wR(`]D뛦?+lfMAɓU=nm7UY㚛@PYkk~,(H;-|ȯ6 ڋ@ G PG[x<X9P(A';˅(55}+V?s&njW9:*cǞWھ{%*ɓ1 +ÇKB_~j5+lCX,}|ԍ_ h hi.[D%l67'mzKH=ʺ'kzDEv -s,*ڊ4ƛfDvvv>[Z,81;uuW][n?&RwFԪL}}} ^ٳxjeԴ4oQQJbΟྐ n+88/P-ϙczz ̯#ʕcS5Y5F۱c|U,?{6u1L1˖9) ;5wj*Ml/RV$'/@鹠tn|-bf_222: @*—#OءC+_O">t9ܗ7o@_g—/_&hCtLͮ]t?7pc"} twwSTnש,^;o}{Y TQNΛv-tNteܹӣ U\**v21lw,u vaaawѨ)svٰ<nwsC>5#h?jP(Dffh?yҹsͺ-/aaN%HΟ?bnE^Uʴ,GkH$??ȈaκɄ]KLvծm۶kiaǿ$-b&^H?\JMQ rڵkɈԠgtttTWW ژSxZZʼnZKKRjj] ml\+W\ Ss{,΋/:88$%%@x*"47ܹ6DÜc""[{DJB#fddXXX曚ߺ՘RXئ9 FdktAaZs%OOOgݑJMM]ϟwwN;; A7z9AAs==-QCLWOO/:"zAB^Hd\pp/HaKD"gaAR(hMcctzrr2c̖QlF&0̵kTr4A>0lK;***֭[:=5@"\p+444$$dڥi14׳k 5ArBG H~SEf0b0Eyxx>vVlvaaPJJ;[U>KDpY,N_z DqMMMCCCpp̤V=O X,Xd.;44DRLӶ6\8K#"JqsssssD=== zgΜp8x<a={Ld1JUQu5@=<O$IRT4QR)áP(FFFY! ?rT~M;13~ LuaLDAP: A Lua interface to an LDAP library
LuaLDAP
A Lua interface to an LDAP library

Introduction

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

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

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).

LuaLDAP is a bind to the 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. ADSI is included on Windows 2000 or newer. Windows NT/Me/98/95 requires an Active Directory Client Extension

Building

LuaLDAP could be built to Lua 5.0 or to Lua 5.1. In both cases, the language library and headers files for the target version must be installed properly.

LuaLDAP offers a Makefile and a separate configuration file, config, which should be edited to suit your installation before runnig make. The file has some definitions like paths to the external libraries, compiler options and the like. One important definition is the version of Lua language, which is not obtained from the installed software.

Installation

The LuaLDAP compiled binary should be copied to a directory in your C path. Lua 5.0 users should install Compat-5.1 also.

Windows users of ADSI can use the binary versions of LuaLDAP (lualdap.dll) available at LuaForge.

Representing attributes

Many LDAP operations manage sets of attributes and values. LuaLDAP provides a uniform way of representing them by using Lua tables. The table attributes can be Lua string, a binary string (a string of bits), or table of n values indexed from 1 to n. Some operations have different approaches that will be explained as necessary.

Here is a simple example:

entry = {
    an_attribute = "a value",
    other_attribute = {
        "first value of other attribute",
        "another value of other attribute",
    },
}
Attribute names cannot contain the '\0' character.

Distinguished names

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.

A more precise definition can be found on the LDAP documentation. A list of some of these files can be found in Related documentation section.

Initialization functions

LuaLDAP provides a single way to connect to an LDAP server:

lualdap.open_simple (hostname, who, password, usetls)
Initializes a session with an LDAP server. This function requires a hostname, accordingly to the C LDAP API definition ("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."). The argument who should be the distinguished name of the entry that has the password to be checked against the third argument, password. The optional argument usetls is a Boolean flag indicating if Transport Layer Security (TLS) should be used.
Returns a connection object if the operation was successful. In case of error it returns nil followed by an error string.

Connection objects

A connection object offers methods which implement LDAP operations. Almost all of them need a distinguished name to identify the entry on which the operation will be executed.

These methods execute asynchronous operations and return a function that should be called to obtain the results. The called functions will return true indicating the success of the operation. The only exception is the compare function which can return either true or false (as the result of the comparison) on a successful operation.

There are two types of errors: API errors, such as wrong parameters, absent connection etc.; and LDAP errors, such as malformed DN, unknown attribute etc. API errors will raise a Lua error, while LDAP errors will be reported by the function/method returning nil plus the error message provided by the OpenLDAP client.

A connection object can be created by calling the Initialization function.

Methods

conn:add (distinguished_name, table_of_attributes)
Adds a new entry to the directory with the given attributes and values.
conn:close()
Closes the connection conn.
conn:compare (distinguished_name, attribute, value)
Compares a value to an entry.
conn:delete (distinguished_name)
Deletes an entry from the directory.
conn:modify (distinguished_name, table_of_operations*)
Changes the values of attributes in the given entry. The tables of operations are tables of attributes with the value on index 1 indicating the operation to be performed. The valid operations are:
  • '+' to add the values to the attributes
  • '-' to delete the values of the attributes
  • '=' to replace the values of the attributes
Any number of tables of operations will be used in a single LDAP modify operation.
conn:rename (distinguished_name, new_relative_dn, new_parent)
Changes an entry name (i.e. change its distinguished name).
conn:search (table_of_search_parameters)
Performs a search operation on the directory. The parameters are described below:

attrs
a string or a list of attribute names to be retrieved (default is to retrieve all attributes).
attrsonly
a Boolean value that must be either false (default) if both attribute names and values are to be retrieved, or true if only names are wanted.
base
The distinguished name of the entry at which to start the search.
filter
A string representing the search filter as described in The String Representation of LDAP Search Filters (RFC 2254).
scope
A string indicating the scope of the search. The valid strings are: "base", "onelevel" and "subtree". The empty string ("") and nil will be treated as the default scope.
sizelimit
The maximum number of entries to return (default is no limit).
timeout
The timeout in seconds (default is no timeout). The precision is microseconds.

The search method will return a search iterator 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 distinguished name and a table of attributes as returned by the search request.

Example

here is a some sample code that demonstrate the basic use of the library.

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")()

Related documentation

Valid XHTML 1.0!

$Id: manual.html,v 1.34 2007-12-14 16:46:15 carregal Exp $

lua-ldap-1.1.0-1-geeac494/src/000077500000000000000000000000001174626301100154415ustar00rootroot00000000000000lua-ldap-1.1.0-1-geeac494/src/lualdap.c000066400000000000000000000636321174626301100172410ustar00rootroot00000000000000/* ** LuaLDAP ** See Copyright Notice in license.html ** $Id: lualdap.c,v 1.48 2007-12-14 15:11:22 carregal 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" #if ! defined (LUA_VERSION_NUM) || LUA_VERSION_NUM < 501 #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" #define LUALDAP_SEARCH_METATABLE "LuaLDAP search" #define LUALDAP_MOD_ADD (LDAP_MOD_ADD | LDAP_MOD_BVALUES) #define LUALDAP_MOD_DEL (LDAP_MOD_DELETE | LDAP_MOD_BVALUES) #define LUALDAP_MOD_REP (LDAP_MOD_REPLACE | LDAP_MOD_BVALUES) #define LUALDAP_NO_OP 0 /* Maximum number of attributes manipulated in an operation */ #ifndef LUALDAP_MAX_ATTRS #define LUALDAP_MAX_ATTRS 100 #endif /* Size of buffer of NULL-terminated arrays of pointers to struct values */ #ifndef LUALDAP_ARRAY_VALUES_SIZE #define LUALDAP_ARRAY_VALUES_SIZE (2 * LUALDAP_MAX_ATTRS) #endif /* Maximum number of values structures */ #ifndef LUALDAP_MAX_VALUES #define LUALDAP_MAX_VALUES (LUALDAP_ARRAY_VALUES_SIZE / 2) #endif /* LDAP connection information */ typedef struct { int version; /* LDAP version */ LDAP *ld; /* LDAP connection */ } conn_data; /* LDAP search context information */ typedef struct { int conn; /* conn_data reference */ int msgid; } search_data; /* LDAP attribute modification structure */ typedef struct { LDAPMod *attrs[LUALDAP_MAX_ATTRS + 1]; LDAPMod mods[LUALDAP_MAX_ATTRS]; int ai; BerValue *values[LUALDAP_ARRAY_VALUES_SIZE]; int vi; BerValue bvals[LUALDAP_MAX_VALUES]; int bi; } attrs_data; int luaopen_lualdap (lua_State *L); /* ** Typical error situation. */ static int faildirect (lua_State *L, const char *errmsg) { lua_pushnil (L); lua_pushstring (L, errmsg); return 2; } /* ** Get a connection object from the first stack position. */ static conn_data *getconnection (lua_State *L) { conn_data *conn = (conn_data *)luaL_checkudata (L, 1, LUALDAP_CONNECTION_METATABLE); luaL_argcheck(L, conn!=NULL, 1, LUALDAP_PREFIX"LDAP connection expected"); luaL_argcheck(L, conn->ld, 1, LUALDAP_PREFIX"LDAP connection is closed"); return conn; } /* ** Get a search object from the first upvalue position. */ static search_data *getsearch (lua_State *L) { /* don't need to check upvalue's integrity */ search_data *search = (search_data *)lua_touserdata (L, lua_upvalueindex (1)); luaL_argcheck (L,search->conn!=LUA_NOREF,1,LUALDAP_PREFIX"LDAP search is closed"); return search; } /* ** Set metatable of userdata on top of the stack. */ static void lualdap_setmeta (lua_State *L, const char *name) { luaL_getmetatable (L, name); lua_setmetatable (L, -2); } /* ** Error on option. */ static int option_error (lua_State *L, const char *name, const char *type) { return luaL_error (L, LUALDAP_PREFIX"invalid value on option `%s': %s expected, got %s", name, type, lua_typename (L, lua_type (L, -1))); } /* ** Get the field called name of the table at position 2. */ static void strgettable (lua_State *L, const char *name) { lua_pushstring (L, name); lua_gettable (L, 2); } /* ** Get the field named name as a string. ** The table MUST be at position 2. */ static const char *strtabparam (lua_State *L, const char *name, char *def) { strgettable (L, name); if (lua_isnil (L, -1)) return def; else if (lua_isstring (L, -1)) return lua_tostring (L, -1); else { option_error (L, name, "string"); return NULL; } } /* ** Get the field named name as an integer. ** The table MUST be at position 2. */ static long longtabparam (lua_State *L, const char *name, int def) { strgettable (L, name); if (lua_isnil (L, -1)) return def; else if (lua_isnumber (L, -1)) return (long)lua_tonumber (L, -1); else return option_error (L, name, "number"); } /* ** Get the field named name as a double. ** The table MUST be at position 2. */ static double numbertabparam (lua_State *L, const char *name, double def) { strgettable (L, name); if (lua_isnil (L, -1)) return def; else if (lua_isnumber (L, -1)) return lua_tonumber (L, -1); else return option_error (L, name, "number"); } /* ** Get the field named name as a boolean. ** The table MUST be at position 2. */ static int booltabparam (lua_State *L, const char *name, int def) { strgettable (L, name); if (lua_isnil (L, -1)) return def; else if (lua_isboolean (L, -1)) return lua_toboolean (L, -1); else return option_error (L, name, "boolean"); } /* ** Error on attribute's value. */ static void value_error (lua_State *L, const char *name) { luaL_error (L, LUALDAP_PREFIX"invalid value of attribute `%s' (%s)", name, lua_typename (L, lua_type (L, -1))); } /* ** Initialize attributes structure. */ static void A_init (attrs_data *attrs) { attrs->ai = 0; attrs->attrs[0] = NULL; attrs->vi = 0; attrs->values[0] = NULL; attrs->bi = 0; } /* ** Store the string on top of the stack on the attributes structure. ** Increment the bvals counter. */ static BerValue *A_setbval (lua_State *L, attrs_data *a, const char *n) { BerValue *ret = &(a->bvals[a->bi]); if (a->bi >= LUALDAP_MAX_VALUES) { luaL_error (L, LUALDAP_PREFIX"too many values"); return NULL; } else if (!lua_isstring (L, -1)) { value_error (L, n); return NULL; } a->bvals[a->bi].bv_len = lua_strlen (L, -1); a->bvals[a->bi].bv_val = (char *)lua_tostring (L, -1); a->bi++; return ret; } /* ** Store a pointer to the value on top of the stack on the attributes structure. */ static BerValue **A_setval (lua_State *L, attrs_data *a, const char *n) { BerValue **ret = &(a->values[a->vi]); if (a->vi >= LUALDAP_ARRAY_VALUES_SIZE) { luaL_error (L, LUALDAP_PREFIX"too many values"); return NULL; } a->values[a->vi] = A_setbval (L, a, n); a->vi++; return ret; } /* ** Store a NULL pointer on the attributes structure. */ static BerValue **A_nullval (lua_State *L, attrs_data *a) { BerValue **ret = &(a->values[a->vi]); if (a->vi >= LUALDAP_ARRAY_VALUES_SIZE) { luaL_error (L, LUALDAP_PREFIX"too many values"); return NULL; } a->values[a->vi] = NULL; a->vi++; return ret; } /* ** Store the value of an attribute. ** Valid values are: ** true => no values; ** string => one value; or ** table of strings => many values. */ static BerValue **A_tab2val (lua_State *L, attrs_data *a, const char *name) { int tab = lua_gettop (L); BerValue **ret = &(a->values[a->vi]); if (lua_isboolean (L, tab) && (lua_toboolean (L, tab) == 1)) /* true */ return NULL; else if (lua_isstring (L, tab)) /* string */ A_setval (L, a, name); else if (lua_istable (L, tab)) { /* list of strings */ int i; int n = luaL_getn (L, tab); for (i = 1; i <= n; i++) { lua_rawgeti (L, tab, i); /* push table element */ A_setval (L, a, name); } lua_pop (L, n); } else { value_error (L, name); return NULL; } A_nullval (L, a); return ret; } /* ** Set a modification value (which MUST be on top of the stack). */ static void A_setmod (lua_State *L, attrs_data *a, int op, const char *name) { if (a->ai >= LUALDAP_MAX_ATTRS) { luaL_error (L, LUALDAP_PREFIX"too many attributes"); return; } a->mods[a->ai].mod_op = op; a->mods[a->ai].mod_type = (char *)name; a->mods[a->ai].mod_bvalues = A_tab2val (L, a, name); a->attrs[a->ai] = &a->mods[a->ai]; a->ai++; } /* ** Convert a Lua table into an array of modifications. ** An array of modifications is a NULL-terminated array of LDAPMod's. */ static void A_tab2mod (lua_State *L, attrs_data *a, int tab, int op) { lua_pushnil (L); /* first key for lua_next */ while (lua_next (L, tab) != 0) { /* attribute must be a string and not a number */ if ((!lua_isnumber (L, -2)) && (lua_isstring (L, -2))) A_setmod (L, a, op, lua_tostring (L, -2)); /* pop value and leave last key on the stack as next key for lua_next */ lua_pop (L, 1); } } /* ** Terminate the array of attributes. */ static void A_lastattr (lua_State *L, attrs_data *a) { if (a->ai >= LUALDAP_MAX_ATTRS) { luaL_error (L, LUALDAP_PREFIX"too many attributes"); return; } a->attrs[a->ai] = NULL; a->ai++; } /* ** Copy a string or a table of strings from Lua to a NULL-terminated array ** of C-strings. */ static int table2strarray (lua_State *L, int tab, char *array[], int limit) { if (lua_isstring (L, tab)) { if (limit < 2) return luaL_error (L, LUALDAP_PREFIX"too many arguments"); array[0] = (char *)lua_tostring (L, tab); array[1] = NULL; } else if (lua_istable (L, tab)) { int i; int n = luaL_getn (L, tab); if (limit < (n+1)) return luaL_error (L, LUALDAP_PREFIX"too many arguments"); for (i = 0; i < n; i++) { lua_rawgeti (L, tab, i+1); /* push table element */ if (lua_isstring (L, -1)) array[i] = (char *)lua_tostring (L, -1); else { return luaL_error (L, LUALDAP_PREFIX"invalid value #%d", i+1); } } array[n] = NULL; } else return luaL_error (L, LUALDAP_PREFIX"bad argument #%d (table or string expected, got %s)", tab, lua_typename (L, lua_type (L, tab))); return 0; } /* ** Get the result message of an operation. ** #1 upvalue == connection ** #2 upvalue == msgid ** #3 upvalue == result code of the message (ADD, DEL etc.) to be received. */ static int result_message (lua_State *L) { struct timeval *timeout = NULL; /* ??? function parameter ??? */ LDAPMessage *res; int rc; conn_data *conn = (conn_data *)lua_touserdata (L, lua_upvalueindex (1)); int msgid = (int)lua_tonumber (L, lua_upvalueindex (2)); /*int res_code = (int)lua_tonumber (L, lua_upvalueindex (3));*/ luaL_argcheck (L, conn->ld, 1, LUALDAP_PREFIX"LDAP connection is closed"); rc = ldap_result (conn->ld, msgid, LDAP_MSG_ONE, timeout, &res); if (rc == 0) return faildirect (L, LUALDAP_PREFIX"result timeout expired"); else if (rc < 0) { ldap_msgfree (res); return faildirect (L, LUALDAP_PREFIX"result error"); } else { int err, ret = 1; char *mdn, *msg; rc = ldap_parse_result (conn->ld, res, &err, &mdn, &msg, NULL, NULL, 1); if (rc != LDAP_SUCCESS) return faildirect (L, ldap_err2string (rc)); switch (err) { case LDAP_SUCCESS: case LDAP_COMPARE_TRUE: lua_pushboolean (L, 1); break; case LDAP_COMPARE_FALSE: lua_pushboolean (L, 0); break; default: lua_pushnil (L); lua_pushliteral (L, LUALDAP_PREFIX); lua_pushstring (L, msg); lua_pushliteral (L, " "); lua_pushstring (L, ldap_err2string(err)); lua_concat (L, 4); ret = 2; } ldap_memfree (mdn); ldap_memfree (msg); return ret; } } /* ** Push a function to process the LDAP result. */ 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 */ lua_pushnumber (L, msgid); /* push msgid as #2 upvalue */ lua_pushnumber (L, code); /* push code as #3 upvalue */ lua_pushcclosure (L, result_message, 3); return 1; } /* ** Unbind from the directory. ** @param #1 LDAP connection. ** @return 1 in case of success; nothing when already closed. */ static int lualdap_close (lua_State *L) { conn_data *conn = (conn_data *)luaL_checkudata (L, 1, LUALDAP_CONNECTION_METATABLE); luaL_argcheck(L, conn!=NULL, 1, LUALDAP_PREFIX"LDAP connection expected"); if (conn->ld == NULL) /* already closed */ return 0; ldap_unbind (conn->ld); conn->ld = NULL; lua_pushnumber (L, 1); return 1; } /* ** Add a new entry to the directory. ** @param #1 LDAP connection. ** @param #2 String with new entry's DN. ** @param #3 Table with new entry's attributes and values. ** @return Function to process the LDAP result. */ static int lualdap_add (lua_State *L) { conn_data *conn = getconnection (L); ldap_pchar_t dn = (ldap_pchar_t) luaL_checkstring (L, 2); attrs_data attrs; ldap_int_t rc, msgid; A_init (&attrs); if (lua_istable (L, 3)) A_tab2mod (L, &attrs, 3, LUALDAP_MOD_ADD); A_lastattr (L, &attrs); rc = ldap_add_ext (conn->ld, dn, attrs.attrs, NULL, NULL, &msgid); return create_future (L, rc, 1, msgid, LDAP_RES_ADD); } /* ** Compare a value against an entry. ** @param #1 LDAP connection. ** @param #2 String with entry's DN. ** @param #3 String with attribute's name. ** @param #4 String with attribute's value. ** @return Function to process the LDAP result. */ static int lualdap_compare (lua_State *L) { conn_data *conn = getconnection (L); ldap_pchar_t dn = (ldap_pchar_t) luaL_checkstring (L, 2); ldap_pchar_t attr = (ldap_pchar_t) luaL_checkstring (L, 3); BerValue bvalue; 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); return create_future (L, rc, 1, msgid, LDAP_RES_COMPARE); } /* ** Delete an entry. ** @param #1 LDAP connection. ** @param #2 String with entry's DN. ** @return Boolean. */ static int lualdap_delete (lua_State *L) { conn_data *conn = getconnection (L); 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); } /* ** Convert a string into an internal LDAP_MOD operation code. */ static int op2code (const char *s) { if (!s) return LUALDAP_NO_OP; switch (*s) { case '+': return LUALDAP_MOD_ADD; case '-': return LUALDAP_MOD_DEL; case '=': return LUALDAP_MOD_REP; default: return LUALDAP_NO_OP; } } /* ** Modify an entry. ** @param #1 LDAP connection. ** @param #2 String with entry's DN. ** @param #3, #4... Tables with modifications to apply. ** @return True on success or nil, error message otherwise. */ static int lualdap_modify (lua_State *L) { conn_data *conn = getconnection (L); ldap_pchar_t dn = (ldap_pchar_t) luaL_checkstring (L, 2); attrs_data attrs; ldap_int_t rc, msgid; int param = 3; A_init (&attrs); while (lua_istable (L, param)) { int op; /* get operation ('+','-','=' operations allowed) */ lua_rawgeti (L, param, 1); op = op2code (lua_tostring (L, -1)); if (op == LUALDAP_NO_OP) return luaL_error (L, LUALDAP_PREFIX"forgotten operation on argument #%d", param); /* get array of attributes and values */ A_tab2mod (L, &attrs, param, op); param++; } A_lastattr (L, &attrs); rc = ldap_modify_ext (conn->ld, dn, attrs.attrs, NULL, NULL, &msgid); return create_future (L, rc, 1, msgid, LDAP_RES_MODIFY); } /* ** Change the distinguished name of an entry. */ static int lualdap_rename (lua_State *L) { conn_data *conn = getconnection (L); 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); 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); } /* ** Push an attribute value (or a table of values) on top of the stack. ** @param L lua_State. ** @param ld LDAP Connection. ** @param entry Current entry. ** @param attr Name of entry's attribute to get values from. ** @return 1 in case of success. */ static int push_values (lua_State *L, LDAP *ld, LDAPMessage *entry, char *attr) { int i, n; BerValue **vals = ldap_get_values_len (ld, entry, attr); n = ldap_count_values_len (vals); if (n == 0) /* no values */ lua_pushboolean (L, 1); else if (n == 1) /* just one value */ lua_pushlstring (L, vals[0]->bv_val, vals[0]->bv_len); else { /* Multiple values */ lua_newtable (L); for (i = 0; i < n; i++) { lua_pushlstring (L, vals[i]->bv_val, vals[i]->bv_len); lua_rawseti (L, -2, i+1); } } ldap_value_free_len (vals); return 1; } /* ** Store entry's attributes and values at the given table. ** @param entry Current entry. ** @param tab Absolute stack index of the table. */ static void set_attribs (lua_State *L, LDAP *ld, LDAPMessage *entry, int tab) { char *attr; BerElement *ber = NULL; for (attr = ldap_first_attribute (ld, entry, &ber); attr != NULL; attr = ldap_next_attribute (ld, entry, ber)) { lua_pushstring (L, attr); push_values (L, ld, entry, attr); lua_rawset (L, tab); /* tab[attr] = vals */ ldap_memfree (attr); } ber_free (ber, 0); /* don't need to test if (ber == NULL) */ } /* ** Get the distinguished name of the given entry and pushes it on the stack. */ static void push_dn (lua_State *L, LDAP *ld, LDAPMessage *entry) { char *dn = ldap_get_dn (ld, entry); lua_pushstring (L, dn); ldap_memfree (dn); } /* ** Release connection reference. */ static void search_close (lua_State *L, search_data *search) { luaL_unref (L, LUA_REGISTRYINDEX, search->conn); search->conn = LUA_NOREF; } /* ** Retrieve next message... ** @return #1 entry's distinguished name. ** @return #2 table with entry's attributes and values. */ static int next_message (lua_State *L) { search_data *search = getsearch (L); conn_data *conn; struct timeval *timeout = NULL; /* ??? function parameter ??? */ LDAPMessage *res; int rc; int ret; lua_rawgeti (L, LUA_REGISTRYINDEX, search->conn); conn = (conn_data *)lua_touserdata (L, -1); /* get connection */ rc = ldap_result (conn->ld, search->msgid, LDAP_MSG_ONE, timeout, &res); if (rc == 0) return faildirect (L, LUALDAP_PREFIX"result timeout expired"); else if (rc == -1) return faildirect (L, LUALDAP_PREFIX"result error"); else if (rc == LDAP_RES_SEARCH_RESULT) { /* last message => nil */ /* close search object to avoid reuse */ search_close (L, search); ret = 0; } else { LDAPMessage *msg = ldap_first_message (conn->ld, res); switch (ldap_msgtype (msg)) { case LDAP_RES_SEARCH_ENTRY: { LDAPMessage *entry = ldap_first_entry (conn->ld, msg); push_dn (L, conn->ld, entry); lua_newtable (L); set_attribs (L, conn->ld, entry, lua_gettop (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? */ lua_pushnil (L); ret = 2; /* two return values */ break; } #endif case LDAP_RES_SEARCH_RESULT: /* close search object to avoid reuse */ search_close (L, search); ret = 0; break; default: ldap_msgfree (res); return luaL_error (L, LUALDAP_PREFIX"error on search result chain"); } } ldap_msgfree (res); return ret; } /* ** Convert a string to one of the possible scopes of the search. */ static int string2scope (lua_State *L, const char *s) { if ((s == NULL) || (*s == '\0')) return LDAP_SCOPE_DEFAULT; switch (*s) { case 'b': return LDAP_SCOPE_BASE; case 'o': return LDAP_SCOPE_ONELEVEL; case 's': return LDAP_SCOPE_SUBTREE; default: return luaL_error (L, LUALDAP_PREFIX"invalid search scope `%s'", s); } } /* ** Close the search object. */ static int lualdap_search_close (lua_State *L) { search_data *search = (search_data *)luaL_checkudata (L, 1, LUALDAP_SEARCH_METATABLE); luaL_argcheck (L, search!=NULL, 1, LUALDAP_PREFIX"LDAP search expected"); if (search->conn == LUA_NOREF) return 0; search_close (L, search); lua_pushnumber (L, 1); return 1; } /* ** Create a search object and leaves it on top of the stack. */ static void create_search (lua_State *L, int conn_index, int msgid) { search_data *search = (search_data *)lua_newuserdata (L, sizeof (search_data)); lualdap_setmeta (L, LUALDAP_SEARCH_METATABLE); search->conn = LUA_NOREF; search->msgid = msgid; lua_pushvalue (L, conn_index); search->conn = luaL_ref (L, LUA_REGISTRYINDEX); } /* ** Fill in the attrs array, according to the attrs parameter. */ static int get_attrs_param (lua_State *L, char *attrs[]) { lua_pushstring (L, "attrs"); lua_gettable (L, 2); if (lua_isstring (L, -1)) { attrs[0] = (char *)lua_tostring (L, -1); attrs[1] = NULL; } else if (!lua_istable (L, -1)) attrs[0] = NULL; else if (table2strarray (L, lua_gettop (L), attrs, LUALDAP_MAX_ATTRS)) return 0; return 1; } /* ** Fill in the struct timeval, according to the timeout parameter. */ static struct timeval *get_timeout_param (lua_State *L, struct timeval *st) { double t = numbertabparam (L, "timeout", 0); st->tv_sec = (long)t; st->tv_usec = (long)(1000000 * (t - st->tv_sec)); if (st->tv_sec == 0 && st->tv_usec == 0) return NULL; else return st; } /* ** Perform a search operation. ** @return #1 Function to iterate over the result entries. ** @return #2 nil. ** @return #3 nil as first entry. ** The search result is defined as an upvalue of the iterator. */ static int lualdap_search (lua_State *L) { conn_data *conn = getconnection (L); ldap_pchar_t base; ldap_pchar_t filter; char *attrs[LUALDAP_MAX_ATTRS]; int scope, attrsonly, msgid, rc, sizelimit; struct timeval st, *timeout; if (!lua_istable (L, 2)) return luaL_error (L, LUALDAP_PREFIX"no search specification"); if (!get_attrs_param (L, attrs)) return 2; /* get other parameters */ attrsonly = booltabparam (L, "attrsonly", 0); 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); rc = ldap_search_ext (conn->ld, base, scope, filter, attrs, attrsonly, NULL, NULL, timeout, sizelimit, &msgid); if (rc != LDAP_SUCCESS) return luaL_error (L, LUALDAP_PREFIX"%s", ldap_err2string (rc)); create_search (L, 1, msgid); lua_pushcclosure (L, next_message, 1); return 1; } /* ** Return the name of the object's metatable. ** This function is used by `tostring'. */ static int lualdap_conn_tostring (lua_State *L) { char buff[100]; conn_data *conn = (conn_data *)lua_touserdata (L, 1); if (conn->ld == NULL) strcpy (buff, "closed"); else sprintf (buff, "%p", conn); lua_pushfstring (L, "%s (%s)", LUALDAP_CONNECTION_METATABLE, buff); return 1; } /* ** Return the name of the object's metatable. ** This function is used by `tostring'. */ static int lualdap_search_tostring (lua_State *L) { char buff[100]; search_data *search = (search_data *)lua_touserdata (L, 1); luaL_argcheck (L,search->conn!=LUA_NOREF,1,LUALDAP_PREFIX"LDAP search is closed"); if (search->conn == LUA_NOREF) strcpy (buff, "closed"); else sprintf (buff, "%p", search); lua_pushfstring (L, "%s (%s)", LUALDAP_SEARCH_METATABLE, buff); return 1; } /* ** Create a metatable. */ static int lualdap_createmeta (lua_State *L) { const luaL_reg methods[] = { {"close", lualdap_close}, {"add", lualdap_add}, {"compare", lualdap_compare}, {"delete", lualdap_delete}, {"modify", lualdap_modify}, {"rename", lualdap_rename}, {"search", lualdap_search}, {NULL, NULL} }; if (!luaL_newmetatable (L, LUALDAP_CONNECTION_METATABLE)) return 0; /* define methods */ luaL_openlib (L, NULL, methods, 0); /* define metamethods */ lua_pushliteral (L, "__gc"); lua_pushcfunction (L, lualdap_close); lua_settable (L, -3); lua_pushliteral (L, "__index"); lua_pushvalue (L, -2); lua_settable (L, -3); lua_pushliteral (L, "__tostring"); lua_pushcfunction (L, lualdap_conn_tostring); lua_settable (L, -3); lua_pushliteral (L, "__metatable"); lua_pushliteral(L,LUALDAP_PREFIX"you're not allowed to get this metatable"); lua_settable (L, -3); if (!luaL_newmetatable (L, LUALDAP_SEARCH_METATABLE)) return 0; lua_pushliteral (L, "__gc"); lua_pushcfunction (L, lualdap_search_close); lua_settable (L, -3); lua_pushliteral (L, "__tostring"); lua_pushcclosure (L, lualdap_search_tostring, 1); lua_settable (L, -3); lua_pushliteral (L, "__metatable"); lua_pushliteral(L,LUALDAP_PREFIX"you're not allowed to get this metatable"); lua_settable (L, -3); return 0; } /* ** Open and initialize a connection to a server. ** @param #1 String with hostname. ** @param #2 String with username. ** @param #3 String with password. ** @param #4 Boolean indicating if TLS must be used. ** @return #1 Userdata with connection structure. */ static int lualdap_open_simple (lua_State *L) { 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)); int err; /* Initialize */ lualdap_setmeta (L, LUALDAP_CONNECTION_METATABLE); conn->version = 0; conn->ld = ldap_init (host, LDAP_PORT); if (conn->ld == NULL) return faildirect(L,LUALDAP_PREFIX"Error connecting to server"); /* Set protocol version */ conn->version = LDAP_VERSION3; if (ldap_set_option (conn->ld, LDAP_OPT_PROTOCOL_VERSION, &conn->version) != LDAP_OPT_SUCCESS) return faildirect(L, LUALDAP_PREFIX"Error setting LDAP version"); /* Use TLS */ if (use_tls) { int rc = ldap_start_tls_s (conn->ld, NULL, NULL); if (rc != LDAP_SUCCESS) return faildirect (L, ldap_err2string (rc)); } /* Bind to a server */ err = ldap_bind_s (conn->ld, who, password, LDAP_AUTH_SIMPLE); if (err != LDAP_SUCCESS) return faildirect (L, ldap_err2string (err)); return 1; } /* ** Assumes the table is on top of the stack. */ static void set_info (lua_State *L) { lua_pushliteral (L, "_COPYRIGHT"); lua_pushliteral (L, "Copyright (C) 2003-2007 Kepler Project"); lua_settable (L, -3); lua_pushliteral (L, "_DESCRIPTION"); lua_pushliteral (L, "LuaLDAP is a simple interface from Lua to an LDAP client"); lua_settable (L, -3); lua_pushliteral (L, "_VERSION"); lua_pushliteral (L, "LuaLDAP 1.1.1"); lua_settable (L, -3); } /* ** Create ldap table and register the open method. */ int luaopen_lualdap (lua_State *L) { struct luaL_reg lualdap[] = { {"open_simple", lualdap_open_simple}, {NULL, NULL}, }; lualdap_createmeta (L); luaL_openlib (L, LUALDAP_TABLENAME, lualdap, 0); set_info (L); return 1; } lua-ldap-1.1.0-1-geeac494/src/lualdap.def000066400000000000000000000001271174626301100175430ustar00rootroot00000000000000LIBRARY lualdap.dll DESCRIPTION "LuaLDAP" VERSION 1.1.1 EXPORTS luaopen_lualdap lua-ldap-1.1.0-1-geeac494/src/open2winldap.h000066400000000000000000000031021174626301100202100ustar00rootroot00000000000000#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 lua-ldap-1.1.0-1-geeac494/tests/000077500000000000000000000000001174626301100160145ustar00rootroot00000000000000lua-ldap-1.1.0-1-geeac494/tests/test.lua000066400000000000000000000325341174626301100175050ustar00rootroot00000000000000#!/usr/local/bin/lua5.1 --------------------------------------------------------------------- -- LuaLDAP test file. -- This test will create a copy of an existing entry on the -- directory to work on. This new entry will be modified, -- renamed and deleted at the end. -- -- See Copyright Notice in license.html -- $Id: test.lua,v 1.15 2006-07-24 01:36:51 tomas Exp $ --------------------------------------------------------------------- -- DN_PAT = "^([^,=]+)%=([^,]+)%,?(.*)$" --------------------------------------------------------------------- -- Print attributes. --------------------------------------------------------------------- function print_attrs (dn, attrs) if not dn then io.write ("nil\n") return end io.write (string.format ("\t[%s]\n", dn)) for name, values in pairs (attrs) do io.write ("["..name.."] : ") local tv = type (values) if tv == "string" then io.write (values) elseif tv == "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 --------------------------------------------------------------------- -- clone a table. --------------------------------------------------------------------- function clone (tab) local new = {} for i, v in pairs (tab) do new[i] = v end return new end --------------------------------------------------------------------- -- checks for a value and throw an error if it is not the expected. --------------------------------------------------------------------- function assert2 (expected, value, msg) if not msg then msg = '' else msg = tostring(msg)..'\n' end local ret = assert (value == expected, msg.."wrong value (["..tostring(value).."] instead of ".. tostring(expected)..")") io.write('.') return ret end --------------------------------------------------------------------- -- object test. --------------------------------------------------------------------- function test_object (obj, objmethods) -- checking object type. assert2 ("userdata", type(obj), "incorrect object type") -- trying to get metatable. assert2 ("LuaLDAP: you're not allowed to get this metatable", getmetatable(obj), "error permitting access to object's metatable") -- trying to set metatable. assert2 (false, pcall (setmetatable, ENV, {})) -- checking existence of object's methods. for i = 1, table.getn (objmethods) do local method = obj[objmethods[i]] assert2 ("function", type(method)) assert2 (false, pcall (method), "no 'self' parameter accepted") end return obj end CONN_OK = function (obj, err) if obj == nil then error (err, 2) end return test_object (obj, { "close", "add", "compare", "delete", "modify", "rename", "search", }) end --------------------------------------------------------------------- -- basic checking test. --------------------------------------------------------------------- function basic_test () local ld = CONN_OK (lualdap.open_simple (HOSTNAME, WHO, PASSWORD)) assert2 (1, ld:close(), "couldn't close connection") -- trying to close without a connection. assert2 (false, pcall (ld.close)) -- trying to close an invalid connection. assert2 (false, pcall (ld.close, io.output())) -- trying to use a closed connection. local _,_,rdn_name,rdn_value = string.find (BASE, DN_PAT) assert2 (false, pcall (ld.compare, ld, BASE, rdn_name, rdn_value), "permitting the use of a closed connection") -- it is ok to close a closed object, but nil is returned instead of 1. assert2 (nil, ld:close()) -- trying to connect to an invalid host. assert2 (nil, lualdap.open_simple ("unknown-server"), "this should be an error") -- reopen the connection. -- first, try using TLS local ok = lualdap.open_simple (HOSTNAME, WHO, PASSWORD, true) if not ok then -- second, try without TLS io.write ("\nWarning! Couldn't connect with TLS. Trying again without it.") ok = lualdap.open_simple (HOSTNAME, WHO, PASSWORD, false) end LD = CONN_OK (ok) CLOSED_LD = ld collectgarbage() end --------------------------------------------------------------------- -- checks return value which should be a function AND also its return value. --------------------------------------------------------------------- function check_future (ret, method, ...) local ok, f = pcall (method, unpack (arg)) assert (ok, f) assert2 ("function", type(f)) assert2 (ret, f()) io.write('.') end --------------------------------------------------------------------- -- checking compare operation. --------------------------------------------------------------------- function compare_test () local _,_,rdn_name,rdn_value = string.find (BASE, DN_PAT) assert (type(rdn_name) == "string", "could not extract RDN name") assert (type(rdn_value) == "string", "could not extract RDN value") -- comparing against the correct value. check_future (true, LD.compare, LD, BASE, rdn_name, rdn_value) -- comparing against a wrong value. check_future (false, LD.compare, LD, BASE, rdn_name, rdn_value..'_') -- comparing against an incorrect attribute name. check_future (nil, LD.compare, LD, BASE, rdn_name..'x', rdn_value) -- comparing on a wrong base. check_future (nil, LD.compare, LD, 'qwerty', rdn_name, rdn_value) -- comparing with a closed connection. assert2 (false, pcall (LD.compare, CLOSED_LD, BASE, rdn_name, rdn_value)) -- comparing with an invalid userdata. assert2 (false, pcall (LD.compare, io.output(), BASE, rdn_name, rdn_value)) end --------------------------------------------------------------------- -- checking basic search operation. --------------------------------------------------------------------- function search_test_1 () local _,_,rdn = string.find (WHO, "^([^,]+)%,.*$") local iter = LD:search { base = BASE, scope = "onelevel", sizelimit = 1, filter = "("..rdn..")", } assert2 ("function", type(iter)) collectgarbage() CONN_OK (LD) local dn, entry = iter () assert2 ("string", type(dn)) assert2 ("table", type(entry)) collectgarbage() assert2 ("function", type(iter)) CONN_OK (LD) DN, ENTRY = LD:search { base = BASE, scope = "onelevel", sizelimit = 1, filter = "("..rdn..")", }() collectgarbage() assert2 ("string", type(DN)) assert2 ("table", type(ENTRY)) end --------------------------------------------------------------------- -- checking add operation. --------------------------------------------------------------------- function add_test () -- clone an entry. NEW = clone (ENTRY) local _,_,rdn_name, rdn_value, parent_dn = string.find (DN, DN_PAT) NEW[rdn_name] = rdn_value.."_copy" NEW_DN = string.format ("%s=%s,%s", rdn_name, NEW[rdn_name], parent_dn) -- trying to insert an entry with a wrong connection. assert2 (false, pcall (LD.add, CLOSED_LD, NEW_DN, NEW)) -- trying to insert an entry with an invalid connection. assert2 (false, pcall (LD.add, io.output(), NEW_DN, NEW)) -- trying to insert an entry with a wrong DN. local wrong_dn = string.format ("%s_x=%s,%s", rdn_name, NEW_DN, parent_dn) --assert2 (nil, LD:add (wrong_dn, NEW)) check_future (nil, LD.add, LD, wrong_dn, NEW) -- trying to insert the clone on the LDAP data base. check_future (true, LD.add, LD, NEW_DN, NEW) -- trying to reinsert the clone entry on the directory. check_future (nil, LD.add, LD, NEW_DN, NEW) end --------------------------------------------------------------------- -- checking modify operation. --------------------------------------------------------------------- function modify_test () -- modifying without connection. assert2 (false, pcall (LD.modify, nil, NEW_DN, {})) -- modifying with a closed connection. assert2 (false, pcall (LD.modify, CLOSED_LD, NEW_DN, {})) -- modifying with an invalid userdata. assert2 (false, pcall (LD.modify, io.output(), NEW_DN, {})) -- checking invalid DN. assert2 (false, pcall (LD.modify, LD, {})) -- no modification to apply. check_future (true, LD.modify, LD, NEW_DN) -- forgotten operation on modifications table. local a_attr, a_value = next (ENTRY) assert2 (false, pcall (LD.modify, LD, NEW_DN, { [a_attr] = "abc"})) -- modifying an unknown entry. local _,_, rdn_name, rdn_value, parent_dn = string.find (NEW_DN, DN_PAT) local new_rdn = rdn_name..'='..rdn_value..'_' local new_dn = string.format ("%s,%s", new_rdn, parent_dn) check_future (nil, LD.modify, LD, new_dn) -- trying to create an undefined attribute. check_future (nil, LD.modify, LD, NEW_DN, {'+', unknown_attribute = 'a'}) end --------------------------------------------------------------------- function count (tab) local counter = 0 for dn, entry in LD:search (tab) do counter = counter + 1 end return counter end --------------------------------------------------------------------- -- checking advanced search operation. --------------------------------------------------------------------- function search_test_2 () local _,_,rdn = string.find (WHO, "^([^,]+)%,.*$") local iter = LD:search { base = BASE, scope = "onelevel", sizelimit = 1, filter = "("..rdn..")", } assert2 ("function", type(iter)) collectgarbage () assert2 ("function", type(iter)) local dn, entry = iter () assert2 ("string", type(dn)) assert2 ("table", type(entry)) collectgarbage () assert2 ("function", type(iter)) iter = nil collectgarbage () -- checking no search specification. assert2 (false, pcall (LD.search, LD)) -- checking invalid scope. assert2 (false, pcall (LD.search, LD, { scope = 'BASE', base = BASE, })) -- checking invalid base. check_future (nil, LD.search, LD, { base = "invalid", scope = "base", }) -- checking filter. local _,_, rdn_name, rdn_value, parent_dn = string.find (NEW_DN, DN_PAT) local filter = string.format ("(%s=%s)", rdn_name, rdn_value) assert (count { base = BASE, scope = "subtree", filter = filter, } == 1) -- checking sizelimit. assert (count { base = BASE, scope = "subtree", sizelimit = 1, } == 1) -- checking attrsonly parameter. for dn, entry in LD:search { base = BASE, scope = "subtree", attrsonly = true, } do for attr, value in pairs (entry) do assert (value == true, "attrsonly failed") end end -- checking reuse of search object. local iter = assert (LD:search { base = BASE, scope = "base", }) assert (type(iter) == "function") local dn, e1 = iter() assert (type(dn) == "string") assert (type(e1) == "table") dn, e1 = iter() assert (type(dn) == "nil") assert (type(e1) == "nil") assert2 (false, pcall (iter)) iter = nil -- checking collecting search objects. local dn, entry = LD:search { base = BASE, scope = "base" }() collectgarbage() end --------------------------------------------------------------------- -- checking rename operation. --------------------------------------------------------------------- function rename_test () local _,_, rdn_name, rdn_value, parent_dn = string.find (NEW_DN, DN_PAT) local new_rdn = rdn_name..'='..rdn_value..'_' local new_dn = string.format ("%s,%s", new_rdn, parent_dn) -- trying to rename with no parent. check_future (true, LD.rename, LD, NEW_DN, new_rdn, nil) -- trying to rename an invalid dn. check_future (nil, LD.rename, LD, NEW_DN, new_rdn, nil) -- trying to rename with the same parent. check_future (true, LD.rename, LD, new_dn, rdn_name..'='..rdn_value, parent_dn) -- trying to rename to an inexistent parent. check_future (nil, LD.rename, LD, NEW_DN, new_rdn, new_dn) -- mal-formed DN. assert2 (false, pcall (LD.rename, LD, "")) -- trying to rename with a closed connection. assert2 (false, pcall (LD.rename, CLOSED_LD, NEW_DN, new_rdn, nil)) -- trying to rename with an invalid connection. assert2 (false, pcall (LD.rename, io.output(), NEW_DN, new_rdn, nil)) end --------------------------------------------------------------------- -- checking delete operation. --------------------------------------------------------------------- function delete_test () -- trying to delete with a closed connection. assert2 (false, pcall (LD.delete, CLOSED_LD, NEW_DN)) -- trying to delete with an invalid connection. assert2 (false, pcall (LD.delete, io.output(), NEW_DN)) -- trying to delete new entry. check_future (true, LD.delete, LD, NEW_DN) -- trying to delete an already deleted entry. check_future (nil, LD.delete, LD, NEW_DN) -- mal-formed DN. check_future (nil, LD.delete, LD, "") -- no DN. assert2 (false, pcall (LD.delete, LD)) end --------------------------------------------------------------------- -- checking close operation. --------------------------------------------------------------------- function close_test () assert (LD:close () == 1, "couldn't close connection") end --------------------------------------------------------------------- tests = { { "basic checking", basic_test }, { "checking compare operation", compare_test }, { "checking basic search operation", search_test_1 }, { "checking add operation", add_test }, { "checking modify operation", modify_test }, { "checking advanced search operation", search_test_2 }, { "checking rename operation", rename_test }, { "checking delete operation", delete_test }, { "closing everything", close_test }, } --------------------------------------------------------------------- -- Main --------------------------------------------------------------------- if table.getn(arg) < 1 then print (string.format ("Usage %s host[:port] base [who [password]]", arg[0])) os.exit() end HOSTNAME = arg[1] BASE = arg[2] WHO = arg[3] PASSWORD = arg[4] require"lualdap" assert (type(lualdap)=="table", "couldn't load LDAP library") for i = 1, table.getn (tests) do local t = tests[i] io.write (t[1].." ...") t[2] () io.write (" OK !\n") end lua-ldap-1.1.0-1-geeac494/vc6/000077500000000000000000000000001174626301100153505ustar00rootroot00000000000000lua-ldap-1.1.0-1-geeac494/vc6/lualdap.def000066400000000000000000000001161174626301100174500ustar00rootroot00000000000000LIBRARY lualdap.dll DESCRIPTION "LuaLDAP" VERSION 1.0 EXPORTS luaopen_lualdap lua-ldap-1.1.0-1-geeac494/vc6/lualdap.dsw000066400000000000000000000030041174626301100175060ustar00rootroot00000000000000Microsoft Developer Studio Workspace File, Format Version 6.00 # WARNING: DO NOT EDIT OR DELETE THIS WORKSPACE FILE! ############################################################################### Project: "liblber"="..\..\external-src\openldap-2.1.30\libraries\liblber\liblber.dsp" - Package Owner=<4> Package=<5> {{{ }}} Package=<4> {{{ }}} ############################################################################### Project: "libldap"="..\..\external-src\openldap-2.1.30\libraries\libldap\libldap.dsp" - Package Owner=<4> Package=<5> {{{ }}} Package=<4> {{{ Begin Project Dependency Project_Dep_Name liblber End Project Dependency Begin Project Dependency Project_Dep_Name libsasl End Project Dependency }}} ############################################################################### Project: "libsasl"="..\..\external-src\cyrus-sasl-1.5.28\win32\libsasl\libsasl.dsp" - Package Owner=<4> Package=<5> {{{ }}} Package=<4> {{{ }}} ############################################################################### Project: "lualdap_dll"=.\lualdap_dll.dsp - Package Owner=<4> Package=<5> {{{ begin source code control lualdap_dll .. end source code control }}} Package=<4> {{{ Begin Project Dependency Project_Dep_Name libldap End Project Dependency }}} ############################################################################### Global: Package=<5> {{{ }}} Package=<3> {{{ }}} ############################################################################### lua-ldap-1.1.0-1-geeac494/vc6/lualdap.rc000066400000000000000000000047141174626301100173260ustar00rootroot00000000000000//Microsoft Developer Studio generated resource script. // #include "resource.h" #define APSTUDIO_READONLY_SYMBOLS ///////////////////////////////////////////////////////////////////////////// // // Generated from the TEXTINCLUDE 2 resource. // #include "afxres.h" ///////////////////////////////////////////////////////////////////////////// #undef APSTUDIO_READONLY_SYMBOLS ///////////////////////////////////////////////////////////////////////////// // Portuguese (Brazil) resources #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_PTB) #ifdef _WIN32 LANGUAGE LANG_PORTUGUESE, SUBLANG_PORTUGUESE_BRAZILIAN #pragma code_page(1252) #endif //_WIN32 #ifndef _MAC ///////////////////////////////////////////////////////////////////////////// // // Version // VS_VERSION_INFO VERSIONINFO FILEVERSION 1,0,0,0 PRODUCTVERSION 1,0,0,0 FILEFLAGSMASK 0x3fL #ifdef _DEBUG FILEFLAGS 0x21L #else FILEFLAGS 0x20L #endif FILEOS 0x40004L FILETYPE 0x2L FILESUBTYPE 0x0L BEGIN BLOCK "StringFileInfo" BEGIN BLOCK "000004b0" BEGIN VALUE "Comments", "OpenLDAP 2.1.30\0" VALUE "CompanyName", "Ideais\0" VALUE "FileDescription", "lualdap\0" VALUE "FileVersion", "1, 0, 0, 0\0" VALUE "InternalName", "lualdap\0" VALUE "LegalCopyright", "Copyright 2005\0" VALUE "LegalTrademarks", "\0" VALUE "OriginalFilename", "lualdap.dll\0" VALUE "PrivateBuild", "\0" VALUE "ProductName", "Ideais lualdap\0" VALUE "ProductVersion", "1, 0, 0, 0\0" VALUE "SpecialBuild", "Kepler Project\0" END END BLOCK "VarFileInfo" BEGIN VALUE "Translation", 0x0, 1200 END END #endif // !_MAC #ifdef APSTUDIO_INVOKED ///////////////////////////////////////////////////////////////////////////// // // TEXTINCLUDE // 1 TEXTINCLUDE DISCARDABLE BEGIN "resource.h\0" END 2 TEXTINCLUDE DISCARDABLE BEGIN "#include ""afxres.h""\r\n" "\0" END 3 TEXTINCLUDE DISCARDABLE BEGIN "\r\n" "\0" END #endif // APSTUDIO_INVOKED #endif // Portuguese (Brazil) resources ///////////////////////////////////////////////////////////////////////////// #ifndef APSTUDIO_INVOKED ///////////////////////////////////////////////////////////////////////////// // // Generated from the TEXTINCLUDE 3 resource. // ///////////////////////////////////////////////////////////////////////////// #endif // not APSTUDIO_INVOKED lua-ldap-1.1.0-1-geeac494/vc6/lualdap_dll.dsp000066400000000000000000000123401174626301100203350ustar00rootroot00000000000000# Microsoft Developer Studio Project File - Name="lualdap_dll" - Package Owner=<4> # Microsoft Developer Studio Generated Build File, Format Version 6.00 # ** DO NOT EDIT ** # TARGTYPE "Win32 (x86) Dynamic-Link Library" 0x0102 CFG=lualdap_dll - Win32 Debug !MESSAGE This is not a valid makefile. To build this project using NMAKE, !MESSAGE use the Export Makefile command and run !MESSAGE !MESSAGE NMAKE /f "lualdap_dll.mak". !MESSAGE !MESSAGE You can specify a configuration when running NMAKE !MESSAGE by defining the macro CFG on the command line. For example: !MESSAGE !MESSAGE NMAKE /f "lualdap_dll.mak" CFG="lualdap_dll - Win32 Debug" !MESSAGE !MESSAGE Possible choices for configuration are: !MESSAGE !MESSAGE "lualdap_dll - Win32 Release" (based on "Win32 (x86) Dynamic-Link Library") !MESSAGE "lualdap_dll - Win32 Debug" (based on "Win32 (x86) Dynamic-Link Library") !MESSAGE # Begin Project # PROP AllowPerConfigDependencies 0 # PROP Scc_ProjName "lualdap_dll" # PROP Scc_LocalPath ".." CPP=cl.exe MTL=midl.exe RSC=rc.exe !IF "$(CFG)" == "lualdap_dll - Win32 Release" # PROP BASE Use_MFC 0 # PROP BASE Use_Debug_Libraries 0 # PROP BASE Output_Dir "Release" # PROP BASE Intermediate_Dir "Release" # PROP BASE Target_Dir "" # PROP Use_MFC 0 # PROP Use_Debug_Libraries 0 # PROP Output_Dir "../lib/vc6" # PROP Intermediate_Dir "lualdap_dll/Release" # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /MT /W3 /GX /O2 /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "LUALDAP_DLL_EXPORTS" /YX /FD /c # ADD CPP /nologo /MD /W3 /GX /O2 /I "../../external-src/lua50/include" /I "../../external-src/openldap-2.1.30/include" /I "../../compat/src" /D "WIN32" /D "NDEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "LUALDAP_DLL_EXPORTS" /FR /YX /FD /c # ADD BASE MTL /nologo /D "NDEBUG" /mktyplib203 /win32 # ADD MTL /nologo /D "NDEBUG" /mktyplib203 /win32 # ADD BASE RSC /l 0x416 /d "NDEBUG" # ADD RSC /l 0x416 /d "NDEBUG" BSC32=bscmake.exe # ADD BASE BSC32 /nologo # ADD BSC32 /nologo LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 # ADD LINK32 lua50.lib wsock32.lib oldap32.lib olber32.lib libsasl.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /machine:I386 /out:"../bin/vc6/lualdap.dll" /libpath:"../../external-src/lua50/lib/dll" /libpath:"../../external-src/openldap-2.1.30/Release" /libpath:"../../external-src/cyrus-sasl-1.5.28/win32/libsasl/Release" # Begin Special Build Tool SOURCE="$(InputPath)" PostBuild_Cmds=cd ../bin/vc6 zip.exe lualdap-1.0-win32.zip lualdap.dll zip.exe -j lualdap-1.0-win32.zip ../../../external-src/cyrus-sasl-1.5.28/win32/libsasl/Release/libsasl.dll # End Special Build Tool !ELSEIF "$(CFG)" == "lualdap_dll - Win32 Debug" # PROP BASE Use_MFC 0 # PROP BASE Use_Debug_Libraries 1 # PROP BASE Output_Dir "Debug" # PROP BASE Intermediate_Dir "Debug" # PROP BASE Target_Dir "" # PROP Use_MFC 0 # PROP Use_Debug_Libraries 1 # PROP Output_Dir "../lib/vc6" # PROP Intermediate_Dir "lualdap_dll/Debug" # PROP Ignore_Export_Lib 0 # PROP Target_Dir "" # ADD BASE CPP /nologo /MTd /W3 /Gm /GX /ZI /Od /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "LUALDAP_DLL_EXPORTS" /YX /FD /GZ /c # ADD CPP /nologo /MDd /W3 /Gm /GX /ZI /Od /I "../../external-src/lua50/include" /I "../../external-src/openldap-2.1.30/include" /I "../../compat/src" /D "WIN32" /D "_DEBUG" /D "_WINDOWS" /D "_MBCS" /D "_USRDLL" /D "LUALDAP_DLL_EXPORTS" /YX /FD /GZ /c # ADD BASE MTL /nologo /D "_DEBUG" /mktyplib203 /win32 # ADD MTL /nologo /D "_DEBUG" /mktyplib203 /win32 # ADD BASE RSC /l 0x416 /d "_DEBUG" # ADD RSC /l 0x416 /d "_DEBUG" BSC32=bscmake.exe # ADD BASE BSC32 /nologo # ADD BSC32 /nologo LINK32=link.exe # ADD BASE LINK32 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /pdbtype:sept # ADD LINK32 lua50.lib oldap32.lib wsock32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /dll /debug /machine:I386 /out:"../bin/vc6/lualdapd.dll" /pdbtype:sept /libpath:"../../external-src/lua50/lib/dll" /libpath:"../../external-src/openldap-2.1.30/Debug" /libpath:"../../external-src/cyrus-sasl-1.5.28/win32/libsasl/Debug" !ENDIF # Begin Target # Name "lualdap_dll - Win32 Release" # Name "lualdap_dll - Win32 Debug" # Begin Group "Source Files" # PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" # Begin Source File SOURCE="..\..\compat\src\compat-5.1.c" # End Source File # Begin Source File SOURCE=..\src\lualdap.c # End Source File # Begin Source File SOURCE=.\lualdap.def # End Source File # Begin Source File SOURCE=.\lualdap.rc # End Source File # End Group # Begin Group "Header Files" # PROP Default_Filter "h;hpp;hxx;hm;inl" # Begin Source File SOURCE="..\..\compat\src\compat-5.1.h" # End Source File # End Group # Begin Group "Resource Files" # PROP Default_Filter "ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe" # End Group # End Target # End Project lua-ldap-1.1.0-1-geeac494/vc6/resource.h000066400000000000000000000006141174626301100173510ustar00rootroot00000000000000//{{NO_DEPENDENCIES}} // Microsoft Developer Studio generated include file. // Used by lualdap.rc // // Next default values for new objects // #ifdef APSTUDIO_INVOKED #ifndef APSTUDIO_READONLY_SYMBOLS #define _APS_NEXT_RESOURCE_VALUE 101 #define _APS_NEXT_COMMAND_VALUE 40001 #define _APS_NEXT_CONTROL_VALUE 1000 #define _APS_NEXT_SYMED_VALUE 101 #endif #endif