[LON-CAPA-cvs] cvs: loncom / lchtmldir lcpasswd lcuseradd

albertel lon-capa-cvs@mail.lon-capa.org
Thu, 07 Apr 2005 22:27:53 -0000


albertel		Thu Apr  7 18:27:53 2005 EDT

  Modified files:              
    /loncom	lchtmldir lcpasswd lcuseradd 
  Log:
  - commiting Martin Siegert's updates to work on systems that don't create user groups by default
  
  
Index: loncom/lchtmldir
diff -u loncom/lchtmldir:1.15 loncom/lchtmldir:1.16
--- loncom/lchtmldir:1.15	Wed Jan 26 07:13:58 2005
+++ loncom/lchtmldir	Thu Apr  7 18:27:52 2005
@@ -144,7 +144,7 @@
 if($DEBUG) {
     print("Save username = $safeuser \n");
 }
-if(($username ne $safeuser) or ($safeuser!~/^[A-za-z]/)) {
+if(($username ne $safeuser) or ($safeuser!~/^[A-z]/)) {
     if($DEBUG) {
 	print("User name $username had illegal characters\n");
     }
@@ -185,6 +185,17 @@
         exit 6;
     }
 }
+if ($authentication eq "unix:") {
+    # check whether group $safeuser exists.
+    my $usergroups = `id -nG $safeuser`;
+    if (! grep /^$safeuser$/, split(/\s+/,$usergroups)) { 
+        if($DEBUG) {
+            print("Group \"$safeuser\" does not exist or $safeuser is not a member of that group.\n");
+        }
+        exit 7;
+    }
+}
+
 &EnableRoot;
 
 &System("/bin/mkdir -p $fulldir")   unless (-e $fulldir);
Index: loncom/lcpasswd
diff -u loncom/lcpasswd:1.20 loncom/lcpasswd:1.21
--- loncom/lcpasswd:1.20	Sat Mar 26 15:40:18 2005
+++ loncom/lcpasswd	Thu Apr  7 18:27:52 2005
@@ -7,7 +7,7 @@
 # YEAR=2002
 # 02/19 Matthew Hall
 #
-# $Id: lcpasswd,v 1.20 2005/03/26 20:40:18 albertel Exp $
+# $Id: lcpasswd,v 1.21 2005/04/07 22:27:52 albertel Exp $
 ###
 
 ###############################################################################
@@ -173,7 +173,7 @@
     ($>,$<)=(0,0); # fool smbpasswd here to think this is not a setuid
                    # environment
 
-#   If the -a swithc is put on the smbpasswd
+#   If the -a switch is put on the smbpasswd
 # command line, either a new entry will be created or the old one
 # will be used. 
 # Therefore the old strategy of looking for and adding a dummy entry is 
Index: loncom/lcuseradd
diff -u loncom/lcuseradd:1.35 loncom/lcuseradd:1.36
--- loncom/lcuseradd:1.35	Thu Jan 27 06:52:46 2005
+++ loncom/lcuseradd	Thu Apr  7 18:27:52 2005
@@ -6,7 +6,7 @@
 #             with adding a user with filesystem privileges (e.g. author)
 #
 #
-# $Id: lcuseradd,v 1.35 2005/01/27 11:52:46 foxr Exp $
+# $Id: lcuseradd,v 1.36 2005/04/07 22:27:52 albertel Exp $
 ###
 
 ###############################################################################
@@ -253,6 +253,32 @@
     unlink('/tmp/lock_lcpasswd');
     &Exit(12);
 }
+my ($dmy1, $dmy2, $uid, $gid) = getpwnam($safeusername);
+my ($group) = getgrgid($gid);
+if (! $group) {
+    print "Error. The primary group of user \"$safeusername\" could not be".
+          "determined.\n" unless $noprint;
+    system("/usr/sbin/userdel -r $safeusername");
+    unlink('/tmp/lock_lcpasswd');
+    &Exit(12);
+}
+if ($group != $safeusername) {
+   $status = system("/usr/sbin/groupadd -g $uid $safeusername");
+   if (! $status) {
+      $status = system("/usr/sbin/usermod -g $uid $safeusername");
+      if ($status) {
+         system("/usr/sbin/groupdel $safeusername");
+      }
+   }
+   if ($status) {
+      print "Error.  Something went wrong with the addition of user ".
+            "\"$safeusername\".\n" unless $noprint;
+      system("/usr/sbin/userdel -r $safeusername");
+      unlink('/tmp/lock_lcpasswd');
+      &Exit(12);
+   }
+}
+
 print "Done adding user\n" unless $noprint;
 # Make www a member of that user group.
 my $groups=`/usr/bin/groups www` or &Exit(6);