示例#1
0
static void
get_smf_properties()
{
	scf_simple_prop_t *prop;
	uint8_t *val;

	if ((prop = scf_simple_prop_get(NULL, RMVOLMGR_FMRI,
	    "rmvolmgr", "legacy_mountpoints")) != NULL) {
		if ((val = scf_simple_prop_next_boolean(prop)) != NULL) {
			rmm_vold_mountpoints_enabled = (*val != 0);
		}
		scf_simple_prop_free(prop);
	}

	if ((prop = scf_simple_prop_get(NULL, RMVOLMGR_FMRI,
	    "rmvolmgr", "cde_compatible")) != NULL) {
		if ((val = scf_simple_prop_next_boolean(prop)) != NULL) {
			rmm_vold_actions_enabled = (*val != 0);
		}
		scf_simple_prop_free(prop);
	}

	if ((prop = scf_simple_prop_get(NULL, RMVOLMGR_FMRI,
	    "rmvolmgr", "eject_button")) != NULL) {
		if ((val = scf_simple_prop_next_boolean(prop)) != NULL) {
			rmm_prop_eject_button = (*val != 0);
		}
		scf_simple_prop_free(prop);
	}
}
示例#2
0
static PyObject *
pyscf_get_bool(PyObject *o, PyObject *args, PyObject *kwargs)
{
	static char *kwlist[] = { "name", NULL };
	scf_simple_prop_t *prop;
	uint8_t *val;
	char *name;

	if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s", kwlist, &name))
		return (NULL);

	prop = scf_simple_prop_get(NULL, XEND_FMRI, XEND_PG, name);

	if (prop == NULL)
		return (scf_exception("scf_simple_prop_get() failed", name));

	if ((val = scf_simple_prop_next_boolean(prop)) == NULL)
		return (scf_exception("scf_simple_prop_next_boolean() failed",
		    name));

	if (*val) {
		scf_simple_prop_free(prop);
		Py_INCREF(Py_True);
		return (Py_True);
	}

	scf_simple_prop_free(prop);
	Py_INCREF(Py_False);
	return (Py_False);
}
示例#3
0
static void *
get_smf_prop(const char *var, char type, void *def_val)
{
	scf_simple_prop_t	*prop;
	void			*val;
	char			*me = "get_smf_prop";

	prop = scf_simple_prop_get(NULL, NULL, "config", var);
	if (prop) {
		switch (type) {
		case 'b':
			val = scf_simple_prop_next_boolean(prop);
			if (val != NULL)
				(void) memcpy(def_val, val, sizeof (uint8_t));
			break;

		case 'i':
			val = scf_simple_prop_next_integer(prop);
			if (val != NULL)
				(void) memcpy(def_val, val, sizeof (int64_t));
			break;
		}
		scf_simple_prop_free(prop);
	}

	if (prop == NULL || val == NULL) {
		char	vs[64];

		switch (type) {
		case 'b':
			if (*(uint8_t *)def_val)
				(void) strcpy(vs, "yes");
			else
				(void) strcpy(vs, "no");

			break;

		case 'i':
			(void) sprintf(vs, "%lld", *(int64_t *)def_val);
			break;

		}
		_NSCD_LOG(NSCD_LOG_SELF_CRED, NSCD_LOG_LEVEL_ALERT)
		(me, "no value for config/%s (%s). "
		    "Using default \"%s\"\n", var,
		    scf_strerror(scf_error()), vs);
	}

	return (def_val);
}
示例#4
0
/*
 * Reads the value of the enabled property from the named property group
 * of the given instance.
 * If an error occurs, the SCF error code is returned. The possible errors are:
 * - SCF_ERROR_INVALID_ARGUMENT: The enabled property is not a boolean.
 * - SCF_ERROR_NONE: No value exists for the enabled property.
 * - SCF_ERROR_CONNECTION_BROKEN: Repository connection broken.
 * - SCF_ERROR_NOT_FOUND: The property wasn't found.
 * - SCF_ERROR_NO_MEMORY: allocation failure.
 * Else 0 is returned and 'enabled' set appropriately.
 */
