pass=Password for LDAP server,3,Detect automatically
ssl=Use encryption with LDAP server?,1,-Detect automatically,1-Yes,2-Yes TLS,0-No
slapd=Full path to OpenLDAP server program,8
-config_file=OpenLDAP server configuration file,8
+config_file=OpenLDAP server configuration file or directory,8
schema_dir=OpenLDAP schema directory,7
ldap_user=User OpenLDAP server runs as,5
init_name=OpenLDAP server boot script name,3,Same as module name
@tds = ( "width=30%" );
print &ui_form_start("save_slapd.cgi", "post");
-print &ui_hidden_table_start($text{'slapd_header'}, undef, 2, "basic", 1,\@tds);
+print &ui_hidden_table_start($text{'slapd_header'}, "width=100%", 2,
+ "basic", 1,\@tds);
# Top-level DN
$suffix = &find_value('suffix', $conf);
print &ui_hidden_table_end("basic");
# SSL section
-print &ui_hidden_table_start($text{'slapd_header2'}, undef, 2, "ssl", 0, \@tds);
+print &ui_hidden_table_start($text{'slapd_header2'}, "width=100%", 2,
+ "ssl", 0, \@tds);
# Protocols to serve
if (&can_get_ldap_protocols()) {
# Functions for configuring and talking to an LDAP server
-# XXX make sure ACLs work!
BEGIN { push(@INC, ".."); };
use WebminCore;
}
else {
# Get from slapd.conf
- -r $config{'config_file'} || return &text('connect_efile',
+ -e $config{'config_file'} || return &text('connect_efile',
"<tt>$config{'config_file'}</tt>");
- local $conf = &get_config();
$server = "127.0.0.1";
- $port = $config{'port'} || &find_value("port", $conf);
- $user = $config{'user'} || &find_value("rootdn", $conf);
+ $port = $config{'port'};
+ $user = $config{'user'};
+ $pass = $config{'pass'};
+ if (&get_config_type() == 1) {
+ # Find defaults from slapd.conf
+ local $conf = &get_config();
+ $port ||= &find_value("port", $conf);
+ $user ||= &find_value("rootdn", $conf);
+ $pass ||= &find_value("rootpw", $conf);
+ }
+ else {
+ # Find defaults from LDIF-format data
+ local $conf = &get_ldif_config();
+ # XXX which database?
+ }
$user || return $text{'connect_euser2'};
- $pass = $config{'pass'} || &find_value("rootpw", $conf);
- #$pass || return $text{'connect_epass2'};
$pass =~ /^\{/ && return $text{'connect_epass3'};
}
$ssl = $config{'ssl'};
$config{'config_file'});
}
return !&has_command($config{'slapd'}) ? -1 :
- !-r $config{'config_file'} ? -2 : 1;
+ !&get_config_type() ? -2 : 1;
}
return 0;
}
return undef;
}
+# get_config_type()
+# Returns 2 for new-style LDIF format directory, 1 for slapd.conf, 0 if unknown
+sub get_config_type
+{
+if (-d $config{'config_file'} && -r "$config{'config_file'}/cn=config.ldif") {
+ return 2;
+ }
+elsif (-r $config{'config_file'}) {
+ return 1;
+ }
+else {
+ return 0;
+ }
+}
+
# get_config([file])
# Returns an array ref of LDAP server configuration settings
sub get_config
return wantarray ? @rv : $rv[0];
}
+# get_ldif_config()
+# Parses the new LDIF-format config files into a list ref
+sub get_ldif_config
+{
+if (defined($get_ldif_config_cache)) {
+ return $get_ldif_config_cache;
+ }
+local @rv;
+foreach my $file (&recursive_find_ldif($config{'config_file'})) {
+ local $lnum = 0;
+ local $cls = $file;
+ $cls =~ s/^\Q$config{'config_file'}\/\E//;
+ $cls =~ s/\.ldif$//;
+ open(CONFIG, $file);
+ while(<CONFIG>) {
+ s/\r|\n//g;
+ s/^#.*$//;
+ if (/^(\S+):\s*(.*)/) {
+ local $dir = { 'file' => $file,
+ 'line' => $lnum,
+ 'class' => $cls,
+ 'name' => $1 };
+ local $value = $2;
+ $dir->{'values'} = [ &split_quoted_string($value) ];
+ push(@rv, $dir);
+ }
+ $lnum++;
+ }
+ close(CONFIG);
+ }
+$get_ldif_config_cache = \@rv;
+return $get_ldif_config_cache;
+}
+
# save_directive(&config, name, value|&values|&directive, ...)
# Update the value(s) of some entry in the config file
sub save_directive