summaryrefslogtreecommitdiff
path: root/perl/Wallet/Kadmin
diff options
context:
space:
mode:
authorRuss Allbery <rra@stanford.edu>2010-01-19 22:48:01 -0800
committerRuss Allbery <rra@stanford.edu>2010-01-19 22:48:01 -0800
commitd684049761db4eb88cd936c530196ea89a524c07 (patch)
treea7be768921000e125b7b0989f75739509c3bde6b /perl/Wallet/Kadmin
parentb7aedd9b7290d51dc5e46c4b123cd5f0f080f9c7 (diff)
Coding style fixes for Perl wallet code
Strip trailing whitespace, convert tabs to spaces, add newlines to exceptions, and remove a few stray blank lines and a few other minor coding style oddities. Make the SQL style consistent.
Diffstat (limited to 'perl/Wallet/Kadmin')
-rw-r--r--perl/Wallet/Kadmin/Heimdal.pm102
-rw-r--r--perl/Wallet/Kadmin/MIT.pm32
2 files changed, 60 insertions, 74 deletions
diff --git a/perl/Wallet/Kadmin/Heimdal.pm b/perl/Wallet/Kadmin/Heimdal.pm
index e4d175b..a8859bf 100644
--- a/perl/Wallet/Kadmin/Heimdal.pm
+++ b/perl/Wallet/Kadmin/Heimdal.pm
@@ -15,8 +15,7 @@ require 5.006;
use strict;
use vars qw($VERSION);
-use Heimdal::Kadm5 qw (KRB5_KDB_DISALLOW_ALL_TIX);
-
+use Heimdal::Kadm5 qw(KRB5_KDB_DISALLOW_ALL_TIX);
use Wallet::Config ();
# This version should be increased on any code change to this module. Always
@@ -37,7 +36,7 @@ sub valid_principal {
return scalar ($principal =~ m,^[\w-]+(/[\w_.-]+)?\z,);
}
-# Create a Heimdal::Kadm5 client object and return it. It should load
+# Create a Heimdal::Kadm5 client object and return it. It should load
# configuration from Wallet::Config.
sub kadmin_client {
unless (defined ($Wallet::Config::KEYTAB_PRINCIPAL)
@@ -45,15 +44,13 @@ sub kadmin_client {
and defined ($Wallet::Config::KEYTAB_REALM)) {
die "keytab object implementation not configured\n";
}
-
my $server = $Wallet::Config::KEYTAB_HOST || 'localhost';
- my $client = Heimdal::Kadm5::Client->new(
- RaiseErrors => 1,
- Server => $server,
- Principal => $Wallet::Config::KEYTAB_PRINCIPAL,
- Realm => $Wallet::Config::KEYTAB_REALM,
- Keytab => $Wallet::Config::KEYTAB_FILE,
- );
+ my @options = (RaiseErrors => 1,
+ Server => $server,
+ Principal => $Wallet::Config::KEYTAB_PRINCIPAL,
+ Realm => $Wallet::Config::KEYTAB_REALM,
+ Keytab => $Wallet::Config::KEYTAB_FILE);
+ my $client = Heimdal::Kadm5::Client->new (@options);
return $client;
}
@@ -70,16 +67,8 @@ sub exists {
$principal .= '@' . $Wallet::Config::KEYTAB_REALM;
}
my $kadmin = $self->{client};
- my $princdata = eval { $kadmin->getPrincipal ($principal) };
-
- if ($@) {
- die $@;
- return 0;
- } elsif ($princdata) {
- return 1;
- } else {
- return 0;
- }
+ my $princdata = $kadmin->getPrincipal ($principal);
+ return $princdata ? 1 : 0;
}
# Create a principal in Kerberos. Since this is only called by create, it
@@ -95,7 +84,7 @@ sub addprinc {
if ($Wallet::Config::KEYTAB_REALM) {
$principal .= '@' . $Wallet::Config::KEYTAB_REALM;
}
- die "error adding principal $principal: $@" if $@;
+ die "error adding principal $principal: $@\n" if $@;
return 1 if $exists;
# The way Heimdal::Kadm5 works, we create a principal object, create the
@@ -106,20 +95,19 @@ sub addprinc {
my $kadmin = $self->{client};
my $princdata = $kadmin->makePrincipal ($principal);
- # Disable the principal before creating, until we've randomized the
+ # Disable the principal before creating, until we've randomized the
# password.
my $attrs = $princdata->getAttributes;
$attrs |= KRB5_KDB_DISALLOW_ALL_TIX;
$princdata->setAttributes ($attrs);
my $password = 'inactive';
- my $retval = eval { $kadmin->createPrincipal ($princdata, $password, 0) };
- die "error adding principal $principal: $@" if $@;
- $retval = eval { $kadmin->randKeyPrincipal ($principal) };
- die "error adding principal $principal: $@" if $@;
- $retval = eval { $kadmin->enablePrincipal ($principal) };
+ eval {
+ $kadmin->createPrincipal ($princdata, $password, 0);
+ $kadmin->randKeyPrincipal ($principal);
+ $kadmin->enablePrincipal ($principal);
+ };
die "error adding principal $principal: $@" if $@;
-
return 1;
}
@@ -130,7 +118,7 @@ sub addprinc {
sub ktadd {
my ($self, $principal, $file, @enctypes) = @_;
unless ($self->valid_principal ($principal)) {
- die ("invalid principal name: $principal");
+ die "invalid principal name: $principal\n";
}
if ($Wallet::Config::KEYTAB_REALM) {
$principal .= '@' . $Wallet::Config::KEYTAB_REALM;
@@ -138,35 +126,35 @@ sub ktadd {
# The way Heimdal works, you can only remove enctypes from a principal,
# not add them back in. So we need to run randkeyPrincipal first each
- # time to restore all possible enctypes and then whittle them back down
+ # time to restore all possible enctypes and then whittle them back down
# to those we have been asked for this time.
my $kadmin = $self->{client};
eval { $kadmin->randKeyPrincipal ($principal) };
- die "error creating keytab for $principal: could not reinit enctypes: $@"
+ die "error creating keytab for $principal: could not reinit enctypes: $@\n"
if $@;
my $princdata = eval { $kadmin->getPrincipal ($principal) };
if ($@) {
- die "error creating keytab for $principal: $@";
+ die "error creating keytab for $principal: $@\n";
} elsif (!$princdata) {
- die "error creating keytab for $principal: principal does not exist";
+ die "error creating keytab for $principal: principal does not exist\n";
}
# Now actually remove any non-requested enctypes, if we requested any.
if (@enctypes) {
- my (%wanted);
- my $alltypes = $princdata->getKeytypes ();
- foreach (@enctypes) { $wanted{$_} = 1 }
- foreach my $key (@{$alltypes}) {
- my $keytype = ${$key}[0];
- next if exists $wanted{$keytype};
- eval { $princdata->delKeytypes ($keytype) };
- die "error removing keytype $keytype from the keytab: $@" if $@;
- }
- eval { $kadmin->modifyPrincipal ($princdata) };
+ my (%wanted);
+ my $alltypes = $princdata->getKeytypes ();
+ foreach (@enctypes) { $wanted{$_} = 1 }
+ foreach my $key (@{$alltypes}) {
+ my $keytype = ${$key}[0];
+ next if exists $wanted{$keytype};
+ eval { $princdata->delKeytypes ($keytype) };
+ die "error removing keytype $keytype from the keytab: $@\n" if $@;
+ }
+ eval { $kadmin->modifyPrincipal ($princdata) };
}
eval { $kadmin->extractKeytab ($princdata, $file) };
- die "error creating keytab for principal: $@" if $@;
+ die "error creating keytab for principal: $@\n" if $@;
return 1;
}
@@ -177,7 +165,7 @@ sub ktadd {
sub delprinc {
my ($self, $principal) = @_;
unless ($self->valid_principal ($principal)) {
- die ("invalid principal name: $principal");
+ die "invalid principal name: $principal\n";
}
my $exists = eval { $self->exists ($principal) };
die $@ if $@;
@@ -190,7 +178,7 @@ sub delprinc {
my $kadmin = $self->{client};
my $retval = eval { $kadmin->deletePrincipal ($principal) };
- die "error deleting $principal: $@" if $@;
+ die "error deleting $principal: $@\n" if $@;
return 1;
}
@@ -199,12 +187,12 @@ sub delprinc {
##############################################################################
# Create a new MIT kadmin object. Very empty for the moment, but later it
-# will probably fill out if we go to using a module rather than calling
+# will probably fill out if we go to using a module rather than calling
# kadmin directly.
sub new {
my ($class) = @_;
my $self = {
- client => kadmin_client (),
+ client => kadmin_client (),
};
bless ($self, $class);
return $self;
@@ -235,7 +223,7 @@ Wallet::Kadmin::MIT is an interface for keytab integration with the wallet,
specifically for using kadmin to create, delete, and add enctypes to keytabs.
It implments the wallet kadmin API and provides the necessary glue to MIT
Kerberos installs for each of these functions, while allowing the wallet
-to keep the details of what type of Kerberos installation is being used
+to keep the details of what type of Kerberos installation is being used
abstracted.
A keytab is an on-disk store for the key or keys for a Kerberos principal.
@@ -254,15 +242,15 @@ information about how to set wallet configuration.
=item addprinc(PRINCIPAL)
-Adds a new principal with a given name. The principal is created with a
-random password, and any other flags set by Wallet::Config. Returns true on
+Adds a new principal with a given name. The principal is created with a
+random password, and any other flags set by Wallet::Config. Returns true on
success, or throws an error if there was a failure in adding the principal.
-If the principal already exists, return true as we are bringing our
+If the principal already exists, return true as we are bringing our
expectations in line with reality.
=item addprinc(PRINCIPAL)
-Removes a principal with the given name. Returns true on success, or throws
+Removes a principal with the given name. Returns true on success, or throws
an error if there was a failure in removing the principal. If the principal
does not exist, return true as we are bringing our expectations in line with
reality.
@@ -270,8 +258,8 @@ reality.
=item ktadd(PRINCIPAL, FILE, ENCTYPES)
Creates a new keytab for the given principal, as the given file, limited to
-the enctypes supplied. The enctype values must be enctype strings recognized
-by Kerberos (strings like C<aes256-cts> or C<des-cbc-crc>). An error is
+the enctypes supplied. The enctype values must be enctype strings recognized
+by Kerberos (strings like C<aes256-cts> or C<des-cbc-crc>). An error is
thrown on failure or if the creation fails, otherwise true is returned.
=back
@@ -279,7 +267,7 @@ thrown on failure or if the creation fails, otherwise true is returned.
=head1 LIMITATIONS
Currently, this implementation calls an external B<kadmin> program rather
- than using a native Perl module and therefore requires B<kadmin> be
+ than using a native Perl module and therefore requires B<kadmin> be
installed and parses its output. It may miss some error conditions if the
output of B<kadmin> ever changes.
diff --git a/perl/Wallet/Kadmin/MIT.pm b/perl/Wallet/Kadmin/MIT.pm
index b7d4913..7bbb248 100644
--- a/perl/Wallet/Kadmin/MIT.pm
+++ b/perl/Wallet/Kadmin/MIT.pm
@@ -130,7 +130,7 @@ sub addprinc {
sub ktadd {
my ($self, $principal, $file, @enctypes) = @_;
unless ($self->valid_principal ($principal)) {
- die ("invalid principal name: $principal");
+ die "invalid principal name: $principal\n";
}
if ($Wallet::Config::KEYTAB_REALM) {
$principal .= '@' . $Wallet::Config::KEYTAB_REALM;
@@ -143,7 +143,7 @@ sub ktadd {
my $output = eval { $self->kadmin ("$command $principal") };
die ($@) if ($@);
if ($output =~ /^(?:kadmin|ktadd): (.*)/m) {
- die ("error creating keytab for $principal: $1");
+ die "error creating keytab for $principal: $1\n";
}
return 1;
}
@@ -154,7 +154,7 @@ sub ktadd {
sub delprinc {
my ($self, $principal) = @_;
unless ($self->valid_principal ($principal)) {
- die ("invalid principal name: $principal");
+ die "invalid principal name: $principal\n";
}
my $exists = eval { $self->exists ($principal) };
die $@ if $@;
@@ -167,7 +167,7 @@ sub delprinc {
my $output = eval { $self->kadmin ("delprinc -force $principal") };
die $@ if $@;
if ($output =~ /^delete_principal: (.*)/m) {
- die ("error deleting $principal: $1");
+ die "error deleting $principal: $1\n";
}
return 1;
}
@@ -177,12 +177,11 @@ sub delprinc {
##############################################################################
# Create a new MIT kadmin object. Very empty for the moment, but later it
-# will probably fill out if we go to using a module rather than calling
+# will probably fill out if we go to using a module rather than calling
# kadmin directly.
sub new {
my ($class) = @_;
- my $self = {
- };
+ my $self = {};
bless ($self, $class);
return $self;
}
@@ -212,7 +211,7 @@ Wallet::Kadmin::MIT is an interface for keytab integration with the wallet,
specifically for using kadmin to create, delete, and add enctypes to keytabs.
It implments the wallet kadmin API and provides the necessary glue to MIT
Kerberos installs for each of these functions, while allowing the wallet
-to keep the details of what type of Kerberos installation is being used
+to keep the details of what type of Kerberos installation is being used
abstracted.
A keytab is an on-disk store for the key or keys for a Kerberos principal.
@@ -231,15 +230,15 @@ information about how to set wallet configuration.
=item addprinc(PRINCIPAL)
-Adds a new principal with a given name. The principal is created with a
-random password, and any other flags set by Wallet::Config. Returns true on
+Adds a new principal with a given name. The principal is created with a
+random password, and any other flags set by Wallet::Config. Returns true on
success, or throws an error if there was a failure in adding the principal.
-If the principal already exists, return true as we are bringing our
+If the principal already exists, return true as we are bringing our
expectations in line with reality.
=item addprinc(PRINCIPAL)
-Removes a principal with the given name. Returns true on success, or throws
+Removes a principal with the given name. Returns true on success, or throws
an error if there was a failure in removing the principal. If the principal
does not exist, return true as we are bringing our expectations in line with
reality.
@@ -247,8 +246,8 @@ reality.
=item ktadd(PRINCIPAL, FILE, ENCTYPES)
Creates a new keytab for the given principal, as the given file, limited to
-the enctypes supplied. The enctype values must be enctype strings recognized
-by Kerberos (strings like C<aes256-cts> or C<des-cbc-crc>). An error is
+the enctypes supplied. The enctype values must be enctype strings recognized
+by Kerberos (strings like C<aes256-cts> or C<des-cbc-crc>). An error is
thrown on failure or if the creation fails, otherwise true is returned.
=back
@@ -256,7 +255,7 @@ thrown on failure or if the creation fails, otherwise true is returned.
=head1 LIMITATIONS
Currently, this implementation calls an external B<kadmin> program rather
- than using a native Perl module and therefore requires B<kadmin> be
+than using a native Perl module and therefore requires B<kadmin> be
installed and parses its output. It may miss some error conditions if the
output of B<kadmin> ever changes.
@@ -269,7 +268,6 @@ from L<http://www.eyrie.org/~eagle/software/wallet/>.
=head1 AUTHORS
-Russ Allbery <rra@stanford.edu>
-Jon Robertson <jonrober@stanford.edu>
+Russ Allbery <rra@stanford.edu> and Jon Robertson <jonrober@stanford.edu>.
=cut