xref: /illumos-gate/usr/src/cmd/ptools/pcred/pcred.c (revision 2a8bcb4e)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
5004388ebScasper  * Common Development and Distribution License (the "License").
6004388ebScasper  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
217c478bd9Sstevel@tonic-gate /*
22*f48205beScasper  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
26*f48205beScasper #include <errno.h>
277c478bd9Sstevel@tonic-gate #include <stdio.h>
28004388ebScasper #include <stdio_ext.h>
297c478bd9Sstevel@tonic-gate #include <stdlib.h>
307c478bd9Sstevel@tonic-gate #include <unistd.h>
317c478bd9Sstevel@tonic-gate #include <fcntl.h>
327c478bd9Sstevel@tonic-gate #include <string.h>
337c478bd9Sstevel@tonic-gate #include <limits.h>
347c478bd9Sstevel@tonic-gate #include <sys/types.h>
357c478bd9Sstevel@tonic-gate #include <pwd.h>
367c478bd9Sstevel@tonic-gate #include <grp.h>
377c478bd9Sstevel@tonic-gate #include <libproc.h>
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate extern int _getgroupsbymember(const char *, gid_t[], int, int);
407c478bd9Sstevel@tonic-gate 
417c478bd9Sstevel@tonic-gate static int look(char *);
427c478bd9Sstevel@tonic-gate static int perr(char *);
437c478bd9Sstevel@tonic-gate 
447c478bd9Sstevel@tonic-gate static void usage(void);
457c478bd9Sstevel@tonic-gate static void initcred(void);
467c478bd9Sstevel@tonic-gate 
477c478bd9Sstevel@tonic-gate static char *command;
487c478bd9Sstevel@tonic-gate static char *procname;
497c478bd9Sstevel@tonic-gate 
507c478bd9Sstevel@tonic-gate static char *user;
517c478bd9Sstevel@tonic-gate static char *group;
527c478bd9Sstevel@tonic-gate static char *grplst;
537c478bd9Sstevel@tonic-gate static char *login;
547c478bd9Sstevel@tonic-gate 
557c478bd9Sstevel@tonic-gate static boolean_t all = B_FALSE;
567c478bd9Sstevel@tonic-gate static boolean_t doset = B_FALSE;
577c478bd9Sstevel@tonic-gate static int ngrp = -1;
587c478bd9Sstevel@tonic-gate static gid_t *groups;
597c478bd9Sstevel@tonic-gate static long ngroups_max;
607c478bd9Sstevel@tonic-gate 
61*f48205beScasper static uid_t uid = (uid_t)-1;
62*f48205beScasper static gid_t gid = (gid_t)-1;
637c478bd9Sstevel@tonic-gate 
647c478bd9Sstevel@tonic-gate int
main(int argc,char ** argv)657c478bd9Sstevel@tonic-gate main(int argc, char **argv)
667c478bd9Sstevel@tonic-gate {
677c478bd9Sstevel@tonic-gate 	int rc = 0;
687c478bd9Sstevel@tonic-gate 	int c;
697c478bd9Sstevel@tonic-gate 	struct rlimit rlim;
707c478bd9Sstevel@tonic-gate 
717c478bd9Sstevel@tonic-gate 	if ((command = strrchr(argv[0], '/')) != NULL)
727c478bd9Sstevel@tonic-gate 		command++;
737c478bd9Sstevel@tonic-gate 	else
747c478bd9Sstevel@tonic-gate 		command = argv[0];
757c478bd9Sstevel@tonic-gate 
767c478bd9Sstevel@tonic-gate 	if ((ngroups_max = sysconf(_SC_NGROUPS_MAX)) < 0)
777c478bd9Sstevel@tonic-gate 		return (perr("sysconf(_SC_NGROUPS_MAX)"));
787c478bd9Sstevel@tonic-gate 
797c478bd9Sstevel@tonic-gate 	opterr = 0;
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate 	while ((c = getopt(argc, argv, "au:g:l:G:")) != EOF) {
827c478bd9Sstevel@tonic-gate 		switch (c) {
837c478bd9Sstevel@tonic-gate 		case 'a':
847c478bd9Sstevel@tonic-gate 			all = B_TRUE;
857c478bd9Sstevel@tonic-gate 			break;
867c478bd9Sstevel@tonic-gate 		case 'u':
877c478bd9Sstevel@tonic-gate 			user = optarg;
887c478bd9Sstevel@tonic-gate 			doset = B_TRUE;
897c478bd9Sstevel@tonic-gate 			break;
907c478bd9Sstevel@tonic-gate 		case 'g':
917c478bd9Sstevel@tonic-gate 			group = optarg;
927c478bd9Sstevel@tonic-gate 			doset = B_TRUE;
937c478bd9Sstevel@tonic-gate 			break;
947c478bd9Sstevel@tonic-gate 		case 'G':
957c478bd9Sstevel@tonic-gate 			grplst = optarg;
967c478bd9Sstevel@tonic-gate 			doset = B_TRUE;
977c478bd9Sstevel@tonic-gate 			break;
987c478bd9Sstevel@tonic-gate 		case 'l':
997c478bd9Sstevel@tonic-gate 			login = optarg;
1007c478bd9Sstevel@tonic-gate 			doset = B_TRUE;
1017c478bd9Sstevel@tonic-gate 			break;
1027c478bd9Sstevel@tonic-gate 		default:
1037c478bd9Sstevel@tonic-gate 			usage();
1047c478bd9Sstevel@tonic-gate 			/*NOTREACHED*/
1057c478bd9Sstevel@tonic-gate 		}
1067c478bd9Sstevel@tonic-gate 	}
1077c478bd9Sstevel@tonic-gate 	if (login != NULL && (user != NULL || group != NULL || grplst != NULL))
1087c478bd9Sstevel@tonic-gate 		usage();
1097c478bd9Sstevel@tonic-gate 
1107c478bd9Sstevel@tonic-gate 	if (all && doset)
1117c478bd9Sstevel@tonic-gate 		usage();
1127c478bd9Sstevel@tonic-gate 
1137c478bd9Sstevel@tonic-gate 	argc -= optind;
1147c478bd9Sstevel@tonic-gate 	argv += optind;
1157c478bd9Sstevel@tonic-gate 
1167c478bd9Sstevel@tonic-gate 	if (argc == 0)
1177c478bd9Sstevel@tonic-gate 		usage();
1187c478bd9Sstevel@tonic-gate 
1197c478bd9Sstevel@tonic-gate 	if (doset)
1207c478bd9Sstevel@tonic-gate 		initcred();
1217c478bd9Sstevel@tonic-gate 
1227c478bd9Sstevel@tonic-gate 	/*
1237c478bd9Sstevel@tonic-gate 	 * Make sure we'll have enough file descriptors to handle a target
1247c478bd9Sstevel@tonic-gate 	 * that has many many mappings.
1257c478bd9Sstevel@tonic-gate 	 */
1267c478bd9Sstevel@tonic-gate 	if (getrlimit(RLIMIT_NOFILE, &rlim) == 0) {
1277c478bd9Sstevel@tonic-gate 		rlim.rlim_cur = rlim.rlim_max;
1287c478bd9Sstevel@tonic-gate 		(void) setrlimit(RLIMIT_NOFILE, &rlim);
129004388ebScasper 		(void) enable_extended_FILE_stdio(-1, -1);
1307c478bd9Sstevel@tonic-gate 	}
1317c478bd9Sstevel@tonic-gate 
1327c478bd9Sstevel@tonic-gate 	while (argc-- > 0)
1337c478bd9Sstevel@tonic-gate 		rc += look(*argv++);
1347c478bd9Sstevel@tonic-gate 
1357c478bd9Sstevel@tonic-gate 	return (rc > 255 ? 255 : rc);
1367c478bd9Sstevel@tonic-gate }
1377c478bd9Sstevel@tonic-gate 
1387c478bd9Sstevel@tonic-gate static void
credupdate(prcred_t * pcr)1397c478bd9Sstevel@tonic-gate credupdate(prcred_t *pcr)
1407c478bd9Sstevel@tonic-gate {
141*f48205beScasper 	if (uid != (uid_t)-1)
1427c478bd9Sstevel@tonic-gate 		pcr->pr_euid = pcr->pr_ruid = pcr->pr_suid = uid;
143*f48205beScasper 	if (gid != (gid_t)-1)
1447c478bd9Sstevel@tonic-gate 		pcr->pr_egid = pcr->pr_rgid = pcr->pr_sgid = gid;
1457c478bd9Sstevel@tonic-gate 	if (ngrp >= 0) {
1467c478bd9Sstevel@tonic-gate 
1477c478bd9Sstevel@tonic-gate 		pcr->pr_ngroups = ngrp;
1487c478bd9Sstevel@tonic-gate 
1497c478bd9Sstevel@tonic-gate 		(void) memcpy(pcr->pr_groups, groups, ngrp * sizeof (gid_t));
1507c478bd9Sstevel@tonic-gate 	}
1517c478bd9Sstevel@tonic-gate }
1527c478bd9Sstevel@tonic-gate 
1537c478bd9Sstevel@tonic-gate static int
look(char * arg)1547c478bd9Sstevel@tonic-gate look(char *arg)
1557c478bd9Sstevel@tonic-gate {
1567c478bd9Sstevel@tonic-gate 	struct ps_prochandle *Pr;
1577c478bd9Sstevel@tonic-gate 	static prcred_t *prcred = NULL;
1587c478bd9Sstevel@tonic-gate 	int gcode;
1597c478bd9Sstevel@tonic-gate 
1607c478bd9Sstevel@tonic-gate 	procname = arg;		/* for perr() */
1617c478bd9Sstevel@tonic-gate 
1627c478bd9Sstevel@tonic-gate 	if (prcred == NULL) {
1637c478bd9Sstevel@tonic-gate 		prcred = malloc(sizeof (prcred_t) +
1647c478bd9Sstevel@tonic-gate 			(ngroups_max - 1) * sizeof (gid_t));
1657c478bd9Sstevel@tonic-gate 		if (prcred == NULL) {
1667c478bd9Sstevel@tonic-gate 			(void) perr("malloc");
1677c478bd9Sstevel@tonic-gate 			exit(1);
1687c478bd9Sstevel@tonic-gate 		}
1697c478bd9Sstevel@tonic-gate 	}
1707c478bd9Sstevel@tonic-gate 
1717c478bd9Sstevel@tonic-gate 	if ((Pr = proc_arg_grab(arg, doset ? PR_ARG_PIDS : PR_ARG_ANY,
1727c478bd9Sstevel@tonic-gate 	    PGRAB_RETAIN | PGRAB_FORCE | (doset ? 0 : PGRAB_RDONLY) |
1737c478bd9Sstevel@tonic-gate 	    PGRAB_NOSTOP, &gcode)) == NULL) {
1747c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr, "%s: cannot examine %s: %s\n",
1757c478bd9Sstevel@tonic-gate 		    command, arg, Pgrab_error(gcode));
1767c478bd9Sstevel@tonic-gate 		return (1);
1777c478bd9Sstevel@tonic-gate 	}
1787c478bd9Sstevel@tonic-gate 
1797c478bd9Sstevel@tonic-gate 	if (Pcred(Pr, prcred, ngroups_max) == -1) {
1807c478bd9Sstevel@tonic-gate 		(void) perr("getcred");
1817c478bd9Sstevel@tonic-gate 		Prelease(Pr, 0);
1827c478bd9Sstevel@tonic-gate 		return (1);
1837c478bd9Sstevel@tonic-gate 	}
1847c478bd9Sstevel@tonic-gate 
1857c478bd9Sstevel@tonic-gate 	if (doset) {
1867c478bd9Sstevel@tonic-gate 		credupdate(prcred);
1877c478bd9Sstevel@tonic-gate 		if (Psetcred(Pr, prcred) != 0) {
1887c478bd9Sstevel@tonic-gate 			(void) perr("setcred");
1897c478bd9Sstevel@tonic-gate 			Prelease(Pr, 0);
1907c478bd9Sstevel@tonic-gate 			return (1);
1917c478bd9Sstevel@tonic-gate 		}
1927c478bd9Sstevel@tonic-gate 		Prelease(Pr, 0);
1937c478bd9Sstevel@tonic-gate 		return (0);
1947c478bd9Sstevel@tonic-gate 	}
1957c478bd9Sstevel@tonic-gate 
1967c478bd9Sstevel@tonic-gate 	if (Pstate(Pr) == PS_DEAD)
1977c478bd9Sstevel@tonic-gate 		(void) printf("core of %d:\t", (int)Pstatus(Pr)->pr_pid);
1987c478bd9Sstevel@tonic-gate 	else
1997c478bd9Sstevel@tonic-gate 		(void) printf("%d:\t", (int)Pstatus(Pr)->pr_pid);
2007c478bd9Sstevel@tonic-gate 
2017c478bd9Sstevel@tonic-gate 	if (!all &&
2027c478bd9Sstevel@tonic-gate 	    prcred->pr_euid == prcred->pr_ruid &&
2037c478bd9Sstevel@tonic-gate 	    prcred->pr_ruid == prcred->pr_suid)
204*f48205beScasper 		(void) printf("e/r/suid=%u  ", prcred->pr_euid);
2057c478bd9Sstevel@tonic-gate 	else
206*f48205beScasper 		(void) printf("euid=%u ruid=%u suid=%u  ",
207*f48205beScasper 			prcred->pr_euid, prcred->pr_ruid, prcred->pr_suid);
2087c478bd9Sstevel@tonic-gate 
2097c478bd9Sstevel@tonic-gate 	if (!all &&
2107c478bd9Sstevel@tonic-gate 	    prcred->pr_egid == prcred->pr_rgid &&
2117c478bd9Sstevel@tonic-gate 	    prcred->pr_rgid == prcred->pr_sgid)
212*f48205beScasper 		(void) printf("e/r/sgid=%u\n", prcred->pr_egid);
2137c478bd9Sstevel@tonic-gate 	else
214*f48205beScasper 		(void) printf("egid=%u rgid=%u sgid=%u\n",
215*f48205beScasper 			prcred->pr_egid, prcred->pr_rgid, prcred->pr_sgid);
2167c478bd9Sstevel@tonic-gate 
2177c478bd9Sstevel@tonic-gate 	if (prcred->pr_ngroups != 0 &&
2187c478bd9Sstevel@tonic-gate 	    (all || prcred->pr_ngroups != 1 ||
2197c478bd9Sstevel@tonic-gate 	    prcred->pr_groups[0] != prcred->pr_rgid)) {
2207c478bd9Sstevel@tonic-gate 		int i;
2217c478bd9Sstevel@tonic-gate 
2227c478bd9Sstevel@tonic-gate 		(void) printf("\tgroups:");
2237c478bd9Sstevel@tonic-gate 		for (i = 0; i < prcred->pr_ngroups; i++)
224*f48205beScasper 			(void) printf(" %u", prcred->pr_groups[i]);
2257c478bd9Sstevel@tonic-gate 		(void) printf("\n");
2267c478bd9Sstevel@tonic-gate 	}
2277c478bd9Sstevel@tonic-gate 
2287c478bd9Sstevel@tonic-gate 	Prelease(Pr, 0);
2297c478bd9Sstevel@tonic-gate 	return (0);
2307c478bd9Sstevel@tonic-gate }
2317c478bd9Sstevel@tonic-gate 
2327c478bd9Sstevel@tonic-gate static int
perr(char * s)2337c478bd9Sstevel@tonic-gate perr(char *s)
2347c478bd9Sstevel@tonic-gate {
2357c478bd9Sstevel@tonic-gate 	if (s)
2367c478bd9Sstevel@tonic-gate 		(void) fprintf(stderr, "%s: ", procname);
2377c478bd9Sstevel@tonic-gate 	else
2387c478bd9Sstevel@tonic-gate 		s = procname;
2397c478bd9Sstevel@tonic-gate 	perror(s);
2407c478bd9Sstevel@tonic-gate 	return (1);
2417c478bd9Sstevel@tonic-gate }
2427c478bd9Sstevel@tonic-gate 
2437c478bd9Sstevel@tonic-gate static void
usage(void)2447c478bd9Sstevel@tonic-gate usage(void)
2457c478bd9Sstevel@tonic-gate {
2467c478bd9Sstevel@tonic-gate 	(void) fprintf(stderr, "usage:\t%s [-a] { pid | core } ...\n"
2477c478bd9Sstevel@tonic-gate 	    "\t%s [-u user] [-g group] [-G groups] pid ...\n"
2487c478bd9Sstevel@tonic-gate 	    "\t%s -l login pid ...\n"
2497c478bd9Sstevel@tonic-gate 	    "  (report or modify process credentials)\n",
2507c478bd9Sstevel@tonic-gate 	    command, command, command);
2517c478bd9Sstevel@tonic-gate 	exit(2);
2527c478bd9Sstevel@tonic-gate }
2537c478bd9Sstevel@tonic-gate 
2547c478bd9Sstevel@tonic-gate 
255*f48205beScasper static uint32_t
str2id(const char * str)2567c478bd9Sstevel@tonic-gate str2id(const char *str)
2577c478bd9Sstevel@tonic-gate {
258*f48205beScasper 	unsigned long res;
2597c478bd9Sstevel@tonic-gate 	char *p;
2607c478bd9Sstevel@tonic-gate 
261*f48205beScasper 	errno = 0;
262*f48205beScasper 	res = strtoul(str, &p, 0);
263*f48205beScasper 	if (p == str || *p != '\0' || errno != 0)
264*f48205beScasper 		return ((uint32_t)-1);
2657c478bd9Sstevel@tonic-gate 	else
266*f48205beScasper 		return ((uint32_t)res);
2677c478bd9Sstevel@tonic-gate }
2687c478bd9Sstevel@tonic-gate 
2697c478bd9Sstevel@tonic-gate static gid_t
str2gid(const char * grnam)2707c478bd9Sstevel@tonic-gate str2gid(const char *grnam)
2717c478bd9Sstevel@tonic-gate {
2727c478bd9Sstevel@tonic-gate 	struct group *grp = getgrnam(grnam);
2737c478bd9Sstevel@tonic-gate 	gid_t res;
2747c478bd9Sstevel@tonic-gate 
2757c478bd9Sstevel@tonic-gate 	if (grp == NULL) {
276*f48205beScasper 		res = (gid_t)str2id(grnam);
277*f48205beScasper 		if (res == (gid_t)-1) {
2787c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr, "%s: %s: unknown group"
2797c478bd9Sstevel@tonic-gate 			    " or bad gid\n",
2807c478bd9Sstevel@tonic-gate 			    command, grnam);
2817c478bd9Sstevel@tonic-gate 			exit(1);
2827c478bd9Sstevel@tonic-gate 		}
2837c478bd9Sstevel@tonic-gate 	} else {
2847c478bd9Sstevel@tonic-gate 		res = grp->gr_gid;
2857c478bd9Sstevel@tonic-gate 	}
2867c478bd9Sstevel@tonic-gate 	return (res);
2877c478bd9Sstevel@tonic-gate }
2887c478bd9Sstevel@tonic-gate 
2897c478bd9Sstevel@tonic-gate static void
initcred(void)2907c478bd9Sstevel@tonic-gate initcred(void)
2917c478bd9Sstevel@tonic-gate {
2927c478bd9Sstevel@tonic-gate 	struct passwd *pwd;
2937c478bd9Sstevel@tonic-gate 
2947c478bd9Sstevel@tonic-gate 	if ((groups = malloc(ngroups_max * sizeof (gid_t))) == NULL) {
2957c478bd9Sstevel@tonic-gate 		(void) perr("malloc");
2967c478bd9Sstevel@tonic-gate 		exit(1);
2977c478bd9Sstevel@tonic-gate 	}
2987c478bd9Sstevel@tonic-gate 
2997c478bd9Sstevel@tonic-gate 	if (login != NULL) {
3007c478bd9Sstevel@tonic-gate 		pwd = getpwnam(login);
3017c478bd9Sstevel@tonic-gate 
3027c478bd9Sstevel@tonic-gate 		if (pwd == NULL) {
3037c478bd9Sstevel@tonic-gate 			(void) fprintf(stderr, "%s: %s: unknown user\n",
3047c478bd9Sstevel@tonic-gate 			    command, login);
3057c478bd9Sstevel@tonic-gate 			exit(1);
3067c478bd9Sstevel@tonic-gate 		}
3077c478bd9Sstevel@tonic-gate 		uid = pwd->pw_uid;
3087c478bd9Sstevel@tonic-gate 		gid = pwd->pw_gid;
3097c478bd9Sstevel@tonic-gate 
3107c478bd9Sstevel@tonic-gate 		groups[0] = gid;
3117c478bd9Sstevel@tonic-gate 
3127c478bd9Sstevel@tonic-gate 		ngrp = _getgroupsbymember(login, groups, (int)ngroups_max, 1);
3137c478bd9Sstevel@tonic-gate 	}
3147c478bd9Sstevel@tonic-gate 
3157c478bd9Sstevel@tonic-gate 	if (user != NULL) {
3167c478bd9Sstevel@tonic-gate 		pwd = getpwnam(user);
3177c478bd9Sstevel@tonic-gate 		if (pwd == NULL) {
318*f48205beScasper 			uid = (uid_t)str2id(user);
319*f48205beScasper 			if (uid == (uid_t)-1) {
3207c478bd9Sstevel@tonic-gate 				(void) fprintf(stderr, "%s: %s: unknown user"
3217c478bd9Sstevel@tonic-gate 				    " or bad uid\n",
3227c478bd9Sstevel@tonic-gate 				    command, user);
3237c478bd9Sstevel@tonic-gate 				exit(1);
3247c478bd9Sstevel@tonic-gate 			}
3257c478bd9Sstevel@tonic-gate 		} else {
3267c478bd9Sstevel@tonic-gate 			uid = pwd->pw_uid;
3277c478bd9Sstevel@tonic-gate 		}
3287c478bd9Sstevel@tonic-gate 	}
3297c478bd9Sstevel@tonic-gate 
3307c478bd9Sstevel@tonic-gate 	if (group != NULL)
3317c478bd9Sstevel@tonic-gate 		gid = str2gid(group);
3327c478bd9Sstevel@tonic-gate 
3337c478bd9Sstevel@tonic-gate 	if (grplst != NULL) {
3347c478bd9Sstevel@tonic-gate 		char *cgrp;
3357c478bd9Sstevel@tonic-gate 
3367c478bd9Sstevel@tonic-gate 		ngrp = 0;
3377c478bd9Sstevel@tonic-gate 
3387c478bd9Sstevel@tonic-gate 		while ((cgrp = strtok(grplst, ",")) != NULL) {
3397c478bd9Sstevel@tonic-gate 
3407c478bd9Sstevel@tonic-gate 			if (ngrp >= ngroups_max) {
3417c478bd9Sstevel@tonic-gate 				(void) fprintf(stderr, "%s: Too many groups\n",
3427c478bd9Sstevel@tonic-gate 				    command);
3437c478bd9Sstevel@tonic-gate 				exit(1);
3447c478bd9Sstevel@tonic-gate 			}
3457c478bd9Sstevel@tonic-gate 			groups[ngrp++] = str2gid(cgrp);
3467c478bd9Sstevel@tonic-gate 
3477c478bd9Sstevel@tonic-gate 			/* For iterations of strtok */
3487c478bd9Sstevel@tonic-gate 			grplst = NULL;
3497c478bd9Sstevel@tonic-gate 		}
3507c478bd9Sstevel@tonic-gate 	}
3517c478bd9Sstevel@tonic-gate }
352