Solaris_NFSShare.c revision 7c478bd95313f5f23a4c958a745db2134aa03244
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License, Version 1.0 only
* (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 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include "Solaris_NFSShare.h"
#include "nfs_keys.h"
#include "nfs_provider_names.h"
#include "nfs_providers_msgstrings.h"
#include "messageStrings.h"
#include "cmdgen.h"
#include "util.h"
#include "libfsmgt.h"
#include "createprop_methods.h"
#include <string.h>
#include <errno.h>
#include <signal.h>
#include <fcntl.h>
/*
* Constants
*/
/* #define SOLARIS_NFSSHARE "Solaris_NFSShare" */
#define NFSD 0
#define MOUNTD 1
/*
* Private method declarations
*/
static CIMBool check_for_PersistentShareEnt(
static CCIMInstanceList *enumerate_shares();
char *hostname,
char *hostname,
int *err);
/*
* Public methods
*/
/*
* Instance provider methods
*/
/*
* Solaris_NFSShare provider
*
* It is important to note that all memory allocated by these functions
* and passed to the CIMOM, is freed by the CIMOM as the caller.
*/
/*
* Name: cp_enumInstances_Solaris_NFSShare
*
* Description: Creates a list of instances and returns that list.
*
* Parameters:
* shareOP - An CCIMObjectPath * which contains the information on
* the class for which to find the instance.
* Returns:
* CCIMInstanceList * if matched instance is found. Otherwise, NULL.
*/
/* ARGSUSED */
{
int err = 0;
/*
* Check object path for NULL value
*/
"SOLARIS_NFSSHARE::ENUM_INSTANCES",
return ((CCIMInstanceList *)NULL);
}
cim_logDebug("cp_enumInstances_Solaris_NFSShare",
"Calling enumerate_shares");
instList = enumerate_shares();
cim_logDebug("cp_enumInstances_Solaris_NFSShare",
"Call from enumerate_sharesreturned NULL");
}
return (instList);
}
/*
* Name: cp_enumInstanceNames_Solaris_NFSShare
*
* Description: Returns a list of instances if found.
*
* Parameters:
* shareOP - An CCIMObjectPath * which contains the information on
* the class for which to find the instance.
* Returns:
* CCIMObjectPathList * if matched instance is found. Otherwise, NULL.
*/
{
int err = 0;
/*
* Check object path for NULL value
*/
util_handleError("SOLARIS_NFSSHARE::ENUM_INSTANCENAMES",
return ((CCIMObjectPathList *)NULL);
}
return ((CCIMObjectPathList *)NULL);
}
return (ObjPathList);
}
/*
* Name: cp_getInstance_Solaris_NFSShare
*
* Description: Returns an instance which matches the passed in object path
* if found.
*
* Parameters:
* shareOP - An CCIMObjectPath * which contains the information on
* the class for which to find the instance.
* Returns:
* CCIMInstance * if matched instance is found. Otherwise, NULL.
*/
/* ARGSUSED */
{
int err = 0;
/*
* Check object path for NULL value
*/
util_handleError("SOLARIS_NFSSHARE::ENUM_INSTANCENAMES",
return ((CCIMInstance *)NULL);
}
return ((CCIMInstance *)NULL);
}
ex = cim_getLastError();
util_handleError("SOLARIS_NFSSHARE::ENUM_INSTANCE",
return ((CCIMInstance *)NULL);
}
return (inst);
}
/*
* cp_setInstanceWithList not supported
*/
/* ARGSUSED */
{
int err = 0;
util_handleError("SOLARIS_NFSSHARE::SET_INSTANCEWITHLIST",
return (cim_false);
}
/*
* cp_setInstance not supported
*/
/* ARGSUSED */
{
int err = 0;
util_handleError("SOLARIS_NFSSHARE::SET_INSTANCE",
return (cim_false);
}
/*
* cp_invokeMethod not supported
*/
/* ARGSUSED */
{
int err = 0;
util_handleError("SOLARIS_NFSSHARE::INVOKE_METHOD",
return ((CCIMProperty *)NULL);
}
/*
* cp_setProperty not supported
*/
/* ARGSUSED */
{
int err = 0;
util_handleError("SOLARIS_NFSSHARE::SET_PROPERTY",
return (cim_false);
}
/*
* Name: cp_createInstance_Solaris_NFSShare
*
* Description: Returns the instance created based on the instance
* inforamtion passed in. A create instance will actually
* share a file system on the current host by calling
* cmd_execute_command_and_retrieve_string() from the cmd
* interface.
*
* Parameters:
* shareOP - An CCIMObjectPath * which contains the information on
* the class for which to find the instance.
* shareInst - an instance that contains the properties for the share
* to be created.
* Returns:
* CCIMObjectPath * - Object path containing the new instance. On
* failure NULL is returned.
*/
{
char *cmd_return, *cmd;
int err = 0;
cim_logDebug("cp_createInstance_Solaris_NFSShare",
"Entering create instance...");
"SOLARIS_NFSSHARE::CREATE_INSTANCE",
return ((CCIMObjectPath *)NULL);
}
&err);
"SOLARIS_NFSSHARE::CREATE_INSTANCE",
return ((CCIMObjectPath *)NULL);
}
if (err != 0) {
/*
* An error occured while executing the command.
*/
if (cmd_return != NULL) {
"SOLARIS_NFSSHARE::CREATE_INSTANCE",
return ((CCIMObjectPath *)NULL);
} else {
"SOLARIS_NFSSHARE::CREATE_INSTANCE",
return ((CCIMObjectPath *)NULL);
}
}
if (nfsShareInstance == NULL) {
/*
* The share instance was not found. The create
* instance failed.
*/
"SOLARIS_NFSSHARE::CREATE_INSTANCE",
return ((CCIMObjectPath *)NULL);
}
if ((nfsShareObjectPath =
ex = cim_getLastError();
util_handleError("SOLARIS_NFSSHARE::CREATE_INSTANCE",
return ((CCIMObjectPath *)NULL);
}
if ((share_Prop != NULL) &&
char error_string[MAXSIZE];
MAXSIZE);
if (cmd_return == NULL) {
"SOLARIS_NFSSHARE::CREATE_INSTANCE",
} else {
char return_string[MAXSIZE];
MAXSIZE);
MAXSIZE);
"SOLARIS_NFSSHARE::CREATE_INSTANCE",
}
}
err = 0;
char error_string[MAXSIZE];
MAXSIZE);
if (cmd_return == NULL) {
"SOLARIS_NFSSHARE::CREATE_INSTANCE",
} else {
char return_string[MAXSIZE];
MAXSIZE);
MAXSIZE);
"SOLARIS_NFSSHARE::CREATE_INSTANCE",
}
}
}
return (nfsShareObjectPath);
} /* cp_createInstance_Solaris_NFSShare */
/*
* Name: cp_deleteInstance_Solaris_NFSShare
*
* Description: The delete instance will unshare a file system on the
* current host by calling
* cmd_execute_command_and_retrieve_string() from the cmd
* interface.
*
* Parameters:
* shareOP - An CCIMObjectPath * - The object path coresponding to the
* instance to be removed.
* Returns:
* CIMBool - Returns cim_true on successful completion. On failure
* cim_false is returned.
*/
{
char *cmd, *cmd_return;
int err = 0;
util_handleError("SOLARIS_NFSSHARE::DELETE_INSTANCE",
return (cim_false);
}
/*
* Get the share that is to be deleted and generatel the
* unshare command.
*/
&err);
"SOLARIS_NFSSHARE::CREATE_INSTANCE",
}
return (cim_false);
}
/*
* Execute the unshare command.
*/
if (err != 0) {
/*
* The unshare command execution failed.
*/
if (cmd_return != NULL) {
util_handleError("SOLARIS_NFSSHARE::DELETE_INSTANCE",
return (cim_false);
} else {
util_handleError("SOLARIS_NFSSHARE::DELETE_INSTANCE",
return (cim_false);
}
}
return (cim_true);
}
/*
* Name: cp_execQuery_Solaris_NFSShare
*
* Description: Builds a list of all instances, prepends the list with an
* empty instance, and returns the instance list. The CIMOM
* interprets the initial empty instance to mean that it has
* to do the filtering. The caller is responsible for freeing
* the memory allocated for the returned object.
*
* Parameters:
* CCIMObjectPath *shareOP - An objectpath which represents the class to
* work on
* char *electClause - The select clause
* char *nonJoinExp - The non join expression
* char *queryExp - The query Expression
* char *queryLang - The Query Language used (s/b "WQL")
*
* Returns:
* Returns the prepended instance list. On error NULL is returned.
*/
/* ARGSUSED */
{
int err = 0;
return ((CCIMInstanceList *)NULL);
}
if ((nfsShareInstList =
util_handleError("SOLARIS_NFSSHARE::EXEC_QUERY",
return ((CCIMInstanceList *)NULL);
}
ex = cim_getLastError();
util_handleError("SOLARIS_NFSSHARE::EXEC_QUERY",
return ((CCIMInstanceList *)NULL);
}
if ((nfsShareInstList =
ex = cim_getLastError();
util_handleError("SOLARIS_NFSSHARE::EXEC_QUERY",
return ((CCIMInstanceList *)NULL);
}
return (nfsShareInstList);
} /* cp_execQuery_Solaris_NFSShare */
/*
* Property provider methods
*/
{
int err = 0;
util_handleError("SOLARIS_NFSSHARE::GET_PROPERTY",
return ((CCIMProperty *)NULL);
}
return ((CCIMProperty *)NULL);
}
return (nfsShareProp);
} /* cp_getProperty_Solaris_NFSShare */
/*
* Not supported
*/
/* ARGSUSED */
{
int err = 0;
util_handleError("SOLARIS_NFSSHARE::SET_PROPERTY",
return (cim_false);
} /* cp_setProperty_Solaris_NFShare */
/*
* Private Methods
*/
/*
* Checks for a persistent share entry for the current share.
*/
{
if (nfsPersistentShareOP == NULL) {
ex = cim_getLastError();
"SOLARIS_NFSSHARE::POPULATE_PROPLIST",
} else {
if (nfsPersistShareOPList != NULL) {
if (nfsPersistShareProp == NULL) {
continue;
}
nfsPersistShareProp->mValue) == 0) {
break;
}
}
} else {
ex = cim_getLastError();
"SOLARIS_NFSSHARE::",
}
}
return (nfsPersistValue);
} /* check_for_PersistentShareEnt */
/*
* Enumerate the nfs shares by using the fs_shares fs_get_share_list
* method
*/
static CCIMInstanceList *
{
int err = 0;
char *hostname;
/*
* retrieve system name
*/
"SOLARIS_NFSSHARE::POPULATE_PROPVALUES",
return ((CCIMInstanceList *)NULL);
}
if (nfs_share_list == NULL) {
/*
* Check whether an error was returned or if we simply don't
* have any nfs shares on the system. If err is not
* equal to 0, an error was encountered.
*/
if (err != 0) {
/*
* Determine the error and log it.
*/
"SOLARIS_NFSSHARE::ENUMERATE_SHARES",
return ((CCIMInstanceList *)NULL);
"SOLARIS_NFSSHARE::ENUMERATE_SHARES",
&err);
/*
* We don't have any nfs shares
*/
cim_logDebug("enumerate_shares",
"There are no shares on the host.");
return ((CCIMInstanceList *)NULL);
} else {
/*
* If any other errors were encountered it
* can be handled as a general error. We may
* not know exactly what the error is.
*/
"SOLARIS_NFSSHARE::enumerate_shares",
return ((CCIMInstanceList *)NULL);
}
}
return ((CCIMInstanceList *)NULL);
} else {
/*
* At this point, one or more nfs shares were found on the
* system, create the instance list from the nfs_share_list.
*/
cim_logDebug("enumerate_shares",
"There were shares found on the system.");
if (nfsShareInstList == NULL) {
ex = cim_getLastError();
util_handleError("SOLARIS_NFSSHARE::enumerate_shares",
return ((CCIMInstanceList *)NULL);
}
/*
* Loop through the nfs shares to retrieve their properties
* and create an instance list containing all the shares and
* their properties.
*/
while (nfs_share_list != NULL) {
/*
* Create the Solaris_NFSShare CCIMInstance
*/
if (solaris_NFSShare_instance == NULL) {
ex = cim_getLastError();
"SOLARIS_NFSSHARE::enumerate_shares",
return ((CCIMInstanceList *)NULL);
}
if (solaris_NFSShare_prop_list == NULL) {
/*
* populatePropertyList already logged this
* error so there is no need to log it here.
*/
return ((CCIMInstanceList *)NULL);
}
/*
* Add the property list to the instance
*/
if (solaris_NFSShare_instance == NULL) {
ex = cim_getLastError();
"SOLARIS_NFSSHARE::enumerate_shares",
return ((CCIMInstanceList *)NULL);
}
/*
* Add the instance to the instance list
*/
if (nfsShareInstList == NULL) {
ex = cim_getLastError();
"SOLARIS_NFSSHARE::enumerate_shares",
return ((CCIMInstanceList *)NULL);
}
} /* while (nfs_share_list != NULL) */
} /* if (nfs_share_list == NULL) */
return (nfsShareInstList);
} /* enumerate_shares() */
/*
* Populates the property list with that share information for each
* instance in the instance list.
*/
/* ARGSUSED */
static CCIMPropertyList *
{
int i, err = 0;
cim_logDebug("populate_Solaris_NFSShare_property_list",
"Just entering...");
if (nfsSharePropList == NULL) {
ex = cim_getLastError();
"SOLARIS_NFSSHARE::POPULATE_PROPLIST",
return ((CCIMPropertyList *)NULL);
}
/*
* Create the CCIMProperties for this instance
*/
"SOLARIS_NFSSHARE::POPULATE_PROPLIST",
return ((CCIMPropertyList *)NULL);
}
for (i = 0; i < PROPCOUNT; i++) {
cim_logDebug("populate_Solaris_NFSShare_property_list",
"propValues[%d] = %s", i, propValues[i]);
if (nfsSharePropList == NULL) {
break;
}
}
return (nfsSharePropList);
} /* populate_Solaris_NFSShare_property_list */
/*
* populate_Solaris_NFSShare_property_Values
* Populates the property array for use in the populate_property_list function
*/
static CIMBool
char *hostname,
int *err)
{
int defaultValue = 0;
char *optValue;
cim_logDebug("populate_Solaris_NFSShare_property_Values",
"Just entering...");
/*
* Allow access control
*/
optValue);
} else {
return (cim_false);
}
/*
* Key - creation class name
*/
/*
* Description
*/
} else {
}
/*
* Effective user ID "anon"
*/
optValue);
} else {
return (cim_false);
}
/*
* Ignore setuid "nosuid"
*/
optValue);
} else {
return (cim_false);
}
/*
* Enable logging, use log file tag "log"
*/
MAXSIZE);
} else {
/*
* Logging not enabled
*/
"populate_Solaris_NFSShare_property_Values",
"No log property for this share");
} else {
}
}
} else {
return (cim_false);
}
/*
* Key - Shared Path
*/
/*
* Persistent share entry
*/
/*
* No subdirectory mounts "nosub"
*/
optValue);
} else {
return (cim_false);
}
/*
* Public filehandle "public"
*/
} else {
return (cim_false);
}
/*
* Share option string
*/
/*
* Key - System Creation class name
*/
/*
* Key - System name
*/
hostname);
return (cim_true);
} /* populate_Solaris_NFSShare_property_Values */
/*
* start_daemons
*
* Starts the nfsd and mountd daemons based on which daemon is requested
* in which_daemon. The string returned from the execution of the damon
* command is returned.
*/
static char *
{
char *pidfile;
char *cmd_return = NULL;
int pid_kill = 0;
switch (which_daemon) {
case NFSD:
pidfile = "/etc/svc/volatile/nfs-server.lock";
break;
case MOUNTD:
pidfile = "/etc/svc/volatile/nfs-mountd.lock";
break;
default:
return (NULL);
}
*err = 0;
err);
return (cmd_return);
} else {
return (cmd_return);
}
}
cim_logDebug("start_daemons",
"Can not read from file %s - %s\n",
return (NULL);
}
if (pid_kill == 0) {
/*
* Setting error to EEXIST so that the error returned
* tells the caller that the daemon already exists.
*/
cim_logDebug("start_daemon",
"Terminated - nfsd(%ld) already running.\n", pid);
/*
* ESRCH indicates that there is no such process and
* the daemon needs to be started.
*/
*err = 0;
} else {
cim_logDebug("start_daemon",
}
return (cmd_return);
} /* start_daemons */