2 # Save LDAP and SQL database options
4 require './spam-lib.pl';
5 &error_setup($text{'db_err'});
7 &set_config_file_in(\%in);
11 $conf = &get_config();
14 if ($in{'mode'} == 0) {
18 elsif ($in{'mode'} == 1) {
19 # Database of some type
20 &to_ipaddress($in{'dbhost'}) || &error($text{'db_edbhost'});
21 $in{'dbdb'} =~ /^[a-z0-9\.\-\_]+$/ || &error($text{'db_edbdb'});
22 $in{'dbport_def'} || $in{'dbport'} =~ /^\d+$/ ||
23 &error($text{'db_edbport'});
24 $dsn = join(":", "DBI", $in{'dbdriver'}, $in{'dbdb'}, $in{'dbhost'});
25 $dsn .= ":".$in{'dbport'} if (!$in{'dbport_def'});
27 elsif ($in{'mode'} == 3) {
29 &to_ipaddress($in{'ldaphost'}) || &to_ip6address($in{'ldaphost'}) ||
30 &error($text{'db_eldaphost'});
31 $in{'ldapport_def'} || $in{'ldapport'} =~ /^\d+$/ ||
32 &error($text{'db_eldapport'});
33 $in{'ldapdn'} =~ /^\S+$/ || &error($text{'db_eldapdn'});
34 $in{'ldapattr'} =~ /^\S+$/ || &error($text{'db_eldapattr'});
35 $in{'ldapuid'} =~ /^\S+$/ || &error($text{'db_eldapuid'});
36 $dsn = "ldap://".$in{'ldaphost'}.
37 ($in{'ldapport_def'} ? "" : ":".$in{'ldapport'})."/".
38 $in{'ldapdn'}."?".$in{'ldapattr'}."?".$in{'ldapscope'}."?".
39 $in{'ldapuid'}."=__USERNAME__";
43 $in{'dsn'} =~ /\S/ || &error($text{'db_edsn'});
46 &save_directives($conf, "user_scores_dsn", [ $dsn ], 1);
48 # Parse username and password
49 &parse_opt($conf, "user_scores_sql_username", \&username_check);
50 &parse_opt($conf, "user_scores_sql_password");
51 &parse_opt($conf, "user_scores_ldap_username", \&username_check);
52 &parse_opt($conf, "user_scores_ldap_password");
58 &redirect($redirect_url);
62 return $_[0] =~ /^\S+$/ ? undef : $text{'db_eusername'};