xref: /titanic_44/usr/src/lib/libsecdb/common/getexecattr.c (revision 01ef659d9b1ead333ef0adc346e7051f7eae7520)
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
5cb5caa98Sdjl  * Common Development and Distribution License (the "License").
6cb5caa98Sdjl  * 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*01ef659dSJoep Vesseur  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
237c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
247c478bd9Sstevel@tonic-gate  */
257c478bd9Sstevel@tonic-gate 
267c478bd9Sstevel@tonic-gate #include <sys/types.h>
277c478bd9Sstevel@tonic-gate #include <stdio.h>
287c478bd9Sstevel@tonic-gate #include <string.h>
297c478bd9Sstevel@tonic-gate #include <stdlib.h>
307c478bd9Sstevel@tonic-gate #include <nss_dbdefs.h>
317c478bd9Sstevel@tonic-gate #include <deflt.h>
327c478bd9Sstevel@tonic-gate #include <exec_attr.h>
337c478bd9Sstevel@tonic-gate #include <user_attr.h>
347c478bd9Sstevel@tonic-gate #include <auth_attr.h>
357c478bd9Sstevel@tonic-gate #include <prof_attr.h>
367c478bd9Sstevel@tonic-gate #include <getxby_door.h>
377c478bd9Sstevel@tonic-gate #include <sys/mman.h>
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate /* Externs from libnsl */
417c478bd9Sstevel@tonic-gate extern execstr_t *_getexecattr(execstr_t *, char *, int, int *);
427c478bd9Sstevel@tonic-gate extern void _setexecattr(void);
437c478bd9Sstevel@tonic-gate extern void _endexecattr(void);
447c478bd9Sstevel@tonic-gate extern execstr_t *_getexecprof(const char *, const char *, const char *, int,
457c478bd9Sstevel@tonic-gate     execstr_t *, char *, int, int *);
467c478bd9Sstevel@tonic-gate extern userstr_t *_getusernam(const char *, userstr_t *, char *, int, int *);
477c478bd9Sstevel@tonic-gate extern userstr_t *_getuserattr(userstr_t *, char *, int, int *);
487c478bd9Sstevel@tonic-gate extern char *_strtok_escape(char *, char *, char **);
497c478bd9Sstevel@tonic-gate extern char *_strdup_null(char *);
507c478bd9Sstevel@tonic-gate 
517c478bd9Sstevel@tonic-gate static execattr_t *userprof(const char *, const char *, const char *, int);
527c478bd9Sstevel@tonic-gate static execattr_t *get_tail(execattr_t *);
537c478bd9Sstevel@tonic-gate static execattr_t *execstr2attr(execstr_t *);
547c478bd9Sstevel@tonic-gate 
557c478bd9Sstevel@tonic-gate execattr_t *
567c478bd9Sstevel@tonic-gate getexecattr()
577c478bd9Sstevel@tonic-gate {
587c478bd9Sstevel@tonic-gate 	int		err = 0;
597c478bd9Sstevel@tonic-gate 	char		buf[NSS_BUFLEN_EXECATTR];
607c478bd9Sstevel@tonic-gate 	execstr_t	exec;
617c478bd9Sstevel@tonic-gate 	execstr_t	*tmp;
627c478bd9Sstevel@tonic-gate 
637c478bd9Sstevel@tonic-gate 	tmp = _getexecattr(&exec, buf, NSS_BUFLEN_EXECATTR, &err);
647c478bd9Sstevel@tonic-gate 
657c478bd9Sstevel@tonic-gate 	return (execstr2attr(tmp));
667c478bd9Sstevel@tonic-gate }
677c478bd9Sstevel@tonic-gate 
687c478bd9Sstevel@tonic-gate 
697c478bd9Sstevel@tonic-gate execattr_t *
707c478bd9Sstevel@tonic-gate getexecprof(const char *name, const char *type, const char *id, int search_flag)
717c478bd9Sstevel@tonic-gate {
727c478bd9Sstevel@tonic-gate 	int		err = 0;
737c478bd9Sstevel@tonic-gate 	char		unique[NSS_BUFLEN_EXECATTR];
747c478bd9Sstevel@tonic-gate 	char		buf[NSS_BUFLEN_EXECATTR];
75499fd601Sgww 	execattr_t	*head = NULL;
76499fd601Sgww 	execattr_t	*prev = NULL;
777c478bd9Sstevel@tonic-gate 	execstr_t	exec;
787c478bd9Sstevel@tonic-gate 	execstr_t	*tmp;
797c478bd9Sstevel@tonic-gate 
807c478bd9Sstevel@tonic-gate 	(void) memset(unique, 0, NSS_BUFLEN_EXECATTR);
817c478bd9Sstevel@tonic-gate 	(void) memset(&exec, 0, sizeof (execstr_t));
827c478bd9Sstevel@tonic-gate 
83*01ef659dSJoep Vesseur 	if (!IS_GET_ONE(search_flag) && !IS_GET_ALL(search_flag)) {
84499fd601Sgww 		return (NULL);
857c478bd9Sstevel@tonic-gate 	}
867c478bd9Sstevel@tonic-gate 
877c478bd9Sstevel@tonic-gate 	if ((name == NULL) && (type == NULL) && (id == NULL)) {
887c478bd9Sstevel@tonic-gate 		setexecattr();
89*01ef659dSJoep Vesseur 		if (IS_GET_ONE(search_flag)) {
907c478bd9Sstevel@tonic-gate 			head = getexecattr();
91*01ef659dSJoep Vesseur 		} else if (IS_GET_ALL(search_flag)) {
927c478bd9Sstevel@tonic-gate 			head = getexecattr();
937c478bd9Sstevel@tonic-gate 			prev = head;
947c478bd9Sstevel@tonic-gate 			while (prev != NULL) {
957c478bd9Sstevel@tonic-gate 				prev->next = getexecattr();
967c478bd9Sstevel@tonic-gate 				prev = prev->next;
977c478bd9Sstevel@tonic-gate 			};
98*01ef659dSJoep Vesseur 		} else {
99499fd601Sgww 			head = NULL;
1007c478bd9Sstevel@tonic-gate 		}
1017c478bd9Sstevel@tonic-gate 		endexecattr();
1027c478bd9Sstevel@tonic-gate 		return (head);
1037c478bd9Sstevel@tonic-gate 	}
1047c478bd9Sstevel@tonic-gate 
1057c478bd9Sstevel@tonic-gate 	tmp = _getexecprof(name,
1067c478bd9Sstevel@tonic-gate 	    type,
1077c478bd9Sstevel@tonic-gate 	    id,
1087c478bd9Sstevel@tonic-gate 	    search_flag,
1097c478bd9Sstevel@tonic-gate 	    &exec,
1107c478bd9Sstevel@tonic-gate 	    buf,
1117c478bd9Sstevel@tonic-gate 	    NSS_BUFLEN_EXECATTR,
1127c478bd9Sstevel@tonic-gate 	    &err);
1137c478bd9Sstevel@tonic-gate 
1147c478bd9Sstevel@tonic-gate 	return (execstr2attr(tmp));
1157c478bd9Sstevel@tonic-gate }
1167c478bd9Sstevel@tonic-gate 
1177c478bd9Sstevel@tonic-gate execattr_t *
1187c478bd9Sstevel@tonic-gate getexecuser(const char *username, const char *type, const char *id,
1197c478bd9Sstevel@tonic-gate     int search_flag)
1207c478bd9Sstevel@tonic-gate {
1217c478bd9Sstevel@tonic-gate 	int		err = 0;
1227c478bd9Sstevel@tonic-gate 	char		buf[NSS_BUFLEN_USERATTR];
1237c478bd9Sstevel@tonic-gate 	userstr_t	user;
1247c478bd9Sstevel@tonic-gate 	userstr_t	*utmp;
125499fd601Sgww 	execattr_t	*head = NULL;
126499fd601Sgww 	execattr_t	*prev =  NULL;
127499fd601Sgww 	execattr_t	*new = NULL;
1287c478bd9Sstevel@tonic-gate 
129*01ef659dSJoep Vesseur 	if (!IS_GET_ONE(search_flag) && !IS_GET_ALL(search_flag)) {
130499fd601Sgww 		return (NULL);
1317c478bd9Sstevel@tonic-gate 	}
1327c478bd9Sstevel@tonic-gate 
1337c478bd9Sstevel@tonic-gate 	if (username == NULL) {
1347c478bd9Sstevel@tonic-gate 		setuserattr();
1357c478bd9Sstevel@tonic-gate 		/* avoid userstr2attr mallocs by calling libnsl directly */
1367c478bd9Sstevel@tonic-gate 		utmp = _getuserattr(&user, buf, NSS_BUFLEN_USERATTR, &err);
1377c478bd9Sstevel@tonic-gate 		if (utmp == NULL) {
1387c478bd9Sstevel@tonic-gate 			return (head);
1397c478bd9Sstevel@tonic-gate 		}
140*01ef659dSJoep Vesseur 		if (IS_GET_ONE(search_flag)) {
1417c478bd9Sstevel@tonic-gate 			head = userprof((const char *)(utmp->name), type, id,
1427c478bd9Sstevel@tonic-gate 			    search_flag);
143*01ef659dSJoep Vesseur 		} else if (IS_GET_ALL(search_flag)) {
1447c478bd9Sstevel@tonic-gate 			head = userprof((const char *)(utmp->name), type, id,
1457c478bd9Sstevel@tonic-gate 			    search_flag);
1467c478bd9Sstevel@tonic-gate 			if (head != NULL) {
1477c478bd9Sstevel@tonic-gate 				prev = get_tail(head);
1487c478bd9Sstevel@tonic-gate 			}
1497c478bd9Sstevel@tonic-gate 			while ((utmp = _getuserattr(&user,
1507c478bd9Sstevel@tonic-gate 			    buf, NSS_BUFLEN_USERATTR, &err)) != NULL) {
1517c478bd9Sstevel@tonic-gate 				if ((new =
1527c478bd9Sstevel@tonic-gate 				    userprof((const char *)(utmp->name),
1537c478bd9Sstevel@tonic-gate 				    type, id, search_flag)) != NULL) {
1547c478bd9Sstevel@tonic-gate 					if (prev != NULL) {
1557c478bd9Sstevel@tonic-gate 						prev->next = new;
1567c478bd9Sstevel@tonic-gate 						prev = get_tail(prev->next);
1577c478bd9Sstevel@tonic-gate 					} else {
1587c478bd9Sstevel@tonic-gate 						head = new;
1597c478bd9Sstevel@tonic-gate 						prev = get_tail(head);
1607c478bd9Sstevel@tonic-gate 					}
1617c478bd9Sstevel@tonic-gate 				}
1627c478bd9Sstevel@tonic-gate 			}
163*01ef659dSJoep Vesseur 		} else {
164499fd601Sgww 			head = NULL;
1657c478bd9Sstevel@tonic-gate 		}
1667c478bd9Sstevel@tonic-gate 		enduserattr();
1677c478bd9Sstevel@tonic-gate 	} else {
1687c478bd9Sstevel@tonic-gate 		head = userprof(username, type, id, search_flag);
1697c478bd9Sstevel@tonic-gate 	}
1707c478bd9Sstevel@tonic-gate 
1717c478bd9Sstevel@tonic-gate 	return (head);
1727c478bd9Sstevel@tonic-gate }
1737c478bd9Sstevel@tonic-gate 
1747c478bd9Sstevel@tonic-gate 
1757c478bd9Sstevel@tonic-gate execattr_t *
1767c478bd9Sstevel@tonic-gate match_execattr(execattr_t *exec, const char *profname, const char *type,
1777c478bd9Sstevel@tonic-gate     const char *id)
1787c478bd9Sstevel@tonic-gate {
179499fd601Sgww 	execattr_t	*execp = NULL;
1807c478bd9Sstevel@tonic-gate 
1817c478bd9Sstevel@tonic-gate 	for (execp = exec; execp != NULL; execp = execp->next) {
1827c478bd9Sstevel@tonic-gate 		if ((profname && execp->name &&
1837c478bd9Sstevel@tonic-gate 		    (strcmp(profname, execp->name) != 0)) ||
1847c478bd9Sstevel@tonic-gate 		    (type && execp->type && (strcmp(type, execp->type) != 0)) ||
1857c478bd9Sstevel@tonic-gate 		    (id && execp->id && (strcmp(id, execp->id) != 0)))
1867c478bd9Sstevel@tonic-gate 			continue;
1877c478bd9Sstevel@tonic-gate 	}
1887c478bd9Sstevel@tonic-gate 
1897c478bd9Sstevel@tonic-gate 	return (execp);
1907c478bd9Sstevel@tonic-gate }
1917c478bd9Sstevel@tonic-gate 
1927c478bd9Sstevel@tonic-gate 
1937c478bd9Sstevel@tonic-gate void
1947c478bd9Sstevel@tonic-gate setexecattr()
1957c478bd9Sstevel@tonic-gate {
1967c478bd9Sstevel@tonic-gate 	_setexecattr();
1977c478bd9Sstevel@tonic-gate }
1987c478bd9Sstevel@tonic-gate 
1997c478bd9Sstevel@tonic-gate 
2007c478bd9Sstevel@tonic-gate void
2017c478bd9Sstevel@tonic-gate endexecattr()
2027c478bd9Sstevel@tonic-gate {
2037c478bd9Sstevel@tonic-gate 	_endexecattr();
2047c478bd9Sstevel@tonic-gate }
2057c478bd9Sstevel@tonic-gate 
2067c478bd9Sstevel@tonic-gate 
2077c478bd9Sstevel@tonic-gate void
2087c478bd9Sstevel@tonic-gate free_execattr(execattr_t *exec)
2097c478bd9Sstevel@tonic-gate {
210499fd601Sgww 	if (exec != NULL) {
2117c478bd9Sstevel@tonic-gate 		free(exec->name);
2127c478bd9Sstevel@tonic-gate 		free(exec->type);
2137c478bd9Sstevel@tonic-gate 		free(exec->policy);
2147c478bd9Sstevel@tonic-gate 		free(exec->res1);
2157c478bd9Sstevel@tonic-gate 		free(exec->res2);
2167c478bd9Sstevel@tonic-gate 		free(exec->id);
2177c478bd9Sstevel@tonic-gate 		_kva_free(exec->attr);
2187c478bd9Sstevel@tonic-gate 		free_execattr(exec->next);
2197c478bd9Sstevel@tonic-gate 		free(exec);
2207c478bd9Sstevel@tonic-gate 	}
2217c478bd9Sstevel@tonic-gate }
2227c478bd9Sstevel@tonic-gate 
2237c478bd9Sstevel@tonic-gate 
2247c478bd9Sstevel@tonic-gate static execattr_t *
2257c478bd9Sstevel@tonic-gate userprof(const char *username, const char *type, const char *id,
2267c478bd9Sstevel@tonic-gate     int search_flag)
2277c478bd9Sstevel@tonic-gate {
2287c478bd9Sstevel@tonic-gate 
2297c478bd9Sstevel@tonic-gate 	int		err = 0;
2307c478bd9Sstevel@tonic-gate 	char		*last;
2317c478bd9Sstevel@tonic-gate 	char		*sep = ",";
232499fd601Sgww 	char		*proflist = NULL;
233499fd601Sgww 	char		*profname = NULL;
2347c478bd9Sstevel@tonic-gate 	char		buf[NSS_BUFLEN_USERATTR];
2357c478bd9Sstevel@tonic-gate 	char		pwdb[NSS_BUFLEN_PASSWD];
2367c478bd9Sstevel@tonic-gate 	kva_t		*user_attr;
2377c478bd9Sstevel@tonic-gate 	userstr_t	user;
2387c478bd9Sstevel@tonic-gate 	userstr_t	*utmp;
2397c478bd9Sstevel@tonic-gate 	execattr_t	*exec;
240499fd601Sgww 	execattr_t	*head = NULL;
241499fd601Sgww 	execattr_t	*prev = NULL;
2427c478bd9Sstevel@tonic-gate 	struct passwd	pwd;
2437c478bd9Sstevel@tonic-gate 
2447c478bd9Sstevel@tonic-gate 	char		*profArray[MAXPROFS];
2457c478bd9Sstevel@tonic-gate 	int		profcnt = 0;
2467c478bd9Sstevel@tonic-gate 	int		i;
2477c478bd9Sstevel@tonic-gate 
2487c478bd9Sstevel@tonic-gate 	/*
2497c478bd9Sstevel@tonic-gate 	 * Check if specified username is valid user
2507c478bd9Sstevel@tonic-gate 	 */
2517c478bd9Sstevel@tonic-gate 	if (getpwnam_r(username, &pwd, pwdb, sizeof (pwdb)) == NULL) {
2527c478bd9Sstevel@tonic-gate 		return (head);
2537c478bd9Sstevel@tonic-gate 	}
2547c478bd9Sstevel@tonic-gate 
2557c478bd9Sstevel@tonic-gate 	utmp = _getusernam(username, &user, buf, NSS_BUFLEN_USERATTR, &err);
2567c478bd9Sstevel@tonic-gate 	if (utmp != NULL) {
2577c478bd9Sstevel@tonic-gate 		user_attr = _str2kva(user.attr, KV_ASSIGN, KV_DELIMITER);
2587c478bd9Sstevel@tonic-gate 		if ((proflist = kva_match(user_attr, "profiles")) != NULL) {
2597c478bd9Sstevel@tonic-gate 			/* Get the list of profiles for this user */
2607c478bd9Sstevel@tonic-gate 			for (profname = _strtok_escape(proflist, sep, &last);
2617c478bd9Sstevel@tonic-gate 			    profname != NULL;
2627c478bd9Sstevel@tonic-gate 			    profname = _strtok_escape(NULL, sep, &last)) {
2637c478bd9Sstevel@tonic-gate 				getproflist(profname, profArray, &profcnt);
2647c478bd9Sstevel@tonic-gate 			}
2657c478bd9Sstevel@tonic-gate 		}
2667c478bd9Sstevel@tonic-gate 	}
2677c478bd9Sstevel@tonic-gate 
2687c478bd9Sstevel@tonic-gate 	/* Get the list of default profiles */
269499fd601Sgww 	proflist = NULL;
270499fd601Sgww 	(void) _get_user_defs(username, NULL, &proflist);
2717c478bd9Sstevel@tonic-gate 	if (proflist != NULL) {
2727c478bd9Sstevel@tonic-gate 		for (profname = _strtok_escape(proflist, sep, &last);
2737c478bd9Sstevel@tonic-gate 		    profname != NULL;
2747c478bd9Sstevel@tonic-gate 		    profname = _strtok_escape(NULL, sep, &last)) {
2757c478bd9Sstevel@tonic-gate 			getproflist(profname, profArray, &profcnt);
2767c478bd9Sstevel@tonic-gate 		}
277499fd601Sgww 		_free_user_defs(NULL, proflist);
2787c478bd9Sstevel@tonic-gate 	}
2797c478bd9Sstevel@tonic-gate 
2807c478bd9Sstevel@tonic-gate 	if (profcnt == 0) {
2817c478bd9Sstevel@tonic-gate 		return (head);
2827c478bd9Sstevel@tonic-gate 	}
2837c478bd9Sstevel@tonic-gate 
2847c478bd9Sstevel@tonic-gate 	/* Get execs from the list of profiles */
2857c478bd9Sstevel@tonic-gate 	for (i = 0; i < profcnt; i++) {
2867c478bd9Sstevel@tonic-gate 		profname = profArray[i];
2877c478bd9Sstevel@tonic-gate 		if ((exec = getexecprof(profname, type, id, search_flag)) !=
2887c478bd9Sstevel@tonic-gate 		    NULL) {
289*01ef659dSJoep Vesseur 			if (IS_GET_ONE(search_flag)) {
2907c478bd9Sstevel@tonic-gate 				head = exec;
2917c478bd9Sstevel@tonic-gate 				break;
292*01ef659dSJoep Vesseur 			} else if (IS_GET_ALL(search_flag)) {
2937c478bd9Sstevel@tonic-gate 				if (head == NULL) {
2947c478bd9Sstevel@tonic-gate 					head = exec;
2957c478bd9Sstevel@tonic-gate 					prev = get_tail(head);
2967c478bd9Sstevel@tonic-gate 				} else {
2977c478bd9Sstevel@tonic-gate 					prev->next = exec;
2987c478bd9Sstevel@tonic-gate 					prev = get_tail(exec);
2997c478bd9Sstevel@tonic-gate 				}
3007c478bd9Sstevel@tonic-gate 			}
3017c478bd9Sstevel@tonic-gate 		}
3027c478bd9Sstevel@tonic-gate 	}
3037c478bd9Sstevel@tonic-gate 	free_proflist(profArray, profcnt);
3047c478bd9Sstevel@tonic-gate 	return (head);
3057c478bd9Sstevel@tonic-gate }
3067c478bd9Sstevel@tonic-gate 
3077c478bd9Sstevel@tonic-gate 
3087c478bd9Sstevel@tonic-gate static execattr_t *
3097c478bd9Sstevel@tonic-gate get_tail(execattr_t *exec)
3107c478bd9Sstevel@tonic-gate {
311499fd601Sgww 	execattr_t *i_exec = NULL;
312499fd601Sgww 	execattr_t *j_exec = NULL;
3137c478bd9Sstevel@tonic-gate 
3147c478bd9Sstevel@tonic-gate 	if (exec != NULL) {
3157c478bd9Sstevel@tonic-gate 		if (exec->next == NULL) {
3167c478bd9Sstevel@tonic-gate 			j_exec = exec;
3177c478bd9Sstevel@tonic-gate 		} else {
3187c478bd9Sstevel@tonic-gate 			for (i_exec = exec->next; i_exec != NULL;
3197c478bd9Sstevel@tonic-gate 			    i_exec = i_exec->next) {
3207c478bd9Sstevel@tonic-gate 				j_exec = i_exec;
3217c478bd9Sstevel@tonic-gate 			}
3227c478bd9Sstevel@tonic-gate 		}
3237c478bd9Sstevel@tonic-gate 	}
3247c478bd9Sstevel@tonic-gate 
3257c478bd9Sstevel@tonic-gate 	return (j_exec);
3267c478bd9Sstevel@tonic-gate }
3277c478bd9Sstevel@tonic-gate 
3287c478bd9Sstevel@tonic-gate 
3297c478bd9Sstevel@tonic-gate static execattr_t *
3307c478bd9Sstevel@tonic-gate execstr2attr(execstr_t *es)
3317c478bd9Sstevel@tonic-gate {
3327c478bd9Sstevel@tonic-gate 	execattr_t	*newexec;
3337c478bd9Sstevel@tonic-gate 
3347c478bd9Sstevel@tonic-gate 	if (es == NULL) {
335499fd601Sgww 		return (NULL);
3367c478bd9Sstevel@tonic-gate 	}
337499fd601Sgww 	if ((newexec = malloc(sizeof (execattr_t))) == NULL) {
338499fd601Sgww 		return (NULL);
3397c478bd9Sstevel@tonic-gate 	}
3407c478bd9Sstevel@tonic-gate 
3417c478bd9Sstevel@tonic-gate 	newexec->name = _do_unescape(es->name);
3427c478bd9Sstevel@tonic-gate 	newexec->policy = _do_unescape(es->policy);
3437c478bd9Sstevel@tonic-gate 	newexec->type = _do_unescape(es->type);
3447c478bd9Sstevel@tonic-gate 	newexec->res1 =  _do_unescape(es->res1);
3457c478bd9Sstevel@tonic-gate 	newexec->res2 = _do_unescape(es->res2);
3467c478bd9Sstevel@tonic-gate 	newexec->id = _do_unescape(es->id);
3477c478bd9Sstevel@tonic-gate 	newexec->attr = _str2kva(es->attr, KV_ASSIGN, KV_DELIMITER);
3487c478bd9Sstevel@tonic-gate 	if (es->next) {
3497c478bd9Sstevel@tonic-gate 		newexec->next = execstr2attr((execstr_t *)(es->next));
3507c478bd9Sstevel@tonic-gate 	} else {
351499fd601Sgww 		newexec->next = NULL;
3527c478bd9Sstevel@tonic-gate 	}
3537c478bd9Sstevel@tonic-gate 	return (newexec);
3547c478bd9Sstevel@tonic-gate }
3557c478bd9Sstevel@tonic-gate 
3567c478bd9Sstevel@tonic-gate #ifdef DEBUG
3577c478bd9Sstevel@tonic-gate void
3587c478bd9Sstevel@tonic-gate print_execattr(execattr_t *exec)
3597c478bd9Sstevel@tonic-gate {
3607c478bd9Sstevel@tonic-gate 	extern void print_kva(kva_t *);
3617c478bd9Sstevel@tonic-gate 	char *empty = "empty";
3627c478bd9Sstevel@tonic-gate 
3637c478bd9Sstevel@tonic-gate 	if (exec != NULL) {
3647c478bd9Sstevel@tonic-gate 		printf("name=%s\n", exec->name ? exec->name : empty);
3657c478bd9Sstevel@tonic-gate 		printf("policy=%s\n", exec->policy ? exec->policy : empty);
3667c478bd9Sstevel@tonic-gate 		printf("type=%s\n", exec->type ? exec->type : empty);
3677c478bd9Sstevel@tonic-gate 		printf("res1=%s\n", exec->res1 ? exec->res1 : empty);
3687c478bd9Sstevel@tonic-gate 		printf("res2=%s\n", exec->res2 ? exec->res2 : empty);
3697c478bd9Sstevel@tonic-gate 		printf("id=%s\n", exec->id ? exec->id : empty);
3707c478bd9Sstevel@tonic-gate 		printf("attr=\n");
3717c478bd9Sstevel@tonic-gate 		print_kva(exec->attr);
3727c478bd9Sstevel@tonic-gate 		fflush(stdout);
3737c478bd9Sstevel@tonic-gate 		if (exec->next) {
3747c478bd9Sstevel@tonic-gate 			print_execattr(exec->next);
3757c478bd9Sstevel@tonic-gate 		}
3767c478bd9Sstevel@tonic-gate 	} else {
3777c478bd9Sstevel@tonic-gate 		printf("NULL\n");
3787c478bd9Sstevel@tonic-gate 	}
3797c478bd9Sstevel@tonic-gate }
3807c478bd9Sstevel@tonic-gate #endif  /* DEBUG */
381