Ejemplo n.º 1
0
/*
 * retrieve_inetd_hash retrieves inetd's configuration file hash from the
 * repository. On success, hash is modified to point to the hash string and
 * SCF_ERROR_NONE is returned. Otherwise, the scf_error value is returned.
 * The space for the hash string is obtained using malloc(3C) and should be
 * freed by the caller.
 */
scf_error_t
retrieve_inetd_hash(char **hash)
{
	scf_simple_prop_t *sp;
	char *hashstr, *s;
	scf_error_t scf_err;

	if ((sp = scf_simple_prop_get(NULL, INETD_INSTANCE_FMRI, HASH_PG,
	    HASH_PROP)) == NULL)
		return (scf_error());

	if ((hashstr = scf_simple_prop_next_astring(sp)) == NULL) {
		scf_err = scf_error();
		scf_simple_prop_free(sp);
		return (scf_err);
	}

	if ((s = strdup(hashstr)) == NULL) {
		scf_simple_prop_free(sp);
		return (SCF_ERROR_NO_MEMORY);
	}
	*hash = s;
	scf_simple_prop_free(sp);
	return (SCF_ERROR_NONE);
}
Ejemplo n.º 2
0
static void
load_mdns_domaincfg(scf_handle_t *h, char **storelist,
			const char *scfprop, int maxprops)
{
	scf_simple_prop_t *sprop;
	char *tchr;
	char *pchr;
	int tlen;
	int cnt = 0;

	if ((sprop = scf_simple_prop_get(h, SMF_MDNS_FMRI,
	    SMF_NSSMDNSCFG_PROPGRP, scfprop)) == NULL)
			return;

	while ((cnt < maxprops) &&
	    (tchr = scf_simple_prop_next_astring(sprop)) != NULL) {

		/* Remove beginning & trailing '.' chars */
		while (*tchr && (*tchr == '.'))
			tchr++;

		if (*tchr && ((tlen = strlen(tchr)) < MAXDNAME)) {
			pchr = &tchr[tlen-1];
			while ((pchr != tchr) && (*pchr == '.'))
				pchr--;
			*(++pchr) = '\0';
			storelist[cnt] = strdup(tchr);
			cnt++;
		}
	}
	scf_simple_prop_free(sprop);
}
Ejemplo n.º 3
0
static PyObject *
pyscf_get_string(PyObject *o, PyObject *args, PyObject *kwargs)
{
	static char *kwlist[] = { "name", NULL };
	scf_simple_prop_t *prop;
	PyObject *obj;
	char *name;
	char *str;

	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 ((str = scf_simple_prop_next_astring(prop)) == NULL) {
		scf_simple_prop_free(prop);
		return (scf_exception("scf_simple_prop_next_astring() failed",
		    name));
	}

	obj = PyString_FromString(str);
	scf_simple_prop_free(prop);
	return (obj);
}
Ejemplo n.º 4
0
static char *
mdb_scf_console_term(void)
{
	scf_simple_prop_t *prop;
	char *term = NULL;

	if ((prop = scf_simple_prop_get(NULL,
	    "svc:/system/console-login:default", "ttymon",
	    "terminal_type")) == NULL)
		return (NULL);

	if (scf_simple_prop_type(prop) == SCF_TYPE_ASTRING &&
	    (term = scf_simple_prop_next_astring(prop)) != NULL)
		term = strdup(term);

	scf_simple_prop_free(prop);
	return (term);
}
Ejemplo n.º 5
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());
}
Ejemplo n.º 6
0
/*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);
}