$dn = $in{'dn'};
}
+# Work out class for the DN
+$schema = $ldap->schema();
+@allocs = map { $_->{'name'} }
+ grep { $_->{'structural'} }
+ $schema->all_objectclasses();
+@ocs = ( );
+foreach my $poc ("top", "domain") {
+ if (&indexof($poc, @allocs) >= 0) {
+ push(@ocs, $poc);
+ }
+ }
+@ocs || &error(&text('create_eoc'));
+
# Do it, while showing the user
&ui_print_unbuffered_header(undef, $text{'create_title'}, "");
# Create the DN
print &text('create_doingdn', "<tt>".&html_escape($dn)."</tt>"),"<br>\n";
-$rv = $ldap->add($dn, attr => [ "objectClass", "top" ]);
+@attrs = ( "objectClass", \@ocs );
+if (&indexof("domain", @ocs) >= 0) {
+ # Domain class needs dc
+ if ($dn =~ /^([^=]+)=([^, ]+)/) {
+ push(@attrs, $1, $2);
+ }
+ }
+$rv = $ldap->add($dn, attr => \@attrs);
if (!$rv || $rv->code) {
print &text('create_edoingdn', &ldap_error($rv)),"<p>\n";
}
$rootmode == 1 ? &text('slapd_root1', $rootcrypt) :
$rootmode == 2 ? &text('slapd_root2', $rootsha1) :
$rootmode == 3 ? &text('slapd_root3', $rootenc) :
+ $rootplain eq '' ? $text{'slapd_noroot'} :
$rootplain);
# Set to new
# Cache sizes
$cachesize = &find_value('cachesize', $conf);
print &ui_table_row($text{'slapd_cachesize'},
- &ui_textbox("cachesize", $cachesize, 10));
+ &ui_opt_textbox("cachesize", $cachesize, 10, $text{'default'}));
$dbcachesize = &find_value('dbcachesize', $conf);
print &ui_table_row($text{'slapd_dbcachesize'},
- &ui_textbox("dbcachesize", $dbcachesize, 10));
+ &ui_opt_textbox("dbcachesize", $dbcachesize, 10, $text{'default'}));
# Access control options
$allowdir = &find("allow", $conf);
# Is it installed and usable?
$local = &local_ldap_server();
if ($local == -1) {
- &ui_print_endpage(&text('index_eslapd', "<tt>$config{'slapd'}</tt>",
- "../config.cgi?$module_name"));
+ # Expected, but not installed
+ print &text('index_eslapd', "<tt>$config{'slapd'}</tt>",
+ "../config.cgi?$module_name"),"<p>\n";
+
+ &foreign_require("software", "software-lib.pl");
+ $lnk = &software::missing_install_link("openldap",
+ $text{'index_openldap'},
+ "../$module_name/", $module_info{'desc'});
+ print $lnk,"<p>\n" if ($lnk);
+
+ &ui_print_footer("/", $text{'index'});
+ return;
}
elsif ($local == -2) {
+ # Installed but config missing
&ui_print_endpage(&text('index_econfig',
"<tt>$config{'config_file'}</tt>",
"../config.cgi?$module_name"));
}
}
-# Check if need to init new install
-# XXX
+# Check if need to init new install, by creating the root DN
+$ldap = &connect_ldap_db();
+if (ref($ldap) && $access{'browser'}) {
+ $conf = &get_config();
+ $base = &find_value("suffix", $conf);
+ $rv = $ldap->search(base => $base,
+ filter => '(objectClass=*)',
+ scope => 'base');
+ if ($rv->code) {
+ # Not found .. offer to init
+ print "<center>\n";
+ print &ui_form_start("create.cgi");
+ print &ui_hidden('mode', 1);
+ print &ui_hidden('dn', $base);
+ print &text('index_setupdesc', "<tt>$base</tt>"),"<p>\n";
+ print &ui_form_end([ [ undef, $text{'index_setup'} ] ]);
+ print "</center>\n";
+ print "<hr>\n";
+ }
+ }
# Work out icons
if ($local) {
index_version=OpenLDAP $1
+index_openldap=OpenLDAP
index_eslapd=The OpenLDAP server program $1 was not found on your system. Perhaps the path on the <a href='$2'>module configuration</a> page is incorrect?
index_econfig=The OpenLDAP server configuration file $1 was not found on your system. Perhaps the path on the <a href='$2'>module configuration</a> page is incorrect?
index_econnect=An error occurred connection to the LDAP server : $1. You may need to adjust settings on the <a href='$2'>module configuration</a> page.
index_return=module index
index_boot=Start at boot?
index_bootdesc=Change this selection to determine if the OpenLDAP server is started at boot time or not.
+index_setupdesc=Your LDAP server's database does not contain the root DN $1 yet, which means that no data can be added until you create it. However, Webmin can do this for you by clicking the button below.
+index_setup=Create Root DN
connect_eserver=The LDAP server $1 does not exist
connect_euser=No user to login as has been configured
connect_eldap=Failed to connect to LDAP server $1 on port $2
connect_essl=Failed to start TLS encryption with LDAP server $1 : $2
connect_elogin=Failed to login to LDAP server $1 as $2 : $3
+connect_cpan=You can have the <tt>$1</tt> Perl module <a href='$2'>automatically installed</a> from CPAN.
slapd_title=OpenLDAP Server Configuration
slapd_header=Global LDAP server options
slapd_root1=Unix encrypted <tt>$1</tt>
slapd_root2=SHA1 encrypted <tt>$1</tt>
slapd_root3=Encrypted <tt>$1</tt>
+slapd_noroot=<i>No password set</i>
slapd_rootchange=New administration password
slapd_leave=Don't change
slapd_set=Set to
create_done=.. done
create_doingex=Creating example object with DN $1 ..
create_edoingex=.. failed : $1. However, the tree can still be used.
+create_eoc=Could not find a suitable object class for the new DN
eunknown=Unknown error
# Functions for configuring and talking to an LDAP server
# XXX help pages
-# XXX init ldap server
# XXX acl section
+# XXX /var/lib/ldap/* files are owned by root on redhat
do '../web-lib.pl';
&init_config();
# Do we have the module?
if ($net_ldap_error) {
- return &text('connect_emod', "<tt>Net::LDAP</tt>",
+ local $msg = &text('connect_emod', "<tt>Net::LDAP</tt>",
"<pre>".&html_escape($net_ldap_error)."</pre>");
+ if (foreign_available("cpan")) {
+ $msg .= "<p>\n";
+ $msg .= &text('connect_cpan', "Net::LDAP",
+ "../cpan/download.cgi?source=3&cpan=Net::LDAP&".
+ "cpan=Convert::ASN1&".
+ "return=../$module_name/&returndesc=".
+ &urlize($module_info{'desc'}));
+ }
+ return $msg;
}
# Work out server name, login and TLS mode
$user = $config{'user'} || &find_value("rootdn", $conf);
$user || return $text{'connect_euser2'};
$pass = $config{'pass'} || &find_value("rootpw", $conf);
- $pass || return $text{'connect_epass2'};
+ #$pass || return $text{'connect_epass2'};
$pass =~ /^\{/ && return $text{'connect_epass3'};
}
$ssl = $config{'ssl'};
$ldap || return "This can't happen!";
# Login to server
-local $mesg = $ldap->bind(dn => $user, password => $pass);
+local $mesg = $pass eq '' ?
+ $ldap->bind(dn => $user, anonymous => 1) :
+ $ldap->bind(dn => $user, password => $pass);
if (!$mesg || $mesg->code) {
return &text('connect_elogin', "<tt>$server</tt>", "<tt>$user</tt>",
&ldap_error($mesg));
sub get_ldap_server_version
{
return undef if (&local_ldap_server() != 1);
-local $out = &backquote_command("$config{'slapd'} -V 2>&1 </dev/null");
+local $out = &backquote_with_timeout(
+ "$config{'slapd'} -V -d 1 2>&1 </dev/null", 1, 1, 1);
if ($out =~ /slapd\s+([0-9\.]+)/) {
return $1;
}
}
# Cache sizes
-$in{'cachesize'} =~ /^\d+$/ || &error($text{'slapd_ecachesize'});
-&save_directive($conf, 'cachesize', $in{'cachesize'});
-$in{'dbcachesize'} =~ /^\d+$/ || &error($text{'slapd_edbcachesize'});
-&save_directive($conf, 'dbcachesize', $in{'dbcachesize'});
+if (!$in{'cachesize_def'}) {
+ $in{'cachesize'} =~ /^\d+$/ || &error($text{'slapd_ecachesize'});
+ &save_directive($conf, 'cachesize', $in{'cachesize'});
+ }
+else {
+ &save_directive($conf, 'cachesize', undef);
+ }
+if (!$in{'dbcachesize_def'}) {
+ $in{'dbcachesize'} =~ /^\d+$/ || &error($text{'slapd_edbcachesize'});
+ &save_directive($conf, 'dbcachesize', $in{'dbcachesize'});
+ }
+else {
+ &save_directive($conf, 'dbcachesize', undef);
+ }
# Access control options
@allow = split(/\0/, $in{'allow'});