1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186
|
#
# $Id$
#
# Perl module for Kamailio
#
# Copyright (C) 2006 Collax GmbH
# (Bastian Friedrich <bastian.friedrich@collax.com>)
#
# This file is part of Kamailio, a free SIP server.
#
# Kamailio is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version
#
# Kamailio is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#
# This file was kindly donated by Collax GmbH
=head1 Kamailio::LDAPUtils::LDAPConf
Kamailio::LDAPUtils::LDAPConf - Read openldap config from standard config files.
use Kamailio::LDAPUtils::LDAPConf;
my $conf = new Kamailio::LDAPUtils::LDAPConf();
This module may be used to retrieve the global LDAP configuration as
used by other LDAP software, such as C<nsswitch.ldap> and C<pam-ldap>.
The configuration is usualy stored in C</etc/openldap/ldap.conf>
When used from an account with sufficient privilegs (e.g. root), the
ldap manager passwort is also retrieved.
=cut
package Kamailio::LDAPUtils::LDAPConf;
my $def_ldap_path = "/etc/openldap" ;
my $def_conf = "ldap.conf";
my $def_secret = "ldap.secret";
=head2 Constructor new()
Returns a new, initialized C<Kamailio::LDAPUtils::LDAPConf> object.
=cut
sub new {
my $class = shift;
my $self = _init( $def_ldap_path . "/" . $def_conf ,
$def_ldap_path . "/" . $def_secret);
if( ! $self ) { return undef; } ## can happen during customizing
bless $self , $class;
return $self;
}
sub _init {
my $conf_file = shift;
my $secret_file = shift;
my $result = {};
if( open(LDAPCONF,"<$conf_file") ) {
while(<LDAPCONF>) {
chomp;
s/#.*$//;
if( m/^\s*$/ ) { next; }
my ($var,$val) = split(" ",$_,2);
$result->{lc($var)} = $val;
}
close(LDAPCONF);
} else {
return undef;
}
if( -r $secret_file ) {
if( open(SECRET,"<$secret_file") ) {
my $secret = <SECRET>;
chomp $secret;
$result->{'rootbindpw'} = $secret;
close(SECRET);
}
}
return $result;
}
=head2 Method base()
Returns the servers base-dn to use when doing queries.
=cut
sub base { return $_[0]->{'base'}; }
=head2 Method host()
Returns the ldap host to contact.
=cut
sub host { return $_[0]->{'host'}; }
=head2 Method port()
Returns the ldap servers port.
=cut
sub port { return $_[0]->{'port'}; }
=head2 Method uri()
Returns an uri to contact the ldap server. When there is no ldap_uri in
the configuration file, an C<ldap:> uri is constucted from host and port.
=cut
sub uri {
my $self = shift;
if( $self->{'ldap_uri'} ) { return $self->{'ldap_uri'}; }
return "ldap://" . $self->host . ":" . $self->port ;
}
=head2 Method rootbindpw()
Returns the ldap "root" password.
Note that the C<rootbindpw> is only available when the current account has
sufficient privilegs to access C</etc/openldap/ldap.secret>.
=cut
sub rootbindpw { return $_[0]->{'rootbindpw'}; }
=head2 Method rootbinddn()
Returns the DN to use for "root"-access to the ldap server.
=cut
sub rootbinddn { return $_[0]->{'rootbinddn'}; }
=head2 Method binddn()
Returns the DN to use for authentication to the ldap server. When no
bind dn has been specified in the configuration file, returns the
C<rootbinddn>.
=cut
sub binddn {
my $self = shift;
if( $self->{'binddn'} ) { return $self->{'binddn'}; }
return $self->rootbinddn;
}
=head2 Method bindpw()
Returns the password to use for authentication to the ldap server. When no
bind password has been specified, returns the C<rootbindpw> if any.
=cut
sub bindpw {
my $self = shift;
if( $self->{'bindpw'} ) { return $self->{'bindpw'}; }
return $self->rootbindpw;
}
1;
|