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
5*2830Sdjl  * Common Development and Distribution License (the "License").
6*2830Sdjl  * 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  */
21132Srobinson 
220Sstevel@tonic-gate /*
23*2830Sdjl  * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
240Sstevel@tonic-gate  * Use is subject to license terms.
250Sstevel@tonic-gate  */
260Sstevel@tonic-gate 
270Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
280Sstevel@tonic-gate 
290Sstevel@tonic-gate #include "mt.h"
300Sstevel@tonic-gate #include <stdio.h>
310Sstevel@tonic-gate #include <stdlib.h>
320Sstevel@tonic-gate #include <sys/types.h>
330Sstevel@tonic-gate #include <nss_dbdefs.h>
340Sstevel@tonic-gate #include <string.h>
350Sstevel@tonic-gate #include <strings.h>
360Sstevel@tonic-gate #include <sys/systeminfo.h>
370Sstevel@tonic-gate #include <thread.h>
380Sstevel@tonic-gate #include <synch.h>
390Sstevel@tonic-gate #include <nsswitch.h>
400Sstevel@tonic-gate #include <prof_attr.h>
410Sstevel@tonic-gate #include <exec_attr.h>
420Sstevel@tonic-gate 
430Sstevel@tonic-gate /* externs from libc */
440Sstevel@tonic-gate extern void _nss_db_state_destr(struct nss_db_state *);
450Sstevel@tonic-gate 
460Sstevel@tonic-gate /* externs from parse.c */
470Sstevel@tonic-gate extern char *_strtok_escape(char *, char *, char **);
480Sstevel@tonic-gate extern char *_strdup_null(char *);
490Sstevel@tonic-gate /* extern from getprofattr.c */
500Sstevel@tonic-gate extern int str2profattr(const char *, int, void *, char *, int);
510Sstevel@tonic-gate 
520Sstevel@tonic-gate char *_exec_wild_id(char *, const char *);
530Sstevel@tonic-gate execstr_t *_dup_execstr(execstr_t *);
540Sstevel@tonic-gate void _free_execstr(execstr_t *);
550Sstevel@tonic-gate 
560Sstevel@tonic-gate static char *_nsw_search_path = NULL;
570Sstevel@tonic-gate 
580Sstevel@tonic-gate /*
590Sstevel@tonic-gate  * Unsynchronized, but it affects only efficiency, not correctness
600Sstevel@tonic-gate  */
610Sstevel@tonic-gate 
620Sstevel@tonic-gate static DEFINE_NSS_DB_ROOT(exec_root);
630Sstevel@tonic-gate static DEFINE_NSS_GETENT(context);
640Sstevel@tonic-gate 
650Sstevel@tonic-gate void
660Sstevel@tonic-gate _nss_initf_execattr(nss_db_params_t *p)
670Sstevel@tonic-gate {
680Sstevel@tonic-gate 	p->name = NSS_DBNAM_EXECATTR;
690Sstevel@tonic-gate 	p->config_name    = NSS_DBNAM_PROFATTR; /* use config for "prof_attr" */
700Sstevel@tonic-gate }
710Sstevel@tonic-gate 
720Sstevel@tonic-gate void
730Sstevel@tonic-gate _nsw_initf_execattr(nss_db_params_t *p)
740Sstevel@tonic-gate {
750Sstevel@tonic-gate 	p->name = NSS_DBNAM_EXECATTR;
760Sstevel@tonic-gate 	p->flags |= NSS_USE_DEFAULT_CONFIG;
770Sstevel@tonic-gate 	p->default_config = _nsw_search_path;
780Sstevel@tonic-gate }
790Sstevel@tonic-gate 
800Sstevel@tonic-gate void
810Sstevel@tonic-gate _nsw_initf_profattr(nss_db_params_t *p)
820Sstevel@tonic-gate {
830Sstevel@tonic-gate 	p->name = NSS_DBNAM_PROFATTR;
840Sstevel@tonic-gate 	p->flags |= NSS_USE_DEFAULT_CONFIG;
850Sstevel@tonic-gate 	p->default_config = _nsw_search_path;
860Sstevel@tonic-gate }
870Sstevel@tonic-gate 
880Sstevel@tonic-gate /*
890Sstevel@tonic-gate  * Return values: 0 = success, 1 = parse error, 2 = erange ... The structure
900Sstevel@tonic-gate  * pointer passed in is a structure in the caller's space wherein the field
910Sstevel@tonic-gate  * pointers would be set to areas in the buffer if need be. instring and buffer
920Sstevel@tonic-gate  * should be separate areas.
930Sstevel@tonic-gate  */
940Sstevel@tonic-gate int
950Sstevel@tonic-gate str2execattr(const char *instr, int lenstr, void *ent, char *buffer, int buflen)
960Sstevel@tonic-gate {
97132Srobinson 	char		*last = NULL;
980Sstevel@tonic-gate 	char		*sep = KV_TOKEN_DELIMIT;
990Sstevel@tonic-gate 	execstr_t	*exec = (execstr_t *)ent;
1000Sstevel@tonic-gate 
101132Srobinson 	if (lenstr >= buflen)
1020Sstevel@tonic-gate 		return (NSS_STR_PARSE_ERANGE);
103*2830Sdjl 
104*2830Sdjl 	if (instr != buffer)
105*2830Sdjl 		(void) strncpy(buffer, instr, buflen);
106*2830Sdjl 
1070Sstevel@tonic-gate 	/*
1080Sstevel@tonic-gate 	 * Remove newline that nis (yp_match) puts at the
1090Sstevel@tonic-gate 	 * end of the entry it retrieves from the map.
1100Sstevel@tonic-gate 	 */
1110Sstevel@tonic-gate 	if (buffer[lenstr] == '\n') {
1120Sstevel@tonic-gate 		buffer[lenstr] = '\0';
1130Sstevel@tonic-gate 	}
1140Sstevel@tonic-gate 
115*2830Sdjl 	/* quick exit do not entry fill if not needed */
116*2830Sdjl 	if (ent == (void *)NULL)
117*2830Sdjl 		return (NSS_STR_PARSE_SUCCESS);
118*2830Sdjl 
1190Sstevel@tonic-gate 	exec->name = _strtok_escape(buffer, sep, &last);
1200Sstevel@tonic-gate 	exec->policy = _strtok_escape(NULL, sep, &last);
1210Sstevel@tonic-gate 	exec->type = _strtok_escape(NULL, sep, &last);
1220Sstevel@tonic-gate 	exec->res1 = _strtok_escape(NULL, sep, &last);
1230Sstevel@tonic-gate 	exec->res2 = _strtok_escape(NULL, sep, &last);
1240Sstevel@tonic-gate 	exec->id = _strtok_escape(NULL, sep, &last);
1250Sstevel@tonic-gate 	exec->attr = _strtok_escape(NULL, sep, &last);
126132Srobinson 	exec->next = NULL;
1270Sstevel@tonic-gate 
1280Sstevel@tonic-gate 	return (NSS_STR_PARSE_SUCCESS);
1290Sstevel@tonic-gate }
1300Sstevel@tonic-gate 
1310Sstevel@tonic-gate 
1320Sstevel@tonic-gate void
1330Sstevel@tonic-gate _setexecattr(void)
1340Sstevel@tonic-gate {
1350Sstevel@tonic-gate 	nss_setent(&exec_root, _nss_initf_execattr, &context);
1360Sstevel@tonic-gate }
1370Sstevel@tonic-gate 
1380Sstevel@tonic-gate 
1390Sstevel@tonic-gate void
1400Sstevel@tonic-gate _endexecattr(void)
1410Sstevel@tonic-gate {
1420Sstevel@tonic-gate 	nss_endent(&exec_root, _nss_initf_execattr, &context);
1430Sstevel@tonic-gate 	nss_delete(&exec_root);
1440Sstevel@tonic-gate }
1450Sstevel@tonic-gate 
1460Sstevel@tonic-gate 
1470Sstevel@tonic-gate execstr_t *
1480Sstevel@tonic-gate _getexecattr(execstr_t *result, char *buffer, int buflen, int *errnop)
1490Sstevel@tonic-gate {
1500Sstevel@tonic-gate 	nss_status_t    res;
1510Sstevel@tonic-gate 	nss_XbyY_args_t arg;
1520Sstevel@tonic-gate 
1530Sstevel@tonic-gate 	NSS_XbyY_INIT(&arg, result, buffer, buflen, str2execattr);
1540Sstevel@tonic-gate 	res = nss_getent(&exec_root, _nss_initf_execattr, &context, &arg);
1550Sstevel@tonic-gate 	arg.status = res;
1560Sstevel@tonic-gate 	*errnop = arg.h_errno;
1570Sstevel@tonic-gate 
1580Sstevel@tonic-gate 	return ((execstr_t *)NSS_XbyY_FINI(&arg));
1590Sstevel@tonic-gate }
1600Sstevel@tonic-gate 
1610Sstevel@tonic-gate execstr_t *
1620Sstevel@tonic-gate _getexecprof(char *name,
1630Sstevel@tonic-gate     char *type,
1640Sstevel@tonic-gate     char *id,
1650Sstevel@tonic-gate     int search_flag,
1660Sstevel@tonic-gate     execstr_t *result,
1670Sstevel@tonic-gate     char *buffer,
1680Sstevel@tonic-gate     int buflen,
1690Sstevel@tonic-gate     int *errnop)
1700Sstevel@tonic-gate {
1710Sstevel@tonic-gate 	int		getby_flag;
1720Sstevel@tonic-gate 	char		policy_buf[BUFSIZ];
173132Srobinson 	const char	*empty = NULL;
1740Sstevel@tonic-gate 	nss_status_t	res = NSS_NOTFOUND;
1750Sstevel@tonic-gate 	nss_XbyY_args_t	arg;
1760Sstevel@tonic-gate 	_priv_execattr	_priv_exec;
1770Sstevel@tonic-gate 	static mutex_t	_nsw_exec_lock = DEFAULTMUTEX;
1780Sstevel@tonic-gate 
1790Sstevel@tonic-gate 	NSS_XbyY_INIT(&arg, result, buffer, buflen, str2execattr);
1800Sstevel@tonic-gate 
1810Sstevel@tonic-gate 	_priv_exec.name = (name == NULL) ? empty : (const char *)name;
1820Sstevel@tonic-gate 	_priv_exec.type = (type == NULL) ? empty : (const char *)type;
1830Sstevel@tonic-gate 	_priv_exec.id = (id == NULL) ? empty : (const char *)id;
1840Sstevel@tonic-gate #ifdef SI_SECPOLICY
1850Sstevel@tonic-gate 	if (sysinfo(SI_SECPOLICY, policy_buf, BUFSIZ) == -1)
1860Sstevel@tonic-gate #endif	/* SI_SECPOLICY */
187132Srobinson 	(void) strncpy(policy_buf, DEFAULT_POLICY, BUFSIZ);
1880Sstevel@tonic-gate 
1890Sstevel@tonic-gate retry_policy:
1900Sstevel@tonic-gate 	_priv_exec.policy = policy_buf;
1910Sstevel@tonic-gate 	_priv_exec.search_flag = search_flag;
192132Srobinson 	_priv_exec.head_exec = NULL;
193132Srobinson 	_priv_exec.prev_exec = NULL;
1940Sstevel@tonic-gate 
1950Sstevel@tonic-gate 	if ((name != NULL) && (id != NULL)) {
1960Sstevel@tonic-gate 		getby_flag = NSS_DBOP_EXECATTR_BYNAMEID;
1970Sstevel@tonic-gate 	} else if (name != NULL) {
1980Sstevel@tonic-gate 		getby_flag = NSS_DBOP_EXECATTR_BYNAME;
1990Sstevel@tonic-gate 	} else if (id != NULL) {
2000Sstevel@tonic-gate 		getby_flag = NSS_DBOP_EXECATTR_BYID;
2010Sstevel@tonic-gate 	}
2020Sstevel@tonic-gate 
2030Sstevel@tonic-gate 	arg.key.attrp = &(_priv_exec);
2040Sstevel@tonic-gate 
2050Sstevel@tonic-gate 	switch (getby_flag) {
2060Sstevel@tonic-gate 	case NSS_DBOP_EXECATTR_BYID:
2070Sstevel@tonic-gate 		res = nss_search(&exec_root, _nss_initf_execattr, getby_flag,
2080Sstevel@tonic-gate 		    &arg);
2090Sstevel@tonic-gate 		break;
2100Sstevel@tonic-gate 	case NSS_DBOP_EXECATTR_BYNAMEID:
2110Sstevel@tonic-gate 	case NSS_DBOP_EXECATTR_BYNAME:
2120Sstevel@tonic-gate 		{
2130Sstevel@tonic-gate 			char			pbuf[NSS_BUFLEN_PROFATTR];
2140Sstevel@tonic-gate 			profstr_t		prof;
2150Sstevel@tonic-gate 			nss_status_t		pres;
2160Sstevel@tonic-gate 			nss_XbyY_args_t		parg;
2170Sstevel@tonic-gate 			enum __nsw_parse_err	pserr;
2180Sstevel@tonic-gate 			struct __nsw_lookup	*lookups = NULL;
2190Sstevel@tonic-gate 			struct __nsw_switchconfig *conf = NULL;
2200Sstevel@tonic-gate 
2210Sstevel@tonic-gate 			if (conf = __nsw_getconfig(NSS_DBNAM_PROFATTR, &pserr))
2220Sstevel@tonic-gate 				if ((lookups = conf->lookups) == NULL)
2230Sstevel@tonic-gate 					goto out;
2240Sstevel@tonic-gate 			NSS_XbyY_INIT(&parg, &prof, pbuf, NSS_BUFLEN_PROFATTR,
2250Sstevel@tonic-gate 			    str2profattr);
2260Sstevel@tonic-gate 			parg.key.name = name;
2270Sstevel@tonic-gate 			do {
2280Sstevel@tonic-gate 				/*
2290Sstevel@tonic-gate 				 * search the exec_attr entry only in the scope
2300Sstevel@tonic-gate 				 * that we find the profile in.
2310Sstevel@tonic-gate 				 * if conf = NULL, search in local files only,
2320Sstevel@tonic-gate 				 * as we were not able to read nsswitch.conf.
2330Sstevel@tonic-gate 				 */
2340Sstevel@tonic-gate 				DEFINE_NSS_DB_ROOT(prof_root);
2350Sstevel@tonic-gate 				if (mutex_lock(&_nsw_exec_lock) != 0)
2360Sstevel@tonic-gate 					goto out;
2370Sstevel@tonic-gate 				_nsw_search_path = (conf == NULL)
2380Sstevel@tonic-gate 				    ? NSS_FILES_ONLY
2390Sstevel@tonic-gate 				    : lookups->service_name;
2400Sstevel@tonic-gate 				pres = nss_search(&prof_root,
2410Sstevel@tonic-gate 				    _nsw_initf_profattr,
2420Sstevel@tonic-gate 				    NSS_DBOP_PROFATTR_BYNAME, &parg);
2430Sstevel@tonic-gate 				if (pres == NSS_SUCCESS) {
2440Sstevel@tonic-gate 					DEFINE_NSS_DB_ROOT(pexec_root);
2450Sstevel@tonic-gate 					res = nss_search(&pexec_root,
2460Sstevel@tonic-gate 					    _nsw_initf_execattr, getby_flag,
2470Sstevel@tonic-gate 					    &arg);
248*2830Sdjl 					if (pexec_root.s != NULL)
249*2830Sdjl 						_nss_db_state_destr(
250*2830Sdjl 							pexec_root.s);
2510Sstevel@tonic-gate 				}
252*2830Sdjl 				if (prof_root.s != NULL)
253*2830Sdjl 					_nss_db_state_destr(prof_root.s);
2540Sstevel@tonic-gate 				(void) mutex_unlock(&_nsw_exec_lock);
2550Sstevel@tonic-gate 				if ((pres == NSS_SUCCESS) || (conf == NULL))
2560Sstevel@tonic-gate 					break;
2570Sstevel@tonic-gate 			} while (lookups && (lookups = lookups->next));
2580Sstevel@tonic-gate 		}
2590Sstevel@tonic-gate 		break;
2600Sstevel@tonic-gate 	default:
2610Sstevel@tonic-gate 		break;
2620Sstevel@tonic-gate 	}
2630Sstevel@tonic-gate 
2640Sstevel@tonic-gate out:
2650Sstevel@tonic-gate 	/*
2660Sstevel@tonic-gate 	 * If we can't find an entry for the current default policy
2670Sstevel@tonic-gate 	 * fall back to the old "suser" policy.  The nameservice is
2680Sstevel@tonic-gate 	 * shared between different OS releases.
2690Sstevel@tonic-gate 	 */
2700Sstevel@tonic-gate 	if (res == NSS_NOTFOUND && strcmp(policy_buf, DEFAULT_POLICY) == 0) {
2710Sstevel@tonic-gate 		(void) strlcpy(policy_buf, SUSER_POLICY, BUFSIZ);
2720Sstevel@tonic-gate 		goto retry_policy;
2730Sstevel@tonic-gate 	}
2740Sstevel@tonic-gate 
2750Sstevel@tonic-gate 	arg.status = res;
2760Sstevel@tonic-gate 	*errnop = res;
2770Sstevel@tonic-gate 	return ((execstr_t *)NSS_XbyY_FINI(&arg));
2780Sstevel@tonic-gate }
2790Sstevel@tonic-gate 
2800Sstevel@tonic-gate 
2810Sstevel@tonic-gate int
2820Sstevel@tonic-gate _doexeclist(nss_XbyY_args_t *argp)
2830Sstevel@tonic-gate {
2840Sstevel@tonic-gate 	int		status = 1;
2850Sstevel@tonic-gate 	_priv_execattr	*_priv_exec = (_priv_execattr *)(argp->key.attrp);
2860Sstevel@tonic-gate 	execstr_t	*exec = (execstr_t *)((argp->buf.result));
2870Sstevel@tonic-gate 
2880Sstevel@tonic-gate 	if (_priv_exec->head_exec == NULL) {
2890Sstevel@tonic-gate 		if (_priv_exec->head_exec = _dup_execstr(exec))
2900Sstevel@tonic-gate 			_priv_exec->prev_exec = _priv_exec->head_exec;
2910Sstevel@tonic-gate 		else
2920Sstevel@tonic-gate 			status = 0;
2930Sstevel@tonic-gate 	} else {
2940Sstevel@tonic-gate 		if (_priv_exec->prev_exec->next = _dup_execstr(exec))
2950Sstevel@tonic-gate 			_priv_exec->prev_exec = _priv_exec->prev_exec->next;
2960Sstevel@tonic-gate 		else
2970Sstevel@tonic-gate 			status = 0;
2980Sstevel@tonic-gate 	}
299132Srobinson 	(void) memset(argp->buf.buffer, NULL, argp->buf.buflen);
3000Sstevel@tonic-gate 
3010Sstevel@tonic-gate 	return (status);
3020Sstevel@tonic-gate 
3030Sstevel@tonic-gate }
3040Sstevel@tonic-gate 
3050Sstevel@tonic-gate 
3060Sstevel@tonic-gate /*
3070Sstevel@tonic-gate  * Converts id to a wildcard string. e.g.:
3080Sstevel@tonic-gate  *   For type = KV_COMMAND: /usr/ccs/bin/what ---> /usr/ccs/bin/\* ---> \*
3090Sstevel@tonic-gate  *   For type = KV_ACTION: Dtfile;*;*;*;0 ---> *;*;*;*;*
3100Sstevel@tonic-gate  *
3110Sstevel@tonic-gate  * Returns NULL if id is already a wild-card.
3120Sstevel@tonic-gate  */
3130Sstevel@tonic-gate char *
3140Sstevel@tonic-gate _exec_wild_id(char *id, const char *type)
3150Sstevel@tonic-gate {
3160Sstevel@tonic-gate 	char	c_id = '/';
3170Sstevel@tonic-gate 	char	*pchar = NULL;
3180Sstevel@tonic-gate 
3190Sstevel@tonic-gate 	if ((id == NULL) || (type == NULL))
3200Sstevel@tonic-gate 		return (NULL);
3210Sstevel@tonic-gate 
3220Sstevel@tonic-gate 	if (strcmp(type, KV_ACTION) == 0) {
3230Sstevel@tonic-gate 		return ((strcmp(id, KV_ACTION_WILDCARD) == 0) ? NULL :
3240Sstevel@tonic-gate 		    KV_ACTION_WILDCARD);
3250Sstevel@tonic-gate 	} else if (strcmp(type, KV_COMMAND) == 0) {
3260Sstevel@tonic-gate 		if ((pchar = rindex(id, c_id)) == NULL)
3270Sstevel@tonic-gate 			/*
3280Sstevel@tonic-gate 			 * id = \*
3290Sstevel@tonic-gate 			 */
3300Sstevel@tonic-gate 			return (NULL);
3310Sstevel@tonic-gate 		else if (*(++pchar) == KV_WILDCHAR)
3320Sstevel@tonic-gate 			/*
3330Sstevel@tonic-gate 			 * id = /usr/ccs/bin/\*
3340Sstevel@tonic-gate 			 */
3350Sstevel@tonic-gate 			return (pchar);
3360Sstevel@tonic-gate 		/*
3370Sstevel@tonic-gate 		 * id = /usr/ccs/bin/what
3380Sstevel@tonic-gate 		 */
339132Srobinson 		(void) strcpy(pchar, KV_WILDCARD);
3400Sstevel@tonic-gate 		return (id);
3410Sstevel@tonic-gate 	}
3420Sstevel@tonic-gate 
3430Sstevel@tonic-gate 	return (NULL);
3440Sstevel@tonic-gate 
3450Sstevel@tonic-gate }
3460Sstevel@tonic-gate 
3470Sstevel@tonic-gate 
3480Sstevel@tonic-gate execstr_t *
3490Sstevel@tonic-gate _dup_execstr(execstr_t *old_exec)
3500Sstevel@tonic-gate {
351132Srobinson 	execstr_t *new_exec = NULL;
3520Sstevel@tonic-gate 
353132Srobinson 	if (old_exec == NULL)
354132Srobinson 		return (NULL);
355132Srobinson 	if ((new_exec = malloc(sizeof (execstr_t))) != NULL) {
3560Sstevel@tonic-gate 		new_exec->name = _strdup_null(old_exec->name);
3570Sstevel@tonic-gate 		new_exec->type = _strdup_null(old_exec->type);
3580Sstevel@tonic-gate 		new_exec->policy = _strdup_null(old_exec->policy);
3590Sstevel@tonic-gate 		new_exec->res1 = _strdup_null(old_exec->res1);
3600Sstevel@tonic-gate 		new_exec->res2 = _strdup_null(old_exec->res2);
3610Sstevel@tonic-gate 		new_exec->id = _strdup_null(old_exec->id);
3620Sstevel@tonic-gate 		new_exec->attr = _strdup_null(old_exec->attr);
3630Sstevel@tonic-gate 		new_exec->next = old_exec->next;
3640Sstevel@tonic-gate 	}
3650Sstevel@tonic-gate 	return (new_exec);
3660Sstevel@tonic-gate }
3670Sstevel@tonic-gate 
3680Sstevel@tonic-gate void
3690Sstevel@tonic-gate _free_execstr(execstr_t *exec)
3700Sstevel@tonic-gate {
3710Sstevel@tonic-gate 	if (exec != NULL) {
3720Sstevel@tonic-gate 		free(exec->name);
3730Sstevel@tonic-gate 		free(exec->type);
3740Sstevel@tonic-gate 		free(exec->policy);
3750Sstevel@tonic-gate 		free(exec->res1);
3760Sstevel@tonic-gate 		free(exec->res2);
3770Sstevel@tonic-gate 		free(exec->id);
3780Sstevel@tonic-gate 		free(exec->attr);
3790Sstevel@tonic-gate 		_free_execstr(exec->next);
3800Sstevel@tonic-gate 		free(exec);
3810Sstevel@tonic-gate 	}
3820Sstevel@tonic-gate }
3830Sstevel@tonic-gate 
3840Sstevel@tonic-gate void
3850Sstevel@tonic-gate _exec_cleanup(nss_status_t res, nss_XbyY_args_t *argp)
3860Sstevel@tonic-gate {
3870Sstevel@tonic-gate 	_priv_execattr	*_priv_exec = (_priv_execattr *)(argp->key.attrp);
3880Sstevel@tonic-gate 
3890Sstevel@tonic-gate 	if (res == NSS_SUCCESS) {
3900Sstevel@tonic-gate 		if (_priv_exec->head_exec != NULL) {
3910Sstevel@tonic-gate 			argp->buf.result = _priv_exec->head_exec;
3920Sstevel@tonic-gate 			argp->returnval = argp->buf.result;
3930Sstevel@tonic-gate 		}
3940Sstevel@tonic-gate 	} else {
3950Sstevel@tonic-gate 		if (_priv_exec->head_exec != NULL)
3960Sstevel@tonic-gate 			_free_execstr(_priv_exec->head_exec);
3970Sstevel@tonic-gate 		argp->returnval = NULL;
3980Sstevel@tonic-gate 	}
3990Sstevel@tonic-gate }
400