smb_scfutil.c revision da6c28aaf62fa55f0fdb8004aa40f88f23bf53f0
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2007 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/* helper functions for using libscf with CIFS */
#include <libscf.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <syslog.h>
#include <errno.h>
#include <libintl.h>
#include <assert.h>
#include <strings.h>
/*
* smb_smf_scf_log_error(msg)
* Logs error messages from scf API's
*/
static void
smb_smf_scf_log_error(char *msg)
{
if (!msg) {
scf_strerror(scf_error()));
} else { /*LINTED E_SEC_PRINTF_E_VAR_FMT*/
}
}
/*
* Check if instance with given name exists for a service.
* Returns 0 is instance exist
*/
int
{
int ret = SMBD_SMF_OK;
return (SMBD_SMF_SYSTEM_ERR);
return (ret);
}
/*
* Create a service instance. returns 0 if successful.
* If instance already exists enable it.
*/
int
char *inst_name)
{
char *instance;
int ret = SMBD_SMF_OK;
int sz;
return (SMBD_SMF_SYSTEM_ERR);
if (!serv_prefix || !inst_name)
return (SMBD_SMF_SYSTEM_ERR);
if (!instance)
return (SMBD_SMF_NO_MEMORY);
if (smf_enable_instance(instance, 0))
} else {
}
} else {
if (smf_enable_instance(instance, 0))
}
return (ret);
}
/*
* Delete a specified instance. Return SMBD_SMF_OK for success.
*/
int
{
int ret = SMBD_SMF_OK;
return (SMBD_SMF_SYSTEM_ERR);
return (ret);
} else {
}
} else {
}
return (ret);
}
/*
* smb_smf_create_service_pgroup(handle, pgroup)
*
* create a new property group at service level.
*/
int
{
int ret = SMBD_SMF_OK;
int err;
return (SMBD_SMF_SYSTEM_ERR);
}
/*
* only create a handle if it doesn't exist. It is ok to exist
* since the pg handle will be set as a side effect.
*/
/*
* if the pgroup exists, we are done. If it doesn't, then we
* need to actually add one to the service instance.
*/
/* doesn't exist so create one */
if (err != SCF_ERROR_NONE)
switch (err) {
break;
default:
break;
}
}
}
return (ret);
}
/*
* smb_smf_create_instance_pgroup(handle, pgroup)
*
* create a new property group at instance level.
*/
int
{
int ret = SMBD_SMF_OK;
int err;
return (SMBD_SMF_SYSTEM_ERR);
}
/*
* only create a handle if it doesn't exist. It is ok to exist
* since the pg handle will be set as a side effect.
*/
/*
* if the pgroup exists, we are done. If it doesn't, then we
* need to actually add one to the service instance.
*/
/* doesn't exist so create one */
if (err != SCF_ERROR_NONE)
switch (err) {
break;
default:
break;
}
}
}
return (ret);
}
/*
* smb_smf_delete_service_pgroup(handle, pgroup)
*
* remove the property group from the current service.
* but only if it actually exists.
*/
int
{
int ret = SMBD_SMF_OK;
int err;
return (SMBD_SMF_SYSTEM_ERR);
}
/*
* only create a handle if it doesn't exist. It is ok to exist
* since the pg handle will be set as a side effect.
*/
/*
* only delete if it does exist.
*/
/* does exist so delete it */
if (err != SCF_ERROR_NONE) {
smb_smf_scf_log_error("SMF delpg "
"problem: %s\n");
}
}
} else {
if (err != SCF_ERROR_NONE)
smb_smf_scf_log_error("SMF getpg problem: %s\n");
}
if (ret == SMBD_SMF_SYSTEM_ERR &&
scf_error() == SCF_ERROR_PERMISSION_DENIED) {
}
return (ret);
}
/*
* smb_smf_delete_instance_pgroup(handle, pgroup)
*
* remove the property group from the current instance.
* but only if it actually exists.
*/
int
{
int ret = SMBD_SMF_OK;
int err;
return (SMBD_SMF_SYSTEM_ERR);
/*
* only create a handle if it doesn't exist. It is ok to exist
* since the pg handle will be set as a side effect.
*/
/*
* only delete if it does exist.
*/
/* does exist so delete it */
if (err != SCF_ERROR_NONE) {
smb_smf_scf_log_error("SMF delpg "
"problem: %s\n");
}
}
} else {
if (err != SCF_ERROR_NONE)
smb_smf_scf_log_error("SMF getpg problem: %s\n");
}
if (ret == SMBD_SMF_SYSTEM_ERR &&
return (ret);
}
/*
* Start transaction on current pg in handle.
* The pg could be service or instance level.
* Must be called after pg handle is obtained
* from create or get.
*/
int
{
int ret = SMBD_SMF_OK;
return (SMBD_SMF_SYSTEM_ERR);
/*
* lookup the property group and create it if it doesn't already
* exist.
*/
if (ret == SMBD_SMF_OK) {
}
} else {
}
}
}
if (ret == SMBD_SMF_SYSTEM_ERR &&
return (ret);
}
/*
* smb_smf_end_transaction(handle)
*
* Commit the changes that were added to the transaction in the
* handle. Do all necessary cleanup.
*/
int
{
int ret = SMBD_SMF_OK;
return (SMBD_SMF_SYSTEM_ERR);
} else {
smb_smf_scf_log_error("Failed to commit "
"transaction: %s");
}
}
return (ret);
}
/*
* Deletes property in current pg
*/
int
{
int ret = SMBD_SMF_OK;
return (SMBD_SMF_SYSTEM_ERR);
/*
* properties must be set in transactions and don't take
*/
propname) != 0) {
}
} else {
}
if (ret == SMBD_SMF_SYSTEM_ERR) {
switch (scf_error()) {
break;
}
}
/*
* cleanup if there were any errors that didn't leave these
* values where they would be cleaned up later.
*/
return (ret);
}
/*
* Sets string property in current pg
*/
int
{
int ret = SMBD_SMF_OK;
return (SMBD_SMF_SYSTEM_ERR);
/*
* properties must be set in transactions and don't take
*/
propname, SCF_TYPE_ASTRING) == 0 ||
propname, SCF_TYPE_ASTRING) == 0) {
}
/* the value is in the transaction */
} else {
/* value couldn't be constructed */
}
/* the entry is in the transaction */
} else {
}
} else {
}
if (ret == SMBD_SMF_SYSTEM_ERR) {
switch (scf_error()) {
break;
}
}
/*
* cleanup if there were any errors that didn't leave these
* values where they would be cleaned up later.
*/
return (ret);
}
/*
* Gets string property value.upto sz size.
* Caller is responsible to have enough memory allocated.
*/
int
{
int ret = SMBD_SMF_OK;
return (SMBD_SMF_SYSTEM_ERR);
}
} else {
}
} else {
}
return (ret);
}
/*
* Set integer value of property.
* The value is returned as int64_t value
* Caller ensures appropriate translation.
*/
int
{
int ret = SMBD_SMF_OK;
return (SMBD_SMF_SYSTEM_ERR);
/*
* properties must be set in transactions and don't take
*/
propname, SCF_TYPE_INTEGER) == 0 ||
propname, SCF_TYPE_INTEGER) == 0) {
}
/* the value is in the transaction */
}
/* the entry is in the transaction */
} else {
}
if (ret == SMBD_SMF_SYSTEM_ERR) {
switch (scf_error()) {
break;
}
}
/*
* cleanup if there were any errors that didn't leave these
* values where they would be cleaned up later.
*/
return (ret);
}
/*
* Gets integer property value.
* Caller is responsible to have enough memory allocated.
*/
int
{
int ret = SMBD_SMF_OK;
return (SMBD_SMF_SYSTEM_ERR);
valint) != 0) {
}
} else {
}
} else {
}
return (ret);
}
/*
* Set boolean value of property.
* The value is returned as int64_t value
* Caller ensures appropriate translation.
*/
int
{
int ret = SMBD_SMF_OK;
return (SMBD_SMF_SYSTEM_ERR);
/*
* properties must be set in transactions and don't take
*/
propname, SCF_TYPE_BOOLEAN) == 0 ||
propname, SCF_TYPE_BOOLEAN) == 0) {
}
/* the value is in the transaction */
}
/* the entry is in the transaction */
} else {
}
if (ret == SMBD_SMF_SYSTEM_ERR) {
switch (scf_error()) {
break;
}
}
/*
* cleanup if there were any errors that didn't leave these
* values where they would be cleaned up later.
*/
return (ret);
}
/*
* Gets boolean property value.
* Caller is responsible to have enough memory allocated.
*/
int
{
int ret = SMBD_SMF_OK;
return (SMBD_SMF_SYSTEM_ERR);
valbool) != 0) {
}
} else {
}
} else {
}
return (ret);
}
/*
* Sets a blob property value.
*/
int
{
int ret = SMBD_SMF_OK;
return (SMBD_SMF_SYSTEM_ERR);
/*
* properties must be set in transactions and don't take
*/
propname, SCF_TYPE_OPAQUE) == 0 ||
propname, SCF_TYPE_OPAQUE) == 0) {
}
/* the value is in the transaction */
} else {
/* value couldn't be constructed */
}
/* the entry is in the transaction */
} else {
}
} else {
}
if (ret == SMBD_SMF_SYSTEM_ERR) {
switch (scf_error()) {
break;
}
}
/*
* cleanup if there were any errors that didn't leave these
* values where they would be cleaned up later.
*/
return (ret);
}
/*
* Gets a blob property value.
* Caller is responsible to have enough memory allocated.
*/
int
{
int ret = SMBD_SMF_OK;
return (SMBD_SMF_SYSTEM_ERR);
}
} else {
}
} else {
}
return (ret);
}
/*
* Get property based on property type. Returns string value of that
* property. Only SCF_TYPE_ASTRING, SCF_TYPE_INTEGER, SCF_TYPE_BOOLEAN
* supported.
*/
int
{
int ret = SMBD_SMF_OK;
switch (proptype) {
case SCF_TYPE_ASTRING:
break;
case SCF_TYPE_INTEGER:
&valint)) != 0)
return (ret);
break;
case SCF_TYPE_BOOLEAN:
&valbool)) != 0)
return (ret);
break;
default:
return (SMBD_SMF_SYSTEM_ERR);
}
return (ret);
}
/*
* Set property based on property type.
* Only SCF_TYPE_ASTRING, SCF_TYPE_INTEGER, SCF_TYPE_BOOLEAN supported.
*/
int
{
int ret = SMBD_SMF_OK;
switch (proptype) {
case SCF_TYPE_ASTRING:
valstr);
break;
case SCF_TYPE_INTEGER:
valint);
break;
case SCF_TYPE_BOOLEAN:
valbool = 1;
break;
default:
return (SMBD_SMF_SYSTEM_ERR);
}
return (ret);
}
/*
* Gets an instance iterator for the service specified.
*/
smb_smf_get_iterator(char *svc_name)
{
if (!handle)
return (NULL);
if (handle->scf_inst_iter) {
handle->scf_service) != 0) {
} else {
}
} else {
}
return (handle);
}
/*
* smb_smf_scf_init()
*
* must be called before using any of the SCF functions.
* Returns smb_scfhandle_t pointer if success.
*/
smb_smf_scf_init(char *svc_name)
{
goto err;
!= SCF_SUCCESS) {
goto err;
}
} else {
goto err;
}
} else {
smb_smf_scf_log_error("Could not access SMF "
"repository: %s\n");
}
}
return (handle);
err:
(void) smb_smf_scf_fini(handle);
(void) smb_smf_scf_log_error("SMF initialization problem: %s\n");
return (NULL);
}
/*
* smb_smf_scf_fini(handle)
*
* must be called when done. Called with the handle allocated in
* smb_smf_scf_init(), it cleans up the state and frees any SCF resources
* still in use.
*/
void
{
int unbind = 0;
unbind = 1;
if (unbind)
}
}