xref: /illumos-gate/usr/src/lib/passwdutil/nss_attr.c (revision cbea7aca3fd7787405cbdbd93752998f03dfc25f)
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
5c6dc4be3Sgww  * Common Development and Distribution License (the "License").
6c6dc4be3Sgww  * 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 /*
2236e852a1SRaja Andra  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
24*cbea7acaSDominik Hassler  * Copyright 2024 OmniOS Community Edition (OmniOSce) Association.
257c478bd9Sstevel@tonic-gate  */
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate #include <sys/types.h>
287c478bd9Sstevel@tonic-gate #include <errno.h>
297c478bd9Sstevel@tonic-gate #include <stdlib.h>
307c478bd9Sstevel@tonic-gate #include <pwd.h>
317c478bd9Sstevel@tonic-gate #include <shadow.h>
327c478bd9Sstevel@tonic-gate #include <string.h>
337c478bd9Sstevel@tonic-gate #include <stdlib.h>
347c478bd9Sstevel@tonic-gate #include <unistd.h>
357c478bd9Sstevel@tonic-gate #include <nss_dbdefs.h>
367c478bd9Sstevel@tonic-gate 
377c478bd9Sstevel@tonic-gate #include "passwdutil.h"
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate /* from files_attr.c */
407c478bd9Sstevel@tonic-gate struct passwd *private_getpwnam_r(const char *name, struct passwd *result,
417c478bd9Sstevel@tonic-gate     char *buffer, int buflen);
427c478bd9Sstevel@tonic-gate 
43*cbea7acaSDominik Hassler int nss_getattr(const char *name, attrlist *item, pwu_repository_t *rep);
44*cbea7acaSDominik Hassler int nss_getpwnam(const char *name, attrlist *items, pwu_repository_t *rep,
457c478bd9Sstevel@tonic-gate     void **buf);
467c478bd9Sstevel@tonic-gate 
477c478bd9Sstevel@tonic-gate /*
487c478bd9Sstevel@tonic-gate  * nss function pointer table, used by passwdutil_init to initialize
497c478bd9Sstevel@tonic-gate  * the global Repository-OPerations table "rops"
507c478bd9Sstevel@tonic-gate  */
517c478bd9Sstevel@tonic-gate struct repops nss_repops = {
527c478bd9Sstevel@tonic-gate 	NULL,		/* checkhistory */
537c478bd9Sstevel@tonic-gate 	nss_getattr,
547c478bd9Sstevel@tonic-gate 	nss_getpwnam,
557c478bd9Sstevel@tonic-gate 	NULL,		/* update */
567c478bd9Sstevel@tonic-gate 	NULL,		/* putpwnam */
577c478bd9Sstevel@tonic-gate 	NULL,		/* user_to_authenticate */
587c478bd9Sstevel@tonic-gate 	NULL,		/* lock */
597c478bd9Sstevel@tonic-gate 	NULL		/* unlock */
607c478bd9Sstevel@tonic-gate };
617c478bd9Sstevel@tonic-gate 
627c478bd9Sstevel@tonic-gate /*
637c478bd9Sstevel@tonic-gate  * this structure defines the buffer used to keep state between
647c478bd9Sstevel@tonic-gate  * get/update/put calls
657c478bd9Sstevel@tonic-gate  */
667c478bd9Sstevel@tonic-gate struct pwbuf {
677c478bd9Sstevel@tonic-gate 	struct passwd *pwd;
687c478bd9Sstevel@tonic-gate 	char   *pwd_scratch;
697c478bd9Sstevel@tonic-gate 	struct spwd *spwd;
707c478bd9Sstevel@tonic-gate 	char   *spwd_scratch;
717c478bd9Sstevel@tonic-gate 	char   *rep_name;
727c478bd9Sstevel@tonic-gate };
737c478bd9Sstevel@tonic-gate 
747c478bd9Sstevel@tonic-gate /*
757c478bd9Sstevel@tonic-gate  * We should use sysconf, but there is no sysconf name for SHADOW
767c478bd9Sstevel@tonic-gate  * so we use these from nss_dbdefs
777c478bd9Sstevel@tonic-gate  */
787c478bd9Sstevel@tonic-gate #define	PWD_SCRATCH_SIZE NSS_LINELEN_PASSWD
797c478bd9Sstevel@tonic-gate #define	SPW_SCRATCH_SIZE NSS_LINELEN_SHADOW
807c478bd9Sstevel@tonic-gate 
817c478bd9Sstevel@tonic-gate 
827c478bd9Sstevel@tonic-gate /*
837c478bd9Sstevel@tonic-gate  * nss_getpwnam(name, items, rep, buf)
847c478bd9Sstevel@tonic-gate  *
857c478bd9Sstevel@tonic-gate  */
867c478bd9Sstevel@tonic-gate /*ARGSUSED*/
877c478bd9Sstevel@tonic-gate int
nss_getpwnam(const char * name,attrlist * items,pwu_repository_t * rep,void ** buf)88*cbea7acaSDominik Hassler nss_getpwnam(const char *name, attrlist *items, pwu_repository_t *rep,
89*cbea7acaSDominik Hassler     void **buf)
907c478bd9Sstevel@tonic-gate {
917c478bd9Sstevel@tonic-gate 	attrlist *p;
927c478bd9Sstevel@tonic-gate 	struct pwbuf *pwbuf;
937c478bd9Sstevel@tonic-gate 	int repositories = REP_ERANGE;	/* changed if ATTR_REP_NAME is set */
947c478bd9Sstevel@tonic-gate 	int err = PWU_SUCCESS;
957c478bd9Sstevel@tonic-gate 
967c478bd9Sstevel@tonic-gate 	*buf = calloc(1, sizeof (struct pwbuf));
977c478bd9Sstevel@tonic-gate 	pwbuf = (struct pwbuf *)*buf;
98c6dc4be3Sgww 	if (pwbuf == NULL)
99c6dc4be3Sgww 		return (PWU_NOMEM);
1007c478bd9Sstevel@tonic-gate 
1017c478bd9Sstevel@tonic-gate 	/*
1027c478bd9Sstevel@tonic-gate 	 * determine which password structure (/etc/passwd or /etc/shadow)
1037c478bd9Sstevel@tonic-gate 	 * we need for the items we need to update
1047c478bd9Sstevel@tonic-gate 	 */
1057c478bd9Sstevel@tonic-gate 	for (p = items; p != NULL; p = p->next) {
1067c478bd9Sstevel@tonic-gate 		switch (p->type) {
1077c478bd9Sstevel@tonic-gate 		case ATTR_NAME:
1087c478bd9Sstevel@tonic-gate 		case ATTR_UID:
1097c478bd9Sstevel@tonic-gate 		case ATTR_GID:
1107c478bd9Sstevel@tonic-gate 		case ATTR_AGE:
1117c478bd9Sstevel@tonic-gate 		case ATTR_COMMENT:
1127c478bd9Sstevel@tonic-gate 		case ATTR_GECOS:
1137c478bd9Sstevel@tonic-gate 		case ATTR_HOMEDIR:
1147c478bd9Sstevel@tonic-gate 		case ATTR_SHELL:
1157c478bd9Sstevel@tonic-gate 			if (pwbuf->pwd == NULL)
1167c478bd9Sstevel@tonic-gate 				pwbuf->pwd = (struct passwd *)
1177c478bd9Sstevel@tonic-gate 				    malloc(sizeof (struct passwd));
1187c478bd9Sstevel@tonic-gate 			if (pwbuf->pwd == NULL) {
1197c478bd9Sstevel@tonic-gate 				errno = ENOMEM;
1207c478bd9Sstevel@tonic-gate 				if (pwbuf->spwd)
1217c478bd9Sstevel@tonic-gate 					free(pwbuf->spwd);
1227c478bd9Sstevel@tonic-gate 				return (PWU_NOMEM);
1237c478bd9Sstevel@tonic-gate 			}
1247c478bd9Sstevel@tonic-gate 			break;
1257c478bd9Sstevel@tonic-gate 		case ATTR_PASSWD:
1267c478bd9Sstevel@tonic-gate 		case ATTR_PASSWD_SERVER_POLICY:
1277c478bd9Sstevel@tonic-gate 		case ATTR_LSTCHG:
1287c478bd9Sstevel@tonic-gate 		case ATTR_MIN:
1297c478bd9Sstevel@tonic-gate 		case ATTR_MAX:
1307c478bd9Sstevel@tonic-gate 		case ATTR_WARN:
1317c478bd9Sstevel@tonic-gate 		case ATTR_INACT:
1327c478bd9Sstevel@tonic-gate 		case ATTR_EXPIRE:
1337c478bd9Sstevel@tonic-gate 		case ATTR_FLAG:
1347c478bd9Sstevel@tonic-gate 		case ATTR_LOCK_ACCOUNT:
1357c478bd9Sstevel@tonic-gate 		case ATTR_EXPIRE_PASSWORD:
1367c478bd9Sstevel@tonic-gate 		case ATTR_FAILED_LOGINS:
1377c478bd9Sstevel@tonic-gate 			if (pwbuf->spwd == NULL)
1387c478bd9Sstevel@tonic-gate 				pwbuf->spwd = (struct spwd *)
1397c478bd9Sstevel@tonic-gate 				    malloc(sizeof (struct spwd));
1407c478bd9Sstevel@tonic-gate 			if (pwbuf->spwd == NULL) {
1417c478bd9Sstevel@tonic-gate 				errno = ENOMEM;
1427c478bd9Sstevel@tonic-gate 				if (pwbuf->pwd)
1437c478bd9Sstevel@tonic-gate 					free(pwbuf->pwd);
1447c478bd9Sstevel@tonic-gate 				return (PWU_NOMEM);
1457c478bd9Sstevel@tonic-gate 			}
1467c478bd9Sstevel@tonic-gate 			break;
1477c478bd9Sstevel@tonic-gate 		case ATTR_REP_NAME:
1487c478bd9Sstevel@tonic-gate 			/* get the compat names (REP_COMPAT_*) */
1497c478bd9Sstevel@tonic-gate 			repositories = get_ns(rep, PWU_READ);
1507c478bd9Sstevel@tonic-gate 			break;
1517c478bd9Sstevel@tonic-gate 		default:
1527c478bd9Sstevel@tonic-gate 			/*
1537c478bd9Sstevel@tonic-gate 			 * Some other repository might have different values
1547c478bd9Sstevel@tonic-gate 			 * so we ignore those.
1557c478bd9Sstevel@tonic-gate 			 */
1567c478bd9Sstevel@tonic-gate 			break;
1577c478bd9Sstevel@tonic-gate 		}
1587c478bd9Sstevel@tonic-gate 	}
1597c478bd9Sstevel@tonic-gate 
1607c478bd9Sstevel@tonic-gate 	if (pwbuf->pwd) {
1617c478bd9Sstevel@tonic-gate 		if ((pwbuf->pwd_scratch = malloc(PWD_SCRATCH_SIZE)) == NULL) {
1627c478bd9Sstevel@tonic-gate 			err = PWU_NOMEM;
1637c478bd9Sstevel@tonic-gate 			goto error;
1647c478bd9Sstevel@tonic-gate 		}
1657c478bd9Sstevel@tonic-gate 		if (getpwnam_r(name, pwbuf->pwd, pwbuf->pwd_scratch,
1667c478bd9Sstevel@tonic-gate 		    PWD_SCRATCH_SIZE) == NULL) {
1677c478bd9Sstevel@tonic-gate 			err = PWU_NOT_FOUND;
1687c478bd9Sstevel@tonic-gate 			goto error;
1697c478bd9Sstevel@tonic-gate 		}
1707c478bd9Sstevel@tonic-gate 	}
1717c478bd9Sstevel@tonic-gate 
1727c478bd9Sstevel@tonic-gate 	if (pwbuf->spwd) {
1737c478bd9Sstevel@tonic-gate 		if ((pwbuf->spwd_scratch = malloc(SPW_SCRATCH_SIZE)) == NULL) {
1747c478bd9Sstevel@tonic-gate 			err = PWU_NOMEM;
1757c478bd9Sstevel@tonic-gate 			goto error;
1767c478bd9Sstevel@tonic-gate 		}
1777c478bd9Sstevel@tonic-gate 		if (getspnam_r(name, pwbuf->spwd, pwbuf->spwd_scratch,
1787c478bd9Sstevel@tonic-gate 		    SPW_SCRATCH_SIZE) == NULL) {
1797c478bd9Sstevel@tonic-gate 			err = PWU_NOT_FOUND;
1807c478bd9Sstevel@tonic-gate 			goto error;
1817c478bd9Sstevel@tonic-gate 		}
1827c478bd9Sstevel@tonic-gate 	}
1837c478bd9Sstevel@tonic-gate 
1847c478bd9Sstevel@tonic-gate 	/* pwbuf->rep_name tells us where the user in fact comes from */
1857c478bd9Sstevel@tonic-gate 	if (repositories != REP_ERANGE) {
1867c478bd9Sstevel@tonic-gate 		struct passwd pwd;
1877c478bd9Sstevel@tonic-gate 		char pwd_scratch[PWD_SCRATCH_SIZE];
1887c478bd9Sstevel@tonic-gate 
1897c478bd9Sstevel@tonic-gate 		/* can we find the user locally? */
1907c478bd9Sstevel@tonic-gate 		if (private_getpwnam_r(name, &pwd, pwd_scratch,
1917c478bd9Sstevel@tonic-gate 		    PWD_SCRATCH_SIZE) != NULL)
1927c478bd9Sstevel@tonic-gate 			pwbuf->rep_name = "files";
1937c478bd9Sstevel@tonic-gate 		else if (repositories & REP_COMPAT_LDAP)
1947c478bd9Sstevel@tonic-gate 			pwbuf->rep_name = "ldap";
1957c478bd9Sstevel@tonic-gate 		else if (repositories & REP_COMPAT_NIS)
1967c478bd9Sstevel@tonic-gate 			pwbuf->rep_name = "nis";
1977c478bd9Sstevel@tonic-gate 		else
1987c478bd9Sstevel@tonic-gate 			pwbuf->rep_name = "nss";
1997c478bd9Sstevel@tonic-gate 	} else
2007c478bd9Sstevel@tonic-gate 		pwbuf->rep_name = "nss";
2017c478bd9Sstevel@tonic-gate 
2027c478bd9Sstevel@tonic-gate 	return (PWU_SUCCESS);
2037c478bd9Sstevel@tonic-gate error:
2047c478bd9Sstevel@tonic-gate 	if (pwbuf->pwd) free(pwbuf->pwd);
2057c478bd9Sstevel@tonic-gate 	if (pwbuf->pwd_scratch) free(pwbuf->pwd_scratch);
2067c478bd9Sstevel@tonic-gate 	if (pwbuf->spwd) free(pwbuf->spwd);
2077c478bd9Sstevel@tonic-gate 	if (pwbuf->spwd_scratch) free(pwbuf->spwd_scratch);
2087c478bd9Sstevel@tonic-gate 	free(pwbuf);
2097c478bd9Sstevel@tonic-gate 	*buf = NULL;
2107c478bd9Sstevel@tonic-gate 
2117c478bd9Sstevel@tonic-gate 	return (err);
2127c478bd9Sstevel@tonic-gate }
2137c478bd9Sstevel@tonic-gate 
2147c478bd9Sstevel@tonic-gate 
2157c478bd9Sstevel@tonic-gate /*
2167c478bd9Sstevel@tonic-gate  * nss_getattr(name, items, rep)
2177c478bd9Sstevel@tonic-gate  *
2187c478bd9Sstevel@tonic-gate  * Get attributes specified in list 'items'
2197c478bd9Sstevel@tonic-gate  */
2207c478bd9Sstevel@tonic-gate int
nss_getattr(const char * name,attrlist * items,pwu_repository_t * rep)221*cbea7acaSDominik Hassler nss_getattr(const char *name, attrlist *items, pwu_repository_t *rep)
2227c478bd9Sstevel@tonic-gate {
2237c478bd9Sstevel@tonic-gate 	struct pwbuf *pwbuf;
2247c478bd9Sstevel@tonic-gate 	struct passwd *pw;
2257c478bd9Sstevel@tonic-gate 	struct spwd *spw;
2267c478bd9Sstevel@tonic-gate 	attrlist *w;
2277c478bd9Sstevel@tonic-gate 	int res = 0;
2287c478bd9Sstevel@tonic-gate 
2297c478bd9Sstevel@tonic-gate 	res = nss_getpwnam(name, items, rep, (void **)&pwbuf);
2307c478bd9Sstevel@tonic-gate 	if (res != PWU_SUCCESS)
2317c478bd9Sstevel@tonic-gate 		return (res);
2327c478bd9Sstevel@tonic-gate 
2337c478bd9Sstevel@tonic-gate 	pw = pwbuf->pwd;
2347c478bd9Sstevel@tonic-gate 	spw = pwbuf->spwd;
2357c478bd9Sstevel@tonic-gate 
2367c478bd9Sstevel@tonic-gate 	for (w = items; res == PWU_SUCCESS && w != NULL; w = w->next) {
2377c478bd9Sstevel@tonic-gate 		switch (w->type) {
2387c478bd9Sstevel@tonic-gate 		case ATTR_NAME:
2397c478bd9Sstevel@tonic-gate 			if ((w->data.val_s = strdup(pw->pw_name)) == NULL)
2407c478bd9Sstevel@tonic-gate 				res = PWU_NOMEM;
2417c478bd9Sstevel@tonic-gate 			break;
2427c478bd9Sstevel@tonic-gate 		case ATTR_COMMENT:
2437c478bd9Sstevel@tonic-gate 			if ((w->data.val_s = strdup(pw->pw_comment)) == NULL)
2447c478bd9Sstevel@tonic-gate 				res = PWU_NOMEM;
2457c478bd9Sstevel@tonic-gate 			break;
2467c478bd9Sstevel@tonic-gate 		case ATTR_GECOS:
2477c478bd9Sstevel@tonic-gate 			if ((w->data.val_s = strdup(pw->pw_gecos)) == NULL)
2487c478bd9Sstevel@tonic-gate 				res = PWU_NOMEM;
2497c478bd9Sstevel@tonic-gate 			break;
2507c478bd9Sstevel@tonic-gate 		case ATTR_HOMEDIR:
2517c478bd9Sstevel@tonic-gate 			if ((w->data.val_s = strdup(pw->pw_dir)) == NULL)
2527c478bd9Sstevel@tonic-gate 				res = PWU_NOMEM;
2537c478bd9Sstevel@tonic-gate 			break;
2547c478bd9Sstevel@tonic-gate 		case ATTR_SHELL:
2557c478bd9Sstevel@tonic-gate 			if ((w->data.val_s = strdup(pw->pw_shell)) == NULL)
2567c478bd9Sstevel@tonic-gate 				res = PWU_NOMEM;
2577c478bd9Sstevel@tonic-gate 			break;
2587c478bd9Sstevel@tonic-gate 		/*
2597c478bd9Sstevel@tonic-gate 		 * Nothing special needs to be done for
2607c478bd9Sstevel@tonic-gate 		 * server policy
2617c478bd9Sstevel@tonic-gate 		 */
2627c478bd9Sstevel@tonic-gate 		case ATTR_PASSWD:
2637c478bd9Sstevel@tonic-gate 		case ATTR_PASSWD_SERVER_POLICY:
2647c478bd9Sstevel@tonic-gate 			if ((w->data.val_s = strdup(spw->sp_pwdp)) == NULL)
2657c478bd9Sstevel@tonic-gate 				res = PWU_NOMEM;
2667c478bd9Sstevel@tonic-gate 			break;
2677c478bd9Sstevel@tonic-gate 		case ATTR_AGE:
2687c478bd9Sstevel@tonic-gate 			if ((w->data.val_s = strdup(pw->pw_age)) == NULL)
2697c478bd9Sstevel@tonic-gate 				res = PWU_NOMEM;
2707c478bd9Sstevel@tonic-gate 			break;
2717c478bd9Sstevel@tonic-gate 		case ATTR_REP_NAME:
2727c478bd9Sstevel@tonic-gate 			if ((w->data.val_s = strdup(pwbuf->rep_name)) == NULL)
2737c478bd9Sstevel@tonic-gate 				res = PWU_NOMEM;
2747c478bd9Sstevel@tonic-gate 			break;
2757c478bd9Sstevel@tonic-gate 
2767c478bd9Sstevel@tonic-gate 		/* integer values */
2777c478bd9Sstevel@tonic-gate 		case ATTR_UID:
2787c478bd9Sstevel@tonic-gate 			w->data.val_i = pw->pw_uid;
2797c478bd9Sstevel@tonic-gate 			break;
2807c478bd9Sstevel@tonic-gate 		case ATTR_GID:
2817c478bd9Sstevel@tonic-gate 			w->data.val_i = pw->pw_gid;
2827c478bd9Sstevel@tonic-gate 			break;
2837c478bd9Sstevel@tonic-gate 		case ATTR_LSTCHG:
2847c478bd9Sstevel@tonic-gate 			w->data.val_i = spw->sp_lstchg;
2857c478bd9Sstevel@tonic-gate 			break;
2867c478bd9Sstevel@tonic-gate 		case ATTR_MIN:
2877c478bd9Sstevel@tonic-gate 			w->data.val_i = spw->sp_min;
2887c478bd9Sstevel@tonic-gate 			break;
2897c478bd9Sstevel@tonic-gate 		case ATTR_MAX:
2907c478bd9Sstevel@tonic-gate 			w->data.val_i = spw->sp_max;
2917c478bd9Sstevel@tonic-gate 			break;
2927c478bd9Sstevel@tonic-gate 		case ATTR_WARN:
2937c478bd9Sstevel@tonic-gate 			w->data.val_i = spw->sp_warn;
2947c478bd9Sstevel@tonic-gate 			break;
2957c478bd9Sstevel@tonic-gate 		case ATTR_INACT:
2967c478bd9Sstevel@tonic-gate 			w->data.val_i = spw->sp_inact;
2977c478bd9Sstevel@tonic-gate 			break;
2987c478bd9Sstevel@tonic-gate 		case ATTR_EXPIRE:
2997c478bd9Sstevel@tonic-gate 			w->data.val_i = spw->sp_expire;
3007c478bd9Sstevel@tonic-gate 			break;
3017c478bd9Sstevel@tonic-gate 		case ATTR_FLAG:
3027c478bd9Sstevel@tonic-gate 			w->data.val_i = spw->sp_flag;
3037c478bd9Sstevel@tonic-gate 			break;
3047c478bd9Sstevel@tonic-gate 		case ATTR_FAILED_LOGINS:
3057c478bd9Sstevel@tonic-gate 			w->data.val_i = spw->sp_flag & FAILCOUNT_MASK;
3067c478bd9Sstevel@tonic-gate 			break;
3077c478bd9Sstevel@tonic-gate 		default:
3087c478bd9Sstevel@tonic-gate 			break;
3097c478bd9Sstevel@tonic-gate 		}
3107c478bd9Sstevel@tonic-gate 	}
3117c478bd9Sstevel@tonic-gate 
3127c478bd9Sstevel@tonic-gate 	if (pwbuf->pwd) free(pwbuf->pwd);
3137c478bd9Sstevel@tonic-gate 	if (pwbuf->pwd_scratch) free(pwbuf->pwd_scratch);
3147c478bd9Sstevel@tonic-gate 	if (pwbuf->spwd) free(pwbuf->spwd);
3157c478bd9Sstevel@tonic-gate 	if (pwbuf->spwd_scratch) free(pwbuf->spwd_scratch);
3167c478bd9Sstevel@tonic-gate 	free(pwbuf);
3177c478bd9Sstevel@tonic-gate 
3187c478bd9Sstevel@tonic-gate 	return (res);
3197c478bd9Sstevel@tonic-gate }
320