Home > Articles

Like this article? We recommend

UNIX Authentication Plug-in

Our sample plug-in is expected to perform the following tasks:

  • Accept a parameter in the form of a distinguished name that indicates the directory under which it should override the directory server authentication.

  • Perform a /etc/passwd-based authentication (in the same way as Telnet, for example).

With this in mind, it is very easy to identify the kind of plug-in we need. We need a preoperation plug-in to intercept the bind data, and then to change the bind mechanism for users authenticating with UNIX login names and passwords.

At this point, all we need to do is plan the development and go straight to the code.

To Plan the Creation of a Plug-in

  1. Before you start to write a plug-in, write a good makefile that, at a minimum, will perform the following tasks:

    • Compile the plug-in or compile the debug version of the plug-in (if any).

    • Install the plug-in in the directory server.

    • Uninstall the plug-in.

    • Clean up compilations of intermediate files.

    The following version of a makefile works with a GNU makefile and GNU Compiler Collection (GCC). I provide it for those who like to use GNU tools. Use alternative settings as suggested at the beginning of the makefile to use the Sun™ ONE studio compiler:

    # Makefile for compiling the UnixAuth plugin
    # Hint for compiling libraries with gcc on SPARC(actually on
    # every platform supporting PIC code):
    # gcc -fPIC -c *.c # generate PIC obj files
    # for SunONE Studio tools suite, which is the default on Solaris OE, use this vars:
    # CC=/opt/SUNWspro/bin/CC (check your install dir)
    # SOFLAGS=-G
    # LD=/opt/SUNWspro/bin/CC (check your install dir)
    # change the following props to reflect your installation / environment
    # (make sure LDAP cmd line utils are in PATH... :)
    LDAP_DMANAGER_DN="cn=Directory Manager"
    RM=rm -rf
    lib: $(SONAME).$(MAJOR).$(MINOR)
    $(CC) $(LDFLAGS) $< -o $(SONAME).$(MAJOR).$(MINOR)
    $(CC) -c $(CFLAGS) $< -o $@
    $(RM) *.o
    cleanall: clean
    $(RM) *.so.*
    ldapmodify -p $(LDAP_PORT) -h $(LDAP_HOST) -D $(LDAP_DMANAGER_DN) -w $(LDAP_DMANAGER_PASSWD) -f
    ´cat $(PLUGIN_INSTALL_LDIF) | grep "^dn"| sed "s/dn: //g"´

    As you can see, this makefile expects the Sun ONE Directory Server tool ldapmodify, libraries, and include files to be on the same box where you are developing. This is usually the case.

  2. In addition, before you create a plug-in, you must prepare the installation/uninstallation LDAP data interchange format (LDIF) file.

  3. From a directory server point of view, a plug-in is two things. It is an entry in the directory information tree (DIT) and a shared object (*.so) to load that contains the functions to execute. The latter part is just what you write, the plug-in code; the former part is an ordinary LDIF modification in the following form:

    dn: cn=unixauth,cn=plugins,cn=config
    changetype: add
    cn: unixauth
    objectclass: top
    objectclass: nsSlapdPlugin
    objectclass: extensibleObject
    nsslapd-pluginpath: /export/home/nico/devel/ids/unixauth_pg/ unixauth.so.1.0
    nsslapd-plugininitfunc: unixauth_preop_init
    nsslapd-plugintype: preoperation
    nsslapd-pluginarg0: 1
    nsslapd-pluginarg1: ou=unix,dc=iplanet,dc=italy,dc=sun,dc=com
    nsslapd-pluginenabled: on
    nsslapd-pluginid: Unix authentication plugin
    nsslapd-pluginversion: 1.0
    nsslapd-pluginvendor: Sun Microsystems Italy
    nsslapd-plugindescription: This plug-in performs standard Unix passwd authentication

    The preceding LDIF file adds a new entry in the cn=plugins,cn=config directory, which is where all plug-ins are registered. With a little trick in the makefile target uninstall, we perform the uninstallation of the plug-in without an uninstallation LDIF file.

    The following attributes are relevant in the LDIF installation file:

    • cn—The name of the plug-in.

    • nsslapd-pluginpath—The location of your plug-in library (in this case, it points to a subdirectory of my home directory).

    • nsslapd-plugininitfunc—Specifies which function in the plug-in library the directory server must use to initialize the plug-in.

    • nsslapd-pluginargX, where X=0,1,2,...—Your plug-in arguments. Use this attribute as your needs dictate. In our case, the first argument indicates whether the plug-in runs in debug mode and the second argument identifies where to perform the special authentication.

    The other attributes of the entry are pretty intuitive. Not included in the preceding list, the attributes nsslapd-depends-on-name or nsslapd-depends-on-type specifies plug-in names or plug-in types on which your plug-in depends. Refer to the product documentation for the details.

To Code a Preoperation Plug-in

Like many other types of plug-ins, a preoperation plug-in is essentially made up of the following pieces of code:

  • An initialization/registration function

  • An operation function (the function you specify to do the work)

  • Other helper routines for your own use

  1. Write an initialization function that is responsible for the following tasks, at a minimum:

    • Specifying server version compatibility.

    • Registering the operation it intends to handle and the related routine. Basically, tell the directory server that you want to hook a certain operation and provide the function it should call when this operation, for example a SEARCH or DELETE, takes place. The function also registers the plug-in description structure, which the server uses later to show plug-in information in the directory console.

    • Collecting arguments passed through the nsslapd-pluginargX attribute.

    • Returning a valid result code (for example, 0 if nothing goes wrong).

    Here are some relevant details of our specific registration function, unixauth_preop_init.

    1. Ensure that the registration function accepts a parameter called Slapi_PBlock, which is common for plug-in API functions, and ensure that it returns an error code to report registration result.

    2. The slapi_pblock_(set|get) functions are used to manipulate the Slapi_PBlock structure. An integer constant (for example, SLAPI_PLUGIN_VERSION) specifies the field of the structure you want to access. Don't forget that this structure is used by other functions, before and after your functions are called.

      To register our preoperation function, we set SLAPI_PLUGIN_PRE_BIND_FN with a pointer to the function passwd_bind_fn. There are similar constants to register pre and post operation for search, modify, and delete. Our authentication plug-in example needs to handle only binding operations.

    3. Use the registration of the information structure unixauthDesc to enable you to pass textual information you see when managing plug-ins through the directory server console.

    4. Before returning control to the directory server, read arguments passed to the plug-in (arg0 and arg1), using the slapi_pblock_get() API routines, and then store them for later use.

    We set this argument in the LDIF installation file. However, you can change it through the administration console, and even add other new arguments.

    The following is the operation function for the unixauth authentication plug-in:

     * ROUTINE: 	unixauth_preop_init
     * DESCR: 	plug-in initialization and registration routine. Called directly 
     *	   	by iDS at startup
     * PARAMS: 	pb=parameter block
     * RETURNS: 	0 if ok, -1 on error (as plug-in specs require...)
    int unixauth_preop_init(Slapi_PBlock *pb)
     int argc; 
     char **argv; /* args var */
     slapi_log_error( SLAPI_LOG_PLUGIN, "unixauth_preop_init", 
    "Registering plugin functions...\n" );
     * set plugin about info 
     if(slapi_pblock_set(pb, SLAPI_PLUGIN_PRE_BIND_FN, (void *)passwd_bind_fn) != 0)
     slapi_log_error( SLAPI_LOG_PLUGIN, "unixauth_preop_init", 
    "Error while registering plugin function\n" );
     return ERR;
     * specify server compatibility 
     if(slapi_pblock_set(pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_VERSION_03) == -1)
     slapi_log_error( SLAPI_LOG_PLUGIN, "unixauth_preop_init", 
    "Error while setting comp. version" );
     return ERR;
     * set plugin about info 
     if(slapi_pblock_set(pb, SLAPI_PLUGIN_DESCRIPTION, &unixauthDesc) == -1)
     slapi_log_error( SLAPI_LOG_PLUGIN, "unixauth_preop_init", 
    "Error while setting plugin info\n" );
     return ERR;
     * get plugin args 
     if(slapi_pblock_get(pb, SLAPI_PLUGIN_ARGC, &argc) != 0 ||
     slapi_pblock_get( pb, SLAPI_PLUGIN_ARGV, &argv ) != 0 )
     slapi_log_error( SLAPI_LOG_PLUGIN, "unixauth_preop_init", 
    "Error while getting plugin args\n" );
     return ERR;
     /* setup args */
     unix_dn_realm = argv[0];
     debug = atoi(argv[1]);
     slapi_log_error( SLAPI_LOG_PLUGIN, "unixauth_preop_init", "Args:\n" );
     slapi_log_error( SLAPI_LOG_PLUGIN, "unixauth_preop_init", "\tunix_dn_realm=%s\n",
     slapi_log_error( SLAPI_LOG_PLUGIN, "unixauth_preop_init", "\tdebug=%d\n",debug);
     slapi_log_error( SLAPI_LOG_PLUGIN, "unixauth_preop_init", "Registration...done!\n" );
     return OK; /* ok! */

    At this point, the directory server calls the passwd_bind_fn() function whenever a user binds. To manage binding through UNIX password authentication, we split the code into two functions, as follows:

    • passwd_bind_fn, which is responsible for collecting binding information (user name, password, and authentication method) and for doing mandatory actions.

    • authenticate_unix_user, which is responsible for the pure authentication. It does the dirty work, taking the user name/password pairs and checking the user in /etc/passwd and /etc/shadow.

    To completely take over the bind operation, passwd_bind_fn must cooperate with the directory server. This requires you to set some pointers in the Slapi_PBlock structure. In particular, set the bind DN and the authentication method (for example, the former is required by other operations for access control list [ACL] evaluation purposes). Some of the information to set is available from the Slapi_PBlock through slapi_pblock_get().

    After calling authenticate_unix_user, there is a simple switch that evaluates the authentication result code. Note that the slapi_send_ldap_result() is used to send results to the client. The slapi_send_ldap_result() function sends you the "No such object" or "Invalid credentials" messages when authentication goes wrong, either because of a bad user name or a bad password. You must use this function to send meaningful messages back to the client (for example the message "Unable to read /etc/passwd or /etc/shadow file").

    The authenticate_unix_user() function is pretty simple to understand if you have some UNIX programming experience.

    • The system call getspnam(3C) is used to read the shadow passwords from /etc/shadow. Note that to call this function and read the shadow file, you must have root privileges and, therefore, the directory server daemon must have root privileges.

    • The system function crypt(3C) is called to encode the clear text password entered by the user, before comparing it with the password stored in /etc/passwd.

  2. Write an operation function.

  3. The operation function contains the code that performs your logic and is the area where you must pay the most attention and devote your best effort. The following is an example operation function:

     * ROUTINE: 	passwd_bind_fn
     * DESCR: 	plug-in preoperation function 
     * PARAMS: 	pb=parameter block
     * RETURNS: 	0 if ok, -1 on error (as plug-in specs require...)
    int passwd_bind_fn(Slapi_PBlock *pb)
     char *bind_dn = NULL;
     struct berval *bind_cred = NULL;
     int bind_method;
     char username[MAX_USERNAME];
     char passwd[MAX_PASSWD];
     int res;
     char *p, *q;
     if(debug)slapi_log_error( SLAPI_LOG_PLUGIN, "passwd_bind_fn", "Entering...\n" );
    /* get bind data */
      slapi_pblock_get( pb, SLAPI_BIND_TARGET, &bind_dn ) != 0 ||
      slapi_pblock_get( pb, SLAPI_BIND_CREDENTIALS, &bind_cred ) != 0 ||
      slapi_pblock_get( pb, SLAPI_BIND_METHOD, &bind_method ) != 0 )
     if(debug)slapi_log_error( SLAPI_LOG_PLUGIN, "passwd_bind_fn", "Error occurred on slapi_pblock_get...\n" );
     slapi_send_ldap_result(pb, LDAP_OPERATIONS_ERROR,NULL, "Internal error", 0, NULL); 
     return ERR; 
     * Let the server handle SASL
     if (bind_method == LDAP_AUTH_SASL)
    	return 0;
     * plugin mandatory actions
     if(slapi_pblock_set( pb, SLAPI_CONN_DN, slapi_ch_strdup(bind_dn) ) != 0 ||
     slapi_pblock_set( pb, SLAPI_CONN_AUTHMETHOD, SLAPD_AUTH_SIMPLE ) != 0)
     if(debug)slapi_log_error( SLAPI_LOG_PLUGIN, "passwd_bind_fn", "Error occurred 
    on  slapi_pblock_set...\n" ); slapi_send_ldap_result(pb, LDAP_OPERATIONS_ERROR,NULL,
     "Internal error", 0, NULL); 
     return ERR;
     if(debug) /* debug stuff :) */
     slapi_log_error( SLAPI_LOG_PLUGIN, "passwd_bind_fn", "Bind DN: %s\n", bind_dn);
     slapi_log_error( SLAPI_LOG_PLUGIN, "passwd_bind_fn", "Bind cred(ln): %d\n",bind_cred->bv_len);
     slapi_log_error( SLAPI_LOG_PLUGIN, "passwd_bind_fn", "Bind cred(pw): %s\n",bind_cred->bv_val); 
     slapi_log_error( SLAPI_LOG_PLUGIN, "passwd_bind_fn", "Bind method: %d\n", bind_method);
     * performs Unix authentication if the bind DN
     * is under the unix_dn_realm
     if(!slapi_dn_issuffix(slapi_dn_normalize_case(bind_dn), unix_dn_realm))
     if(debug)slapi_log_error( SLAPI_LOG_PLUGIN, "passwd_bind_fn", "Not in Unix realm, go on...\n" );
      * Performs standard directory authentication 
      res = do_standard_authentication(bind_dn, bind_cred,bind_method);
      slapi_send_ldap_result(pb, res,NULL, NULL, 0, NULL); 
      return 1;
    /* extracts username part of uid=nick,ou=.... */
     p = bind_dn + 4; 	/* skip "uid=": we suppose an inetOrgPerson entry, of coarse ;) */
     q = &username[0];
     while(',' != *p)*q++=*p++;
     res = authenticate_unix_user(username, bind_cred->bv_val); 
      if(debug)slapi_log_error( SLAPI_LOG_PLUGIN, "passwd_bind_fn", "Error in 
      authenticate_unix_user\n" );
      slapi_send_ldap_result(pb, LDAP_OPERATIONS_ERROR,NULL, "Internal error", 0, NULL); 
      return ERR;
      if(debug)slapi_log_error( SLAPI_LOG_PLUGIN, "passwd_bind_fn", "User not found in /etc/passwd.\n" );
    slapi_send_ldap_result(pb, LDAP_NO_SUCH_OBJECT,NULL, "User not found in /etc/passwd", 0, NULL); 
      return ERR;
      if(debug)slapi_log_error( SLAPI_LOG_PLUGIN, "passwd_bind_fn", "Wrong credentials\n" );
      slapi_send_ldap_result(pb, LDAP_INVALID_CREDENTIALS,NULL, "Wrong credentials", 0, NULL); 
      return ERR; 
     assert(res == UNIXAUTH_AUTHENTICATED);
     /* sends back auth result */
     slapi_send_ldap_result(pb, LDAP_SUCCESS,NULL, "Unix user authenticated ", 0, NULL); 
     if(debug)slapi_log_error( SLAPI_LOG_PLUGIN, "passwd_bind_fn", " User authenticated\n" );
     return 1; /* ok! must be >0 in any case */

InformIT Promotional Mailings & Special Offers

I would like to receive exclusive offers and hear about products from InformIT and its family of brands. I can unsubscribe at any time.


Pearson Education, Inc., 221 River Street, Hoboken, New Jersey 07030, (Pearson) presents this site to provide information about products and services that can be purchased through this site.

This privacy notice provides an overview of our commitment to privacy and describes how we collect, protect, use and share personal information collected through this site. Please note that other Pearson websites and online products and services have their own separate privacy policies.

Collection and Use of Information

To conduct business and deliver products and services, Pearson collects and uses personal information in several ways in connection with this site, including:

Questions and Inquiries

For inquiries and questions, we collect the inquiry or question, together with name, contact details (email address, phone number and mailing address) and any other additional information voluntarily submitted to us through a Contact Us form or an email. We use this information to address the inquiry and respond to the question.

Online Store

For orders and purchases placed through our online store on this site, we collect order details, name, institution name and address (if applicable), email address, phone number, shipping and billing addresses, credit/debit card information, shipping options and any instructions. We use this information to complete transactions, fulfill orders, communicate with individuals placing orders or visiting the online store, and for related purposes.


Pearson may offer opportunities to provide feedback or participate in surveys, including surveys evaluating Pearson products, services or sites. Participation is voluntary. Pearson collects information requested in the survey questions and uses the information to evaluate, support, maintain and improve products, services or sites, develop new products and services, conduct educational research and for other purposes specified in the survey.

Contests and Drawings

Occasionally, we may sponsor a contest or drawing. Participation is optional. Pearson collects name, contact information and other information specified on the entry form for the contest or drawing to conduct the contest or drawing. Pearson may collect additional personal information from the winners of a contest or drawing in order to award the prize and for tax reporting purposes, as required by law.


If you have elected to receive email newsletters or promotional mailings and special offers but want to unsubscribe, simply email information@informit.com.

Service Announcements

On rare occasions it is necessary to send out a strictly service related announcement. For instance, if our service is temporarily suspended for maintenance we might send users an email. Generally, users may not opt-out of these communications, though they can deactivate their account information. However, these communications are not promotional in nature.

Customer Service

We communicate with users on a regular basis to provide requested services and in regard to issues relating to their account we reply via email or phone in accordance with the users' wishes when a user submits their information through our Contact Us form.

Other Collection and Use of Information

Application and System Logs

Pearson automatically collects log data to help ensure the delivery, availability and security of this site. Log data may include technical information about how a user or visitor connected to this site, such as browser type, type of computer/device, operating system, internet service provider and IP address. We use this information for support purposes and to monitor the health of the site, identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents and appropriately scale computing resources.

Web Analytics

Pearson may use third party web trend analytical services, including Google Analytics, to collect visitor information, such as IP addresses, browser types, referring pages, pages visited and time spent on a particular site. While these analytical services collect and report information on an anonymous basis, they may use cookies to gather web trend information. The information gathered may enable Pearson (but not the third party web trend services) to link information with application and system log data. Pearson uses this information for system administration and to identify problems, improve service, detect unauthorized access and fraudulent activity, prevent and respond to security incidents, appropriately scale computing resources and otherwise support and deliver this site and its services.

Cookies and Related Technologies

This site uses cookies and similar technologies to personalize content, measure traffic patterns, control security, track use and access of information on this site, and provide interest-based messages and advertising. Users can manage and block the use of cookies through their browser. Disabling or blocking certain cookies may limit the functionality of this site.

Do Not Track

This site currently does not respond to Do Not Track signals.


Pearson uses appropriate physical, administrative and technical security measures to protect personal information from unauthorized access, use and disclosure.


This site is not directed to children under the age of 13.


Pearson may send or direct marketing communications to users, provided that

  • Pearson will not use personal information collected or processed as a K-12 school service provider for the purpose of directed or targeted advertising.
  • Such marketing is consistent with applicable law and Pearson's legal obligations.
  • Pearson will not knowingly direct or send marketing communications to an individual who has expressed a preference not to receive marketing.
  • Where required by applicable law, express or implied consent to marketing exists and has not been withdrawn.

Pearson may provide personal information to a third party service provider on a restricted basis to provide marketing solely on behalf of Pearson or an affiliate or customer for whom Pearson is a service provider. Marketing preferences may be changed at any time.

Correcting/Updating Personal Information

If a user's personally identifiable information changes (such as your postal address or email address), we provide a way to correct or update that user's personal data provided to us. This can be done on the Account page. If a user no longer desires our service and desires to delete his or her account, please contact us at customer-service@informit.com and we will process the deletion of a user's account.


Users can always make an informed choice as to whether they should proceed with certain services offered by InformIT. If you choose to remove yourself from our mailing list(s) simply visit the following page and uncheck any communication you no longer want to receive: www.informit.com/u.aspx.

Sale of Personal Information

Pearson does not rent or sell personal information in exchange for any payment of money.

While Pearson does not sell personal information, as defined in Nevada law, Nevada residents may email a request for no sale of their personal information to NevadaDesignatedRequest@pearson.com.

Supplemental Privacy Statement for California Residents

California residents should read our Supplemental privacy statement for California residents in conjunction with this Privacy Notice. The Supplemental privacy statement for California residents explains Pearson's commitment to comply with California law and applies to personal information of California residents collected in connection with this site and the Services.

Sharing and Disclosure

Pearson may disclose personal information, as follows:

  • As required by law.
  • With the consent of the individual (or their parent, if the individual is a minor)
  • In response to a subpoena, court order or legal process, to the extent permitted or required by law
  • To protect the security and safety of individuals, data, assets and systems, consistent with applicable law
  • In connection the sale, joint venture or other transfer of some or all of its company or assets, subject to the provisions of this Privacy Notice
  • To investigate or address actual or suspected fraud or other illegal activities
  • To exercise its legal rights, including enforcement of the Terms of Use for this site or another contract
  • To affiliated Pearson companies and other companies and organizations who perform work for Pearson and are obligated to protect the privacy of personal information consistent with this Privacy Notice
  • To a school, organization, company or government agency, where Pearson collects or processes the personal information in a school setting or on behalf of such organization, company or government agency.


This web site contains links to other sites. Please be aware that we are not responsible for the privacy practices of such other sites. We encourage our users to be aware when they leave our site and to read the privacy statements of each and every web site that collects Personal Information. This privacy statement applies solely to information collected by this web site.

Requests and Contact

Please contact us about this Privacy Notice or if you have any requests or questions relating to the privacy of your personal information.

Changes to this Privacy Notice

We may revise this Privacy Notice through an updated posting. We will identify the effective date of the revision in the posting. Often, updates are made to provide greater clarity or to comply with changes in regulatory requirements. If the updates involve material changes to the collection, protection, use or disclosure of Personal Information, Pearson will provide notice of the change through a conspicuous notice on this site or other appropriate way. Continued use of the site after the effective date of a posted revision evidences acceptance. Please contact us if you have questions or concerns about the Privacy Notice or any objection to any revisions.

Last Update: November 17, 2020