From 951dabbabb4ed074c37141b1fdb0f3231746ef87 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Sun, 9 Oct 2011 17:02:52 +0100 Subject: [PATCH 01/10] Drop CVSROOT from repository --- CVSROOT/checkoutlist | 13 --------- CVSROOT/commitinfo | 24 ---------------- CVSROOT/config | 37 ------------------------- CVSROOT/cvswrappers | 19 ------------- CVSROOT/loginfo | 31 --------------------- CVSROOT/modules | 26 ----------------- CVSROOT/notify | 17 ------------ CVSROOT/rcsinfo | 13 --------- CVSROOT/taginfo | 40 --------------------------- CVSROOT/verifymsg | 29 ------------------- lualdap/Makefile => Makefile | 0 lualdap/Makefile.win => Makefile.win | 0 lualdap/README => README | 0 lualdap/config => config | 0 lualdap/config.win => config.win | 0 {lualdap/doc => doc}/us/index.html | 0 {lualdap/doc => doc}/us/license.html | 0 {lualdap/doc => doc}/us/lualdap.png | Bin {lualdap/doc => doc}/us/manual.html | 0 {lualdap/src => src}/lualdap.c | 0 {lualdap/src => src}/lualdap.def | 0 {lualdap/src => src}/open2winldap.h | 0 {lualdap/tests => tests}/test.lua | 0 {lualdap/vc6 => vc6}/lualdap.def | 0 {lualdap/vc6 => vc6}/lualdap.dsw | 0 {lualdap/vc6 => vc6}/lualdap.rc | 0 {lualdap/vc6 => vc6}/lualdap_dll.dsp | 0 {lualdap/vc6 => vc6}/resource.h | 0 28 files changed, 249 deletions(-) delete mode 100755 CVSROOT/checkoutlist delete mode 100755 CVSROOT/commitinfo delete mode 100755 CVSROOT/config delete mode 100755 CVSROOT/cvswrappers delete mode 100755 CVSROOT/loginfo delete mode 100755 CVSROOT/modules delete mode 100755 CVSROOT/notify delete mode 100755 CVSROOT/rcsinfo delete mode 100755 CVSROOT/taginfo delete mode 100755 CVSROOT/verifymsg rename lualdap/Makefile => Makefile (100%) rename lualdap/Makefile.win => Makefile.win (100%) rename lualdap/README => README (100%) rename lualdap/config => config (100%) rename lualdap/config.win => config.win (100%) rename {lualdap/doc => doc}/us/index.html (100%) rename {lualdap/doc => doc}/us/license.html (100%) rename {lualdap/doc => doc}/us/lualdap.png (100%) rename {lualdap/doc => doc}/us/manual.html (100%) rename {lualdap/src => src}/lualdap.c (100%) rename {lualdap/src => src}/lualdap.def (100%) rename {lualdap/src => src}/open2winldap.h (100%) rename {lualdap/tests => tests}/test.lua (100%) rename {lualdap/vc6 => vc6}/lualdap.def (100%) rename {lualdap/vc6 => vc6}/lualdap.dsw (100%) rename {lualdap/vc6 => vc6}/lualdap.rc (100%) rename {lualdap/vc6 => vc6}/lualdap_dll.dsp (100%) rename {lualdap/vc6 => vc6}/resource.h (100%) 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 100% rename from lualdap/Makefile rename to Makefile 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 100% rename from lualdap/config rename to config 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 100% rename from lualdap/src/lualdap.c rename to src/lualdap.c 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 From 4e94b143c05ca31633b4bbed40acc81f314385f8 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Tue, 13 Mar 2012 01:54:54 +0000 Subject: [PATCH 02/10] Make some helper functions more useful by allowing them to receive the stack offset as a parameter --- src/lualdap.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/lualdap.c b/src/lualdap.c index b3a56be..f531c7e 100755 --- a/src/lualdap.c +++ b/src/lualdap.c @@ -141,9 +141,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 +151,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 +168,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 +183,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 +199,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)) @@ -786,8 +786,8 @@ 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); +static struct timeval *get_timeout_param (lua_State *L, int idx, struct timeval *st) { + double t = numbertabparam (L, idx, "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) @@ -818,11 +818,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); From 3a50722a40c02b04e721d4c8954fb4ae8dee5fd4 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Tue, 13 Mar 2012 02:07:39 +0000 Subject: [PATCH 03/10] Allow result_message() and next_message() to take a timeout parameter (nil or negative timeout blocks indefinitely). Compiles but completely untested. --- src/lualdap.c | 34 ++++++++++++++++------------------ 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/src/lualdap.c b/src/lualdap.c index f531c7e..512a8ec 100755 --- a/src/lualdap.c +++ b/src/lualdap.c @@ -386,6 +386,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 +405,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 +413,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) { @@ -666,7 +678,7 @@ 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; @@ -674,7 +686,7 @@ static int next_message (lua_State *L) { 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 +795,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, int idx, struct timeval *st) { - double t = numbertabparam (L, idx, "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. From ef9777df0e2e5ec888aaeaa5cb61d998d1563e4f Mon Sep 17 00:00:00 2001 From: Dennis Schridde Date: Thu, 31 May 2012 17:23:08 +0200 Subject: [PATCH 04/10] Install to DESTDIR --- Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 6a4f06d..a5617fe 100755 --- a/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) From 4cd967acd9c7ebbb26e48a442d4089c3d2b98a55 Mon Sep 17 00:00:00 2001 From: Dennis Schridde Date: Thu, 31 May 2012 17:23:57 +0200 Subject: [PATCH 05/10] Fix compatibility with Lua 5.1 luaL_openlib was removed in favour of luaL_register --- src/lualdap.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/lualdap.c b/src/lualdap.c index 512a8ec..779ff70 100755 --- a/src/lualdap.c +++ b/src/lualdap.c @@ -885,7 +885,11 @@ static int lualdap_createmeta (lua_State *L) { return 0; /* define methods */ +#if LUA_VERSION_NUM >= 501 + luaL_register (L, NULL, methods); +#else luaL_openlib (L, NULL, methods, 0); +#endif /* define metamethods */ lua_pushliteral (L, "__gc"); @@ -991,7 +995,11 @@ int luaopen_lualdap (lua_State *L) { }; lualdap_createmeta (L); +#if LUA_VERSION_NUM >= 501 + luaL_register (L, LUALDAP_TABLENAME, lualdap); +#else luaL_openlib (L, LUALDAP_TABLENAME, lualdap, 0); +#endif set_info (L); return 1; From 141c0326283325963f689b48df5e6cd7d399da30 Mon Sep 17 00:00:00 2001 From: Dennis Schridde Date: Thu, 31 May 2012 17:28:07 +0200 Subject: [PATCH 06/10] Fix compatibility with OpenLDAP 2.3 Several functions were deprecated --- src/lualdap.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/lualdap.c b/src/lualdap.c index 779ff70..99c756e 100755 --- a/src/lualdap.c +++ b/src/lualdap.c @@ -473,7 +473,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; @@ -941,13 +945,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; @@ -961,7 +979,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)); From 0d2e40bb182d8e417a5dac9000e5a5bb17422adf Mon Sep 17 00:00:00 2001 From: Dennis Schridde Date: Thu, 31 May 2012 17:30:49 +0200 Subject: [PATCH 07/10] Fix potential Lua error (attempt to concatenate a nil value) when ldap_parse_result returns a NULL error message --- src/lualdap.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/lualdap.c b/src/lualdap.c index 99c756e..d170038 100755 --- a/src/lualdap.c +++ b/src/lualdap.c @@ -436,10 +436,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); From a4be4efbe7b3c065bd83a99b31044b381680ab2e Mon Sep 17 00:00:00 2001 From: Dennis Schridde Date: Tue, 2 Oct 2012 21:42:52 +0200 Subject: [PATCH 08/10] Fix bug introduced in 9d744fb7f7d6 (was passing struct instead of pointer to memset) --- src/lualdap.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lualdap.c b/src/lualdap.c index d170038..c19c779 100755 --- a/src/lualdap.c +++ b/src/lualdap.c @@ -989,7 +989,7 @@ static int lualdap_open_simple (lua_State *L) { 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)); + memset(&cred, 0, sizeof(cred)); #else err = ldap_bind_s (conn->ld, who, password, LDAP_AUTH_SIMPLE); #endif From b785fbd7ad0b17d33bb26b9d6c1cee207117eae4 Mon Sep 17 00:00:00 2001 From: Dennis Schridde Date: Tue, 2 Oct 2012 21:45:00 +0200 Subject: [PATCH 09/10] Use Lua 5.2 and add compatibility fallbacks for Lua 5.1 Lua 5.0 is no longer supported! --- config | 2 +- src/lualdap.c | 38 ++++++++++++++++++-------------------- 2 files changed, 19 insertions(+), 21 deletions(-) diff --git a/config b/config index 84543b3..9d43a64 100755 --- a/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/src/lualdap.c b/src/lualdap.c index c19c779..6db5d52 100755 --- a/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 @@ -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++) { @@ -524,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); } @@ -878,7 +882,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}, @@ -893,11 +897,7 @@ static int lualdap_createmeta (lua_State *L) { return 0; /* define methods */ -#if LUA_VERSION_NUM >= 501 - luaL_register (L, NULL, methods); -#else - luaL_openlib (L, NULL, methods, 0); -#endif + luaL_setfuncs(L, methods, 0); /* define metamethods */ lua_pushliteral (L, "__gc"); @@ -1020,17 +1020,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); -#if LUA_VERSION_NUM >= 501 - luaL_register (L, LUALDAP_TABLENAME, lualdap); -#else - luaL_openlib (L, LUALDAP_TABLENAME, lualdap, 0); -#endif + luaL_newlib(L, lualdap); + lua_pushvalue(L, -1); + lua_setglobal(L, LUALDAP_TABLENAME); set_info (L); return 1; From 2867f1f76321fe3832d19ee309b80be0bccaba1d Mon Sep 17 00:00:00 2001 From: Dennis Schridde Date: Tue, 2 Oct 2012 23:20:37 +0200 Subject: [PATCH 10/10] Stricter argument checking in next_message and return proper values from lualdap_search lualdap_search did not return a state, hence none was passed to next_message. Apparently earlier versions of Lua implicitly used the argument to the generator (lualdap_search) as state argument for the iterator. --- src/lualdap.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/lualdap.c b/src/lualdap.c index 6db5d52..d0c03e7 100755 --- a/src/lualdap.c +++ b/src/lualdap.c @@ -695,6 +695,8 @@ static int next_message (lua_State *L) { 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 */ @@ -841,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; }