[Setup-tool-hackers] [PATCH] Progress towards making users-adminwork on FBSD




Here we go again... :)

I've been hacking the GST backends a bit, the result is attached. I
don't know perl however, so I'd really appreciate some review before
commit approval.

Attached patch does the following:
 - Make users-conf find the pw(8) tool
 - Make users-conf able to use pw(8) on FreeBSD in order to:
   - Add users
   - Delete users
   - Change user info
   - Change extended user info
   - Add groups
   - Delete groups
 - Fix XML produced from FreeBSD's passwd(5) file
    (it can contain the '&' character)

Remaining items/bugs/issues:
 - Change group info not yet ported
 - Figure out the profile and login.defs stuff


Regards,
 - Theo

-- 
Theo van Klaveren <t.vanklaveren@student.utwente.nl>
http://home.student.utwente.nl/t.vanklaveren
Index: users-conf.in
===================================================================
RCS file: /cvs/gnome/setup-tools-backends/users-conf.in,v
retrieving revision 1.88
diff -u -3 -p -r1.88 users-conf.in
--- users-conf.in	15 Dec 2001 00:02:45 -0000	1.88
+++ users-conf.in	2 Sep 2002 10:34:45 -0000
@@ -43,6 +43,7 @@
 # usermod: modifying user data.
 # passwd: assigning or changing passwords. (Un)locking users.
 # chfn: modifying finger information - Name, Office, Office phone, Home phone.
+# pw: modifying users/groups and user/group data on FreeBSD.
 
 
 BEGIN {
@@ -73,9 +74,9 @@ $version = "___version___";
 
               "debian-2.2", "debian-woody",
 
-              "suse-7.0", "turbolinux-7.0");
+              "suse-7.0", "turbolinux-7.0",
 
-#, "freebsd-4", "freebsd-5");
+              "freebsd-4", "freebsd-5");
 
 $description =<<"end_of_description;";
        Manages system users.
@@ -89,7 +90,7 @@ end_of_description;
 @passwd_names =     ( "/etc/passwd" );
 @shadow_names =     ( "/etc/shadow", "/etc/master.passwd" );
 @group_names =      ( "/etc/group" );
-@login_defs_names = ( "/etc/login.defs", "/etc/adduser.conf" );
+@login_defs_names = ( "/etc/login.defs", "/etc/pw.conf" );
 @shell_names =      ( "/etc/shells" );
 @skel_dir =         ( "/usr/share/skel", "/etc/skel" );
 
