9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21 /*
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
24 */
25
26 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
27 /* All Rights Reserved */
28
29
30 #include <sys/types.h>
31 #include <stdio.h>
32 #include <stdlib.h>
33 #include <sys/param.h>
34 #include <unistd.h>
35 #include <users.h>
36 #include <userdefs.h>
37 #include "messages.h"
38
39 extern void exit();
40 extern char *strtok();
41
42 static gid_t *grplist;
43 static int ngroups_max = 0;
44
45 /* Validate a list of groups */
46 int **
47 valid_lgroup(char *list, gid_t gid)
48 {
49 int n_invalid = 0, i = 0, j;
50 char *ptr;
51 struct group *g_ptr;
52 int warning;
53 int dup_prim = 0; /* we don't duplicate our primary as a supplemental */
54
55 if( !list || !*list )
56 return( (int **) NULL );
57
58 if (ngroups_max == 0) {
59 ngroups_max = sysconf(_SC_NGROUPS_MAX);
60 grplist = malloc((ngroups_max + 1) * sizeof (gid_t));
61 }
62
63 while (ptr = strtok(((i || n_invalid || dup_prim)? NULL: list), ",")) {
64
65 switch (valid_group(ptr, &g_ptr, &warning)) {
66 case INVALID:
67 errmsg( M_INVALID, ptr, "group id" );
68 n_invalid++;
69 break;
70 case TOOBIG:
71 errmsg( M_TOOBIG, "gid", ptr );
72 n_invalid++;
73 break;
74 case UNIQUE:
75 errmsg( M_GRP_NOTUSED, ptr );
76 n_invalid++;
77 break;
78 case NOTUNIQUE:
79 /* ignore duplicated primary */
80 if (g_ptr->gr_gid == gid) {
81 if (!dup_prim)
82 dup_prim++;
83 continue;
|
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21 /*
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
24 */
25
26 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
27 /* All Rights Reserved */
28
29 /*
30 * Copyright (c) 2013 RackTop Systems.
31 */
32
33
34 #include <sys/types.h>
35 #include <stdio.h>
36 #include <stdlib.h>
37 #include <sys/param.h>
38 #include <unistd.h>
39 #include <users.h>
40 #include <userdefs.h>
41 #include "messages.h"
42
43 extern void exit();
44 extern char *strtok();
45
46 static gid_t *grplist;
47 static int ngroups_max = 0;
48
49 /* Validate a list of groups */
50 int **
51 valid_lgroup(char *list, gid_t gid)
52 {
53 int n_invalid = 0, i = 0, j;
54 char *ptr;
55 struct group *g_ptr;
56 int warning;
57 int dup_prim = 0; /* we don't duplicate our primary as a supplemental */
58
59 if( !list || !*list )
60 return( (int **) NULL );
61
62 if (ngroups_max == 0) {
63 ngroups_max = sysconf(_SC_NGROUPS_MAX);
64 grplist = malloc((ngroups_max + 1) * sizeof (gid_t));
65 }
66
67 while ((ptr = strtok((i || n_invalid || dup_prim)? NULL: list, ","))) {
68
69 switch (valid_group(ptr, &g_ptr, &warning)) {
70 case INVALID:
71 errmsg( M_INVALID, ptr, "group id" );
72 n_invalid++;
73 break;
74 case TOOBIG:
75 errmsg( M_TOOBIG, "gid", ptr );
76 n_invalid++;
77 break;
78 case UNIQUE:
79 errmsg( M_GRP_NOTUSED, ptr );
80 n_invalid++;
81 break;
82 case NOTUNIQUE:
83 /* ignore duplicated primary */
84 if (g_ptr->gr_gid == gid) {
85 if (!dup_prim)
86 dup_prim++;
87 continue;
|