Scroll to navigation

MUTT_LDAP_QUERY(1) User Contributed Perl Documentation MUTT_LDAP_QUERY(1)

NAME

mutt_ldap_query - Query LDAP server for Mutt mail-reader

SYNOPSIS

mutt_ldap_query.pl [options] <name_to_query> [[<other_name_to_query>] ...]

OPTIONS

specify an alternate resource file other than the system ones (/etc/lbdb_ldap.rc or /etc/mutt_ldap_query.rc) or default personal ones ($HOME/.lbdb/ldap.rc or $HOME/.mutt_ldap_query.rc).
hostname of your ldap server. You can also use an ldap://foo[:port] or ldaps://foo[:port] URL here to talk to different ports or SSL encrypted servers. Or use ldapi://%2fvar%2flib%2fldap_sock to access an ldap server via a socket (use %2f as as replacement for a slash in the file name).
use <search_base> as the starting point for the search instead of the default.
list of the fields on which the query will be performed.
list of the fields expected as the answer of the ldap server that will be used for composing the output of the script.
format to be used for composing the email output result. It has to be based on the expected ldap server answers and can use variable containers of the form ${variable} where variable belongs to the <ldap_expected_answers> set.
format to be used for composing the realname output result. It has to be based on the expected ldap server answers and can use variable containers of the form ${variable} where variable belongs to the <ldap_expected_answers> set.
format to be used for composing the comment output result. It has to be based on the expected ldap server answers and can use variable containers of the form ${variable} where variable belongs to the <ldap_expected_answers> set.
the destinguished name of the user who binds to the LDAP server. Leave it empty for an anonmyous bind.
the bind password for binding to the LDAP server. Leave it empty for an anonmyous bind.
enable or disable transport layer security (TLS).
the SASL mechanism, for example GSSAPI (empty string to turn off).
shortcut for avoiding to use all the previous options by using the script builtin or alternate config file table of common servers and associated options. All the required parameters are then derived by performing a <lbdb_server_nickname> lookup.
turn on debugging messages.
generates this help message.
ignorant mode: search using wildcard for *name_to_query* (requires a longer processing from LDAP server but is quite convenient :).
suppress number of matches output (suited for interfacing with little brother database https://www.spinnaker.de/lbdb/)
show the version.

DESCRIPTION

mutt_ldap_query performs ldap queries using either ldapsearch command or the perl-ldap module and it outputs the required formatted data for feeding mutt when using its "External Address Query" feature.

The output of the script consists in 3 fields separated with tabs: the email address, the name of the person and a comment.

INTERFACING WITH MUTT

This perl script can be interfaced with mutt by defining in your .muttrc:

    set query_command = "mutt_ldap_query.pl %s"

Multiple requests are supported: the "Q" command of mutt accepts as argument a list of queries (e.g. "Gosse de\ Courville").

Alternatively mutt_ldap_query can be interfaced with the more generic little brother database query program (https://www.spinnaker.de/lbdb/) using:

    set query_command = "lbdbq %s"

and by specifying in your ~/.lbdb/lbdbrc file another method of query just adding to the METHODS variable the m_ldap module e.g.:

    METHODS='m_inmail m_passwd m_ldap m_muttalias m_finger'

and the right path to access m_ldap in MODULES_PATH, e.g. if you moved m_ldap in ~/.lbdb/modules:

    MODULES_PATH="/usr/local/lib $HOME/.lbdb/modules"

Just make sure to use the correct path for calling mutt_ldap_query in the m_ldap script.

RESOURCE FILE FORMAT

mutt_ldap_query is now fully customizable using an external resource file. By default mutt_ldap_query parses the system definition file located generally at /etc/mutt_ldap_query.rc or /usr/local/etc/mutt_ldap_query.rc and also the user one: $HOME/.mutt_ldap_query.rc.

Instead of using command line options, the user can redefine all the variables using the resource file by two manners in order to match his site configuration. A file example is provided below:

    # The format of each entry of the ldap server database is the following:
    # LDAP_NICKNAME => ['LDAP_SERVER', 
    #                   'LDAP_SEARCH_BASE',
    #                   'LDAP_SEARCH_FIELDS',
    #                   'LDAP_EXPECTED_ANSWERS',
    #                   'LDAP_RESULT_EMAIL',
    #                   'LDAP_RESULT_REALNAME',
    #                   'LDAP_RESULT_COMMENT'],
    # a practical illustrating example being:
    #  debian   => ['db.debian.org',
    #               'ou=users,dc=debian,dc=org',
    #               'uid cn sn ircnick',
    #               'uid cn sn ircnick',
    #               '${uid}@debian.org',
    #               '${cn} ${sn}',
    #               '${ircnick}'],
    # the output of the query will be then: 
    # ${uid}@debian.org\t${cn} ${sn}\t${ircnick} (i.e.: email name comment)
    # warning this database will erase default script builtin
    %ldap_server_db = (
      'four11'          => ['ldap.four11.com',
                            'c=US',
                            'givenname sn cn mail',
                            'givenname cn sn mail o',
                            '${mail}',
                            '${givenname} ${sn}',
                            '${o}' ],
      'infospace'       => ['ldap.infospace.com',
                            'c=US',
                            'givenname sn cn mail',
                            'givenname cn sn mail o',
                            '${mail}',
                            '${givenname} ${sn}',
                            '${o}' ],
      'whowhere'        => ['ldap.whowhere.com',
                            'c=US',
                            'givenname sn cn mail',
                            'givenname cn sn mail o',
                            '${mail}',
                            '${givenname} ${sn}',
                            '${o}' ],
      'bigfoot'         => ['ldap.bigfoot.com',
                            'c=US',
                            'givenname sn cn mail'
                           , 'givenname cn sn mail o'
                           , '${mail}'
                           , '${givenname} ${sn}',
                            '${o}' ],
      'switchboard'     => ['ldap.switchboard.com',
                            'c=US',
                            'givenname sn cn mail'
                           , 'givenname cn sn mail o',
                            '${mail}',
                            '${givenname} ${sn}',
                            '${o}' ],
      'infospacebiz'    => ['ldapbiz.infospace.com',
                            'c=US',
                            'givenname sn cn mail',
                            'givenname cn sn mail o',
                            '${mail}',
                            '${givenname} ${sn}',
                            '${o}' ],
    );
    # hostname of your ldap server
    $ldap_server = 'ldap.four11.com';
    # ldap base search
    $search_base = 'c=US';
    # list of the fields that will be used for the query
    $ldap_search_fields = 'givenname sn cn mail';
    # list of the fields that will be used for composing the answer
    $ldap_expected_answers = 'givenname sn cn mail o';
    # format of the email result based on the expected answers of the ldap query
    $ldap_result_email = '${mail}';
    # format of the realname result based on the expected answers of the ldap query
    $ldap_result_realname = '${givenname} ${sn}';
    # format of the comment result based on the expected answers of the ldap query
    $ldap_result_comment = '(${o})';

EXAMPLES OF QUERIES

    mutt_ldap_query.pl --ldap_server='ldap.mot.com' \
       --search_base='ou=employees, o=Motorola,c=US' \
       --ldap_search_fields='commonName gn sn cn uid' \
       --ldap_expected_answers='gn sn preferredRfc822Recipient ou c telephonenumber' \
       --ldap_result_email='${preferredRfc822Recipient}' \
       --ldap_result_realname='${gn} ${sn}' \
       --ldap_result_comment='(${telephonenumber}) ${ou} ${c}' \
       Gosse de\ Courville

performs a query using the ldap server ldap.mot.com using the following searching base 'ou=employees, o=Motorola,c=US' and performing a search on the fields 'commonName gn sn cn uid' for 'Gosse' and then "de Courville" looking for the following answers 'gn sn preferredRfc822Recipient ou c telephonenumber'. Based on this answers, mutt_ldap_query will return a list of entries identified of the form:

  <${preferredRfc822Recipient}>\t${gn} ${sn}\t(${telephonenumber}) ${ou} ${c}

where ${} variables should be considered as containers that are replaced by the results of the query. The previous query can be greatly simplified by using the ldap server mini database feature of the resource file introducing for example a nickname.

    mutt_ldap_query.pl --ldap_server_nickname='motorola' Gosse de\ Courville

When not sure of the full name (i.e. it should contain Courville) the ignorant mode is useful since the query will be performed using wildcards, i.e. *Courville* in the following case:

    mutt_ldap_query.pl --ignorant Courville

WHERE TO GET IT

The latest version can be retrieved at
ftp://ftp.mutt.org/pub/mutt/contrib or
http://www.courville.org/

Note that now the script is integrated in the latest version of the little brother database available at https://www.spinnaker.de/lbdb/. It is thus easier to use through this standard package than to hand customize it to fit your system/distribution needs.

REFERENCES

AUTHORS

Marc de Courville <marc@courville.org> and the various other contributors... that kindly sent their patches.

Please report any bugs, or post any suggestions, to <marc@courville.org>.

COPYRIGHT

Copyright (c) 1998-2003 Marc de Courville <marc@courville.org>. All rights reserved. This program is free software; you can redistribute it and/or modify it under the GNU General Public License (GPL). See http://www.opensource.org/gpl-license.html and http://www.opensource.org/.

2022-02-25 perl v5.34.0