additional usermod flag, '-a'
Peter Vrabec <[email protected]> Thu, 07 Jul 2005 14:50:21 +0200
| Newsgroups | gmane.linux.pld.shadow.general |
|---|---|
| Message-ID | <[email protected]> |
Hi, here is the patch, which adds new '-a' flag to usermod. This flag can only be used in conjunction with the -G option. It cause usermod to append user to the current supplementary group list. This flag would be helpful in everyday admin duties. Patch is against the version 4.0.10.
shadow-4.0.10-aflgForUsermod.patch
(text/x-patch, 3.8 KB)
--- shadow-4.0.10/man/usermod.8.aflg 2005-06-16 18:08:37.000000000 +0200
+++ shadow-4.0.10/man/usermod.8 2005-07-06 14:36:35.000000000 +0200
@@ -24,7 +24,7 @@
.ad l
.hy 0
.HP 8
-\fBusermod\fR [\-c\ \fIcomment\fR] [\-d\ \fIhome_dir\fR\ [\-m]] [\-e\ \fIexpire_date\fR] [\-f\ \fIinactive_days\fR] [\-g\ \fIinitial_group\fR] [\-G\ \fIgroup1\fR\ [\fI,group2,\fR...\ \fI,\fR\ [\fIgroupN\fR]]] [\-l\ \fIlogin_name\fR] [\-p\ \fIpasswd\fR] [\-s\ \fIshell\fR] [\-u\ \fIuid\fR\ [\-o]] [\fB\-L\fR | \fB\-U\fR] \fIlogin\fR
+\fBusermod\fR [\-c\ \fIcomment\fR] [\-d\ \fIhome_dir\fR\ [\-m]] [\-e\ \fIexpire_date\fR] [\-f\ \fIinactive_days\fR] [\-g\ \fIinitial_group\fR] [[-a] \-G\ \fIgroup1\fR\ [\fI,group2,\fR...\ \fI,\fR\ [\fIgroupN\fR]]] [\-l\ \fIlogin_name\fR] [\-p\ \fIpasswd\fR] [\-s\ \fIshell\fR] [\-u\ \fIuid\fR\ [\-o]] [\fB\-L\fR | \fB\-U\fR] \fIlogin\fR
.ad
.hy
@@ -60,7 +60,7 @@
.TP
\fB\-G\fR \fIgroup1\fR[\fI ,group2,\&.\&.\&., \fR [\fIgroupN\fR]]]
-A list of supplementary groups which the user is also a member of\&. Each group is separated from the next by a comma, with no intervening whitespace\&. The groups are subject to the same restrictions as the group given with the \fB\-g\fR option\&. If the user is currently a member of a group which is not listed, the user will be removed from the group\&.
+A list of supplementary groups which the user is also a member of\&. Each group is separated from the next by a comma, with no intervening whitespace\&. The groups are subject to the same restrictions as the group given with the \fB\-g\fR option\&. If the user is currently a member of a group which is not listed, the user will be removed from the group\&. This behaviour can be changed via \fB\-a\fR option, which appends user to the current supplementary group list\&.
.TP
\fB\-l\fR \fIlogin_name\fR
--- shadow-4.0.10/src/usermod.c.aflg 2005-06-20 12:17:10.000000000 +0200
+++ shadow-4.0.10/src/usermod.c 2005-07-06 14:37:25.000000000 +0200
@@ -94,6 +94,7 @@
uflg = 0, /* specify new user ID */
oflg = 0, /* permit non-unique user ID to be specified with -u */
gflg = 0, /* new primary group ID */
+ aflg = 0, /* append to existing secondary group set */
Gflg = 0, /* new secondary group set */
dflg = 0, /* new home directory */
sflg = 0, /* new shell program */
@@ -276,7 +277,7 @@
{
fprintf (stderr,
_
- ("Usage: %s\t[-u uid [-o]] [-g group] [-G group,...] \n"),
+ ("Usage: %s\t[-u uid [-o]] [-g group] [[-a] [-G group,...]] \n"),
Prog);
fprintf (stderr,
_
@@ -473,7 +474,7 @@
user_name, user_newname,
ngrp->gr_name));
}
- } else if (was_member && Gflg && !is_member) {
+ } else if (was_member && !aflg && Gflg && !is_member) {
ngrp->gr_mem = del_list (ngrp->gr_mem, user_name);
changed = 1;
SYSLOG ((LOG_INFO, "delete `%s' from group `%s'",
@@ -590,7 +591,7 @@
user_name, user_newname,
nsgrp->sg_name));
}
- } else if (was_member && Gflg && !is_member) {
+ } else if (was_member && !aflg && Gflg && !is_member) {
nsgrp->sg_mem = del_list (nsgrp->sg_mem, user_name);
changed = 1;
SYSLOG ((LOG_INFO,
@@ -737,8 +738,11 @@
user_inactive = spwd->sp_inact;
}
- while ((arg = getopt (argc, argv, "A:u:og:G:d:s:c:mf:e:l:p:LU")) != EOF) {
+ while ((arg = getopt (argc, argv, "aA:u:og:G:d:s:c:mf:e:l:p:LU")) != EOF) {
switch (arg) {
+ case 'a':
+ aflg++;
+ break;
case 'c':
if (!VALID (optarg)) {
fprintf (stderr,
@@ -878,6 +882,13 @@
if (optind != argc - 1)
usage ();
+ if (aflg && (!Gflg)) {
+ fprintf (stderr, "\n%s: -a flag is ONLY allowed with the -G flag\n\n",
+ Prog);
+ usage();
+ exit (E_USAGE);
+ }
+
if (dflg && strcmp (user_home, user_newhome) == 0)
dflg = mflg = 0;