2 # This is a shell archive (produced by GNU sharutils 4.2.1).
3 # To extract the files from this archive, save it to some FILE, remove
4 # everything before the `!/bin/sh' line above, then type `sh FILE'.
6 # Made on 2000-05-25 14:41 CDT by <gk4@gnu.austin.ibm.com>.
7 # Source directory was `/home/gk4/src/groupmem'.
9 # Existing files will *not* be overwritten unless `-c' is specified.
13 # ------ ---------- ------------------------------------------
14 # 1960 -rw-r--r-- Makefile
15 # 6348 -rw-r--r-- groupmems.c
16 # 3372 -rw------- groupmems.8
25 if test "$gettext_dir" = FAILED && test -f $dir/gettext \
26 && ($dir/gettext --version >/dev/null 2>&1)
28 set `$dir/gettext --version 2>&1`
34 if test "$locale_dir" = FAILED && test -f $dir/shar \
35 && ($dir/shar --print-text-domain-dir >/dev/null 2>&1)
37 locale_dir=`$dir/shar --print-text-domain-dir`
41 if test "$locale_dir" = FAILED || test "$gettext_dir" = FAILED
45 TEXTDOMAINDIR=$locale_dir
49 echo="$gettext_dir/gettext -s"
51 if touch -am -t 200112312359.59 $$.touch >/dev/null 2>&1 && test ! -f 200112312359.59 -a -f $$.touch; then
52 shar_touch='touch -am -t $1$2$3$4$5$6.$7 "$8"'
53 elif touch -am 123123592001.59 $$.touch >/dev/null 2>&1 && test ! -f 123123592001.59 -a ! -f 123123592001.5 -a -f $$.touch; then
54 shar_touch='touch -am $3$4$5$6$1$2.$7 "$8"'
55 elif touch -am 1231235901 $$.touch >/dev/null 2>&1 && test ! -f 1231235901 -a -f $$.touch; then
56 shar_touch='touch -am $3$4$5$6$2 "$8"'
60 $echo 'WARNING: not restoring timestamps. Consider getting and'
61 $echo "installing GNU \`touch', distributed in GNU File Utilities..."
64 rm -f 200112312359.59 123123592001.59 123123592001.5 1231235901 $$.touch
66 if mkdir _sh10937; then
67 $echo 'x -' 'creating lock directory'
69 $echo 'failed to create lock directory'
72 # ============= Makefile ==============
73 if test -f 'Makefile' && test "$first_param" != -c; then
74 $echo 'x -' SKIPPING 'Makefile' '(file already exists)'
76 $echo 'x -' extracting 'Makefile' '(text)'
77 sed 's/^X//' << 'SHAR_EOF' > 'Makefile' &&
79 # Copyright 2000, International Business Machines, Inc.
80 # All rights reserved.
82 # original author: George Kraft IV, gk4@us.ibm.com
84 # Redistribution and use in source and binary forms, with or without
85 # modification, are permitted provided that the following conditions
88 # 1. Redistributions of source code must retain the above copyright
89 # notice, this list of conditions and the following disclaimer.
90 # 2. Redistributions in binary form must reproduce the above copyright
91 # notice, this list of conditions and the following disclaimer in the
92 # documentation and/or other materials provided with the distribution.
93 # 3. Neither the name of International Business Machines, Inc., nor the
94 # names of its contributors may be used to endorse or promote products
95 # derived from this software without specific prior written permission.
97 # THIS SOFTWARE IS PROVIDED BY INTERNATIONAL BUSINESS MACHINES, INC. AND
98 # CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
99 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
100 # FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
101 # INTERNATIONAL BUSINESS MACHINES, INC. OR CONTRIBUTORS BE LIABLE
102 # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
103 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
104 # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
105 # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
106 # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
107 # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
113 groupmems: groupmems.c
114 X cc -g -o groupmems groupmems.c -L. -lshadow
117 X -/usr/sbin/groupadd groups
118 X install -o root -g groups -m 4770 groupmems /usr/bin
120 install.man: groupmems.8
121 X install -o root -g root -m 644 groupmems.8 /usr/man/man8
124 (set 20 00 05 25 14 40 28 'Makefile'; eval "$shar_touch") &&
125 chmod 0644 'Makefile' ||
126 $echo 'restore of' 'Makefile' 'failed'
127 if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
128 && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
129 md5sum -c << SHAR_EOF >/dev/null 2>&1 \
130 || $echo 'Makefile:' 'MD5 check failed'
131 b46cf7ef8d59149093c011ced3f3103c Makefile
134 shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'Makefile'`"
135 test 1960 -eq "$shar_count" ||
136 $echo 'Makefile:' 'original size' '1960,' 'current size' "$shar_count!"
139 # ============= groupmems.c ==============
140 if test -f 'groupmems.c' && test "$first_param" != -c; then
141 $echo 'x -' SKIPPING 'groupmems.c' '(file already exists)'
143 $echo 'x -' extracting 'groupmems.c' '(text)'
144 sed 's/^X//' << 'SHAR_EOF' > 'groupmems.c' &&
146 X * Copyright 2000, International Business Machines, Inc.
147 X * All rights reserved.
149 X * original author: George Kraft IV, gk4@us.ibm.com
151 X * Redistribution and use in source and binary forms, with or without
152 X * modification, are permitted provided that the following conditions
155 X * 1. Redistributions of source code must retain the above copyright
156 X * notice, this list of conditions and the following disclaimer.
157 X * 2. Redistributions in binary form must reproduce the above copyright
158 X * notice, this list of conditions and the following disclaimer in the
159 X * documentation and/or other materials provided with the distribution.
160 X * 3. Neither the name of International Business Machines, Inc., nor the
161 X * names of its contributors may be used to endorse or promote products
162 X * derived from this software without specific prior written permission.
164 X * THIS SOFTWARE IS PROVIDED BY INTERNATIONAL BUSINESS MACHINES, INC. AND
165 X * CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
166 X * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
167 X * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
168 X * INTERNATIONAL BUSINESS MACHINES, INC. OR CONTRIBUTORS BE LIABLE
169 X * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
170 X * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
171 X * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
172 X * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
173 X * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
174 X * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
179 ** Utility "groupmem" adds and deletes members from a user's group.
181 ** Setup (as "root"):
183 ** groupadd -r groups
184 ** chmod 2770 groupmems
185 ** chown root.groups groupmems
186 ** groupmems -g groups -a gk4
190 ** groupmems -a olive
191 ** groupmems -a jordan
192 ** groupmems -a meghan
193 ** groupmems -a morgan
203 #include <sys/types.h>
204 #include <sys/stat.h>
209 /* Exit Status Values */
211 #define EXIT_SUCCESS 0 /* success */
212 #define EXIT_USAGE 1 /* invalid command syntax */
213 #define EXIT_GROUP_FILE 2 /* group file access problems */
214 #define EXIT_NOT_ROOT 3 /* not superuser */
215 #define EXIT_NOT_EROOT 4 /* not effective superuser */
216 #define EXIT_NOT_PRIMARY 5 /* not primary owner of group */
217 #define EXIT_NOT_MEMBER 6 /* member of group does not exist */
218 #define EXIT_MEMBER_EXISTS 7 /* member of group already exists */
227 static char *adduser = NULL;
228 static char *deluser = NULL;
229 static char *thisgroup = NULL;
230 static int purge = FALSE;
231 static int list = FALSE;
232 static int exclusive = 0;
234 static int isroot(void) {
235 X return getuid() ? FALSE : TRUE;
238 static int isgroup(void) {
239 X gid_t g = getgid();
240 X struct group *grp = getgrgid(g);
245 static char *whoami(void) {
246 X struct group *grp = getgrgid(getgid());
247 X struct passwd *usr = getpwuid(getuid());
249 X if (0 == strcmp(usr->pw_name, grp->gr_name)) {
250 X return (char *)strdup(usr->pw_name);
257 addtogroup(char *user, char **members) {
261 X for (i = 0; NULL != members[i]; i++ ) {
262 X if (0 == strcmp(user, members[i])) {
263 X fprintf(stderr, "Member already exists\n");
264 X exit(EXIT_MEMBER_EXISTS);
269 X pmembers = (char **)calloc(2, sizeof(char *));
271 X pmembers = (char **)realloc(members, sizeof(char *)*(i+1));
274 X *members = *pmembers;
276 X members[i+1] = NULL;
280 rmfromgroup(char *user, char **members) {
285 X while (!found && NULL != members[i]) {
286 X if (0 == strcmp(user, members[i])) {
293 X while (found && NULL != members[i]) {
294 X members[i] = members[++i];
298 X fprintf(stderr, "Member to remove could not be found\n");
299 X exit(EXIT_NOT_MEMBER);
304 nomembers(char **members) {
307 X for (i = 0; NULL != members[i]; i++ ) {
313 members(char **members) {
316 X for (i = 0; NULL != members[i]; i++ ) {
317 X printf("%s ", members[i]);
319 X if (NULL == members[i+1]) {
327 static void usage(void) {
328 X fprintf(stderr, "usage: groupmems -a username | -d username | -D | -l [-g groupname]\n");
332 main(int argc, char **argv) {
337 X while ((arg = getopt(argc, argv, "a:d:g:Dl")) != EOF) {
340 X adduser = strdup(optarg);
344 X deluser = strdup(optarg);
348 X thisgroup = strdup(optarg);
363 X if (exclusive > 1 || optind < argc) {
367 X if (!isroot() && NULL != thisgroup) {
368 X fprintf(stderr, "Only root can add members to different groups\n");
369 X exit(EXIT_NOT_ROOT);
370 X } else if (isroot() && NULL != thisgroup) {
372 X } else if (!isgroup()) {
373 X fprintf(stderr, "Group access is required\n");
374 X exit(EXIT_NOT_EROOT);
375 X } else if (NULL == (name = whoami())) {
376 X fprintf(stderr, "Not primary owner of current group\n");
377 X exit(EXIT_NOT_PRIMARY);
381 X fprintf(stderr, "Unable to lock group file\n");
382 X exit(EXIT_GROUP_FILE);
385 X if (!gr_open(O_RDWR)) {
386 X fprintf(stderr, "Unable to open group file\n");
387 X exit(EXIT_GROUP_FILE);
390 X grp = (struct group *)gr_locate(name);
392 X if (NULL != adduser) {
393 X addtogroup(adduser, grp->gr_mem);
395 X } else if (NULL != deluser) {
396 X rmfromgroup(deluser, grp->gr_mem);
398 X } else if (purge) {
399 X nomembers(grp->gr_mem);
402 X members(grp->gr_mem);
406 X fprintf(stderr, "Cannot close group file\n");
407 X exit(EXIT_GROUP_FILE);
412 X exit(EXIT_SUCCESS);
417 (set 20 00 05 25 14 36 38 'groupmems.c'; eval "$shar_touch") &&
418 chmod 0644 'groupmems.c' ||
419 $echo 'restore of' 'groupmems.c' 'failed'
420 if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
421 && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
422 md5sum -c << SHAR_EOF >/dev/null 2>&1 \
423 || $echo 'groupmems.c:' 'MD5 check failed'
424 f0dd68f8d762d89d24d3ce1f4141f981 groupmems.c
427 shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'groupmems.c'`"
428 test 6348 -eq "$shar_count" ||
429 $echo 'groupmems.c:' 'original size' '6348,' 'current size' "$shar_count!"
432 # ============= groupmems.8 ==============
433 if test -f 'groupmems.8' && test "$first_param" != -c; then
434 $echo 'x -' SKIPPING 'groupmems.8' '(file already exists)'
436 $echo 'x -' extracting 'groupmems.8' '(text)'
437 sed 's/^X//' << 'SHAR_EOF' > 'groupmems.8' &&
439 X.\" Copyright 2000, International Business Machines, Inc.
440 X.\" All rights reserved.
442 X.\" original author: George Kraft IV, gk4@us.ibm.com
444 X.\" Redistribution and use in source and binary forms, with or without
445 X.\" modification, are permitted provided that the following conditions
448 X.\" 1. Redistributions of source code must retain the above copyright
449 X.\" notice, this list of conditions and the following disclaimer.
450 X.\" 2. Redistributions in binary form must reproduce the above copyright
451 X.\" notice, this list of conditions and the following disclaimer in the
452 X.\" documentation and/or other materials provided with the distribution.
453 X.\" 3. Neither the name of International Business Machines, Inc., nor the
454 X.\" names of its contributors may be used to endorse or promote products
455 X.\" derived from this software without specific prior written permission.
457 X.\" THIS SOFTWARE IS PROVIDED BY INTERNATIONAL BUSINESS MACHINES, INC. AND
458 X.\" CONTRIBUTORS ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
459 X.\" BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
460 X.\" FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
461 X.\" INTERNATIONAL BUSINESS MACHINES, INC. OR CONTRIBUTORS BE LIABLE
462 X.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
463 X.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
464 X.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
465 X.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
466 X.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
467 X.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
470 X.\" $Id: groupmems.shar 1342 2007-11-10 23:46:11Z nekral-guest $
474 groupmems \- Administer members of a user's primary group
477 \fB-a\fI user_name \fR |
478 \fB-d\fI user_name \fR |
481 [\fB-g\fI group_name \fR]
483 The \fBgroupmems\fR utility allows a user to administer his/her own
484 group membership list without the requirement of superuser privileges.
485 The \fBgroupmems\fR utility is for systems that configure its users to
486 be in their own name sake primary group (i.e., guest / guest).
488 Only the superuser, as administrator, can use \fBgroupmems\fR to alter
489 the memberships of other groups.
490 X.IP "\fB-a \fIuser_name\fR"
491 Add a new user to the group membership list.
492 X.IP "\fB-d \fIuser_name\fR"
493 Delete a user from the group membership list.
495 List the group membership list.
497 Delete all users from the group membership list.
498 X.IP "\fB-g \fIgroup_name\fR"
499 The superuser can specify which group membership list to modify.
501 The \fBgroupmems\fR executable should be in mode \fB2770\fR as user \fBroot\fR
502 and in group \fBgroups\fR. The system administrator can add users to
503 group groups to allow or disallow them using the \fBgroupmems\fR utility
504 to manager their own group membership list.
506 X $ groupadd -r groups
508 X $ chmod 2770 groupmems
510 X $ chown root.groups groupmems
512 X $ groupmems -g groups -a gk4
527 George Kraft IV (gk4@us.ibm.com)
530 (set 20 00 05 25 14 38 23 'groupmems.8'; eval "$shar_touch") &&
531 chmod 0600 'groupmems.8' ||
532 $echo 'restore of' 'groupmems.8' 'failed'
533 if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
534 && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
535 md5sum -c << SHAR_EOF >/dev/null 2>&1 \
536 || $echo 'groupmems.8:' 'MD5 check failed'
537 181e6cd3a3c9d3df320197fa2cde2b4a groupmems.8
540 shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'groupmems.8'`"
541 test 3372 -eq "$shar_count" ||
542 $echo 'groupmems.8:' 'original size' '3372,' 'current size' "$shar_count!"