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*4754Svp157776  * Common Development and Distribution License (the "License").
6*4754Svp157776  * 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  */
210Sstevel@tonic-gate /*
22*4754Svp157776  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
230Sstevel@tonic-gate  * Use is subject to license terms.
240Sstevel@tonic-gate  */
250Sstevel@tonic-gate 
260Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
270Sstevel@tonic-gate 
280Sstevel@tonic-gate /*
290Sstevel@tonic-gate  * Routines used by inetd to read inetd's configuration from the repository,
300Sstevel@tonic-gate  * to validate it and setup inetd's data structures appropriately based on
310Sstevel@tonic-gate  * in.
320Sstevel@tonic-gate  */
330Sstevel@tonic-gate 
340Sstevel@tonic-gate #include <stdlib.h>
350Sstevel@tonic-gate #include <string.h>
360Sstevel@tonic-gate #include <errno.h>
370Sstevel@tonic-gate #include <unistd.h>
380Sstevel@tonic-gate #include <netdb.h>
390Sstevel@tonic-gate #include <netinet/in.h>
400Sstevel@tonic-gate #include <libintl.h>
410Sstevel@tonic-gate #include <nss_dbdefs.h>
420Sstevel@tonic-gate #include <signal.h>
430Sstevel@tonic-gate #include <wait.h>
440Sstevel@tonic-gate #include "inetd_impl.h"
450Sstevel@tonic-gate 
460Sstevel@tonic-gate 
470Sstevel@tonic-gate /* method timeout used if one isn't explicitly specified */
480Sstevel@tonic-gate #define	DEFAULT_METHOD_TIMEOUT	10
490Sstevel@tonic-gate 
500Sstevel@tonic-gate 
510Sstevel@tonic-gate /* supported method properties and their attributes */
520Sstevel@tonic-gate static inetd_prop_t method_props[] = {
531293Smh138676 {PR_EXEC_NAME, "", INET_TYPE_STRING, B_FALSE, IVE_UNSET, NULL, B_FALSE},
541293Smh138676 {PR_ARG0_NAME, "", INET_TYPE_STRING, B_TRUE, IVE_UNSET, NULL, B_FALSE},
551293Smh138676 {SCF_PROPERTY_TIMEOUT, "", INET_TYPE_COUNT, B_TRUE, IVE_UNSET, NULL, B_FALSE},
561293Smh138676 {NULL},
570Sstevel@tonic-gate };
580Sstevel@tonic-gate 
590Sstevel@tonic-gate /* enumeration of method properties; used to index into method_props[] */
600Sstevel@tonic-gate typedef enum {
610Sstevel@tonic-gate 	MP_EXEC,
620Sstevel@tonic-gate 	MP_ARG0,
631293Smh138676 	MP_TIMEOUT
640Sstevel@tonic-gate } method_prop_t;
650Sstevel@tonic-gate 
660Sstevel@tonic-gate 
670Sstevel@tonic-gate /* handle used for repository access in read_prop() */
680Sstevel@tonic-gate static scf_handle_t	*rep_handle = NULL;
690Sstevel@tonic-gate 
700Sstevel@tonic-gate /* pool used to create proto_info_t lists (generic proto info structure) */
710Sstevel@tonic-gate static uu_list_pool_t	*proto_info_pool = NULL;
720Sstevel@tonic-gate 
730Sstevel@tonic-gate static void destroy_method_props(inetd_prop_t *);
740Sstevel@tonic-gate static int proto_info_compare(const void *, const void *, void *);
750Sstevel@tonic-gate 
760Sstevel@tonic-gate int
770Sstevel@tonic-gate config_init(void)
780Sstevel@tonic-gate {
790Sstevel@tonic-gate 	if ((rep_handle = scf_handle_create(SCF_VERSION)) == NULL) {
800Sstevel@tonic-gate 		error_msg("%s: %s",
810Sstevel@tonic-gate 		    gettext("Failed to create repository handle"),
820Sstevel@tonic-gate 		    scf_strerror(scf_error()));
830Sstevel@tonic-gate 		return (-1);
840Sstevel@tonic-gate 	} else if (make_handle_bound(rep_handle) == -1) {
850Sstevel@tonic-gate 		/* let config_fini clean-up */
860Sstevel@tonic-gate 		return (-1);
870Sstevel@tonic-gate 	}
880Sstevel@tonic-gate 
890Sstevel@tonic-gate 	if ((proto_info_pool = uu_list_pool_create("proto_info_pool",
900Sstevel@tonic-gate 	    sizeof (proto_info_t), offsetof(proto_info_t, link),
910Sstevel@tonic-gate 	    proto_info_compare, UU_LIST_POOL_DEBUG)) == NULL) {
920Sstevel@tonic-gate 		error_msg(gettext("Failed to create uu list pool: %s"),
930Sstevel@tonic-gate 		    uu_strerror(uu_error()));
940Sstevel@tonic-gate 		return (-1);
950Sstevel@tonic-gate 	}
960Sstevel@tonic-gate 
970Sstevel@tonic-gate 	return (0);
980Sstevel@tonic-gate }
990Sstevel@tonic-gate 
1000Sstevel@tonic-gate void
1010Sstevel@tonic-gate config_fini(void)
1020Sstevel@tonic-gate {
1030Sstevel@tonic-gate 	if (rep_handle == NULL)
1040Sstevel@tonic-gate 		return;
1050Sstevel@tonic-gate 
1060Sstevel@tonic-gate 	if (proto_info_pool != NULL) {
1070Sstevel@tonic-gate 		uu_list_pool_destroy(proto_info_pool);
1080Sstevel@tonic-gate 		proto_info_pool = NULL;
1090Sstevel@tonic-gate 	}
1100Sstevel@tonic-gate 
1110Sstevel@tonic-gate 	(void) scf_handle_unbind(rep_handle);
1120Sstevel@tonic-gate 	scf_handle_destroy(rep_handle);
1130Sstevel@tonic-gate 	rep_handle = NULL;
1140Sstevel@tonic-gate }
1150Sstevel@tonic-gate 
1160Sstevel@tonic-gate static void
1170Sstevel@tonic-gate destroy_method_info(method_info_t *mi)
1180Sstevel@tonic-gate {
1190Sstevel@tonic-gate 	if (mi == NULL)
1200Sstevel@tonic-gate 		return;
1210Sstevel@tonic-gate 
1220Sstevel@tonic-gate 	if (mi->wordexp_arg0_backup != NULL) {
1230Sstevel@tonic-gate 		/*
1240Sstevel@tonic-gate 		 * Return the wordexp structure back to its original
1250Sstevel@tonic-gate 		 * state so it can be consumed by wordfree.
1260Sstevel@tonic-gate 		 */
1270Sstevel@tonic-gate 		free(mi->exec_args_we.we_wordv[0]);
1280Sstevel@tonic-gate 		mi->exec_args_we.we_wordv[0] =
1290Sstevel@tonic-gate 		    (char *)mi->wordexp_arg0_backup;
1300Sstevel@tonic-gate 	}
1310Sstevel@tonic-gate 
1320Sstevel@tonic-gate 	free(mi->exec_path);
1330Sstevel@tonic-gate 
1340Sstevel@tonic-gate 	wordfree(&mi->exec_args_we);
1350Sstevel@tonic-gate 
1360Sstevel@tonic-gate 	free(mi);
1370Sstevel@tonic-gate }
1380Sstevel@tonic-gate 
1390Sstevel@tonic-gate /*
1400Sstevel@tonic-gate  * Transforms the properties read from the repository for a method into a
1410Sstevel@tonic-gate  * method_info_t and returns a pointer to it. If expansion of the exec
1420Sstevel@tonic-gate  * property fails, due to an invalid string or memory allocation failure,
1430Sstevel@tonic-gate  * NULL is returned and exec_invalid is set appropriately to indicate whether
1440Sstevel@tonic-gate  * it was a memory allocation failure or an invalid exec string.
1450Sstevel@tonic-gate  */
1460Sstevel@tonic-gate static method_info_t *
1470Sstevel@tonic-gate create_method_info(const inetd_prop_t *mprops, boolean_t *exec_invalid)
1480Sstevel@tonic-gate {
1490Sstevel@tonic-gate 	method_info_t	*ret;
1500Sstevel@tonic-gate 	int		i;
1510Sstevel@tonic-gate 
1520Sstevel@tonic-gate 	debug_msg("Entering create_method_info");
1530Sstevel@tonic-gate 
1540Sstevel@tonic-gate 	if ((ret = calloc(1, sizeof (method_info_t))) == NULL)
1550Sstevel@tonic-gate 		goto alloc_fail;
1560Sstevel@tonic-gate 
1570Sstevel@tonic-gate 	/* Expand the exec string. */
1581293Smh138676 	if ((i = wordexp(get_prop_value_string(mprops, PR_EXEC_NAME),
1590Sstevel@tonic-gate 	    &ret->exec_args_we, WRDE_NOCMD|WRDE_UNDEF)) != 0) {
1600Sstevel@tonic-gate 		if (i == WRDE_NOSPACE)
1610Sstevel@tonic-gate 			goto alloc_fail;
1620Sstevel@tonic-gate 
1630Sstevel@tonic-gate 		*exec_invalid = B_TRUE;
1640Sstevel@tonic-gate 		free(ret);
1650Sstevel@tonic-gate 		return (NULL);
1660Sstevel@tonic-gate 	}
1670Sstevel@tonic-gate 
1680Sstevel@tonic-gate 	if ((ret->exec_path = strdup(ret->exec_args_we.we_wordv[0])) == NULL)
1690Sstevel@tonic-gate 		goto alloc_fail;
1700Sstevel@tonic-gate 
1710Sstevel@tonic-gate 	if (mprops[MP_ARG0].ip_error == IVE_VALID) {	/* arg0 is set */
1720Sstevel@tonic-gate 		/*
1730Sstevel@tonic-gate 		 * Keep a copy of arg0 of the wordexp structure so that
1740Sstevel@tonic-gate 		 * wordfree() gets passed what wordexp() originally returned,
1750Sstevel@tonic-gate 		 * as documented as required in the man page.
1760Sstevel@tonic-gate 		 */
1770Sstevel@tonic-gate 		ret->wordexp_arg0_backup = ret->exec_args_we.we_wordv[0];
1780Sstevel@tonic-gate 		if ((ret->exec_args_we.we_wordv[0] =
1791293Smh138676 		    strdup(get_prop_value_string(mprops, PR_ARG0_NAME)))
1801293Smh138676 		    == NULL)
1810Sstevel@tonic-gate 			goto alloc_fail;
1820Sstevel@tonic-gate 	}
1830Sstevel@tonic-gate 
1840Sstevel@tonic-gate 	if (mprops[MP_TIMEOUT].ip_error == IVE_VALID) {
1851293Smh138676 		ret->timeout = get_prop_value_count(mprops,
1861293Smh138676 		    SCF_PROPERTY_TIMEOUT);
1870Sstevel@tonic-gate 	} else {
1880Sstevel@tonic-gate 		ret->timeout = DEFAULT_METHOD_TIMEOUT;
1890Sstevel@tonic-gate 	}
1900Sstevel@tonic-gate 
1910Sstevel@tonic-gate 	/* exec_invalid not set on success */
1920Sstevel@tonic-gate 
1930Sstevel@tonic-gate 	return (ret);
1940Sstevel@tonic-gate 
1950Sstevel@tonic-gate alloc_fail:
1960Sstevel@tonic-gate 	error_msg(strerror(errno));
1970Sstevel@tonic-gate 	destroy_method_info(ret);
1980Sstevel@tonic-gate 	*exec_invalid = B_FALSE;
1990Sstevel@tonic-gate 	return (NULL);
2000Sstevel@tonic-gate }
2010Sstevel@tonic-gate 
2020Sstevel@tonic-gate /*
2030Sstevel@tonic-gate  * Returns B_TRUE if the contents of the 2 method_info_t structures are
2040Sstevel@tonic-gate  * equivalent, else B_FALSE.
2050Sstevel@tonic-gate  */
2060Sstevel@tonic-gate boolean_t
2070Sstevel@tonic-gate method_info_equal(const method_info_t *mi, const method_info_t *mi2)
2080Sstevel@tonic-gate {
2090Sstevel@tonic-gate 	int		i;
2100Sstevel@tonic-gate 
2110Sstevel@tonic-gate 	debug_msg("Entering method_info_equal");
2120Sstevel@tonic-gate 
2130Sstevel@tonic-gate 	if ((mi == NULL) && (mi2 == NULL)) {
2140Sstevel@tonic-gate 		return (B_TRUE);
2150Sstevel@tonic-gate 	} else if (((mi == NULL) || (mi2 == NULL)) ||
2160Sstevel@tonic-gate 	    (mi->exec_args_we.we_wordc != mi2->exec_args_we.we_wordc) ||
2170Sstevel@tonic-gate 	    (strcmp(mi->exec_path, mi2->exec_path) != 0)) {
2180Sstevel@tonic-gate 		return (B_FALSE);
2190Sstevel@tonic-gate 	}
2200Sstevel@tonic-gate 
2210Sstevel@tonic-gate 	for (i = 0; i < mi->exec_args_we.we_wordc; i++) {
2220Sstevel@tonic-gate 		if (strcmp(mi->exec_args_we.we_wordv[i],
2230Sstevel@tonic-gate 		    mi2->exec_args_we.we_wordv[i]) != 0) {
2240Sstevel@tonic-gate 			return (B_FALSE);
2250Sstevel@tonic-gate 		}
2260Sstevel@tonic-gate 	}
2270Sstevel@tonic-gate 
2280Sstevel@tonic-gate 	return (B_TRUE);
2290Sstevel@tonic-gate }
2300Sstevel@tonic-gate 
2310Sstevel@tonic-gate /*
2320Sstevel@tonic-gate  * Checks if the contents of the 2 socket_info_t structures are equivalent.
2330Sstevel@tonic-gate  * If 'isrpc' is false, the address components of the two structures are
2340Sstevel@tonic-gate  * compared for equality as part of this. If the two structures are
2350Sstevel@tonic-gate  * equivalent B_TRUE is returned, else B_FALSE.
2360Sstevel@tonic-gate  */
2370Sstevel@tonic-gate boolean_t
2380Sstevel@tonic-gate socket_info_equal(const socket_info_t *si, const socket_info_t *si2,
2390Sstevel@tonic-gate     boolean_t isrpc)
2400Sstevel@tonic-gate {
2410Sstevel@tonic-gate 	return ((isrpc || (memcmp(&si->local_addr, &si2->local_addr,
2420Sstevel@tonic-gate 	    sizeof (si->local_addr)) == 0)) &&
2430Sstevel@tonic-gate 	    (si->type == si2->type));
2440Sstevel@tonic-gate 
2450Sstevel@tonic-gate }
2460Sstevel@tonic-gate 
2470Sstevel@tonic-gate /*
2480Sstevel@tonic-gate  * proto_info_t comparison function. Returns 0 on match, else -1, as required
2490Sstevel@tonic-gate  * by uu_list_find().
2500Sstevel@tonic-gate  */
2510Sstevel@tonic-gate static int
2520Sstevel@tonic-gate proto_info_compare(const void *lv, const void *rv, void *istlx)
2530Sstevel@tonic-gate {
2540Sstevel@tonic-gate 	proto_info_t	*pi = (proto_info_t *)lv;
2550Sstevel@tonic-gate 	proto_info_t	*pi2 = (proto_info_t *)rv;
2560Sstevel@tonic-gate 
2570Sstevel@tonic-gate 	/* check their RPC configuration matches */
2580Sstevel@tonic-gate 	if (pi->ri != NULL) {
2590Sstevel@tonic-gate 		if ((pi2->ri == NULL) || !rpc_info_equal(pi->ri, pi2->ri))
2600Sstevel@tonic-gate 			return (-1);
2610Sstevel@tonic-gate 	} else if (pi2->ri != NULL) {
2620Sstevel@tonic-gate 		return (-1);
2630Sstevel@tonic-gate 	}
2640Sstevel@tonic-gate 
2650Sstevel@tonic-gate 	if (pi->v6only != pi2->v6only)
2660Sstevel@tonic-gate 		return (-1);
2670Sstevel@tonic-gate 
2680Sstevel@tonic-gate 	if (*(boolean_t *)istlx) {
2690Sstevel@tonic-gate 		if (tlx_info_equal((tlx_info_t *)lv, (tlx_info_t *)rv,
2700Sstevel@tonic-gate 		    pi->ri != NULL))
2710Sstevel@tonic-gate 			return (0);
2720Sstevel@tonic-gate 	} else {
2730Sstevel@tonic-gate 		if (socket_info_equal((socket_info_t *)lv,
2740Sstevel@tonic-gate 		    (socket_info_t *)rv, pi->ri != NULL))
2750Sstevel@tonic-gate 			return (0);
2760Sstevel@tonic-gate 	}
2770Sstevel@tonic-gate 	return (-1);
2780Sstevel@tonic-gate }
2790Sstevel@tonic-gate 
2800Sstevel@tonic-gate /*
2810Sstevel@tonic-gate  * Returns B_TRUE if the bind configuration of the two instance_cfg_t
2820Sstevel@tonic-gate  * structures are equivalent, else B_FALSE.
2830Sstevel@tonic-gate  */
2840Sstevel@tonic-gate boolean_t
2850Sstevel@tonic-gate bind_config_equal(const basic_cfg_t *c1, const basic_cfg_t *c2)
2860Sstevel@tonic-gate {
2870Sstevel@tonic-gate 	proto_info_t	*pi;
2880Sstevel@tonic-gate 
2890Sstevel@tonic-gate 	debug_msg("Entering bind_config_equal");
2900Sstevel@tonic-gate 
2910Sstevel@tonic-gate 	if ((c1->iswait != c2->iswait) ||
2920Sstevel@tonic-gate 	    (c1->istlx != c2->istlx))
2930Sstevel@tonic-gate 		return (B_FALSE);
2940Sstevel@tonic-gate 
2950Sstevel@tonic-gate 	if (uu_list_numnodes(c1->proto_list) !=
2960Sstevel@tonic-gate 	    uu_list_numnodes(c2->proto_list))
2970Sstevel@tonic-gate 		return (B_FALSE);
2980Sstevel@tonic-gate 	/*
2990Sstevel@tonic-gate 	 * For each element in the first configuration's socket/tlx list,
3000Sstevel@tonic-gate 	 * check there's a matching one in the other list.
3010Sstevel@tonic-gate 	 */
3020Sstevel@tonic-gate 	for (pi = uu_list_first(c1->proto_list); pi != NULL;
3030Sstevel@tonic-gate 	    pi = uu_list_next(c1->proto_list, pi)) {
3040Sstevel@tonic-gate 		uu_list_index_t idx;
3050Sstevel@tonic-gate 
3060Sstevel@tonic-gate 		if (uu_list_find(c2->proto_list, pi, (void *)&c1->istlx,
3070Sstevel@tonic-gate 		    &idx) == NULL)
3080Sstevel@tonic-gate 			return (B_FALSE);
3090Sstevel@tonic-gate 	}
3100Sstevel@tonic-gate 
3110Sstevel@tonic-gate 	return (B_TRUE);
3120Sstevel@tonic-gate }
3130Sstevel@tonic-gate 
3140Sstevel@tonic-gate /*
3150Sstevel@tonic-gate  * Write the default values contained in 'bprops', read by
3160Sstevel@tonic-gate  * read_instance_props(), into 'cfg'.
3170Sstevel@tonic-gate  * Returns -1 if memory allocation fails, else 0.
3180Sstevel@tonic-gate  */
3190Sstevel@tonic-gate static int
3200Sstevel@tonic-gate populate_defaults(inetd_prop_t *bprops, basic_cfg_t *cfg)
3210Sstevel@tonic-gate {
3220Sstevel@tonic-gate 	debug_msg("Entering populate_defaults");
3230Sstevel@tonic-gate 
3241293Smh138676 	cfg->do_tcp_wrappers = get_prop_value_boolean(bprops,
3251293Smh138676 	    PR_DO_TCP_WRAPPERS_NAME);
3261293Smh138676 	cfg->do_tcp_trace = get_prop_value_boolean(bprops,
3271293Smh138676 	    PR_DO_TCP_TRACE_NAME);
3281293Smh138676 	cfg->inherit_env = get_prop_value_boolean(bprops, PR_INHERIT_ENV_NAME);
3291293Smh138676 	cfg->wait_fail_cnt = get_prop_value_int(bprops,
3301293Smh138676 	    PR_MAX_FAIL_RATE_CNT_NAME);
3311293Smh138676 	cfg->wait_fail_interval =  get_prop_value_int(bprops,
3320Sstevel@tonic-gate 	    PR_MAX_FAIL_RATE_INTVL_NAME);
3331293Smh138676 	cfg->max_copies = get_prop_value_int(bprops, PR_MAX_COPIES_NAME);
3341293Smh138676 	cfg->conn_rate_offline = get_prop_value_int(bprops,
3351293Smh138676 	    PR_CON_RATE_OFFLINE_NAME);
3361293Smh138676 	cfg->conn_rate_max = get_prop_value_int(bprops, PR_CON_RATE_MAX_NAME);
3371293Smh138676 	cfg->bind_fail_interval = get_prop_value_int(bprops,
3381293Smh138676 	    PR_BIND_FAIL_INTVL_NAME);
3391293Smh138676 	cfg->bind_fail_max = get_prop_value_int(bprops, PR_BIND_FAIL_MAX_NAME);
340*4754Svp157776 	cfg->conn_backlog = get_prop_value_int(bprops,
341*4754Svp157776 	    PR_CONNECTION_BACKLOG_NAME);
3420Sstevel@tonic-gate 	if ((cfg->bind_addr =
3431293Smh138676 	    strdup(get_prop_value_string(bprops, PR_BIND_ADDR_NAME))) == NULL) {
3440Sstevel@tonic-gate 		error_msg(strerror(errno));
3450Sstevel@tonic-gate 		return (-1);
3460Sstevel@tonic-gate 	}
3470Sstevel@tonic-gate 	return (0);
3480Sstevel@tonic-gate }
3490Sstevel@tonic-gate 
3500Sstevel@tonic-gate void
3510Sstevel@tonic-gate destroy_method_infos(method_info_t **mis)
3520Sstevel@tonic-gate {
3530Sstevel@tonic-gate 	int i;
3540Sstevel@tonic-gate 
3550Sstevel@tonic-gate 	for (i = 0; i < NUM_METHODS; i++) {
3560Sstevel@tonic-gate 		destroy_method_info(mis[i]);
3570Sstevel@tonic-gate 		mis[i] = NULL;
3580Sstevel@tonic-gate 	}
3590Sstevel@tonic-gate }
3600Sstevel@tonic-gate 
3610Sstevel@tonic-gate /*
3620Sstevel@tonic-gate  * For each method, if it was specifed convert its entry in 'mprops',
3630Sstevel@tonic-gate  * into an entry in 'mis'. Returns -1 if memory allocation fails or one of the
3640Sstevel@tonic-gate  * exec strings was invalid, else 0.
3650Sstevel@tonic-gate  */
3660Sstevel@tonic-gate static int
3670Sstevel@tonic-gate create_method_infos(const char *fmri, inetd_prop_t **mprops,
3680Sstevel@tonic-gate     method_info_t **mis)
3690Sstevel@tonic-gate {
3700Sstevel@tonic-gate 	int i;
3710Sstevel@tonic-gate 
3720Sstevel@tonic-gate 	debug_msg("Entering create_method_infos, inst: %s", fmri);
3730Sstevel@tonic-gate 
3740Sstevel@tonic-gate 	for (i = 0; i < NUM_METHODS; i++) {
3750Sstevel@tonic-gate 		/*
3760Sstevel@tonic-gate 		 * Only create a method info structure if the method properties
3770Sstevel@tonic-gate 		 * contain an exec string, which we take to mean the method
3780Sstevel@tonic-gate 		 * is specified.
3790Sstevel@tonic-gate 		 */
3800Sstevel@tonic-gate 		if (mprops[i][MP_EXEC].ip_error == IVE_VALID) {
3810Sstevel@tonic-gate 			boolean_t exec_invalid;
3820Sstevel@tonic-gate 
3830Sstevel@tonic-gate 			if ((mis[i] = create_method_info(mprops[i],
3840Sstevel@tonic-gate 			    &exec_invalid)) == NULL) {
3850Sstevel@tonic-gate 				if (exec_invalid) {
3860Sstevel@tonic-gate 					error_msg(gettext("Property %s for "
3870Sstevel@tonic-gate 					    "method %s of instance %s is "
3880Sstevel@tonic-gate 					    "invalid"), PR_EXEC_NAME,
3890Sstevel@tonic-gate 					    methods[i].name, fmri);
3900Sstevel@tonic-gate 				}
3910Sstevel@tonic-gate 				return (-1);
3920Sstevel@tonic-gate 			}
3930Sstevel@tonic-gate 		}
3940Sstevel@tonic-gate 	}
3950Sstevel@tonic-gate 	return (0);
3960Sstevel@tonic-gate }
3970Sstevel@tonic-gate 
3980Sstevel@tonic-gate /*
3990Sstevel@tonic-gate  * Try and read each of the method properties for the method 'method' of
4000Sstevel@tonic-gate  * instance 'inst', and return a table containing all method properties. If an
4010Sstevel@tonic-gate  * error occurs, NULL is returned, with 'err' set to indicate the cause.
4020Sstevel@tonic-gate  * Otherwise, a pointer to an inetd_prop_t table is returned containing all
4030Sstevel@tonic-gate  * the method properties, and each of the properties is flagged according to
4040Sstevel@tonic-gate  * whether it was present or not, and if it was present its value is set in
4050Sstevel@tonic-gate  * the property's entry in the table.
4060Sstevel@tonic-gate  */
4070Sstevel@tonic-gate static inetd_prop_t *
4080Sstevel@tonic-gate read_method_props(const char *inst, instance_method_t method, scf_error_t *err)
4090Sstevel@tonic-gate {
4100Sstevel@tonic-gate 	inetd_prop_t	*ret;
4110Sstevel@tonic-gate 	int		i;
4120Sstevel@tonic-gate 
4130Sstevel@tonic-gate 	debug_msg("Entering read_method_props");
4140Sstevel@tonic-gate 
4150Sstevel@tonic-gate 	if ((ret = calloc(1, sizeof (method_props))) == NULL) {
4160Sstevel@tonic-gate 		*err = SCF_ERROR_NO_MEMORY;
4170Sstevel@tonic-gate 		return (NULL);
4180Sstevel@tonic-gate 	}
4190Sstevel@tonic-gate 
4200Sstevel@tonic-gate 	(void) memcpy(ret, method_props, sizeof (method_props));
4211293Smh138676 	for (i = 0; ret[i].ip_name != NULL; i++) {
4220Sstevel@tonic-gate 		*err = read_prop(rep_handle, &ret[i], i, inst,
4230Sstevel@tonic-gate 		    methods[method].name);
4240Sstevel@tonic-gate 		if ((*err != 0) && (*err != SCF_ERROR_NOT_FOUND)) {
4250Sstevel@tonic-gate 			destroy_method_props(ret);
4260Sstevel@tonic-gate 			return (NULL);
4270Sstevel@tonic-gate 		}
4280Sstevel@tonic-gate 	}
4290Sstevel@tonic-gate 
4300Sstevel@tonic-gate 	return (ret);
4310Sstevel@tonic-gate }
4320Sstevel@tonic-gate 
4330Sstevel@tonic-gate static void
4340Sstevel@tonic-gate destroy_method_props(inetd_prop_t *mprop)
4350Sstevel@tonic-gate {
4360Sstevel@tonic-gate 	int i;
4370Sstevel@tonic-gate 
4380Sstevel@tonic-gate 	if (mprop == NULL)
4390Sstevel@tonic-gate 		return;
4400Sstevel@tonic-gate 
4411293Smh138676 	for (i = 0; mprop[i].ip_name != NULL; i++) {
4421293Smh138676 		if (mprop[i].ip_type == INET_TYPE_STRING &&
4431293Smh138676 		    mprop[i].ip_error == IVE_VALID)
4441293Smh138676 			free(mprop[i].ip_value.iv_string);
4450Sstevel@tonic-gate 	}
4460Sstevel@tonic-gate 
4470Sstevel@tonic-gate 	free(mprop);
4480Sstevel@tonic-gate }
4490Sstevel@tonic-gate 
4500Sstevel@tonic-gate /*
4510Sstevel@tonic-gate  * Destroy the basic and method properties returned by read_inst_props().
4520Sstevel@tonic-gate  */
4530Sstevel@tonic-gate static void
4540Sstevel@tonic-gate destroy_inst_props(inetd_prop_t *bprops, inetd_prop_t **mprops)
4550Sstevel@tonic-gate {
4560Sstevel@tonic-gate 	int	i;
4570Sstevel@tonic-gate 
4580Sstevel@tonic-gate 	free_instance_props(bprops);
4590Sstevel@tonic-gate 	for (i = 0; i < NUM_METHODS; i++)
4600Sstevel@tonic-gate 		destroy_method_props(mprops[i]);
4610Sstevel@tonic-gate }
4620Sstevel@tonic-gate 
4630Sstevel@tonic-gate /*
4640Sstevel@tonic-gate  * Read all the basic and method properties for instance 'inst', as inetd_prop_t
4650Sstevel@tonic-gate  * tables, into the spaces referenced by 'bprops' and 'mprops' respectively.
4660Sstevel@tonic-gate  * Each of the properties in the tables are flagged to indicate if the
4670Sstevel@tonic-gate  * property was present or not, and if it was the value is stored within it.
4680Sstevel@tonic-gate  * If an error occurs at any time -1 is returned and 'err' is set to
4690Sstevel@tonic-gate  * indicate the reason, else 0 is returned.
4700Sstevel@tonic-gate  */
4710Sstevel@tonic-gate static int
4720Sstevel@tonic-gate read_inst_props(const char *fmri, inetd_prop_t **bprops,
4730Sstevel@tonic-gate     inetd_prop_t **mprops, scf_error_t *err)
4740Sstevel@tonic-gate {
4750Sstevel@tonic-gate 	size_t		nprops;
4760Sstevel@tonic-gate 	int		i;
4770Sstevel@tonic-gate 
4780Sstevel@tonic-gate 	debug_msg("Entering read_inst_props");
4790Sstevel@tonic-gate 
4800Sstevel@tonic-gate 	if ((*bprops = read_instance_props(rep_handle, (char *)fmri, &nprops,
4810Sstevel@tonic-gate 	    err)) == NULL)
4820Sstevel@tonic-gate 		return (-1);
4830Sstevel@tonic-gate 
4840Sstevel@tonic-gate 	for (i = 0; i < NUM_METHODS; i++) {
4850Sstevel@tonic-gate 		if ((mprops[i] =
4860Sstevel@tonic-gate 		    read_method_props(fmri, (instance_method_t)i, err)) ==
4870Sstevel@tonic-gate 		    NULL) {
4880Sstevel@tonic-gate 			for (i--; i >= 0; i--)
4890Sstevel@tonic-gate 				destroy_method_props(mprops[i]);
4900Sstevel@tonic-gate 			free_instance_props(*bprops);
4910Sstevel@tonic-gate 			return (-1);
4920Sstevel@tonic-gate 		}
4930Sstevel@tonic-gate 	}
4940Sstevel@tonic-gate 
4950Sstevel@tonic-gate 	return (0);
4960Sstevel@tonic-gate }
4970Sstevel@tonic-gate 
4980Sstevel@tonic-gate /*
4990Sstevel@tonic-gate  * Returns B_TRUE if all required properties were read from the repository
5000Sstevel@tonic-gate  * (whether taken from the defaults or directly from the instance), they
5010Sstevel@tonic-gate  * all had valid values, all the required methods were present, and they
5020Sstevel@tonic-gate  * each had the required properties with valid values. Else, returns B_FALSE.
5030Sstevel@tonic-gate  * If the function returns B_TRUE, the storage referenced by 'cfg' is set
5040Sstevel@tonic-gate  * to point at an allocated instance_cfg_t initialized based on the basic
5050Sstevel@tonic-gate  * properties (not method or defaults).
5060Sstevel@tonic-gate  */
5070Sstevel@tonic-gate static boolean_t
5080Sstevel@tonic-gate valid_inst_props(const char *fmri, inetd_prop_t *bprops, inetd_prop_t **mprops,
5090Sstevel@tonic-gate     basic_cfg_t **cfg)
5100Sstevel@tonic-gate {
5110Sstevel@tonic-gate 	boolean_t	valid;
5120Sstevel@tonic-gate 	size_t		num_bprops;
5130Sstevel@tonic-gate 	int		i;
5140Sstevel@tonic-gate 
5150Sstevel@tonic-gate 	debug_msg("Entering valid_inst_props: inst: %s, bprops: %x, mprops: %x",
5160Sstevel@tonic-gate 	    fmri, bprops, *mprops);
5170Sstevel@tonic-gate 
5180Sstevel@tonic-gate 	valid = valid_props(bprops, fmri, cfg, proto_info_pool, conn_ind_pool);
5190Sstevel@tonic-gate 
5200Sstevel@tonic-gate 	/*
5210Sstevel@tonic-gate 	 * Double check we've got all necessary properties (valid_props()
5220Sstevel@tonic-gate 	 * doesn't enforce the presence of defaults), and output error messages
5230Sstevel@tonic-gate 	 * for each invalid/ missing property.
5240Sstevel@tonic-gate 	 */
5250Sstevel@tonic-gate 	(void) get_prop_table(&num_bprops);
5261293Smh138676 	for (i = 0; bprops[i].ip_name != NULL; i++) {
5270Sstevel@tonic-gate 		switch (bprops[i].ip_error) {
5280Sstevel@tonic-gate 		case IVE_UNSET:
5290Sstevel@tonic-gate 			if (!bprops[i].ip_default)
5300Sstevel@tonic-gate 				continue;
5310Sstevel@tonic-gate 			if ((i == PT_ARG0_INDEX) || (i == PT_EXEC_INDEX))
5320Sstevel@tonic-gate 				continue;
5330Sstevel@tonic-gate 			/* FALLTHROUGH */
5340Sstevel@tonic-gate 		case IVE_INVALID:
5350Sstevel@tonic-gate 			error_msg(gettext("Property '%s' of instance "
5360Sstevel@tonic-gate 			    "%s is missing, inconsistent or invalid"),
5370Sstevel@tonic-gate 			    bprops[i].ip_name, fmri);
5380Sstevel@tonic-gate 			valid = B_FALSE;
5390Sstevel@tonic-gate 		}
5400Sstevel@tonic-gate 	}
5410Sstevel@tonic-gate 
5420Sstevel@tonic-gate 	for (i = 0; i < NUM_METHODS; i++) {
5430Sstevel@tonic-gate 		int	j;
5440Sstevel@tonic-gate 
5450Sstevel@tonic-gate 		/* check if any properties are set */
5461293Smh138676 		for (j = 0; mprops[i][j].ip_name != NULL; j++) {
5470Sstevel@tonic-gate 			if (mprops[i][j].ip_error != IVE_UNSET)
5480Sstevel@tonic-gate 				break;
5490Sstevel@tonic-gate 		}
5500Sstevel@tonic-gate 
5511293Smh138676 		if (mprops[i][j].ip_name == NULL) {
5520Sstevel@tonic-gate 			/* an unspecified method */
5530Sstevel@tonic-gate 			if ((instance_method_t)i == IM_START) {
5540Sstevel@tonic-gate 				error_msg(gettext(
5550Sstevel@tonic-gate 				    "Unspecified %s method for instance %s"),
5560Sstevel@tonic-gate 				    START_METHOD_NAME, fmri);
5570Sstevel@tonic-gate 				valid = B_FALSE;
5580Sstevel@tonic-gate 			}
5590Sstevel@tonic-gate 		} else if (mprops[i][MP_EXEC].ip_error == IVE_UNSET) {
5600Sstevel@tonic-gate 			error_msg(gettext("Missing %s property from method %s "
5610Sstevel@tonic-gate 			    "of instance %s"), PR_EXEC_NAME,
5620Sstevel@tonic-gate 			    methods[(instance_method_t)i].name, fmri);
5630Sstevel@tonic-gate 			valid = B_FALSE;
5640Sstevel@tonic-gate 		}
5650Sstevel@tonic-gate 	}
5660Sstevel@tonic-gate 
5670Sstevel@tonic-gate 	if (!valid)
5680Sstevel@tonic-gate 		destroy_basic_cfg(*cfg);
5690Sstevel@tonic-gate 
5700Sstevel@tonic-gate 	return (valid);
5710Sstevel@tonic-gate }
5720Sstevel@tonic-gate 
5730Sstevel@tonic-gate void
5740Sstevel@tonic-gate destroy_instance_cfg(instance_cfg_t *cfg)
5750Sstevel@tonic-gate {
5760Sstevel@tonic-gate 	if (cfg != NULL) {
5770Sstevel@tonic-gate 		destroy_basic_cfg(cfg->basic);
5780Sstevel@tonic-gate 		destroy_method_infos(cfg->methods);
5790Sstevel@tonic-gate 		free(cfg);
5800Sstevel@tonic-gate 	}
5810Sstevel@tonic-gate }
5820Sstevel@tonic-gate 
5830Sstevel@tonic-gate /*
5840Sstevel@tonic-gate  * Returns an allocated instance_cfg_t representation of an instance's
5850Sstevel@tonic-gate  * configuration read from the repository. If the configuration is invalid, a
5860Sstevel@tonic-gate  * repository error occurred, or a memory allocation occurred returns NULL,
5870Sstevel@tonic-gate  * else returns a pointer to the allocated instance_cfg_t.
5880Sstevel@tonic-gate  */
5890Sstevel@tonic-gate instance_cfg_t *
5900Sstevel@tonic-gate read_instance_cfg(const char *fmri)
5910Sstevel@tonic-gate {
5920Sstevel@tonic-gate 	uint_t		retries;
5930Sstevel@tonic-gate 	inetd_prop_t	*bprops;
5940Sstevel@tonic-gate 	inetd_prop_t	*mprops[NUM_METHODS];
5950Sstevel@tonic-gate 	instance_cfg_t	*ret = NULL;
5960Sstevel@tonic-gate 	scf_error_t	err;
5970Sstevel@tonic-gate 
5980Sstevel@tonic-gate 	debug_msg("Entering read_instance_cfg");
5990Sstevel@tonic-gate 
6000Sstevel@tonic-gate 	if ((ret = calloc(1, sizeof (instance_cfg_t))) == NULL)
6010Sstevel@tonic-gate 		return (NULL);
6020Sstevel@tonic-gate 
6030Sstevel@tonic-gate 	for (retries = 0; retries <= REP_OP_RETRIES; retries++) {
6040Sstevel@tonic-gate 		if (make_handle_bound(rep_handle) == -1) {
6050Sstevel@tonic-gate 			err = scf_error();
6060Sstevel@tonic-gate 			goto read_error;
6070Sstevel@tonic-gate 		}
6080Sstevel@tonic-gate 
6090Sstevel@tonic-gate 		if (read_inst_props(fmri, &bprops, mprops, &err) == 0)
6100Sstevel@tonic-gate 			break;
6110Sstevel@tonic-gate 		if (err != SCF_ERROR_CONNECTION_BROKEN)
6120Sstevel@tonic-gate 			goto read_error;
6130Sstevel@tonic-gate 		(void) scf_handle_unbind(rep_handle);
6140Sstevel@tonic-gate 	}
6150Sstevel@tonic-gate 	if (retries > REP_OP_RETRIES)
6160Sstevel@tonic-gate 		goto read_error;
6170Sstevel@tonic-gate 
6180Sstevel@tonic-gate 	/*
6190Sstevel@tonic-gate 	 * Switch off validation of the start method's exec string, since
6200Sstevel@tonic-gate 	 * during boot the filesystem it resides on may not have been
6210Sstevel@tonic-gate 	 * mounted yet, which would result in a false validation failure.
6220Sstevel@tonic-gate 	 * We'll catch any real errors when the start method is first run
6230Sstevel@tonic-gate 	 * in passes_basic_exec_checks().
6240Sstevel@tonic-gate 	 */
6250Sstevel@tonic-gate 	bprops[PT_EXEC_INDEX].ip_error = IVE_UNSET;
6260Sstevel@tonic-gate 
6270Sstevel@tonic-gate 	if ((!valid_inst_props(fmri, bprops, mprops, &ret->basic)) ||
6280Sstevel@tonic-gate 	    (populate_defaults(bprops, ret->basic) != 0) ||
6290Sstevel@tonic-gate 	    (create_method_infos(fmri, mprops, ret->methods) != 0)) {
6300Sstevel@tonic-gate 		destroy_instance_cfg(ret);
6310Sstevel@tonic-gate 		ret = NULL;
6320Sstevel@tonic-gate 	}
6330Sstevel@tonic-gate 
6340Sstevel@tonic-gate 	destroy_inst_props(bprops, mprops);
6350Sstevel@tonic-gate 	return (ret);
6360Sstevel@tonic-gate 
6370Sstevel@tonic-gate read_error:
6380Sstevel@tonic-gate 	error_msg(gettext(
6390Sstevel@tonic-gate 	    "Failed to read the configuration of instance %s: %s"), fmri,
6400Sstevel@tonic-gate 	    scf_strerror(err));
6410Sstevel@tonic-gate 	free(ret);
6420Sstevel@tonic-gate 	return (NULL);
6430Sstevel@tonic-gate }
6440Sstevel@tonic-gate 
6450Sstevel@tonic-gate /*
6460Sstevel@tonic-gate  * Returns a pointer to an allocated method context for the specified method
6470Sstevel@tonic-gate  * of the specified instance if it could retrieve it. Else, if there were
6480Sstevel@tonic-gate  * errors retrieving it, NULL is returned and the pointer referenced by
6490Sstevel@tonic-gate  * 'errstr' is set to point at an appropriate error string.
6500Sstevel@tonic-gate  */
6510Sstevel@tonic-gate struct method_context *
6520Sstevel@tonic-gate read_method_context(const char *inst_fmri, const char *method, const char *path,
6530Sstevel@tonic-gate     const char **errstr)
6540Sstevel@tonic-gate {
6550Sstevel@tonic-gate 	scf_instance_t			*scf_inst = NULL;
6560Sstevel@tonic-gate 	struct method_context		*ret;
6570Sstevel@tonic-gate 	uint_t				retries;
6580Sstevel@tonic-gate 	const char			*tmpstr;
6590Sstevel@tonic-gate 
6600Sstevel@tonic-gate 	debug_msg("Entering read_method_context: inst: %s, method: %s, "
6610Sstevel@tonic-gate 	    "path: %s", inst_fmri, method, path);
6620Sstevel@tonic-gate 
6630Sstevel@tonic-gate 	for (retries = 0; retries <= REP_OP_RETRIES; retries++) {
6640Sstevel@tonic-gate 		if (make_handle_bound(rep_handle) == -1)
6650Sstevel@tonic-gate 			goto inst_failure;
6660Sstevel@tonic-gate 
6670Sstevel@tonic-gate 		if (((scf_inst = scf_instance_create(rep_handle)) != NULL) &&
6680Sstevel@tonic-gate 		    (scf_handle_decode_fmri(rep_handle, inst_fmri, NULL, NULL,
6690Sstevel@tonic-gate 		    scf_inst, NULL, NULL, SCF_DECODE_FMRI_EXACT) == 0))
6700Sstevel@tonic-gate 			break;
6710Sstevel@tonic-gate 		if (scf_error() != SCF_ERROR_CONNECTION_BROKEN) {
6720Sstevel@tonic-gate 			scf_instance_destroy(scf_inst);
6730Sstevel@tonic-gate 			goto inst_failure;
6740Sstevel@tonic-gate 		}
6750Sstevel@tonic-gate 
6760Sstevel@tonic-gate 		(void) scf_instance_destroy(scf_inst);
6770Sstevel@tonic-gate 		scf_inst = NULL;
6780Sstevel@tonic-gate 
6790Sstevel@tonic-gate 		(void) scf_handle_unbind(rep_handle);
6800Sstevel@tonic-gate 	}
6810Sstevel@tonic-gate 	if (retries > REP_OP_RETRIES)
6820Sstevel@tonic-gate 		goto inst_failure;
6830Sstevel@tonic-gate 
6840Sstevel@tonic-gate 	if ((tmpstr = restarter_get_method_context(
6850Sstevel@tonic-gate 	    RESTARTER_METHOD_CONTEXT_VERSION, scf_inst, NULL, method, path,
6860Sstevel@tonic-gate 	    &ret)) != NULL) {
6870Sstevel@tonic-gate 		ret = NULL;
6880Sstevel@tonic-gate 		*errstr = tmpstr;
6890Sstevel@tonic-gate 	}
6900Sstevel@tonic-gate 
6910Sstevel@tonic-gate 	scf_instance_destroy(scf_inst);
6920Sstevel@tonic-gate 	return (ret);
6930Sstevel@tonic-gate 
6940Sstevel@tonic-gate inst_failure:
6950Sstevel@tonic-gate 	/*
6960Sstevel@tonic-gate 	 * We can rely on this string not becoming invalid
6970Sstevel@tonic-gate 	 * since we don't call bind_textdomain_codeset() or
6980Sstevel@tonic-gate 	 * setlocale(3C) after initialization.
6990Sstevel@tonic-gate 	 */
7000Sstevel@tonic-gate 	*errstr = gettext("failed to get instance from repository");
7010Sstevel@tonic-gate 	return (NULL);
7020Sstevel@tonic-gate }
7030Sstevel@tonic-gate 
7040Sstevel@tonic-gate /*
7050Sstevel@tonic-gate  * Reads the value of the enabled property from the named property group
7060Sstevel@tonic-gate  * of the given instance.
7070Sstevel@tonic-gate  * If an error occurs, the SCF error code is returned. The possible errors are:
7080Sstevel@tonic-gate  * - SCF_ERROR_INVALID_ARGUMENT: The enabled property is not a boolean.
7090Sstevel@tonic-gate  * - SCF_ERROR_NONE: No value exists for the enabled property.
7100Sstevel@tonic-gate  * - SCF_ERROR_CONNECTION_BROKEN: Repository connection broken.
7110Sstevel@tonic-gate  * - SCF_ERROR_NOT_FOUND: The property wasn't found.
7120Sstevel@tonic-gate  * - SCF_ERROR_NO_MEMORY: allocation failure.
7130Sstevel@tonic-gate  * Else 0 is returned and 'enabled' set appropriately.
7140Sstevel@tonic-gate  */
7150Sstevel@tonic-gate static scf_error_t
7160Sstevel@tonic-gate read_enable_prop(const char *fmri, boolean_t *enabled, const char *pg)
7170Sstevel@tonic-gate {
7180Sstevel@tonic-gate 	scf_simple_prop_t	*sp;
7190Sstevel@tonic-gate 	uint8_t			*u8p;
7200Sstevel@tonic-gate 
7210Sstevel@tonic-gate 	if ((sp = scf_simple_prop_get(rep_handle, fmri, pg,
7220Sstevel@tonic-gate 	    SCF_PROPERTY_ENABLED)) == NULL)
7230Sstevel@tonic-gate 		return (scf_error());
7240Sstevel@tonic-gate 
7250Sstevel@tonic-gate 	if ((u8p = scf_simple_prop_next_boolean(sp)) == NULL) {
7260Sstevel@tonic-gate 		scf_simple_prop_free(sp);
7270Sstevel@tonic-gate 		return (scf_error());
7280Sstevel@tonic-gate 	}
7290Sstevel@tonic-gate 
7300Sstevel@tonic-gate 	*enabled = (*u8p != 0);
7310Sstevel@tonic-gate 	scf_simple_prop_free(sp);
7320Sstevel@tonic-gate 	return (0);
7330Sstevel@tonic-gate }
7340Sstevel@tonic-gate 
7350Sstevel@tonic-gate /*
7360Sstevel@tonic-gate  * Reads the enabled value for the given instance FMRI. The read value
7370Sstevel@tonic-gate  * is based on a merge of the 'standard' enabled property, and the temporary
7380Sstevel@tonic-gate  * override one; the merge involves using the latter properties value if
7390Sstevel@tonic-gate  * present, else resporting to the formers. If an error occurs -1 is returned,
7400Sstevel@tonic-gate  * else 0 is returned and 'enabled' set approriately.
7410Sstevel@tonic-gate  */
7420Sstevel@tonic-gate int
7430Sstevel@tonic-gate read_enable_merged(const char *fmri, boolean_t *enabled)
7440Sstevel@tonic-gate {
7450Sstevel@tonic-gate 	uint_t		retries;
7460Sstevel@tonic-gate 
7470Sstevel@tonic-gate 	debug_msg("Entering read_enabled_prop: inst: %s", fmri);
7480Sstevel@tonic-gate 
7490Sstevel@tonic-gate 	for (retries = 0; retries <= REP_OP_RETRIES; retries++) {
7500Sstevel@tonic-gate 		if (make_handle_bound(rep_handle) == -1)
7510Sstevel@tonic-gate 			goto gen_fail;
7520Sstevel@tonic-gate 
7530Sstevel@tonic-gate 		switch (read_enable_prop(fmri, enabled, SCF_PG_GENERAL_OVR)) {
7540Sstevel@tonic-gate 		case 0:
7550Sstevel@tonic-gate 			debug_msg("read %d from override", *enabled);
7560Sstevel@tonic-gate 			return (0);
7570Sstevel@tonic-gate 		case SCF_ERROR_CONNECTION_BROKEN:
7580Sstevel@tonic-gate 			break;
7590Sstevel@tonic-gate 		case SCF_ERROR_NOT_FOUND:
7600Sstevel@tonic-gate 		case SCF_ERROR_NONE:
7610Sstevel@tonic-gate 		case SCF_ERROR_INVALID_ARGUMENT:
7620Sstevel@tonic-gate 			switch (read_enable_prop(fmri, enabled,
7630Sstevel@tonic-gate 			    SCF_PG_GENERAL)) {
7640Sstevel@tonic-gate 			case 0:
7650Sstevel@tonic-gate 				debug_msg("read %d from non_override",
7660Sstevel@tonic-gate 				    *enabled);
7670Sstevel@tonic-gate 				return (0);
7680Sstevel@tonic-gate 			case SCF_ERROR_CONNECTION_BROKEN:
7690Sstevel@tonic-gate 				break;
7700Sstevel@tonic-gate 			case SCF_ERROR_NOT_FOUND:
7710Sstevel@tonic-gate 			case SCF_ERROR_NONE:
7720Sstevel@tonic-gate 			case SCF_ERROR_INVALID_ARGUMENT:
7730Sstevel@tonic-gate 				error_msg(gettext("Missing %s property/value "
7740Sstevel@tonic-gate 				    "for instance %s"), SCF_PROPERTY_ENABLED,
7750Sstevel@tonic-gate 				    fmri);
7760Sstevel@tonic-gate 				return (-1);
7770Sstevel@tonic-gate 			default:
7780Sstevel@tonic-gate 				goto gen_fail;
7790Sstevel@tonic-gate 			}
7800Sstevel@tonic-gate 			break;
7810Sstevel@tonic-gate 		default:
7820Sstevel@tonic-gate 			goto gen_fail;
7830Sstevel@tonic-gate 		}
7840Sstevel@tonic-gate 
7850Sstevel@tonic-gate 		(void) scf_handle_unbind(rep_handle);
7860Sstevel@tonic-gate 		continue;
7870Sstevel@tonic-gate 	}
7880Sstevel@tonic-gate 
7890Sstevel@tonic-gate gen_fail:
7900Sstevel@tonic-gate 	error_msg(gettext("Failed to read the %s property of instance %s: %s"),
7910Sstevel@tonic-gate 	    SCF_PROPERTY_ENABLED, fmri, scf_strerror(scf_error()));
7920Sstevel@tonic-gate 	return (-1);
7930Sstevel@tonic-gate }
794