Handle hostnames with upper-case letters
[webmin.git] / ldap-server / save_ldif.cgi
1 #!/usr/local/bin/perl
2 # Update local LDAP server LDIF file configuration options
3
4 require './ldap-server-lib.pl';
5 &error_setup($text{'slapd_err'});
6 $access{'slapd'} || &error($text{'slapd_ecannot'});
7 &local_ldap_server() == 1 || &error($text{'slapd_elocal'});
8 &ReadParse();
9
10 &lock_slapd_files();
11 $conf = &get_ldif_config();
12
13 # Validate and store inputs
14
15 # Top-level DN
16 $defdb = &get_default_db();
17 $in{'suffix'} =~ /=/ || &error($text{'slapd_esuffix'});
18 &save_ldif_directive($conf, 'olcSuffix', $defdb, $in{'suffix'});
19
20 # Admin login
21 $in{'rootdn'} =~ /=/ || &error($text{'slapd_erootdn'});
22 &save_ldif_directive($conf, 'olcRootDN', $defdb, $in{'rootdn'});
23
24 # Admin password
25 if (!$in{'rootchange_def'}) {
26         $in{'rootchange'} =~ /\S/ || &error($text{'slapd_erootpw'});
27         $crypt = &unix_crypt($in{'rootchange'}, substr(time(), -2));
28         &save_ldif_directive($conf, 'olcRootPW', $defdb, "{crypt}".$crypt);
29         $config{'pass'} = $in{'rootchange'};
30         $save_config = 1;
31         }
32
33 # Cache sizes
34 if (!$in{'dbcachesize_def'}) {
35         $in{'dbcachesize'} =~ /^\d+$/ || &error($text{'slapd_edbcachesize'});
36         &save_ldif_directive($conf, 'olcDbCachesize', $defdb,
37                              $in{'dbcachesize'});
38         }
39 else {
40         &save_ldif_directive($conf, 'olcDbCachesize', $defdb, undef);
41         }
42
43 # Size limit
44 if ($in{'sizelimit_def'}) {
45         &save_ldif_directive($conf, 'olcSizeLimit', $defdb, undef);
46         }
47 else {
48         $in{'sizelimit'} =~ /^[1-9]\d*$/ || &error($text{'slapd_esizelimit'});
49         &save_ldif_directive($conf, 'olcSizeLimit', $defdb, $in{'sizelimit'});
50         }
51
52 # LDAP protocols
53 if (&can_get_ldap_protocols()) {
54         @newprotos = split(/\0/, $in{'protos'});
55         @newprotos || &error($text{'slapd_eprotos'});
56         }
57
58 # SSL file options
59 $confdb = &get_config_db();
60 foreach $s ([ 'olcTLSCertificateFile', 'cert' ],
61             [ 'olcTLSCertificateKeyFile', 'key' ],
62             [ 'olcTLSCACertificateFile', 'ca' ]) {
63         if ($in{$s->[1].'_def'}) {
64                 &save_ldif_directive($conf, $s->[0], $confdb, undef);
65                 }
66         else {
67                 &valid_pem_file($in{$s->[1]}, $s->[1]) ||
68                         &error($text{'slapd_e'.$s->[1]});
69                 &save_ldif_directive($conf, $s->[0], $confdb, $in{$s->[1]});
70                 }
71         }
72
73 # Write out the files
74 &flush_file_lines();
75 &unlock_slapd_files();
76 if ($save_config) {
77         &lock_file($module_config_file);
78         &save_module_config();
79         &unlock_file($module_config_file);
80         }
81 if (&can_get_ldap_protocols()) {
82         $protos = &get_ldap_protocols();
83         foreach $p (keys %$protos) {
84                 $protos->{$p} = 0;
85                 }
86         foreach $p (@newprotos) {
87                 $protos->{$p} = 1;
88                 }
89         &save_ldap_protocols($protos);
90         }
91 &webmin_log('slapd');
92
93 &redirect("");
94