summaryrefslogtreecommitdiff
path: root/scripts/system/vyatta_update_login_user.pl
diff options
context:
space:
mode:
authorAn-Cheng Huang <ancheng@sydney.vyatta.com>2007-10-23 10:17:57 -0700
committerAn-Cheng Huang <ancheng@sydney.vyatta.com>2007-10-23 10:17:57 -0700
commitc07bfa52d381abfa0177dc5940e142bc4252b7b8 (patch)
tree990452e72abe6199ae9766f0815ab797c83593f9 /scripts/system/vyatta_update_login_user.pl
parentcb287eb4589e46b72001d8e84de1eb5bae26d543 (diff)
downloadvyatta-cfg-quagga-c07bfa52d381abfa0177dc5940e142bc4252b7b8.tar.gz
vyatta-cfg-quagga-c07bfa52d381abfa0177dc5940e142bc4252b7b8.zip
* add non-root users to 'quaggavty' group.
* set up sudo for 'quaggavty' group.
Diffstat (limited to 'scripts/system/vyatta_update_login_user.pl')
-rwxr-xr-xscripts/system/vyatta_update_login_user.pl44
1 files changed, 43 insertions, 1 deletions
diff --git a/scripts/system/vyatta_update_login_user.pl b/scripts/system/vyatta_update_login_user.pl
index 86c0074c..f51b8001 100755
--- a/scripts/system/vyatta_update_login_user.pl
+++ b/scripts/system/vyatta_update_login_user.pl
@@ -61,6 +61,46 @@ sub get_shadow_line {
return undef;
}
+my $DEF_GROUP = 'quaggavty';
+
+# arg: login name
+# removes the specified user from group/gshadow
+sub remove_user_from_group {
+ my $user = shift;
+ my $sed_cmd = 'sed -i \'/^' . $DEF_GROUP . ':/{'
+ . 's/:' . $user . ',/:/;'
+ . 's/,' . $user . ',/,/;'
+ . 's/,' . $user . '$//;}\'';
+ system("$sed_cmd /etc/group");
+ exit 1 if ($? >> 8);
+ system("$sed_cmd /etc/gshadow");
+ exit 1 if ($? >> 8);
+}
+
+# arg: login name
+# adds the specified user to group/gshadow
+sub add_user_to_group {
+ my $user = shift;
+
+ my $gcmd = 'grep -q -e \'^' . $DEF_GROUP . ':.*[:,]' . $user . '\(,\|$\)\'';
+ my $ret = system("$gcmd /etc/group");
+ my $in_group = (($ret >> 8) == 0) ? 1 : 0;
+ $ret = system("$gcmd /etc/gshadow");
+ my $in_gshadow = (($ret >> 8) == 0) ? 1 : 0;
+
+ my $sed_cmd = 'sed -i \'/^' . $DEF_GROUP . ':/{'
+ . 's/:$/:' . $user . '/;'
+ . 's/\([^:]\)$/\1,' . $user . '/;}\'';
+ if (!$in_group) {
+ system("$sed_cmd /etc/group");
+ exit 1 if ($? >> 8);
+ }
+ if (!$in_gshadow) {
+ system("$sed_cmd /etc/gshadow");
+ exit 1 if ($? >> 8);
+ }
+}
+
my $user = shift;
my $full = shift;
my $encrypted = shift;
@@ -92,12 +132,12 @@ if ($user eq "-d") {
exit 6 if ($ret >> 8);
$ret = system("rm -rf /home/$user");
exit 7 if ($ret >> 8);
+ remove_user_from_group($user);
exit 0;
}
exit 4 if (!defined($user) || !defined($full) || !defined($encrypted));
-my $DEF_GROUP = "quagga";
my $DEF_SHELL = "/bin/bash";
open(GRP, "/etc/group") or exit 5;
@@ -152,6 +192,8 @@ open(SHADOW, ">>/etc/shadow") or exit 12;
print SHADOW "$shadow_line\n";
close SHADOW;
+add_user_to_group($user);
+
if (($new_user) && !(-e "/home/$user")) {
if (-d "/etc/skel") {
$ret = system("cp -a /etc/skel /home/$user");