da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * CDDL HEADER START
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * The contents of this file are subject to the terms of the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Common Development and Distribution License (the "License").
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * You may not use this file except in compliance with the License.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * See the License for the specific language governing permissions
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * and limitations under the License.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * When distributing Covered Code, include this CDDL HEADER in each
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * If applicable, add the following below this CDDL HEADER, with the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * fields enclosed by brackets "[]" replaced with your own identifying
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * information: Portions Copyright [yyyy] [name of copyright owner]
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * CDDL HEADER END
dc20a3024900c47dd2ee44b9707e6df38f7d62a5as * Copyright 2008 Sun Microsystems, Inc. All rights reserved.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Use is subject to license terms.
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * Copyright 2015 Nexenta Systems, Inc. All rights reserved.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw/* helper functions for using libscf with CIFS */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * smb_smf_scf_log_error(msg)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Logs error messages from scf API's
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwstatic void
b819cea2f73f98c5662230cc9affc8cc84f77fcfGordon Ross syslog(LOG_ERR, " %s: %s", msg, scf_strerror(scf_error()));
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * smb_smf_create_service_pgroup(handle, pgroup)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * create a new property group at service level.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwsmb_smf_create_service_pgroup(smb_scfhandle_t *handle, char *pgroup)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * only create a handle if it doesn't exist. It is ok to exist
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * since the pg handle will be set as a side effect.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * if the pgroup exists, we are done. If it doesn't, then we
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * need to actually add one to the service instance.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* doesn't exist so create one */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw switch (err) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Start transaction on current pg in handle.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * The pg could be service or instance level.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Must be called after pg handle is obtained
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * from create or get.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * lookup the property group and create it if it doesn't already
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * smb_smf_end_transaction(handle)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Commit the changes that were added to the transaction in the
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * handle. Do all necessary cleanup.
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross } else if (rc == 0) {
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross smb_smf_scf_log_error("Failed to commit, old pg: "
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross "transaction: %s");
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross smb_smf_scf_log_error("Failed to commit, error: "
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw "transaction: %s");
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Sets string property in current pg
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * properties must be set in transactions and don't take
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * effect until the transaction has been ended/committed.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (scf_transaction_property_change(handle->scf_trans, entry,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* the value is in the transaction */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* value couldn't be constructed */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* the entry is in the transaction */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw switch (scf_error()) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * cleanup if there were any errors that didn't leave these
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * values where they would be cleaned up later.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Gets string property value.upto sz size.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Caller is responsible to have enough memory allocated.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwsmb_smf_get_string_property(smb_scfhandle_t *handle, char *propname,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw (scf_pg_get_property(handle->scf_pg, propname, prop) == 0)) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Set integer value of property.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * The value is returned as int64_t value
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Caller ensures appropriate translation.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwsmb_smf_set_integer_property(smb_scfhandle_t *handle, char *propname,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * properties must be set in transactions and don't take
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * effect until the transaction has been ended/committed.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (scf_transaction_property_change(handle->scf_trans, entry,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* the value is in the transaction */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* the entry is in the transaction */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw switch (scf_error()) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * cleanup if there were any errors that didn't leave these
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * values where they would be cleaned up later.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Gets integer property value.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Caller is responsible to have enough memory allocated.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwsmb_smf_get_integer_property(smb_scfhandle_t *handle, char *propname,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw (scf_pg_get_property(handle->scf_pg, propname, prop) == 0)) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Set boolean value of property.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * The value is returned as int64_t value
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Caller ensures appropriate translation.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwsmb_smf_set_boolean_property(smb_scfhandle_t *handle, char *propname,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * properties must be set in transactions and don't take
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * effect until the transaction has been ended/committed.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (scf_transaction_property_change(handle->scf_trans, entry,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* the value is in the transaction */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* the entry is in the transaction */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw switch (scf_error()) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * cleanup if there were any errors that didn't leave these
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * values where they would be cleaned up later.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Gets boolean property value.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Caller is responsible to have enough memory allocated.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwsmb_smf_get_boolean_property(smb_scfhandle_t *handle, char *propname,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw (scf_pg_get_property(handle->scf_pg, propname, prop) == 0)) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Sets a blob property value.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwsmb_smf_set_opaque_property(smb_scfhandle_t *handle, char *propname,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * properties must be set in transactions and don't take
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * effect until the transaction has been ended/committed.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw if (scf_transaction_property_change(handle->scf_trans, entry,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* the value is in the transaction */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* value couldn't be constructed */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw /* the entry is in the transaction */
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw switch (scf_error()) {
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * cleanup if there were any errors that didn't leave these
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * values where they would be cleaned up later.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Gets a blob property value.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Caller is responsible to have enough memory allocated.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amwsmb_smf_get_opaque_property(smb_scfhandle_t *handle, char *propname,
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw (scf_pg_get_property(handle->scf_pg, propname, prop) == 0)) {
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * Delete a property (for properties obsoleted during an upgrade).
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Rosssmb_smf_delete_property(smb_scfhandle_t *handle, char *propname)
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * properties must be set in transactions and don't take
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross * effect until the transaction has been ended/committed.
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross if (scf_transaction_property_delete(handle->scf_trans,
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross /* the entry is in the transaction */
a90cf9f29973990687fa61de9f1f6ea22e924e40Gordon Ross /* Did not exist. We're done. */
8d7e41661dc4633488e93b13363137523ce59977jose borrego * Put the smb service into maintenance mode.
8d7e41661dc4633488e93b13363137523ce59977jose borrego return (smf_maintain_instance(SMBD_DEFAULT_INSTANCE_FMRI, 0));
8d7e41661dc4633488e93b13363137523ce59977jose borrego * Restart the smb service.
c8ec8eea9849cac239663c46be8a7f5d2ba7ca00jose borrego return (smf_restart_instance(SMBD_DEFAULT_INSTANCE_FMRI));
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * smb_smf_scf_init()
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * must be called before using any of the SCF functions.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * Returns smb_scfhandle_t pointer if success.
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw "repository: %s\n");
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw (void) smb_smf_scf_log_error("SMF initialization problem: %s\n");
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * smb_smf_scf_fini(handle)
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * must be called when done. Called with the handle allocated in
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * smb_smf_scf_init(), it cleans up the state and frees any SCF resources
da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0amw * still in use.