Authen-SASL-XS
view release on metacpan or search on metacpan
C<setpass> sets a new password (depends on the mechanism if the setpass callback
is called). C<checkpass> checks a password for the user (calls the checkpass
callback).
For both function see the man pages of the Cyrus SASL for a detailed description.
Both functions return true on success, false otherwise.
=pod
=item global_listmech ( )
C<global_listmech> is only available when using Cyrus-SASL 2.x library.
It returns an array with all mechanisms loaded by the library.
=pod
=item encode ( STRING )
=item decode ( STRING )
Cyrus-SASL developers suggest using the C<encode> and C<decode> functions
for every traffic which will run over the network after a successful authentication
C<encode> returns the encrypted string generated from STRING.
C<decode> returns the decrypted string generated from STRING.
It depends on the used mechanism how secure the encryption will be.
=pod
=item error ( )
C<error> returns an array with all known error messages.
Basicly the sasl_errstring function is called with the current error_code.
When using Cyrus-SASL 2.x library also the string returned by sasl_errdetail
is given back. Additionally the special Authen::SASL::XS advise is
returned if set.
After calling the C<error> function, the error code and the special advice
are thrown away.
=pod
=item code ( )
C<code> returns the current Cyrus-SASL error code.
=pod
=item mechanism ( )
C<mechanism> returns the current used authentication mechanism.
=pod
=item need_step ( )
C<need_step> returns true if another step is need by the SASL library. Otherwise
false is returned. You can also use C<code == 1> but it looks smarter I think.
That's why we all using perl, eh?
=pod
=back
=head1 EXAMPLE
=head2 Server-side
# The example uses Cyrus-SASL v2
# Set the SASL_PATH to the location of the SASL-Plugins
# default is /usr/lib/sasl2
$ENV{'SASL_PATH'} = "/opt/products/sasl/2.1.15/lib/sasl2";
#
my $sasl = Authen::SASL->new (
mechanism => "PLAIN",
callback => {
checkpass => \&checkpass,
canonuser => \&canonuser,
}
);
# Creating the Authen::SASL::XS object
my $conn = $sasl->server_new("service","","ip;port local","ip;port remote");
# Clients first string (maybe "", depends on mechanism)
# Client has to start always
sendreply( $conn->server_start( &getreply() ) );
while ($conn->need_step) {
sendreply( $conn->server_step( &getreply() ) );
}
if ($conn->code == 0) {
print "Negotiation succeeded.\n";
} else {
print "Negotiation failed.\n";
}
=head2 Client-side
# The example uses Cyrus-SASL v2
# Set the SASL_PATH to the location of the SASL-Plugins
# default is /usr/lib/sasl2
$ENV{'SASL_PATH'} = "/opt/products/sasl/2.1.15/lib/sasl2";
#
my $sasl = Authen::SASL->new (
mechanism => "PLAIN",
callback => {
user => \&getusername,
pass => \&getpassword,
}
);
# Creating the Authen::SASL::XS object
my $conn = $sasl->client_new("service", "hostname.domain.tld");
( run in 2.028 seconds using v1.01-cache-2.11-cpan-5a3173703d6 )