From 5d23fb605bc40f699ab677e6ee13a7e498c9fb14 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Sven=20Sch=C3=B6ling?= Date: Wed, 2 Jun 2010 17:01:38 +0200 Subject: [PATCH] Auth Konstanten ausgelagert in ein eigenes Package. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Dadurch keine Probleme mit zirkulären Includes mehr. Ausserdem DBI an der richtigen Stelle eingebunden. --- SL/Auth.pm | 9 ++----- SL/Auth/Constants.pm | 63 ++++++++++++++++++++++++++++++++++++++++++++ SL/Auth/DB.pm | 10 +++---- SL/Auth/LDAP.pm | 12 ++++----- 4 files changed, 75 insertions(+), 19 deletions(-) create mode 100644 SL/Auth/Constants.pm diff --git a/SL/Auth.pm b/SL/Auth.pm index 4b6f2fa20..10855e25b 100644 --- a/SL/Auth.pm +++ b/SL/Auth.pm @@ -1,18 +1,13 @@ package SL::Auth; -use constant OK => 0; -use constant ERR_PASSWORD => 1; -use constant ERR_BACKEND => 100; - -use constant SESSION_OK => 0; -use constant SESSION_NONE => 1; -use constant SESSION_EXPIRED => 2; +use DBI; use Digest::MD5 qw(md5_hex); use IO::File; use Time::HiRes qw(gettimeofday); use List::MoreUtils qw(uniq); +use SL::Auth::Constants qw(:all); use SL::Auth::DB; use SL::Auth::LDAP; diff --git a/SL/Auth/Constants.pm b/SL/Auth/Constants.pm new file mode 100644 index 000000000..4fe520a45 --- /dev/null +++ b/SL/Auth/Constants.pm @@ -0,0 +1,63 @@ +package SL::Auth::Constants; + +use strict; + +use Exporter qw(import); + +our %EXPORT_TAGS = ( + OK => [ qw( + OK + ) ], + ERR => [ qw( + ERR_PASSWORD + ERR_BACKEND + ) ], + SESSION => [ qw( + SESSION_OK + SESSION_NONE + SESSION_EXPIRED + ) ], +); + +# add all the other ":class" tags to the ":all" class, +# deleting duplicates +{ + my %seen; + push @{$EXPORT_TAGS{all}}, grep {!$seen{$_}++} @$_ for values %EXPORT_TAGS; +} + +Exporter::export_ok_tags('all'); + +use constant OK => 0; +use constant ERR_PASSWORD => 1; +use constant ERR_BACKEND => 100; + +use constant SESSION_OK => 0; +use constant SESSION_NONE => 1; +use constant SESSION_EXPIRED => 2; + +1; + +__END__ + +=head1 NAME + +SL::Auth::Constants - COnstants for Auth module + +=head1 SYNOPSIS + + use SL::Auth::Constants qw(:all); + + OK == $auth->authenticate($user, $pass) or die; + +=head1 DESCRIPTION + +This module provides status constants for authentication handling + +=head1 FUNCTIONS + +=head1 BUGS + +=head1 AUTHOR + +=cut diff --git a/SL/Auth/DB.pm b/SL/Auth/DB.pm index d4e4d48cc..2ad131a8d 100644 --- a/SL/Auth/DB.pm +++ b/SL/Auth/DB.pm @@ -1,8 +1,6 @@ package SL::Auth::DB; -use DBI; - -#use SL::Auth; +use SL::Auth::Constants qw(:all); use SL::DBUtils; use strict; @@ -34,7 +32,7 @@ sub authenticate { if (!$dbh) { $main::lxdebug->leave_sub(); - return SL::Auth->ERR_BACKEND(); + return ERR_BACKEND; } my $query = qq|SELECT password FROM auth."user" WHERE login = ?|; @@ -45,7 +43,7 @@ sub authenticate { $main::lxdebug->leave_sub(); - return $password eq $stored_password ? SL::Auth->OK() : SL::Auth->ERR_PASSWORD(); + return $password eq $stored_password ? OK : ERR_PASSWORD; } sub can_change_password { @@ -64,7 +62,7 @@ sub change_password { if (!$dbh) { $main::lxdebug->leave_sub(); - return SL::Auth->ERR_BACKEND() + return ERR_BACKEND; } $password = crypt $password, substr($login, 0, 2) if (!$is_crypted); diff --git a/SL/Auth/LDAP.pm b/SL/Auth/LDAP.pm index 10d15c0b8..1b33de36a 100644 --- a/SL/Auth/LDAP.pm +++ b/SL/Auth/LDAP.pm @@ -2,7 +2,7 @@ package SL::Auth::LDAP; use English '-no_match_vars'; -#use SL::Auth; +use SL::Auth::Constants qw(:all); use strict; @@ -146,14 +146,14 @@ sub authenticate { if ($is_crypted) { $main::lxdebug->leave_sub(); - return SL::Auth->ERR_BACKEND(); + return ERR_BACKEND; } my $ldap = $self->_connect(); if (!$ldap) { $main::lxdebug->leave_sub(); - return SL::Auth->ERR_BACKEND(); + return ERR_BACKEND; } my $dn = $self->_get_user_dn($ldap, $login); @@ -162,7 +162,7 @@ sub authenticate { if (!$dn) { $main::lxdebug->leave_sub(); - return SL::Auth->ERR_BACKEND(); + return ERR_BACKEND; } my $mesg = $ldap->bind($dn, 'password' => $password); @@ -171,7 +171,7 @@ sub authenticate { $main::lxdebug->leave_sub(); - return $mesg->is_error() ? SL::Auth->ERR_PASSWORD() : SL::Auth->OK(); + return $mesg->is_error() ? ERR_PASSWORD : OK; } sub can_change_password { @@ -179,7 +179,7 @@ sub can_change_password { } sub change_password { - return SL::Auth->ERR_BACKEND(); + return ERR_BACKEND; } sub verify_config { -- 2.20.1