[LON-CAPA-cvs] cvs: loncom / lond

foxr lon-capa-cvs@mail.lon-capa.org
Thu, 05 Aug 2004 11:37:05 -0000


foxr		Thu Aug  5 07:37:05 2004 EDT

  Modified files:              
    /loncom	lond 
  Log:
  Modifed usage of lcuseradd to tell it to log exit status codes in a file,
  we then read/unlink the file and can now correctly report lcuseradd
  failures to the client.  This allows the cuser to indicate that 
  changing the passwd on a filesystem authenticated user really does fail
  rather than work...the message, however may not be so obvious 
  (lcuseradd_failed:User already exists), since the wrong lond request is
  getting invoked ultimately by the UI (Filed a bug on this).  The
  user will be astonished: Of course the user exists you idiotic computer,
  that's why I'm trying to change the password!!
  
  
  
Index: loncom/lond
diff -u loncom/lond:1.222 loncom/lond:1.223
--- loncom/lond:1.222	Wed Aug  4 17:11:16 2004
+++ loncom/lond	Thu Aug  5 07:37:05 2004
@@ -2,7 +2,7 @@
 # The LearningOnline Network
 # lond "LON Daemon" Server (port "LOND" 5663)
 #
-# $Id: lond,v 1.222 2004/08/04 21:11:16 foxr Exp $
+# $Id: lond,v 1.223 2004/08/05 11:37:05 foxr Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -57,7 +57,7 @@
 my $status='';
 my $lastlog='';
 
-my $VERSION='$Revision: 1.222 $'; #' stupid emacs
+my $VERSION='$Revision: 1.223 $'; #' stupid emacs
 my $remoteVERSION;
 my $currenthostid="default";
 my $currentdomainid;
@@ -122,8 +122,10 @@
 		   "lcpasswd Cannot set new passwd.",
 		   "lcpasswd Username has invalid characters",
 		   "lcpasswd Invalid characters in password",
-		    "11", "12",
-		    "lcpasswd Password mismatch");
+		   "lcpasswd User already exists", 
+                   "lcpasswd Something went wrong with user addition.",
+		    "lcpasswd Password mismatch",
+		    "lcpasswd Error filename is invalid");
 
 
 #  The array below are lcuseradd error strings.:
@@ -1689,7 +1691,7 @@
 	    } else {
 		my $result=&make_passwd_file($uname, $umode,$npass,
 					     $passfilename);
-		print $client $result;
+		Reply($client, $result, $userinput);
 	    }
 	} else {
 	    Reply($client, "refused\n", $userinput);
@@ -4305,7 +4307,8 @@
 		return "no_priv_account_error\n";
 	    }
 
-	    my $execpath="$perlvar{'lonDaemons'}/"."lcuseradd";
+	    my $execpath       ="$perlvar{'lonDaemons'}/"."lcuseradd";
+	    my $lc_error_file  = "/tmp/lcuseradd".$$.".status";
 	    {
 		&Debug("Executing external: ".$execpath);
 		&Debug("user  = ".$uname.", Password =". $npass);
@@ -4313,17 +4316,28 @@
 		print $se "$uname\n";
 		print $se "$npass\n";
 		print $se "$npass\n";
+		print $se "$lc_error_file\n"; # Status -> unique file.
 	    }
-	    my $useraddok = $?;
+	    my $error = IO::File->new("< $lc_error_file");
+	    my $useraddok = <$error>;
+	    $error->close;
+	    unlink($lc_error_file);
+
+	    chomp $useraddok;
+
 	    if($useraddok > 0) {
-		&logthis("Failed lcuseradd: ".&lcuseraddstrerror($useraddok));
+		my $error_text = &lcuseraddstrerror($useraddok);
+		&logthis("Failed lcuseradd: $error_text");
+		$result = "lcuseradd_failed:$error_text\n";
+	    }
+	    else {
+		my $pf = IO::File->new(">$passfilename");
+		print $pf "unix:\n";
 	    }
-	    my $pf = IO::File->new(">$passfilename");
-	    print $pf "unix:\n";
 	}
     } elsif ($umode eq 'none') {
 	{
-	    my $pf = IO::File->new(">$passfilename");
+	    my $pf = IO::File->new("> $passfilename");
 	    print $pf "none:\n";
 	}
     } else {