d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck * CDDL HEADER START
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck * The contents of this file are subject to the terms of the
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck * Common Development and Distribution License (the "License").
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck * You may not use this file except in compliance with the License.
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck * See the License for the specific language governing permissions
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck * and limitations under the License.
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck * When distributing Covered Code, include this CDDL HEADER in each
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck * If applicable, add the following below this CDDL HEADER, with the
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck * fields enclosed by brackets "[]" replaced with your own identifying
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck * information: Portions Copyright [yyyy] [name of copyright owner]
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck * CDDL HEADER END
f6da83d4178694e7113b71d1e452f15b296f73d8Anurag S. Maskey * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * util.c contains a set of miscellaneous utility functions which,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * among other things:
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck * - start a child process
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck * - look up the zone name
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * - look up/set SMF properties
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeckextern char **environ;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * A holder for all the resources needed to get a property value
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * using libscf.
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeystatic pthread_mutex_t uid_mutex = PTHREAD_MUTEX_INITIALIZER;
38f140aaa4a32508dc5318744dd8d51ab84b23a5Michael Hunter priv_set = priv_str_to_set("zone", ",", NULL);
38f140aaa4a32508dc5318744dd8d51ab84b23a5Michael Hunter pfail("creating privilege set: %s", strerror(errno));
38f140aaa4a32508dc5318744dd8d51ab84b23a5Michael Hunter if (setppriv(PRIV_SET, PRIV_EFFECTIVE, priv_set) == -1) {
38f140aaa4a32508dc5318744dd8d51ab84b23a5Michael Hunter pfail("setppriv effective: %s", strerror(errno));
38f140aaa4a32508dc5318744dd8d51ab84b23a5Michael Hunter /* build up our minimal set of privs. */
38f140aaa4a32508dc5318744dd8d51ab84b23a5Michael Hunter priv_set = priv_str_to_set("basic", ",", NULL);
38f140aaa4a32508dc5318744dd8d51ab84b23a5Michael Hunter allpriv_set = priv_str_to_set("zone", ",", NULL);
38f140aaa4a32508dc5318744dd8d51ab84b23a5Michael Hunter pfail("converting privilege sets: %s", strerror(errno));
38f140aaa4a32508dc5318744dd8d51ab84b23a5Michael Hunter (void) priv_addset(priv_set, PRIV_FILE_CHOWN_SELF);
38f140aaa4a32508dc5318744dd8d51ab84b23a5Michael Hunter (void) priv_addset(priv_set, PRIV_FILE_DAC_READ);
38f140aaa4a32508dc5318744dd8d51ab84b23a5Michael Hunter (void) priv_addset(priv_set, PRIV_FILE_DAC_WRITE);
38f140aaa4a32508dc5318744dd8d51ab84b23a5Michael Hunter (void) priv_addset(priv_set, PRIV_NET_RAWACCESS);
38f140aaa4a32508dc5318744dd8d51ab84b23a5Michael Hunter (void) priv_addset(priv_set, PRIV_NET_PRIVADDR);
38f140aaa4a32508dc5318744dd8d51ab84b23a5Michael Hunter (void) priv_addset(priv_set, PRIV_PROC_AUDIT);
38f140aaa4a32508dc5318744dd8d51ab84b23a5Michael Hunter (void) priv_addset(priv_set, PRIV_PROC_OWNER);
38f140aaa4a32508dc5318744dd8d51ab84b23a5Michael Hunter (void) priv_addset(priv_set, PRIV_PROC_SETID);
38f140aaa4a32508dc5318744dd8d51ab84b23a5Michael Hunter (void) priv_addset(priv_set, PRIV_SYS_CONFIG);
38f140aaa4a32508dc5318744dd8d51ab84b23a5Michael Hunter (void) priv_addset(priv_set, PRIV_SYS_IP_CONFIG);
38f140aaa4a32508dc5318744dd8d51ab84b23a5Michael Hunter (void) priv_addset(priv_set, PRIV_SYS_IPC_CONFIG);
38f140aaa4a32508dc5318744dd8d51ab84b23a5Michael Hunter (void) priv_addset(priv_set, PRIV_SYS_MOUNT);
38f140aaa4a32508dc5318744dd8d51ab84b23a5Michael Hunter (void) priv_addset(priv_set, PRIV_SYS_NET_CONFIG);
38f140aaa4a32508dc5318744dd8d51ab84b23a5Michael Hunter (void) priv_addset(priv_set, PRIV_SYS_RES_CONFIG);
38f140aaa4a32508dc5318744dd8d51ab84b23a5Michael Hunter (void) priv_addset(priv_set, PRIV_SYS_RESOURCE);
38f140aaa4a32508dc5318744dd8d51ab84b23a5Michael Hunter * Since our zone might not have all these privs,
38f140aaa4a32508dc5318744dd8d51ab84b23a5Michael Hunter * just ask for those that are available.
38f140aaa4a32508dc5318744dd8d51ab84b23a5Michael Hunter if (setppriv(PRIV_SET, PRIV_INHERITABLE, priv_set) == -1) {
38f140aaa4a32508dc5318744dd8d51ab84b23a5Michael Hunter pfail("setppriv inheritable: %s", strerror(errno));
38f140aaa4a32508dc5318744dd8d51ab84b23a5Michael Hunter * Need to ensure permitted set contains all privs so we can
38f140aaa4a32508dc5318744dd8d51ab84b23a5Michael Hunter * escalate later.
38f140aaa4a32508dc5318744dd8d51ab84b23a5Michael Hunter if (setppriv(PRIV_SET, PRIV_PERMITTED, allpriv_set) == -1) {
38f140aaa4a32508dc5318744dd8d51ab84b23a5Michael Hunter pfail("setppriv permitted: %s", strerror(errno));
38f140aaa4a32508dc5318744dd8d51ab84b23a5Michael Hunter * We need to find a smaller set of privs that are important to
38f140aaa4a32508dc5318744dd8d51ab84b23a5Michael Hunter * us. Otherwise we really are not gaining much by doing this.
38f140aaa4a32508dc5318744dd8d51ab84b23a5Michael Hunter if (setppriv(PRIV_SET, PRIV_EFFECTIVE, priv_set) == -1) {
38f140aaa4a32508dc5318744dd8d51ab84b23a5Michael Hunter pfail("setppriv effective: %s", strerror(errno));
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck * This starts a child process determined by command. If command contains a
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck * slash then it is assumed to be a full path; otherwise the path is searched
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck * for an executable file with the name command. Command is also used as
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck * argv[0] of the new process. The rest of the arguments of the function
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck * up to the first NULL make up pointers to arguments of the new process.
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck * This function returns child exit status on success and -1 on failure.
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck * NOTE: original_sigmask must be set before this function is called.
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeynwamd_start_childv(const char *command, char const * const *argv)
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck n = sizeof (vbuf);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nlog(LOG_ERR, "nwamd_start_childv can't log full arg vector");
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nlog(LOG_DEBUG, "posix_spawnattr_init %d %s\n",
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck return (-1);
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck if ((rc = posix_spawnattr_setsigdefault(&attr, &fullset)) != 0) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nlog(LOG_DEBUG, "setsigdefault %d %s\n", rc, strerror(rc));
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck return (-1);
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck if ((rc = posix_spawnattr_setsigmask(&attr, &original_sigmask)) != 0) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nlog(LOG_DEBUG, "setsigmask %d %s\n", rc, strerror(rc));
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck return (-1);
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck POSIX_SPAWN_SETSIGDEF|POSIX_SPAWN_SETSIGMASK)) != 0) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nlog(LOG_DEBUG, "setflags %d %s\n", rc, strerror(rc));
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck return (-1);
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck if ((rc = posix_spawnp(&pid, command, NULL, &attr, (char * const *)argv,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nlog(LOG_DEBUG, "posix_spawnp failed errno %d", rc);
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck return (-1);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nlog(LOG_DEBUG, "posix_spawn_attr_destroy %d %s\n",
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck return (-1);
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck i = WIFSIGNALED(status) ? WTERMSIG(status) : WSTOPSIG(status);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nlog(LOG_ERR, "'%s%s' %s with signal %d (%s)", command, vbuf,
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck return (-2);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nlog(LOG_INFO, "'%s%s' completed normally: %d", command, vbuf,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * For global zone, check if the link is used by a non-global
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * zone, note that the non-global zones doesn't need this check,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * because zoneadm has taken care of this when the zone boots.
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * In the global zone, we ignore events for local-zone-owned links
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * since these are taken care of by the local zone's network
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * configuration services.
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeynwamd_link_belongs_to_this_zone(const char *linkname)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if ((status = dladm_name2info(dld_handle, linkname, &linkid,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nlog(LOG_DEBUG, "nwamd_link_belongs_to_this_zone: "
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey "could not get linkid for %s: %s",
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey linkname, dladm_status2str(status, errstr));
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey ret = zone_check_datalink(&zoneid, linkid);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey (void) getzonenamebyid(zoneid, zonename, ZONENAME_MAX);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nlog(LOG_DEBUG, "nwamd_link_belongs_to_this_zone: "
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey "%s is used by non-global zone: %s",
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * res is a pointer to the scf_resources_t to be released.
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * fmri is the instance to look up
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * res is a pointer to an scf_resources_t. This is an internal
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * structure that holds all the handles needed to get a specific
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * property from the running snapshot; on a successful return it
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * contains the scf_value_t that should be passed to the desired
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * scf_value_get_foo() function, and must be freed after use by
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * calling release_scf_resources(). On a failure return, any
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * resources that may have been assigned to res are released, so
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * the caller does not need to do any cleanup in the failure case.
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * 0 on success
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * -1 on failure
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeycreate_scf_resources(const char *fmri, scf_resources_t *res)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if ((res->sr_handle = scf_handle_create(SCF_VERSION)) == NULL) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (scf_handle_bind(res->sr_handle) != 0) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if ((res->sr_inst = scf_instance_create(res->sr_handle)) == NULL) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (scf_handle_decode_fmri(res->sr_handle, fmri, NULL, NULL,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey res->sr_inst, NULL, NULL, SCF_DECODE_FMRI_REQUIRE_INSTANCE) != 0) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if ((res->sr_snap = scf_snapshot_create(res->sr_handle)) == NULL) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (scf_instance_get_snapshot(res->sr_inst, "running",
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if ((res->sr_pg = scf_pg_create(res->sr_handle)) == NULL) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if ((res->sr_prop = scf_property_create(res->sr_handle)) == NULL) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if ((res->sr_val = scf_value_create(res->sr_handle)) == NULL) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if ((res->sr_tx = scf_transaction_create(res->sr_handle)) == NULL) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if ((res->sr_ent = scf_entry_create(res->sr_handle)) == NULL) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nlog(LOG_ERR, "create_scf_resources failed: %s",
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * fmri is the instance to look up
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * pg is the property group to look up
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * prop is the property within that group to look up
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * running specifies if running snapshot is to be used
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * res is a pointer to an scf_resources_t. This is an internal
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * structure that holds all the handles needed to get a specific
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * property from the running snapshot; on a successful return it
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * contains the scf_value_t that should be passed to the desired
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * scf_value_get_foo() function, and must be freed after use by
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * calling release_scf_resources(). On a failure return, any
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * resources that may have been assigned to res are released, so
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * the caller does not need to do any cleanup in the failure case.
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * 0 on success
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * -1 on failure
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeyget_property_value(const char *fmri, const char *pg, const char *prop,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (scf_instance_get_pg_composed(res->sr_inst,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey running ? res->sr_snap : NULL, pg, res->sr_pg) != 0) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (scf_pg_get_property(res->sr_pg, prop, res->sr_prop) != 0) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (scf_property_get_value(res->sr_prop, res->sr_val) != 0) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * lfmri is the instance fmri to look up
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * lpg is the property group to look up
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * lprop is the property within that group to look up
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * answer is a pointer to the property value
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * 0 on success
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * -1 on failure
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * If successful, the property value is retured in *answer.
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * Otherwise, *answer is undefined, and it is up to the caller to decide
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * how to handle that case.
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeynwamd_lookup_boolean_property(const char *lfmri, const char *lpg,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (get_property_value(lfmri, lpg, lprop, B_TRUE, &res) != 0) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * an error was already logged by get_property_value,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * and it released any resources assigned to res before
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (scf_value_get_boolean(res.sr_val, &prop_val) != 0) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * lfmri is the instance fmri to look up
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * lpg is the property group to look up
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * lprop is the property within that group to look up
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * buf is the place to put the answer
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * bufsz is the size of buf
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * 0 on success
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * -1 on failure
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * If successful, the property value is retured in buf.
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * Otherwise, buf is undefined, and it is up to the caller to decide
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * how to handle that case.
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeynwamd_lookup_string_property(const char *lfmri, const char *lpg,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey const char *lprop, char *buf, size_t bufsz)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (get_property_value(lfmri, lpg, lprop, B_TRUE, &res) != 0) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * The above function fails when trying to get a
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * non-persistent property group from the running snapshot.
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * Try going for the non-running snapshot.
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (get_property_value(lfmri, lpg, lprop, B_FALSE, &res) != 0) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * an error was already logged by get_property_value,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * and it released any resources assigned to res before
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (scf_value_get_astring(res.sr_val, buf, bufsz) == 0)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * lfmri is the instance fmri to look up
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * lpg is the property group to look up
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * lprop is the property within that group to look up
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * answer is a pointer to the property value
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * 0 on success
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * -1 on failure
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * If successful, the property value is retured in *answer.
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * Otherwise, *answer is undefined, and it is up to the caller to decide
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * how to handle that case.
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeynwamd_lookup_count_property(const char *lfmri, const char *lpg,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (get_property_value(lfmri, lpg, lprop, B_TRUE, &res) != 0) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * an error was already logged by get_property_value,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * and it released any resources assigned to res before
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (scf_value_get_count(res.sr_val, answer) != 0) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeyset_property_value(scf_resources_t *res, const char *propname,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey new = (scf_pg_get_property(res->sr_pg, propname, res->sr_prop) != 0);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (scf_transaction_start(res->sr_tx, res->sr_pg) == -1) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (scf_transaction_property_new(res->sr_tx, res->sr_ent,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (scf_transaction_property_change(res->sr_tx, res->sr_ent,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (scf_entry_add_value(res->sr_ent, res->sr_val) != 0) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey result = scf_transaction_commit(res->sr_tx);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nlog(LOG_INFO, "set_property_value: transaction commit failed "
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeynwamd_set_count_property(const char *fmri, const char *pg, const char *prop,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (scf_instance_add_pg(res.sr_inst, pg, SCF_GROUP_APPLICATION,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey SCF_PG_FLAG_NONPERSISTENT, res.sr_pg) != 0) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (scf_instance_get_pg_composed(res.sr_inst, NULL, pg,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey scf_value_set_count(res.sr_val, (uint64_t)count);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (set_property_value(&res, prop, SCF_TYPE_COUNT) != 0)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nlog(LOG_INFO, "nwamd_set_count_property: scf failure %s while "
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey "setting %s", scf_strerror(scf_error()), prop);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeynwamd_set_string_property(const char *fmri, const char *pg, const char *prop,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (scf_instance_add_pg(res.sr_inst, pg, SCF_GROUP_APPLICATION,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey SCF_PG_FLAG_NONPERSISTENT, res.sr_pg) != 0) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (scf_instance_get_pg_composed(res.sr_inst, NULL, pg,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (scf_value_set_astring(res.sr_val, str) != 0)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (set_property_value(&res, prop, SCF_TYPE_ASTRING) != 0)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nlog(LOG_INFO, "nwamd_set_string_property: scf failure %s while "
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey "setting %s", scf_strerror(scf_error()), prop);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * Deletes property prop from property group pg in SMF instance fmri.
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * Returns 0 on success, -1 on failure.
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeynwamd_delete_scf_property(const char *fmri, const char *pg, const char *prop)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (scf_instance_add_pg(res.sr_inst, pg, SCF_GROUP_APPLICATION,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey SCF_PG_FLAG_NONPERSISTENT, res.sr_pg) != 0) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (scf_instance_get_pg_composed(res.sr_inst, NULL, pg,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (scf_pg_get_property(res.sr_pg, prop, res.sr_prop) != 0)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (scf_transaction_start(res.sr_tx, res.sr_pg) == -1)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (scf_transaction_property_delete(res.sr_tx, res.sr_ent, prop) == -1)