static scf_error_t
read_enable_prop(const char *fmri, boolean_t *enabled, const char *pg)
{
	scf_simple_prop_t	*sp;
	uint8_t			*u8p;

	if ((sp = scf_simple_prop_get(rep_handle, fmri, pg,
	    SCF_PROPERTY_ENABLED)) == NULL)
		return (scf_error());

	if ((u8p = scf_simple_prop_next_boolean(sp)) == NULL) {
		scf_simple_prop_free(sp);
		return (scf_error());
	}

	*enabled = (*u8p != 0);
	scf_simple_prop_free(sp);
	return (0);
}
示例#5
0
static int
get_smf_prop(const char *var, boolean_t def_val)
{
	scf_simple_prop_t *prop;
	uint8_t *val;
	boolean_t res = def_val;
	prop = scf_simple_prop_get(NULL, "svc:/application/security/tcsd:default",
		"config", var);
	if (prop) {
		if ((val = scf_simple_prop_next_boolean(prop)) != NULL)
			res = (*val == 0) ? B_FALSE : B_TRUE;
		scf_simple_prop_free(prop);
	}
	if (prop == NULL || val == NULL) {
		syslog(LOG_ALERT, "no value for config/%s (%s). "
			"Using default \"%s\"", var, scf_strerror(scf_error()),
			def_val ? "true" : "false");
	}
	return (res);
}
示例#6
0
/*
 * Refresh the value of debug property under the property group "config"
 * for network/inetd service.
 */
