The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Config::Parser::ldap - configuration file parser for ldap.conf

SYNOPSIS

    $cfg = new Config::Parser::ldap($filename);

    $base = $cfg->get('base');

DESCRIPTION

A parser for ldap.conf and similar files.

The syntax of ldap.conf configuration file is very simple. Each statement occupies one physical line and consists of a keyword and its value separated by one or more space characters. Keywords are case-insensitive. A value starts with the first non-blank character after the keyword, and terminates at the end of the line, or at the last sequence of blanks before the end of the line.

Blank lines and lines beginning with a hash mark are ignored.

CONSTRUCTOR

$cfg = new Config::Parser::ldap(%opts);

Parses the supplied configuration file and creates a new object for manipulating its settings. Keyword arguments %opts are:

filename

Name of the file to parse. The file must exist.

line

Optional line where the configuration starts in $filename. It is used to keep track of statement location in the file for correct diagnostics. If not supplied, 1 is assumed.

fh

File handle to read from. If it is not supplied, new handle will be created by using open on the supplied $filename.

lexicon

Dictionary of configuration statements that are allowed in the file. You will most probably not need this parameter. It is listed here for completeness sake. Refer to the Config::AST constructor for details.

METHODS

All methods for accessing the configuration settings are inherited from Config::AST.

If you wish to use this class as a base class, please refer to Config::Parser for implementation details.

EXAMPLE

The following simplified example shows how to use this module to connect and bind to a LDAP server.

    use Config::Parser::ldap;
    use Net::LDAP;

    # Parse configuration file
    $cf = new Config::Parser::ldap(filename => '/etc/ldap.conf');

    # Connect to server.
    $ldap = Net::LDAP->new($cf->uri->value);

    # Start TLS if required
    $args{capath} = $cf->get('tls_cacertdir');
    $args{cafile} = $cf->get('tls_cacert');
    $args{clientcert} = $cf->get('tls_cert');
    $args{clientkey} = $cf->get('tls_key');
    $args{ciphers} = $cf->get('tls_cipher_suite');
    if ($reqcert = $cf->get('tls_reqcert')) {
        my %tab = (
            none => 'never',
            allow => 'optional',
            demand => 'require',
            hard => 'require',
            try => 'optional'
        );
        $args{verify} = $tab{$reqcert}
            or die "unrecognized tls_reqcert: $reqcert";
    }
    $mesg = $ldap->start_tls(%args);
    $mesg->code && die $mesg->error;

    # Bind
    @bindargs = ();
    if (my $v = $cf->get('binddn')) {
        push @bindargs, $v
    }
    if (my $v = $cf->get('bindpw')) {
        push @bindargs, password => $v;
    }
    $mesg = $ldap->bind(@bindargs);
    $mesg->code && die $mesg->error;

SEE ALSO

Config::AST.

Config::Parser.