Your Search Results

    Using LDAP XPCOM with XULRunner

    By default, XULRunner is built without LDAP XPCOM support. If you want to use LDAP components in your XUL application, you have two options : compile XULRunner with LDAP support enabled, or add LDAP XPCOM directly to your XUL app (in the components directory).

    In any case, you will have to build LDAP XPCOM, by adding --enable-ldap build option. See the Build_Documentation for more information about how to build XULRunner. When Configuring Build Options, just add:

    ac_add_options --enable-ldap

    to your .mozconfig file.

    This will create two files in the components directory of the build package:

    • mozldap.dll (or or...)
    • mozldap.xpt

    and two files in the root directory of the build package: On windows:

    • nsldap32v50.dll
    • nsldappr32v50.dll

    On linux:


    Those are the native LDAP library.

    If you copy as usual those files in the components directory of your XUL app, this can't work. Actually, the LDAP interfaces are available (for exemple, Components.interfaces.nsILDAPConnection is not null), but the components can't be loaded (for example, Components.classes[";1"] is null). This is due to the fact that the native LDAP library files are not found by the XULRunner process.

    The solution is to use the bsmedberg stub, described in Using Dependent Libraries In Extension Components: the component library is just a loader of the real library and all its dependencies, so as all the needed libraries are loaded.

    Create a subdirectory extensions/ldapstub in the mozilla source code directory, containing two files, and LDAPStubLoader.cpp:

    # Copyright (c) 2005 Benjamin Smedberg <>
    DEPTH = ../..
    srcdir = @srcdir@
    topsrcdir = @top_srcdir@
    VPATH = @srcdir@
    include $(DEPTH)/config/
    MODULE = mozldapstub
    LIBRARY_NAME = mozldap_stub
    REQUIRES = \
    	xpcom \
    	string \
    CPPSRCS = LDAPStubLoader.cpp
    	$(DIST)/lib/$(LIB_PREFIX)xpcomglue_s.$(LIB_SUFFIX) \
            $(NSPR_LIBS) \
    include $(topsrcdir)/config/


    // Copyright (c) 2005 Benjamin Smedberg <>
    #include "nscore.h"
    #include "nsModule.h"
    #include "prlink.h"
    #include "nsILocalFile.h"
    #include "nsStringAPI.h"
    #include "nsCOMPtr.h"
    static char const *const kDependentLibraries[] =
    #ifdef NS_WIN32
      MOZ_DLL_PREFIX "nsldap32v50" MOZ_DLL_SUFFIX,
      MOZ_DLL_PREFIX "nsldappr32v50" MOZ_DLL_SUFFIX,
    #endif //NS_WIN32
    #ifdef NS_UNIX
    #endif //NS_UNIX
    // component.dll on windows, libcomponent.dll on linux
    static char kRealComponent[] = MOZ_DLL_PREFIX "mozldap" MOZ_DLL_SUFFIX;
    NSGetModule(nsIComponentManager* aCompMgr,
                nsIFile* aLocation,
                nsIModule* *aResult)
      nsresult rv;
      nsCOMPtr<nsIFile> libraries;
      rv = aLocation->GetParent(getter_AddRefs(libraries));
      if (NS_FAILED(rv))
        return rv;
      nsCOMPtr<nsILocalFile> library(do_QueryInterface(libraries));
      if (!library)
        return NS_ERROR_UNEXPECTED;
      // loop through and load dependent libraries
      for (char const *const *dependent = kDependentLibraries;
           ++dependent) {
        PRLibrary *lib;
        // 1) We don't care if this failed!
        // 2) We are going to leak this library. We don't care about that either.
      PRLibrary *lib;
      rv = library->Load(&lib);
      if (NS_FAILED(rv))
        return rv;
      nsGetModuleProc getmoduleproc = (nsGetModuleProc)
        PR_FindFunctionSymbol(lib, NS_GET_MODULE_SYMBOL);
      if (!getmoduleproc)
        return NS_ERROR_FAILURE;
      return getmoduleproc(aCompMgr, aLocation, aResult);

    Then change your .mozconfig to add this line:

    ac_add_options --enable-extensions=ldapstub

    Rebuild XULRunner. This will create a new file in the components subdirectory of the built package, mozldap_stub.dll (on Windows) or (on Linux).

    Copy mozldap.xpt and mozldap_stub.dll into your components XUL app subdirectory. Create a libraries subdirectory in your XUL app directory, and copy mozldap.dll (or, and the native LDAP binaries into it.

    Don't forget to clean your profile.

    You can now use the LDAP components.

    Document Tags and Contributors

    Contributors to this page: Sheppy, fscholz, ethertank, Mgjbot, Andreas Wuest, Francoisberetti
    Last updated by: fscholz,