Some work on new LDIF config format for OpenLDAP
authorJamie Cameron <jcameron@webmin.com>
Fri, 1 May 2009 01:07:23 +0000 (01:07 +0000)
committerJamie Cameron <jcameron@webmin.com>
Fri, 1 May 2009 01:07:23 +0000 (01:07 +0000)
ldap-server/config-Ubuntu-Linux-8.10-* [new file with mode: 0644]
ldap-server/config.info
ldap-server/edit_slapd.cgi
ldap-server/ldap-server-lib.pl

diff --git a/ldap-server/config-Ubuntu-Linux-8.10-* b/ldap-server/config-Ubuntu-Linux-8.10-*
new file mode 100644 (file)
index 0000000..4a5804f
--- /dev/null
@@ -0,0 +1,9 @@
+config_file=/etc/ldap/slapd.d
+schema_dir=/etc/ldap/slapd.d/cn=schema
+slapd=slapd
+ldap_user=ldap
+browse_max=100
+start_cmd=/etc/init.d/slapd start
+stop_cmd=/etc/init.d/slapd stop
+apply_cmd=/etc/init.d/slapd restart
+init_name=slapd
index 99451f1..9791378 100644 (file)
@@ -5,7 +5,7 @@ user=Login for LDAP server,3,Detect automatically
 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
index 026e9f9..8b2ae17 100644 (file)
@@ -10,7 +10,8 @@ $conf = &get_config();
 @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);
@@ -84,7 +85,8 @@ print &ui_table_row($text{'slapd_timelimit'},
 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()) {
index bf0037e..7c791fc 100644 (file)
@@ -1,5 +1,4 @@
 # Functions for configuring and talking to an LDAP server
-# XXX make sure ACLs work!
 
 BEGIN { push(@INC, ".."); };
 use WebminCore;
@@ -50,15 +49,25 @@ if ($config{'server'}) {
        }
 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'};
@@ -98,7 +107,7 @@ if (!$config{'server'} || &to_ipaddress($config{'server'}) eq '127.0.0.1' ||
                                  $config{'config_file'});
                }
        return !&has_command($config{'slapd'}) ? -1 :
-              !-r $config{'config_file'} ? -2 : 1;
+              !&get_config_type() ? -2 : 1;
        }
 return 0;
 }
@@ -122,6 +131,21 @@ if ($out =~ /slapd\s+([0-9\.]+)/) {
 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
@@ -177,6 +201,40 @@ local @rv = map { $_->{'values'}->[0] } &find(@_);
 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