4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
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]
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
27 /* All Rights Reserved */
30 * Copyright (c) 2013 RackTop Systems.
34 #include <sys/types.h>
37 #include <sys/param.h>
44 extern char *strtok();
46 static gid_t
*grplist
;
47 static int ngroups_max
= 0;
49 /* Validate a list of groups */
51 valid_lgroup(char *list
, gid_t gid
)
53 int n_invalid
= 0, i
= 0, j
;
57 int dup_prim
= 0; /* we don't duplicate our primary as a supplemental */
60 return( (int **) NULL
);
62 if (ngroups_max
== 0) {
63 ngroups_max
= sysconf(_SC_NGROUPS_MAX
);
64 grplist
= malloc((ngroups_max
+ 1) * sizeof (gid_t
));
67 while ((ptr
= strtok((i
|| n_invalid
|| dup_prim
)? NULL
: list
, ","))) {
69 switch (valid_group(ptr
, &g_ptr
, &warning
)) {
71 errmsg( M_INVALID
, ptr
, "group id" );
75 errmsg( M_TOOBIG
, "gid", ptr
);
79 errmsg( M_GRP_NOTUSED
, ptr
);
83 /* ignore duplicated primary */
84 if (g_ptr
->gr_gid
== gid
) {
91 grplist
[ i
++ ] = g_ptr
->gr_gid
;
93 /* Keep out duplicates */
94 for( j
= 0; j
< i
; j
++ )
95 if( g_ptr
->gr_gid
== grplist
[j
] )
100 grplist
[i
++] = g_ptr
->gr_gid
;
106 warningmsg(warning
, ptr
);
108 if( i
>= ngroups_max
) {
109 errmsg( M_MAXGROUPS
, ngroups_max
);
114 /* Terminate the list */
120 return( (int **)grplist
);