void
refresh_debug_flag(void)
{
	scf_simple_prop_t	*sprop;
	uint8_t			*tmp_bool;

	if ((sprop = scf_simple_prop_get(rep_handle, INETD_INSTANCE_FMRI,
	    PG_NAME_APPLICATION_CONFIG, PR_NAME_DEBUG_FLAG)) == NULL) {
		error_msg(gettext("Unable to read %s property from %s property "
		    "group. scf_simple_prop_get() failed: %s"),
		    PR_NAME_DEBUG_FLAG, PG_NAME_APPLICATION_CONFIG,
		    scf_strerror(scf_error()));
		return;
	} else if ((tmp_bool = scf_simple_prop_next_boolean(sprop)) == NULL) {
		error_msg(gettext("Unable to read %s property for %s service. "
		    "scf_simple_prop_next_boolean() failed: %s"),
		    PR_NAME_DEBUG_FLAG, INETD_INSTANCE_FMRI,
		    scf_strerror(scf_error()));
	} else {
		debug_enabled = ((*tmp_bool == 0) ? B_FALSE : B_TRUE);
	}

	scf_simple_prop_free(sprop);
}
示例#7
0
/*ARGSUSED*/
scf_error_t
read_prop(scf_handle_t *h, inetd_prop_t *iprop, int index, const char *inst,
    const char *pg_name)
{
	scf_simple_prop_t	*sprop;
	uint8_t			*tmp_bool;
	int64_t			*tmp_int;
	uint64_t		*tmp_cnt;
	char			*tmp_char;

	if ((sprop = scf_simple_prop_get(h, inst, pg_name, iprop->ip_name)) ==
	    NULL)
		return (scf_error());

	switch (iprop->ip_type) {
	case INET_TYPE_STRING:
		if ((tmp_char = scf_simple_prop_next_astring(sprop)) == NULL)
			goto scf_error;
		if ((iprop->ip_value.iv_string = strdup(tmp_char)) == NULL) {
			scf_simple_prop_free(sprop);
			return (SCF_ERROR_NO_MEMORY);
		}
		break;
	case INET_TYPE_STRING_LIST:
		{
			int	j = 0;

			while ((tmp_char =
			    scf_simple_prop_next_astring(sprop)) != NULL) {
				char	**cpp;

				if ((cpp = realloc(
				    iprop->ip_value.iv_string_list,
				    (j + 2) * sizeof (char *))) == NULL) {
					scf_simple_prop_free(sprop);
					return (SCF_ERROR_NO_MEMORY);
				}
				iprop->ip_value.iv_string_list = cpp;
				if ((cpp[j] = strdup(tmp_char)) == NULL) {
					scf_simple_prop_free(sprop);
					return (SCF_ERROR_NO_MEMORY);
				}
				cpp[++j] = NULL;
			}
			if ((j == 0) || (scf_error() != SCF_ERROR_NONE))
				goto scf_error;
		}
		break;
	case INET_TYPE_BOOLEAN:
		if ((tmp_bool = scf_simple_prop_next_boolean(sprop)) == NULL)
			goto scf_error;
		iprop->ip_value.iv_boolean =
		    (*tmp_bool == 0) ? B_FALSE : B_TRUE;
		break;
	case INET_TYPE_COUNT:
		if ((tmp_cnt = scf_simple_prop_next_count(sprop)) == NULL)
			goto scf_error;
		iprop->ip_value.iv_cnt = *tmp_cnt;
		break;
	case INET_TYPE_INTEGER:
		if ((tmp_int = scf_simple_prop_next_integer(sprop)) == NULL)
			goto scf_error;
		iprop->ip_value.iv_int = *tmp_int;
		break;
	default:
		assert(0);
	}

	iprop->ip_error = IVE_VALID;
	scf_simple_prop_free(sprop);
	return (0);

scf_error:
	scf_simple_prop_free(sprop);
	if (scf_error() == SCF_ERROR_NONE)
		return (SCF_ERROR_NOT_FOUND);
	return (scf_error());
}
示例#8
0
文件: inetadm.c 项目: andreiw/polaris
/*ARGSUSED*/
static int
list_callback(scf_handle_t *hin, scf_instance_t *inst, void *buf)
{
	ssize_t			max_name_length;
	char			*inst_name;
	scf_simple_prop_t	*prop = NULL, *prop2 = NULL;
	const uint8_t		*enabled;
	const char		*state, *restart_str;

	max_name_length = scf_limit(SCF_LIMIT_MAX_NAME_LENGTH);
	if ((inst_name = malloc(max_name_length + 1)) == NULL)
		uu_die(gettext("Error: Out of memory.\n"));

	/*
	 * Get the FMRI of the instance, and check if its delegated restarter
	 * is inetd.
	 */

	if (scf_instance_to_fmri(inst, inst_name, max_name_length + 1) < 0)
		return (SCF_FAILED);

	if ((prop = scf_simple_prop_get(hin, inst_name, SCF_PG_GENERAL,
	    SCF_PROPERTY_RESTARTER)) == NULL)
		goto out;

	if ((restart_str = scf_simple_prop_next_ustring(prop)) == NULL)
		goto out;

	if (strstr(restart_str, INETADM_INETD_STR) == NULL)
		goto out;

	/* Free restarter prop so it can be reused below */
	scf_simple_prop_free(prop);

	/*
	 * We know that this instance is managed by inetd.
	 * Now get the enabled and state properties.
	 */

	if (((prop = scf_simple_prop_get(hin, inst_name, SCF_PG_GENERAL,
	    SCF_PROPERTY_ENABLED)) == NULL) ||
	    ((enabled = scf_simple_prop_next_boolean(prop)) == NULL)) {
		(void) uu_warn(gettext("Error: Instance %s is missing enabled "
		    "property.\n"), inst_name);
		goto out;
	}

	if (((prop2 = scf_simple_prop_get(hin, inst_name, SCF_PG_RESTARTER,
	    SCF_PROPERTY_STATE)) == NULL) ||
	    ((state = scf_simple_prop_next_astring(prop2)) == NULL)) {
		(void) uu_warn(gettext("Error: Instance %s is missing state "
		    "property.\n"), inst_name);
		goto out;
	}

	/* Print enabled/disabled, state, and FMRI for the instance. */

	if (*enabled)
		(void) printf("%-10s%-15s%s\n", INETADM_ENABLED_STR, state,
		    inst_name);
	else
		(void) printf("%-10s%-15s%s\n", INETADM_DISABLED_STR, state,
		    inst_name);

out:
	free(inst_name);
	scf_simple_prop_free(prop);
	scf_simple_prop_free(prop2);
	return (SCF_SUCCESS);
}