Some minor bug fixes

This commit is contained in:
Martin Kamerbeek 2002-11-24 16:18:50 +00:00
parent 6d10ab7481
commit eda4d29de4
3 changed files with 186 additions and 17 deletions

View file

@ -1,7 +1,7 @@
package WebGUI::Authentication::LDAP;
#-------------------------------------------------------------------
# This module is made by M. Kamerbeek of Procolix (procolix.com)
# This module is copyright by M. Kamerbeek of Procolix (procolix.com)
# for WebGUI and released under GNU/GPL.
#-------------------------------------------------------------------
@ -16,7 +16,6 @@ package WebGUI::Authentication::LDAP;
#-------------------------------------------------------------------
use strict;
use WebGUI::SQL;
use WebGUI::Session;
use WebGUI::HTMLForm;
use WebGUI::Authentication;
@ -52,7 +51,7 @@ sub hasBadUserData {
$ldap = Net::LDAP->new($uri->host, %args) or $error .= WebGUI::International::get(79);
return $error if ($error);
$ldap->bind;
$search = $ldap->search (base => $uri->dn, filter => $session{setting}{ldapId}."=".$session{form}{ldapId});
$search = $ldap->search (base => $uri->dn, filter => $session{setting}{ldapId}."=".$session{form}{loginId});
if (defined $search->entry(0)) {
$connectDN = "cn=".$search->entry(0)->get_value("cn");
$ldap->unbind;
@ -60,7 +59,7 @@ sub hasBadUserData {
$auth = $ldap->bind(dn=>$connectDN, password=>$session{form}{ldapPassword});
if ($auth->code == 48 || $auth->code == 49) {
$error = '<li>'.WebGUI::International::get(68);
WebGUI::ErrorHandler::warn("Invalid LDAP information for registration of LDAP ID: ".$session{form}{ldapId});
WebGUI::ErrorHandler::warn("Invalid LDAP information for registration of LDAP ID: ".$session{form}{loginId});
} elsif ($auth->code > 0) {
$error = '<li>LDAP error "'.$ldapStatusCode{$auth->code}.'" occured. '.WebGUI::International::get(69);
WebGUI::ErrorHandler::warn("LDAP error: ".$ldapStatusCode{$auth->code});
@ -76,7 +75,7 @@ sub hasBadUserData {
#-------------------------------------------------------------------
sub validateUser {
my ($userId, $password, $userData, $uri, $port, %args, $ldap, $auth, $error);
my ($userId, $password, $userData, $uri, $port, %args, $ldap, $auth, $result);
($userId, $password) = @_;
$userData = WebGUI::Authentication::getParams($userId, 'LDAP');
@ -88,21 +87,22 @@ sub validateUser {
$port = $uri->port;
}
%args = (port => $port);
$ldap = Net::LDAP->new($uri->host, %args) or $error = WebGUI::International::get(79);
return $error if $error;
$ldap = Net::LDAP->new($uri->host, %args) or $result = WebGUI::International::get(79);
return $result if $result;
$auth = $ldap->bind(dn=>$$userData{connectDN}, password=>$session{form}{identifier});
if ($auth->code == 48 || $auth->code == 49) {
$error = WebGUI::International::get(68);
$result = WebGUI::International::get(68);
WebGUI::ErrorHandler::security("login to account ".$session{form}{username}." with invalid information.");
} elsif ($auth->code > 0) {
$error .= 'LDAP error "'.$ldapStatusCode{$auth->code}.'" occured.';
$error .= WebGUI::International::get(69);
$result .= 'LDAP error "'.$ldapStatusCode{$auth->code}.'" occured.';
$result .= WebGUI::International::get(69);
WebGUI::ErrorHandler::warn("LDAP error: ".$ldapStatusCode{$auth->code});
} else {
$error = 1;
$result = 1;
}
$ldap->unbind;
return $error
return $result;
}
#-------------------------------------------------------------------------
@ -126,7 +126,11 @@ sub formAddUser {
#-------------------------------------------------------------------
sub saveAddUser {
WebGUI::Authentication::saveParams($session{form}{uid},'LDAP',{connectDN => $session{form}{connectDN}, ldapURL => $session{form}{ldapURL}});
WebGUI::Authentication::saveParams($session{form}{uid},'LDAP',
{
connectDN => $session{form}{connectDN},
ldapURL => $session{form}{ldapURL}
});
}
#-------------------------------------------------------------------
@ -161,7 +165,11 @@ sub saveCreateAccount {
}
$ldap->unbind;
WebGUI::Authentication::saveParams($uid,'LDAP',{connectDN => $connectDN, ldapURL => $session{setting}{ldapURL}});
WebGUI::Authentication::saveParams($uid,'LDAP',
{
connectDN => $connectDN,
ldapURL => $session{setting}{ldapURL}
});
}
#-------------------------------------------------------------------
@ -191,7 +199,11 @@ sub formEditUser {
#-------------------------------------------------------------------
sub saveEditUser {
WebGUI::Authentication::saveParams($session{form}{uid},'LDAP',{connectDN => $session{form}{connectDN}, ldapURL => $session{form}{ldapURL}});
WebGUI::Authentication::saveParams($session{form}{uid},'LDAP',
{
connectDN => $session{form}{connectDN},
ldapURL => $session{form}{ldapURL}
});
}

View file

@ -0,0 +1,158 @@
package WebGUI::Authentication::SMB;
#-------------------------------------------------------------------
# This module is copyright by M. Kamerbeek of Procolix (procolix.com)
# for WebGUI and released under GNU/GPL.
#-------------------------------------------------------------------
#-------------------------------------------------------------------
# WebGUI is Copyright 2001-2002 Plain Black LLC.
#-------------------------------------------------------------------
# Please read the legal notices (docs/legal.txt) and the license
# (docs/license.txt) that came with this distribution before using
# this software.
#-------------------------------------------------------------------
# http://www.plainblack.com info@plainblack.com
#-------------------------------------------------------------------~
use strict;
use WebGUI::Session;
use WebGUI::HTMLForm;
use WebGUI::Authentication;
use Authen::Smb;
use warnings;
my %smbError = (
1 => 'SMB Server Error (1)<br>Something went wrong accessing the domain controller. Perhaps the connection timed out. Please try again or contact your sysadmin.',
2 => 'SMB Protocol Error (2)<br>Please contact your sysadmin',
3 => 'SMB Logon Error (3)<br>You have supplied an invalid username/password pair. Probably a typo, please try again.'
);
#-------------------------------------------------------------------
sub hasBadUserData {
my ($pdc, $bdc, $ntDomain, $smbLogin, $smb, $error);
$pdc = $session{setting}{smbPDC};
$bdc = $session{setting}{smbBDC};
$ntDomain = $session{setting}{smbDomain};
$smbLogin = $session{form}{loginId};
$smb = Authen::Smb::authen($smbLogin, $session{form}{smbPassword}, $pdc, $bdc, $ntDomain);
if ($smb > 0) {
$error = '<li>'. $smbError{$smb} . "pdc: $pdc, bdc: $bdc, domain: $ntDomain";
}
return $error;
}
#-------------------------------------------------------------------
sub validateUser {
my ($uid, $password, $userData, $smb, $result);
($uid, $password) = @_;
$userData = WebGUI::Authentication::getParams($uid, 'SMB');
$smb = Authen::Smb::authen($userData->{smbLogin}, $password, $userData->{smbPDC}, $userData->{smbBDC}, $userData->{smbDomain});
if ($smb > 0) {
$result = '<li>'. $smbError{$smb} . <br> ."Login: *$userData->{smbLogin}, PDC: *$userData->{smbPDC}*, BDC: *$userData->{smbBDC}*, Domain: *$userData->{smbDomain}*";
} else {
$result = 1;
}
return $result;
}
#-------------------------------------------------------------------------
# Below are the subs that create and save the forms used for inputting
# config data for this auth module. The 'form' and 'save' subs of each
# from are so related that I've grouped by function. Apart from the
# 'save' and 'form' stuff the subs are still in alphabetical order though.
#-------------------------------------------------------------------------
#-------------------------------------------------------------------
sub formAddUser {
my $f;
$f = WebGUI::HTMLForm->new;
$f->readOnly("<b>SMB Authentication Options</b>");
$f->text("smbPDC","PDC",$session{setting}{smbPDC});
$f->text("smbBDC","BDC",$session{setting}{smbBDC});
$f->text("smbDomain","NT Domain",$session{setting}{smbDomain});
$f->text("smbLogin","NT Login name",'');
return $f->printRowsOnly;
}
#-------------------------------------------------------------------
sub saveAddUser {
WebGUI::Authentication::saveParams($session{form}{uid},'SMB',
{
smbPDC => $session{form}{smbPDC},
smbBDC => $session{form}{smbBDC},
smbDomain => $session{form}{smbDomain},
smbLogin => $session{form}{smbLogin}
});
}
#-------------------------------------------------------------------
sub formCreateAccount {
my $f;
$f = WebGUI::HTMLForm->new;
$f->password("smbPassword","NT Password");
return $f->printRowsOnly;
}
#-------------------------------------------------------------------
sub saveCreateAccount {
my $uid;
$uid = shift;
WebGUI::Authentication::saveParams($uid,'SMB',
{
smbPDC => $session{setting}{smbPDC},
smbBDC => $session{setting}{smbBDC},
smbDomain => $session{setting}{smbDomain},
smbLogin => $session{form}{loginId}
});
}
#-------------------------------------------------------------------
sub formEditUserSettings {
my $f;
$f = WebGUI::HTMLForm->new;
$f->readOnly("<b>SMB Authentication Options</b>");
$f->text("smbPDC","PDC",$session{setting}{smbPDC});
$f->text("smbBDC","BDC",$session{setting}{smbBDC});
$f->text("smbDomain","NT Domain",$session{setting}{smbDomain});
return $f->printRowsOnly;
}
#-------------------------------------------------------------------
sub formEditUser {
my ($f, $userData);
$userData = WebGUI::Authentication::getParams($session{form}{uid}, 'SMB');
$f = WebGUI::HTMLForm->new;
$f->readOnly("<b>SMB Authentication Options</b>");
$f->text("smbPDC","PDC",$$userData{smbPDC});
$f->text("smbBDC","BDC",$$userData{smbBDC});
$f->text("smbDomain","NT Domain",$$userData{smbDomain});
$f->text("smbLogin","NT Login name",$$userData{smbLogin});
return $f->printRowsOnly;
}
#-------------------------------------------------------------------
sub saveEditUser {
WebGUI::Authentication::saveParams($session{form}{uid},'SMB',
{
smbPDC => $session{form}{smbPDC},
smbBDC => $session{form}{smbBDC},
smbDomain => $session{form}{smbDomain},
smbLogin => $session{form}{smbLogin}
});
}
1;

View file

@ -1,7 +1,7 @@
package WebGUI::Authentication::WebGUI;
#-------------------------------------------------------------------
# This module is made by M. Kamerbeek of Procolix (procolix.com)
# This module is copyright by M. Kamerbeek of Procolix (procolix.com)
# for WebGUI and released under GNU/GPL.
#-------------------------------------------------------------------
@ -16,7 +16,6 @@ package WebGUI::Authentication::WebGUI;
#-------------------------------------------------------------------
use strict;
use WebGUI;
use WebGUI::Session;
use WebGUI::Authentication;
use WebGUI::HTMLForm;