pax_global_header00006660000000000000000000000064134143554510014517gustar00rootroot0000000000000052 comment=598acdf093619fb3ca0af738c5d3ecdf8ab919be lualdap-1.2.5/000077500000000000000000000000001341435545100131465ustar00rootroot00000000000000lualdap-1.2.5/.circleci/000077500000000000000000000000001341435545100150015ustar00rootroot00000000000000lualdap-1.2.5/.circleci/config.yml000066400000000000000000000035021341435545100167710ustar00rootroot00000000000000version: 2.1 orbs: codecov: codecov/codecov@1.0.1 jobs: build_and_test: description: "Build and test for a specific Lua version" parameters: version: type: string working_directory: /lualdap docker: - image: quay.io/devurandom/lua-dev:debian9.6-1@sha256:9a69efdc28b97354fe9ea3c174473ddf906f8307d3c8b9fd4cf3ddc8fc218528 - image: docker.io/openshift/openldap-2441-centos7@sha256:b5619d4de8efec7973dbd280eb2cc462ebeb8ae6e457acef4b743b7374dd600d steps: - checkout - run: name: Install build / test dependencies command: | apt -y update apt -y install libldap2-dev ldap-utils netcat - run: name: "Wait for OpenLDAP to spin up" command: while ! nc -z localhost 389 ; do sleep 1 ; done - run: name: Prime and test LDAP DB command: ./tests/setup.sh - run: name: "Build" environment: - LUAENV_VERSION: <> command: eval "$(luaenv init -)" && luarocks make COVERAGE=1 JUNITXML=1 - run: name: "Test" environment: - LUAENV_VERSION: <> command: eval "$(luaenv init -)" && make BUILD_VARIANT=$LUAENV_VERSION COVERAGE=1 JUNITXML=1 check - codecov/upload: file: "*.gcov" flags: default upload_name: <> - store_test_results: path: test-reports/ workflows: version: 2 build_and_test: jobs: - build_and_test: name: lua-5.1.5 version: 5.1.5 - build_and_test: name: lua-5.2.4 version: 5.2.4 - build_and_test: name: lua-5.3.5 version: 5.3.5 - build_and_test: name: luajit-2.0.5 version: luajit-2.0.5 - build_and_test: name: luajit-2.1.0-beta3 version: luajit-2.1.0-beta3 lualdap-1.2.5/.codecov.yml000066400000000000000000000000401341435545100153630ustar00rootroot00000000000000ignore: - "src/compat-5.3.[ch]" lualdap-1.2.5/.gitignore000066400000000000000000000001261341435545100151350ustar00rootroot00000000000000*~ *.bak *.gcda *.gcno *.gcov *.json *.o *.out *.so *.so.* *.rock *.xml test-reports/ lualdap-1.2.5/.luacov000066400000000000000000000001641341435545100144410ustar00rootroot00000000000000return { root = ".", include = { -- Prevent coverage reports of the tests or helper utilities "src/.+", }, } lualdap-1.2.5/CONTRIBUTING.md000066400000000000000000000036701341435545100154050ustar00rootroot00000000000000# Releases ## Version numbers In the following `${VERSION}` represents the version to be released. If it is a release candidate, it ends in `-rc1`, `-rc2`, and so on. Example: `VERSION=1.2.4-rc1` Since LuaRocks does not support dashes in the version string, except for the build number, we replace eventual dashes (`-`) in `${VERSION}` with dots (`.`). With LuaRocks, the version number is followed by a dash and the build number, which is usually one (`1`), except for release candidates, where we use zero (`0`). We use `${LUAROCKS_VERSION}` to represent this version string below. Example: `LUAROCKS_VERSION=1.2.4.rc1-0` Since Windows libraries use a four number versioning scheme without the possibility for non-digit characters, we use the fourth and last number to distinguish between releases (`0` in the last position) and release candidates (previous version number in the first three positions, but `99`, `999` and so on in the last position). This number is represented by `${WINDOWS_VERSION}` in the following. Example: `WINDOWS_VERSION=1.2.3.99` Note that for Git tags we prefix `${VERSION}` with `v`. This is explicit in the instructions below. ## Release checklist -[] Copy `rockspecs/rockspec` to `rockspecs/lualdap/lualdap-${LUAROCKS_VERSION}.rockspec` -[] In `Makefile` and `Makefile.win` adjust `V` to `${VERSION}` -[] In `src/lualdap.def` adjust `VERSION` to `${WINDOWS_VERSION}` -[] In `README.md` adjust "Current version" to `${VERSION}` under "installation" -[] In `NEWS.md`: -[] Rename "Unreleased" to `${VERSION}` -[] Adjust the link for `Unreleased` to show the changelog (commit log) between the previous version and `v${VERSION}` and rename it to `${VERSION}` -[] Add a new, empty "Unreleased" section -[] Add a new link for `Unreleased` to show the changelog between `v${VERSION}` and `HEAD` -[] Commit these changes with message "Release v${VERSION}" -[] Tag this commit with `v${VERSION}` lualdap-1.2.5/CONTRIBUTORS.md000066400000000000000000000030221341435545100154220ustar00rootroot00000000000000LuaLDAP was originally created by [Kepler Project](http://www.keplerproject.org/). A CVS-to-Git conversion was done by [LuaForge](http://luaforge.net/) from [their project](http://luaforge.net/projects/lualdap/) to [a GitHub repository](https://github.com/luaforge/lualdap). From there various members of the community took over and curated fixes and improvements in a new [repository under the LuaLDAP GitHub organisation](https://github.com/lualdap/lualdap). Significant contributions were made by (in order of appearance): * [Matthew Wild](https://github.com/mwild1) : Bugfixes; curation of community patches * [Dennis Schridde](https://github.com/devurandom) : Lua 5.1, 5.2, 5.3 compatibility; OpenLDAP 2.3 compatibility; initial CircleCI and Codecov setup; bugfixes; curation of community patches * [Vadim A. Misbakh-Soloviov](https://github.com/msva) : Bugfix * Michael Bienia , Micah Gersten , Luca Capello : [Bugfix for Debian](https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=722175) * [John Regan](https://github.com/jprjr) : Initial Rockspec * [Dan Callaghan](https://github.com/danc86) : Initial test harness using a live OpenLDAP server; bugfixes * [Brett Delle Grazie](https://github.com/bdellegrazie) : Documentation updates; curation of community patches * [Jakub Jirutka](https://github.com/jirutka) : Initial Travis CI setup; bugfixes lualdap-1.2.5/LICENSE.md000066400000000000000000000003331341435545100145510ustar00rootroot00000000000000The original authors and subsequent contributors released this software under the same license as [LUA](http://www.lua.org/license.html) which is simply the [MIT License](http://opensource.org/licenses/mit-license.html)lualdap-1.2.5/Makefile000066400000000000000000000037371341435545100146200ustar00rootroot00000000000000N= LuaLDAP T= lualdap V= 1.2.5 PACKAGE_STRING=$(N) $(V) CONFIG= ./config include $(CONFIG) ifneq ($(filter check,$(MAKECMDGOALS)),) include tests/test.env LDAP_VARS=LDAP_URI LDAP_BASE_DN LDAP_BIND_DN LDAP_BIND_PASSWORD LDAP_TEST_DN LDAP_TEST_PASSWORD $(foreach var,$(LDAP_VARS),$(if $(value $(var)),$(info $(var): $(value $(var))),$(error $(var) required when running tests))) LDAP_HOST= $(shell echo "$(LDAP_URI)" | sed -r 's,^.*://([^:/]+).*$$,\1,') endif CFLAGS_WARN := -pedantic -Wall -W -Waggregate-return -Wcast-align -Wmissing-prototypes -Wnested-externs -Wshadow -Wwrite-strings override CPPFLAGS := -DPACKAGE_STRING="\"$(PACKAGE_STRING)\"" -DLUA_C89_NUMBERS $(CPPFLAGS) override CFLAGS := -O2 -fPIC -std=c89 $(CFLAGS_WARN) $(CFLAGS) ifdef BUILD_VARIANT REPORT_DIR := test-reports/$(BUILD_VARIANT) else REPORT_DIR := test-reports endif ifdef COVERAGE override CFLAGS := $(CFLAGS) -O0 -g --coverage override BUSTEDFLAGS := $(BUSTEDFLAGS) --coverage endif ifdef JUNITXML override BUSTEDFLAGS := $(BUSTEDFLAGS) --output=junit -Xoutput $(REPORT_DIR)/report.xml endif OBJS= src/lualdap.o INCS := -I$(LUA_INCDIR) -I$(LDAP_INCDIR) -I$(LBER_INCDIR) LIBS := -L$(LDAP_LIBDIR) $(LDAP_LIB) -L$(LBER_LIBDIR) $(LBER_LIB) override CPPFLAGS := $(INCS) $(CPPFLAGS) override LDFLAGS := $(LIBFLAG) $(LDFLAGS) LIBNAME=$(T).so src/$(LIBNAME): $(OBJS) $(CC) $(CFLAGS) -o src/$(LIBNAME) $(LDFLAGS) $(OBJS) $(LIBS) install: src/$(LIBNAME) $(INSTALL) src/$(LIBNAME) $(DESTDIR)$(INST_LIBDIR) clean: $(RM) -r $(OBJS) src/$(LIBNAME) src/*.gcda src/*.gcno src/*.gcov luacov.*.out $(REPORT_DIR) check: $(REPORT_DIR) env $(foreach var,$(LDAP_VARS) LDAP_HOST,$(var)=$($(var))) busted $(BUSTEDFLAGS) tests/test.lua ifdef COVERAGE luacov mv luacov.*.out $(REPORT_DIR) endif $(REPORT_DIR): mkdir -p $@ package_string: # useful on custom builds, like in Debian that doesn't use directly make to # build the project. So it can be used like # -DPACKAGE_STRING="\"$(shell make package_string)\"" @echo "$(PACKAGE_STRING)" lualdap-1.2.5/Makefile.win000066400000000000000000000007651341435545100154120ustar00rootroot00000000000000N= LuaLDAP T= lualdap V= 1.2.5 include config.win SRCS= src\$T.c OBJS= src\$T.obj CPPFLAGS:=$(CPPFLAGS) /DPACKAGE_STRING="\"$N $V\"" lib: src\$(LIBNAME) .c.obj: $(CC) /c /Fo$@ $(CPPFLAGS) $(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 lualdap-1.2.5/NEWS.md000066400000000000000000000036071341435545100142520ustar00rootroot00000000000000# Changelog All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). ## [Unreleased] ## [1.2.5] - 2019-01-06 ### Changed * `CPPFLAGS`, `CFLAGS` and `LDFLAGS` can now be overridden on the `make` command line. It is not longer necessary to edit the `config` file. ### Removed * We no longer export a `lualdap` global variable, in accordance with Lua 5.2 module rules (#8) - cf. https://www.lua.org/manual/5.2/manual.html#8.2 * Remove support for Lua 5.0 by including an external file outside the source directory - Support for Lua 5.1 and 5.2 continues through our inclusion of lua-compat-5.3 (see release notes for v1.2.4-rc1) ## [1.2.4] - 2019-01-02 ### Added * Build system additions to accomodate Debian ## [1.2.4-rc1] - 2018-12-22 ### Added * Lua 5.3 compatibility - Backwards compatibility using Kepler Project's [lua-compat-5.3](https://github.com/keplerproject/lua-compat-5.3/) * Support specifying a URI in hostname argument to `open_simple()` ### Changed * Switch to [busted](http://olivinelabs.com/busted/) unit testing framework * Automate building and running unit tests using [CircleCI](http://circleci.com/) - Tests run against [OpenShift's OpenLDAP 2.4.41](https://hub.docker.com/r/openshift/openldap-2441-centos7/) ([source](https://github.com/openshift/openldap/)) * Keep track of unit test coverage using [Codecov](http://codecov.io/) ### Fixed * C89 compatibility * Fix two credentials-related segfaults in `open_simple()` [Unreleased]: https://github.com/lualdap/lualdap/compare/v1.2.5...HEAD [1.2.5]: https://github.com/lualdap/lualdap/compare/v1.2.4...v1.2.5 [1.2.4]: https://github.com/lualdap/lualdap/compare/v1.2.4-rc1...v1.2.4 [1.2.4-rc1]: https://github.com/lualdap/lualdap/compare/v1.2.3...v1.2.4-rc1 lualdap-1.2.5/README.md000066400000000000000000000031621341435545100144270ustar00rootroot00000000000000# LuaLDAP [![CircleCI](https://circleci.com/gh/lualdap/lualdap.svg?style=shield)](https://circleci.com/gh/lualdap/lualdap) [![codecov](https://codecov.io/gh/lualdap/lualdap/branch/master/graph/badge.svg)](https://codecov.io/gh/lualdap/lualdap) LuaLDAP is a simple interface from Lua to an LDAP client, in fact it is a bind to OpenLDAP or to Active Directory Service Interfaces (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. # Installation Current version is 1.2.5. It was developed for Lua 5.1, 5.2 and 5.3, and both OpenLDAP 2.1 or newer and ADSI. # Source code directory structure Files in the distribution: /doc/us/*.html -- Documentation /src/* -- Source files /tests/* -- Test files /vc6/* -- Build files for MS Visual C 6 (deprecated) /rockspecs/ -- luarocks build system releases Makefile -- Makefile for Unix systems (deprecated) config -- Configurations to build on Unix systems (deprecated) Makefile.win -- Makefile for Windows systens with MS Visual C 8 (unmaintained) config.win -- Configurations to build on Windows systems (unmaintained) README.md -- This file NEWS.md -- News and release notes CONTRIBUTORS.md -- Who contributed what LICENSE.md -- MIT License reference # License LuaLDAP is free software and uses the same license as Lua 5.1. # Contributors Please see CONTRIBUTORS for contribution information and documentation on original source. lualdap-1.2.5/config000066400000000000000000000020771341435545100143440ustar00rootroot00000000000000# Lua binary LUA := lua # Lua version number (first and second digits of target version) LUA_VERSION := $(shell $(LUA) -e 'print(_VERSION:match("%S+%s+(%S+)"))') # Lua library LUA_LIB = -llua$(LUA_VERSION) # Lua library directory LUA_LIBDIR = /usr/lib # Lua include directory LUA_INCDIR = /usr/include/lua$(LUA_VERSION) # Installation prefix INST_PREFIX = /usr # Lua binary directory INST_BINDIR = /usr/bin # Lua binary module directory INST_LIBDIR = /usr/lib/lua/$(LUA_VERSION) # Lua source module directory INST_LUADIR = /usr/share/lua/$(LUA_VERSION) # OpenLDAP library (an optional directory can be specified with -L) LDAP_LIB = -lldap # System's libraries directory (where binary libraries are installed) LDAP_LIBDIR = /usr/lib # OpenLDAP includes directory LDAP_INCDIR = /usr/include LBER_LIB = -llber LBER_LIBDIR = /usr/lib LBER_INCDIR = /usr/include # OS dependent LIBFLAG = -shared # for Linux #LIBFLAG = -bundle -undefined dynamic_lookup # for MacOS X # Compilation parameters CC= gcc INSTALL= install MACOSX_DEPLOYMENT_TARGET="10.3" export MACOSX_DEPLOYMENT_TARGET lualdap-1.2.5/config.win000066400000000000000000000012611341435545100151320ustar00rootroot00000000000000# 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 lualdap-1.2.5/doc/000077500000000000000000000000001341435545100137135ustar00rootroot00000000000000lualdap-1.2.5/doc/logo/000077500000000000000000000000001341435545100146535ustar00rootroot00000000000000lualdap-1.2.5/doc/logo/LICENSE000066400000000000000000000013771341435545100156700ustar00rootroot00000000000000Graphic design by Alexandre Nakonechnyj. PostScript programming by the Lua team. This code is hereby placed in the public domain. Permission is hereby granted, without written agreement and without license or royalty fees, to use, copy, and distribute this logo for any purpose, including commercial applications, subject to the following conditions: * The origin of this logo must not be misrepresented; you must not claim that you drew the original logo. We recommend that you give credit to the graphics designer in all printed matter that includes the logo. * The only modification you can make is to adapt the orbiting text to your product name. * The logo can be used in any scale as long as the relative proportions of its elements are maintained. lualdap-1.2.5/doc/logo/lualdap-logo-512x512.png000066400000000000000000001044061341435545100206730ustar00rootroot00000000000000PNG  IHDR{C pHYsaa?itIME&/; IDATxw`[u5aI;$$@(Җ޷.ZRKz[Fᒆ `Nx;KeKx5xɶ$Y_}tsfZ(BԃC    l" p8 ~HP(t:F@ry^vnw |V~v=OT* |>_ B"y4h @ `X~3Ln r{6EkkkaC q8---faaaqEy 222`NRnpGdrr̙3ZF@B$d1 W^0@`܂[t:,NDFќN1 jo߾}, sQ(A$ҘL沁= 򁁁@  "ܱTXX8G ۷o_fffGGj]JZS!999 s&?L&c`ޅH$>Ckjj0:5??3/ѯ^?66ֆ\@`5 !$hkks:61L---ϟxQ-..@*o?n0$)Ng0 |Ad\CCƦZ B""%gM' -N[4 ;vͅ !HRi}}իW#odJ `j~  w8NsaapX,׻^A&ܹ P^^>???99x0tvv2L(t:É`0,,,l,/L&8p E Y0zL,J.HP0Ut%N"L&3P*.k?L޵kסCXL$>Fصk&h4vttl! oohh?6vgق Ba2t:=N}D&UTT\~=Ew&HT*5##Jd.rY,V:{^N$dV >d2TE\P(ٱ2z\.LвT"sNV# ?c O.2L"t:"Hd2b(J$L4|W*gϞP(aECG өTқ Z]'''1]Y `0 œ@i1dydzj,kiTh^4rѾKfyyy+Z@ p\.`0,Er4 $a q:frՖ`0 6>AX,r~>ADSb.D҉mb<H֩xxxeYJW]]]QQ0#T*<}(,5*pttM2!, w7~P*ZBRJ{OM[.-+c|sfz:$S*Yɫ IFimmUttt8{bܶ 0UqPVVP("1"299YPPefRdWjaI [bJL&l,2֏L*YuuΎyl6 fy|||xxxټEqc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;DNSuvv?rM!H$C @v COOO{{BFSUUd2nDjz*ֈq` @!r\.'%%uvvvuulx<F::: !%Iff@ww^t{@&( "^l6|u:tNgZaS.EQX,333GFF:;;ׅP`%ހqـ^ ]]]CCCr\$q0L###CCC}t:]JJ  f0 GFFH$ =>>n2u:h%_N'* ÷su2}BdzX,>f}+El6F  t~/BJJR, BaV\.Pe2bxҥ\.7lvVX,VUT/)JɤRD"H$ 8"##C,ܱxR<(=CbX G{zzZ H$7''''&&,dr8Bp~֚YVkf~0MW^oZ @Xd2LBX,s8NB8\.7>>R BtT*_AP(W/߼B@+C\\˓H$߹6d2Fp8d2`@& rъn7 v… t:=}tKoyyyVV~tbbwd2! ҿo Ql:    YԭIENDB`lualdap-1.2.5/doc/logo/lualdap-logo.ps000066400000000000000000000112721341435545100176020ustar00rootroot00000000000000%!PS-Adobe-2.0 EPSF-2.0 %%Title: LuaLDAP logo %%Creator: lua@tecgraf.puc-rio.br %%CreationDate: Wed Nov 29 19:04:04 EDT 2000 %%BoundingBox: -45 0 1035 1080 %%Pages: 1 %%EndComments %%EndProlog %------------------------------------------------------------------------------ % % Graphic design by Alexandre Nakonechnyj. % PostScript programming by the Lua team. % This code is hereby placed in the public domain. % % Permission is hereby granted, without written agreement and without license % or royalty fees, to use, copy, and distribute this logo for any purpose, % including commercial applications, subject to the following conditions: % % * The origin of this logo must not be misrepresented; you must not % claim that you drew the original logo. We recommend that you give credit % to the graphics designer in all printed matter that includes the logo. % % * The only modification you can make is to adapt the orbiting text to % your product name. % % * The logo can be used in any scale as long as the relative proportions % of its elements are maintained. % %------------------------------------------------------------------------------ /LABEL (LuaLDAP) def %-- DO NOT CHANGE ANYTHING BELOW THIS LINE ------------------------------------ /PLANETCOLOR {0 0 0.5 setrgbcolor} bind def /HOLECOLOR {1.0 setgray} bind def /ORBITCOLOR {0.5 setgray} bind def /LOGOFONT {/Helvetica 0.90} def /LABELFONT {/Helvetica 0.36} def %------------------------------------------------------------------------------ /MOONCOLOR {PLANETCOLOR} bind def /LOGOCOLOR {HOLECOLOR} bind def /LABELCOLOR {ORBITCOLOR} bind def /LABELANGLE 125 def /LOGO (Lua) def /DASHANGLE 10 def /HALFDASHANGLE DASHANGLE 2 div def % moon radius. planet radius is 1. /r 1 2 sqrt 2 div sub def /D {0 360 arc fill} bind def /F {exch findfont exch scalefont setfont} bind def % place it nicely on the paper /RESOLUTION 1024 def RESOLUTION 2 div dup translate RESOLUTION 2 div 2 sqrt div dup scale %-------------------------------------------------------------------- planet -- PLANETCOLOR 0 0 1 D %---------------------------------------------------------------------- hole -- HOLECOLOR 1 2 r mul sub dup r D %---------------------------------------------------------------------- moon -- MOONCOLOR 1 1 r D %---------------------------------------------------------------------- logo -- LOGOCOLOR LOGOFONT F LOGO stringwidth pop 2 div neg -0.5 moveto LOGO show %------------------------------------------------------------------------------ % based on code from Blue Book Program 10, on pages 167--169 % available at ftp://ftp.adobe.com/pub/adobe/displaypostscript/bluebook.shar % str ptsize centerangle radius outsidecircletext -- /outsidecircletext { circtextdict begin /radius exch def /centerangle exch def /ptsize exch def /str exch def gsave str radius ptsize findhalfangle centerangle add rotate str { /charcode exch def ( ) dup 0 charcode put outsideplacechar } forall grestore end } def % string radius ptsize findhalfangle halfangle /findhalfangle { 4 div add exch stringwidth pop 2 div exch 2 mul 3.1415926535 mul div 360 mul } def /circtextdict 16 dict def circtextdict begin /outsideplacechar { /char exch def /halfangle char radius ptsize findhalfangle def gsave halfangle neg rotate radius 0 translate -90 rotate char stringwidth pop 2 div neg 0 moveto char show grestore halfangle 2 mul neg rotate } def end %--------------------------------------------------------------------- label -- LABELFONT F /LABELSIZE LABELFONT exch pop def /LABELRADIUS LABELSIZE 3 div 1 r add sub neg 1.02 mul def /HALFANGLE LABEL LABELRADIUS LABELSIZE findhalfangle HALFDASHANGLE div ceiling HALFDASHANGLE mul def /LABELANGLE 60 LABELANGLE HALFANGLE sub lt { HALFANGLE HALFANGLE DASHANGLE div floor DASHANGLE mul eq {LABELANGLE DASHANGLE div ceiling DASHANGLE mul} {LABELANGLE HALFDASHANGLE sub DASHANGLE div round DASHANGLE mul HALFDASHANGLE add} ifelse } {HALFANGLE 60 add} ifelse def LABELCOLOR LABEL LABELSIZE LABELANGLE LABELRADIUS outsidecircletext %--------------------------------------------------------------------- orbit -- ORBITCOLOR 0.03 setlinewidth [1 r add 3.1415926535 180 div HALFDASHANGLE mul mul] 0 setdash newpath 0 0 1 r add 3 copy 30 LABELANGLE HALFANGLE add arcn stroke 60 LABELANGLE HALFANGLE sub 2 copy lt {arc stroke} {4 {pop} repeat} ifelse %------------------------------------------------------------------ copyright -- /COPYRIGHT (Graphic design by A. Nakonechnyj. Copyright (c) 1998, All rights reserved.) def LABELCOLOR LOGOFONT 32 div F 2 sqrt 0.99 mul dup neg moveto COPYRIGHT 90 rotate %show %---------------------------------------------------------------------- done -- showpage %%Trailer %%EOF lualdap-1.2.5/doc/us/000077500000000000000000000000001341435545100143425ustar00rootroot00000000000000lualdap-1.2.5/doc/us/index.html000066400000000000000000000125311341435545100163410ustar00rootroot00000000000000 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 $

