Print this page
4078 groupadd execs getent unnecessarily
Reviewed by: Rich Lowe <richlowe@richlowe.net>
Reviewed by: Gary Mills <gary_mills@fastmail.fm>
Reviewed by: Milan Jurik <milan.jurik@xylab.cz>
Reviewed by: Gordon Ross <Gordon.W.Ross@gmail.com>
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/oamuser/user/val_lgrp.c
+++ new/usr/src/cmd/oamuser/user/val_lgrp.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
↓ open down ↓ |
18 lines elided |
↑ open up ↑ |
19 19 * CDDL HEADER END
20 20 */
21 21 /*
22 22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 23 * Use is subject to license terms.
24 24 */
25 25
26 26 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
27 27 /* All Rights Reserved */
28 28
29 +/*
30 + * Copyright (c) 2013 RackTop Systems.
31 + */
32 +
29 33
30 34 #include <sys/types.h>
31 35 #include <stdio.h>
32 36 #include <stdlib.h>
33 37 #include <sys/param.h>
34 38 #include <unistd.h>
35 39 #include <users.h>
36 40 #include <userdefs.h>
37 41 #include "messages.h"
38 42
39 43 extern void exit();
40 44 extern char *strtok();
41 45
42 46 static gid_t *grplist;
43 47 static int ngroups_max = 0;
44 48
45 49 /* Validate a list of groups */
46 50 int **
47 51 valid_lgroup(char *list, gid_t gid)
48 52 {
49 53 int n_invalid = 0, i = 0, j;
50 54 char *ptr;
51 55 struct group *g_ptr;
52 56 int warning;
↓ open down ↓ |
14 lines elided |
↑ open up ↑ |
53 57 int dup_prim = 0; /* we don't duplicate our primary as a supplemental */
54 58
55 59 if( !list || !*list )
56 60 return( (int **) NULL );
57 61
58 62 if (ngroups_max == 0) {
59 63 ngroups_max = sysconf(_SC_NGROUPS_MAX);
60 64 grplist = malloc((ngroups_max + 1) * sizeof (gid_t));
61 65 }
62 66
63 - while (ptr = strtok(((i || n_invalid || dup_prim)? NULL: list), ",")) {
67 + while ((ptr = strtok((i || n_invalid || dup_prim)? NULL: list, ","))) {
64 68
65 69 switch (valid_group(ptr, &g_ptr, &warning)) {
66 70 case INVALID:
67 71 errmsg( M_INVALID, ptr, "group id" );
68 72 n_invalid++;
69 73 break;
70 74 case TOOBIG:
71 75 errmsg( M_TOOBIG, "gid", ptr );
72 76 n_invalid++;
73 77 break;
74 78 case UNIQUE:
75 79 errmsg( M_GRP_NOTUSED, ptr );
76 80 n_invalid++;
77 81 break;
78 82 case NOTUNIQUE:
79 83 /* ignore duplicated primary */
80 84 if (g_ptr->gr_gid == gid) {
81 85 if (!dup_prim)
82 86 dup_prim++;
83 87 continue;
84 88 }
85 89
86 90 if( !i )
87 91 grplist[ i++ ] = g_ptr->gr_gid;
88 92 else {
89 93 /* Keep out duplicates */
90 94 for( j = 0; j < i; j++ )
91 95 if( g_ptr->gr_gid == grplist[j] )
92 96 break;
93 97
94 98 if( j == i )
95 99 /* Not a duplicate */
96 100 grplist[i++] = g_ptr->gr_gid;
97 101 }
98 102 break;
99 103
100 104 }
101 105 if (warning)
102 106 warningmsg(warning, ptr);
103 107
104 108 if( i >= ngroups_max ) {
105 109 errmsg( M_MAXGROUPS, ngroups_max );
106 110 break;
107 111 }
108 112 }
109 113
110 114 /* Terminate the list */
111 115 grplist[ i ] = -1;
112 116
113 117 if( n_invalid )
114 118 exit( EX_BADARG );
115 119
116 120 return( (int **)grplist );
117 121 }
↓ open down ↓ |
44 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX