d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck/*
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck * CDDL HEADER START
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck *
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 *
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck * or http://www.opensolaris.org/os/licensing.
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck * See the License for the specific language governing permissions
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck * and limitations under the License.
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck *
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 *
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck * CDDL HEADER END
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck */
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck/*
f6da83d4178694e7113b71d1e452f15b296f73d8Anurag S. Maskey * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck */
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck/*
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
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * - drop/escalate privs
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck */
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey#include <assert.h>
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey#include <errno.h>
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey#include <libdllink.h>
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey#include <limits.h>
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey#include <libscf.h>
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey#include <net/if.h>
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey#include <pthread.h>
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey#include <pwd.h>
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey#include <spawn.h>
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck#include <stdarg.h>
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck#include <stdio.h>
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck#include <stdlib.h>
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck#include <string.h>
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey#include <strings.h>
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck#include <stropts.h>
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck#include <sys/socket.h>
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey#include <sys/sockio.h>
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey#include <sys/types.h>
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey#include <unistd.h>
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck#include <wait.h>
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck#include <zone.h>
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey#include "util.h"
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey#include "llp.h"
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeckextern char **environ;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeyextern sigset_t original_sigmask;
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey/*
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * A holder for all the resources needed to get a property value
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * using libscf.
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey */
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeytypedef struct scf_resources {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey scf_handle_t *sr_handle;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey scf_instance_t *sr_inst;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey scf_snapshot_t *sr_snap;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey scf_propertygroup_t *sr_pg;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey scf_property_t *sr_prop;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey scf_value_t *sr_val;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey scf_transaction_t *sr_tx;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey scf_transaction_entry_t *sr_ent;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey} scf_resources_t;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeystatic pthread_mutex_t uid_mutex = PTHREAD_MUTEX_INITIALIZER;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeystatic uid_t uid;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeystatic int uid_cnt;
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeyvoid
38f140aaa4a32508dc5318744dd8d51ab84b23a5Michael Hunternwamd_escalate(void) {
38f140aaa4a32508dc5318744dd8d51ab84b23a5Michael Hunter priv_set_t *priv_set;
38f140aaa4a32508dc5318744dd8d51ab84b23a5Michael Hunter priv_set = priv_str_to_set("zone", ",", NULL);
38f140aaa4a32508dc5318744dd8d51ab84b23a5Michael Hunter
38f140aaa4a32508dc5318744dd8d51ab84b23a5Michael Hunter if (priv_set == NULL)
38f140aaa4a32508dc5318744dd8d51ab84b23a5Michael Hunter pfail("creating privilege set: %s", strerror(errno));
38f140aaa4a32508dc5318744dd8d51ab84b23a5Michael Hunter
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey (void) pthread_mutex_lock(&uid_mutex);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (uid == 0)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey uid = getuid();
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (uid_cnt++ == 0) {
38f140aaa4a32508dc5318744dd8d51ab84b23a5Michael Hunter if (setppriv(PRIV_SET, PRIV_EFFECTIVE, priv_set) == -1) {
38f140aaa4a32508dc5318744dd8d51ab84b23a5Michael Hunter priv_freeset(priv_set);
38f140aaa4a32508dc5318744dd8d51ab84b23a5Michael Hunter pfail("setppriv effective: %s", strerror(errno));
38f140aaa4a32508dc5318744dd8d51ab84b23a5Michael Hunter }
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck }
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey (void) pthread_mutex_unlock(&uid_mutex);
38f140aaa4a32508dc5318744dd8d51ab84b23a5Michael Hunter
38f140aaa4a32508dc5318744dd8d51ab84b23a5Michael Hunter priv_freeset(priv_set);
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck}
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck
b00044a2eb43864b8718585d21949611a2ee59efJames Carlsonvoid
38f140aaa4a32508dc5318744dd8d51ab84b23a5Michael Hunternwamd_deescalate(void) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey (void) pthread_mutex_lock(&uid_mutex);
3773ed2d24481549fc50fa942cc59d7ba81c6e71Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey assert(uid_cnt > 0);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (--uid_cnt == 0) {
3773ed2d24481549fc50fa942cc59d7ba81c6e71Anurag S. Maskey priv_set_t *priv_set, *allpriv_set;
3773ed2d24481549fc50fa942cc59d7ba81c6e71Anurag S. Maskey
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 if (priv_set == NULL || allpriv_set == NULL)
38f140aaa4a32508dc5318744dd8d51ab84b23a5Michael Hunter pfail("converting privilege sets: %s", strerror(errno));
38f140aaa4a32508dc5318744dd8d51ab84b23a5Michael Hunter
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
38f140aaa4a32508dc5318744dd8d51ab84b23a5Michael Hunter /*
38f140aaa4a32508dc5318744dd8d51ab84b23a5Michael Hunter * Since our zone might not have all these privs,
38f140aaa4a32508dc5318744dd8d51ab84b23a5Michael Hunter * just ask for those that are available.
38f140aaa4a32508dc5318744dd8d51ab84b23a5Michael Hunter */
38f140aaa4a32508dc5318744dd8d51ab84b23a5Michael Hunter priv_intersect(allpriv_set, priv_set);
38f140aaa4a32508dc5318744dd8d51ab84b23a5Michael Hunter
38f140aaa4a32508dc5318744dd8d51ab84b23a5Michael Hunter if (setppriv(PRIV_SET, PRIV_INHERITABLE, priv_set) == -1) {
38f140aaa4a32508dc5318744dd8d51ab84b23a5Michael Hunter priv_freeset(allpriv_set);
38f140aaa4a32508dc5318744dd8d51ab84b23a5Michael Hunter priv_freeset(priv_set);
38f140aaa4a32508dc5318744dd8d51ab84b23a5Michael Hunter pfail("setppriv inheritable: %s", strerror(errno));
38f140aaa4a32508dc5318744dd8d51ab84b23a5Michael Hunter }
38f140aaa4a32508dc5318744dd8d51ab84b23a5Michael Hunter /*
38f140aaa4a32508dc5318744dd8d51ab84b23a5Michael Hunter * Need to ensure permitted set contains all privs so we can
38f140aaa4a32508dc5318744dd8d51ab84b23a5Michael Hunter * escalate later.
38f140aaa4a32508dc5318744dd8d51ab84b23a5Michael Hunter */
38f140aaa4a32508dc5318744dd8d51ab84b23a5Michael Hunter if (setppriv(PRIV_SET, PRIV_PERMITTED, allpriv_set) == -1) {
38f140aaa4a32508dc5318744dd8d51ab84b23a5Michael Hunter priv_freeset(allpriv_set);
38f140aaa4a32508dc5318744dd8d51ab84b23a5Michael Hunter priv_freeset(priv_set);
38f140aaa4a32508dc5318744dd8d51ab84b23a5Michael Hunter pfail("setppriv permitted: %s", strerror(errno));
38f140aaa4a32508dc5318744dd8d51ab84b23a5Michael Hunter }
38f140aaa4a32508dc5318744dd8d51ab84b23a5Michael Hunter /*
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 */
38f140aaa4a32508dc5318744dd8d51ab84b23a5Michael Hunter if (setppriv(PRIV_SET, PRIV_EFFECTIVE, priv_set) == -1) {
38f140aaa4a32508dc5318744dd8d51ab84b23a5Michael Hunter priv_freeset(allpriv_set);
38f140aaa4a32508dc5318744dd8d51ab84b23a5Michael Hunter priv_freeset(priv_set);
38f140aaa4a32508dc5318744dd8d51ab84b23a5Michael Hunter pfail("setppriv effective: %s", strerror(errno));
38f140aaa4a32508dc5318744dd8d51ab84b23a5Michael Hunter }
3773ed2d24481549fc50fa942cc59d7ba81c6e71Anurag S. Maskey
3773ed2d24481549fc50fa942cc59d7ba81c6e71Anurag S. Maskey priv_freeset(priv_set);
3773ed2d24481549fc50fa942cc59d7ba81c6e71Anurag S. Maskey priv_freeset(allpriv_set);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey }
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey (void) pthread_mutex_unlock(&uid_mutex);
b00044a2eb43864b8718585d21949611a2ee59efJames Carlson}
b00044a2eb43864b8718585d21949611a2ee59efJames Carlson
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck/*
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck *
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 *
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck * This function returns child exit status on success and -1 on failure.
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck *
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck * NOTE: original_sigmask must be set before this function is called.
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck */
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeckint
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeynwamd_start_childv(const char *command, char const * const *argv)
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck{
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck posix_spawnattr_t attr;
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck sigset_t fullset;
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck int i, rc, status, n;
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck pid_t pid;
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck char vbuf[1024];
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck vbuf[0] = 0;
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck n = sizeof (vbuf);
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck for (i = 1; argv[i] != NULL && n > 2; i++) {
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck n -= strlcat(vbuf, " ", n);
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck n -= strlcat(vbuf, argv[i], n);
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck }
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck if (argv[i] != NULL || n < 0)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nlog(LOG_ERR, "nwamd_start_childv can't log full arg vector");
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck if ((rc = posix_spawnattr_init(&attr)) != 0) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nlog(LOG_DEBUG, "posix_spawnattr_init %d %s\n",
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey rc, strerror(rc));
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck return (-1);
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck }
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck (void) sigfillset(&fullset);
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 }
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 }
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck if ((rc = posix_spawnattr_setflags(&attr,
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 }
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck if ((rc = posix_spawnp(&pid, command, NULL, &attr, (char * const *)argv,
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck environ)) > 0) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nlog(LOG_DEBUG, "posix_spawnp failed errno %d", rc);
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck return (-1);
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck }
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck if ((rc = posix_spawnattr_destroy(&attr)) != 0) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nlog(LOG_DEBUG, "posix_spawn_attr_destroy %d %s\n",
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey rc, strerror(rc));
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck return (-1);
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck }
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck (void) waitpid(pid, &status, 0);
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck if (WIFSIGNALED(status) || WIFSTOPPED(status)) {
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck i = WIFSIGNALED(status) ? WTERMSIG(status) : WSTOPSIG(status);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nlog(LOG_ERR, "'%s%s' %s with signal %d (%s)", command, vbuf,
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck (WIFSIGNALED(status) ? "terminated" : "stopped"), i,
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck strsignal(i));
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck return (-2);
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck } else {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nlog(LOG_INFO, "'%s%s' completed normally: %d", command, vbuf,
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck WEXITSTATUS(status));
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck return (WEXITSTATUS(status));
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck }
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck}
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey/*
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. Maskey */
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeyboolean_t
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeynwamd_link_belongs_to_this_zone(const char *linkname)
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck{
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey zoneid_t zoneid;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey char zonename[ZONENAME_MAX];
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey int ret;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey zoneid = getzoneid();
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (zoneid == GLOBAL_ZONEID) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey datalink_id_t linkid;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey dladm_status_t status;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey char errstr[DLADM_STRSIZE];
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if ((status = dladm_name2info(dld_handle, linkname, &linkid,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey NULL, NULL, NULL)) != DLADM_STATUS_OK) {
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 return (B_FALSE);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey }
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey zoneid = ALL_ZONES;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey ret = zone_check_datalink(&zoneid, linkid);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (ret == 0) {
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 linkname, zonename);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey return (B_FALSE);
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck }
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey }
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey return (B_TRUE);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey}
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey/*
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * Inputs:
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * res is a pointer to the scf_resources_t to be released.
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey */
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeystatic void
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeyrelease_scf_resources(scf_resources_t *res)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey{
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey scf_entry_destroy(res->sr_ent);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey scf_transaction_destroy(res->sr_tx);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey scf_value_destroy(res->sr_val);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey scf_property_destroy(res->sr_prop);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey scf_pg_destroy(res->sr_pg);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey scf_snapshot_destroy(res->sr_snap);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey scf_instance_destroy(res->sr_inst);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey (void) scf_handle_unbind(res->sr_handle);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey scf_handle_destroy(res->sr_handle);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey}
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck/*
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * Inputs:
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * fmri is the instance to look up
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * Outputs:
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 * Returns:
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * 0 on success
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * -1 on failure
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck */
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeystatic int
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeycreate_scf_resources(const char *fmri, scf_resources_t *res)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey{
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey res->sr_tx = NULL;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey res->sr_ent = NULL;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey res->sr_inst = NULL;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey res->sr_snap = NULL;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey res->sr_pg = NULL;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey res->sr_prop = NULL;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey res->sr_val = NULL;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if ((res->sr_handle = scf_handle_create(SCF_VERSION)) == NULL) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey return (-1);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey }
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (scf_handle_bind(res->sr_handle) != 0) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey scf_handle_destroy(res->sr_handle);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey return (-1);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey }
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if ((res->sr_inst = scf_instance_create(res->sr_handle)) == NULL) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey goto failure;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey }
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 goto failure;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey }
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if ((res->sr_snap = scf_snapshot_create(res->sr_handle)) == NULL) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey goto failure;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey }
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (scf_instance_get_snapshot(res->sr_inst, "running",
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey res->sr_snap) != 0) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey goto failure;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey }
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if ((res->sr_pg = scf_pg_create(res->sr_handle)) == NULL) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey goto failure;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey }
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if ((res->sr_prop = scf_property_create(res->sr_handle)) == NULL) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey goto failure;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey }
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if ((res->sr_val = scf_value_create(res->sr_handle)) == NULL) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey goto failure;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey }
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if ((res->sr_tx = scf_transaction_create(res->sr_handle)) == NULL) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey goto failure;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey }
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if ((res->sr_ent = scf_entry_create(res->sr_handle)) == NULL) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey goto failure;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey }
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey return (0);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeyfailure:
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nlog(LOG_ERR, "create_scf_resources failed: %s",
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey scf_strerror(scf_error()));
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey release_scf_resources(res);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey return (-1);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey}
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey/*
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * Inputs:
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 * Outputs:
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 * Returns:
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * 0 on success
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * -1 on failure
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey */
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeystatic int
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeyget_property_value(const char *fmri, const char *pg, const char *prop,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey boolean_t running, scf_resources_t *res)
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck{
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (create_scf_resources(fmri, res) != 0)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey return (-1);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
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 goto failure;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey }
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (scf_pg_get_property(res->sr_pg, prop, res->sr_prop) != 0) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey goto failure;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey }
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (scf_property_get_value(res->sr_prop, res->sr_val) != 0) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey goto failure;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey }
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey return (0);
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeyfailure:
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey release_scf_resources(res);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey return (-1);
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck}
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey/*
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * Inputs:
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 * Outputs:
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * answer is a pointer to the property value
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * Returns:
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. Maskey */
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeyint
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeynwamd_lookup_boolean_property(const char *lfmri, const char *lpg,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey const char *lprop, boolean_t *answer)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey{
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey int result = -1;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey scf_resources_t res;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey uint8_t prop_val;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (get_property_value(lfmri, lpg, lprop, B_TRUE, &res) != 0) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey /*
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 * returning.
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey */
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey return (result);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey }
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (scf_value_get_boolean(res.sr_val, &prop_val) != 0) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey goto cleanup;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey }
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey *answer = (boolean_t)prop_val;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey result = 0;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeycleanup:
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey release_scf_resources(&res);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey return (result);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey}
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey/*
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * Inputs:
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 * Outputs:
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey *
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * Returns:
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. Maskey */
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeyint
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeynwamd_lookup_string_property(const char *lfmri, const char *lpg,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey const char *lprop, char *buf, size_t bufsz)
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck{
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey int result = -1;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey scf_resources_t res;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (get_property_value(lfmri, lpg, lprop, B_TRUE, &res) != 0) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey /*
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 */
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (get_property_value(lfmri, lpg, lprop, B_FALSE, &res) != 0) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey /*
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 * returning.
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey */
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey return (result);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey }
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey }
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (scf_value_get_astring(res.sr_val, buf, bufsz) == 0)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey goto cleanup;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey result = 0;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeycleanup:
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey release_scf_resources(&res);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey return (result);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey}
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey/*
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * Inputs:
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 * Outputs:
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * answer is a pointer to the property value
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey * Returns:
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. Maskey */
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeyint
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeynwamd_lookup_count_property(const char *lfmri, const char *lpg,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey const char *lprop, uint64_t *answer)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey{
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey int result = -1;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey scf_resources_t res;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (get_property_value(lfmri, lpg, lprop, B_TRUE, &res) != 0) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey /*
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 * returning.
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey */
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey return (result);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey }
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (scf_value_get_count(res.sr_val, answer) != 0) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey goto cleanup;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey }
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey result = 0;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeycleanup:
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey release_scf_resources(&res);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey return (result);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey}
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeystatic int
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeyset_property_value(scf_resources_t *res, const char *propname,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey scf_type_t proptype)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey{
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey int result = -1;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey boolean_t new;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeyretry:
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey new = (scf_pg_get_property(res->sr_pg, propname, res->sr_prop) != 0);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (scf_transaction_start(res->sr_tx, res->sr_pg) == -1) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey goto failure;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey }
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (new) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (scf_transaction_property_new(res->sr_tx, res->sr_ent,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey propname, proptype) == -1) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey goto failure;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey }
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey } else {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (scf_transaction_property_change(res->sr_tx, res->sr_ent,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey propname, proptype) == -1) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey goto failure;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey }
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey }
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (scf_entry_add_value(res->sr_ent, res->sr_val) != 0) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey goto failure;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey }
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey result = scf_transaction_commit(res->sr_tx);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (result == 0) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey scf_transaction_reset(res->sr_tx);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (scf_pg_update(res->sr_pg) == -1) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey goto failure;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey }
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey nlog(LOG_INFO, "set_property_value: transaction commit failed "
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey "for %s; retrying", propname);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey goto retry;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey }
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (result == -1)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey goto failure;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey return (0);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeyfailure:
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey return (-1);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey}
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeyint
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeynwamd_set_count_property(const char *fmri, const char *pg, const char *prop,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey uint64_t count)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey{
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey scf_resources_t res;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (create_scf_resources(fmri, &res) != 0)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey return (-1);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
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_error() != SCF_ERROR_EXISTS)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey goto failure;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (scf_instance_get_pg_composed(res.sr_inst, NULL, pg,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey res.sr_pg) != 0)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey goto failure;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey }
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey scf_value_set_count(res.sr_val, (uint64_t)count);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (set_property_value(&res, prop, SCF_TYPE_COUNT) != 0)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey goto failure;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey release_scf_resources(&res);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey return (0);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeyfailure:
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. Maskey release_scf_resources(&res);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey return (-1);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey}
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeyint
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeynwamd_set_string_property(const char *fmri, const char *pg, const char *prop,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey const char *str)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey{
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey scf_resources_t res;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (create_scf_resources(fmri, &res) != 0)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey return (-1);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
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_error() != SCF_ERROR_EXISTS)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey goto failure;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (scf_instance_get_pg_composed(res.sr_inst, NULL, pg,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey res.sr_pg) != 0)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey goto failure;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey }
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (scf_value_set_astring(res.sr_val, str) != 0)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey goto failure;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (set_property_value(&res, prop, SCF_TYPE_ASTRING) != 0)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey goto failure;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey release_scf_resources(&res);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey return (0);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeyfailure:
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 release_scf_resources(&res);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey return (-1);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey}
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey/*
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. Maskey */
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeyint
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeynwamd_delete_scf_property(const char *fmri, const char *pg, const char *prop)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey{
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey scf_resources_t res;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey int result = -1;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (create_scf_resources(fmri, &res) != 0)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey return (-1);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
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_error() != SCF_ERROR_EXISTS)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey goto failure;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (scf_instance_get_pg_composed(res.sr_inst, NULL, pg,
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey res.sr_pg) != 0)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey goto failure;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey }
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (scf_pg_get_property(res.sr_pg, prop, res.sr_prop) != 0)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey goto failure;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeyretry:
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (scf_transaction_start(res.sr_tx, res.sr_pg) == -1)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey goto failure;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (scf_transaction_property_delete(res.sr_tx, res.sr_ent, prop) == -1)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey goto failure;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey result = scf_transaction_commit(res.sr_tx);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (result == 0) {
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey scf_transaction_reset(res.sr_tx);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (scf_pg_update(res.sr_pg) == -1)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey goto failure;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey goto retry;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey }
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey if (result == -1)
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey goto failure;
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey release_scf_resources(&res);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey return (0);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskeyfailure:
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey release_scf_resources(&res);
6ba597c56d749c61b4f783157f63196d7b2445f0Anurag S. Maskey return (-1);
d71dbb732372504daff1f1783bc0d8864ce9bd50jbeck}