lualdap-1.2.5/doc/us/license.html000066400000000000000000000116641341435545100166620ustar00rootroot00000000000000 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 $

lualdap-1.2.5/doc/us/lualdap.png000066400000000000000000000172741341435545100165050ustar00rootroot00000000000000PNG  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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B33",/(ґ;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 $

lualdap-1.2.5/rockspecs/000077500000000000000000000000001341435545100151425ustar00rootroot00000000000000lualdap-1.2.5/rockspecs/lualdap/000077500000000000000000000000001341435545100165645ustar00rootroot00000000000000lualdap-1.2.5/rockspecs/lualdap/lualdap-1.2.1-1.rockspec000066400000000000000000000013461341435545100225400ustar00rootroot00000000000000package="lualdap" version="1.2.1-1" source = { url = "https://github.com/bdellegrazie/lualdap/archive/v1.2.1.tar.gz", dir = "lualdap-1.2.1", } description = { summary = "Simple interface from Lua to an LDAP Client", detailed = [[ Simple interface from Lua to an LDAP client. ]], homepage = "https://github.com/bdellegrazie/lualdap", license = "MIT" } dependencies = { "lua >= 5.1, < 5.3" } external_dependencies = { LIBLDAP = { header = "ldap.h", library = "ldap", } } build = { type = "builtin", modules = { lualdap = { sources = "src/lualdap.c", libdirs = "$(LIBLDAP_LIBDIR)", incdirs = "$(LIBLDAP_INCDIR)", libraries = "ldap", }, } } lualdap-1.2.5/rockspecs/lualdap/lualdap-1.2.2-1.rockspec000066400000000000000000000013461341435545100225410ustar00rootroot00000000000000package="lualdap" version="1.2.2-1" source = { url = "https://github.com/bdellegrazie/lualdap/archive/v1.2.2.tar.gz", dir = "lualdap-1.2.2", } description = { summary = "Simple interface from Lua to an LDAP Client", detailed = [[ Simple interface from Lua to an LDAP client. ]], homepage = "https://github.com/bdellegrazie/lualdap", license = "MIT" } dependencies = { "lua >= 5.1, < 5.3" } external_dependencies = { LIBLDAP = { header = "ldap.h", library = "ldap", } } build = { type = "builtin", modules = { lualdap = { sources = "src/lualdap.c", libdirs = "$(LIBLDAP_LIBDIR)", incdirs = "$(LIBLDAP_INCDIR)", libraries = "ldap", }, } } lualdap-1.2.5/rockspecs/lualdap/lualdap-1.2.3-1.rockspec000066400000000000000000000013171341435545100225400ustar00rootroot00000000000000package="lualdap" version="1.2.3-1" source = { url = "git://github.com/bdellegrazie/lualdap", tag = "v1.2.3", } description = { summary = "Simple interface from Lua to an LDAP Client", detailed = [[ Simple interface from Lua to an LDAP client. ]], homepage = "https://github.com/bdellegrazie/lualdap", license = "MIT" } dependencies = { "lua >= 5.1, < 5.3" } external_dependencies = { LIBLDAP = { header = "ldap.h", library = "ldap", } } build = { type = "builtin", modules = { lualdap = { sources = {"src/lualdap.c"}, libdirs = {"$(LIBLDAP_LIBDIR)"}, incdirs = {"$(LIBLDAP_INCDIR)"}, libraries = {"ldap"}, }, } } lualdap-1.2.5/rockspecs/lualdap/lualdap-1.2.4-1.rockspec000066400000000000000000000023171341435545100225420ustar00rootroot00000000000000package="lualdap" version="1.2.4.rc1-0" source = { url = "git://github.com/lualdap/lualdap", tag = "v1.2.4-rc1", } description = { summary = "Simple interface from Lua to an LDAP Client", detailed = [[ Simple interface from Lua to an LDAP client. ]], homepage = "https://github.com/bdellegrazie/lualdap", license = "MIT" } dependencies = { "lua >= 5.1", } external_dependencies = { LDAP = { header = "ldap.h", library = "ldap", }, LBER = { header = "lber.h", library = "lber", }, } build = { type = "make", variables = { COVERAGE="$(COVERAGE)", JUNITXML="$(JUNITXML)", }, build_variables = { CFLAGS="$(CFLAGS) -std=c89 -pedantic -Wall -Werror", LIBFLAG="$(LIBFLAG)", LUA_LIBDIR="$(LUA_LIBDIR)", LUA_BINDIR="$(LUA_BINDIR)", LUA_INCDIR="$(LUA_INCDIR)", LUA="$(LUA)", LDAP_LIBDIR="$(LDAP_LIBDIR)", LDAP_INCDIR="$(LDAP_INCDIR)", LBER_LIBDIR="$(LBER_LIBDIR)", LBER_INCDIR="$(LBER_INCDIR)", }, install_variables = { INST_PREFIX="$(PREFIX)", INST_BINDIR="$(BINDIR)", INST_LIBDIR="$(LIBDIR)", INST_LUADIR="$(LUADIR)", INST_CONFDIR="$(CONFDIR)", }, } lualdap-1.2.5/rockspecs/lualdap/lualdap-1.2.4.rc1-0.rockspec000066400000000000000000000023171341435545100232250ustar00rootroot00000000000000package="lualdap" version="1.2.4.rc1-0" source = { url = "git://github.com/lualdap/lualdap", tag = "v1.2.4-rc1", } description = { summary = "Simple interface from Lua to an LDAP Client", detailed = [[ Simple interface from Lua to an LDAP client. ]], homepage = "https://github.com/bdellegrazie/lualdap", license = "MIT" } dependencies = { "lua >= 5.1", } external_dependencies = { LDAP = { header = "ldap.h", library = "ldap", }, LBER = { header = "lber.h", library = "lber", }, } build = { type = "make", variables = { COVERAGE="$(COVERAGE)", JUNITXML="$(JUNITXML)", }, build_variables = { CFLAGS="$(CFLAGS) -std=c89 -pedantic -Wall -Werror", LIBFLAG="$(LIBFLAG)", LUA_LIBDIR="$(LUA_LIBDIR)", LUA_BINDIR="$(LUA_BINDIR)", LUA_INCDIR="$(LUA_INCDIR)", LUA="$(LUA)", LDAP_LIBDIR="$(LDAP_LIBDIR)", LDAP_INCDIR="$(LDAP_INCDIR)", LBER_LIBDIR="$(LBER_LIBDIR)", LBER_INCDIR="$(LBER_INCDIR)", }, install_variables = { INST_PREFIX="$(PREFIX)", INST_BINDIR="$(BINDIR)", INST_LIBDIR="$(LIBDIR)", INST_LUADIR="$(LUADIR)", INST_CONFDIR="$(CONFDIR)", }, } lualdap-1.2.5/rockspecs/lualdap/lualdap-1.2.5.rockspec000066400000000000000000000023101341435545100223760ustar00rootroot00000000000000package="lualdap" version="dev-1" source = { url = "git://github.com/lualdap/lualdap", branch = "master", } description = { summary = "Simple interface from Lua to an LDAP Client", detailed = [[ Simple interface from Lua to an LDAP client. ]], homepage = "https://github.com/bdellegrazie/lualdap", license = "MIT" } dependencies = { "lua >= 5.1", } external_dependencies = { LDAP = { header = "ldap.h", library = "ldap", }, LBER = { header = "lber.h", library = "lber", }, } build = { type = "make", variables = { COVERAGE="$(COVERAGE)", JUNITXML="$(JUNITXML)", }, build_variables = { CFLAGS="$(CFLAGS) -std=c89 -pedantic -Wall -Werror", LIBFLAG="$(LIBFLAG)", LUA_LIBDIR="$(LUA_LIBDIR)", LUA_BINDIR="$(LUA_BINDIR)", LUA_INCDIR="$(LUA_INCDIR)", LUA="$(LUA)", LDAP_LIBDIR="$(LDAP_LIBDIR)", LDAP_INCDIR="$(LDAP_INCDIR)", LBER_LIBDIR="$(LBER_LIBDIR)", LBER_INCDIR="$(LBER_INCDIR)", }, install_variables = { INST_PREFIX="$(PREFIX)", INST_BINDIR="$(BINDIR)", INST_LIBDIR="$(LIBDIR)", INST_LUADIR="$(LUADIR)", INST_CONFDIR="$(CONFDIR)", }, } lualdap-1.2.5/rockspecs/rockspec000066400000000000000000000023101341435545100166720ustar00rootroot00000000000000package="lualdap" version="dev-1" source = { url = "git://github.com/lualdap/lualdap", branch = "master", } description = { summary = "Simple interface from Lua to an LDAP Client", detailed = [[ Simple interface from Lua to an LDAP client. ]], homepage = "https://github.com/bdellegrazie/lualdap", license = "MIT" } dependencies = { "lua >= 5.1", } external_dependencies = { LDAP = { header = "ldap.h", library = "ldap", }, LBER = { header = "lber.h", library = "lber", }, } build = { type = "make", variables = { COVERAGE="$(COVERAGE)", JUNITXML="$(JUNITXML)", }, build_variables = { CFLAGS="$(CFLAGS) -std=c89 -pedantic -Wall -Werror", LIBFLAG="$(LIBFLAG)", LUA_LIBDIR="$(LUA_LIBDIR)", LUA_BINDIR="$(LUA_BINDIR)", LUA_INCDIR="$(LUA_INCDIR)", LUA="$(LUA)", LDAP_LIBDIR="$(LDAP_LIBDIR)", LDAP_INCDIR="$(LDAP_INCDIR)", LBER_LIBDIR="$(LBER_LIBDIR)", LBER_INCDIR="$(LBER_INCDIR)", }, install_variables = { INST_PREFIX="$(PREFIX)", INST_BINDIR="$(BINDIR)", INST_LIBDIR="$(LIBDIR)", INST_LUADIR="$(LUADIR)", INST_CONFDIR="$(CONFDIR)", }, } lualdap-1.2.5/src/000077500000000000000000000000001341435545100137355ustar00rootroot00000000000000lualdap-1.2.5/src/compat-5.3.c000066400000000000000000000700021341435545100156660ustar00rootroot00000000000000#include #include #include #include #include #include #include "compat-5.3.h" /* don't compile it again if it already is included via compat53.h */ #ifndef COMPAT53_C_ #define COMPAT53_C_ /* definitions for Lua 5.1 only */ #if defined(LUA_VERSION_NUM) && LUA_VERSION_NUM == 501 #ifndef COMPAT53_FOPEN_NO_LOCK # if defined(_MSC_VER) # define COMPAT53_FOPEN_NO_LOCK 1 # else /* otherwise */ # define COMPAT53_FOPEN_NO_LOCK 0 # endif /* VC++ only so far */ #endif /* No-lock fopen_s usage if possible */ #if defined(_MSC_VER) && COMPAT53_FOPEN_NO_LOCK # include #endif /* VC++ _fsopen for share-allowed file read */ #ifndef COMPAT53_HAVE_STRERROR_R # if (defined(_POSIX_C_SOURCE) && _POSIX_C_SOURCE >= 200112L) || \ (defined(_XOPEN_SOURCE) && _XOPEN_SOURCE >= 600) || \ defined(__APPLE__) # define COMPAT53_HAVE_STRERROR_R 1 # else /* none of the defines matched: define to 0 */ # define COMPAT53_HAVE_STRERROR_R 0 # endif /* have strerror_r of some form */ #endif /* strerror_r */ #ifndef COMPAT53_HAVE_STRERROR_S # if defined(_MSC_VER) || (defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L && \ defined(__STDC_LIB_EXT1__) && __STDC_LIB_EXT1__) # define COMPAT53_HAVE_STRERROR_S 1 # else /* not VC++ or C11 */ # define COMPAT53_HAVE_STRERROR_S 0 # endif /* strerror_s from VC++ or C11 */ #endif /* strerror_s */ #ifndef COMPAT53_LUA_FILE_BUFFER_SIZE # define COMPAT53_LUA_FILE_BUFFER_SIZE 4096 #endif /* Lua File Buffer Size */ static char* compat53_strerror (int en, char* buff, size_t sz) { #if COMPAT53_HAVE_STRERROR_R /* use strerror_r here, because it's available on these specific platforms */ if (sz > 0) { buff[0] = '\0'; /* we don't care whether the GNU version or the XSI version is used: */ if (strerror_r(en, buff, sz)) { /* Yes, we really DO want to ignore the return value! * GCC makes that extra hard, not even a (void) cast will do. */ } if (buff[0] == '\0') { /* Buffer is unchanged, so we probably have called GNU strerror_r which * returned a static constant string. Chances are that strerror will * return the same static constant string and therefore be thread-safe. */ return strerror(en); } } return buff; /* sz is 0 *or* strerror_r wrote into the buffer */ #elif COMPAT53_HAVE_STRERROR_S /* for MSVC and other C11 implementations, use strerror_s since it's * provided by default by the libraries */ strerror_s(buff, sz, en); return buff; #else /* fallback, but strerror is not guaranteed to be threadsafe due to modifying * errno itself and some impls not locking a static buffer for it ... but most * known systems have threadsafe errno: this might only change if the locale * is changed out from under someone while this function is being called */ (void)buff; (void)sz; return strerror(en); #endif } COMPAT53_API int lua_absindex (lua_State *L, int i) { if (i < 0 && i > LUA_REGISTRYINDEX) i += lua_gettop(L) + 1; return i; } static void compat53_call_lua (lua_State *L, char const code[], size_t len, int nargs, int nret) { lua_rawgetp(L, LUA_REGISTRYINDEX, (void*)code); if (lua_type(L, -1) != LUA_TFUNCTION) { lua_pop(L, 1); if (luaL_loadbuffer(L, code, len, "=none")) lua_error(L); lua_pushvalue(L, -1); lua_rawsetp(L, LUA_REGISTRYINDEX, (void*)code); } lua_insert(L, -nargs-1); lua_call(L, nargs, nret); } static const char compat53_arith_code[] = "local op,a,b=...\n" "if op==0 then return a+b\n" "elseif op==1 then return a-b\n" "elseif op==2 then return a*b\n" "elseif op==3 then return a/b\n" "elseif op==4 then return a%b\n" "elseif op==5 then return a^b\n" "elseif op==6 then return -a\n" "end\n"; COMPAT53_API void lua_arith (lua_State *L, int op) { if (op < LUA_OPADD || op > LUA_OPUNM) luaL_error(L, "invalid 'op' argument for lua_arith"); luaL_checkstack(L, 5, "not enough stack slots"); if (op == LUA_OPUNM) lua_pushvalue(L, -1); lua_pushnumber(L, op); lua_insert(L, -3); compat53_call_lua(L, compat53_arith_code, sizeof(compat53_arith_code)-1, 3, 1); } static const char compat53_compare_code[] = "local a,b=...\n" "return a<=b\n"; COMPAT53_API int lua_compare (lua_State *L, int idx1, int idx2, int op) { int result = 0; switch (op) { case LUA_OPEQ: return lua_equal(L, idx1, idx2); case LUA_OPLT: return lua_lessthan(L, idx1, idx2); case LUA_OPLE: luaL_checkstack(L, 5, "not enough stack slots"); idx1 = lua_absindex(L, idx1); idx2 = lua_absindex(L, idx2); lua_pushvalue(L, idx1); lua_pushvalue(L, idx2); compat53_call_lua(L, compat53_compare_code, sizeof(compat53_compare_code)-1, 2, 1); result = lua_toboolean(L, -1); lua_pop(L, 1); return result; default: luaL_error(L, "invalid 'op' argument for lua_compare"); } return 0; } COMPAT53_API void lua_copy (lua_State *L, int from, int to) { int abs_to = lua_absindex(L, to); luaL_checkstack(L, 1, "not enough stack slots"); lua_pushvalue(L, from); lua_replace(L, abs_to); } COMPAT53_API void lua_len (lua_State *L, int i) { switch (lua_type(L, i)) { case LUA_TSTRING: lua_pushnumber(L, (lua_Number)lua_objlen(L, i)); break; case LUA_TTABLE: if (!luaL_callmeta(L, i, "__len")) lua_pushnumber(L, (lua_Number)lua_objlen(L, i)); break; case LUA_TUSERDATA: if (luaL_callmeta(L, i, "__len")) break; /* FALLTHROUGH */ default: luaL_error(L, "attempt to get length of a %s value", lua_typename(L, lua_type(L, i))); } } COMPAT53_API int lua_rawgetp (lua_State *L, int i, const void *p) { int abs_i = lua_absindex(L, i); lua_pushlightuserdata(L, (void*)p); lua_rawget(L, abs_i); return lua_type(L, -1); } COMPAT53_API void lua_rawsetp (lua_State *L, int i, const void *p) { int abs_i = lua_absindex(L, i); luaL_checkstack(L, 1, "not enough stack slots"); lua_pushlightuserdata(L, (void*)p); lua_insert(L, -2); lua_rawset(L, abs_i); } COMPAT53_API lua_Number lua_tonumberx (lua_State *L, int i, int *isnum) { lua_Number n = lua_tonumber(L, i); if (isnum != NULL) { *isnum = (n != 0 || lua_isnumber(L, i)); } return n; } COMPAT53_API void luaL_checkversion (lua_State *L) { (void)L; } COMPAT53_API void luaL_checkstack (lua_State *L, int sp, const char *msg) { if (!lua_checkstack(L, sp+LUA_MINSTACK)) { if (msg != NULL) luaL_error(L, "stack overflow (%s)", msg); else { lua_pushliteral(L, "stack overflow"); lua_error(L); } } } COMPAT53_API int luaL_getsubtable (lua_State *L, int i, const char *name) { int abs_i = lua_absindex(L, i); luaL_checkstack(L, 3, "not enough stack slots"); lua_pushstring(L, name); lua_gettable(L, abs_i); if (lua_istable(L, -1)) return 1; lua_pop(L, 1); lua_newtable(L); lua_pushstring(L, name); lua_pushvalue(L, -2); lua_settable(L, abs_i); return 0; } COMPAT53_API lua_Integer luaL_len (lua_State *L, int i) { lua_Integer res = 0; int isnum = 0; luaL_checkstack(L, 1, "not enough stack slots"); lua_len(L, i); res = lua_tointegerx(L, -1, &isnum); lua_pop(L, 1); if (!isnum) luaL_error(L, "object length is not an integer"); return res; } COMPAT53_API void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup) { luaL_checkstack(L, nup+1, "too many upvalues"); for (; l->name != NULL; l++) { /* fill the table with given functions */ int i; lua_pushstring(L, l->name); for (i = 0; i < nup; i++) /* copy upvalues to the top */ lua_pushvalue(L, -(nup + 1)); lua_pushcclosure(L, l->func, nup); /* closure with those upvalues */ lua_settable(L, -(nup + 3)); /* table must be below the upvalues, the name and the closure */ } lua_pop(L, nup); /* remove upvalues */ } COMPAT53_API void luaL_setmetatable (lua_State *L, const char *tname) { luaL_checkstack(L, 1, "not enough stack slots"); luaL_getmetatable(L, tname); lua_setmetatable(L, -2); } COMPAT53_API void *luaL_testudata (lua_State *L, int i, const char *tname) { void *p = lua_touserdata(L, i); luaL_checkstack(L, 2, "not enough stack slots"); if (p == NULL || !lua_getmetatable(L, i)) return NULL; else { int res = 0; luaL_getmetatable(L, tname); res = lua_rawequal(L, -1, -2); lua_pop(L, 2); if (!res) p = NULL; } return p; } static int compat53_countlevels (lua_State *L) { lua_Debug ar; int li = 1, le = 1; /* find an upper bound */ while (lua_getstack(L, le, &ar)) { li = le; le *= 2; } /* do a binary search */ while (li < le) { int m = (li + le)/2; if (lua_getstack(L, m, &ar)) li = m + 1; else le = m; } return le - 1; } static int compat53_findfield (lua_State *L, int objidx, int level) { if (level == 0 || !lua_istable(L, -1)) return 0; /* not found */ lua_pushnil(L); /* start 'next' loop */ while (lua_next(L, -2)) { /* for each pair in table */ if (lua_type(L, -2) == LUA_TSTRING) { /* ignore non-string keys */ if (lua_rawequal(L, objidx, -1)) { /* found object? */ lua_pop(L, 1); /* remove value (but keep name) */ return 1; } else if (compat53_findfield(L, objidx, level - 1)) { /* try recursively */ lua_remove(L, -2); /* remove table (but keep name) */ lua_pushliteral(L, "."); lua_insert(L, -2); /* place '.' between the two names */ lua_concat(L, 3); return 1; } } lua_pop(L, 1); /* remove value */ } return 0; /* not found */ } static int compat53_pushglobalfuncname (lua_State *L, lua_Debug *ar) { int top = lua_gettop(L); lua_getinfo(L, "f", ar); /* push function */ lua_pushvalue(L, LUA_GLOBALSINDEX); if (compat53_findfield(L, top + 1, 2)) { lua_copy(L, -1, top + 1); /* move name to proper place */ lua_pop(L, 2); /* remove pushed values */ return 1; } else { lua_settop(L, top); /* remove function and global table */ return 0; } } static void compat53_pushfuncname (lua_State *L, lua_Debug *ar) { if (*ar->namewhat != '\0') /* is there a name? */ lua_pushfstring(L, "function " LUA_QS, ar->name); else if (*ar->what == 'm') /* main? */ lua_pushliteral(L, "main chunk"); else if (*ar->what == 'C') { if (compat53_pushglobalfuncname(L, ar)) { lua_pushfstring(L, "function " LUA_QS, lua_tostring(L, -1)); lua_remove(L, -2); /* remove name */ } else lua_pushliteral(L, "?"); } else lua_pushfstring(L, "function <%s:%d>", ar->short_src, ar->linedefined); } #define COMPAT53_LEVELS1 12 /* size of the first part of the stack */ #define COMPAT53_LEVELS2 10 /* size of the second part of the stack */ COMPAT53_API void luaL_traceback (lua_State *L, lua_State *L1, const char *msg, int level) { lua_Debug ar; int top = lua_gettop(L); int numlevels = compat53_countlevels(L1); int mark = (numlevels > COMPAT53_LEVELS1 + COMPAT53_LEVELS2) ? COMPAT53_LEVELS1 : 0; if (msg) lua_pushfstring(L, "%s\n", msg); lua_pushliteral(L, "stack traceback:"); while (lua_getstack(L1, level++, &ar)) { if (level == mark) { /* too many levels? */ lua_pushliteral(L, "\n\t..."); /* add a '...' */ level = numlevels - COMPAT53_LEVELS2; /* and skip to last ones */ } else { lua_getinfo(L1, "Slnt", &ar); lua_pushfstring(L, "\n\t%s:", ar.short_src); if (ar.currentline > 0) lua_pushfstring(L, "%d:", ar.currentline); lua_pushliteral(L, " in "); compat53_pushfuncname(L, &ar); lua_concat(L, lua_gettop(L) - top); } } lua_concat(L, lua_gettop(L) - top); } COMPAT53_API int luaL_fileresult (lua_State *L, int stat, const char *fname) { const char *serr = NULL; int en = errno; /* calls to Lua API may change this value */ char buf[512] = { 0 }; if (stat) { lua_pushboolean(L, 1); return 1; } else { lua_pushnil(L); serr = compat53_strerror(en, buf, sizeof(buf)); if (fname) lua_pushfstring(L, "%s: %s", fname, serr); else lua_pushstring(L, serr); lua_pushnumber(L, (lua_Number)en); return 3; } } static int compat53_checkmode (lua_State *L, const char *mode, const char *modename, int err) { if (mode && strchr(mode, modename[0]) == NULL) { lua_pushfstring(L, "attempt to load a %s chunk (mode is '%s')", modename, mode); return err; } return LUA_OK; } typedef struct { lua_Reader reader; void *ud; int has_peeked_data; const char *peeked_data; size_t peeked_data_size; } compat53_reader_data; static const char *compat53_reader (lua_State *L, void *ud, size_t *size) { compat53_reader_data *data = (compat53_reader_data *)ud; if (data->has_peeked_data) { data->has_peeked_data = 0; *size = data->peeked_data_size; return data->peeked_data; } else return data->reader(L, data->ud, size); } COMPAT53_API int lua_load (lua_State *L, lua_Reader reader, void *data, const char *source, const char *mode) { int status = LUA_OK; compat53_reader_data compat53_data = { 0, NULL, 1, 0, 0 }; compat53_data.reader = reader; compat53_data.ud = data; compat53_data.peeked_data = reader(L, data, &(compat53_data.peeked_data_size)); if (compat53_data.peeked_data && compat53_data.peeked_data_size && compat53_data.peeked_data[0] == LUA_SIGNATURE[0]) /* binary file? */ status = compat53_checkmode(L, mode, "binary", LUA_ERRSYNTAX); else status = compat53_checkmode(L, mode, "text", LUA_ERRSYNTAX); if (status != LUA_OK) return status; /* we need to call the original 5.1 version of lua_load! */ #undef lua_load return lua_load(L, compat53_reader, &compat53_data, source); #define lua_load COMPAT53_CONCAT(COMPAT53_PREFIX, _load_53) } typedef struct { int n; /* number of pre-read characters */ FILE *f; /* file being read */ char buff[COMPAT53_LUA_FILE_BUFFER_SIZE]; /* area for reading file */ } compat53_LoadF; static const char *compat53_getF (lua_State *L, void *ud, size_t *size) { compat53_LoadF *lf = (compat53_LoadF *)ud; (void)L; /* not used */ if (lf->n > 0) { /* are there pre-read characters to be read? */ *size = lf->n; /* return them (chars already in buffer) */ lf->n = 0; /* no more pre-read characters */ } else { /* read a block from file */ /* 'fread' can return > 0 *and* set the EOF flag. If next call to 'compat53_getF' called 'fread', it might still wait for user input. The next check avoids this problem. */ if (feof(lf->f)) return NULL; *size = fread(lf->buff, 1, sizeof(lf->buff), lf->f); /* read block */ } return lf->buff; } static int compat53_errfile (lua_State *L, const char *what, int fnameindex) { char buf[512] = {0}; const char *serr = compat53_strerror(errno, buf, sizeof(buf)); const char *filename = lua_tostring(L, fnameindex) + 1; lua_pushfstring(L, "cannot %s %s: %s", what, filename, serr); lua_remove(L, fnameindex); return LUA_ERRFILE; } static int compat53_skipBOM (compat53_LoadF *lf) { const char *p = "\xEF\xBB\xBF"; /* UTF-8 BOM mark */ int c; lf->n = 0; do { c = getc(lf->f); if (c == EOF || c != *(const unsigned char *)p++) return c; lf->buff[lf->n++] = (char)c; /* to be read by the parser */ } while (*p != '\0'); lf->n = 0; /* prefix matched; discard it */ return getc(lf->f); /* return next character */ } /* ** reads the first character of file 'f' and skips an optional BOM mark ** in its beginning plus its first line if it starts with '#'. Returns ** true if it skipped the first line. In any case, '*cp' has the ** first "valid" character of the file (after the optional BOM and ** a first-line comment). */ static int compat53_skipcomment (compat53_LoadF *lf, int *cp) { int c = *cp = compat53_skipBOM(lf); if (c == '#') { /* first line is a comment (Unix exec. file)? */ do { /* skip first line */ c = getc(lf->f); } while (c != EOF && c != '\n'); *cp = getc(lf->f); /* skip end-of-line, if present */ return 1; /* there was a comment */ } else return 0; /* no comment */ } COMPAT53_API int luaL_loadfilex (lua_State *L, const char *filename, const char *mode) { compat53_LoadF lf; int status, readstatus; int c; int fnameindex = lua_gettop(L) + 1; /* index of filename on the stack */ if (filename == NULL) { lua_pushliteral(L, "=stdin"); lf.f = stdin; } else { lua_pushfstring(L, "@%s", filename); #if defined(_MSC_VER) /* This code is here to stop a deprecation error that stops builds * if a certain macro is defined. While normally not caring would * be best, some header-only libraries and builds can't afford to * dictate this to the user. A quick check shows that fopen_s this * goes back to VS 2005, and _fsopen goes back to VS 2003 .NET, * possibly even before that so we don't need to do any version * number checks, since this has been there since forever. */ /* TO USER: if you want the behavior of typical fopen_s/fopen, * which does lock the file on VC++, define the macro used below to 0 */ #if COMPAT53_FOPEN_NO_LOCK lf.f = _fsopen(filename, "r", _SH_DENYNO); /* do not lock the file in any way */ if (lf.f == NULL) return compat53_errfile(L, "open", fnameindex); #else /* use default locking version */ if (fopen_s(&lf.f, filename, "r") != 0) return compat53_errfile(L, "open", fnameindex); #endif /* Locking vs. No-locking fopen variants */ #else lf.f = fopen(filename, "r"); /* default stdlib doesn't forcefully lock files here */ if (lf.f == NULL) return compat53_errfile(L, "open", fnameindex); #endif } if (compat53_skipcomment(&lf, &c)) /* read initial portion */ lf.buff[lf.n++] = '\n'; /* add line to correct line numbers */ if (c == LUA_SIGNATURE[0] && filename) { /* binary file? */ #if defined(_MSC_VER) if (freopen_s(&lf.f, filename, "rb", lf.f) != 0) return compat53_errfile(L, "reopen", fnameindex); #else lf.f = freopen(filename, "rb", lf.f); /* reopen in binary mode */ if (lf.f == NULL) return compat53_errfile(L, "reopen", fnameindex); #endif compat53_skipcomment(&lf, &c); /* re-read initial portion */ } if (c != EOF) lf.buff[lf.n++] = (char)c; /* 'c' is the first character of the stream */ status = lua_load(L, &compat53_getF, &lf, lua_tostring(L, -1), mode); readstatus = ferror(lf.f); if (filename) fclose(lf.f); /* close file (even in case of errors) */ if (readstatus) { lua_settop(L, fnameindex); /* ignore results from 'lua_load' */ return compat53_errfile(L, "read", fnameindex); } lua_remove(L, fnameindex); return status; } COMPAT53_API int luaL_loadbufferx (lua_State *L, const char *buff, size_t sz, const char *name, const char *mode) { int status = LUA_OK; if (sz > 0 && buff[0] == LUA_SIGNATURE[0]) { status = compat53_checkmode(L, mode, "binary", LUA_ERRSYNTAX); } else { status = compat53_checkmode(L, mode, "text", LUA_ERRSYNTAX); } if (status != LUA_OK) return status; return luaL_loadbuffer(L, buff, sz, name); } #if !defined(l_inspectstat) && \ (defined(unix) || defined(__unix) || defined(__unix__) || \ defined(__TOS_AIX__) || defined(_SYSTYPE_BSD) || \ (defined(__APPLE__) && defined(__MACH__))) /* some form of unix; check feature macros in unistd.h for details */ # include /* check posix version; the relevant include files and macros probably * were available before 2001, but I'm not sure */ # if defined(_POSIX_VERSION) && _POSIX_VERSION >= 200112L # include # define l_inspectstat(stat,what) \ if (WIFEXITED(stat)) { stat = WEXITSTATUS(stat); } \ else if (WIFSIGNALED(stat)) { stat = WTERMSIG(stat); what = "signal"; } # endif #endif /* provide default (no-op) version */ #if !defined(l_inspectstat) # define l_inspectstat(stat,what) ((void)0) #endif COMPAT53_API int luaL_execresult (lua_State *L, int stat) { const char *what = "exit"; if (stat == -1) return luaL_fileresult(L, 0, NULL); else { l_inspectstat(stat, what); if (*what == 'e' && stat == 0) lua_pushboolean(L, 1); else lua_pushnil(L); lua_pushstring(L, what); lua_pushinteger(L, stat); return 3; } } COMPAT53_API void luaL_buffinit (lua_State *L, luaL_Buffer_53 *B) { /* make it crash if used via pointer to a 5.1-style luaL_Buffer */ B->b.p = NULL; B->b.L = NULL; B->b.lvl = 0; /* reuse the buffer from the 5.1-style luaL_Buffer though! */ B->ptr = B->b.buffer; B->capacity = LUAL_BUFFERSIZE; B->nelems = 0; B->L2 = L; } COMPAT53_API char *luaL_prepbuffsize (luaL_Buffer_53 *B, size_t s) { if (B->capacity - B->nelems < s) { /* needs to grow */ char* newptr = NULL; size_t newcap = B->capacity * 2; if (newcap - B->nelems < s) newcap = B->nelems + s; if (newcap < B->capacity) /* overflow */ luaL_error(B->L2, "buffer too large"); newptr = (char*)lua_newuserdata(B->L2, newcap); memcpy(newptr, B->ptr, B->nelems); if (B->ptr != B->b.buffer) lua_replace(B->L2, -2); /* remove old buffer */ B->ptr = newptr; B->capacity = newcap; } return B->ptr+B->nelems; } COMPAT53_API void luaL_addlstring (luaL_Buffer_53 *B, const char *s, size_t l) { memcpy(luaL_prepbuffsize(B, l), s, l); luaL_addsize(B, l); } COMPAT53_API void luaL_addvalue (luaL_Buffer_53 *B) { size_t len = 0; const char *s = lua_tolstring(B->L2, -1, &len); if (!s) luaL_error(B->L2, "cannot convert value to string"); if (B->ptr != B->b.buffer) lua_insert(B->L2, -2); /* userdata buffer must be at stack top */ luaL_addlstring(B, s, len); lua_remove(B->L2, B->ptr != B->b.buffer ? -2 : -1); } void luaL_pushresult (luaL_Buffer_53 *B) { lua_pushlstring(B->L2, B->ptr, B->nelems); if (B->ptr != B->b.buffer) lua_replace(B->L2, -2); /* remove userdata buffer */ } #endif /* Lua 5.1 */ /* definitions for Lua 5.1 and Lua 5.2 */ #if defined( LUA_VERSION_NUM ) && LUA_VERSION_NUM <= 502 COMPAT53_API int lua_geti (lua_State *L, int index, lua_Integer i) { index = lua_absindex(L, index); lua_pushinteger(L, i); lua_gettable(L, index); return lua_type(L, -1); } #ifndef LUA_EXTRASPACE #define LUA_EXTRASPACE (sizeof(void*)) #endif COMPAT53_API void *lua_getextraspace (lua_State *L) { int is_main = 0; void *ptr = NULL; luaL_checkstack(L, 4, "not enough stack slots available"); lua_pushliteral(L, "__compat53_extraspace"); lua_pushvalue(L, -1); lua_rawget(L, LUA_REGISTRYINDEX); if (!lua_istable(L, -1)) { lua_pop(L, 1); lua_createtable(L, 0, 2); lua_createtable(L, 0, 1); lua_pushliteral(L, "k"); lua_setfield(L, -2, "__mode"); lua_setmetatable(L, -2); lua_pushvalue(L, -2); lua_pushvalue(L, -2); lua_rawset(L, LUA_REGISTRYINDEX); } lua_replace(L, -2); is_main = lua_pushthread(L); lua_rawget(L, -2); ptr = lua_touserdata(L, -1); if (!ptr) { lua_pop(L, 1); ptr = lua_newuserdata(L, LUA_EXTRASPACE); if (is_main) { memset(ptr, '\0', LUA_EXTRASPACE); lua_pushthread(L); lua_pushvalue(L, -2); lua_rawset(L, -4); lua_pushboolean(L, 1); lua_pushvalue(L, -2); lua_rawset(L, -4); } else { void* mptr = NULL; lua_pushboolean(L, 1); lua_rawget(L, -3); mptr = lua_touserdata(L, -1); if (mptr) memcpy(ptr, mptr, LUA_EXTRASPACE); else memset(ptr, '\0', LUA_EXTRASPACE); lua_pop(L, 1); lua_pushthread(L); lua_pushvalue(L, -2); lua_rawset(L, -4); } } lua_pop(L, 2); return ptr; } COMPAT53_API int lua_isinteger (lua_State *L, int index) { if (lua_type(L, index) == LUA_TNUMBER) { lua_Number n = lua_tonumber(L, index); lua_Integer i = lua_tointeger(L, index); if (i == n) return 1; } return 0; } COMPAT53_API lua_Integer lua_tointegerx (lua_State *L, int i, int *isnum) { int ok = 0; lua_Number n = lua_tonumberx(L, i, &ok); if (ok) { if (n == (lua_Integer)n) { if (isnum) *isnum = 1; return (lua_Integer)n; } } if (isnum) *isnum = 0; return 0; } static void compat53_reverse (lua_State *L, int a, int b) { for (; a < b; ++a, --b) { lua_pushvalue(L, a); lua_pushvalue(L, b); lua_replace(L, a); lua_replace(L, b); } } COMPAT53_API void lua_rotate (lua_State *L, int idx, int n) { int n_elems = 0; idx = lua_absindex(L, idx); n_elems = lua_gettop(L)-idx+1; if (n < 0) n += n_elems; if ( n > 0 && n < n_elems) { luaL_checkstack(L, 2, "not enough stack slots available"); n = n_elems - n; compat53_reverse(L, idx, idx+n-1); compat53_reverse(L, idx+n, idx+n_elems-1); compat53_reverse(L, idx, idx+n_elems-1); } } COMPAT53_API void lua_seti (lua_State *L, int index, lua_Integer i) { luaL_checkstack(L, 1, "not enough stack slots available"); index = lua_absindex(L, index); lua_pushinteger(L, i); lua_insert(L, -2); lua_settable(L, index); } #if !defined(lua_str2number) # define lua_str2number(s, p) strtod((s), (p)) #endif COMPAT53_API size_t lua_stringtonumber (lua_State *L, const char *s) { char* endptr; lua_Number n = lua_str2number(s, &endptr); if (endptr != s) { while (*endptr != '\0' && isspace((unsigned char)*endptr)) ++endptr; if (*endptr == '\0') { lua_pushnumber(L, n); return endptr - s + 1; } } return 0; } COMPAT53_API const char *luaL_tolstring (lua_State *L, int idx, size_t *len) { if (!luaL_callmeta(L, idx, "__tostring")) { int t = lua_type(L, idx), tt = 0; char const* name = NULL; switch (t) { case LUA_TNIL: lua_pushliteral(L, "nil"); break; case LUA_TSTRING: case LUA_TNUMBER: lua_pushvalue(L, idx); break; case LUA_TBOOLEAN: if (lua_toboolean(L, idx)) lua_pushliteral(L, "true"); else lua_pushliteral(L, "false"); break; default: tt = luaL_getmetafield(L, idx, "__name"); name = (tt == LUA_TSTRING) ? lua_tostring(L, -1) : lua_typename(L, t); lua_pushfstring(L, "%s: %p", name, lua_topointer(L, idx)); if (tt != LUA_TNIL) lua_replace(L, -2); break; } } else { if (!lua_isstring(L, -1)) luaL_error(L, "'__tostring' must return a string"); } return lua_tolstring(L, -1, len); } COMPAT53_API void luaL_requiref (lua_State *L, const char *modname, lua_CFunction openf, int glb) { luaL_checkstack(L, 3, "not enough stack slots available"); luaL_getsubtable(L, LUA_REGISTRYINDEX, "_LOADED"); if (lua_getfield(L, -1, modname) == LUA_TNIL) { lua_pop(L, 1); lua_pushcfunction(L, openf); lua_pushstring(L, modname); lua_call(L, 1, 1); lua_pushvalue(L, -1); lua_setfield(L, -3, modname); } if (glb) { lua_pushvalue(L, -1); lua_setglobal(L, modname); } lua_replace(L, -2); } #endif /* Lua 5.1 and 5.2 */ #endif /* COMPAT53_C_ */ /********************************************************************* * This file contains parts of Lua 5.2's and Lua 5.3's source code: * * Copyright (C) 1994-2014 Lua.org, PUC-Rio. * * 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. *********************************************************************/ lualdap-1.2.5/src/compat-5.3.h000066400000000000000000000311321341435545100156740ustar00rootroot00000000000000#ifndef COMPAT53_H_ #define COMPAT53_H_ #include #include #include #if defined(__cplusplus) && !defined(COMPAT53_LUA_CPP) extern "C" { #endif #include #include #include #if defined(__cplusplus) && !defined(COMPAT53_LUA_CPP) } #endif #undef COMPAT53_INCLUDE_SOURCE #if defined(COMPAT53_PREFIX) /* - change the symbol names of functions to avoid linker conflicts * - compat-5.3.c needs to be compiled (and linked) separately */ # if !defined(COMPAT53_API) # define COMPAT53_API extern # endif #else /* COMPAT53_PREFIX */ /* - make all functions static and include the source. * - compat-5.3.c doesn't need to be compiled (and linked) separately */ # define COMPAT53_PREFIX compat53 # undef COMPAT53_API # if defined(__GNUC__) || defined(__clang__) # define COMPAT53_API __attribute__((__unused__)) static # else # define COMPAT53_API static # endif # define COMPAT53_INCLUDE_SOURCE #endif /* COMPAT53_PREFIX */ #define COMPAT53_CONCAT_HELPER(a, b) a##b #define COMPAT53_CONCAT(a, b) COMPAT53_CONCAT_HELPER(a, b) /* declarations for Lua 5.1 */ #if defined(LUA_VERSION_NUM) && LUA_VERSION_NUM == 501 /* XXX not implemented: * lua_arith (new operators) * lua_upvalueid * lua_upvaluejoin * lua_version * lua_yieldk */ #ifndef LUA_OK # define LUA_OK 0 #endif #ifndef LUA_OPADD # define LUA_OPADD 0 #endif #ifndef LUA_OPSUB # define LUA_OPSUB 1 #endif #ifndef LUA_OPMUL # define LUA_OPMUL 2 #endif #ifndef LUA_OPDIV # define LUA_OPDIV 3 #endif #ifndef LUA_OPMOD # define LUA_OPMOD 4 #endif #ifndef LUA_OPPOW # define LUA_OPPOW 5 #endif #ifndef LUA_OPUNM # define LUA_OPUNM 6 #endif #ifndef LUA_OPEQ # define LUA_OPEQ 0 #endif #ifndef LUA_OPLT # define LUA_OPLT 1 #endif #ifndef LUA_OPLE # define LUA_OPLE 2 #endif /* LuaJIT/Lua 5.1 does not have the updated * error codes for thread status/function returns (but some patched versions do) * define it only if it's not found */ #if !defined(LUA_ERRGCMM) /* Use + 2 because in some versions of Lua (Lua 5.1) * LUA_ERRFILE is defined as (LUA_ERRERR+1) * so we need to avoid it (LuaJIT might have something at this * integer value too) */ # define LUA_ERRGCMM (LUA_ERRERR + 2) #endif /* LUA_ERRGCMM define */ typedef size_t lua_Unsigned; typedef struct luaL_Buffer_53 { luaL_Buffer b; /* make incorrect code crash! */ char *ptr; size_t nelems; size_t capacity; lua_State *L2; } luaL_Buffer_53; #define luaL_Buffer luaL_Buffer_53 /* In PUC-Rio 5.1, userdata is a simple FILE* * In LuaJIT, it's a struct where the first member is a FILE* * We can't support the `closef` member */ typedef struct luaL_Stream { FILE *f; } luaL_Stream; #define lua_absindex COMPAT53_CONCAT(COMPAT53_PREFIX, _absindex) COMPAT53_API int lua_absindex (lua_State *L, int i); #define lua_arith COMPAT53_CONCAT(COMPAT53_PREFIX, _arith) COMPAT53_API void lua_arith (lua_State *L, int op); #define lua_compare COMPAT53_CONCAT(COMPAT53_PREFIX, _compare) COMPAT53_API int lua_compare (lua_State *L, int idx1, int idx2, int op); #define lua_copy COMPAT53_CONCAT(COMPAT53_PREFIX, _copy) COMPAT53_API void lua_copy (lua_State *L, int from, int to); #define lua_getuservalue(L, i) \ (lua_getfenv((L), (i)), lua_type((L), -1)) #define lua_setuservalue(L, i) \ (luaL_checktype((L), -1, LUA_TTABLE), lua_setfenv((L), (i))) #define lua_len COMPAT53_CONCAT(COMPAT53_PREFIX, _len) COMPAT53_API void lua_len (lua_State *L, int i); #define lua_pushstring(L, s) \ (lua_pushstring((L), (s)), lua_tostring((L), -1)) #define lua_pushlstring(L, s, len) \ ((((len) == 0) ? lua_pushlstring((L), "", 0) : lua_pushlstring((L), (s), (len))), lua_tostring((L), -1)) #ifndef luaL_newlibtable # define luaL_newlibtable(L, l) \ (lua_createtable((L), 0, sizeof((l))/sizeof(*(l))-1)) #endif #ifndef luaL_newlib # define luaL_newlib(L, l) \ (luaL_newlibtable((L), (l)), luaL_register((L), NULL, (l))) #endif #define lua_pushglobaltable(L) \ lua_pushvalue((L), LUA_GLOBALSINDEX) #define lua_rawgetp COMPAT53_CONCAT(COMPAT53_PREFIX, _rawgetp) COMPAT53_API int lua_rawgetp (lua_State *L, int i, const void *p); #define lua_rawsetp COMPAT53_CONCAT(COMPAT53_PREFIX, _rawsetp) COMPAT53_API void lua_rawsetp(lua_State *L, int i, const void *p); #define lua_rawlen(L, i) lua_objlen((L), (i)) #define lua_tointeger(L, i) lua_tointegerx((L), (i), NULL) #define lua_tonumberx COMPAT53_CONCAT(COMPAT53_PREFIX, _tonumberx) COMPAT53_API lua_Number lua_tonumberx (lua_State *L, int i, int *isnum); #define luaL_checkversion COMPAT53_CONCAT(COMPAT53_PREFIX, L_checkversion) COMPAT53_API void luaL_checkversion (lua_State *L); #define lua_load COMPAT53_CONCAT(COMPAT53_PREFIX, _load_53) COMPAT53_API int lua_load (lua_State *L, lua_Reader reader, void *data, const char* source, const char* mode); #define luaL_loadfilex COMPAT53_CONCAT(COMPAT53_PREFIX, L_loadfilex) COMPAT53_API int luaL_loadfilex (lua_State *L, const char *filename, const char *mode); #define luaL_loadbufferx COMPAT53_CONCAT(COMPAT53_PREFIX, L_loadbufferx) COMPAT53_API int luaL_loadbufferx (lua_State *L, const char *buff, size_t sz, const char *name, const char *mode); #define luaL_checkstack COMPAT53_CONCAT(COMPAT53_PREFIX, L_checkstack_53) COMPAT53_API void luaL_checkstack (lua_State *L, int sp, const char *msg); #define luaL_getsubtable COMPAT53_CONCAT(COMPAT53_PREFIX, L_getsubtable) COMPAT53_API int luaL_getsubtable (lua_State* L, int i, const char *name); #define luaL_len COMPAT53_CONCAT(COMPAT53_PREFIX, L_len) COMPAT53_API lua_Integer luaL_len (lua_State *L, int i); #define luaL_setfuncs COMPAT53_CONCAT(COMPAT53_PREFIX, L_setfuncs) COMPAT53_API void luaL_setfuncs (lua_State *L, const luaL_Reg *l, int nup); #define luaL_setmetatable COMPAT53_CONCAT(COMPAT53_PREFIX, L_setmetatable) COMPAT53_API void luaL_setmetatable (lua_State *L, const char *tname); #define luaL_testudata COMPAT53_CONCAT(COMPAT53_PREFIX, L_testudata) COMPAT53_API void *luaL_testudata (lua_State *L, int i, const char *tname); #define luaL_traceback COMPAT53_CONCAT(COMPAT53_PREFIX, L_traceback) COMPAT53_API void luaL_traceback (lua_State *L, lua_State *L1, const char *msg, int level); #define luaL_fileresult COMPAT53_CONCAT(COMPAT53_PREFIX, L_fileresult) COMPAT53_API int luaL_fileresult (lua_State *L, int stat, const char *fname); #define luaL_execresult COMPAT53_CONCAT(COMPAT53_PREFIX, L_execresult) COMPAT53_API int luaL_execresult (lua_State *L, int stat); #define lua_callk(L, na, nr, ctx, cont) \ ((void)(ctx), (void)(cont), lua_call((L), (na), (nr))) #define lua_pcallk(L, na, nr, err, ctx, cont) \ ((void)(ctx), (void)(cont), lua_pcall((L), (na), (nr), (err))) #define lua_resume(L, from, nargs) \ ((void)(from), lua_resume((L), (nargs))) #define luaL_buffinit COMPAT53_CONCAT(COMPAT53_PREFIX, _buffinit_53) COMPAT53_API void luaL_buffinit (lua_State *L, luaL_Buffer_53 *B); #define luaL_prepbuffsize COMPAT53_CONCAT(COMPAT53_PREFIX, _prepbufsize_53) COMPAT53_API char *luaL_prepbuffsize (luaL_Buffer_53 *B, size_t s); #define luaL_addlstring COMPAT53_CONCAT(COMPAT53_PREFIX, _addlstring_53) COMPAT53_API void luaL_addlstring (luaL_Buffer_53 *B, const char *s, size_t l); #define luaL_addvalue COMPAT53_CONCAT(COMPAT53_PREFIX, _addvalue_53) COMPAT53_API void luaL_addvalue (luaL_Buffer_53 *B); #define luaL_pushresult COMPAT53_CONCAT(COMPAT53_PREFIX, _pushresult_53) COMPAT53_API void luaL_pushresult (luaL_Buffer_53 *B); #undef luaL_buffinitsize #define luaL_buffinitsize(L, B, s) \ (luaL_buffinit((L), (B)), luaL_prepbuffsize((B), (s))) #undef luaL_prepbuffer #define luaL_prepbuffer(B) \ luaL_prepbuffsize((B), LUAL_BUFFERSIZE) #undef luaL_addchar #define luaL_addchar(B, c) \ ((void)((B)->nelems < (B)->capacity || luaL_prepbuffsize((B), 1)), \ ((B)->ptr[(B)->nelems++] = (c))) #undef luaL_addsize #define luaL_addsize(B, s) \ ((B)->nelems += (s)) #undef luaL_addstring #define luaL_addstring(B, s) \ luaL_addlstring((B), (s), strlen((s))) #undef luaL_pushresultsize #define luaL_pushresultsize(B, s) \ (luaL_addsize((B), (s)), luaL_pushresult((B))) #if defined(LUA_COMPAT_APIINTCASTS) #define lua_pushunsigned(L, n) \ lua_pushinteger((L), (lua_Integer)(n)) #define lua_tounsignedx(L, i, is) \ ((lua_Unsigned)lua_tointegerx((L), (i), (is))) #define lua_tounsigned(L, i) \ lua_tounsignedx((L), (i), NULL) #define luaL_checkunsigned(L, a) \ ((lua_Unsigned)luaL_checkinteger((L), (a))) #define luaL_optunsigned(L, a, d) \ ((lua_Unsigned)luaL_optinteger((L), (a), (lua_Integer)(d))) #endif #endif /* Lua 5.1 only */ /* declarations for Lua 5.1 and 5.2 */ #if defined(LUA_VERSION_NUM) && LUA_VERSION_NUM <= 502 typedef int lua_KContext; typedef int (*lua_KFunction)(lua_State *L, int status, lua_KContext ctx); #define lua_dump(L, w, d, s) \ ((void)(s), lua_dump((L), (w), (d))) #define lua_getfield(L, i, k) \ (lua_getfield((L), (i), (k)), lua_type((L), -1)) #define lua_gettable(L, i) \ (lua_gettable((L), (i)), lua_type((L), -1)) #define lua_geti COMPAT53_CONCAT(COMPAT53_PREFIX, _geti) COMPAT53_API int lua_geti (lua_State *L, int index, lua_Integer i); #define lua_getextraspace COMPAT53_CONCAT(COMPAT53_PREFIX, _getextraspace) COMPAT53_API void *lua_getextraspace (lua_State *L); #define lua_isinteger COMPAT53_CONCAT(COMPAT53_PREFIX, _isinteger) COMPAT53_API int lua_isinteger (lua_State *L, int index); #define lua_tointegerx COMPAT53_CONCAT(COMPAT53_PREFIX, _tointegerx_53) COMPAT53_API lua_Integer lua_tointegerx (lua_State *L, int i, int *isnum); #define lua_numbertointeger(n, p) \ ((*(p) = (lua_Integer)(n)), 1) #define lua_rawget(L, i) \ (lua_rawget((L), (i)), lua_type((L), -1)) #define lua_rawgeti(L, i, n) \ (lua_rawgeti((L), (i), (n)), lua_type((L), -1)) #define lua_rotate COMPAT53_CONCAT(COMPAT53_PREFIX, _rotate) COMPAT53_API void lua_rotate (lua_State *L, int idx, int n); #define lua_seti COMPAT53_CONCAT(COMPAT53_PREFIX, _seti) COMPAT53_API void lua_seti (lua_State *L, int index, lua_Integer i); #define lua_stringtonumber COMPAT53_CONCAT(COMPAT53_PREFIX, _stringtonumber) COMPAT53_API size_t lua_stringtonumber (lua_State *L, const char *s); #define luaL_tolstring COMPAT53_CONCAT(COMPAT53_PREFIX, L_tolstring) COMPAT53_API const char *luaL_tolstring (lua_State *L, int idx, size_t *len); #define luaL_getmetafield(L, o, e) \ (luaL_getmetafield((L), (o), (e)) ? lua_type((L), -1) : LUA_TNIL) #define luaL_newmetatable(L, tn) \ (luaL_newmetatable((L), (tn)) ? (lua_pushstring((L), (tn)), lua_setfield((L), -2, "__name"), 1) : 0) #define luaL_requiref COMPAT53_CONCAT(COMPAT53_PREFIX, L_requiref_53) COMPAT53_API void luaL_requiref (lua_State *L, const char *modname, lua_CFunction openf, int glb ); #endif /* Lua 5.1 and Lua 5.2 */ /* declarations for Lua 5.2 */ #if defined(LUA_VERSION_NUM) && LUA_VERSION_NUM == 502 /* XXX not implemented: * lua_isyieldable * lua_arith (new operators) * lua_pushfstring (new formats) */ #define lua_getglobal(L, n) \ (lua_getglobal((L), (n)), lua_type((L), -1)) #define lua_getuservalue(L, i) \ (lua_getuservalue((L), (i)), lua_type((L), -1)) #define lua_pushlstring(L, s, len) \ (((len) == 0) ? lua_pushlstring((L), "", 0) : lua_pushlstring((L), (s), (len))) #define lua_rawgetp(L, i, p) \ (lua_rawgetp((L), (i), (p)), lua_type((L), -1)) #define LUA_KFUNCTION(_name) \ static int (_name)(lua_State *L, int status, lua_KContext ctx); \ static int (_name ## _52)(lua_State *L) { \ lua_KContext ctx; \ int status = lua_getctx(L, &ctx); \ return (_name)(L, status, ctx); \ } \ static int (_name)(lua_State *L, int status, lua_KContext ctx) #define lua_pcallk(L, na, nr, err, ctx, cont) \ lua_pcallk((L), (na), (nr), (err), (ctx), cont ## _52) #define lua_callk(L, na, nr, ctx, cont) \ lua_callk((L), (na), (nr), (ctx), cont ## _52) #define lua_yieldk(L, nr, ctx, cont) \ lua_yieldk((L), (nr), (ctx), cont ## _52) #ifdef lua_call # undef lua_call # define lua_call(L, na, nr) \ (lua_callk)((L), (na), (nr), 0, NULL) #endif #ifdef lua_pcall # undef lua_pcall # define lua_pcall(L, na, nr, err) \ (lua_pcallk)((L), (na), (nr), (err), 0, NULL) #endif #ifdef lua_yield # undef lua_yield # define lua_yield(L, nr) \ (lua_yieldk)((L), (nr), 0, NULL) #endif #endif /* Lua 5.2 only */ /* other Lua versions */ #if !defined(LUA_VERSION_NUM) || LUA_VERSION_NUM < 501 || LUA_VERSION_NUM > 503 # error "unsupported Lua version (i.e. not Lua 5.1, 5.2, or 5.3)" #endif /* other Lua versions except 5.1, 5.2, and 5.3 */ /* helper macro for defining continuation functions (for every version * *except* Lua 5.2) */ #ifndef LUA_KFUNCTION #define LUA_KFUNCTION(_name) \ static int (_name)(lua_State *L, int status, lua_KContext ctx) #endif #if defined(COMPAT53_INCLUDE_SOURCE) # include "compat-5.3.c" #endif #endif /* COMPAT53_H_ */ lualdap-1.2.5/src/lualdap.c000066400000000000000000000716171341435545100155370ustar00rootroot00000000000000/* ** LuaLDAP ** See Copyright Notice in license.html ** $Id: lualdap.c,v 1.48 2007-12-14 15:11:22 carregal Exp $ */ #include #include #include #ifdef WIN32 #include #else #include #endif #ifdef WINLDAP #include "open2winldap.h" #else #include "ldap.h" #endif #include #include #include "compat-5.3.h" #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, int idx, const char *name) { lua_pushstring (L, name); lua_gettable (L, idx); } /* ** Get the field named name as a string. ** The table MUST be at position 2. */ 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)) 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, int idx, const char *name, int def) { strgettable (L, idx, 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, int idx, const char *name, double def) { strgettable (L, idx, 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, 2, 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_rawlen (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 = lua_rawlen (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 = lua_rawlen (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; } /* ** 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 ** #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; 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, get_timeout_param (L, 1, &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, ldap_err2string(err)); 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); 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; #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; } /* ** Bind to the directory. ** @param #1 LDAP connection. ** @param #2 String with username. ** @param #3 String with password. ** @return Boolean. */ static int lualdap_bind_simple (lua_State *L) { conn_data *conn = getconnection (L); ldap_pchar_t who = (ldap_pchar_t) luaL_checkstring (L, 2); const char *password = luaL_checkstring (L, 3); int err; #if defined(LDAP_API_FEATURE_X_OPENLDAP) && LDAP_API_FEATURE_X_OPENLDAP >= 20300 struct berval cred = { 0, NULL }; 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_simple_bind_s (conn->ld, who, password); #endif if (err != LDAP_SUCCESS) return faildirect (L, ldap_err2string (err)); lua_pushboolean (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_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); } /* ** 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; 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, get_timeout_param (L, 1, &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; } /* ** 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, 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); 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); lua_pushvalue(L, 2); return 2; } /* ** 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", (void*)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", (void*)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}, {"bind_simple", lualdap_bind_simple}, {"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_setfuncs(L, 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 (without binding). ** @param #1 String with URI. ** @return #1 Userdata with connection structure. */ static int lualdap_initialize (lua_State *L) { ldap_pchar_t uri = (ldap_pchar_t) luaL_checkstring (L, 1); conn_data *conn = (conn_data *)lua_newuserdata (L, sizeof(conn_data)); int err; int lev=7; /* Initialize */ lualdap_setmeta (L, LUALDAP_CONNECTION_METATABLE); conn->version = 0; err = ldap_initialize (&conn->ld, uri); if (err != LDAP_SUCCESS) return faildirect(L, ldap_err2string(err)); /* 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"); ldap_set_option(conn->ld, LDAP_OPT_DEBUG_LEVEL, &lev); return 1; } /* ** 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, ""); 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 = 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 if (strstr(host, "://") != NULL) { err = ldap_initialize(&conn->ld, host); } else { char *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; 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 */ #if defined(LDAP_API_FEATURE_X_OPENLDAP) && LDAP_API_FEATURE_X_OPENLDAP >= 20300 cred = ber_bvstrdup(password); err = ldap_sasl_bind_s (conn->ld, who, LDAP_SASL_SIMPLE, cred, NULL, NULL, NULL); ber_bvfree(cred); #else err = ldap_bind_s (conn->ld, who, password, LDAP_AUTH_SIMPLE); #endif 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, PACKAGE_STRING); lua_settable (L, -3); } /* ** Create ldap table and register the open method. */ int luaopen_lualdap (lua_State *L) { struct luaL_Reg lualdap[] = { {"initialize", lualdap_initialize}, {"open_simple", lualdap_open_simple}, {NULL, NULL}, }; lualdap_createmeta (L); luaL_newlib(L, lualdap); lua_pushvalue(L, -1); /* In Lua 5.2 "modules are not expected to set global variables": https://www.lua.org/manual/5.2/manual.html#8.2 */ #if LUA_VERSION_NUM < 502 lua_setglobal(L, LUALDAP_TABLENAME); #endif set_info (L); return 1; } lualdap-1.2.5/src/lualdap.def000066400000000000000000000001311341435545100160320ustar00rootroot00000000000000LIBRARY lualdap.dll DESCRIPTION "LuaLDAP" VERSION 1.2.5.0 EXPORTS luaopen_lualdap lualdap-1.2.5/src/open2winldap.h000066400000000000000000000031021341435545100165040ustar00rootroot00000000000000#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 lualdap-1.2.5/tests/000077500000000000000000000000001341435545100143105ustar00rootroot00000000000000lualdap-1.2.5/tests/run-tests.sh000077500000000000000000000041411341435545100166130ustar00rootroot00000000000000#!/bin/sh set -ex d=$(readlink -f "$(dirname $0)") password=thepassword rm -rf "$d/slapd-config" "$d/slapd-data" mkdir "$d/slapd-config" "$d/slapd-data" module_path='/usr/lib/ldap' test -d "$module_path" \ || module_path='/usr/lib/openldap' schema_path='/etc/ldap/schema' test -d "$schema_path" \ || module_path='/etc/openldap/schema' # populate slapd config slapadd -F "$d/slapd-config" -n0 < 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> {{{ }}} ############################################################################### lualdap-1.2.5/vc6/lualdap.rc000066400000000000000000000047141341435545100156220ustar00rootroot00000000000000//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 lualdap-1.2.5/vc6/lualdap_dll.dsp000066400000000000000000000123401341435545100166310ustar00rootroot00000000000000# 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 lualdap-1.2.5/vc6/resource.h000066400000000000000000000006141341435545100156450ustar00rootroot00000000000000//{{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