Skip to content

Commit

Permalink
Evaluating LDAP->Write return values and reporting errors
Browse files Browse the repository at this point in the history
- More at BNC#768708
  • Loading branch information
kobliha committed Aug 15, 2012
1 parent 0893ca5 commit c6cdca7
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions src/DnsZones.pm
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ textdomain("dns-server");
YaST::YCP::Import ("Hostname");
YaST::YCP::Import ("String");
YaST::YCP::Import ("Mode");
YaST::YCP::Import ("Ldap");

#use io_routines;
#use check_routines;
Expand Down Expand Up @@ -690,16 +691,21 @@ sub ZoneFileWriteLdap {
}
y2debug ("New base record: ".Dumper(\%ldap_record));

my $ldap_write = 1;
if (scalar (@{$found_ref || []}) == 0)
{
y2milestone ("Creating new zone record");
SCR->Write (".ldap.add", \%ldap_cmd, \%ldap_record);
$ldap_write = SCR->Write(".ldap.add", \%ldap_cmd, \%ldap_record);
}
else
{
y2milestone ("Modifying existing zone record");
delete $ldap_record{"objectClass"}; # objectclass can be changed by mail-server
SCR->Write (".ldap.modify", \%ldap_cmd, \%ldap_record);
$ldap_write = SCR->Write(".ldap.modify", \%ldap_cmd, \%ldap_record);
}
unless ($ldap_write) {
y2error("LDAP Error (write): ".Ldap->LDAPError());
Ldap->LDAPErrorMessage('write', Ldap->LDAPError());
}

my @all_records = map {
Expand Down Expand Up @@ -741,7 +747,12 @@ sub ZoneFileWriteLdap {
foreach my $d (@deleted)
{
y2milestone ("Removing all records regarding $d");
SCR->Write (".ldap.delete", {"dn" => "relativeDomainName=$d,$zone_dn"});
$ldap_write = SCR->Write(".ldap.delete", {"dn" => "relativeDomainName=$d,$zone_dn"});
last unless $ldap_write; # skip the rest
}
unless ($ldap_write) {
y2error("LDAP Error (delete): ".Ldap->LDAPError());
Ldap->LDAPErrorMessage('write', Ldap->LDAPError());
}

# write all the other records
Expand Down Expand Up @@ -797,14 +808,21 @@ sub ZoneFileWriteLdap {

if (scalar (@{$found_ref || []}) == 0)
{
SCR->Write (".ldap.add", \%ldap_cmd, \%ldap_record);
$ldap_write = SCR->Write (".ldap.add", \%ldap_cmd, \%ldap_record);
last unless $ldap_write; # skip the rest
}
else
{
SCR->Write (".ldap.modify", \%ldap_cmd, \%ldap_record);
$ldap_write = SCR->Write (".ldap.modify", \%ldap_cmd, \%ldap_record);
last unless $ldap_write; # skip the rest
}
}
return 1;
unless ($ldap_write) {
y2error("LDAP Error (write): ".Ldap->LDAPError());
Ldap->LDAPErrorMessage('write', Ldap->LDAPError());
}

return $ldap_write;
}

BEGIN { $TYPEINFO{ZonesDeleteLdap} = ["function", "boolean", [ "list", "string",]];}
Expand Down

0 comments on commit c6cdca7

Please sign in to comment.