allow to pass emtpy strings to delete settings
authorDietmar Maurer <dietmar@proxmox.com>
Fri, 13 Jan 2012 08:42:53 +0000 (09:42 +0100)
committerDietmar Maurer <dietmar@proxmox.com>
Fri, 13 Jan 2012 08:42:53 +0000 (09:42 +0100)
PVE/API2/Domains.pm
PVE/AccessControl.pm

index 117ef3c..c79e44e 100644 (file)
@@ -146,12 +146,15 @@ __PACKAGE__->register_method ({
 
                foreach my $p (keys %$param) {
                    next if $p eq 'realm';
-                   $cfg->{$realm}->{$p} = $param->{$p};
+                   $cfg->{$realm}->{$p} = $param->{$p} if $param->{$p};
                }
 
                # port 0 ==> use default
-               if (defined($param->{port}) && !$param->{port}) { 
-                   delete $cfg->{$realm}->{port};
+               # server2 == '' ===> delete server2
+               for my $p (qw(port server2)) { 
+                   if (defined($param->{$p}) && !$param->{$p}) { 
+                       delete $cfg->{$realm}->{$p};
+                   }
                }
 
                cfs_write_file($domainconfigfile, $cfg);
@@ -247,12 +250,11 @@ __PACKAGE__->register_method ({
                }
 
                foreach my $p (keys %$param) {
-                   $cfg->{$realm}->{$p} = $param->{$p};
-               }
-
-               # port 0 ==> use default
-               if (defined($param->{port}) && !$param->{port}) { 
-                   delete $cfg->{$realm}->{port};
+                   if ($param->{$p}) {
+                       $cfg->{$realm}->{$p} = $param->{$p};
+                   } else {
+                       delete $cfg->{$realm}->{$p};
+                   }
                }
 
                cfs_write_file($domainconfigfile, $cfg);
index 3db2bff..5ba3d39 100644 (file)
@@ -899,7 +899,7 @@ sub write_domains {
                    $wrote_default = 1;
            } elsif (defined($formats->{$k})) {
                if (!$formats->{$k}) {
-                   $data .= "\t$k\n";
+                   $data .= "\t$k\n" if $v;
                } elsif ($v =~ m/^$formats->{$k}$/) {
                    $v = PVE::Tools::encode_text($v) if $k eq 'comment';
                    $data .= "\t$k $v\n";
@@ -994,6 +994,8 @@ sub parse_domains {
                warn "ignoring domain '$realm' - missing user attribute\n";
            } elsif (($entry->{type} eq "ldap") && !$entry->{base_dn}) {
                warn "ignoring domain '$realm' - missing base_dn attribute\n";
+           } elsif (($entry->{type} eq "ad") && !$entry->{domain}) {
+               warn "ignoring domain '$realm' - missing domain attribute\n";
            } else {
                $cfg->{$realm} = $entry;
            }