Deleted Added
full compact
pw_user.c (273043) pw_user.c (274082)
1/*-
2 * Copyright (C) 1996
3 * David L. Nugent. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 13 unchanged lines hidden (view full) ---

22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 */
27
28#ifndef lint
29static const char rcsid[] =
1/*-
2 * Copyright (C) 1996
3 * David L. Nugent. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 13 unchanged lines hidden (view full) ---

22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 */
27
28#ifndef lint
29static const char rcsid[] =
30 "$FreeBSD: stable/10/usr.sbin/pw/pw_user.c 273043 2014-10-13 15:56:47Z des $";
30 "$FreeBSD: stable/10/usr.sbin/pw/pw_user.c 274082 2014-11-04 07:50:48Z bapt $";
31#endif /* not lint */
32
33#include <ctype.h>
34#include <err.h>
35#include <fcntl.h>
36#include <sys/param.h>
37#include <dirent.h>
38#include <paths.h>

--- 277 unchanged lines hidden (view full) ---

316 * know.
317 */
318 if (mode != M_ADD && pwd == NULL
319 && strspn(a_name->val, "0123456789") == strlen(a_name->val)
320 && *a_name->val) {
321 (a_uid = a_name)->ch = 'u';
322 a_name = NULL;
323 }
31#endif /* not lint */
32
33#include <ctype.h>
34#include <err.h>
35#include <fcntl.h>
36#include <sys/param.h>
37#include <dirent.h>
38#include <paths.h>

--- 277 unchanged lines hidden (view full) ---

316 * know.
317 */
318 if (mode != M_ADD && pwd == NULL
319 && strspn(a_name->val, "0123456789") == strlen(a_name->val)
320 && *a_name->val) {
321 (a_uid = a_name)->ch = 'u';
322 a_name = NULL;
323 }
324 } else {
325 if (strspn(a_uid->val, "0123456789") != strlen(a_uid->val))
326 errx(EX_USAGE, "-u expects a number");
324 }
325
326 /*
327 * Update, delete & print require that the user exists
328 */
329 if (mode == M_UPDATE || mode == M_DELETE ||
330 mode == M_PRINT || mode == M_LOCK || mode == M_UNLOCK) {
331

--- 414 unchanged lines hidden (view full) ---

746 }
747 }
748
749 /*
750 * Ok, user is created or changed - now edit group file
751 */
752
753 if (mode == M_ADD || getarg(args, 'G') != NULL) {
327 }
328
329 /*
330 * Update, delete & print require that the user exists
331 */
332 if (mode == M_UPDATE || mode == M_DELETE ||
333 mode == M_PRINT || mode == M_LOCK || mode == M_UNLOCK) {
334

--- 414 unchanged lines hidden (view full) ---

749 }
750 }
751
752 /*
753 * Ok, user is created or changed - now edit group file
754 */
755
756 if (mode == M_ADD || getarg(args, 'G') != NULL) {
754 int i;
757 int i, j;
758 /* First remove the user from all group */
759 SETGRENT();
760 while ((grp = GETGRENT()) != NULL) {
761 char group[MAXLOGNAME];
762 if (grp->gr_mem == NULL)
763 continue;
764 for (i = 0; grp->gr_mem[i] != NULL; i++) {
765 if (strcmp(grp->gr_mem[i] , pwd->pw_name) != 0)
766 continue;
767 for (j = i; grp->gr_mem[j] != NULL ; j++)
768 grp->gr_mem[j] = grp->gr_mem[j+1];
769 strlcpy(group, grp->gr_name, MAXLOGNAME);
770 chggrent(group, grp);
771 }
772 }
773 ENDGRENT();
774
775 /* now add to group where needed */
755 for (i = 0; cnf->groups[i] != NULL; i++) {
756 grp = GETGRNAM(cnf->groups[i]);
757 grp = gr_add(grp, pwd->pw_name);
758 /*
759 * grp can only be NULL in 2 cases:
760 * - the new member is already a member
761 * - a problem with memory occurs
762 * in both cases we want to skip now.

--- 562 unchanged lines hidden ---
776 for (i = 0; cnf->groups[i] != NULL; i++) {
777 grp = GETGRNAM(cnf->groups[i]);
778 grp = gr_add(grp, pwd->pw_name);
779 /*
780 * grp can only be NULL in 2 cases:
781 * - the new member is already a member
782 * - a problem with memory occurs
783 * in both cases we want to skip now.

--- 562 unchanged lines hidden ---