patches/system-tools-backends-08-users.diff
author padraigo
Mon, 10 Apr 2006 15:59:20 +0000
changeset 7035 3cfd68e4e41f
parent 6983 48e372aed92d
child 7329 ea6dd6dd48ce
permissions -rw-r--r--
2006-04-10 Padraig O'Briain <[email protected]> * gnome-system-tools.spec: Add define USE_AUTHEN_PAM for Solaris. * patches/gnome-system-tools-07-users.diff: Update to not encrypt password if USE_AUTHEN_PAM is defined. * patches/system-tools-backends-02-common.diff: Update patch to suppress writing line containing password in debug output in gst_debug_print_to_file in debug.pl. * patches/system-tools-backends-08-users.diff: Update patch to use Authen::PAM to change passwords on Solaris.

--- /usr/tmp/clean/system-tools-backends-1.4.2/users-conf.in	Mon Jan  2 15:48:06 2006
+++ system-tools-backends-1.4.2/users-conf.in	Mon Apr 10 15:21:15 2006
@@ -47,6 +47,8 @@
 # pw: modifying users/groups and user/group data on FreeBSD.
 
 
+use Authen::PAM;
+
 BEGIN {
   $SCRIPTSDIR = "@scriptsdir@";
   if ($SCRIPTSDIR =~ /^@scriptsdir[@]/)
@@ -74,6 +76,7 @@
               "mandrake-7.1", "mandrake-7.2", "mandrake-9.0", "mandrake-9.1", "mandrake-9.2",
               "mandrake-10.0", "mandrake-10.1",
               "debian-2.2", "debian-3.0", "debian-sarge",
+               "nexenta-1.0", "solaris-2.11",
               "suse-7.0", "suse-9.0", "suse-9.1", "turbolinux-7.0",
               "slackware-8.0.0", "slackware-8.1", "slackware-9.0.0", "slackware-9.1.0", "slackware-10.0.0", "slackware-10.1.0", "slackware-10.2.0",
               "freebsd-4", "freebsd-5", "freebsd-6",
@@ -115,9 +118,12 @@
 # --- Mapping constants --- #
 
 %users_prop_map = ();
+
+sub get_users_prop_array
+{
 @users_prop_array = ();
 
-if ($$tool{"platform"} eq "Linux")
+if ($$tool{"system"} eq "Linux" || $$tool{"system"} eq "SunOS")
 {
   @users_prop_array = (
     "key", 0,
@@ -157,6 +163,7 @@
   $users_prop_map {$users_prop_array[$i]} = $users_prop_array[$i + 1];
   $users_prop_map {$users_prop_array[$i + 1]} = $users_prop_array[$i];
 }
+}
 
 %groups_prop_map = ();
 @groups_prop_array = (
@@ -315,6 +322,20 @@
   }
 }
 
+my $nexenta_logindefs_defaults = {
+  'shell'       => '/bin/bash',
+  'group'       => 'users',
+  'skel_dir'    => '/etc/skel/',
+  'home_prefix' => '/export/home/$user',
+};
+
+my $solaris_logindefs_defaults = {
+  'shell'       => '/bin/bash',
+  'group'       => 'users',
+  'skel_dir'    => '/etc/skel/',
+  'home_prefix' => '/home/$user',
+};
+
 my $rh_logindefs_defaults = {
   'shell'       => '/bin/bash',
   'group'       => '$user',
@@ -362,6 +383,8 @@
   'debian-2.2'      => $rh_logindefs_defaults,
   'debian-3.0'      => $rh_logindefs_defaults,
   'debian-sarge'    => $rh_logindefs_defaults,
+  'nexenta-1.0'    => $nexenta_logindefs_defaults,
+  'solaris-2.11'    => $solaris_logindefs_defaults,
   'vine-3.0'        => $rh_logindefs_defaults,
   'vine-3.1'        => $rh_logindefs_defaults,
   'gentoo'	        => $gentoo_logindefs_defaults,
@@ -740,7 +763,40 @@
   push (@shells, "/bin/false") if (stat ("/bin/false"));
   
   $ifh = &gst_file_open_read_from_names(@shell_names);
-  return unless $ifh;
+  unless ($ifh)
+  {
+     if ($gst_dist =~ /solaris/)
+     {
+       push (@shells, "/bin/bash");
+       push (@shells, "/bin/csh");
+       push (@shells, "/bin/jsh");
+       push (@shells,  "/bin/ksh");
+       push (@shells,  "/bin/pfcsh");
+       push (@shells, "/bin/pfksh");
+       push (@shells, "/bin/pfsh");
+       push (@shells, "/bin/sh");
+       push (@shells, "/bin/tcsh");
+       push (@shells, "/bin/zsh");
+       push (@shells, "/sbin/jsh");
+       push (@shells, "/sbin/jsh");
+       push (@shells, "/sbin/pfsh");
+       push (@shells, "/sbin/sh");
+       push (@shells, "/usr/bin/bash");
+       push (@shells, "/usr/bin/csh");
+       push (@shells, "/usr/bin/jsh");
+       push (@shells, "/usr/bin/ksh");
+       push (@shells, "/usr/bin/pfcsh");
+       push (@shells, "/usr/bin/pfksh");
+       push (@shells, "/usr/bin/pfsh");
+       push (@shells, "/usr/bin/sh");
+       push (@shells, "/usr/bin/tcsh");
+       push (@shells, "/usr/bin/zsh");
+       push (@shells, "/usr/xpg4/bin/sh");
+       $$hash{"shelldb"} = \@shells;
+     }
+     return;
+  }
+  
 
   while (<$ifh>)
   {
@@ -879,6 +935,11 @@
   {
     $command = "$cmd_pw usermod -n " . $username . " -c \'" . $comment . "\'";
   }
+  elsif ($gst_dist =~ /^solaris/)
+  {
+    ($fname, $office, $office_phone, $home_phone) = @line;
+    $command = "$cmd_usermod" . " -c \'" . $fname . "\' " . $username; 
+  }
   else
   {
     ($fname, $office, $office_phone, $home_phone) = @line;
@@ -886,7 +947,7 @@
     $fname = "-f \'" . $fname . "\'";
     $home_phone = "-h \'" . $home_phone . "\'";
 
-    if ($gst_dist =~ /^debian/  || $gst_dist =~ /^archlinux/)
+    if ($gst_dist =~ /^debian/  || $gst_dist =~ /^archlinux/ || $gst_dist =~ /^nexenta/)
     {
       $office = "-r \'" . $office . "\'";
       $office_phone = "-w \'" . $office_phone . "\'";
@@ -903,6 +964,30 @@
   &gst_file_run ($command);
 }
 
+$service = "passwd";
+$username = "";
+$newpassword = "";
+
+sub my_conv_func {
+  my @res;
+  while ( @_ ) {
+      my $code = shift;
+      my $msg = shift;
+      my $ans = "";
+
+      $ans = $username if ($code == PAM_PROMPT_ECHO_ON() );
+      if ($code == PAM_PROMPT_ECHO_OFF() ) {
+        $ans = $newpassword;
+        $ans = $newpassword;
+
+      }
+
+      push @res, (PAM_SUCCESS(),$ans);
+  }
+  push @res, PAM_SUCCESS();
+  return @res;
+}
+
 sub add_user
 {
 	my ($data) = @_;
@@ -932,6 +1017,38 @@
     print $pwdpipe $$data[$users_prop_map{"password"}];
     &gst_file_close ($pwdpipe);
   }
+  elsif ($gst_dist =~ /^nexenta/)
+  {
+    my $pwdpipe;
+    $home_parents = $$data[$users_prop_map{"home"}];
+    $home_parents =~ s/\/+[^\/]+\/*$//;
+    &gst_file_run ("$tool_mkdir -p $home_parents");
+
+    $command = "$cmd_useradd" . " -d \'" . $$data[$users_prop_map{"home"}] .
+     "\' -g \'"    . $$data[$users_prop_map{"gid"}] .
+     "\' -s \'"    . $$data[$users_prop_map{"shell"}] .
+     "\' -u \'"    . $$data[$users_prop_map{"uid"}] .
+     "\' \'"       . $$data[$users_prop_map{"login"}] . "\'";
+    &gst_file_run ($command);
+    &gst_file_run("echo " . $$data[$users_prop_map{"login"}] . ":" . $$data[$users_prop_map{"password"}] . " | chpasswd -e");
+  }
+  elsif ($gst_dist =~ /^solaris/)
+  {
+    $home_parents = $$data[$users_prop_map{"home"}];
+    $home_parents =~ s/\/+[^\/]+\/*$//;
+    &gst_file_run ("$tool_mkdir -p $home_parents");
+
+    $command = "$cmd_useradd" . " -d \'" . $$data[$users_prop_map{"home"}] .
+     "\' -g \'"    . $$data[$users_prop_map{"gid"}] .
+     "\' -m -s \'"    . $$data[$users_prop_map{"shell"}] .
+     "\' -u \'"    . $$data[$users_prop_map{"uid"}] .
+     "\' \'"       . $$data[$users_prop_map{"login"}] . "\'";
+    &gst_file_run ($command);
+    $username = $$data[$users_prop_map{"login"}];
+    $newpassword = $$data[$users_prop_map{"password"}];
+    ref($pamh = new Authen::PAM($service, $username, \&my_conv_func));
+    $pamh->pam_chauthtok(PAM_NO_AUTHTOK_CHECK());
+  }
   else
   {
     $home_parents = $$data[$users_prop_map{"home"}];
@@ -967,9 +1084,33 @@
      " -H 0"; # pw(8) reads password from STDIN
 
     $pwdpipe = &gst_file_run_pipe($command, $GST_FILE_WRITE);
-    print $pwdpipe $$data[$users_prop_map{"password"}];
+    print $pwdpipe $$new_data[$users_prop_map{"password"}];
     &gst_file_close ($pwdpipe);
   }
+  elsif ($gst_dist =~ /^nexenta/)
+  {
+    $command = "$cmd_usermod" . " -d \'" . $$new_data[$users_prop_map{"home"}] .
+     "\' -g \'" . $$new_data[$users_prop_map{"gid"}] .
+     "\' -l \'" . $$new_data[$users_prop_map{"login"}] .
+     "\' -s \'" . $$new_data[$users_prop_map{"shell"}] .
+     "\' -u \'" . $$new_data[$users_prop_map{"uid"}] .
+     "\' \'" . $$old_data[$users_prop_map{"login"}] . "\'";
+    &gst_file_run ($command);
+    &gst_file_run("echo " . $$new_data[$users_prop_map{"login"}] . ":" . $$new_data[$users_prop_map{"password"}] . " | chpasswd -e");
+  }
+  elsif ($gst_dist =~ /^solaris/)
+  {
+    $command = "$cmd_usermod" . " -d \'" . $$new_data[$users_prop_map{"home"}] .
+     "\' -g \'" . $$new_data[$users_prop_map{"gid"}] .
+     "\' -s \'" . $$new_data[$users_prop_map{"shell"}] .
+     "\' -u \'" . $$new_data[$users_prop_map{"uid"}] .
+     "\' \'" . $$old_data[$users_prop_map{"login"}] . "\'";
+    &gst_file_run ($command);
+    $username = $$old_data[$users_prop_map{"login"}];
+    $newpassword = $$new_data[$users_prop_map{"password"}];
+    ref($pamh = new Authen::PAM($service, $username, \&my_conv_func));
+    $pamh->pam_chauthtok(PAM_NO_AUTHTOK_CHECK());
+  }
   else
   {
     $command = "$cmd_usermod" . " -d \'" . $$new_data[$users_prop_map{"home"}] .
@@ -1026,8 +1167,24 @@
 
     foreach $user (@$u)
     {
-      $command = "$cmd_gpasswd -a \'" . $user .
-        "\' " . $$data[$groups_prop_map{"name"}];
+      if ($gst_dist =~ /^solaris/)
+      {
+        my ($groups, @a);
+        $command = "groups \'" . $user . "\'";
+        $groups = &gst_file_run_backtick ($command);
+        chomp ($groups);
+        @a = split (/ /, $groups);
+        $groups = join (',', @a);
+
+        $command = "$cmd_usermod -G " . $groups . "," .
+                $$data[$groups_prop_map{"name"}] .  " " .
+                $user . " ";
+      }
+      else
+      {
+        $command = "$cmd_gpasswd -a \'" . $user .
+          "\' " . $$data[$groups_prop_map{"name"}];
+      }
       &gst_file_run ($command);
     }
   }
@@ -1069,25 +1226,62 @@
       $max_o = $#$o;
       for ($i = 0, $j = 0; $i <= &max ($max_n, $max_o); ) {
         $r = $$n[$i] cmp $$o[$j];
-        $r *= -1 if (($$o[$j] eq "") || ($$n[$i] eq ""));
 
-        if ($r < 0) { # add this user to the group.
-          $command = "$cmd_gpasswd -a \'" . $$n[$i] . "\' \'" . 
-            $$new_data[$groups_prop_map{"name"}] . "\'";
+        if ($r > 0) { # add this user to the group.
+          if ($gst_dist =~ /^solaris/)
+          {
+            my ($groups, @a);
+            $command = "groups \'" . $$n[$i] . "\'";
+            $groups = &gst_file_run_backtick ($command);
+            chomp ($groups);
+            @a = split (/ /, $groups);
+            $groups = join (',', @a);
+
+            $command = "$cmd_usermod -G " . $groups . "," .
+                $$new_data[$groups_prop_map{"name"}] .  " " .
+                $$n[$i] . " ";
+          }
+          else
+          {
+            $command = "$cmd_gpasswd -a " . $$n[$i] . " " .  $$new_data[$groups_prop_map{"name"}] . " ";
+          }
           $i ++;
-				
+
           &gst_file_run ($command);
-			  } elsif ($r > 0) { # delete the user from the group.
-          $command = "$cmd_gpasswd -d \'" . $$o[$j] . "\' \'" . 
-            $$new_data[$groups_prop_map{"name"}] . "\'";
+        } elsif ($r < 0) { # delete the user from the group.
+          if ($gst_dist =~ /^solaris/)
+          {
+            my ($groups, @a, $k);
+            $command = "groups \'" . $$o[$j] . "\'";
+            $groups = &gst_file_run_backtick ($command);
+            chomp ($groups);
+            @a = split (/ /, $groups);
+            for ($k = 0; $k < $#a + 1; $k++)
+            {
+              if ($a[$k] eq $$new_data[$groups_prop_map{"name"}])
+              {
+                splice (@a, $k, 1);
+                last;
+              }
+            }
+            $groups = join (',', @a);
+
+            $command = "$cmd_usermod -G " . $groups . " " .
+                $$o[$j] . " ";
+          }
+          else
+          {
+            $command = "$cmd_gpasswd -d \'" . $$o[$j] . "\' \'" .
+              $$new_data[$groups_prop_map{"name"}] . "\'";
+          }
           $j ++;
-				
+
           &gst_file_run ($command);
-			  } else { # The information is the same. Go to next tuple.
+        } else { # The information is the same. Go to next tuple.
           $i ++; $j ++;
-			  }	
-		  }	
-	  }
+        }
+      }
+    }
   }
 }
 
@@ -1204,6 +1398,7 @@
 		elsif ($$tree[0] eq "group_last_modified") { &xml_parse_group_last_modified ($$tree[1], $hash); }
 		elsif ($$tree[0] eq "userdb") { &xml_parse_userdb ($$tree[1], $hash); }
 		elsif ($$tree[0] eq "groupdb") { &xml_parse_groupdb ($$tree[1], $hash); }
+		elsif ($$tree[0] eq "use_md5")  { }
 		elsif ($$tree[0] eq "shelldb")  { }
 		elsif ($$tree[0] eq "profiledb")  { &xml_parse_profiledb ($$tree[1], $hash); }
 		else
@@ -1323,6 +1518,7 @@
 		  if ($$tree[0] eq "users") { $line[$groups_prop_map{$$tree[0]}] = $$tree[1]; }
 			else { $line[$groups_prop_map{$$tree[0]}] = $$tree[1][2]; }
 		}
+		elsif ($$tree[0] eq "allows_to") { }
 		else
 		{
 		  &gst_report ("xml_unexp_tag", $$tree[0]);
@@ -1627,6 +1823,7 @@
 $tool = &gst_init ($name, $version, $description, $directives, @ARGV);
 &gst_platform_ensure_supported ($tool, @platforms);
 
+&get_users_prop_array ();
 &get_login_defs_prop_array ();
 &get_profiles_prop_array   ();