Notes about the Lua/APR binding

APR documentation

The online API documentation for APR has been my most useful resource while working on the Lua/APR binding but it leaves something to be desired when you're looking for a high level overview. The following online resources help in this regard:

Building APR on Windows

Building APR on Windows can be a pain in the ass. It is meant to be done with Microsoft tools but fortunately these are freely available. Here are some notes I made in the process:

  1. Install Microsoft Visual C++ Express. You only need the command line tools, the GUI isn’t needed.

  2. Install the Microsoft Platform SDK. The full SDK is over 1 GB but you only need the following:

  3. Download the APR, APR-util and APR-iconv archives (I used apr-1.4.2-win32-src.zip, apr-util-1.3.9-win32-src.zip and apr-iconv-1.2.1-win32-src-r2.zip) from apr.apache.org. Unpack all archives to the same directory and rename the subdirectories to apr, apr-util and apr-iconv.

  4. The instructions about building APR on Windows don’t work for me so this is where things get sketchy: Open a Windows SDK command prompt and navigate to the apr-util directory. Inside this directory execute nmake -f Makefile.win buildall. This doesn’t work for me out of the box because of what’s probably a bug in the APR-util makefile; I needed to replace apr_app with aprapp on lines 176 and 177 of Makefile.win. After this change nmake still exits with errors but nevertheless seems to build libapr-1.dll and libaprutil-1.dll

Building the SQlite3 database driver on Windows

The SQLite 3 driver is included in the Windows binaries but for the benefit of those who want to build the Apache Portable Runtime on Windows here are the steps involved:

  1. Download the precompiled SQLite 3 binaries For Windows (273.98 KiB) and unpack the files somewhere

  2. Create sqlite3.lib from sqlite3.def (included in the precompiled binaries) using the command lib /machine:i386 /def:sqlite3.def and copy sqlite3.lib to apr-util-1.3.9/LibR

  3. Download the corresponding source code distribution (1.20 MiB) and copy sqlite3.h to apr-util-1.3.9/include

  4. Build the driver in the Windows SDK command prompt using the command nmake /f apr_dbd_sqlite3.mak

  5. To install the driver you can copy sqlite3.dll and apr_dbd_sqlite3-1.dll to Lua’s installation directory

Building libapreq2 on Windows

I wasted a few hours getting libapreq2 version 2.13 to build on Windows because of the following issues:

Eventually I decided to just rewrite the damned makefile and be done with it, enabling me to finally test the HTTP request parsing module on Windows (all tests passed the first time). I've included the customized makefile in the Lua/APR git repository.

Setting up a basic LDAP server on Ubuntu

The following instructions are based on the Ubuntu server guide and my experiments on an Ubuntu Lucid (10.04) installation.

Start by executing the following commands in a terminal:

sudo apt-get install slapd ldap-utils
sudo ldapadd -Y EXTERNAL -H ldapi:/// -/etc/ldap/schema/cosine.ldif
sudo ldapadd -Y EXTERNAL -H ldapi:/// -/etc/ldap/schema/nis.ldif
sudo ldapadd -Y EXTERNAL -H ldapi:/// -/etc/ldap/schema/inetorgperson.ldif

Create the file ~/backend.localhost.localdomain.ldif with the following contents:

# Load dynamic backend modules
dn: cn=module,cn=config
objectClass: olcModuleList
cn: module
olcModulepath: /usr/lib/ldap
olcModuleload: back_hdb

# Database settings
dn: olcDatabase=hdb,cn=config
objectClass: olcDatabaseConfig
objectClass: olcHdbConfig
olcDatabase: {1}hdb
olcSuffix: dc=localhost,dc=localdomain
olcDbDirectory: /var/lib/ldap
olcRootDN: cn=admin,dc=localhost,dc=localdomain
olcRootPW: fFUzJHoQMm
olcDbConfig: set_cachesize 0 2097152 0
olcDbConfig: set_lk_max_objects 1500
olcDbConfig: set_lk_max_locks 1500
olcDbConfig: set_lk_max_lockers 1500
olcDbIndex: objectClass eq
olcLastMod: TRUE
olcDbCheckpoint: 512 30
olcAccess: to attrs=userPassword by dn="cn=admin,dc=localhost,dc=localdomain" write by anonymous auth by self write by * none
olcAccess: to attrs=shadowLastChange by self write by * read
olcAccess: to dn.base="" by * read
olcAccess: to * by dn="cn=admin,dc=localhost,dc=localdomain" write by * read

Load the file by executing the command:

sudo ldapadd -Y EXTERNAL -H ldapi:/// -f ~/backend.localhost.localdomain.ldif

Create the file ~/frontend.localhost.localdomain.ldif with the following contents:

# Create the top-level object in the domain.
dn: dc=localhost,dc=localdomain
objectClass: dcObject
objectclass: organization
o: Home LDAP server
dc: localhost

# Create the "admin" user.
dn: cn=admin,dc=localhost,dc=localdomain
objectclass: organizationalRole
cn: admin

# Create the "users" group.
dn: ou=users,dc=localhost,dc=localdomain
ou: users
objectClass: top
objectClass: organizationalUnit

# Create the "addressbook" group.
dn: ou=addressbook,dc=localhost,dc=localdomain
ou: addressbook
objectClass: top
objectClass: organizationalUnit

If you're wondering which fields you can use see this page. Now load the file by executing the command:

ldapadd --D cn=admin,dc=localhost,dc=localdomain -w fFUzJHoQMm -f ~/frontend.localhost.localdomain.ldif

Change the password in the above command and execute the command. You should now be able to search your LDAP server using the following command:

ldapsearch -xLLL -b dc=localhost,dc=localdomain

:%s/^dn: cn=\([^,]\+\).*/dn: cn=\1,ou=addressbook,dc=localhost,dc=localdomain/
:g/^modifytimestamp\|birth/d
Entry voor RenĂ© Mulder en Huismeesters gestript

Unsorted but useful LDAP references