diff --git a/CVSROOT/checkoutlist b/CVSROOT/checkoutlist deleted file mode 100755 index 2921bff..0000000 --- a/CVSROOT/checkoutlist +++ /dev/null @@ -1,13 +0,0 @@ -# The "checkoutlist" file is used to support additional version controlled -# administrative files in $CVSROOT/CVSROOT, such as template files. -# -# The first entry on a line is a filename which will be checked out from -# the corresponding RCS file in the $CVSROOT/CVSROOT directory. -# The remainder of the line is an error message to use if the file cannot -# be checked out. -# -# File format: -# -# [][] -# -# comment lines begin with '#' diff --git a/CVSROOT/commitinfo b/CVSROOT/commitinfo deleted file mode 100755 index d4ade55..0000000 --- a/CVSROOT/commitinfo +++ /dev/null @@ -1,24 +0,0 @@ -# The "commitinfo" file is used to control pre-commit checks. -# The filter on the right is invoked with the repository and a list -# of files to check. A non-zero exit of the filter program will -# cause the commit to be aborted. -# -# The first entry on a line is a regular expression which is tested -# against the directory that the change is being committed to, relative -# to the $CVSROOT. For the first match that is found, then the remainder -# of the line is the name of the filter to run. -# -# Format strings present in the filter will be replaced as follows: -# %p = path relative to repository -# %r = repository (path portion of $CVSROOT) -# %{s} = file name, file name, ... -# -# If no format strings are present in the filter string, a default of -# " %r %s" will be appended to the filter string, but this usage is -# deprecated. -# -# If the repository name does not match any of the regular expressions in this -# file, the "DEFAULT" line is used, if it is specified. -# -# If the name "ALL" appears as a regular expression it is always used -# in addition to the first matching regex or "DEFAULT". diff --git a/CVSROOT/config b/CVSROOT/config deleted file mode 100755 index 6accc36..0000000 --- a/CVSROOT/config +++ /dev/null @@ -1,37 +0,0 @@ -# Set this to "no" if pserver shouldn't check system users/passwords -#SystemAuth=no - -# Put CVS lock files in this directory rather than directly in the repository. -#LockDir=/var/lock/cvs - -# Set `TopLevelAdmin' to `yes' to create a CVS directory at the top -# level of the new working directory when using the `cvs checkout' -# command. -#TopLevelAdmin=no - -# Set `LogHistory' to `all' or `TOEFWUPCGMAR' to log all transactions to the -# history file, or a subset as needed (ie `TMAR' logs all write operations) -#LogHistory=TOEFWUPCGMAR - -# Set `RereadLogAfterVerify' to `always' (the default) to allow the verifymsg -# script to change the log message. Set it to `stat' to force CVS to verify -# that the file has changed before reading it (this can take up to an extra -# second per directory being committed, so it is not recommended for large -# repositories. Set it to `never' (the previous CVS behavior) to prevent -# verifymsg scripts from changing the log message. -#RereadLogAfterVerify=always - -# Set `UserAdminOptions' to the list of `cvs admin' commands (options) -# that users not in the `cvsadmin' group are allowed to run. This -# defaults to `k', or only allowing the changing of the default -# keyword expansion mode for files for users not in the `cvsadmin' group. -# This value is ignored if the `cvsadmin' group does not exist. -# -# The following string would enable all `cvs admin' commands for all -# users: -#UserAdminOptions=aAbceIklLmnNostuU - -# Set `UseNewInfoFmtStrings' to `no' if you must support a legacy system by -# enabling the deprecated old style info file command line format strings. -# Be warned that these strings could be disabled in any new version of CVS. -UseNewInfoFmtStrings=yes diff --git a/CVSROOT/cvswrappers b/CVSROOT/cvswrappers deleted file mode 100755 index e989b75..0000000 --- a/CVSROOT/cvswrappers +++ /dev/null @@ -1,19 +0,0 @@ -# This file affects handling of files based on their names. -# -# The -m option specifies whether CVS attempts to merge files. -# -# The -k option specifies keyword expansion (e.g. -kb for binary). -# -# Format of wrapper file ($CVSROOT/CVSROOT/cvswrappers or .cvswrappers) -# -# wildcard [option value][option value]... -# -# where option is one of -# -f from cvs filter value: path to filter -# -t to cvs filter value: path to filter -# -m update methodology value: MERGE or COPY -# -k expansion mode value: b, o, kkv, &c -# -# and value is a single-quote delimited value. -# For example: -#*.gif -k 'b' diff --git a/CVSROOT/loginfo b/CVSROOT/loginfo deleted file mode 100755 index 4dd6562..0000000 --- a/CVSROOT/loginfo +++ /dev/null @@ -1,31 +0,0 @@ -# The "loginfo" file controls where "cvs commit" log information -# is sent. The first entry on a line is a regular expression which must match -# the directory that the change is being made to, relative to the -# $CVSROOT. If a match is found, then the remainder of the line is a filter -# program that should expect log information on its standard input. -# -# If the repository name does not match any of the regular expressions in this -# file, the "DEFAULT" line is used, if it is specified. -# -# If the name ALL appears as a regular expression it is always used -# in addition to the first matching regex or DEFAULT. -# -# If any format strings are present in the filter, they will be replaced as follows: -# %p = path relative to repository -# %r = repository (path portion of $CVSROOT) -# %{sVv} = attribute list = file name, old version number (pre-checkin), -# new version number (post-checkin). When either old or new revision is -# unknown, doesn't exist, or isn't applicable, the string "NONE" will be -# placed on the command line instead. -# -# Note that %{sVv} is a list operator and not all elements are necessary. Thus %{sv} is -# a legal format string, but will only be replaced with file name and new revision. -# it also generates multiple arguments for each file being operated upon. i.e. if two -# files, file1 & file2, are being commited from 1.1 to version 1.1.2.1 and from 1.1.2.2 -# to 1.1.2.3, respectively, %{sVv} will generate the following six arguments in this -# order: file1, 1.1, 1.1.2.1, file2, 1.1.2.2, 1.1.2.3. -# -# For example: -#DEFAULT (echo ""; id; echo %s; date; cat) >> $CVSROOT/CVSROOT/commitlog -# or -#DEFAULT (echo ""; id; echo %{sVv}; date; cat) >> $CVSROOT/CVSROOT/commitlog diff --git a/CVSROOT/modules b/CVSROOT/modules deleted file mode 100755 index cb9e9ef..0000000 --- a/CVSROOT/modules +++ /dev/null @@ -1,26 +0,0 @@ -# Three different line formats are valid: -# key -a aliases... -# key [options] directory -# key [options] directory files... -# -# Where "options" are composed of: -# -i prog Run "prog" on "cvs commit" from top-level of module. -# -o prog Run "prog" on "cvs checkout" of module. -# -e prog Run "prog" on "cvs export" of module. -# -t prog Run "prog" on "cvs rtag" of module. -# -u prog Run "prog" on "cvs update" of module. -# -d dir Place module in directory "dir" instead of module name. -# -l Top-level directory only -- do not recurse. -# -# NOTE: If you change any of the "Run" options above, you'll have to -# release and re-checkout any working directories of these modules. -# -# And "directory" is a path to a directory relative to $CVSROOT. -# -# The "-a" option specifies an alias. An alias is interpreted as if -# everything on the right of the "-a" had been typed on the command line. -# -# You can encode a module within a module by using the special '&' -# character to interpose another module into the current module. This -# can be useful for creating a module that consists of many directories -# spread out over the entire source repository. diff --git a/CVSROOT/notify b/CVSROOT/notify deleted file mode 100755 index 196c3ea..0000000 --- a/CVSROOT/notify +++ /dev/null @@ -1,17 +0,0 @@ -# The "notify" file controls where notifications from watches set by -# "cvs watch add" or "cvs edit" are sent. The first entry on a line is -# a regular expression which is tested against the directory that the -# change is being made to, relative to the $CVSROOT. If it matches, -# then the remainder of the line is a filter program that should contain -# one occurrence of %s for the user to notify, and information on its -# standard input. -# -# "ALL" or "DEFAULT" can be used in place of the regular expression. -# -# format strings are replaceed as follows: -# %p = path relative to repository -# %r = repository (path portion of $CVSROOT) -# %s = user to notify -# -# For example: -#ALL (echo Committed to %r/%p; cat) |mail %s -s "CVS notification" diff --git a/CVSROOT/rcsinfo b/CVSROOT/rcsinfo deleted file mode 100755 index 49e59f4..0000000 --- a/CVSROOT/rcsinfo +++ /dev/null @@ -1,13 +0,0 @@ -# The "rcsinfo" file is used to control templates with which the editor -# is invoked on commit and import. -# -# The first entry on a line is a regular expression which is tested -# against the directory that the change is being made to, relative to the -# $CVSROOT. For the first match that is found, then the remainder of the -# line is the name of the file that contains the template. -# -# If the repository name does not match any of the regular expressions in this -# file, the "DEFAULT" line is used, if it is specified. -# -# If the name "ALL" appears as a regular expression it is always used -# in addition to the first matching regex or "DEFAULT". diff --git a/CVSROOT/taginfo b/CVSROOT/taginfo deleted file mode 100755 index 025657c..0000000 --- a/CVSROOT/taginfo +++ /dev/null @@ -1,40 +0,0 @@ -# The "taginfo" file is used to control pre-tag checks. -# The filter on the right is invoked with the following arguments if no format strings are present: -# -# $1 -- tagname -# $2 -- operation "add" for tag, "mov" for tag -F, and "del" for tag -d -# $3 -- tagtype "?" on delete, "T" for branch, "N" for static -# $4 -- repository -# $5-> file revision [file revision ...] -# -# If any format strings are present in the filter, they will be replaced as follows: -# %b = branch mode = "?" (delete ops - unknown) | "T" (branch) | "N" (not branch) -# %o = operation = "add" | "mov" | "del" -# %p = path relative to repository -# %r = repository (path portion of $CVSROOT) -# %t = tagname -# %{sVv} = attribute list = file name, old version tag will be deleted from, -# new version tag will be added to (or deleted from, but this feature is -# deprecated. When either old or new revision is unknown, doesn't exist, -# or isn't applicable, the string "NONE" will be placed on the command -# line. -# -# Note that %{sVv} is a list operator and not all elements are necessary. Thus %{sV} is -# a legal format string, but will only be replaced with file name and old revision. -# it also generates multiple arguments for each file being operated upon. i.e. if two -# files, file1 & file2, are having a tag moved from version 1.1 to versoin 1.1.2.9, %{sVv} -# will generate the following six arguments in this order: file1, 1.1, 1.1.2.9, file2, 1.1, -# 1.1.2.9. -# -# A non-zero exit of the filter program will cause the tag to be aborted. -# -# The first entry on a line is a regular expression which is tested -# against the directory that the change is being committed to, relative -# to the $CVSROOT. For the first match that is found, then the remainder -# of the line is the name of the filter to run. -# -# If the repository name does not match any of the regular expressions in this -# file, the "DEFAULT" line is used, if it is specified. -# -# If the name "ALL" appears as a regular expression it is always used -# in addition to the first matching regex or "DEFAULT". diff --git a/CVSROOT/verifymsg b/CVSROOT/verifymsg deleted file mode 100755 index 165d1cd..0000000 --- a/CVSROOT/verifymsg +++ /dev/null @@ -1,29 +0,0 @@ -# The "verifymsg" file is used to allow verification of logging -# information. It works best when a template (as specified in the -# rcsinfo file) is provided for the logging procedure. Given a -# template with locations for, a bug-id number, a list of people who -# reviewed the code before it can be checked in, and an external -# process to catalog the differences that were code reviewed, the -# following test can be applied to the code: -# -# Making sure that the entered bug-id number is correct. -# Validating that the code that was reviewed is indeed the code being -# checked in (using the bug-id number or a seperate review -# number to identify this particular code set.). -# -# If any of the above test failed, then the commit would be aborted. -# -# Format strings present in the filter will be replaced as follows: -# %p = path relative to repository -# %r = repository (path portion of $CVSROOT) -# %l = name of log file to be verified. -# -# If no format strings are present in the filter, a default " %l" will -# be appended to the filter, but this usage is deprecated. -# -# Actions such as mailing a copy of the report to each reviewer are -# better handled by an entry in the loginfo file. -# -# One thing that should be noted is the the ALL keyword is not -# supported. There can be only one entry that matches a given -# repository. diff --git a/lualdap/Makefile b/Makefile similarity index 80% rename from lualdap/Makefile rename to Makefile index 6a4f06d..a5617fe 100755 --- a/lualdap/Makefile +++ b/Makefile @@ -20,9 +20,9 @@ $(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 + mkdir -p $(DESTDIR)$(LUA_LIBDIR) + cp src/$(LIBNAME) $(DESTDIR)$(LUA_LIBDIR) + cd $(DESTDIR)$(LUA_LIBDIR); ln -f -s $(LIBNAME) $T.so clean: rm -f $(OBJS) src/$(LIBNAME) diff --git a/lualdap/Makefile.win b/Makefile.win similarity index 100% rename from lualdap/Makefile.win rename to Makefile.win diff --git a/lualdap/README b/README similarity index 100% rename from lualdap/README rename to README diff --git a/lualdap/config b/config similarity index 97% rename from lualdap/config rename to config index 84543b3..9d43a64 100755 --- a/lualdap/config +++ b/config @@ -13,7 +13,7 @@ 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 +LUA_VERSION_NUM= 501 LIBNAME= $T.so.$V COMPAT_DIR= ../compat/src diff --git a/lualdap/config.win b/config.win similarity index 100% rename from lualdap/config.win rename to config.win diff --git a/lualdap/doc/us/index.html b/doc/us/index.html similarity index 100% rename from lualdap/doc/us/index.html rename to doc/us/index.html diff --git a/lualdap/doc/us/license.html b/doc/us/license.html similarity index 100% rename from lualdap/doc/us/license.html rename to doc/us/license.html diff --git a/lualdap/doc/us/lualdap.png b/doc/us/lualdap.png similarity index 100% rename from lualdap/doc/us/lualdap.png rename to doc/us/lualdap.png diff --git a/lualdap/doc/us/manual.html b/doc/us/manual.html similarity index 100% rename from lualdap/doc/us/manual.html rename to doc/us/manual.html diff --git a/lualdap/src/lualdap.c b/src/lualdap.c similarity index 89% rename from lualdap/src/lualdap.c rename to src/lualdap.c index b3a56be..d0c03e7 100755 --- a/lualdap/src/lualdap.c +++ b/src/lualdap.c @@ -19,10 +19,14 @@ #include "ldap.h" #endif -#include "lua.h" -#include "lauxlib.h" -#if ! defined (LUA_VERSION_NUM) || LUA_VERSION_NUM < 501 -#include "compat-5.1.h" +#include +#include + +#if LUA_VERSION_NUM < 502 +/* lua_rawlen: Not entirely correct, but should work anyway */ +# define lua_rawlen lua_objlen +# define luaL_newlib(L,l) (lua_newtable(L), luaL_register(L,NULL,l)) +# define luaL_setfuncs(L,l,n) (assert(n==0), luaL_register(L,NULL,l)) #endif #ifdef WINLDAPAPI @@ -141,9 +145,9 @@ static int option_error (lua_State *L, const char *name, const char *type) { /* ** Get the field called name of the table at position 2. */ -static void strgettable (lua_State *L, const char *name) { +static void strgettable (lua_State *L, int idx, const char *name) { lua_pushstring (L, name); - lua_gettable (L, 2); + lua_gettable (L, idx); } @@ -151,8 +155,8 @@ static void strgettable (lua_State *L, const char *name) { ** 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); +static const char *strtabparam (lua_State *L, int idx, const char *name, char *def) { + strgettable (L, idx, name); if (lua_isnil (L, -1)) return def; else if (lua_isstring (L, -1)) @@ -168,8 +172,8 @@ static const char *strtabparam (lua_State *L, const char *name, char *def) { ** 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); +static long longtabparam (lua_State *L, int idx, const char *name, int def) { + strgettable (L, idx, name); if (lua_isnil (L, -1)) return def; else if (lua_isnumber (L, -1)) @@ -183,8 +187,8 @@ static long longtabparam (lua_State *L, const char *name, int def) { ** 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); +static double numbertabparam (lua_State *L, int idx, const char *name, double def) { + strgettable (L, idx, name); if (lua_isnil (L, -1)) return def; else if (lua_isnumber (L, -1)) @@ -199,7 +203,7 @@ static double numbertabparam (lua_State *L, const char *name, double def) { ** The table MUST be at position 2. */ static int booltabparam (lua_State *L, const char *name, int def) { - strgettable (L, name); + strgettable (L, 2, name); if (lua_isnil (L, -1)) return def; else if (lua_isboolean (L, -1)) @@ -243,7 +247,7 @@ static BerValue *A_setbval (lua_State *L, attrs_data *a, const char *n) { value_error (L, n); return NULL; } - a->bvals[a->bi].bv_len = lua_strlen (L, -1); + a->bvals[a->bi].bv_len = lua_rawlen (L, -1); a->bvals[a->bi].bv_val = (char *)lua_tostring (L, -1); a->bi++; return ret; @@ -296,7 +300,7 @@ static BerValue **A_tab2val (lua_State *L, attrs_data *a, const char *name) { A_setval (L, a, name); else if (lua_istable (L, tab)) { /* list of strings */ int i; - int n = luaL_getn (L, tab); + int n = lua_rawlen (L, tab); for (i = 1; i <= n; i++) { lua_rawgeti (L, tab, i); /* push table element */ A_setval (L, a, name); @@ -368,7 +372,7 @@ static int table2strarray (lua_State *L, int tab, char *array[], int limit) { array[1] = NULL; } else if (lua_istable (L, tab)) { int i; - int n = luaL_getn (L, tab); + int n = lua_rawlen (L, tab); if (limit < (n+1)) return luaL_error (L, LUALDAP_PREFIX"too many arguments"); for (i = 0; i < n; i++) { @@ -386,6 +390,18 @@ static int table2strarray (lua_State *L, int tab, char *array[], int limit) { } +/* +** Fill in the struct timeval, according to the timeout parameter. +*/ +static struct timeval *get_timeout_param (lua_State *L, int idx, struct timeval *st) { + double t = numbertabparam (L, idx, "timeout", -1); + if(t < 0) + return NULL; /* No timeout, block */ + st->tv_sec = (long)t; + st->tv_usec = (long)(1000000 * (t - st->tv_sec)); + return st; +} + /* ** Get the result message of an operation. ** #1 upvalue == connection @@ -393,7 +409,7 @@ static int table2strarray (lua_State *L, int tab, char *array[], int limit) { ** #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 ??? */ + struct timeval timeout; LDAPMessage *res; int rc; conn_data *conn = (conn_data *)lua_touserdata (L, lua_upvalueindex (1)); @@ -401,7 +417,7 @@ static int result_message (lua_State *L) { /*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); + rc = ldap_result (conn->ld, msgid, LDAP_MSG_ONE, get_timeout_param (L, 1, &timeout), &res); if (rc == 0) return faildirect (L, LUALDAP_PREFIX"result timeout expired"); else if (rc < 0) { @@ -424,10 +440,14 @@ static int result_message (lua_State *L) { 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); + lua_concat (L, 2); + if (msg != NULL) { + lua_pushliteral (L, " ("); + lua_pushstring (L, msg); + lua_pushliteral (L, ")"); + lua_concat (L, 4); + } ret = 2; } ldap_memfree (mdn); @@ -461,7 +481,11 @@ static int lualdap_close (lua_State *L) { luaL_argcheck(L, conn!=NULL, 1, LUALDAP_PREFIX"LDAP connection expected"); if (conn->ld == NULL) /* already closed */ return 0; +#if defined(LDAP_API_FEATURE_X_OPENLDAP) && LDAP_API_FEATURE_X_OPENLDAP >= 20300 + ldap_unbind_ext (conn->ld, NULL, NULL); +#else ldap_unbind (conn->ld); +#endif conn->ld = NULL; lua_pushnumber (L, 1); return 1; @@ -504,7 +528,7 @@ static int lualdap_compare (lua_State *L) { BerValue bvalue; ldap_int_t rc, msgid; bvalue.bv_val = (char *)luaL_checkstring (L, 4); - bvalue.bv_len = lua_strlen (L, 4); + bvalue.bv_len = lua_rawlen (L, 4); rc = ldap_compare_ext (conn->ld, dn, attr, &bvalue, NULL, NULL, &msgid); return create_future (L, rc, 1, msgid, LDAP_RES_COMPARE); } @@ -666,15 +690,17 @@ static void search_close (lua_State *L, search_data *search) { static int next_message (lua_State *L) { search_data *search = getsearch (L); conn_data *conn; - struct timeval *timeout = NULL; /* ??? function parameter ??? */ + struct timeval timeout; LDAPMessage *res; int rc; int ret; + luaL_checktype(L, 1, LUA_TTABLE); + 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); + rc = ldap_result (conn->ld, search->msgid, LDAP_MSG_ONE, get_timeout_param (L, 1, &timeout), &res); if (rc == 0) return faildirect (L, LUALDAP_PREFIX"result timeout expired"); else if (rc == -1) @@ -783,20 +809,6 @@ static int get_attrs_param (lua_State *L, char *attrs[]) { } -/* -** 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. @@ -818,11 +830,11 @@ static int lualdap_search (lua_State *L) { 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); + base = (ldap_pchar_t) strtabparam (L, 2, "base", NULL); + filter = (ldap_pchar_t) strtabparam (L, 2, "filter", NULL); + scope = string2scope (L, strtabparam (L, 2, "scope", NULL)); + sizelimit = longtabparam (L, 2, "sizelimit", LDAP_NO_LIMIT); + timeout = get_timeout_param (L, 2, &st); rc = ldap_search_ext (conn->ld, base, scope, filter, attrs, attrsonly, NULL, NULL, timeout, sizelimit, &msgid); @@ -831,7 +843,8 @@ static int lualdap_search (lua_State *L) { create_search (L, 1, msgid); lua_pushcclosure (L, next_message, 1); - return 1; + lua_pushvalue(L, 2); + return 2; } @@ -872,7 +885,7 @@ static int lualdap_search_tostring (lua_State *L) { ** Create a metatable. */ static int lualdap_createmeta (lua_State *L) { - const luaL_reg methods[] = { + const luaL_Reg methods[] = { {"close", lualdap_close}, {"add", lualdap_add}, {"compare", lualdap_compare}, @@ -887,7 +900,7 @@ static int lualdap_createmeta (lua_State *L) { return 0; /* define methods */ - luaL_openlib (L, NULL, methods, 0); + luaL_setfuncs(L, methods, 0); /* define metamethods */ lua_pushliteral (L, "__gc"); @@ -939,13 +952,27 @@ static int lualdap_open_simple (lua_State *L) { 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)); +#if defined(LDAP_API_FEATURE_X_OPENLDAP) && LDAP_API_FEATURE_X_OPENLDAP >= 20300 + struct berval cred = { 0, NULL }; + char *host_with_schema = NULL; +#endif int err; /* Initialize */ lualdap_setmeta (L, LUALDAP_CONNECTION_METATABLE); conn->version = 0; +#if defined(LDAP_API_FEATURE_X_OPENLDAP) && LDAP_API_FEATURE_X_OPENLDAP >= 20300 + host_with_schema = malloc(strlen(host) + 8); + strcpy(host_with_schema, "ldap://"); + strcat(host_with_schema, host); + err = ldap_initialize(&conn->ld, host_with_schema); + free(host_with_schema); + host_with_schema = NULL; + if (err != LDAP_SUCCESS) +#else conn->ld = ldap_init (host, LDAP_PORT); if (conn->ld == NULL) +#endif return faildirect(L,LUALDAP_PREFIX"Error connecting to server"); /* Set protocol version */ conn->version = LDAP_VERSION3; @@ -959,7 +986,16 @@ static int lualdap_open_simple (lua_State *L) { return faildirect (L, ldap_err2string (rc)); } /* Bind to a server */ +#if defined(LDAP_API_FEATURE_X_OPENLDAP) && LDAP_API_FEATURE_X_OPENLDAP >= 20300 + cred.bv_len = strlen(password); + cred.bv_val = malloc(cred.bv_len+1); + strcpy(cred.bv_val, password); + err = ldap_sasl_bind_s (conn->ld, who, LDAP_SASL_SIMPLE, &cred, NULL, NULL, NULL); + free(cred.bv_val); + memset(&cred, 0, sizeof(cred)); +#else err = ldap_bind_s (conn->ld, who, password, LDAP_AUTH_SIMPLE); +#endif if (err != LDAP_SUCCESS) return faildirect (L, ldap_err2string (err)); @@ -987,13 +1023,15 @@ static void set_info (lua_State *L) { ** Create ldap table and register the open method. */ int luaopen_lualdap (lua_State *L) { - struct luaL_reg lualdap[] = { + struct luaL_Reg lualdap[] = { {"open_simple", lualdap_open_simple}, {NULL, NULL}, }; lualdap_createmeta (L); - luaL_openlib (L, LUALDAP_TABLENAME, lualdap, 0); + luaL_newlib(L, lualdap); + lua_pushvalue(L, -1); + lua_setglobal(L, LUALDAP_TABLENAME); set_info (L); return 1; diff --git a/lualdap/src/lualdap.def b/src/lualdap.def similarity index 100% rename from lualdap/src/lualdap.def rename to src/lualdap.def diff --git a/lualdap/src/open2winldap.h b/src/open2winldap.h similarity index 100% rename from lualdap/src/open2winldap.h rename to src/open2winldap.h diff --git a/lualdap/tests/test.lua b/tests/test.lua similarity index 100% rename from lualdap/tests/test.lua rename to tests/test.lua diff --git a/lualdap/vc6/lualdap.def b/vc6/lualdap.def similarity index 100% rename from lualdap/vc6/lualdap.def rename to vc6/lualdap.def diff --git a/lualdap/vc6/lualdap.dsw b/vc6/lualdap.dsw similarity index 100% rename from lualdap/vc6/lualdap.dsw rename to vc6/lualdap.dsw diff --git a/lualdap/vc6/lualdap.rc b/vc6/lualdap.rc similarity index 100% rename from lualdap/vc6/lualdap.rc rename to vc6/lualdap.rc diff --git a/lualdap/vc6/lualdap_dll.dsp b/vc6/lualdap_dll.dsp similarity index 100% rename from lualdap/vc6/lualdap_dll.dsp rename to vc6/lualdap_dll.dsp diff --git a/lualdap/vc6/resource.h b/vc6/resource.h similarity index 100% rename from lualdap/vc6/resource.h rename to vc6/resource.h