4bff34e37def8a90f9194d81bc345c52ba20086athurlow/*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * CDDL HEADER START
4bff34e37def8a90f9194d81bc345c52ba20086athurlow *
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * The contents of this file are subject to the terms of the
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Common Development and Distribution License (the "License").
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * You may not use this file except in compliance with the License.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow *
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * or http://www.opensolaris.org/os/licensing.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * See the License for the specific language governing permissions
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * and limitations under the License.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow *
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * When distributing Covered Code, include this CDDL HEADER in each
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * If applicable, add the following below this CDDL HEADER, with the
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * fields enclosed by brackets "[]" replaced with your own identifying
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * information: Portions Copyright [yyyy] [name of copyright owner]
4bff34e37def8a90f9194d81bc345c52ba20086athurlow *
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * CDDL HEADER END
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow/*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Use is subject to license terms.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#pragma ident "%Z%%M% %I% %E% SMI"
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow/* helper functions for using libscf with CIFS */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#include <libscf.h>
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#include <string.h>
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#include <stdio.h>
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#include <stdlib.h>
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#include <syslog.h>
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#include <errno.h>
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#include <uuid/uuid.h>
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#include <sys/param.h>
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#include <libintl.h>
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#include <assert.h>
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#include <strings.h>
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#include "libshare.h"
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#include "libshare_smbfs.h"
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow/*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * smb_smf_scf_log_error(msg)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Logs error messages from scf API's
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlowstatic void
4bff34e37def8a90f9194d81bc345c52ba20086athurlowsmb_smf_scf_log_error(char *msg)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow{
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (!msg) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow syslog(LOG_ERR, " SMBC SMF problem: %s\n",
4bff34e37def8a90f9194d81bc345c52ba20086athurlow scf_strerror(scf_error()));
4bff34e37def8a90f9194d81bc345c52ba20086athurlow } else { /*LINTED E_SEC_PRINTF_E_VAR_FMT*/
4bff34e37def8a90f9194d81bc345c52ba20086athurlow syslog(LOG_ERR, msg, scf_strerror(scf_error()));
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow}
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow/*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * smb_smf_scf_fini(handle)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow *
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * must be called when done. Called with the handle allocated in
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * smb_smf_scf_init(), it cleans up the state and frees any SCF resources
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * still in use.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlowvoid
4bff34e37def8a90f9194d81bc345c52ba20086athurlowsmb_smf_scf_fini(smb_scfhandle_t *handle)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow{
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (handle != NULL) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow int unbind = 0;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (handle->scf_pg_iter != NULL) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow scf_iter_destroy(handle->scf_pg_iter);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow handle->scf_pg_iter = NULL;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (handle->scf_inst_iter != NULL) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow scf_iter_destroy(handle->scf_inst_iter);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow handle->scf_inst_iter = NULL;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (handle->scf_scope != NULL) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow unbind = 1;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow scf_scope_destroy(handle->scf_scope);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow handle->scf_scope = NULL;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (handle->scf_instance != NULL) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow scf_instance_destroy(handle->scf_instance);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow handle->scf_instance = NULL;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (handle->scf_service != NULL) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow scf_service_destroy(handle->scf_service);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow handle->scf_service = NULL;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (handle->scf_pg != NULL) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow scf_pg_destroy(handle->scf_pg);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow handle->scf_pg = NULL;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (handle->scf_handle != NULL) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow handle->scf_state = SCH_STATE_UNINIT;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (unbind)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow (void) scf_handle_unbind(handle->scf_handle);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow scf_handle_destroy(handle->scf_handle);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow handle->scf_handle = NULL;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow free(handle);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow}
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow/*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Check if instance with given name exists for a service.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Returns 0 is instance exist
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlowint
4bff34e37def8a90f9194d81bc345c52ba20086athurlowsmb_smf_instance_exists(smb_scfhandle_t *handle, char *inst_name)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow{
4bff34e37def8a90f9194d81bc345c52ba20086athurlow int ret = SMBC_SMF_OK;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (handle == NULL) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow return (SMBC_SMF_SYSTEM_ERR);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow handle->scf_instance = scf_instance_create(handle->scf_handle);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (scf_service_get_instance(handle->scf_service, inst_name,
4bff34e37def8a90f9194d81bc345c52ba20086athurlow handle->scf_instance) != SCF_SUCCESS) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow ret = SMBC_SMF_SYSTEM_ERR;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow scf_instance_destroy(handle->scf_instance);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow handle->scf_instance = NULL;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow return (ret);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow}
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow/*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Create a service instance. returns 0 if successful.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * If instance already exists enable it.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlowint
4bff34e37def8a90f9194d81bc345c52ba20086athurlowsmb_smf_instance_create(smb_scfhandle_t *handle, char *serv_prefix,
4bff34e37def8a90f9194d81bc345c52ba20086athurlow char *inst_name)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow{
4bff34e37def8a90f9194d81bc345c52ba20086athurlow char *instance;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow int ret = SMBC_SMF_OK;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow int sz;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (handle == NULL) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow return (SMBC_SMF_SYSTEM_ERR);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (!serv_prefix || !inst_name) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow return (SMBC_SMF_SYSTEM_ERR);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow sz = strlen(serv_prefix) + strlen(inst_name) + 2;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow instance = malloc(sz);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (!instance) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow return (SMBC_SMF_SYSTEM_ERR);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow (void) snprintf(instance, sz, "%s:%s", serv_prefix, inst_name);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow handle->scf_instance = scf_instance_create(handle->scf_handle);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (scf_service_get_instance(handle->scf_service, inst_name,
4bff34e37def8a90f9194d81bc345c52ba20086athurlow handle->scf_instance) != SCF_SUCCESS) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (scf_service_add_instance(handle->scf_service,
4bff34e37def8a90f9194d81bc345c52ba20086athurlow inst_name, handle->scf_instance) == SCF_SUCCESS) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (smf_enable_instance(instance, 0))
4bff34e37def8a90f9194d81bc345c52ba20086athurlow ret = SMBC_SMF_SYSTEM_ERR;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow } else {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow ret = SMBC_SMF_SYSTEM_ERR;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow } else {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (smf_enable_instance(instance, 0))
4bff34e37def8a90f9194d81bc345c52ba20086athurlow ret = SMBC_SMF_SYSTEM_ERR;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow free(instance);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow return (ret);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow}
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow/*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Delete a specified instance. Return SMBC_SMF_OK for success.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlowint
4bff34e37def8a90f9194d81bc345c52ba20086athurlowsmb_smf_instance_delete(smb_scfhandle_t *handle, char *inst_name)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow{
4bff34e37def8a90f9194d81bc345c52ba20086athurlow int ret = SMBC_SMF_OK;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (handle == NULL) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow return (SMBC_SMF_SYSTEM_ERR);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow handle->scf_instance = scf_instance_create(handle->scf_handle);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (scf_service_get_instance(handle->scf_service, inst_name,
4bff34e37def8a90f9194d81bc345c52ba20086athurlow handle->scf_instance) == SCF_SUCCESS) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (scf_instance_delete(handle->scf_instance) == SCF_SUCCESS) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow return (ret);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow } else {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow ret = SMBC_SMF_SYSTEM_ERR;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow } else {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow smb_smf_scf_log_error(NULL);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow ret = SMBC_SMF_SYSTEM_ERR;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow return (ret);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow}
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow/*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * smb_smf_scf_init()
4bff34e37def8a90f9194d81bc345c52ba20086athurlow *
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * must be called before using any of the SCF functions.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Returns smb_scfhandle_t pointer if success.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlowsmb_scfhandle_t *
4bff34e37def8a90f9194d81bc345c52ba20086athurlowsmb_smf_scf_init(char *svc_name)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow{
4bff34e37def8a90f9194d81bc345c52ba20086athurlow smb_scfhandle_t *handle;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow handle = malloc(sizeof (smb_scfhandle_t));
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (handle != NULL) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow bzero((char *)handle, sizeof (smb_scfhandle_t));
4bff34e37def8a90f9194d81bc345c52ba20086athurlow handle->scf_state = SCH_STATE_INITIALIZING;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow handle->scf_handle = scf_handle_create(SCF_VERSION);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (handle->scf_handle != NULL) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (scf_handle_bind(handle->scf_handle) == 0) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow handle->scf_scope =
4bff34e37def8a90f9194d81bc345c52ba20086athurlow scf_scope_create(handle->scf_handle);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (scf_handle_get_local_scope(
4bff34e37def8a90f9194d81bc345c52ba20086athurlow handle->scf_handle, handle->scf_scope) != 0)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow goto err;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow handle->scf_service =
4bff34e37def8a90f9194d81bc345c52ba20086athurlow scf_service_create(handle->scf_handle);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (scf_scope_get_service(handle->scf_scope,
4bff34e37def8a90f9194d81bc345c52ba20086athurlow svc_name, handle->scf_service)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow != SCF_SUCCESS) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow goto err;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow handle->scf_pg =
4bff34e37def8a90f9194d81bc345c52ba20086athurlow scf_pg_create(handle->scf_handle);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow handle->scf_state = SCH_STATE_INIT;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow } else {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow goto err;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow } else {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow free(handle);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow handle = NULL;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow smb_smf_scf_log_error("Could not access SMF "
4bff34e37def8a90f9194d81bc345c52ba20086athurlow "repository: %s\n");
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow return (handle);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow /* error handling/unwinding */
4bff34e37def8a90f9194d81bc345c52ba20086athurlowerr:
4bff34e37def8a90f9194d81bc345c52ba20086athurlow (void) smb_smf_scf_fini(handle);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow (void) smb_smf_scf_log_error("SMF initialization problem: %s\n");
4bff34e37def8a90f9194d81bc345c52ba20086athurlow return (NULL);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow}
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow/*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * smb_smf_create_service_pgroup(handle, pgroup)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow *
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * create a new property group at service level.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlowint
4bff34e37def8a90f9194d81bc345c52ba20086athurlowsmb_smf_create_service_pgroup(smb_scfhandle_t *handle, char *pgroup)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow{
4bff34e37def8a90f9194d81bc345c52ba20086athurlow int ret = SMBC_SMF_OK;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow int err;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (handle == NULL) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow return (SMBC_SMF_SYSTEM_ERR);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow /*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * only create a handle if it doesn't exist. It is ok to exist
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * since the pg handle will be set as a side effect.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (handle->scf_pg == NULL) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow handle->scf_pg = scf_pg_create(handle->scf_handle);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow /*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * if the pgroup exists, we are done. If it doesn't, then we
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * need to actually add one to the service instance.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (scf_service_get_pg(handle->scf_service,
4bff34e37def8a90f9194d81bc345c52ba20086athurlow pgroup, handle->scf_pg) != 0) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow /* doesn't exist so create one */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (scf_service_add_pg(handle->scf_service, pgroup,
4bff34e37def8a90f9194d81bc345c52ba20086athurlow SCF_GROUP_FRAMEWORK, 0, handle->scf_pg) != 0) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow err = scf_error();
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (err != SCF_ERROR_NONE)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow smb_smf_scf_log_error(NULL);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow switch (err) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow case SCF_ERROR_PERMISSION_DENIED:
4bff34e37def8a90f9194d81bc345c52ba20086athurlow ret = SMBC_SMF_NO_PERMISSION;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow break;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow default:
4bff34e37def8a90f9194d81bc345c52ba20086athurlow ret = SMBC_SMF_SYSTEM_ERR;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow break;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow return (ret);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow}
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow/*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * smb_smf_create_instance_pgroup(handle, pgroup)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow *
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * create a new property group at instance level.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlowint
4bff34e37def8a90f9194d81bc345c52ba20086athurlowsmb_smf_create_instance_pgroup(smb_scfhandle_t *handle, char *pgroup)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow{
4bff34e37def8a90f9194d81bc345c52ba20086athurlow int ret = SMBC_SMF_OK;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow int err;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (handle == NULL) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow return (SMBC_SMF_SYSTEM_ERR);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow /*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * only create a handle if it doesn't exist. It is ok to exist
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * since the pg handle will be set as a side effect.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (handle->scf_pg == NULL) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow handle->scf_pg = scf_pg_create(handle->scf_handle);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow /*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * if the pgroup exists, we are done. If it doesn't, then we
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * need to actually add one to the service instance.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (scf_instance_get_pg(handle->scf_instance,
4bff34e37def8a90f9194d81bc345c52ba20086athurlow pgroup, handle->scf_pg) != 0) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow /* doesn't exist so create one */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (scf_instance_add_pg(handle->scf_instance, pgroup,
4bff34e37def8a90f9194d81bc345c52ba20086athurlow SCF_GROUP_APPLICATION, 0, handle->scf_pg) != 0) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow err = scf_error();
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (err != SCF_ERROR_NONE)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow smb_smf_scf_log_error(NULL);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow switch (err) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow case SCF_ERROR_PERMISSION_DENIED:
4bff34e37def8a90f9194d81bc345c52ba20086athurlow ret = SMBC_SMF_NO_PERMISSION;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow break;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow default:
4bff34e37def8a90f9194d81bc345c52ba20086athurlow ret = SMBC_SMF_SYSTEM_ERR;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow break;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow return (ret);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow}
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow/*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * smb_smf_delete_service_pgroup(handle, pgroup)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow *
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * remove the property group from the current service.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * but only if it actually exists.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlowint
4bff34e37def8a90f9194d81bc345c52ba20086athurlowsmb_smf_delete_service_pgroup(smb_scfhandle_t *handle, char *pgroup)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow{
4bff34e37def8a90f9194d81bc345c52ba20086athurlow int ret = SMBC_SMF_OK;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow int err;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (handle == NULL) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow return (SMBC_SMF_SYSTEM_ERR);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow /*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * only create a handle if it doesn't exist. It is ok to exist
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * since the pg handle will be set as a side effect.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (handle->scf_pg == NULL) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow handle->scf_pg = scf_pg_create(handle->scf_handle);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow /*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * only delete if it does exist.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (scf_service_get_pg(handle->scf_service,
4bff34e37def8a90f9194d81bc345c52ba20086athurlow pgroup, handle->scf_pg) == 0) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow /* does exist so delete it */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (scf_pg_delete(handle->scf_pg) != 0) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow ret = SMBC_SMF_SYSTEM_ERR;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow err = scf_error();
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (err != SCF_ERROR_NONE) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow smb_smf_scf_log_error("SMF delpg "
4bff34e37def8a90f9194d81bc345c52ba20086athurlow "problem: %s\n");
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow } else {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow err = scf_error();
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (err != SCF_ERROR_NONE)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow smb_smf_scf_log_error("SMF getpg problem: %s\n");
4bff34e37def8a90f9194d81bc345c52ba20086athurlow ret = SMBC_SMF_SYSTEM_ERR;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (ret == SMBC_SMF_SYSTEM_ERR &&
4bff34e37def8a90f9194d81bc345c52ba20086athurlow scf_error() == SCF_ERROR_PERMISSION_DENIED) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow ret = SMBC_SMF_NO_PERMISSION;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow return (ret);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow}
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow/*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * smb_smf_delete_instance_pgroup(handle, pgroup)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow *
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * remove the property group from the current instance.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * but only if it actually exists.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlowint
4bff34e37def8a90f9194d81bc345c52ba20086athurlowsmb_smf_delete_instance_pgroup(smb_scfhandle_t *handle, char *pgroup)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow{
4bff34e37def8a90f9194d81bc345c52ba20086athurlow int ret = SMBC_SMF_OK;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow int err;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (handle == NULL) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow return (SMBC_SMF_SYSTEM_ERR);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow /*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * only create a handle if it doesn't exist. It is ok to exist
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * since the pg handle will be set as a side effect.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (handle->scf_pg == NULL) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow handle->scf_pg = scf_pg_create(handle->scf_handle);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow /*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * only delete if it does exist.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (scf_instance_get_pg(handle->scf_instance,
4bff34e37def8a90f9194d81bc345c52ba20086athurlow pgroup, handle->scf_pg) == 0) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow /* does exist so delete it */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (scf_pg_delete(handle->scf_pg) != 0) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow ret = SMBC_SMF_SYSTEM_ERR;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow err = scf_error();
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (err != SCF_ERROR_NONE) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow smb_smf_scf_log_error("SMF delpg "
4bff34e37def8a90f9194d81bc345c52ba20086athurlow "problem: %s\n");
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow } else {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow err = scf_error();
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (err != SCF_ERROR_NONE)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow smb_smf_scf_log_error("SMF getpg problem: %s\n");
4bff34e37def8a90f9194d81bc345c52ba20086athurlow ret = SMBC_SMF_SYSTEM_ERR;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (ret == SMBC_SMF_SYSTEM_ERR &&
4bff34e37def8a90f9194d81bc345c52ba20086athurlow scf_error() == SCF_ERROR_PERMISSION_DENIED) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow ret = SMBC_SMF_NO_PERMISSION;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow return (ret);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow}
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow/*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Start transaction on current pg in handle.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * The pg could be service or instance level.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Must be called after pg handle is obtained
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * from create or get.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlowint
4bff34e37def8a90f9194d81bc345c52ba20086athurlowsmb_smf_start_transaction(smb_scfhandle_t *handle)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow{
4bff34e37def8a90f9194d81bc345c52ba20086athurlow int ret = SMBC_SMF_OK;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (!handle || (!handle->scf_pg)) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow return (SMBC_SMF_SYSTEM_ERR);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow /*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * lookup the property group and create it if it doesn't already
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * exist.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (handle->scf_state == SCH_STATE_INIT) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (ret == SMBC_SMF_OK) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow handle->scf_trans =
4bff34e37def8a90f9194d81bc345c52ba20086athurlow scf_transaction_create(handle->scf_handle);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (handle->scf_trans != NULL) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (scf_transaction_start(handle->scf_trans,
4bff34e37def8a90f9194d81bc345c52ba20086athurlow handle->scf_pg) != 0) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow ret = SMBC_SMF_SYSTEM_ERR;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow scf_transaction_destroy(
4bff34e37def8a90f9194d81bc345c52ba20086athurlow handle->scf_trans);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow handle->scf_trans = NULL;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow } else {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow ret = SMBC_SMF_SYSTEM_ERR;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (ret == SMBC_SMF_SYSTEM_ERR &&
4bff34e37def8a90f9194d81bc345c52ba20086athurlow scf_error() == SCF_ERROR_PERMISSION_DENIED) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow ret = SMBC_SMF_NO_PERMISSION;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow return (ret);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow}
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow/*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * smb_smf_end_transaction(handle)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow *
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Commit the changes that were added to the transaction in the
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * handle. Do all necessary cleanup.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlowint
4bff34e37def8a90f9194d81bc345c52ba20086athurlowsmb_smf_end_transaction(smb_scfhandle_t *handle)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow{
4bff34e37def8a90f9194d81bc345c52ba20086athurlow int ret = SMBC_SMF_OK;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (handle == NULL) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow return (SMBC_SMF_SYSTEM_ERR);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (handle->scf_trans == NULL) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow ret = SMBC_SMF_SYSTEM_ERR;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow } else {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (scf_transaction_commit(handle->scf_trans) < 0) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow ret = SMBC_SMF_SYSTEM_ERR;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow smb_smf_scf_log_error("Failed to commit "
4bff34e37def8a90f9194d81bc345c52ba20086athurlow "transaction: %s");
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow scf_transaction_destroy_children(handle->scf_trans);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow scf_transaction_destroy(handle->scf_trans);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow handle->scf_trans = NULL;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow return (ret);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow}
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow/*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Deletes property in current pg
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlowint
4bff34e37def8a90f9194d81bc345c52ba20086athurlowsmb_smf_delete_property(smb_scfhandle_t *handle, char *propname)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow{
4bff34e37def8a90f9194d81bc345c52ba20086athurlow int ret = SMBC_SMF_OK;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow scf_transaction_entry_t *entry = NULL;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (handle == NULL) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow return (SMBC_SMF_SYSTEM_ERR);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow /*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * properties must be set in transactions and don't take
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * effect until the transaction has been ended/committed.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow entry = scf_entry_create(handle->scf_handle);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (entry != NULL) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (scf_transaction_property_delete(handle->scf_trans, entry,
4bff34e37def8a90f9194d81bc345c52ba20086athurlow propname) != 0) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow ret = SMBC_SMF_SYSTEM_ERR;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow } else {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow ret = SMBC_SMF_SYSTEM_ERR;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (ret == SMBC_SMF_SYSTEM_ERR) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow switch (scf_error()) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow case SCF_ERROR_PERMISSION_DENIED:
4bff34e37def8a90f9194d81bc345c52ba20086athurlow ret = SMBC_SMF_NO_PERMISSION;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow break;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow /*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * cleanup if there were any errors that didn't leave these
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * values where they would be cleaned up later.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if ((ret != SMBC_SMF_OK) && (entry != NULL)) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow scf_entry_destroy(entry);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow return (ret);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow}
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow/*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Sets string property in current pg
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlowint
4bff34e37def8a90f9194d81bc345c52ba20086athurlowsmb_smf_set_string_property(smb_scfhandle_t *handle,
4bff34e37def8a90f9194d81bc345c52ba20086athurlow char *propname, char *valstr)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow{
4bff34e37def8a90f9194d81bc345c52ba20086athurlow int ret = SMBC_SMF_OK;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow scf_value_t *value = NULL;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow scf_transaction_entry_t *entry = NULL;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (handle == NULL) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow return (SMBC_SMF_SYSTEM_ERR);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow /*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * properties must be set in transactions and don't take
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * effect until the transaction has been ended/committed.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow value = scf_value_create(handle->scf_handle);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow entry = scf_entry_create(handle->scf_handle);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (value != NULL && entry != NULL) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (scf_transaction_property_change(handle->scf_trans, entry,
4bff34e37def8a90f9194d81bc345c52ba20086athurlow propname, SCF_TYPE_ASTRING) == 0 ||
4bff34e37def8a90f9194d81bc345c52ba20086athurlow scf_transaction_property_new(handle->scf_trans, entry,
4bff34e37def8a90f9194d81bc345c52ba20086athurlow propname, SCF_TYPE_ASTRING) == 0) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (scf_value_set_astring(value, valstr) == 0) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (scf_entry_add_value(entry, value) != 0) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow ret = SMBC_SMF_SYSTEM_ERR;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow scf_value_destroy(value);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow /* the value is in the transaction */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow value = NULL;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow } else {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow /* value couldn't be constructed */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow ret = SMBC_SMF_SYSTEM_ERR;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow /* the entry is in the transaction */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow entry = NULL;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow } else {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow ret = SMBC_SMF_SYSTEM_ERR;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow } else {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow ret = SMBC_SMF_SYSTEM_ERR;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (ret == SMBC_SMF_SYSTEM_ERR) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow switch (scf_error()) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow case SCF_ERROR_PERMISSION_DENIED:
4bff34e37def8a90f9194d81bc345c52ba20086athurlow ret = SMBC_SMF_NO_PERMISSION;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow break;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow /*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * cleanup if there were any errors that didn't leave these
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * values where they would be cleaned up later.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (value != NULL)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow scf_value_destroy(value);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (entry != NULL)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow scf_entry_destroy(entry);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow return (ret);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow}
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow/*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Gets string property value.upto sz size.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Caller is responsible to have enough memory allocated.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlowint
4bff34e37def8a90f9194d81bc345c52ba20086athurlowsmb_smf_get_string_property(smb_scfhandle_t *handle, char *propname,
4bff34e37def8a90f9194d81bc345c52ba20086athurlow char *valstr, size_t sz)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow{
4bff34e37def8a90f9194d81bc345c52ba20086athurlow int ret = SMBC_SMF_OK;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow scf_value_t *value;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow scf_property_t *prop;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (handle == NULL) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow return (SMBC_SMF_SYSTEM_ERR);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow value = scf_value_create(handle->scf_handle);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow prop = scf_property_create(handle->scf_handle);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (value && prop &&
4bff34e37def8a90f9194d81bc345c52ba20086athurlow (scf_pg_get_property(handle->scf_pg, propname, prop) == 0)) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (scf_property_get_value(prop, value) == 0) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (scf_value_get_astring(value, valstr, sz) < 0) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow ret = SMBC_SMF_SYSTEM_ERR;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow } else {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow ret = SMBC_SMF_SYSTEM_ERR;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow } else {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow ret = SMBC_SMF_SYSTEM_ERR;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (value != NULL)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow scf_value_destroy(value);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (prop != NULL)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow scf_property_destroy(prop);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow return (ret);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow}
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow/*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Get integer value of property.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * The value is returned as int64_t value
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Caller ensures appropriate translation.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlowint
4bff34e37def8a90f9194d81bc345c52ba20086athurlowsmb_smf_set_integer_property(smb_scfhandle_t *handle, char *propname,
4bff34e37def8a90f9194d81bc345c52ba20086athurlow int64_t valint)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow{
4bff34e37def8a90f9194d81bc345c52ba20086athurlow int ret = SMBC_SMF_OK;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow scf_value_t *value = NULL;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow scf_transaction_entry_t *entry = NULL;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (handle == NULL) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow return (SMBC_SMF_SYSTEM_ERR);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow /*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * properties must be set in transactions and don't take
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * effect until the transaction has been ended/committed.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow value = scf_value_create(handle->scf_handle);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow entry = scf_entry_create(handle->scf_handle);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (value != NULL && entry != NULL) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (scf_transaction_property_change(handle->scf_trans, entry,
4bff34e37def8a90f9194d81bc345c52ba20086athurlow propname, SCF_TYPE_INTEGER) == 0 ||
4bff34e37def8a90f9194d81bc345c52ba20086athurlow scf_transaction_property_new(handle->scf_trans, entry,
4bff34e37def8a90f9194d81bc345c52ba20086athurlow propname, SCF_TYPE_INTEGER) == 0) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow scf_value_set_integer(value, valint);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (scf_entry_add_value(entry, value) != 0) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow ret = SMBC_SMF_SYSTEM_ERR;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow scf_value_destroy(value);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow /* the value is in the transaction */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow value = NULL;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow /* the entry is in the transaction */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow entry = NULL;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow } else {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow ret = SMBC_SMF_SYSTEM_ERR;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (ret == SMBC_SMF_SYSTEM_ERR) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow switch (scf_error()) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow case SCF_ERROR_PERMISSION_DENIED:
4bff34e37def8a90f9194d81bc345c52ba20086athurlow ret = SMBC_SMF_NO_PERMISSION;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow break;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow /*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * cleanup if there were any errors that didn't leave these
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * values where they would be cleaned up later.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (value != NULL)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow scf_value_destroy(value);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (entry != NULL)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow scf_entry_destroy(entry);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow return (ret);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow}
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow/*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Sets integer property value.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Caller is responsible to have enough memory allocated.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlowint
4bff34e37def8a90f9194d81bc345c52ba20086athurlowsmb_smf_get_integer_property(smb_scfhandle_t *handle, char *propname,
4bff34e37def8a90f9194d81bc345c52ba20086athurlow int64_t *valint)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow{
4bff34e37def8a90f9194d81bc345c52ba20086athurlow int ret = SMBC_SMF_OK;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow scf_value_t *value = NULL;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow scf_property_t *prop = NULL;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (handle == NULL) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow return (SMBC_SMF_SYSTEM_ERR);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow value = scf_value_create(handle->scf_handle);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow prop = scf_property_create(handle->scf_handle);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if ((prop) && (value) &&
4bff34e37def8a90f9194d81bc345c52ba20086athurlow (scf_pg_get_property(handle->scf_pg, propname, prop) == 0)) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (scf_property_get_value(prop, value) == 0) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (scf_value_get_integer(value,
4bff34e37def8a90f9194d81bc345c52ba20086athurlow valint) != 0) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow ret = SMBC_SMF_SYSTEM_ERR;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow } else {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow ret = SMBC_SMF_SYSTEM_ERR;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow } else {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow ret = SMBC_SMF_SYSTEM_ERR;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (value != NULL)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow scf_value_destroy(value);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (prop != NULL)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow scf_property_destroy(prop);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow return (ret);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow}
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow/*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Get boolean value of property.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * The value is returned as int64_t value
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Caller ensures appropriate translation.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlowint
4bff34e37def8a90f9194d81bc345c52ba20086athurlowsmb_smf_set_boolean_property(smb_scfhandle_t *handle, char *propname,
4bff34e37def8a90f9194d81bc345c52ba20086athurlow uint8_t valbool)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow{
4bff34e37def8a90f9194d81bc345c52ba20086athurlow int ret = SMBC_SMF_OK;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow scf_value_t *value = NULL;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow scf_transaction_entry_t *entry = NULL;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (handle == NULL) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow return (SMBC_SMF_SYSTEM_ERR);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow /*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * properties must be set in transactions and don't take
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * effect until the transaction has been ended/committed.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow value = scf_value_create(handle->scf_handle);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow entry = scf_entry_create(handle->scf_handle);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (value != NULL && entry != NULL) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (scf_transaction_property_change(handle->scf_trans, entry,
4bff34e37def8a90f9194d81bc345c52ba20086athurlow propname, SCF_TYPE_BOOLEAN) == 0 ||
4bff34e37def8a90f9194d81bc345c52ba20086athurlow scf_transaction_property_new(handle->scf_trans, entry,
4bff34e37def8a90f9194d81bc345c52ba20086athurlow propname, SCF_TYPE_BOOLEAN) == 0) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow scf_value_set_boolean(value, valbool);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (scf_entry_add_value(entry, value) != 0) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow ret = SMBC_SMF_SYSTEM_ERR;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow scf_value_destroy(value);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow /* the value is in the transaction */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow value = NULL;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow /* the entry is in the transaction */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow entry = NULL;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow } else {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow ret = SMBC_SMF_SYSTEM_ERR;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (ret == SMBC_SMF_SYSTEM_ERR) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow switch (scf_error()) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow case SCF_ERROR_PERMISSION_DENIED:
4bff34e37def8a90f9194d81bc345c52ba20086athurlow ret = SMBC_SMF_NO_PERMISSION;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow break;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow /*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * cleanup if there were any errors that didn't leave these
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * values where they would be cleaned up later.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (value != NULL)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow scf_value_destroy(value);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (entry != NULL)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow scf_entry_destroy(entry);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow return (ret);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow}
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow/*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Sets boolean property value.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Caller is responsible to have enough memory allocated.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlowint
4bff34e37def8a90f9194d81bc345c52ba20086athurlowsmb_smf_get_boolean_property(smb_scfhandle_t *handle, char *propname,
4bff34e37def8a90f9194d81bc345c52ba20086athurlow uint8_t *valbool)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow{
4bff34e37def8a90f9194d81bc345c52ba20086athurlow int ret = SMBC_SMF_OK;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow scf_value_t *value = NULL;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow scf_property_t *prop = NULL;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (handle == NULL) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow return (SMBC_SMF_SYSTEM_ERR);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow value = scf_value_create(handle->scf_handle);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow prop = scf_property_create(handle->scf_handle);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if ((prop) && (value) &&
4bff34e37def8a90f9194d81bc345c52ba20086athurlow (scf_pg_get_property(handle->scf_pg, propname, prop) == 0)) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (scf_property_get_value(prop, value) == 0) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (scf_value_get_boolean(value,
4bff34e37def8a90f9194d81bc345c52ba20086athurlow valbool) != 0) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow ret = SMBC_SMF_SYSTEM_ERR;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow } else {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow ret = SMBC_SMF_SYSTEM_ERR;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow } else {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow ret = SMBC_SMF_SYSTEM_ERR;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (value != NULL)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow scf_value_destroy(value);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (prop != NULL)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow scf_property_destroy(prop);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow return (ret);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow}
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow/*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Sets a blob property value.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlowint
4bff34e37def8a90f9194d81bc345c52ba20086athurlowsmb_smf_set_opaque_property(smb_scfhandle_t *handle, char *propname,
4bff34e37def8a90f9194d81bc345c52ba20086athurlow void *voidval, size_t sz)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow{
4bff34e37def8a90f9194d81bc345c52ba20086athurlow int ret = SMBC_SMF_OK;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow scf_value_t *value;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow scf_transaction_entry_t *entry;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (handle == NULL) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow return (SMBC_SMF_SYSTEM_ERR);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow /*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * properties must be set in transactions and don't take
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * effect until the transaction has been ended/committed.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow value = scf_value_create(handle->scf_handle);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow entry = scf_entry_create(handle->scf_handle);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (value != NULL && entry != NULL) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (scf_transaction_property_change(handle->scf_trans, entry,
4bff34e37def8a90f9194d81bc345c52ba20086athurlow propname, SCF_TYPE_OPAQUE) == 0 ||
4bff34e37def8a90f9194d81bc345c52ba20086athurlow scf_transaction_property_new(handle->scf_trans, entry,
4bff34e37def8a90f9194d81bc345c52ba20086athurlow propname, SCF_TYPE_OPAQUE) == 0) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (scf_value_set_opaque(value, voidval, sz) == 0) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (scf_entry_add_value(entry, value) != 0) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow ret = SMBC_SMF_SYSTEM_ERR;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow scf_value_destroy(value);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow /* the value is in the transaction */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow value = NULL;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow } else {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow /* value couldn't be constructed */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow ret = SMBC_SMF_SYSTEM_ERR;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow /* the entry is in the transaction */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow entry = NULL;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow } else {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow ret = SMBC_SMF_SYSTEM_ERR;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow } else {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow ret = SMBC_SMF_SYSTEM_ERR;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (ret == SMBC_SMF_SYSTEM_ERR) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow switch (scf_error()) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow case SCF_ERROR_PERMISSION_DENIED:
4bff34e37def8a90f9194d81bc345c52ba20086athurlow ret = SMBC_SMF_NO_PERMISSION;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow break;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow /*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * cleanup if there were any errors that didn't leave these
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * values where they would be cleaned up later.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (value != NULL)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow scf_value_destroy(value);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (entry != NULL)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow scf_entry_destroy(entry);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow return (ret);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow}
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow/*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Gets a blob property value.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Caller is responsible to have enough memory allocated.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlowint
4bff34e37def8a90f9194d81bc345c52ba20086athurlowsmb_smf_get_opaque_property(smb_scfhandle_t *handle, char *propname,
4bff34e37def8a90f9194d81bc345c52ba20086athurlow void *v, size_t sz)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow{
4bff34e37def8a90f9194d81bc345c52ba20086athurlow int ret = SMBC_SMF_OK;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow scf_value_t *value = NULL;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow scf_property_t *prop = NULL;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (handle == NULL) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow return (SMBC_SMF_SYSTEM_ERR);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow value = scf_value_create(handle->scf_handle);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow prop = scf_property_create(handle->scf_handle);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if ((prop) && (value) &&
4bff34e37def8a90f9194d81bc345c52ba20086athurlow (scf_pg_get_property(handle->scf_pg, propname, prop) == 0)) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (scf_property_get_value(prop, value) == 0) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (scf_value_get_opaque(value, (char *)v, sz) != sz) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow ret = SMBC_SMF_SYSTEM_ERR;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow } else {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow ret = SMBC_SMF_SYSTEM_ERR;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow } else {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow ret = SMBC_SMF_SYSTEM_ERR;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (value != NULL)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow scf_value_destroy(value);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (prop != NULL)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow scf_property_destroy(prop);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow return (ret);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow}
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow/*
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Gets an instance iterator for the service specified.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow */
4bff34e37def8a90f9194d81bc345c52ba20086athurlowsmb_scfhandle_t *
4bff34e37def8a90f9194d81bc345c52ba20086athurlowsmb_smf_get_iterator(char *svc_name)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow{
4bff34e37def8a90f9194d81bc345c52ba20086athurlow smb_scfhandle_t *handle = NULL;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow handle = smb_smf_scf_init(svc_name);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (!handle) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow return (NULL);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow
4bff34e37def8a90f9194d81bc345c52ba20086athurlow handle->scf_inst_iter = scf_iter_create(handle->scf_handle);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (handle->scf_inst_iter) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (scf_iter_service_instances(handle->scf_inst_iter,
4bff34e37def8a90f9194d81bc345c52ba20086athurlow handle->scf_service) != 0) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow smb_smf_scf_fini(handle);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow handle = NULL;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow } else {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow handle->scf_instance = NULL;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow } else {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow smb_smf_scf_fini(handle);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow handle = NULL;
4bff34e37def8a90f9194d81bc345c52ba20086athurlow }
4bff34e37def8a90f9194d81bc345c52ba20086athurlow return (handle);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow}