In what follows $principal denotes an instance of Heimdal::Kadm5::Principal, $name denotes a principal
name, $bitmask denotes an (you guessed it!) integer representing a bitmask, $seconds an integer
representing seconds since the epoch (time_t value), $client a Heimdal::Kadm5::Client instance. Other
variables should be even more obvious or are explained in the text.
Heimdal::Kadm5::Client
Minimal use:
my $client =
Heimdal::Kadm5::Client->new(Client=>'you');
This would connect using a password for 'you@DEFREALM'. The password is prompted on the active tty.
A more complex example:
my $client =
Heimdal::Kadm5::Client->new(
RaiseErrors => 1,
Server => 'adm.somewhere.net',
Port => '8899',
# Required:
Client => 'you/admin',
Realm => 'OTHER.REALM',
# --- Either ---
Password => 'very secret',
# --- Or ---
Keytab => '$HOME/mysecret.keytab'
);
Be very careful when using the Password parameter: it implies storing the password in the script or
reading it from command line arguments or through some other means. Only use this on secured hosts, never
from NFS mounted filesystems, and never using principals allowed to perform all operations on the kdc. In
this case using a keytable (see ktutil(8) for information on how to create keytabs) is a better way to
go.
Normally both the Server, Port and Realm parameters are determined from the kerberos context
(configuration files, DNS etc etc) but you may need to override them. If you leave out the password or
set it to undef the client library will prompt you for a password. You must include the Client parameter
which is usually your admin or root -instance depending on your local system of belief. If for some
reason the client connection cannot be initialized undef is returned and errors are sent to warn unless
the RaiseError parameter is set in which case all errors are propagated by die.
my @names = $client->getPrincipals($pattern);
The getPrincipals method returns a list of principals matching $pattern which is not a regular expression
but rather a glob-like animal. For instance '*/admin@REALM' is an ok pattern. The elements of the list
are principal names which can be used to obtain Heimdal::Kadm5::Principal object using
my $principal = $client->getPrincipal($name);
which returns a Heimdal::Kadm5::Principal object (see the next section for details).
my $principal = $client->makePrincipal($name);
The makePrincipal method takes a principal name and creates an empty Heimdal::Kadm5::Principal object.
This is intended for adding principals to the kdc. After creating the principal using makePrincipal use
the accessor methods in Heimdal::Kadm5::Principal to set values before adding the principal using
$client->createPrincipal($principal,$password,$mask);
If $mask is set this value is used to determine which elements of the principal to include in the
creation. Normally this value is automatically determined by tracking the uses of the accessor methods in
the Heimdal::Kadm5::Principal class.
Modifications to an existing principal is done using this method:
$client->createPrincipal($principal,$mask);
The $mask value works in the same way as described above for createPrincipal. It is sometimes useful to
disable (lock) a principal, for instance when several operations must be performed. The following
methods can be used:
$client->disablePrincipal($name);
$client->enablePrincipal($name);
Other methods which modify the kdc are and the use of which should be obvious:
$client->changePassword($name, $password);
$client->deletePrincipal($name);
$client->renamePrincipal($name, $newname);
$client->randKeyPrincipal($name);
This method creates a random set of keys for the principal named $name. This is typically done for
service principals. When creating a new service principal it is probably a good idea to create the
principal with some initial password, disable the principal, apply the randKeyPrincipal method and then
enable the principal.
$client->handle->c_flush();
This method flushes all modifications to the datastore. It is called automatically when the client handle
is DESTROYed if any modifications (password change, create, rename or delete has been performed);
$client->extractKeytab($principal,$keytab);
This method extracts the keys belonging to the principal object to the keytab (optionally) specified by
the second argument. If the second argument is missing it defaults to the standard default keytab,
typically /etc/krb5.keytab.
Heimdal::Kadm5::Principal
$principal->dump($io);
Dumps a representation of $principal on the $io handle (which defaults to \*STDOUT). This is mostly
usable for debugging or simple scripts.
my $name = $principal->getPrincipal(); $principal->setPrincipal($name);
Gets and sets the principal name.
my $seconds = $principal->getPrincExpireTime(); $principal->setPrincExpireTime($seconds);
Gets and sets the time this principal expires.
my $seconds = $principal->getLastPwdChange();
Returns the last time this principal's password was changed.
my $kvno = $principal->getKvno();
Returns the key version number of this principal's password.
my $mkvno = $principal->getMKvno();
Returns this principal's MKvno.
my $seconds = $principal->getPwExpiration(); $principal->setPwExpiration($seconds);
Gets and sets the password expriation time.
my $seconds = $principal->getMaxLife(); $principal->setMaxLife($seconds);
Gets and sets the maximum lifetime of a ticket.
my $seconds = $principal->getMaxRenewableLife(); $principal->setMaxRenewableLife($seconds);
Gets and sets the maximum renewable ticket lifetime.
my $name = $principal->getModName();
Returns the principal name of the last modifier of the entry. Not currently (as of heimdal 0.1g)
supported by heimdal and contains undef.
my $seconds = $principal->getModDate();
Returns the date of last modification of the entry.
my $policyname = $principal->getPolicy();
getPolicy returns undef if no policy is set. Policies are not currently supported (as of heimdal 0.1g)
and always returns undef.
my $seconds = $principal->getLastSuccess();
Last time a successful authentication was done against this principal.
my $seconds= $principal->getLastFailed();
Last time a failed authentication was done against this principal.
my $nfailed = $principal->getFailAuthCounts();
How many failed login attempts was done against this principal.
my $bitmask = $principal->getAttributes();
The bitmask of attributes for this principal.
my @names = $principal->getAttributeNames();
The list of attribute names for this principal, expanded from the bitmask.
my $arrayref = $principal->getKeyTypes();
getKeyTypes returns an array reference consisting of a list of array references with two elements each:
[keytype,salt]. The keytype and salt are strings which describe a key associated with the principal.
Note that this data may not be present depending on how the principal was obtained.
my $password = $principal->getPassword();
getPassword returns the password if its saved in the Kerberos database. Not the that principal object
need to fetched with the bit KADM5_TL_DATA set in the mask.