diff options
| author | Russ Allbery <rra@stanford.edu> | 2007-09-20 02:50:17 +0000 | 
|---|---|---|
| committer | Russ Allbery <rra@stanford.edu> | 2007-09-20 02:50:17 +0000 | 
| commit | 516744caf3f0a46bf56528bdabb2128fef791327 (patch) | |
| tree | c44509ce272b53939a68d478e877b09f49181044 | |
| parent | f26e22d3adb4379c7dfb24ba3b278fd5545cccae (diff) | |
Change the error handling of the Wallet::ACL list() method to return the
empty list on errors and clear error() so that it can be used to
distinguish between an error and an empty ACL.
| -rw-r--r-- | perl/Wallet/ACL.pm | 15 | ||||
| -rw-r--r-- | perl/Wallet/Server.pm | 2 | 
2 files changed, 9 insertions, 8 deletions
| diff --git a/perl/Wallet/ACL.pm b/perl/Wallet/ACL.pm index d6cc29c..4a9bd88 100644 --- a/perl/Wallet/ACL.pm +++ b/perl/Wallet/ACL.pm @@ -259,6 +259,7 @@ sub remove {  # error.  Sets the internal error string on error.  sub list {      my ($self) = @_; +    undef $self->{error};      my @entries;      eval {          my $sql = 'select ae_scheme, ae_identifier from acl_entries where @@ -272,7 +273,7 @@ sub list {      };      if ($@) {          $self->error ("cannot retrieve ACL $self->{id}: $@"); -        return (undef); +        return;      } else {          return @entries;      } @@ -285,7 +286,7 @@ sub list {  sub show {      my ($self) = @_;      my @entries = $self->list; -    if (@entries == 1 and not defined ($entries[0])) { +    if (not @entries and $self->error) {          return undef;      }      my $name = $self->name; @@ -314,7 +315,7 @@ sub check {          return undef;      }      my @entries = $self->list; -    return undef if (@entries == 1 and not defined $entries[0]); +    return undef if (not @entries and $self->error);      my %verifier;      $self->{check_errors} = [];      for my $entry (@entries) { @@ -481,10 +482,10 @@ C<alice@EXAMPLE.COM> and C<bob@EXAMPLE.COM>, list() would return:      ([ 'krb5', 'alice@EXAMPLE.COM' ], [ 'krb5', 'bob@EXAMPLE.COM' ]) -Returns C<(undef)> (the list containing the single element undef) on -failure, so that it can be distinguished from the empty list, which -indicates the ACL contains no entries.  On failure, the caller should call -error() to get the error message. +Returns the empty list on failure.  To distinguish between this and the +ACL containing no entries, the caller should call error().  error() is +guaranteed to return the error message if there was an error and undef if +there was no error.  =item name() diff --git a/perl/Wallet/Server.pm b/perl/Wallet/Server.pm index 894a52e..b646eb0 100644 --- a/perl/Wallet/Server.pm +++ b/perl/Wallet/Server.pm @@ -555,7 +555,7 @@ sub acl_remove {      }      if ($acl->name eq 'ADMIN') {          my @e = $acl->list; -        if (@e == 1 and not defined ($e[0])) { +        if (not @e and $acl->error) {              $self->error ($acl->error);              return undef;          } elsif (@e == 1 && $e[0][0] eq $scheme && $e[0][1] eq $identifier) { | 
