[LON-CAPA-cvs] cvs: loncom(version_2_11_X) /auth lonauth.pm

raeburn raeburn at source.lon-capa.org
Sat Feb 26 21:06:20 EST 2022


raeburn		Sun Feb 27 02:06:20 2022 EDT

  Modified files:              (Branch: version_2_11_X)
    /loncom/auth	lonauth.pm 
  Log:
  - For 2.11
    Backport 1.172
  
  
Index: loncom/auth/lonauth.pm
diff -u loncom/auth/lonauth.pm:1.121.2.24 loncom/auth/lonauth.pm:1.121.2.25
--- loncom/auth/lonauth.pm:1.121.2.24	Thu Dec 30 05:11:28 2021
+++ loncom/auth/lonauth.pm	Sun Feb 27 02:06:20 2022
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # User Authentication Module
 #
-# $Id: lonauth.pm,v 1.121.2.24 2021/12/30 05:11:28 raeburn Exp $
+# $Id: lonauth.pm,v 1.121.2.25 2022/02/27 02:06:20 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -421,9 +421,33 @@
 # --------------------------------------------------------------------- Failed?
 
     if ($authhost eq 'no_host') {
-	&failed($r,'Username and/or password could not be authenticated.',
-		\%form);
-        return OK;
+        my $pwdverify;
+        if (&Apache::lonnet::homeserver($form{'uname'},$form{'udom'}) eq 'no_host') {
+            my %possunames = &alternate_unames_check($form{'uname'},$form{'udom'});
+            if (keys(%possunames) > 0) {
+                foreach my $rulematch (keys(%possunames)) {
+                    my $possuname = $possunames{$rulematch};
+                    if (($possuname ne '') && ($possuname =~ /^$match_username$/)) {
+                        $authhost=Apache::lonnet::authenticate($possuname,$upass,
+                                                               $form{'udom'},undef,
+                                                               $clientcancheckhost);
+                        if (($authhost eq 'no_host') || ($authhost eq 'no_account_on_host')) {
+                            next;
+                        } elsif (($authhost ne '') && (&Apache::lonnet::hostname($authhost) ne '')) {
+                            $pwdverify = 1;
+                            &Apache::lonnet::logthis("Authenticated user: $possuname was submitted as: $form{'uname'}");
+                            $form{'uname'} = $possuname;
+                            last;
+                        }
+                    }
+                }
+            }
+        }
+        unless ($pwdverify) {
+            &failed($r,'Username and/or password could not be authenticated.',
+                    \%form);
+            return OK;
+        }
     } elsif ($authhost eq 'no_account_on_host') {
         if ($defaultauth) {
             my $domdesc = &Apache::lonnet::domain($form{'udom'},'description');
@@ -811,6 +835,20 @@
     return;
 }
 
+sub alternate_unames_check {
+    my ($uname,$udom) = @_;
+    my %possunames;
+    my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
+    if (ref($domdefs{'unamemap_rule'}) eq 'ARRAY') {
+        if (@{$domdefs{'unamemap_rule'}} > 0) {
+            %possunames =
+                &Apache::lonnet::inst_rulecheck($udom,$uname,undef,
+                                                'unamemap',$domdefs{'unamemap_rule'});
+        }
+    }
+    return %possunames;
+}
+
 1;
 __END__
 




More information about the LON-CAPA-cvs mailing list