From owner-svn-ports-head@FreeBSD.ORG Thu Jan 17 23:44:13 2013 Return-Path: Delivered-To: svn-ports-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by hub.freebsd.org (Postfix) with ESMTP id 4A99D8D8; Thu, 17 Jan 2013 23:44:13 +0000 (UTC) (envelope-from mandree@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) by mx1.freebsd.org (Postfix) with ESMTP id 2AD5BDB4; Thu, 17 Jan 2013 23:44:13 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.5/8.14.5) with ESMTP id r0HNiD7Z050484; Thu, 17 Jan 2013 23:44:13 GMT (envelope-from mandree@svn.freebsd.org) Received: (from mandree@localhost) by svn.freebsd.org (8.14.5/8.14.5/Submit) id r0HNiCH0050478; Thu, 17 Jan 2013 23:44:12 GMT (envelope-from mandree@svn.freebsd.org) Message-Id: <201301172344.r0HNiCH0050478@svn.freebsd.org> From: Matthias Andree Date: Thu, 17 Jan 2013 23:44:12 +0000 (UTC) To: ports-committers@freebsd.org, svn-ports-all@freebsd.org, svn-ports-head@freebsd.org Subject: svn commit: r310576 - in head/net: . lualdap lualdap/files X-SVN-Group: ports-head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-ports-head@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the ports tree for head List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 17 Jan 2013 23:44:13 -0000 Author: mandree Date: Thu Jan 17 23:44:11 2013 New Revision: 310576 URL: http://svnweb.freebsd.org/changeset/ports/310576 Log: 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. WWW: http://www.keplerproject.org/lualdap/ PR: 172415 Submitted by: Piotr Florczyk Added: head/net/lualdap/ head/net/lualdap/Makefile (contents, props changed) head/net/lualdap/distinfo (contents, props changed) head/net/lualdap/files/ head/net/lualdap/files/patch-src__lualdap.c (contents, props changed) head/net/lualdap/pkg-descr (contents, props changed) head/net/lualdap/pkg-plist (contents, props changed) Modified: head/net/Makefile Modified: head/net/Makefile ============================================================================== --- head/net/Makefile Thu Jan 17 23:12:24 2013 (r310575) +++ head/net/Makefile Thu Jan 17 23:44:11 2013 (r310576) @@ -366,6 +366,7 @@ SUBDIR += lla SUBDIR += ltm SUBDIR += lua50-luasocket + SUBDIR += lualdap SUBDIR += luasocket SUBDIR += lvwimax SUBDIR += mDNSResponder Added: head/net/lualdap/Makefile ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/net/lualdap/Makefile Thu Jan 17 23:44:11 2013 (r310576) @@ -0,0 +1,36 @@ +# Created by: Piotr Florczyk +# $FreeBSD$ + +PORTNAME= lualdap +PORTVERSION= 1.1.0 +CATEGORIES= net +MASTER_SITES= http://files.luaforge.net/releases/${PORTNAME}/${PORTNAME}/LuaLDAP${PORTVERSION}/ +PKGNAMEPREFIX= ${LUA_PKGNAMEPREFIX} + +MAINTAINER= pf@itwf.pl +COMMENT= LDAP support for the Lua language + +USE_GMAKE= yes +USE_LUA= 5.1+ +USE_OPENLDAP= yes + +# the CPPFLAGS fixes builds where PREFIX != LOCALBASE +CPPFLAGS+= -I${LOCALBASE}/include/${LUA_SUBDIR} +MAKE_ARGS+= LUA_LIBDIR="${LUA_LIBDIR}" \ + LUA_INC="${LUA_INCDIR}" \ + OPENLDAP_LIB="-L${LOCALBASE}/lib -lldap" \ + LUA_VERSION_NUM="${LUA_VER_STR}0" + +ALL_TARGET= + +.include + +do-install: + ${MKDIR} ${LUA_MODLIBDIR} + ${INSTALL_PROGRAM} ${WRKSRC}/src/lualdap.so.${PORTVERSION} ${LUA_MODLIBDIR}/${PORTNAME}.so +.if ${PORT_OPTIONS:MDOCS} + @${MKDIR} ${DOCSDIR} + @${INSTALL_DATA} ${WRKSRC}/doc/us/* ${DOCSDIR} +.endif + +.include Added: head/net/lualdap/distinfo ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/net/lualdap/distinfo Thu Jan 17 23:44:11 2013 (r310576) @@ -0,0 +1,2 @@ +SHA256 (lualdap-1.1.0.tar.gz) = c2875704b8cdc6398c2f1cf25199a16d217ded2c696d134ae591935ab3c98d33 +SIZE (lualdap-1.1.0.tar.gz) = 30087 Added: head/net/lualdap/files/patch-src__lualdap.c ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/net/lualdap/files/patch-src__lualdap.c Thu Jan 17 23:44:11 2013 (r310576) @@ -0,0 +1,346 @@ +--- ./src/lualdap.c.orig 2007-12-14 16:11:22.000000000 +0100 ++++ ./src/lualdap.c 2013-01-18 00:29:50.000000000 +0100 +@@ -6,6 +6,7 @@ + + #include + #include ++#include + + #ifdef WIN32 + #include +@@ -19,10 +20,14 @@ + #include "ldap.h" + #endif + +-#include "lua.h" +-#include "lauxlib.h" +-#if ! defined (LUA_VERSION_NUM) || LUA_VERSION_NUM < 501 +-#include "compat-5.1.h" ++#include ++#include ++ ++#if LUA_VERSION_NUM < 502 ++/* lua_rawlen: Not entirely correct, but should work anyway */ ++# define lua_rawlen lua_objlen ++# define luaL_newlib(L,l) (lua_newtable(L), luaL_register(L,NULL,l)) ++# define luaL_setfuncs(L,l,n) (assert(n==0), luaL_register(L,NULL,l)) + #endif + + #ifdef WINLDAPAPI +@@ -141,9 +146,9 @@ + /* + ** Get the field called name of the table at position 2. + */ +-static void strgettable (lua_State *L, const char *name) { ++static void strgettable (lua_State *L, int idx, const char *name) { + lua_pushstring (L, name); +- lua_gettable (L, 2); ++ lua_gettable (L, idx); + } + + +@@ -151,8 +156,8 @@ + ** Get the field named name as a string. + ** The table MUST be at position 2. + */ +-static const char *strtabparam (lua_State *L, const char *name, char *def) { +- strgettable (L, name); ++static const char *strtabparam (lua_State *L, int idx, const char *name, char *def) { ++ strgettable (L, idx, name); + if (lua_isnil (L, -1)) + return def; + else if (lua_isstring (L, -1)) +@@ -168,8 +173,8 @@ + ** Get the field named name as an integer. + ** The table MUST be at position 2. + */ +-static long longtabparam (lua_State *L, const char *name, int def) { +- strgettable (L, name); ++static long longtabparam (lua_State *L, int idx, const char *name, int def) { ++ strgettable (L, idx, name); + if (lua_isnil (L, -1)) + return def; + else if (lua_isnumber (L, -1)) +@@ -183,8 +188,8 @@ + ** Get the field named name as a double. + ** The table MUST be at position 2. + */ +-static double numbertabparam (lua_State *L, const char *name, double def) { +- strgettable (L, name); ++static double numbertabparam (lua_State *L, int idx, const char *name, double def) { ++ strgettable (L, idx, name); + if (lua_isnil (L, -1)) + return def; + else if (lua_isnumber (L, -1)) +@@ -199,7 +204,7 @@ + ** The table MUST be at position 2. + */ + static int booltabparam (lua_State *L, const char *name, int def) { +- strgettable (L, name); ++ strgettable (L, 2, name); + if (lua_isnil (L, -1)) + return def; + else if (lua_isboolean (L, -1)) +@@ -243,7 +248,7 @@ + value_error (L, n); + return NULL; + } +- a->bvals[a->bi].bv_len = lua_strlen (L, -1); ++ a->bvals[a->bi].bv_len = lua_rawlen (L, -1); + a->bvals[a->bi].bv_val = (char *)lua_tostring (L, -1); + a->bi++; + return ret; +@@ -296,7 +301,7 @@ + A_setval (L, a, name); + else if (lua_istable (L, tab)) { /* list of strings */ + int i; +- int n = luaL_getn (L, tab); ++ int n = lua_rawlen (L, tab); + for (i = 1; i <= n; i++) { + lua_rawgeti (L, tab, i); /* push table element */ + A_setval (L, a, name); +@@ -368,7 +373,7 @@ + array[1] = NULL; + } else if (lua_istable (L, tab)) { + int i; +- int n = luaL_getn (L, tab); ++ int n = lua_rawlen (L, tab); + if (limit < (n+1)) + return luaL_error (L, LUALDAP_PREFIX"too many arguments"); + for (i = 0; i < n; i++) { +@@ -387,13 +392,25 @@ + + + /* ++** 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 = NULL; /* ??? function parameter ??? */ ++ struct timeval timeout; + LDAPMessage *res; + int rc; + conn_data *conn = (conn_data *)lua_touserdata (L, lua_upvalueindex (1)); +@@ -401,7 +418,7 @@ + /*int res_code = (int)lua_tonumber (L, lua_upvalueindex (3));*/ + + luaL_argcheck (L, conn->ld, 1, LUALDAP_PREFIX"LDAP connection is closed"); +- rc = ldap_result (conn->ld, msgid, LDAP_MSG_ONE, timeout, &res); ++ rc = ldap_result (conn->ld, msgid, LDAP_MSG_ONE, get_timeout_param (L, 1, &timeout), &res); + if (rc == 0) + return faildirect (L, LUALDAP_PREFIX"result timeout expired"); + else if (rc < 0) { +@@ -424,10 +441,14 @@ + default: + lua_pushnil (L); + lua_pushliteral (L, LUALDAP_PREFIX); +- lua_pushstring (L, msg); +- lua_pushliteral (L, " "); + lua_pushstring (L, ldap_err2string(err)); +- lua_concat (L, 4); ++ lua_concat (L, 2); ++ if (msg != NULL) { ++ lua_pushliteral (L, " ("); ++ lua_pushstring (L, msg); ++ lua_pushliteral (L, ")"); ++ lua_concat (L, 4); ++ } + ret = 2; + } + ldap_memfree (mdn); +@@ -461,7 +482,11 @@ + luaL_argcheck(L, conn!=NULL, 1, LUALDAP_PREFIX"LDAP connection expected"); + if (conn->ld == NULL) /* already closed */ + return 0; ++#if defined(LDAP_API_FEATURE_X_OPENLDAP) && LDAP_API_FEATURE_X_OPENLDAP >= 20300 ++ ldap_unbind_ext (conn->ld, NULL, NULL); ++#else + ldap_unbind (conn->ld); ++#endif + conn->ld = NULL; + lua_pushnumber (L, 1); + return 1; +@@ -504,7 +529,7 @@ + BerValue bvalue; + ldap_int_t rc, msgid; + bvalue.bv_val = (char *)luaL_checkstring (L, 4); +- bvalue.bv_len = lua_strlen (L, 4); ++ bvalue.bv_len = lua_rawlen (L, 4); + rc = ldap_compare_ext (conn->ld, dn, attr, &bvalue, NULL, NULL, &msgid); + return create_future (L, rc, 1, msgid, LDAP_RES_COMPARE); + } +@@ -666,15 +691,17 @@ + static int next_message (lua_State *L) { + search_data *search = getsearch (L); + conn_data *conn; +- struct timeval *timeout = NULL; /* ??? function parameter ??? */ ++ struct timeval timeout; + LDAPMessage *res; + int rc; + int ret; + ++ luaL_checktype(L, 1, LUA_TTABLE); ++ + lua_rawgeti (L, LUA_REGISTRYINDEX, search->conn); + conn = (conn_data *)lua_touserdata (L, -1); /* get connection */ + +- rc = ldap_result (conn->ld, search->msgid, LDAP_MSG_ONE, timeout, &res); ++ rc = ldap_result (conn->ld, search->msgid, LDAP_MSG_ONE, get_timeout_param (L, 1, &timeout), &res); + if (rc == 0) + return faildirect (L, LUALDAP_PREFIX"result timeout expired"); + else if (rc == -1) +@@ -724,8 +751,10 @@ + */ + static int string2scope (lua_State *L, const char *s) { + if ((s == NULL) || (*s == '\0')) +- return LDAP_SCOPE_DEFAULT; ++ return LDAP_SCOPE_SUBTREE; + switch (*s) { ++ case 'd': ++ return LDAP_SCOPE_DEFAULT; + case 'b': + return LDAP_SCOPE_BASE; + case 'o': +@@ -784,20 +813,6 @@ + + + /* +-** Fill in the struct timeval, according to the timeout parameter. +-*/ +-static struct timeval *get_timeout_param (lua_State *L, struct timeval *st) { +- double t = numbertabparam (L, "timeout", 0); +- st->tv_sec = (long)t; +- st->tv_usec = (long)(1000000 * (t - st->tv_sec)); +- if (st->tv_sec == 0 && st->tv_usec == 0) +- return NULL; +- else +- return st; +-} +- +- +-/* + ** Perform a search operation. + ** @return #1 Function to iterate over the result entries. + ** @return #2 nil. +@@ -818,11 +833,11 @@ + return 2; + /* get other parameters */ + attrsonly = booltabparam (L, "attrsonly", 0); +- base = (ldap_pchar_t) strtabparam (L, "base", NULL); +- filter = (ldap_pchar_t) strtabparam (L, "filter", NULL); +- scope = string2scope (L, strtabparam (L, "scope", NULL)); +- sizelimit = longtabparam (L, "sizelimit", LDAP_NO_LIMIT); +- timeout = get_timeout_param (L, &st); ++ base = (ldap_pchar_t) strtabparam (L, 2, "base", NULL); ++ filter = (ldap_pchar_t) strtabparam (L, 2, "filter", NULL); ++ scope = string2scope (L, strtabparam (L, 2, "scope", NULL)); ++ sizelimit = longtabparam (L, 2, "sizelimit", LDAP_NO_LIMIT); ++ timeout = get_timeout_param (L, 2, &st); + + rc = ldap_search_ext (conn->ld, base, scope, filter, attrs, attrsonly, + NULL, NULL, timeout, sizelimit, &msgid); +@@ -831,7 +846,8 @@ + + create_search (L, 1, msgid); + lua_pushcclosure (L, next_message, 1); +- return 1; ++ lua_pushvalue(L, 2); ++ return 2; + } + + +@@ -872,7 +888,7 @@ + ** Create a metatable. + */ + static int lualdap_createmeta (lua_State *L) { +- const luaL_reg methods[] = { ++ const luaL_Reg methods[] = { + {"close", lualdap_close}, + {"add", lualdap_add}, + {"compare", lualdap_compare}, +@@ -887,7 +903,7 @@ + return 0; + + /* define methods */ +- luaL_openlib (L, NULL, methods, 0); ++ luaL_setfuncs(L, methods, 0); + + /* define metamethods */ + lua_pushliteral (L, "__gc"); +@@ -939,13 +955,27 @@ + const char *password = luaL_optstring (L, 3, NULL); + int use_tls = lua_toboolean (L, 4); + conn_data *conn = (conn_data *)lua_newuserdata (L, sizeof(conn_data)); ++#if defined(LDAP_API_FEATURE_X_OPENLDAP) && LDAP_API_FEATURE_X_OPENLDAP >= 20300 ++ struct berval cred = { 0, NULL }; ++ char *host_with_schema = NULL; ++#endif + int err; + + /* Initialize */ + lualdap_setmeta (L, LUALDAP_CONNECTION_METATABLE); + conn->version = 0; ++#if defined(LDAP_API_FEATURE_X_OPENLDAP) && LDAP_API_FEATURE_X_OPENLDAP >= 20300 ++ host_with_schema = malloc(strlen(host) + 8); ++ strcpy(host_with_schema, "ldap://"); ++ strcat(host_with_schema, host); ++ err = ldap_initialize(&conn->ld, host_with_schema); ++ free(host_with_schema); ++ host_with_schema = NULL; ++ if (err != LDAP_SUCCESS) ++#else + conn->ld = ldap_init (host, LDAP_PORT); + if (conn->ld == NULL) ++#endif + return faildirect(L,LUALDAP_PREFIX"Error connecting to server"); + /* Set protocol version */ + conn->version = LDAP_VERSION3; +@@ -959,7 +989,16 @@ + return faildirect (L, ldap_err2string (rc)); + } + /* Bind to a server */ ++#if defined(LDAP_API_FEATURE_X_OPENLDAP) && LDAP_API_FEATURE_X_OPENLDAP >= 20300 ++ cred.bv_len = strlen(password); ++ cred.bv_val = malloc(cred.bv_len+1); ++ strcpy(cred.bv_val, password); ++ err = ldap_sasl_bind_s (conn->ld, who, LDAP_SASL_SIMPLE, &cred, NULL, NULL, NULL); ++ free(cred.bv_val); ++ memset(&cred, 0, sizeof(cred)); ++#else + err = ldap_bind_s (conn->ld, who, password, LDAP_AUTH_SIMPLE); ++#endif + if (err != LDAP_SUCCESS) + return faildirect (L, ldap_err2string (err)); + +@@ -987,13 +1026,15 @@ + ** Create ldap table and register the open method. + */ + int luaopen_lualdap (lua_State *L) { +- struct luaL_reg lualdap[] = { ++ struct luaL_Reg lualdap[] = { + {"open_simple", lualdap_open_simple}, + {NULL, NULL}, + }; + + lualdap_createmeta (L); +- luaL_openlib (L, LUALDAP_TABLENAME, lualdap, 0); ++ luaL_newlib(L, lualdap); ++ lua_pushvalue(L, -1); ++ lua_setglobal(L, LUALDAP_TABLENAME); + set_info (L); + + return 1; Added: head/net/lualdap/pkg-descr ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/net/lualdap/pkg-descr Thu Jan 17 23:44:11 2013 (r310576) @@ -0,0 +1,8 @@ +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. + +WWW: http://www.keplerproject.org/lualdap/ Added: head/net/lualdap/pkg-plist ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/net/lualdap/pkg-plist Thu Jan 17 23:44:11 2013 (r310576) @@ -0,0 +1,6 @@ +%%LUA_MODLIBDIR%%/lualdap.so +%%PORTDOCS%%%%DOCSDIR%%/index.html +%%PORTDOCS%%%%DOCSDIR%%/license.html +%%PORTDOCS%%%%DOCSDIR%%/lualdap.png +%%PORTDOCS%%%%DOCSDIR%%/manual.html +%%PORTDOCS%%@dirrm %%DOCSDIR%%