Now than we have built LDAP components, the aim is to use it in a xulapp with the standard XULRunner, which has not LDAP support enabled.

The first idea is to copy mozldap.dll and mozldap.xpt (which can be found in the components directory of your LDAP-enabled-xulrunner package) into the components directory of your xulapp. The native LDAP SDK dlls must also be copied. They can be found in the xulrunner root directory: nsldap32v50.dll and nsldappr32v50.dll.

The tests I have made show that the interfaces published by the component are read by xulrunner (example: nsILDAPConnection). You can see it by executing this js code:

if (Components.interfaces.nsILDAPConnection)
{
  jsdump("nsILDAPConnection available");
}

(I am using a simple jsdump function to log stuff in to the js console, as explained here: Debugging a XULRunner Application)

But the LDAP components can't be loaded. You can see it by executing this js code:

if (Components.classes["@mozilla.org/network/ldap-connection;1"])
{
  jsdump("ldap-connection available");
}

This means that the LDAP dlls can't be loaded. Actually, this is perfectly normal, since they are neither in the xulrunner.exe directory, nor in any directory of the system library path.

The solution is described here: Using Dependent Libraries In Extension Components.

As I did not want to have a stub dll named bsmedberg_stub :-) I changed the names. Here are the steps I followed:

Create a subdirectory extensions/ldapstub in the mozilla source code directory, containing two files, makefile.in and LDAPStubLoader.cpp. Those files are attached to this post.

Then change your .mozconfig to add this line:

ac_add_options --enable-extensions=ldapstub

Then, build xulrunner by running:

make -f client.mk build

at the root of your mozilla directory.

Repackage XULRunner by running:

make -C xpinstall/packager

and extract it somewhere.

Now, create a subdirectory named libraries in your xulapp directory.

  • in the components directory, copy the mozldap.xpt and ldapstub.dll, both found in the components directory of XULRunner.
  • in the libraries directory, copy the mozldap.dll, nsldap32v50.dll, and nsldappr32v50.dll files (mozldap.dll can be found in the components directory of XULRunner, while nsldap32v50.dll and nsldappr32v50.dll can be found directly in the XULRunner directory).

Delete your xulapp directory in your user profile, and restart your xulapp with xulrunner. The LDAP components should be available.