Example #1
0
/*
 * Transforms the properties read from the repository for a method into a
 * method_info_t and returns a pointer to it. If expansion of the exec
 * property fails, due to an invalid string or memory allocation failure,
 * NULL is returned and exec_invalid is set appropriately to indicate whether
 * it was a memory allocation failure or an invalid exec string.
 */
static method_info_t *
create_method_info(const inetd_prop_t *mprops, boolean_t *exec_invalid)
{
	method_info_t	*ret;
	int		i;

	debug_msg("Entering create_method_info");

	if ((ret = calloc(1, sizeof (method_info_t))) == NULL)
		goto alloc_fail;

	/* Expand the exec string. */
	if ((i = wordexp(get_prop_value_string(mprops, PR_EXEC_NAME),
	    &ret->exec_args_we, WRDE_NOCMD|WRDE_UNDEF)) != 0) {
		if (i == WRDE_NOSPACE)
			goto alloc_fail;

		*exec_invalid = B_TRUE;
		free(ret);
		return (NULL);
	}

	if ((ret->exec_path = strdup(ret->exec_args_we.we_wordv[0])) == NULL)
		goto alloc_fail;

	if (mprops[MP_ARG0].ip_error == IVE_VALID) {	/* arg0 is set */
		/*
		 * Keep a copy of arg0 of the wordexp structure so that
		 * wordfree() gets passed what wordexp() originally returned,
		 * as documented as required in the man page.
		 */
		ret->wordexp_arg0_backup = ret->exec_args_we.we_wordv[0];
		if ((ret->exec_args_we.we_wordv[0] =
		    strdup(get_prop_value_string(mprops, PR_ARG0_NAME)))
		    == NULL)
			goto alloc_fail;
	}

	if (mprops[MP_TIMEOUT].ip_error == IVE_VALID) {
		ret->timeout = get_prop_value_count(mprops,
		    SCF_PROPERTY_TIMEOUT);
	} else {
		ret->timeout = DEFAULT_METHOD_TIMEOUT;
	}

	/* exec_invalid not set on success */

	return (ret);

alloc_fail:
	error_msg(strerror(errno));
	destroy_method_info(ret);
	*exec_invalid = B_FALSE;
	return (NULL);
}
Example #2
0
/*
 * Write the default values contained in 'bprops', read by
 * read_instance_props(), into 'cfg'.
 * Returns -1 if memory allocation fails, else 0.
 */
static int
populate_defaults(inetd_prop_t *bprops, basic_cfg_t *cfg)
{
	cfg->do_tcp_wrappers = get_prop_value_boolean(bprops,
	    PR_DO_TCP_WRAPPERS_NAME);
	cfg->do_tcp_trace = get_prop_value_boolean(bprops,
	    PR_DO_TCP_TRACE_NAME);
	cfg->do_tcp_keepalive = get_prop_value_boolean(bprops,
	    PR_DO_TCP_KEEPALIVE_NAME);
	cfg->inherit_env = get_prop_value_boolean(bprops, PR_INHERIT_ENV_NAME);
	cfg->wait_fail_cnt = get_prop_value_int(bprops,
	    PR_MAX_FAIL_RATE_CNT_NAME);
	cfg->wait_fail_interval =  get_prop_value_int(bprops,
	    PR_MAX_FAIL_RATE_INTVL_NAME);
	cfg->max_copies = get_prop_value_int(bprops, PR_MAX_COPIES_NAME);
	cfg->conn_rate_offline = get_prop_value_int(bprops,
	    PR_CON_RATE_OFFLINE_NAME);
	cfg->conn_rate_max = get_prop_value_int(bprops, PR_CON_RATE_MAX_NAME);
	cfg->bind_fail_interval = get_prop_value_int(bprops,
	    PR_BIND_FAIL_INTVL_NAME);
	cfg->bind_fail_max = get_prop_value_int(bprops, PR_BIND_FAIL_MAX_NAME);
	cfg->conn_backlog = get_prop_value_int(bprops,
	    PR_CONNECTION_BACKLOG_NAME);
	if ((cfg->bind_addr =
	    strdup(get_prop_value_string(bprops, PR_BIND_ADDR_NAME))) == NULL) {
		error_msg(strerror(errno));
		return (-1);
	}
	return (0);
}