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'};
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
return wantarray ? @rv : $rv[0];
}
-# find(name, &config)
+# find_value(name, &config)
# Returns the directive values with some name
sub find_value
{
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
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;
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
}
}
+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;