Ejemplo n.º 1
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);
}
Ejemplo n.º 2
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.º 3
0
static int
sig_auditd(int sig)
{
	scf_simple_prop_t *prop = NULL;
	uint64_t	*cid = NULL;

	if ((prop = scf_simple_prop_get(NULL, AUDITD_FMRI, SCF_PG_RESTARTER,
	    SCF_PROPERTY_CONTRACT)) == NULL) {
		display_smf_error();
		return (1);
	}
	if ((scf_simple_prop_numvalues(prop) < 0) ||
	    (cid = scf_simple_prop_next_count(prop)) == NULL) {
		scf_simple_prop_free(prop);
		display_smf_error();
		return (1);
	}
	if (sigsend(P_CTID, (ctid_t)*cid, sig) != 0) {
		perror("audit: can't signal auditd");
		scf_simple_prop_free(prop);
		return (1);
	}
	scf_simple_prop_free(prop);
	return (0);
}
Ejemplo n.º 4
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);
	}
}
Ejemplo n.º 5
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.º 6
0
static PyObject *
pyscf_get_int(PyObject *o, PyObject *args, PyObject *kwargs)
{
	static char *kwlist[] = { "name", NULL };
	scf_simple_prop_t *prop;
	PyObject *obj;
	int64_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_integer(prop)) == NULL)
		return (scf_exception("scf_simple_prop_next_integer() failed",
		    name));

	obj = PyInt_FromLong((long)*val);
	scf_simple_prop_free(prop);
	return (obj);
}
Ejemplo n.º 7
0
static void
_nss_mdns_get_svcstatetimestamp(struct timeval *ptv)
{
	scf_handle_t *h;
	scf_simple_prop_t *sprop;
	int32_t nsec;

	(void) memset(ptv, 0, sizeof (struct timeval));

	h = scf_handle_create(SCF_VERSION);
	if (h == NULL)
		return;

	if (scf_handle_bind(h) == -1) {
		scf_handle_destroy(h);
		return;
	}

	if ((sprop = scf_simple_prop_get(h, SMF_MDNS_FMRI,
	    SCF_PG_RESTARTER, SCF_PROPERTY_STATE_TIMESTAMP)) != NULL) {
		ptv->tv_sec = *(time_t *)(scf_simple_prop_next_time(sprop,
		    &nsec));
		ptv->tv_usec = nsec / 1000;
		scf_simple_prop_free(sprop);
	}

	if (h != NULL)
		scf_handle_destroy(h);
}
Ejemplo n.º 8
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.º 9
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);
}
Ejemplo n.º 10
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);
}
Ejemplo n.º 11
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.º 12
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);
}
Ejemplo n.º 13
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);
}
Ejemplo n.º 14
0
void
wait_till_to(char *fmri)
{
	char *state;
	useconds_t max;
	useconds_t usecs;
	uint64_t *cp = NULL;
	scf_simple_prop_t *sp = NULL;

	max = DEFAULT_TIMEOUT;

	if (((sp = scf_simple_prop_get(NULL, fmri, "stop",
	    SCF_PROPERTY_TIMEOUT)) != NULL) &&
	    ((cp = scf_simple_prop_next_count(sp)) != NULL) && (*cp != 0))
		max = (*cp) * 1000000;	/* convert to usecs */

	if (sp != NULL)
		scf_simple_prop_free(sp);

	for (usecs = INIT_WAIT_USECS; max > 0; max -= usecs) {
		/* incremental wait */
		usecs *= 2;
		usecs = (usecs > max) ? max : usecs;

		(void) usleep(usecs);

		/* Check state after the wait */
		if ((state = smf_get_state(fmri)) != NULL) {
			if (strcmp(state, "disabled") == 0)
				return;
		}
	}

	(void) fprintf(stderr, gettext("Warning: delete %s timed out.\n"),
	    fmri);
}
Ejemplo n.º 15
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);
}
Ejemplo n.º 16
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.º 17
0
/* ARGSUSED0 */
static int
list_props_cb(void *data, scf_walkinfo_t *wip)
{
	int			i;
	const char		*instname = wip->fmri;
	scf_simple_prop_t	*prop;
	inetd_prop_t		*proplist;
	const char		*restart_str;
	boolean_t		is_rpc = B_FALSE;
	size_t			numprops;
	scf_handle_t		*h;
	scf_error_t		err;

	if (((h = scf_handle_create(SCF_VERSION)) == NULL) ||
	    (scf_handle_bind(h) == -1))
		scfdie();

	/*
	 * Get the property that holds the name of this instance's
	 * restarter, and make sure that it is inetd.
	 */
	if ((prop = scf_simple_prop_get(h, instname, SCF_PG_GENERAL,
	    SCF_PROPERTY_RESTARTER)) == NULL) {
		if (scf_error() == SCF_ERROR_NOT_FOUND)
			uu_die(gettext("Error: Specified service instance "
			    "\"%s\" has no restarter property.  inetd is not "
			    "the delegated restarter of this instance.\n"),
			    instname);
		if (scf_error() == SCF_ERROR_INVALID_ARGUMENT)
			uu_die(gettext("Error: \"%s\" is not a valid service "
			    "instance.\n"), instname);

		scfdie();
	}

	if (((restart_str = scf_simple_prop_next_ustring(prop)) == NULL) ||
	    (strstr(restart_str, INETADM_INETD_STR) == NULL)) {
		uu_die(gettext("Error: inetd is not the delegated restarter of "
		    "specified service instance \"%s\".\n"), instname);
	}

	scf_simple_prop_free(prop);

	/*
	 * This instance is controlled by inetd, so now we display all
	 * of its properties.  First the mandatory properties, and then
	 * the properties that have default values, substituting the
	 * default values inherited from inetd as necessary (this is done
	 * for us by read_instance_props()).
	 */

	if ((proplist = read_instance_props(h, instname, &numprops, &err)) ==
	    NULL) {
		uu_die(gettext("Unexpected libscf error: %s.  Exiting.\n"),
		    scf_strerror(err));
	}
	scf_handle_destroy(h);

	(void) printf("%-9s%s\n", "SCOPE", "NAME=VALUE");

	for (i = 0; i < numprops; i++) {
		/* Skip rpc version properties if it's not an RPC service */
		if ((strcmp(PR_RPC_LW_VER_NAME, proplist[i].ip_name) == 0) ||
		    (strcmp(PR_RPC_HI_VER_NAME, proplist[i].ip_name) == 0))
			if (!is_rpc)
				continue;

		/* If it's not an unset property, print it out. */
		if (proplist[i].ip_error != IVE_UNSET) {
			if (strcmp(PR_ISRPC_NAME, proplist[i].ip_name) == 0)
				is_rpc = proplist[i].ip_value.iv_boolean;

			(void) printf("%-9s%s=",
			    proplist[i].from_inetd ? INETADM_DEFAULT_STR : "",
			    proplist[i].ip_name);
			print_prop_val(&proplist[i]);
			continue;
		}

		/* arg0 is non-default, but also doesn't have to be set. */

		if (i == PT_ARG0_INDEX)
			continue;

		/* all other properties should have values. */
		if (proplist[i].ip_default) {
			(void) uu_warn(gettext("Error: Property %s is missing "
			    "and has no defined default value.\n"),
			    proplist[i].ip_name);
		} else {
			(void) uu_warn(gettext("Error: Required property %s is "
			    "missing.\n"), proplist[i].ip_name);
		}
	}

	free_instance_props(proplist);
	return (0);
}