help logoLON-CAPA Help


When a user is assigned an authentication type of "Local authentication" , the perl module /home/httpd/lib/perl/localauth.pm will be used to evaluate the user's credentials. The documentation included in the stub provided with a LON-CAPA installation describes the basic operation of localauth.pm

The localauth routine receives four arguments (in the order: two required, one optrional, another required).

  1. the username the user types in.

  2. the password the user typed in.

  3. optional information stored when the authentication mechanism was specified for the user ("Local authentication with argument: ....")

  4. the domain the user typed in.

The routine will return 1 if the user is authenticated and 0 otherwise, and it can optionally return a negative value for an error condition. This negative value will be logged along with the username used in the failed authentication which resulted in the error condition.

A common use of localauth.pm is to connect with an LDAP service.

package localauth;

use strict;

use Net::LDAP;

use Net::LDAPS;

sub localauth {

my ($username,$password) = @_;

my $ldap_host_name = ''; # insert the host name of your ldap server, e.g., ldap.msu.edu

my $ldap_ca_file_name = ''; # insert the ldap certificate filename - include absolute path

# certificate is required if you wish to encrypt the password.

# e.g., /home/http/perl/lib/local/ldap.certificate

my $ldap_search_base = ''; # ldap search base, this might be set to 'o=msu.edu'.

my $ldap = Net::LDAPS->new(

$ldap_host_name,

verify => 'require', # 'require' -> a certificate is needed, -> 'none' if no certificate used

cafile => $ldap_ca_file_name,

);

if (!(defined($ldap))) {

return (0);
}

$ldap->bind;

my $search_string = '(uid=".$username.")';

my $mesg = $ldap->search (

base => $ldap_search_base,

filter => $search_string,

attrs => ['dn'] ,

);

if ($mesg->code) {

$ldap->unbind;

$ldap->disconnect;

return (0);

}

my @entries = $mesg->all_entries;

if (@entries > 0) {

$ldap->unbind;

$ldap->disconnect;

return (0);

}

$mesg = $ldap->bind (

dn => $entries[0]->dn,

password => $password,

);

$ldap->unbind;

$ldap->disconnect;

if ($mesg->code) {

return (0)
}

return (1);

}

1;