[LON-CAPA-cvs] cvs: loncom(version_2_11_X) / lond

raeburn raeburn at source.lon-capa.org
Thu Aug 22 10:51:52 EDT 2019


raeburn		Thu Aug 22 14:51:52 2019 EDT

  Modified files:              (Branch: version_2_11_X)
    /loncom	lond 
  Log:
  - For 2.11
    Backport 1.558
  
  
Index: loncom/lond
diff -u loncom/lond:1.489.2.32 loncom/lond:1.489.2.33
--- loncom/lond:1.489.2.32	Thu Aug  1 18:17:02 2019
+++ loncom/lond	Thu Aug 22 14:51:51 2019
@@ -2,7 +2,7 @@
 # The LearningOnline Network
 # lond "LON Daemon" Server (port "LOND" 5663)
 #
-# $Id: lond,v 1.489.2.32 2019/08/01 18:17:02 raeburn Exp $
+# $Id: lond,v 1.489.2.33 2019/08/22 14:51:51 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -63,7 +63,7 @@
 my $status='';
 my $lastlog='';
 
-my $VERSION='$Revision: 1.489.2.32 $'; #' stupid emacs
+my $VERSION='$Revision: 1.489.2.33 $'; #' stupid emacs
 my $remoteVERSION;
 my $currenthostid="default";
 my $currentdomainid;
@@ -2107,12 +2107,84 @@
     }
     if($validated) {
 	my $realpasswd  = &get_auth_type($udom, $uname); # Defined since authd.
-	
 	my ($howpwd,$contentpwd)=split(/:/,$realpasswd);
+        my $notunique;
 	if ($howpwd eq 'internal') {
 	    &Debug("internal auth");
             my $ncpass = &hash_passwd($udom,$npass);
-	    if(&rewrite_password_file($udom, $uname, "internal:$ncpass")) {
+            my (undef,$method, at rest) = split(/!/,$contentpwd);
+            if ($method eq 'bcrypt') {
+                my %passwdconf = &Apache::lonnet::get_passwdconf($udom);
+                if (($passwdconf{'numsaved'}) && ($passwdconf{'numsaved'} =~ /^\d+$/)) {
+                    my @oldpasswds;
+                    my $userpath = &propath($udom,$uname);
+                    my $fullpath = $userpath.'/oldpasswds';
+                    if (-d $userpath) {
+                        my @oldfiles;
+                        if (-e $fullpath) {
+                            if (opendir(my $dir,$fullpath)) {
+                                (@oldfiles) = grep(/^\d+$/,readdir($dir));
+                                closedir($dir);
+                            }
+                            if (@oldfiles) {
+                                @oldfiles = sort { $b <=> $a } (@oldfiles);
+                                my $numremoved = 0;
+                                for (my $i=0; $i<@oldfiles; $i++) {
+                                    if ($i>=$passwdconf{'numsaved'}) {
+                                        if (-f "$fullpath/$oldfiles[$i]") {
+                                            if (unlink("$fullpath/$oldfiles[$i]")) {
+                                                $numremoved ++;
+                                            }
+                                        }
+                                    } elsif (open(my $fh,'<',"$fullpath/$oldfiles[$i]")) {
+                                        while (my $line = <$fh>) {
+                                            push(@oldpasswds,$line);
+                                        }
+                                        close($fh);
+                                    }
+                                }
+                                if ($numremoved) {
+                                    &logthis("unlinked $numremoved old password files for $uname:$udom");
+                                }
+                            }
+                        }
+                        push(@oldpasswds,$contentpwd);
+                        foreach my $item (@oldpasswds) {
+                            my (undef,$method, at rest) = split(/!/,$item);
+                            if ($method eq 'bcrypt') {
+                                my $result = &hash_passwd($udom,$npass, at rest);
+                                if ($result eq $item) {
+                                    $notunique = 1;
+                                    last;
+                                }
+                            }
+                        }
+                        unless ($notunique) {
+                            unless (-e $fullpath) {
+                                if (&mkpath("$fullpath/")) {
+                                    chmod(0700,$fullpath);
+                                }
+                            }
+                            if (-d $fullpath) {
+                                my $now = time;
+                                if (open(my $fh,'>',"$fullpath/$now")) {
+                                    print $fh $contentpwd;
+                                    close($fh);
+                                    chmod(0400,"$fullpath/$now");
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+            if ($notunique) {
+                my $msg="Result of password change for $uname:$udom - password matches one used before";
+                if ($lonhost) {
+                    $msg .= " - request originated from: $lonhost";
+                }
+                &logthis($msg);
+                &Reply($client, "prioruse\n", $userinput);
+	    } elsif (&rewrite_password_file($udom, $uname, "internal:$ncpass")) {
 		my $msg="Result of password change for $uname: pwchange_success";
                 if ($lonhost) {
                     $msg .= " - request originated from: $lonhost";
@@ -2140,7 +2212,6 @@
 	    #
 	    &Failure( $client, "auth_mode_error\n", $userinput);
 	}  
-	
     } else {
 	if ($failure eq '') {
 	    $failure = 'non_authorized';




More information about the LON-CAPA-cvs mailing list