mirror of
https://github.com/webmin/webmin.git
synced 2026-06-20 19:30:30 +01:00
More work on new LDAP config format
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
config_file=/etc/ldap/slapd.d
|
||||
schema_dir=/etc/ldap/slapd.d/cn=schema
|
||||
schema_dir=/etc/ldap/slapd.d/cn=config/cn=schema
|
||||
slapd=slapd
|
||||
ldap_user=ldap
|
||||
browse_max=100
|
||||
|
||||
@@ -19,8 +19,7 @@ if ($in{'goparent'}) {
|
||||
$base = $in{'parent'};
|
||||
}
|
||||
elsif (!$in{'base'}) {
|
||||
$conf = &get_config();
|
||||
$base = &find_value("suffix", $conf);
|
||||
$base = &get_ldap_base();
|
||||
}
|
||||
else {
|
||||
$base = $in{'base'};
|
||||
|
||||
@@ -65,7 +65,10 @@ else {
|
||||
else {
|
||||
# Find defaults from LDIF-format data
|
||||
local $conf = &get_ldif_config();
|
||||
# XXX which database?
|
||||
$defdb = &get_default_db();
|
||||
$port ||= &find_ldif_value("olcPort", $conf, $defdb);
|
||||
$user ||= &find_ldif_value("olcRootDN", $conf, $defdb);
|
||||
$pass ||= &find_ldif_value("olcRootPW", $conf, $defdb);
|
||||
}
|
||||
$user || return $text{'connect_euser2'};
|
||||
$pass =~ /^\{/ && return $text{'connect_epass3'};
|
||||
@@ -93,6 +96,14 @@ $connect_ldap_db = $ldap;
|
||||
return $ldap;
|
||||
}
|
||||
|
||||
# get_default_db()
|
||||
# For LDIF format configs, returns the config DN for the default database
|
||||
sub get_default_db
|
||||
{
|
||||
# XXX make configurable
|
||||
return "cn=config,olcDatabase={1}hdb";
|
||||
}
|
||||
|
||||
# local_ldap_server()
|
||||
# Returns 1 if OpenLDAP is installed locally and we are configuring it, 0 if
|
||||
# remote, or -1 the binary is missing, -2 if the config is missing
|
||||
@@ -192,7 +203,7 @@ local @rv = grep { lc($_->{'name'}) eq lc($name) } @$conf;
|
||||
return wantarray ? @rv : $rv[0];
|
||||
}
|
||||
|
||||
# find(name, &config)
|
||||
# find_value(name, &config)
|
||||
# Returns the directive values with some name
|
||||
sub find_value
|
||||
{
|
||||
@@ -201,6 +212,29 @@ local @rv = map { $_->{'values'}->[0] } &find(@_);
|
||||
return wantarray ? @rv : $rv[0];
|
||||
}
|
||||
|
||||
# find_ldif(name, &config, [class])
|
||||
# Returns the structures with some name and optionally class in the LDIF
|
||||
# configuration array ref
|
||||
sub find_ldif
|
||||
{
|
||||
local ($name, $conf, $cls) = @_;
|
||||
local @rv = grep { lc($_->{'name'}) eq lc($name) } @$conf;
|
||||
if ($cls) {
|
||||
@rv = grep { lc($_->{'class'}) eq lc($cls) } @rv;
|
||||
}
|
||||
return wantarray ? @rv : $rv[0];
|
||||
}
|
||||
|
||||
# find_ldif_value(name, &config, [class])
|
||||
# Returns the values with some name and optionally class in the LDIF
|
||||
# configuration array ref
|
||||
sub find_ldif_value
|
||||
{
|
||||
local ($name, $conf, $cls) = @_;
|
||||
local @rv = map { $_->{'values'}->[0] } &find_ldif(@_);
|
||||
return wantarray ? @rv : $rv[0];
|
||||
}
|
||||
|
||||
# get_ldif_config()
|
||||
# Parses the new LDIF-format config files into a list ref
|
||||
sub get_ldif_config
|
||||
@@ -214,6 +248,7 @@ foreach my $file (&recursive_find_ldif($config{'config_file'})) {
|
||||
local $cls = $file;
|
||||
$cls =~ s/^\Q$config{'config_file'}\/\E//;
|
||||
$cls =~ s/\.ldif$//;
|
||||
$cls =~ s/\//,/g;
|
||||
open(CONFIG, $file);
|
||||
while(<CONFIG>) {
|
||||
s/\r|\n//g;
|
||||
@@ -235,6 +270,28 @@ $get_ldif_config_cache = \@rv;
|
||||
return $get_ldif_config_cache;
|
||||
}
|
||||
|
||||
# recursive_find_ldif(dir)
|
||||
# Find all .ldif files under some directory
|
||||
sub recursive_find_ldif
|
||||
{
|
||||
local ($dir) = @_;
|
||||
local @rv;
|
||||
opendir(LDIFDIR, $dir);
|
||||
local @files = readdir(LDIFDIR);
|
||||
closedir(LDIFDIR);
|
||||
foreach my $f (@files) {
|
||||
next if ($f eq "." || $f eq "..");
|
||||
local $path = "$dir/$f";
|
||||
if (-r $path && $path =~ /\.ldif$/) {
|
||||
push(@rv, $path);
|
||||
}
|
||||
elsif (-d $path) {
|
||||
push(@rv, &recursive_find_ldif($path));
|
||||
}
|
||||
}
|
||||
return @rv;
|
||||
}
|
||||
|
||||
# save_directive(&config, name, value|&values|&directive, ...)
|
||||
# Update the value(s) of some entry in the config file
|
||||
sub save_directive
|
||||
@@ -649,5 +706,20 @@ elsif ($gconfig{'os_type'} eq 'debian-linux') {
|
||||
}
|
||||
}
|
||||
|
||||
sub get_ldap_base
|
||||
{
|
||||
if (&get_config_type() == 1) {
|
||||
my $conf = &get_config();
|
||||
my $base = &find_value("suffix", $conf);
|
||||
return $base;
|
||||
}
|
||||
elsif (&get_config_type() == 2) {
|
||||
my $conf = &get_ldif_config();
|
||||
my $base = &find_ldif_value("olcSuffix", $conf, &get_default_db());
|
||||
return $base;
|
||||
}
|
||||
return undef;
|
||||
}
|
||||
|
||||
1;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user