4bff34e37def8a90f9194d81bc345c52ba20086athurlow * CDDL HEADER START
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 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * See the License for the specific language governing permissions
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * and limitations under the License.
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 * CDDL HEADER END
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Use is subject to license terms.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow#pragma ident "%Z%%M% %I% %E% SMI"
4bff34e37def8a90f9194d81bc345c52ba20086athurlow/* helper functions for using libscf with CIFS */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * smb_smf_scf_log_error(msg)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Logs error messages from scf API's
4bff34e37def8a90f9194d81bc345c52ba20086athurlow } else { /*LINTED E_SEC_PRINTF_E_VAR_FMT*/
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * smb_smf_scf_fini(handle)
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 * Check if instance with given name exists for a service.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Returns 0 is instance exist
4bff34e37def8a90f9194d81bc345c52ba20086athurlowsmb_smf_instance_exists(smb_scfhandle_t *handle, char *inst_name)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow handle->scf_instance = scf_instance_create(handle->scf_handle);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (scf_service_get_instance(handle->scf_service, inst_name,
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Create a service instance. returns 0 if successful.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * If instance already exists enable it.
4bff34e37def8a90f9194d81bc345c52ba20086athurlowsmb_smf_instance_create(smb_scfhandle_t *handle, char *serv_prefix,
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 * Delete a specified instance. Return SMBC_SMF_OK for success.
4bff34e37def8a90f9194d81bc345c52ba20086athurlowsmb_smf_instance_delete(smb_scfhandle_t *handle, char *inst_name)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow handle->scf_instance = scf_instance_create(handle->scf_handle);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (scf_service_get_instance(handle->scf_service, inst_name,
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (scf_instance_delete(handle->scf_instance) == SCF_SUCCESS) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * smb_smf_scf_init()
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * must be called before using any of the SCF functions.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Returns smb_scfhandle_t pointer if success.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow handle->scf_handle = scf_handle_create(SCF_VERSION);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow "repository: %s\n");
4bff34e37def8a90f9194d81bc345c52ba20086athurlow (void) smb_smf_scf_log_error("SMF initialization problem: %s\n");
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * smb_smf_create_service_pgroup(handle, pgroup)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * create a new property group at service level.
4bff34e37def8a90f9194d81bc345c52ba20086athurlowsmb_smf_create_service_pgroup(smb_scfhandle_t *handle, char *pgroup)
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 * if the pgroup exists, we are done. If it doesn't, then we
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * need to actually add one to the service instance.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow /* doesn't exist so create one */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * smb_smf_create_instance_pgroup(handle, pgroup)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * create a new property group at instance level.
4bff34e37def8a90f9194d81bc345c52ba20086athurlowsmb_smf_create_instance_pgroup(smb_scfhandle_t *handle, char *pgroup)
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 * if the pgroup exists, we are done. If it doesn't, then we
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * need to actually add one to the service instance.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow /* doesn't exist so create one */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (scf_instance_add_pg(handle->scf_instance, pgroup,
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * smb_smf_delete_service_pgroup(handle, pgroup)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * remove the property group from the current service.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * but only if it actually exists.
4bff34e37def8a90f9194d81bc345c52ba20086athurlowsmb_smf_delete_service_pgroup(smb_scfhandle_t *handle, char *pgroup)
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 * only delete if it does exist.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow /* does exist so delete it */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow "problem: %s\n");
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * smb_smf_delete_instance_pgroup(handle, pgroup)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * remove the property group from the current instance.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * but only if it actually exists.
4bff34e37def8a90f9194d81bc345c52ba20086athurlowsmb_smf_delete_instance_pgroup(smb_scfhandle_t *handle, char *pgroup)
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 * only delete if it does exist.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow /* does exist so delete it */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow "problem: %s\n");
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 * lookup the property group and create it if it doesn't already
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * smb_smf_end_transaction(handle)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Commit the changes that were added to the transaction in the
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * handle. Do all necessary cleanup.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (scf_transaction_commit(handle->scf_trans) < 0) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow "transaction: %s");
4bff34e37def8a90f9194d81bc345c52ba20086athurlow scf_transaction_destroy_children(handle->scf_trans);
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Deletes property in current pg
4bff34e37def8a90f9194d81bc345c52ba20086athurlowsmb_smf_delete_property(smb_scfhandle_t *handle, char *propname)
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * properties must be set in transactions and don't take
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * effect until the transaction has been ended/committed.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (scf_transaction_property_delete(handle->scf_trans, entry,
4bff34e37def8a90f9194d81bc345c52ba20086athurlow switch (scf_error()) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * cleanup if there were any errors that didn't leave these
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * values where they would be cleaned up later.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Sets string property in current pg
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * properties must be set in transactions and don't take
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * effect until the transaction has been ended/committed.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (scf_transaction_property_change(handle->scf_trans, entry,
4bff34e37def8a90f9194d81bc345c52ba20086athurlow scf_transaction_property_new(handle->scf_trans, entry,
4bff34e37def8a90f9194d81bc345c52ba20086athurlow /* the value is in the transaction */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow /* value couldn't be constructed */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow /* the entry is in the transaction */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow switch (scf_error()) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * cleanup if there were any errors that didn't leave these
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * values where they would be cleaned up later.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Gets string property value.upto sz size.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Caller is responsible to have enough memory allocated.
4bff34e37def8a90f9194d81bc345c52ba20086athurlowsmb_smf_get_string_property(smb_scfhandle_t *handle, char *propname,
4bff34e37def8a90f9194d81bc345c52ba20086athurlow (scf_pg_get_property(handle->scf_pg, propname, prop) == 0)) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Get integer value of property.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * The value is returned as int64_t value
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Caller ensures appropriate translation.
4bff34e37def8a90f9194d81bc345c52ba20086athurlowsmb_smf_set_integer_property(smb_scfhandle_t *handle, char *propname,
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * properties must be set in transactions and don't take
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * effect until the transaction has been ended/committed.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (scf_transaction_property_change(handle->scf_trans, entry,
4bff34e37def8a90f9194d81bc345c52ba20086athurlow scf_transaction_property_new(handle->scf_trans, entry,
4bff34e37def8a90f9194d81bc345c52ba20086athurlow /* the value is in the transaction */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow /* the entry is in the transaction */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow switch (scf_error()) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * cleanup if there were any errors that didn't leave these
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * values where they would be cleaned up later.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Sets integer property value.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Caller is responsible to have enough memory allocated.
4bff34e37def8a90f9194d81bc345c52ba20086athurlowsmb_smf_get_integer_property(smb_scfhandle_t *handle, char *propname,
4bff34e37def8a90f9194d81bc345c52ba20086athurlow (scf_pg_get_property(handle->scf_pg, propname, prop) == 0)) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Get boolean value of property.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * The value is returned as int64_t value
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Caller ensures appropriate translation.
4bff34e37def8a90f9194d81bc345c52ba20086athurlowsmb_smf_set_boolean_property(smb_scfhandle_t *handle, char *propname,
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * properties must be set in transactions and don't take
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * effect until the transaction has been ended/committed.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (scf_transaction_property_change(handle->scf_trans, entry,
4bff34e37def8a90f9194d81bc345c52ba20086athurlow scf_transaction_property_new(handle->scf_trans, entry,
4bff34e37def8a90f9194d81bc345c52ba20086athurlow /* the value is in the transaction */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow /* the entry is in the transaction */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow switch (scf_error()) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * cleanup if there were any errors that didn't leave these
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * values where they would be cleaned up later.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Sets boolean property value.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Caller is responsible to have enough memory allocated.
4bff34e37def8a90f9194d81bc345c52ba20086athurlowsmb_smf_get_boolean_property(smb_scfhandle_t *handle, char *propname,
4bff34e37def8a90f9194d81bc345c52ba20086athurlow (scf_pg_get_property(handle->scf_pg, propname, prop) == 0)) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Sets a blob property value.
4bff34e37def8a90f9194d81bc345c52ba20086athurlowsmb_smf_set_opaque_property(smb_scfhandle_t *handle, char *propname,
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * properties must be set in transactions and don't take
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * effect until the transaction has been ended/committed.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (scf_transaction_property_change(handle->scf_trans, entry,
4bff34e37def8a90f9194d81bc345c52ba20086athurlow scf_transaction_property_new(handle->scf_trans, entry,
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (scf_value_set_opaque(value, voidval, sz) == 0) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow /* the value is in the transaction */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow /* value couldn't be constructed */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow /* the entry is in the transaction */
4bff34e37def8a90f9194d81bc345c52ba20086athurlow switch (scf_error()) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * cleanup if there were any errors that didn't leave these
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * values where they would be cleaned up later.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Gets a blob property value.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Caller is responsible to have enough memory allocated.
4bff34e37def8a90f9194d81bc345c52ba20086athurlowsmb_smf_get_opaque_property(smb_scfhandle_t *handle, char *propname,
4bff34e37def8a90f9194d81bc345c52ba20086athurlow (scf_pg_get_property(handle->scf_pg, propname, prop) == 0)) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow if (scf_value_get_opaque(value, (char *)v, sz) != sz) {
4bff34e37def8a90f9194d81bc345c52ba20086athurlow * Gets an instance iterator for the service specified.
4bff34e37def8a90f9194d81bc345c52ba20086athurlow handle->scf_inst_iter = scf_iter_create(handle->scf_handle);