xref: /onnv-gate/usr/src/lib/libc/port/gen/getpwnam_r.c (revision 10386:935ab057bcbb)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * CDDL HEADER START
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
52830Sdjl  * Common Development and Distribution License (the "License").
62830Sdjl  * You may not use this file except in compliance with the License.
70Sstevel@tonic-gate  *
80Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
90Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
100Sstevel@tonic-gate  * See the License for the specific language governing permissions
110Sstevel@tonic-gate  * and limitations under the License.
120Sstevel@tonic-gate  *
130Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
140Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
150Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
160Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
170Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
180Sstevel@tonic-gate  *
190Sstevel@tonic-gate  * CDDL HEADER END
200Sstevel@tonic-gate  */
216812Sraf 
220Sstevel@tonic-gate /*
23*10386SPradhap.Devarajan@Sun.COM  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate  * Use is subject to license terms.
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate 
276812Sraf #include "lint.h"
280Sstevel@tonic-gate #include <sys/types.h>
290Sstevel@tonic-gate #include <pwd.h>
300Sstevel@tonic-gate #include <nss_dbdefs.h>
310Sstevel@tonic-gate #include <stdio.h>
320Sstevel@tonic-gate #include <synch.h>
330Sstevel@tonic-gate #include <sys/param.h>
340Sstevel@tonic-gate #include <string.h>
350Sstevel@tonic-gate #include <stdlib.h>
360Sstevel@tonic-gate #include <sys/mman.h>
37*10386SPradhap.Devarajan@Sun.COM #include <errno.h>
380Sstevel@tonic-gate 
390Sstevel@tonic-gate int str2passwd(const char *, int, void *,
400Sstevel@tonic-gate 	char *, int);
410Sstevel@tonic-gate 
420Sstevel@tonic-gate static DEFINE_NSS_DB_ROOT(db_root);
430Sstevel@tonic-gate static DEFINE_NSS_GETENT(context);
440Sstevel@tonic-gate 
450Sstevel@tonic-gate void
_nss_initf_passwd(nss_db_params_t * p)460Sstevel@tonic-gate _nss_initf_passwd(nss_db_params_t *p)
470Sstevel@tonic-gate {
480Sstevel@tonic-gate 	p->name	= NSS_DBNAM_PASSWD;
490Sstevel@tonic-gate 	p->default_config = NSS_DEFCONF_PASSWD;
500Sstevel@tonic-gate }
510Sstevel@tonic-gate 
520Sstevel@tonic-gate #include <getxby_door.h>
530Sstevel@tonic-gate 
540Sstevel@tonic-gate struct passwd *
550Sstevel@tonic-gate _uncached_getpwuid_r(uid_t uid, struct passwd *result, char *buffer,
560Sstevel@tonic-gate 	int buflen);
570Sstevel@tonic-gate 
580Sstevel@tonic-gate struct passwd *
590Sstevel@tonic-gate _uncached_getpwnam_r(const char *name, struct passwd *result, char *buffer,
600Sstevel@tonic-gate     int buflen);
610Sstevel@tonic-gate 
620Sstevel@tonic-gate /*
630Sstevel@tonic-gate  * POSIX.1c Draft-6 version of the function getpwnam_r.
640Sstevel@tonic-gate  * It was implemented by Solaris 2.3.
650Sstevel@tonic-gate  */
660Sstevel@tonic-gate struct passwd *
getpwnam_r(const char * name,struct passwd * result,char * buffer,int buflen)676812Sraf getpwnam_r(const char *name, struct passwd *result, char *buffer, int buflen)
680Sstevel@tonic-gate {
692830Sdjl 	nss_XbyY_args_t arg;
700Sstevel@tonic-gate 
712830Sdjl 	if (name == (const char *)NULL) {
720Sstevel@tonic-gate 		errno = ERANGE;
732830Sdjl 		return (NULL);
740Sstevel@tonic-gate 	}
752830Sdjl 	NSS_XbyY_INIT(&arg, result, buffer, buflen, str2passwd);
762830Sdjl 	arg.key.name = name;
772830Sdjl 	(void) nss_search(&db_root, _nss_initf_passwd, NSS_DBOP_PASSWD_BYNAME,
786812Sraf 	    &arg);
792830Sdjl 	return ((struct passwd *)NSS_XbyY_FINI(&arg));
800Sstevel@tonic-gate }
810Sstevel@tonic-gate 
820Sstevel@tonic-gate /*
830Sstevel@tonic-gate  * POSIX.1c Draft-6 version of the function getpwuid_r.
840Sstevel@tonic-gate  * It was implemented by Solaris 2.3.
850Sstevel@tonic-gate  */
860Sstevel@tonic-gate struct passwd *
getpwuid_r(uid_t uid,struct passwd * result,char * buffer,int buflen)876812Sraf getpwuid_r(uid_t uid, struct passwd *result, char *buffer, int buflen)
880Sstevel@tonic-gate {
892830Sdjl 	nss_XbyY_args_t arg;
900Sstevel@tonic-gate 
912830Sdjl 	NSS_XbyY_INIT(&arg, result, buffer, buflen, str2passwd);
922830Sdjl 	arg.key.uid = uid;
932830Sdjl 	(void) nss_search(&db_root, _nss_initf_passwd, NSS_DBOP_PASSWD_BYUID,
946812Sraf 	    &arg);
952830Sdjl 	return ((struct passwd *)NSS_XbyY_FINI(&arg));
960Sstevel@tonic-gate }
970Sstevel@tonic-gate 
980Sstevel@tonic-gate 
990Sstevel@tonic-gate struct passwd *
_uncached_getpwuid_r(uid_t uid,struct passwd * result,char * buffer,int buflen)1000Sstevel@tonic-gate _uncached_getpwuid_r(uid_t uid, struct passwd *result, char *buffer,
1010Sstevel@tonic-gate 	int buflen)
1020Sstevel@tonic-gate {
1030Sstevel@tonic-gate 	nss_XbyY_args_t arg;
1040Sstevel@tonic-gate 
1050Sstevel@tonic-gate 	NSS_XbyY_INIT(&arg, result, buffer, buflen, str2passwd);
1060Sstevel@tonic-gate 	arg.key.uid = uid;
1070Sstevel@tonic-gate 	(void) nss_search(&db_root, _nss_initf_passwd, NSS_DBOP_PASSWD_BYUID,
1086812Sraf 	    &arg);
1090Sstevel@tonic-gate 	return ((struct passwd *)NSS_XbyY_FINI(&arg));
1100Sstevel@tonic-gate }
1110Sstevel@tonic-gate 
1120Sstevel@tonic-gate 
1130Sstevel@tonic-gate /*
1140Sstevel@tonic-gate  * POSIX.1c standard version of the function getpwuid_r.
1150Sstevel@tonic-gate  * User gets it via static getpwuid_r from the header file.
1160Sstevel@tonic-gate  */
1170Sstevel@tonic-gate int
__posix_getpwuid_r(uid_t uid,struct passwd * pwd,char * buffer,size_t bufsize,struct passwd ** result)1180Sstevel@tonic-gate __posix_getpwuid_r(uid_t uid, struct passwd *pwd, char *buffer,
1190Sstevel@tonic-gate     size_t bufsize, struct passwd **result)
1200Sstevel@tonic-gate {
1210Sstevel@tonic-gate 	int nerrno = 0;
1220Sstevel@tonic-gate 	int oerrno = errno;
1230Sstevel@tonic-gate 
1240Sstevel@tonic-gate 	errno = 0;
1256812Sraf 	if ((*result = getpwuid_r(uid, pwd, buffer, (uintptr_t)bufsize))
1266812Sraf 	    == NULL) {
1270Sstevel@tonic-gate 			nerrno = errno;
1280Sstevel@tonic-gate 	}
1290Sstevel@tonic-gate 	errno = oerrno;
1300Sstevel@tonic-gate 	return (nerrno);
1310Sstevel@tonic-gate }
1320Sstevel@tonic-gate 
1330Sstevel@tonic-gate struct passwd *
_uncached_getpwnam_r(const char * name,struct passwd * result,char * buffer,int buflen)1340Sstevel@tonic-gate _uncached_getpwnam_r(const char *name, struct passwd *result, char *buffer,
1350Sstevel@tonic-gate 	int buflen)
1360Sstevel@tonic-gate {
1370Sstevel@tonic-gate 	nss_XbyY_args_t arg;
1380Sstevel@tonic-gate 
1390Sstevel@tonic-gate 	NSS_XbyY_INIT(&arg, result, buffer, buflen, str2passwd);
1400Sstevel@tonic-gate 	arg.key.name = name;
1410Sstevel@tonic-gate 	(void) nss_search(&db_root, _nss_initf_passwd, NSS_DBOP_PASSWD_BYNAME,
1426812Sraf 	    &arg);
1430Sstevel@tonic-gate 	return ((struct passwd *)NSS_XbyY_FINI(&arg));
1440Sstevel@tonic-gate }
1450Sstevel@tonic-gate 
1460Sstevel@tonic-gate /*
1470Sstevel@tonic-gate  * POSIX.1c standard version of the function getpwnam_r.
1480Sstevel@tonic-gate  * User gets it via static getpwnam_r from the header file.
1490Sstevel@tonic-gate  */
1500Sstevel@tonic-gate int
__posix_getpwnam_r(const char * name,struct passwd * pwd,char * buffer,size_t bufsize,struct passwd ** result)1510Sstevel@tonic-gate __posix_getpwnam_r(const char *name, struct passwd *pwd, char *buffer,
1520Sstevel@tonic-gate     size_t bufsize, struct passwd **result)
1530Sstevel@tonic-gate {
1540Sstevel@tonic-gate 	int nerrno = 0;
1550Sstevel@tonic-gate 	int oerrno = errno;
1560Sstevel@tonic-gate 
1570Sstevel@tonic-gate 	errno = 0;
1586812Sraf 	if ((*result = getpwnam_r(name, pwd, buffer, (uintptr_t)bufsize))
1596812Sraf 	    == NULL) {
1600Sstevel@tonic-gate 			nerrno = errno;
1610Sstevel@tonic-gate 	}
1620Sstevel@tonic-gate 	errno = oerrno;
1630Sstevel@tonic-gate 	return (nerrno);
1640Sstevel@tonic-gate }
1650Sstevel@tonic-gate 
1660Sstevel@tonic-gate void
setpwent(void)1670Sstevel@tonic-gate setpwent(void)
1680Sstevel@tonic-gate {
1690Sstevel@tonic-gate 	nss_setent(&db_root, _nss_initf_passwd, &context);
1700Sstevel@tonic-gate }
1710Sstevel@tonic-gate 
1720Sstevel@tonic-gate void
endpwent(void)1730Sstevel@tonic-gate endpwent(void)
1740Sstevel@tonic-gate {
1750Sstevel@tonic-gate 	nss_endent(&db_root, _nss_initf_passwd, &context);
1760Sstevel@tonic-gate 	nss_delete(&db_root);
1770Sstevel@tonic-gate }
1780Sstevel@tonic-gate 
1790Sstevel@tonic-gate struct passwd *
getpwent_r(struct passwd * result,char * buffer,int buflen)1800Sstevel@tonic-gate getpwent_r(struct passwd *result, char *buffer, int buflen)
1810Sstevel@tonic-gate {
1820Sstevel@tonic-gate 	nss_XbyY_args_t arg;
1830Sstevel@tonic-gate 	char		*nam;
1840Sstevel@tonic-gate 
1850Sstevel@tonic-gate 	/* In getXXent_r(), protect the unsuspecting caller from +/- entries */
1860Sstevel@tonic-gate 
1870Sstevel@tonic-gate 	do {
1880Sstevel@tonic-gate 		NSS_XbyY_INIT(&arg, result, buffer, buflen, str2passwd);
1890Sstevel@tonic-gate 		/* No key to fill in */
1900Sstevel@tonic-gate 		(void) nss_getent(&db_root, _nss_initf_passwd, &context, &arg);
1910Sstevel@tonic-gate 	} while (arg.returnval != 0 &&
1920Sstevel@tonic-gate 	    (nam = ((struct passwd *)arg.returnval)->pw_name) != 0 &&
1936812Sraf 	    (*nam == '+' || *nam == '-'));
1940Sstevel@tonic-gate 
1950Sstevel@tonic-gate 	return ((struct passwd *)NSS_XbyY_FINI(&arg));
1960Sstevel@tonic-gate }
1970Sstevel@tonic-gate 
1980Sstevel@tonic-gate struct passwd *
fgetpwent_r(FILE * f,struct passwd * result,char * buffer,int buflen)1990Sstevel@tonic-gate fgetpwent_r(FILE *f, struct passwd *result, char *buffer, int buflen)
2000Sstevel@tonic-gate {
2010Sstevel@tonic-gate 	extern void	_nss_XbyY_fgets(FILE *, nss_XbyY_args_t *);
2020Sstevel@tonic-gate 	nss_XbyY_args_t	arg;
2030Sstevel@tonic-gate 
2040Sstevel@tonic-gate 	/* ... but in fgetXXent_r, the caller deserves any +/- entry he gets */
2050Sstevel@tonic-gate 
2060Sstevel@tonic-gate 	/* No key to fill in */
2070Sstevel@tonic-gate 	NSS_XbyY_INIT(&arg, result, buffer, buflen, str2passwd);
2080Sstevel@tonic-gate 	_nss_XbyY_fgets(f, &arg);
2090Sstevel@tonic-gate 	return ((struct passwd *)NSS_XbyY_FINI(&arg));
2100Sstevel@tonic-gate }
2110Sstevel@tonic-gate 
2120Sstevel@tonic-gate static char *
gettok(char ** nextpp)2130Sstevel@tonic-gate gettok(char **nextpp)
2140Sstevel@tonic-gate {
2150Sstevel@tonic-gate 	char	*p = *nextpp;
2160Sstevel@tonic-gate 	char	*q = p;
2170Sstevel@tonic-gate 	char	c;
2180Sstevel@tonic-gate 
2190Sstevel@tonic-gate 	if (p == 0)
2200Sstevel@tonic-gate 		return (0);
2210Sstevel@tonic-gate 
2220Sstevel@tonic-gate 	while ((c = *q) != '\0' && c != ':')
2230Sstevel@tonic-gate 		q++;
2240Sstevel@tonic-gate 
2250Sstevel@tonic-gate 	if (c == '\0')
2260Sstevel@tonic-gate 		*nextpp = 0;
2270Sstevel@tonic-gate 	else {
2280Sstevel@tonic-gate 		*q++ = '\0';
2290Sstevel@tonic-gate 		*nextpp = q;
2300Sstevel@tonic-gate 	}
2310Sstevel@tonic-gate 	return (p);
2320Sstevel@tonic-gate }
2330Sstevel@tonic-gate 
2340Sstevel@tonic-gate /*
2350Sstevel@tonic-gate  * Return values: 0 = success, 1 = parse error, 2 = erange ...
2360Sstevel@tonic-gate  * The structure pointer passed in is a structure in the caller's space
2370Sstevel@tonic-gate  * wherein the field pointers would be set to areas in the buffer if
2380Sstevel@tonic-gate  * need be. instring and buffer should be separate areas.
2390Sstevel@tonic-gate  */
2400Sstevel@tonic-gate int
str2passwd(const char * instr,int lenstr,void * ent,char * buffer,int buflen)2410Sstevel@tonic-gate str2passwd(const char *instr, int lenstr, void *ent, char *buffer, int buflen)
2420Sstevel@tonic-gate {
2430Sstevel@tonic-gate 	struct passwd	*passwd	= (struct passwd *)ent;
2440Sstevel@tonic-gate 	char		*p, *next;
2450Sstevel@tonic-gate 	int		black_magic;	/* "+" or "-" entry */
2468040SBaban.Kenkre@Sun.COM 	ulong_t		tmp;
2470Sstevel@tonic-gate 
2480Sstevel@tonic-gate 	if (lenstr + 1 > buflen)
2490Sstevel@tonic-gate 		return (NSS_STR_PARSE_ERANGE);
2500Sstevel@tonic-gate 
2510Sstevel@tonic-gate 	/*
2520Sstevel@tonic-gate 	 * We copy the input string into the output buffer and
2530Sstevel@tonic-gate 	 * operate on it in place.
2540Sstevel@tonic-gate 	 */
2552830Sdjl 	if (instr != buffer) {
2562830Sdjl 		/* Overlapping buffer copies are OK */
2572830Sdjl 		(void) memmove(buffer, instr, lenstr);
2582830Sdjl 		buffer[lenstr] = '\0';
2592830Sdjl 	}
2602830Sdjl 
2612830Sdjl 	/* quick exit do not entry fill if not needed */
2622830Sdjl 	if (ent == (void *)NULL)
2632830Sdjl 		return (NSS_STR_PARSE_SUCCESS);
2640Sstevel@tonic-gate 
2650Sstevel@tonic-gate 	next = buffer;
2660Sstevel@tonic-gate 
2670Sstevel@tonic-gate 	passwd->pw_name = p = gettok(&next);		/* username */
2680Sstevel@tonic-gate 	if (*p == '\0') {
2690Sstevel@tonic-gate 		/* Empty username;  not allowed */
2700Sstevel@tonic-gate 		return (NSS_STR_PARSE_PARSE);
2710Sstevel@tonic-gate 	}
2720Sstevel@tonic-gate 	black_magic = (*p == '+' || *p == '-');
2730Sstevel@tonic-gate 	if (black_magic) {
2740Sstevel@tonic-gate 		passwd->pw_uid = UID_NOBODY;
2750Sstevel@tonic-gate 		passwd->pw_gid = GID_NOBODY;
2760Sstevel@tonic-gate 		/*
2770Sstevel@tonic-gate 		 *  pwconv tests pw_passwd and pw_age == NULL
2780Sstevel@tonic-gate 		 */
2790Sstevel@tonic-gate 		passwd->pw_passwd  = "";
2800Sstevel@tonic-gate 		passwd->pw_age	= "";
2810Sstevel@tonic-gate 		/*
2820Sstevel@tonic-gate 		 * the rest of the passwd entry is "optional"
2830Sstevel@tonic-gate 		 */
2840Sstevel@tonic-gate 		passwd->pw_comment = "";
2850Sstevel@tonic-gate 		passwd->pw_gecos = "";
2860Sstevel@tonic-gate 		passwd->pw_dir	= "";
2870Sstevel@tonic-gate 		passwd->pw_shell = "";
2880Sstevel@tonic-gate 	}
2890Sstevel@tonic-gate 
2900Sstevel@tonic-gate 	passwd->pw_passwd = p = gettok(&next);		/* password */
2910Sstevel@tonic-gate 	if (p == 0) {
2920Sstevel@tonic-gate 		if (black_magic)
2930Sstevel@tonic-gate 			return (NSS_STR_PARSE_SUCCESS);
2940Sstevel@tonic-gate 		else
2950Sstevel@tonic-gate 			return (NSS_STR_PARSE_PARSE);
2960Sstevel@tonic-gate 	}
2970Sstevel@tonic-gate 	for (; *p != '\0';  p++) {			/* age */
2980Sstevel@tonic-gate 		if (*p == ',') {
2990Sstevel@tonic-gate 			*p++ = '\0';
3000Sstevel@tonic-gate 			break;
3010Sstevel@tonic-gate 		}
3020Sstevel@tonic-gate 	}
3030Sstevel@tonic-gate 	passwd->pw_age = p;
3040Sstevel@tonic-gate 
3050Sstevel@tonic-gate 	p = next;					/* uid */
3060Sstevel@tonic-gate 	if (p == 0 || *p == '\0') {
3070Sstevel@tonic-gate 		if (black_magic)
3080Sstevel@tonic-gate 			return (NSS_STR_PARSE_SUCCESS);
3090Sstevel@tonic-gate 		else
3100Sstevel@tonic-gate 			return (NSS_STR_PARSE_PARSE);
3110Sstevel@tonic-gate 	}
3120Sstevel@tonic-gate 	if (!black_magic) {
3138040SBaban.Kenkre@Sun.COM 		/*
3148040SBaban.Kenkre@Sun.COM 		 * strtoul returns unsigned long which is
3158040SBaban.Kenkre@Sun.COM 		 * 8 bytes on a 64-bit system. We don't want
3168040SBaban.Kenkre@Sun.COM 		 * to assign it directly to passwd->pw_uid
3178040SBaban.Kenkre@Sun.COM 		 * which is 4 bytes or else we will end up
3188040SBaban.Kenkre@Sun.COM 		 * truncating the value.
3198040SBaban.Kenkre@Sun.COM 		 */
320*10386SPradhap.Devarajan@Sun.COM 		errno = 0;
3218040SBaban.Kenkre@Sun.COM 		tmp = strtoul(p, &next, 10);
322*10386SPradhap.Devarajan@Sun.COM 		if (next == p || errno != 0) {
3230Sstevel@tonic-gate 			/* uid field should be nonempty */
324*10386SPradhap.Devarajan@Sun.COM 			/* also check errno from strtoul */
3250Sstevel@tonic-gate 			return (NSS_STR_PARSE_PARSE);
3260Sstevel@tonic-gate 		}
3270Sstevel@tonic-gate 		/*
3280Sstevel@tonic-gate 		 * The old code (in 2.0 through 2.5) would check
3290Sstevel@tonic-gate 		 * for the uid being negative, or being greater
3300Sstevel@tonic-gate 		 * than 60001 (the rfs limit).  If it met either of
3310Sstevel@tonic-gate 		 * these conditions, the uid was translated to 60001.
3320Sstevel@tonic-gate 		 *
3338040SBaban.Kenkre@Sun.COM 		 * Now we just check for -1 (UINT32_MAX); anything else
3340Sstevel@tonic-gate 		 * is administrative policy
3350Sstevel@tonic-gate 		 */
3368040SBaban.Kenkre@Sun.COM 		if (tmp >= UINT32_MAX)
3370Sstevel@tonic-gate 			passwd->pw_uid = UID_NOBODY;
3388040SBaban.Kenkre@Sun.COM 		else
3398040SBaban.Kenkre@Sun.COM 			passwd->pw_uid = (uid_t)tmp;
3400Sstevel@tonic-gate 	}
3410Sstevel@tonic-gate 	if (*next++ != ':') {
3420Sstevel@tonic-gate 		if (black_magic)
3430Sstevel@tonic-gate 			(void) gettok(&next);
3440Sstevel@tonic-gate 		else
3450Sstevel@tonic-gate 			return (NSS_STR_PARSE_PARSE);
3460Sstevel@tonic-gate 	}
3470Sstevel@tonic-gate 	p = next;					/* gid */
3480Sstevel@tonic-gate 	if (p == 0 || *p == '\0') {
3490Sstevel@tonic-gate 		if (black_magic)
3500Sstevel@tonic-gate 			return (NSS_STR_PARSE_SUCCESS);
3510Sstevel@tonic-gate 		else
3520Sstevel@tonic-gate 			return (NSS_STR_PARSE_PARSE);
3530Sstevel@tonic-gate 	}
3540Sstevel@tonic-gate 	if (!black_magic) {
355*10386SPradhap.Devarajan@Sun.COM 		errno = 0;
3568040SBaban.Kenkre@Sun.COM 		tmp = strtoul(p, &next, 10);
357*10386SPradhap.Devarajan@Sun.COM 		if (next == p || errno != 0) {
3580Sstevel@tonic-gate 			/* gid field should be nonempty */
359*10386SPradhap.Devarajan@Sun.COM 			/* also check errno from strtoul */
3600Sstevel@tonic-gate 			return (NSS_STR_PARSE_PARSE);
3610Sstevel@tonic-gate 		}
3620Sstevel@tonic-gate 		/*
3638040SBaban.Kenkre@Sun.COM 		 * gid should not be -1; anything else
3640Sstevel@tonic-gate 		 * is administrative policy.
3650Sstevel@tonic-gate 		 */
366*10386SPradhap.Devarajan@Sun.COM 		if (tmp >= UINT32_MAX)
3670Sstevel@tonic-gate 			passwd->pw_gid = GID_NOBODY;
3688040SBaban.Kenkre@Sun.COM 		else
3698040SBaban.Kenkre@Sun.COM 			passwd->pw_gid = (gid_t)tmp;
3700Sstevel@tonic-gate 	}
3710Sstevel@tonic-gate 	if (*next++ != ':') {
3720Sstevel@tonic-gate 		if (black_magic)
3730Sstevel@tonic-gate 			(void) gettok(&next);
3740Sstevel@tonic-gate 		else
3750Sstevel@tonic-gate 			return (NSS_STR_PARSE_PARSE);
3760Sstevel@tonic-gate 	}
3770Sstevel@tonic-gate 
3780Sstevel@tonic-gate 	passwd->pw_gecos = passwd->pw_comment = p = gettok(&next);
3790Sstevel@tonic-gate 	if (p == 0) {
3800Sstevel@tonic-gate 		if (black_magic)
3810Sstevel@tonic-gate 			return (NSS_STR_PARSE_SUCCESS);
3820Sstevel@tonic-gate 		else
3830Sstevel@tonic-gate 			return (NSS_STR_PARSE_PARSE);
3840Sstevel@tonic-gate 	}
3850Sstevel@tonic-gate 
3860Sstevel@tonic-gate 	passwd->pw_dir = p = gettok(&next);
3870Sstevel@tonic-gate 	if (p == 0) {
3880Sstevel@tonic-gate 		if (black_magic)
3890Sstevel@tonic-gate 			return (NSS_STR_PARSE_SUCCESS);
3900Sstevel@tonic-gate 		else
3910Sstevel@tonic-gate 			return (NSS_STR_PARSE_PARSE);
3920Sstevel@tonic-gate 	}
3930Sstevel@tonic-gate 
3940Sstevel@tonic-gate 	passwd->pw_shell = p = gettok(&next);
3950Sstevel@tonic-gate 	if (p == 0) {
3960Sstevel@tonic-gate 		if (black_magic)
3970Sstevel@tonic-gate 			return (NSS_STR_PARSE_SUCCESS);
3980Sstevel@tonic-gate 		else
3990Sstevel@tonic-gate 			return (NSS_STR_PARSE_PARSE);
4000Sstevel@tonic-gate 	}
4010Sstevel@tonic-gate 
4020Sstevel@tonic-gate 	/* Better not be any more fields... */
4030Sstevel@tonic-gate 	if (next == 0) {
4040Sstevel@tonic-gate 		/* Successfully parsed and stored */
4050Sstevel@tonic-gate 		return (NSS_STR_PARSE_SUCCESS);
4060Sstevel@tonic-gate 	}
4070Sstevel@tonic-gate 	return (NSS_STR_PARSE_PARSE);
4080Sstevel@tonic-gate }
409