@@ -106,6 +107,7 @@ $cmd_groupadd = &xst_file_locate_tool ("
 $cmd_groupmod = &xst_file_locate_tool ("groupmod");
 $cmd_gpasswd  = &xst_file_locate_tool ("gpasswd");	
 $cmd_chfn     = &xst_file_locate_tool ("chfn");
+$cmd_pw       = &xst_file_locate_tool ("pw");
 
 # --- Mapping constants --- #
 
@@ -229,6 +231,8 @@ my $logindefs_dist_map = {
   'debian-woody'   => $rh_logindefs_defaults,
   'suse-7.0'       => $rh_logindefs_defaults,
   'turbolinux-7.0' => $rh_logindefs_defaults,
+  'freebsd-4'      => $rh_logindefs_defaults,
+  'freebsd-5'      => $rh_logindefs_defaults,
 };
 
 
@@ -425,8 +429,8 @@ sub read_passwd_shadow
   {
     chomp;
     # FreeBSD allows comments in the passwd file. */
-    next if ($_ =~ /\#.*/);
-    $_ = &xst_xml_unquote ($_);
+    next if &xst_ignore_line ($_);
+    $_ = &xst_xml_quote ($_);
     
     @line = split ':', $_, -1;
     unshift @line, sprintf ("%06d", $i);
@@ -449,7 +453,9 @@ sub read_passwd_shadow
     {
       chomp;
       # FreeBSD allows comments in the shadow passwd file. */
-      next if ($_ =~ /\#.*/);
+      next if &xst_ignore_line ($_);
+      $_ = &xst_xml_quote ($_);
+
       @line = split ':', $_, -1;
       push @line, 1;
       $login = shift @line;
@@ -500,7 +506,11 @@ sub read_group
   while (<$ifh>)
   {
     chomp;
+
+    # FreeBSD allows comments in the group file. */
+    next if &xst_ignore_line ($_);
     $_ = &xst_xml_unquote ($_);
+
     @line = split ':', $_, -1;
     unshift @line, sprintf ("%06d", $i);
     @a = split ',', pop @line;
@@ -647,9 +657,14 @@ sub del_user
 {
 	my ($data) = @_;
   my ($command);
-	
-	$command = "$cmd_userdel -r \'" . $$data[$users_prop_map{"login"}] . "\'";
+
+	if ($xst_dist ~= /^freebsd/) {
+		$command = "$cmd_pw userdel -r -n \'" . $$data[$users_prop_map{"login"}] . "\' ";
+	} else {
+		$command = "$cmd_userdel -r \'" . $$data[$users_prop_map{"login"}] . "\'";
+	}
 	&xst_file_run ($command);
+
 }
 
 sub change_user_chfn
@@ -659,25 +674,29 @@ sub change_user_chfn
   my ($command, @line);
 
   return if !$username;
-  
-  @line = split /\,/, $comment;
-  ($fname, $office, $office_phone, $home_phone) = @line;
-
-  $fname = "-f \'" . $fname . "\'";  
-  $home_phone = "-h \'" . $home_phone . "\'";
+ 
+	if ($xst_dist =~ /^freebsd/) {
+		$command = "$cmd_pw usermod -n " . $username . " -c \'" . $comment . "\'";
+	} else {
+		@line = split /\,/, $comment;
+	 	($fname, $office, $office_phone, $home_phone) = @line;
+
+		$fname = "-f \'" . $fname . "\'";  
+		$home_phone = "-h \'" . $home_phone . "\'";
+
+		if ($xst_dist =~ /^debian/)
+	 	{
+	 		$office = "-r \'" . $office . "\'";
+ 			$office_phone = "-w \'" . $office_phone . "\'";
+ 		}
+	 	else
+	 	{
+	 		$office = "-o \'" . $office . "\'";
+ 			$office_phone = "-p \'" . $office_phone . "\'";
+ 		}  
 
-  if ($xst_dist =~ /^debian/)
-  {
-    $office = "-r \'" . $office . "\'";
-    $office_phone = "-w \'" . $office_phone . "\'";
-  }
-  else
-  {
-    $office = "-o \'" . $office . "\'";
-    $office_phone = "-p \'" . $office_phone . "\'";
-  }  
-  
-  $command = "$cmd_chfn $fname $office $office_phone $home_phone $username";
+	  $command = "$cmd_chfn $fname $office $office_phone $home_phone $username";
+	}
   &xst_file_run ($command);
 }
 
@@ -691,30 +710,63 @@ sub add_user
 
   $tool_mkdir = &xst_file_locate_tool ("mkdir");
   &xst_file_run ("$tool_mkdir -p $home_parents");
-  
-  $command = "$cmd_useradd" . " -d \'" . $$data[$users_prop_map{"home"}] .
-	  "\' -g \'" . $$data[$users_prop_map{"gid"}] .
-	  "\' -m -p \'" . $$data[$users_prop_map{"password"}] .
-	  "\' -s \'" . $$data[$users_prop_map{"shell"}] .
-	  "\' -u \'" . $$data[$users_prop_map{"uid"}] .
-	  "\' \'" . $$data[$users_prop_map{"login"}] . "\'";
-	&xst_file_run ($command);
 
-  &change_user_chfn ($$data[$users_prop_map{"comment"}], $$data[$users_prop_map{"login"}]);
+	if ($xst_dist =~ /^freebsd/) {
+	  my $pwdpipe;
+
+		$command = "$cmd_pw useradd " .
+		 " -n \'" . $$data[$users_prop_map{"login"}] . "\'" .
+		 " -u \'" . $$data[$users_prop_map{"uid"}] . "\'" .
+		 " -d \'" . $$data[$users_prop_map{"home"}] . "\'" .
+		 " -g \'" . $$data[$users_prop_map{"gid"}] . "\'" .
+		 " -s \'" . $$data[$users_prop_map{"shell"}] . "\'" .
+		 " -h 0"; # pw(8) reads password from STDIN
+
+		$pwdpipe = &xst_file_run_pipe($command, $XST_FILE_WRITE);
+		print $pwdpipe $$data[$users_prop_map{"password"}];
+		close(PIPE);
+
+	} else {
+		$command = "$cmd_useradd" . " -d \'" . $$data[$users_prop_map{"home"}] .
+	 	 "\' -g \'" . $$data[$users_prop_map{"gid"}] .
+	 	 "\' -m -p \'" . $$data[$users_prop_map{"password"}] .
+	 	 "\' -s \'" . $$data[$users_prop_map{"shell"}] .
+	 	 "\' -u \'" . $$data[$users_prop_map{"uid"}] .
+	 	 "\' \'" . $$data[$users_prop_map{"login"}] . "\'";
+		&xst_file_run ($command);
+	}
+
+ 	&change_user_chfn ($$data[$users_prop_map{"comment"}], $$data[$users_prop_map{"login"}]);
 }
 
 sub change_user
 {
 	my ($old_data, $new_data) = @_;
 	
-  $command = "$cmd_usermod" . " -d \'" . $$new_data[$users_prop_map{"home"}] .
-	  "\' -g \'" . $$new_data[$users_prop_map{"gid"}] .
-	  "\' -l \'" . $$new_data[$users_prop_map{"login"}] .
-	  "\' -p \'" . $$new_data[$users_prop_map{"password"}] .
-	  "\' -s \'" . $$new_data[$users_prop_map{"shell"}] .
-	  "\' -u \'" . $$new_data[$users_prop_map{"uid"}] .
-	  "\' \'" . $$old_data[$users_prop_map{"login"}] . "\'";
-	&xst_file_run ($command);
+	if ($xst_dist =~ /^freebsd/) {
+	  my $pwdpipe;
+
+		$command = "$cmd_pw usermod " .
+		 " -n \'" . $$data[$users_prop_map{"login"}] . "\'" .
+		 " -u \'" . $$data[$users_prop_map{"uid"}] . "\'" .
+		 " -d \'" . $$data[$users_prop_map{"home"}] . "\'" .
+		 " -g \'" . $$data[$users_prop_map{"gid"}] . "\'" .
+		 " -s \'" . $$data[$users_prop_map{"shell"}] . "\'" .
+		 " -h 0"; # pw(8) reads password from STDIN
+
+		$pwdpipe = &xst_file_run_pipe($command, $XST_FILE_WRITE);
+		print $pwdpipe $$data[$users_prop_map{"password"}];
+		close(PIPE);
+	} else {
+		$command = "$cmd_usermod" . " -d \'" . $$new_data[$users_prop_map{"home"}] .
+		  "\' -g \'" . $$new_data[$users_prop_map{"gid"}] .
+		  "\' -l \'" . $$new_data[$users_prop_map{"login"}] .
+	 		"\' -p \'" . $$new_data[$users_prop_map{"password"}] .
+	 		"\' -s \'" . $$new_data[$users_prop_map{"shell"}] .
+	 		"\' -u \'" . $$new_data[$users_prop_map{"uid"}] .
+	 		"\' \'" . $$old_data[$users_prop_map{"login"}] . "\'";
+		&xst_file_run ($command);
+	}
 
   &change_user_chfn ($$new_data[$users_prop_map{"comment"}], $$new_data[$users_prop_map{"login"}]);
 }
@@ -723,16 +775,25 @@ sub del_group
 {
 	my ($data) = @_;
 
-	$command = "$cmd_groupdel \'" . $$data[$groups_prop_map{"name"}] . "\'";
+	if ($xst_dist =~ /^freebsd/) {
+		$command = "$cmd_pw groupdel -n \'" . $$data[$groups_prop_map{"name"}] . "\'";
+	} else {
+		$command = "$cmd_groupdel \'" . $$data[$groups_prop_map{"name"}] . "\'";
+	}
 	&xst_file_run ($command);
 }
 
 sub add_group
 {
 	my ($data) = @_;
-	
-	$command = "$cmd_groupadd -g \'" . $$data[$groups_prop_map{"gid"}] .
-	  "\' " . $$data[$groups_prop_map{"name"}];
+
+	if ($xst_dist =~ /^freebsd/) {
+		$command = "$cmd_pw groupadd -n \'" . $$data[$groups_prop_map{"name"}] .
+		 "\' -g " . $$data[$groups_prop_map{"gid"}];
+	} else {
+		$command = "$cmd_groupadd -g \'" . $$data[$groups_prop_map{"gid"}] .
+		 "\' " . $$data[$groups_prop_map{"name"}];
+	}
 	&xst_file_run ($command);
 }
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]