From 8b9daeaad45a5181356d76fa9dfde6db25296d69 Mon Sep 17 00:00:00 2001 From: Russ Allbery Date: Tue, 28 Aug 2007 21:12:15 +0000 Subject: Throw exceptions for failure of object new() and create() functions rather than returning undef so that we can save the error message. --- perl/Wallet/Object/Keytab.pm | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'perl/Wallet/Object/Keytab.pm') diff --git a/perl/Wallet/Object/Keytab.pm b/perl/Wallet/Object/Keytab.pm index b10c67a..b386fae 100644 --- a/perl/Wallet/Object/Keytab.pm +++ b/perl/Wallet/Object/Keytab.pm @@ -80,17 +80,18 @@ sub _kadmin_exists { } } -# Create a principal in Kerberos. Return true if successful, false otherwise. +# Create a principal in Kerberos. Since this is only called by create, it +# throws an exception on failure rather than setting the error and returning +# undef. sub _kadmin_addprinc { my ($self, $principal) = @_; unless ($self->_valid_principal ($principal)) { - $self->{error} = "invalid principal name: $principal"; - return undef; + die "invalid principal name $principal\n"; } my $flags = $Wallet::Config::KEYTAB_FLAGS; my $output = $self->_kadmin ("addprinc -randkey $flags $principal"); if ($output =~ /^add_principal: (.*)/m) { - return undef; + die "error adding principal $principal: $!\n"; } return 1; } @@ -144,7 +145,7 @@ sub create { if ($name !~ /\@/ && $Wallet::Config::KEYTAB_REALM) { $name .= '@' . $Wallet::Config::KEYTAB_REALM; } - return undef if not $class->_kadmin_addprinc ($name); + $class->_kadmin_addprinc ($name); return $class->SUPER::create ($name, $type, $dbh, $creator, $host, $time); } -- cgit v1.2.3