|
From: <np...@us...> - 2006-11-02 21:50:56
|
Revision: 17
http://svn.sourceforge.net/omc/?rev=17&view=rev
Author: npaxton
Date: 2006-11-02 13:50:53 -0800 (Thu, 02 Nov 2006)
Log Message:
-----------
Initial TimeZoneSettingData object management
Modified Paths:
--------------
cmpibase/trunk/configure
cmpibase/trunk/src/include/omc/base.h
cmpibase/trunk/src/include/omc/cmpiTimeServiceUtils.h
cmpibase/trunk/src/include/omc/ntpServer.h
cmpibase/trunk/src/lib/omc/base.c
cmpibase/trunk/src/lib/omc/cmpiTimeServiceUtils.c
cmpibase/trunk/src/lib/omc/ntpServer.c
cmpibase/trunk/src/providers/computer-system/hostNameSettingData.c
cmpibase/trunk/src/providers/time-service/remoteTimeServicePort.c
cmpibase/trunk/src/providers/time-service/timeZoneSettingData.c
Modified: cmpibase/trunk/configure
===================================================================
--- cmpibase/trunk/configure 2006-11-02 19:02:03 UTC (rev 16)
+++ cmpibase/trunk/configure 2006-11-02 21:50:53 UTC (rev 17)
@@ -25081,7 +25081,7 @@
done
- ac_config_files="$ac_config_files Makefile src/Makefile src/lib/Makefile src/lib/omc/Makefile src/include/Makefile src/include/omc/Makefile src/providers/Makefile src/providers/processes/Makefile src/providers/computer-system/Makefile src/providers/operating-system/Makefile"
+ ac_config_files="$ac_config_files Makefile src/Makefile src/lib/Makefile src/lib/omc/Makefile src/include/Makefile src/include/omc/Makefile src/providers/Makefile src/providers/processes/Makefile src/providers/computer-system/Makefile src/providers/operating-system/Makefile src/providers/time-service/Makefile"
cat >confcache <<\_ACEOF
# This file is a shell script that caches the results of configure
@@ -25666,6 +25666,7 @@
"src/providers/processes/Makefile" ) CONFIG_FILES="$CONFIG_FILES src/providers/processes/Makefile" ;;
"src/providers/computer-system/Makefile" ) CONFIG_FILES="$CONFIG_FILES src/providers/computer-system/Makefile" ;;
"src/providers/operating-system/Makefile" ) CONFIG_FILES="$CONFIG_FILES src/providers/operating-system/Makefile" ;;
+ "src/providers/time-service/Makefile" ) CONFIG_FILES="$CONFIG_FILES src/providers/time-service/Makefile" ;;
"$ac_config_libobj_dir/fnmatch.h" ) CONFIG_LINKS="$CONFIG_LINKS $ac_config_libobj_dir/fnmatch.h:$ac_config_libobj_dir/fnmatch_.h" ;;
"depfiles" ) CONFIG_COMMANDS="$CONFIG_COMMANDS depfiles" ;;
"config.h" ) CONFIG_HEADERS="$CONFIG_HEADERS config.h" ;;
Modified: cmpibase/trunk/src/include/omc/base.h
===================================================================
--- cmpibase/trunk/src/include/omc/base.h 2006-11-02 19:02:03 UTC (rev 16)
+++ cmpibase/trunk/src/include/omc/base.h 2006-11-02 21:50:53 UTC (rev 17)
@@ -119,6 +119,7 @@
const char *rpmName);
+
#ifdef __cplusplus
}
#endif
Modified: cmpibase/trunk/src/include/omc/cmpiTimeServiceUtils.h
===================================================================
--- cmpibase/trunk/src/include/omc/cmpiTimeServiceUtils.h 2006-11-02 19:02:03 UTC (rev 16)
+++ cmpibase/trunk/src/include/omc/cmpiTimeServiceUtils.h 2006-11-02 21:50:53 UTC (rev 17)
@@ -82,7 +82,41 @@
CMPIStatus *pStatus,
const char **properties);
+
+
+CMPIObjectPath*
+makeTimeZoneSettingDataObjectPath(
+ const CMPIBroker *broker,
+ const char *ns,
+ CMPIStatus *pStatus);
+
+
+CMPIInstance *
+makeTimeZoneSettingDataInstance(
+ const CMPIBroker *broker,
+ const char *ns,
+ CMPIStatus *pStatus,
+ const char **properties);
+
+
+
+
+
int isIPV4Address(const char *arg);
+/**
+ * Get the timezone, time, and whether UTC
+ * @param: timezone [out] preallocated string for timezone
+ * @param: timezonelen [in] length of timezone - num bytes
+ * allocated
+ * @param: utcHwClock [out] int* whether UTC or not
+ */
+void
+omcGetClockInfo(
+ char *timezone,
+ int timezoneLen,
+ int *utcHwClock);
+
+
#endif // TIME_SERVICE_UTILS_H_GUARD__
Modified: cmpibase/trunk/src/include/omc/ntpServer.h
===================================================================
--- cmpibase/trunk/src/include/omc/ntpServer.h 2006-11-02 19:02:03 UTC (rev 16)
+++ cmpibase/trunk/src/include/omc/ntpServer.h 2006-11-02 21:50:53 UTC (rev 17)
@@ -46,13 +46,65 @@
} NTPServer;
-NTPServer *getNTPServers(int *pCount);
-int getNTPServer(const char *serverName, NTPServer *out);
-int deleteNTPServer(const char *serverName);
-int setNTPServer(NTPServer *server);
-void copyNTPServer(const NTPServer *in, NTPServer *out);
-NTPServer *createAndCopyNTPServer(const NTPServer *in);
+/*
+ Determine if the local computer supports NTPServer
+*/
+int
+serverSupportsNTP();
+/*
+ get an array of NTPServers with [pCount] elements
+ Caller is responsible to free the pointer returned
+*/
+NTPServer *
+getNTPServers(
+ int *pCount);
+
+
+/*
+ get the NTPServer that corresponds with [serverName]
+ Caller is responsible to free the pointer returned
+*/
+NTPServer *
+getNTPServer(
+ const char *serverName);
+
+
+/*
+ delete the NTPServer that corresponds with [serverName]
+*/
+int
+deleteNTPServer(
+ const char *serverName);
+
+
+/*
+ modify the settings of NTPServer that corresponds with [oldServerName]
+*/
+int
+setNTPServer(
+ const char *oldServerName,
+ NTPServer *server);
+
+
+/*
+ c version of assignment operator
+*/
+void
+copyNTPServer(
+ const NTPServer *in,
+ NTPServer *out);
+
+
+/*
+ c version of copy constructor
+ Caller is responsible to free the pointer returned
+*/
+NTPServer *
+createAndCopyNTPServer(
+ const NTPServer *in);
+
+
#endif // NTP_SERVER_UTILS_H_GUARD__
Modified: cmpibase/trunk/src/lib/omc/base.c
===================================================================
--- cmpibase/trunk/src/lib/omc/base.c 2006-11-02 19:02:03 UTC (rev 16)
+++ cmpibase/trunk/src/lib/omc/base.c 2006-11-02 21:50:53 UTC (rev 17)
@@ -138,20 +138,20 @@
size_t hostNameOutLen)
{
char namebuf[256];
- if (!hostNameOut || !hostNameOutLen)
+ if (!hostNameOut || !hostNameOutLen)
{
errno = EINVAL;
return NULL;
}
gethostname(namebuf, sizeof(namebuf));
- if (!strchr(namebuf, '.'))
+ if (!strchr(namebuf, '.'))
{
char lbuf[2048];
int herr = 0;
struct hostent hostbuf;
struct hostent* hent = &hostbuf;
- if (gethostbyname_r(namebuf, &hostbuf, lbuf, sizeof(lbuf),
- &hent, &herr) != 0)
+ if (gethostbyname_r(namebuf, &hostbuf, lbuf, sizeof(lbuf),
+ &hent, &herr) != 0)
{
hent = NULL;
}
@@ -225,4 +225,3 @@
return 0;
}
-
Modified: cmpibase/trunk/src/lib/omc/cmpiTimeServiceUtils.c
===================================================================
--- cmpibase/trunk/src/lib/omc/cmpiTimeServiceUtils.c 2006-11-02 19:02:03 UTC (rev 16)
+++ cmpibase/trunk/src/lib/omc/cmpiTimeServiceUtils.c 2006-11-02 21:50:53 UTC (rev 17)
@@ -32,6 +32,7 @@
#include <omc/cmpiTimeServiceUtils.h>
#include <omc/ntpServer.h>
+#include <omc/ioUtils.h>
#include <fnmatch.h>
#include <ctype.h>
@@ -66,6 +67,11 @@
NULL};
+static const char * timezoneSettingDataClassKeys[] = {
+ "InstanceID",
+ NULL};
+
+
/*****************************************************************************/
CMPIObjectPath *
makeTimeServiceObjectPath(
@@ -225,10 +231,9 @@
CMPIObjectPath *op = makeRemoteTimeServicePortObjectPath(broker, ns, serverName, pStatus);
if (!CMIsNullObject(op) && (pStatus->rc == CMPI_RC_OK))
{
- NTPServer *server = malloc(sizeof(NTPServer));
+ NTPServer *server = getNTPServer(serverName);
if (server)
{
- getNTPServer(serverName, server);
instance = CMNewInstance(broker, op, pStatus);
if (!CMIsNullObject(instance) && (pStatus->rc == CMPI_RC_OK))
{
@@ -314,6 +319,7 @@
if(server->maxPoll)
CMSetProperty(instance, "maxpoll", (CMPIValue*)&(server->maxPoll), CMPI_uint16);
}
+ free(server);
}
}
return instance;
@@ -322,6 +328,69 @@
/*****************************************************************************/
+CMPIObjectPath*
+makeTimeZoneSettingDataObjectPath(
+ const CMPIBroker *broker,
+ const char *ns,
+ CMPIStatus *pStatus)
+{
+ CMPIObjectPath *op = CMNewObjectPath(broker, ns, "OMC_TimeZoneSettingData", pStatus);
+ if (!CMIsNullObject(op) && (pStatus->rc == CMPI_RC_OK))
+ {
+ char name[128] = {0};
+ omcGetComputerSystemName(name, sizeof(name));
+
+ CMAddKey(op,
+ "InstanceID",
+ (CMPIValue *)"omc:timezone",
+ CMPI_chars);
+ }
+ return op;
+}
+
+
+
+/*****************************************************************************/
+CMPIInstance *
+makeTimeZoneSettingDataInstance(
+ const CMPIBroker *broker,
+ const char *ns,
+ CMPIStatus *pStatus,
+ const char **properties)
+{
+ CMPIInstance *instance = NULL;
+ CMPIObjectPath *op = makeTimeZoneSettingDataObjectPath(broker, ns, pStatus);
+ if (!CMIsNullObject(op) && (pStatus->rc == CMPI_RC_OK))
+ {
+ char timezone[32] = {0};
+ int utcHwClock = 1;
+
+ omcGetClockInfo(timezone, 32, &utcHwClock);
+
+ instance = CMNewInstance(broker, op, pStatus);
+ if (!CMIsNullObject(instance) && (pStatus->rc == CMPI_RC_OK))
+ {
+ CMSetPropertyFilter(instance, properties, timezoneSettingDataClassKeys);
+ // keys
+ CMSetProperty(instance,
+ "InstanceID",
+ (CMPIValue *)"omc:timezone",
+ CMPI_chars);
+
+ CMSetProperty(instance,
+ "TimeZone",
+ (CMPIValue *)timezone,
+ CMPI_chars);
+
+ CMSetProperty(instance, "UTCHardwareClock", (CMPIValue*)&utcHwClock, CMPI_boolean);
+ }
+ }
+ return instance;
+}
+
+
+
+/*****************************************************************************/
int
isIPV4Address(const char *arg)
{
@@ -342,3 +411,98 @@
return 1;
}
+
+/*****************************************************************************/
+static int
+getKeyValuePair(
+ const char *line,
+ char *key,
+ int keylen,
+ char *value,
+ int valuelen)
+{
+ int retval = 0;
+ char *delim = strchr(line, '=');
+ if(delim)
+ {
+ int localKeyLen = (int)((char*)delim-(char*)line);
+ int localValLen = (int)((char*)(line+strlen(line))-(char*)delim);
+ omcStrNCpy(key, line, (localKeyLen > keylen?keylen:localKeyLen));
+ omcStrTrim(key);
+ omcStrNCpy(value, delim+1, (localValLen > valuelen?valuelen:localValLen));
+ omcStrTrim(value);
+ if (value[0] == '"')
+ {
+ omcStrNCpy(value, value+1, strlen(value)-1 );
+ }
+ if (omcStrEndsWith(value, "\""))
+ {
+ value[strlen(value)-1] = '\0';
+ }
+ retval = 1;
+ }
+
+ return 0;
+}
+
+/*****************************************************************************/
+void omcGetClockInfo(
+ char *timezone,
+ int timezoneLen,
+ int *utcHwClock)
+{
+ FILE *file;
+ unsigned int bfrLen = 0;
+ char *p = NULL, *bufPtr = NULL;
+ //char* errMsgBfr = NULL;
+ //unsigned int errMsgBfrLen = 0;
+
+ DEBUGOUT("Entering omcGetClockInfo\n");
+
+ if (!timezone || !utcHwClock || !timezoneLen)
+ {
+ return;
+ }
+
+ file = fopen("/etc/sysconfig/clock", "r");
+ if (!file)
+ {
+ //errCond(errMsgBfr, errMsgBfrLen, -1,
+ // "Failed to open file /etc/sysconfig/clock");
+ return;
+ }
+
+ char key[32] = {0};
+ char value[256] = {0};
+
+ for(p = omcReadLine(file, &bufPtr, &bfrLen); p;
+ p = omcReadLine(file, &bufPtr, &bfrLen))
+ {
+ DEBUGOUT(" got line: %s\n", bufPtr);
+
+ memset(key, 0, 32);
+ memset(value, 0, 256);
+ getKeyValuePair(bufPtr, key, 32, value, 256);
+ if (strcasecmp(key, "HWCLOCK") == 0)
+ {
+ if (strcasecmp(value, "-u") == 0)
+ {
+ *utcHwClock = 1;
+ }
+ else
+ {
+ *utcHwClock = 0;
+ }
+ }
+ else if (strcasecmp(key, "TIMEZONE") == 0)
+ {
+ omcStrNCpy(timezone, value, timezoneLen);
+ }
+ }
+
+ fclose(file);
+
+ if (bufPtr)
+ free(bufPtr);
+}
+
Modified: cmpibase/trunk/src/lib/omc/ntpServer.c
===================================================================
--- cmpibase/trunk/src/lib/omc/ntpServer.c 2006-11-02 19:02:03 UTC (rev 16)
+++ cmpibase/trunk/src/lib/omc/ntpServer.c 2006-11-02 21:50:53 UTC (rev 17)
@@ -31,6 +31,7 @@
******************************************************************************/
#include <omc/ntpServer.h>
+#include <omc/base.h>
#include <omc/ioUtils.h>
#include <omc/string.h>
@@ -53,6 +54,19 @@
+int
+serverSupportsNTP()
+{
+ unsigned long installDate;
+ installDate = omcGetRPMInstallDate("xntp");
+ if (installDate)
+ {
+ return 1;
+ }
+ return 0;
+}
+
+
char *
lineFromServer(
NTPServer *pServer)
@@ -266,7 +280,7 @@
/*****************************************************************************/
-int getNTPServer(const char *serverName, NTPServer *out)
+NTPServer *getNTPServer(const char *serverName)
{
FILE *file;
unsigned int bfrLen = 0;
@@ -275,16 +289,17 @@
char* errMsgBfr = NULL;
unsigned int errMsgBfrLen = 0;
- if (!serverName || !out)
+ if (!serverName)
{
- return 0;
+ return NULL;
}
file = fopen("/etc/ntp.conf", "r");
if (!file)
{
- return errCond(errMsgBfr, errMsgBfrLen, -1,
+ errCond(errMsgBfr, errMsgBfrLen, -1,
"Failed to open file /etc/ntp.conf");
+ return NULL;
}
for(p = omcReadLine(file, &bufPtr, &bfrLen); p;
@@ -295,13 +310,12 @@
serverFromLine(p, &server);
if(strcasecmp(server.serverName, serverName) == 0)
{
- copyNTPServer(&server, out);
- return 1;
+ return createAndCopyNTPServer(&server);
}
}
}
- return 0;
+ return NULL;
}
@@ -320,7 +334,7 @@
/*****************************************************************************/
-int setNTPServer(NTPServer *server)
+int setNTPServer(const char *oldServerName, NTPServer *server)
{
/*
SetServerListener ssl(server);
Modified: cmpibase/trunk/src/providers/computer-system/hostNameSettingData.c
===================================================================
--- cmpibase/trunk/src/providers/computer-system/hostNameSettingData.c 2006-11-02 19:02:03 UTC (rev 16)
+++ cmpibase/trunk/src/providers/computer-system/hostNameSettingData.c 2006-11-02 21:50:53 UTC (rev 17)
@@ -108,7 +108,7 @@
char* errMsgBfr,
unsigned int errMsgBfrLen)
{
- //DEBUGOUT("%s", "writeLine() called\n");
+ //DEBUGOUT("writeLine() called\n");
// trim this?
if (line[0] == '#')
@@ -191,7 +191,7 @@
static int modifyComputerName(const char *curComputerName,
const char *newComputerName)
{
- DEBUGOUT("%s", "modifyComputerName() called\n");
+ DEBUGOUT("modifyComputerName() called\n");
int bModified = 0;
@@ -226,13 +226,13 @@
char err1[256] = {0};
char err2[256] = {0};
- //DEBUGOUT("%s", "about to call modifyFile on hosts\n");
+ //DEBUGOUT("about to call modifyFile on hosts\n");
int r1 = omcModifyFile("/etc/hosts",
&fms,
err1,
256);
- //DEBUGOUT("%s", "about to call modifyFile on HOSTNAME\n");
+ //DEBUGOUT("about to call modifyFile on HOSTNAME\n");
int r2 = omcModifyFile("/etc/HOSTNAME",
&fms,
err2,
@@ -278,7 +278,7 @@
}
}
//exit:
- DEBUGOUT("%s", "modifyComputerName() returning\n");
+ DEBUGOUT("modifyComputerName() returning\n");
return bModified;
}
@@ -307,7 +307,7 @@
const CMPIResult * results,
const CMPIObjectPath * cop)
{
- DEBUGOUT("%s", "EnumInstanceNames() called\n");
+ DEBUGOUT("EnumInstanceNames() called\n");
CMPIStatus status = {CMPI_RC_OK, NULL};
char * ns = CMGetCharPtr(CMGetNameSpace(cop, NULL));
@@ -345,7 +345,7 @@
static CMPIInstance * CreateSettingDataInstance(const CMPIObjectPath * cop,
const char ** properties)
{
- DEBUGOUT("%s", "CreateSettingDataInstance() called\n");
+ DEBUGOUT("CreateSettingDataInstance() called\n");
CMPIStatus status = {CMPI_RC_OK, NULL};
char * ns = CMGetCharPtr(CMGetNameSpace(cop, NULL));
@@ -359,7 +359,7 @@
}
else
{
- DEBUGOUT("%s", "About to set instance properties\n");
+ DEBUGOUT("About to set instance properties\n");
status = CMSetPropertyFilter(instance, properties, (const char **)classKeys);
@@ -373,7 +373,7 @@
exit:
- DEBUGOUT("%s", "Leaving CreateSettingDataInstance()\n");
+ DEBUGOUT("Leaving CreateSettingDataInstance()\n");
return instance;
}
@@ -394,7 +394,7 @@
const CMPIObjectPath * cop,
const char ** properties)
{
- DEBUGOUT("%s", "EnumInstances() called\n");
+ DEBUGOUT("EnumInstances() called\n");
CMPIStatus status = {CMPI_RC_OK, NULL};
//char * ns = CMGetCharPtr(CMGetNameSpace(cop, NULL));
@@ -432,7 +432,7 @@
const CMPIObjectPath * cop,
const char ** properties)
{
- DEBUGOUT("%s", "GetInstance() called\n");
+ DEBUGOUT("GetInstance() called\n");
CMPIStatus status = {CMPI_RC_OK, NULL};
//char * ns = CMGetCharPtr(CMGetNameSpace(cop, NULL));
@@ -481,7 +481,7 @@
{
CMPIStatus status = {CMPI_RC_OK, NULL};
- DEBUGOUT("%s", "ModifyInstance() called\n");
+ DEBUGOUT("ModifyInstance() called\n");
// do work here if supported
if (getuid() != 0)
@@ -490,11 +490,11 @@
"Insufficient rights to modify the host name setting data");
goto exit;
}
- DEBUGOUT("%s", "Past getuid\n");
+ DEBUGOUT("Past getuid\n");
CMPIData key = CMGetKey(cop, "InstanceID", &status);
if (!CMIsNullValue(key))
{
- DEBUGOUT("%s", "Past getkey.\n");
+ DEBUGOUT("Past getkey.\n");
if (strcmp(CMGetCharPtr(key.value.string), instanceID) == 0)
{
CMPIData newName = CMGetProperty(newinstance, "ComputerName", &status);
@@ -509,7 +509,7 @@
if (strcmp(szNewHostName, csHostName) == 0)
{
- DEBUGOUT("%s", "HostNameSettingData::modifyInstance - Modified host name is the same as the old name. No action taken.\n");
+ DEBUGOUT("HostNameSettingData::modifyInstance - Modified host name is the same as the old name. No action taken.\n");
}
else
{
@@ -546,7 +546,7 @@
{
CMPIStatus status = {CMPI_RC_ERR_NOT_SUPPORTED, NULL};
- DEBUGOUT("%s", "CreateInstance() called - Not Supported");
+ DEBUGOUT("CreateInstance() called - Not Supported");
// do work here if supported
@@ -569,7 +569,7 @@
{
CMPIStatus status = {CMPI_RC_ERR_NOT_SUPPORTED, NULL};
- DEBUGOUT("%s", "DeleteInstance() called\n");
+ DEBUGOUT("DeleteInstance() called\n");
// do work here if supported
@@ -596,7 +596,7 @@
{
CMPIStatus status = {CMPI_RC_ERR_NOT_SUPPORTED, NULL};
- DEBUGOUT("%s", "ExecQuery() called - Not Supported");
+ DEBUGOUT("ExecQuery() called - Not Supported");
// do work here if supported
@@ -617,7 +617,7 @@
{
CMPIStatus status = {CMPI_RC_OK, NULL};
- DEBUGOUT("%s", "Cleanup() called\n");
+ DEBUGOUT("Cleanup() called\n");
// do work here if necessary
@@ -632,7 +632,7 @@
// ****************************************************************************
static void Init(CMPIInstanceMI * self)
{
- DEBUGOUT("%s", "Initialize() called\n");
+ DEBUGOUT("Initialize() called\n");
// do work here if necessary
memset(g_szOldHostName, 0, 128);
@@ -658,7 +658,7 @@
// ****************************************************************************
static void MethodInit(CMPIMethodMI * self)
{
- DEBUGOUT("%s", "MethodInitialize() called\n");
+ DEBUGOUT("MethodInitialize() called\n");
// do work here if necessary
@@ -678,7 +678,7 @@
{
CMPIStatus status = {CMPI_RC_OK, NULL};
- DEBUGOUT("%s", "MethodCleanup() called\n");
+ DEBUGOUT("MethodCleanup() called\n");
// do work here if necessary
@@ -707,7 +707,7 @@
{
CMPIStatus status = {CMPI_RC_OK, NULL};
- DEBUGOUT("%s", "InvokeMethod() called\n");
+ DEBUGOUT("InvokeMethod() called\n");
// do work here
//CMPIString *class = NULL;
Modified: cmpibase/trunk/src/providers/time-service/remoteTimeServicePort.c
===================================================================
--- cmpibase/trunk/src/providers/time-service/remoteTimeServicePort.c 2006-11-02 19:02:03 UTC (rev 16)
+++ cmpibase/trunk/src/providers/time-service/remoteTimeServicePort.c 2006-11-02 21:50:53 UTC (rev 17)
@@ -126,9 +126,8 @@
DEBUGOUT("RemoteTimeServicePort: EnumInstanceNames() called\n");
- if(omcGetRPMInstallDate("xntp"))
+ if(serverSupportsNTP())
{
- DEBUGOUT(" got RPM Install Date for xntp\n");
int numServers = 0;
NTPServer *sra = getNTPServers(&numServers);
if (sra && numServers)
@@ -148,6 +147,7 @@
CMReturnObjectPath(results, cop);
}
}
+ free(sra);
}
}
CMReturnDone(results);
@@ -185,9 +185,8 @@
DEBUGOUT("RemoteTimeServicePort: EnumInstances() called\n");
- if(omcGetRPMInstallDate("xntp"))
+ if(serverSupportsNTP())
{
- DEBUGOUT(" got RPM Install Date for xntp\n");
int numServers = 0;
NTPServer *sra = getNTPServers(&numServers);
if (sra && numServers)
@@ -208,6 +207,7 @@
CMReturnInstance(results, inst);
}
}
+ free(sra);
}
}
CMReturnDone(results);
@@ -241,26 +241,48 @@
const char ** properties)
{
CMPIStatus status = {CMPI_RC_OK, NULL};
+ char * ns = CMGetCharPtr(CMGetNameSpace(cop, NULL));
DEBUGOUT("RemoteTimeServicePort: GetInstance() called\n");
- /*
- CMPIObjectPath *op = makeTimeServiceObjectPath(ns, &status);
+ CMPIData key = CMGetKey(cop, "Name", &status);
+ if (!CMIsNullValue(key))
+ {
+ char *inServerName = CMGetCharPtr(key.value.string);
+ DEBUGOUT(" got servername: %s\n", inServerName);
- if (omccmpiAreObjectPathsSame(cop, op, &status))
- {
- CMPIInstance *inst = makeTimeServiceInstance(ns, &status, properties);
- if ((status.rc != CMPI_RC_OK) || CMIsNullObject(inst))
+ NTPServer *ntpServer = getNTPServer(inServerName);
+ if (ntpServer)
{
- OMC_SETSTATUS(_broker, &status, CMPI_RC_ERROR_SYSTEM, "Failed creating TimeService instance");
- DEBUGOUT("EnumInstances(): makeTimeServiceInstance() failed - %s\n", CMGetCharPtr(status.msg));
+ DEBUGOUT(" got NTPServer: %s\n", ntpServer->serverName);
+ CMPIInstance *inst = makeRemoteTimeServicePortInstance(
+ _broker,
+ ns,
+ ntpServer->serverName,
+ &status,
+ properties);
+ if (!CMIsNullObject(cop))
+ {
+ CMReturnInstance(results, inst);
+ }
+ free(ntpServer);
+ }
+ else
+ {
+ OMC_SETSTATUS(_broker, &status, CMPI_RC_ERR_FAILED, "Didn't find ntpServer in file");
+ DEBUGOUT("RemoteTimeServerPort: getNTPServer() failed - %s\n", CMGetCharPtr(status.msg));
return status;
}
- CMReturnInstance(results, inst);
}
CMReturnDone(results);
- */
+ if (status.rc != CMPI_RC_OK)
+ {
+ OMC_SETSTATUS(_broker, &status, CMPI_RC_ERROR_SYSTEM, "Failed creating RemotePort instance");
+ DEBUGOUT("RemoteTimeServerPort::GetInstance() failed - %s\n", CMGetCharPtr(status.msg));
+ return status;
+ }
+
DEBUGOUT("RemoteTimeServicePort: Leaving GetInstance(): %s\n", (status.rc == CMPI_RC_OK)? "succeeded":"failed");
return status;
}
@@ -285,8 +307,62 @@
DEBUGOUT("RemoteTimeServicePort: ModifyInstance() called - Not Supported\n");
- // do work here if supported
+ //TODO: this should support ModifyInstance - edit an entry in the file
+/*
+ if (::geteuid() != 0)
+ {
+ OW_THROWCIM(CIMException::ACCESS_DENIED);
+ }
+ if(!serverSupportsNTP())
+ {
+ OW_THROWCIMMSG(CIMException::NOT_SUPPORTED,
+ "NTP Support is not available");
+ }
+
+ CIMInstance mci = modifiedInstance.createModifiedInstance(
+ previousInstance, includeQualifiers, propertyList, theClass);
+
+ CIMValue cv = mci.getPropertyValue("Name");
+ if(!cv)
+ {
+ OW_THROWCIMMSG(CIMException::INVALID_PARAMETER,
+ "Name property must be specified");
+ }
+
+ NTPServer server;
+ cv.get(server.serverName);
+ if(server.serverName.empty())
+ {
+ OW_THROWCIMMSG(CIMException::INVALID_PARAMETER,
+ "Name property must be specified");
+ }
+
+ cv = mci.getPropertyValue("Prefer");
+ if(cv)
+ {
+ Bool prefer;
+ cv.get(prefer);
+ server.prefer = prefer;
+ }
+
+ server.key = getUIntFromCIMValue("key", mci);
+ server.ntpVersion = getUIntFromCIMValue("ntpversion", mci);
+ server.minPoll = getUIntFromCIMValue("minpoll", mci);
+ server.maxPoll = getUIntFromCIMValue("maxpoll", mci);
+
+ if(NTPConf::setServer(server) != 0)
+ {
+ OW_THROWCIM(CIMException::FAILED);
+ }
+
+ String errMsg;
+ if(restartNTP(errMsg) != 0)
+ {
+ OW_THROWCIMMSG(CIMException::FAILED, errMsg.c_str());
+ }
+
+*/
DEBUGOUT("RemoteTimeServicePort: Leaving ModifyInstance(): %s\n", (status.rc == CMPI_RC_OK)? "succeeded":"failed");
return status;
}
@@ -310,8 +386,60 @@
DEBUGOUT("RemoteTimeServicePort: CreateInstance() called - Not Supported\n");
- // do work here if supported
+ //TODO: this should support CreateInstance - add an entry to the file
+ /*
+ if (::geteuid() != 0)
+ {
+ OW_THROWCIM(CIMException::ACCESS_DENIED);
+ }
+ if(!serverSupportsNTP())
+ {
+ OW_THROWCIMMSG(CIMException::NOT_SUPPORTED,
+ "NTP Support is not available");
+ }
+
+ CIMValue cv = cimInstance.getPropertyValue("Name");
+ if(!cv)
+ {
+ OW_THROWCIMMSG(CIMException::INVALID_PARAMETER,
+ "Name property must be specified");
+ }
+
+ NTPServer server;
+ cv.get(server.serverName);
+ if(server.serverName.empty())
+ {
+ OW_THROWCIMMSG(CIMException::INVALID_PARAMETER,
+ "Name property must be specified");
+ }
+
+ if((cv = cimInstance.getPropertyValue("Prefer")))
+ {
+ Bool prefer;
+ cv.get(prefer);
+ server.prefer = prefer;
+ }
+
+ server.key = getUIntFromCIMValue("key", cimInstance);
+ server.ntpVersion = getUIntFromCIMValue("ntpversion", cimInstance);
+ server.minPoll = getUIntFromCIMValue("minpoll", cimInstance);
+ server.maxPoll = getUIntFromCIMValue("maxpoll", cimInstance);
+
+ if(NTPConf::setServer(server) != 0)
+ {
+ OW_THROWCIM(CIMException::FAILED);
+ }
+
+ String errMsg;
+ if(restartNTP(errMsg) != 0)
+ {
+ OW_THROWCIMMSG(CIMException::FAILED, errMsg.c_str());
+ }
+
+ return makeRemotePortObjectPath(server.serverName, env, ns);
+ */
+
DEBUGOUT("RemoteTimeServicePort: Leaving CreateInstance(): %s\n", (status.rc == CMPI_RC_OK)? "succeeded":"failed");
return status;
}
@@ -333,8 +461,46 @@
DEBUGOUT("RemoteTimeServicePort: DeleteInstance() called\n");
- // do work here if supported
+ //TODO: this should support DeleteInstance - remove an entry from the file
+/*
+ if (::geteuid() != 0)
+ {
+ OW_THROWCIM(CIMException::ACCESS_DENIED);
+ }
+ if(!serverSupportsNTP())
+ {
+ OW_THROWCIMMSG(CIMException::NOT_SUPPORTED,
+ "NTP Support is not available");
+ }
+
+ CIMValue cv = cop.getKeyValue("Name");
+ if(!cv)
+ {
+ OW_THROWCIMMSG(CIMException::INVALID_PARAMETER,
+ "Name is missing from given object path");
+ }
+
+ String serverName;
+ cv.get(serverName);
+ if(serverName.length() == 0)
+ {
+ OW_THROWCIMMSG(CIMException::INVALID_PARAMETER,
+ "Name is missing from given object path");
+ }
+
+ if(NTPConf::deleteServer(serverName) != 0)
+ {
+ OW_THROWCIM(CIMException::FAILED);
+ }
+
+ String errMsg;
+ if(restartNTP(errMsg) != 0)
+ {
+ OW_THROWCIMMSG(CIMException::FAILED, errMsg.c_str());
+ }
+
+*/
DEBUGOUT("RemoteTimeServicePort: Leaving DeleteInstance(): %s\n", (status.rc == CMPI_RC_OK)? "succeeded":"failed");
return status;
}
Modified: cmpibase/trunk/src/providers/time-service/timeZoneSettingData.c
===================================================================
--- cmpibase/trunk/src/providers/time-service/timeZoneSettingData.c 2006-11-02 19:02:03 UTC (rev 16)
+++ cmpibase/trunk/src/providers/time-service/timeZoneSettingData.c 2006-11-02 21:50:53 UTC (rev 17)
@@ -1,14 +1,53 @@
-// place copyright notice here
+/*******************************************************************************
+* Copyright (C) 2005, 2006 Novell, Inc. All rights reserved.
+*
+* Redistribution and use in source and binary forms, with or without
+* modification, are permitted provided that the following conditions are met:
+*
+* - Redistributions of source code must retain the above copyright notice,
+* this list of conditions and the following disclaimer.
+*
+* - Redistributions in binary form must reproduce the above copyright notice,
+* this list of conditions and the following disclaimer in the documentation
+* and/or other materials provided with the distribution.
+*
+* - Neither the name of Novell, Inc. nor the names of its
+* contributors may be used to endorse or promote products derived from this
+* software without specific prior written permission.
+*
+* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
+* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+* ARE DISCLAIMED. IN NO EVENT SHALL Novell, Inc. OR THE CONTRIBUTORS
+* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+* POSSIBILITY OF SUCH DAMAGE.
+*
+* Author: Norm Paxton (np...@no...)
+******************************************************************************/
-#include "cmpidt.h"
-#include "cmpift.h"
-#include "cmpimacs.h"
+#include <cmpidt.h>
+#include <cmpift.h>
+#include <cmpimacs.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <omc/base.h>
+#include <omc/string.h>
+#include <omc/modifyFile.h>
+#include <omc/exec.h>
+
// NULL terminated list of key property names for this class
-static char * classKeys[] = {"FooKey", NULL};
+static char className[] = "OMC_TimeZoneSettingData";
+static char * classKeys[] = {"InstanceID", NULL};
+static char instanceID[] = "omc:timezone";
-#ifdef DEBUG
+#ifdef OMC_DEBUG
#define DEBUGOUT(fmt, args...) printf(fmt,## args)
#else
#define DEBUGOUT(fmt, args...)
@@ -17,7 +56,7 @@
// Global handle to the CIM broker
// This is initialized by the CIMOM when the provider is loaded
-static CMPIBroker * _broker;
+static const CMPIBroker * _broker;
// ****************************************************************************
@@ -51,6 +90,203 @@
*/
+
+
+char g_szOldTimeZone[128];
+char g_szNewTimeZone[128];
+
+
+// *************
+// Functions to facilitate modifying the host name setting data
+// *************
+//
+// //int (*writeLine)(const char* line, FILE* const ostrm, char* errMsgBfr, unsigned int errMsgBfrLen);
+/*
+static int myWriteLine( const char* line,
+ FILE* const ostrm,
+ char* errMsgBfr,
+ unsigned int errMsgBfrLen)
+{
+ //DEBUGOUT("writeLine() called\n");
+
+ // trim this?
+ if (line[0] == '#')
+ {
+ // just write it and ignore it
+ fputs(line, ostrm);
+ fputs("\n", ostrm);
+ return 0;
+ }
+
+ int bModified = 0;
+ unsigned int tokenCount = 0;
+ char** toks = omcStrTokenize(line, ", \t", &tokenCount);
+ int i=0;
+ if (toks && toks[i])
+ {
+ //DEBUGOUT("line: %s\n", line);
+ while (toks[i])
+ {
+ //DEBUGOUT(" toks[%d]: %s\n", i, toks[i]);
+ if(strcmp(toks[i], g_szOldHostName) == 0)
+ {
+ toks[i] = g_szNewHostName;
+ bModified = 1;
+ //DEBUGOUT(" matched: %s == %s\n", toks[i], g_szOldHostName);
+ }
+ else
+ {
+ //DEBUGOUT(" didn't match: %s != %s\n", toks[i], g_szOldHostName);
+ }
+
+ if(strcmp(toks[i], g_szOldShortName) == 0)
+ {
+ toks[i] = g_szNewShortName;
+ bModified = 1;
+ //DEBUGOUT(" matched: %s != %s\n", toks[i], g_szOldShortName);
+ }
+ else
+ {
+ //DEBUGOUT(" didn't match: %s != %s\n", toks[i], g_szOldShortName);
+ }
+
+ i++;
+ }
+
+ if(bModified > 0)
+ {
+ int newlen = (strlen(line)+1) + (strlen(g_szNewHostName));
+ char *newline = (char*) malloc(newlen);
+ memset(newline, 0, newlen);
+ i = 0;
+ while(toks[i])
+ {
+ omcStrAppend(newline, toks[i], newlen);
+ omcStrAppend(newline, "\t", newlen);
+ i++;
+ }
+ //DEBUGOUT("writing new line: %s\n", newline);
+ fputs(newline, ostrm);
+ fputs("\n", ostrm);
+ free(newline);
+ }
+ else
+ {
+ // didn't modify this line, just write it back out...
+ // bModify is still 0, let end return handle it
+ fputs(line, ostrm);
+ fputs("\n", ostrm);
+ }
+
+ }
+ free(toks);
+
+ //DEBUGOUT("writeLine() returning... modified: %d\n", bModified);
+
+ return bModified;
+}
+
+
+static int modifyComputerName(const char *curComputerName,
+ const char *newComputerName)
+{
+ DEBUGOUT("modifyComputerName() called\n");
+
+ int bModified = 0;
+
+ strncpy(g_szOldHostName, curComputerName, 127);
+ strncpy(g_szNewHostName, newComputerName, 127);
+
+ //DEBUGOUT("Set OldHostName to %s\n", g_szOldHostName );
+ //DEBUGOUT("Set NewHostName to %s\n", g_szNewHostName );
+
+ char * loc = NULL;
+ int len = 0;
+ loc = strchr(curComputerName, (int)'.');
+ len = (int)((char *)loc - (char *)curComputerName);
+ if (len > 0)
+ {
+ strncpy(g_szOldShortName, curComputerName, len);
+ //DEBUGOUT("Set OldShortName to %s\n", g_szOldShortName );
+ }
+
+ loc = strchr(newComputerName, (int)'.');
+ len = (int)((char *)loc - (char *)newComputerName);
+ if (len > 0)
+ {
+ strncpy(g_szNewShortName, newComputerName, len);
+ //DEBUGOUT("Set NewShortName to %s\n", g_szNewShortName );
+ }
+
+
+ omcFileModifier_CBS fms = {0};
+ fms.writeLine = myWriteLine;
+
+ char err1[256] = {0};
+ char err2[256] = {0};
+
+ //DEBUGOUT("about to call modifyFile on hosts\n");
+ int r1 = omcModifyFile("/etc/hosts",
+ &fms,
+ err1,
+ 256);
+
+ //DEBUGOUT("about to call modifyFile on HOSTNAME\n");
+ int r2 = omcModifyFile("/etc/HOSTNAME",
+ &fms,
+ err2,
+ 256);
+
+ if (r1 || r2)
+ {
+ DEBUGOUT("Modifying File returned error:\n hosts: %s\n HOSTNAME: %s\n Attempting rollback\n",
+ err1, err2);
+ r1 = omcModifyRollBack("/etc/hosts",
+ err1,
+ 256 );
+ r2 = omcModifyRollBack("/etc/HOSTNAME",
+ err2,
+ 256 );
+ if (r1 || r2)
+ {
+ DEBUGOUT("Rollback failed. use .orig file for /etc/hosts and /etc/HOSTNAME\n err1: %s\n err2: %s",
+ err1, err2);
+ }
+ }
+ else
+ {
+ char *cmd[] = {"/bin/hostname", g_szNewShortName};
+ int rSys = omcSafeSystem(cmd, NULL);
+ if (rSys != 0)
+ {
+ DEBUGOUT("Call to /bin/hostname failed. Unable to modify hostname");
+ //CMSetStatusWithChars(_broker, &status, CMPI_RC_ERR_FAILED,
+ // "Call to /bin/hostname failed. Unable to modify hostname");
+
+ r1 = omcModifyRollBack("/etc/hosts",
+ err1,
+ 256 );
+ r2 = omcModifyRollBack("/etc/HOSTNAME",
+ err2,
+ 256 );
+ if (r1 || r2)
+ {
+ DEBUGOUT("Rollback failed. use .orig file for /etc/hosts and /etc/HOSTNAME\n err1: %s\n err2: %s",
+ err1, err2);
+ }
+ }
+ }
+//exit:
+ DEBUGOUT("modifyComputerName() returning\n");
+
+ return bModified;
+}
+*/
+
+
+
+
+
// ****************************************************************************
// CMPI INSTANCE PROVIDER FUNCTIONS
// ****************************************************************************
@@ -70,16 +306,27 @@
const CMPIResult * results,
const CMPIObjectPath * cop)
{
+ DEBUGOUT("TimeZoneSettingData: EnumInstanceNames() called\n");
+
CMPIStatus status = {CMPI_RC_OK, NULL};
char * ns = CMGetCharPtr(CMGetNameSpace(cop, NULL));
- DEBUGOUT("EnumInstanceNames() called");
+ CMPIObjectPath *op = makeTimeZoneSettingDataObjectPath(_broker, ns, &status);
- // do work here
+ if ((status.rc != CMPI_RC_OK) || CMIsNullObject(objectpath))
+ {
+ CMSetStatusWithChars(_broker, &status, CMPI_RC_ERR_FAILED,
+ "Could not create TimeZoneSettingData ObjectPath");
+ }
+ else
+ {
+ CMReturnObjectPath(results, op);
+ }
+ //close return handler
CMReturnDone(results);
- DEBUGOUT("Leaving EnumInstanceNames(): %s", (status.rc == CMPI_RC_OK)? "succeeded":"failed");
+ DEBUGOUT("Leaving EnumInstanceNames(): %s\n", (status.rc == CMPI_RC_OK)? "succeeded":"failed");
return status;
}
@@ -98,16 +345,27 @@
const CMPIObjectPath * cop,
const char ** properties)
{
+ DEBUGOUT("EnumInstances() called\n");
+
CMPIStatus status = {CMPI_RC_OK, NULL};
char * ns = CMGetCharPtr(CMGetNameSpace(cop, NULL));
- DEBUGOUT("EnumInstances() called");
+ CMPIInstance *inst = makeTimeZoneSettingDataInstance(_broker, ns, &status, properties);
- // do work here
+ if ((status.rc != CMPI_RC_OK) || CMIsNullObject(inst))
+ {
+ CMSetStatusWithChars(_broker, &status, CMPI_RC_ERR_FAILED,
+ "Could not create TimeZoneSettingData Instance");
+ }
+ else
+ {
+ CMReturnInstance(results, inst);
+ }
+ //close return handler
CMReturnDone(results);
- DEBUGOUT("Leaving EnumInstances(): %s", (status.rc == CMPI_RC_OK)? "succeeded":"failed");
+ DEBUGOUT("Leaving EnumInstances(): %s\n", (status.rc == CMPI_RC_OK)? "succeeded":"failed");
return status;
}
@@ -126,14 +384,39 @@
const CMPIObjectPath * cop,
const char ** properties)
{
+ DEBUGOUT("GetInstance() called\n");
+
CMPIStatus status = {CMPI_RC_OK, NULL};
- char * ns = CMGetCharPtr(CMGetNameSpace(cop, NULL));
+ //char * ns = CMGetCharPtr(CMGetNameSpace(cop, NULL));
- DEBUGOUT("GetInstance() called");
-
// do work here
+ CMPIData key = CMGetKey(cop, "InstanceID", &status);
+ if (!CMIsNullValue(key))
+ {
+ if (strcasecmp(CMGetCharPtr(key.value.string), "omc:timezone") == 0)
+ {
+ CMPIStatus status = {CMPI_RC_OK, NULL};
+ char * ns = CMGetCharPtr(CMGetNameSpace(cop, NULL));
- DEBUGOUT("Leaving GetInstance(): %s", (status.rc == CMPI_RC_OK)? "succeeded":"failed");
+ CMPIInstance *inst = makeTimeZoneSettingDataInstance(_broker, ns, &status, properties);
+
+ if ((status.rc != CMPI_RC_OK) || CMIsNullObject(inst))
+ {
+ CMSetStatusWithChars(_broker, &status, CMPI_RC_ERR_FAILED,
+ "Could not create TimeZoneSettingData Instance");
+ }
+ else
+ {
+ CMReturnInstance(results, inst);
+ }
+ }
+
+ //close return handler
+ CMReturnDone(results);
+ }
+
+exit:
+ DEBUGOUT("Leaving GetInstance(): %s\n", (status.rc == CMPI_RC_OK)? "succeeded":"failed");
return status;
}
@@ -153,13 +436,53 @@
const CMPIInstance * newinstance,
const char ** properties)
{
- CMPIStatus status = {CMPI_RC_ERR_NOT_SUPPORTED, NULL};
+ CMPIStatus status = {CMPI_RC_OK, NULL};
- DEBUGOUT("ModifyInstance() called - Not Supported");
+ DEBUGOUT("ModifyInstance() called\n");
// do work here if supported
+ if (getuid() != 0)
+ {
+ CMSetStatusWithChars(_broker, &status, CMPI_RC_ERR_ACCESS_DENIED,
+ "Insufficient rights to modify the host name setting data");
+ goto exit;
+ }
+ DEBUGOUT("Past getuid\n");
+ CMPIData key = CMGetKey(cop, "InstanceID", &status);
+ if (!CMIsNullValue(key))
+ {
+ DEBUGOUT("Past getkey.\n");
+ if (strcmp(CMGetCharPtr(key.value.string), instanceID) == 0)
+ {
+ CMPIData newName = CMGetProperty(newinstance, "ComputerName", &status);
+ if (!CMIsNullValue(newName))
+ {
+ char *szNewHostName = CMGetCharPtr(newName.value.string);
+ DEBUGOUT("newHostName: %s\n", szNewHostName);
- DEBUGOUT("Leaving ModifyInstance(): %s", (status.rc == CMPI_RC_OK)? "succeeded":"failed");
+ // get current computer system name, to compare
+ char csHostName[128] = {0};
+ omcGetComputerSystemName(csHostName, 128);
+
+ if (strcmp(szNewHostName, csHostName) == 0)
+ {
+ DEBUGOUT("HostNameSettingData::modifyInstance - Modified host name is the same as the old name. No action taken.\n");
+ }
+ else
+ {
+ if (modifyComputerName(csHostName, szNewHostName) != 0)
+ {
+ CMSetStatusWithChars(_broker, &status, CMPI_RC_ERR_FAILED,
+ "Failed to modify the computer name via hostNameSettingData");
+ goto exit;
+ }
+ }
+ }
+ }
+ }
+
+exit:
+ DEBUGOUT("Leaving ModifyInstance(): %s\n", (status.rc == CMPI_RC_OK)? "succeeded":"failed");
return status;
}
@@ -184,7 +507,7 @@
// do work here if supported
- DEBUGOUT("Leaving CreateInstance(): %s", (status.rc == CMPI_RC_OK)? "succeeded":"failed");
+ DEBUGOUT("Leaving CreateInstance(): %s\n", (status.rc == CMPI_RC_OK)? "succeeded":"failed");
return status;
}
@@ -203,11 +526,11 @@
{
CMPIStatus status = {CMPI_RC_ERR_NOT_SUPPORTED, NULL};
- DEBUGOUT("DeleteInstance() called");
+ DEBUGOUT("DeleteInstance() called\n");
// do work here if supported
- DEBUGOUT("Leaving DeleteInstance(): %s", (status.rc == CMPI_RC_OK)? "succeeded":"failed");
+ DEBUGOUT("Leaving DeleteInstance(): %s\n", (status.rc == CMPI_RC_OK)? "succeeded":"failed");
return status;
}
@@ -234,7 +557,7 @@
// do work here if supported
- DEBUGOUT("Leaving ExecQuery(): %s", (status.rc == CMPI_RC_OK)? "succeeded":"failed");
+ DEBUGOUT("Leaving ExecQuery(): %s\n", (status.rc == CMPI_RC_OK)? "succeeded":"failed");
return status;
}
@@ -251,11 +574,11 @@
{
CMPIStatus status = {CMPI_RC_OK, NULL};
- DEBUGOUT("Cleanup() called");
+ DEBUGOUT("Cleanup() called\n");
// do work here if necessary
- DEBUGOUT("Leaving Cleanup(): %s", (status.rc == CMPI_RC_OK)? "succeeded":"failed");
+ DEBUGOUT("Leaving Cleanup(): %s\n", (status.rc == CMPI_RC_OK)? "succeeded":"failed");
return status;
}
@@ -266,359 +589,22 @@
// ****************************************************************************
static void Init(CMPIInstanceMI * self)
{
- CMPIStatus status = {CMPI_RC_OK, NULL};
+ DEBUGOUT("Initialize() called\n");
- DEBUGOUT("Initialize() called");
-
// do work here if necessary
+ memset(g_szOldHostName, 0, 128);
+ memset(g_szNewHostName, 0, 128);
+ memset(g_szOldShortName, 0, 128);
+ memset(g_szNewShortName, 0, 128);
- DEBUGOUT("Leaving Initialize(): %s", (status.rc == CMPI_RC_OK)? "succeeded":"failed");
+ DEBUGOUT("Leaving Initialize(): %s\n", (status.rc == CMPI_RC_OK)? "succeeded":"failed");
}
-
+/*
// ****************************************************************************
-// CMPI ASSOCIATION PROVIDER FUNCTIONS
-// ****************************************************************************
-
-
-static char * ASSOC_CLASSNAME = "OMC_ComputerSystemHostNameSettingData";
-static char * LEFT_CLASSNAME = "OMC_UnitaryComputerSystem";
-static char * RIGHT_CLASSNAME = "OMC_HostNameSettingData";
-static char * LEFT_PROPERTYNAME = "ManagedElement";
-static char * RIGHT_PROPERTYNAME = "SettingData";
-
-// ****************************************************************************
-// doReferences()
-// This is the callback called from the SimpleAssociators helper functions
-// It "handles" one or more instances of the association class
-// to be filtered by the SimpleAssociatior helper functions to return
-// the correct object (instance or object path)
-// ****************************************************************************
-CMPIStatus
-doReferences(
- omccmpiSimpleAssocCtx ctx,
- CMPIAssociationMI* self,
- const CMPIBroker *broker,
- const CMPIContext* context,
- const CMPIResult* results,
- const CMPIObjectPath* cop,
- const char *assocClass,
- const char *resultClass,
- const char *role,
- const char *resultRole,
- const char** properties)
-{
- DEBUGOUT("doReferences called\n");
-
- CMPIStatus status = {CMPI_RC_OK, NULL};
- char * ns = CMGetCharPtr(CMGetNameSpace(cop, NULL));
-
- if (strcasecmp(assocClass, ASSOC_CLASSNAME) == 0)
- {
- char *objClassName = CMGetCharPtr(CMGetClassName(cop, NULL));
-
- if(strcasecmp(objClassName, LEFT_CLASSNAME) == 0)
- {
- // this is a LEFT_CLASSNAME
- // need to get approprate RIGHT_CLASSNAME for ASSOC_CLASSNAME inst
- // but if resultClass is set, it must match
-
- int bHaveMatch = 1; // TRUE
- if ((resultClass != NULL) && (*resultClass != 0))
- {
- // check
- if (!omccmpiClassIsDerivedFrom(RIGHT_CLASSNAME,
- resultClass,
- _broker,ns,&status))
- {
- bHaveMatch = 0; // FALSE
- }
- }
-
- if ((resultRole != NULL) && (*resultRole != 0))
- {
- // check
- if (strcasecmp(resultRole, RIGHT_PROPERTYNAME) != 0)
- {
- bHaveMatch = 0; // FALSE
- }
- }
-
- if (bHaveMatch)
- {
- // do work here:
- // create and return the appropriate association instance(s)
- //
- // loop, if necesssary
- // do appropriate checks
-
- // the left cop was passed in
- CMPIObjectPath *leftCop = cop;
-
- // get or create right side object path
- CMPIObjectPath *rightCop = CMNewObjectPath(_broker, ns, RIGHT_CLASSNAME, &status);
- // add keys
-
-
- // create association instance
- CMPIInstance *assocInst = omccmpiCreateAssociationInst(_broker,
- ns,
- ASSOC_CLASSNAME,
- classKeys,
- properties,
- LEFT_PROPERTYNAME,
- RIGHT_PROPERTYNAME,
- leftCop,
- rightCop,
- &status);
- // "handle" the association
- omccmpiSimpleAssocResults(ctx, assocInst, &status);
- }
- }
- else if(strcmp(objClassName, RIGHT_CLASSNAME) == 0)
- {
- // this is a RIGHT_CLASSNAME
- // need to get approprate LEFT_CLASSNAME for ASSOC_CLASSNAME inst
- // but if resultClass is set, it must match
-
- int bHaveMatch = 1; // TRUE
- if ((resultClass != NULL) && (*resultClass != 0))
- {
- // check
- if (!omccmpiClassIsDerivedFrom(LEFT_CLASSNAME,
- resultClass,
- _broker,ns,&status))
- {
- bHaveMatch = 0; // FALSE
- }
- }
-
- if ((resultRole != NULL) && (*resultRole != 0))
- {
- // check
- if (strcasecmp(resultRole, LEFT_PROPERTYNAME) != 0)
- {
- bHaveMatch = 0; // FALSE
- }
- }
-
- if (bHaveMatch)
- {
- // do work here:
- // create and return the appropriate association instance(s)
- //
- // loop, if necesssary
- // do appropriate checks
-
- // get or create left side object path
- CMPIObjectPath *leftCop = CMNewObjectPath(_broker, ns, LEFT_CLASSNAME, &status);
- // add keys
-
- // the right cop was passed in
- CMPIObjectPath *rightCop = cop;
-
-
- // create association instance
- CMPIInstance *assocInst = omccmpiCreateAssociationInst(_broker,
- ns,
- ASSOC_CLASSNAME,
- classKeys,
- properties,
- LEFT_PROPERTYNAME,
- RIGHT_PROPERTYNAME,
- leftCop,
- rightCop,
- &status);
- // "handle" the association
- omccmpiSimpleAssocResults(ctx, assocInst, &status);
- }
- }
- else
- {
- DEBUGOUT("!!! Object type unknown: %s\n", objClassName);
- }
- }
- //close return handler
- CMReturnDone(results);
-
- DEBUGOUT("Leaving doReferences\n");
- return status;
-}
-
-
-
-// ****************************************************************************
-// AssocInit() - init
-// params: CMPIAssociationMI* self: [in] Handle to this provider
-// ****************************************************************************
-static void AssocInit(CMPIAssociationMI * self)
-{
- CMPIStatus status = {CMPI_RC_OK, NULL};
-
- DEBUGOUT("AssocInit() called");
-
- // do work here if necessary
-
- DEBUGOUT("Leaving AssocInit(): %s", (status.rc == CMPI_RC_OK)? "succeeded":"failed");
-}
-
-
-
-// ****************************************************************************
-// AssociationCleanup() - pre unload
-// params: CMPIAssociationMI* self: [in] Handle to this provider
-// CMPIContext* context: [in] any additional context info
-// CMPIBoolean terminating
-// ****************************************************************************
-static CMPIStatus AssociationCleanup(CMPIAssociationMI* self,
- const CMPIContext* context,
- CMPIBoolean terminating)
-{
- CMPIStatus status = {CMPI_RC_OK, NULL};
-
- DEBUGOUT("AssociationCleanup() called");
-
- // do work here if necessary
-
- DEBUGOUT("Leaving AssociationCleanup(): %s", (status.rc == CMPI_RC_OK)? "succeeded":"failed");
- return status;
-}
-
-
-// ****************************************************************************
-// Associators()
-// params: CMPIAssociationMI* self: [in] Handle to this provider
-// CMPIContext* context: [in] any additional context info
-// CMPIResult* results: [out] Results
-// CMPIObjectPath* cop: [in] target namespace and classname, and desired objectpath
-// char *assocClass
-// char *resultClass
-// char *role
-// char *resultRole
-// char **properties
-// ****************************************************************************
-static CMPIStatus Associators( CMPIAssociationMI* self,
- const CMPIContext* context,
- const CMPIResult* results,
- const CMPIObjectPath* cop,
- const char *assocClass,
- const char *resultClass,
- const char *role,
- const char *resultRole,
- const char** properties)
-{
- CMPIStatus status = {CMPI_RC_OK, NULL};
-
- DEBUGOUT("Associators() called");
-
- CMPIStatus status = omccmpiSimpleAssociators( doReferences, self,
- _broker, context, results, cop, assocClass,
- resultClass, role, resultRole, properties);
-
- DEBUGOUT("Leaving Associatiors(): %s", (status.rc == CMPI_RC_OK)? "succeeded":"failed");
- return status;
-}
-
-
-// ****************************************************************************
-// Associators()
-// params: CMPIAssociationMI* self: [in] Handle to this provider
-// CMPIContext* context: [in] any additional context info
-// CMPIResult* results: [out] Results
-// CMPIObjectPath* cop: [in] target namespace and classname, and desired objectpath
-// char *assocClass
-// char *resultClass
-// char *role
-// char *resultRole
-// ****************************************************************************
-static CMPIStatus AssociatorNames(CMPIAssociationMI* self,
- const CMPIContext* context,
- const CMPIResult* results,
- const CMPIObjectPath* cop,
- const char *assocClass,
- const char *resultClass,
- const char *role,
- const char *resultRole)
-{
- CMPIStatus status = {CMPI_RC_OK, NULL};
-
- DEBUGOUT("AssociatorNames() called");
-
- CMPIStatus status = omccmpiSimpleAssociatorNames( doReferences, self,
- _broker, context, results, cop, assocClass,
- resultClass, role, resultRole);
-
- DEBUGOUT("Leaving AssociatiorNames(): %s", (status.rc == CMPI_RC_OK)? "succeeded":"failed");
- return status;
-}
-
-
-// ****************************************************************************
-// References()
-// params: CMPIAssociationMI* self: [in] Handle to this provider
-// CMPIContext* context: [in] any additional context info
-// CMPIResult* results: [out] Results
-// CMPIObjectPath* cop: [in] target namespace and classname, and desired objectpath
-// char *resultClass
-// char *role
-// char **properties
-// ****************************************************************************
-static CMPIStatus References( CMPIAssociationMI* self,
- const CMPIContext* context,
- const CMPIResult* results,
- const CMPIObjectPath* cop,
- const char *resultClass,
- const char *role ,
- const char** properties)
-{
- CMPIStatus status = {CMPI_RC_OK, NULL};
-
- DEBUGOUT("References() called");
-
- CMPIStatus status = omccmpiSimpleReferences( doReferences, self,
- _broker, context, results, cop, NULL,
- resultClass, role, NULL, properties);
-
- DEBUGOUT("Leaving References(): %s", (status.rc == CMPI_RC_OK)? "succeeded":"failed");
- return status;
-}
-
-
-// ****************************************************************************
-// ReferenceNames()
-// params: CMPIAssociationMI* self: [in] Handle to this provider
-// CMPIContext* context: [in] any additional context info
-// CMPIResult* results: [out] Results
-// CMPIObjectPath* cop: [in] target namespace and classname, and desired objectpath
-// char *resultClass
-// char *role
-// ****************************************************************************
-static CMPIStatus ReferenceNames(CMPIAssociationMI* self,
- const CMPIContext* context,
- const CMPIResult* results,
- const CMPIObjectPath* cop,
- const char* resultClass,
- const char* role)
-{
- CMPIStatus status = {CMPI_RC_OK, NULL};
-
- DEBUGOUT("ReferenceNames() called");
-
- CMPIStatus status = omccmpiSimpleReferenceNames( doReferences, self,
- _broker, context, results, cop, NULL,
- resultClass, role, NULL);
-
- DEBUGOUT("Leaving ReferenceNames(): %s", (status.rc == CMPI_RC_OK)? "succeeded":"failed");
- return status;
-}
-
-
-
-
-// ****************************************************************************
// CMPI METHOD PROVIDER FUNCTIONS
// ****************************************************************************
@@ -629,13 +615,11 @@
// ****************************************************************************
static void MethodInit(CMPIMethodMI * self)
{
- CMPIStatus status = {CMPI_RC_OK, NULL};
+ DEBUGOUT("MethodInitialize() called\n");
- DEBUGOUT("MethodInitialize() called");
-
// do work here if necessary
- DEBUGOUT("Leaving MethodInitialize(): %s", (status.rc == CMPI_RC_OK)? "succeeded":"failed");
+ DEBUGOUT("Leaving MethodInitialize(): %s\n", (status.rc == CMPI_RC_OK)? "succeeded":"failed");
}
@@ -651,11 +635,11 @@
{
CMPIStatus status = {CMPI_RC_OK, NULL};
- DEBUGOUT("MethodCleanup() called");
+ DEBUGOUT("MethodCleanup() called\n");
// do work here if necessary
- DEBUGOUT("Leaving MethodCleanup(): %s", (status.rc == CMPI_RC_OK)? "succeeded":"failed");
+ DEBUGOUT("Leaving MethodCleanup(): %s\n", (status.rc == CMPI_RC_OK)? "succeeded":"failed");
return status;
}
@@ -680,23 +664,23 @@
{
CMPIStatus status = {CMPI_RC_OK, NULL};
- DEBUGOUT("InvokeMethod() called");
+ DEBUGOUT("InvokeMethod() called\n");
// do work here
- // CMPIString *class = NULL;
- // class = CMGetClassName(ref, &status);
- // if (strcasecmp(CMGetCharPtr(class), OMC_FooClass) == 0) &&
- // strcasecmp("MyMethodName", methodName == 0)
- // {}
+ //CMPIString *class = NULL;
+ //class = CMGetClassName(ref, &status);
+ //if (strcasecmp(CMGetCharPtr(class), OMC_FooClass) == 0) &&
+ // strcasecmp("MyMethodName", methodName == 0)
+ //{
+ //}
-
- DEBUGOUT("Leaving InvokeMethod(): %s", (status.rc == CMPI_RC_OK)? "succeeded":"failed");
+ DEBUGOUT("Leaving InvokeMethod(): %s\n", (status.rc == CMPI_RC_OK)? "succeeded":"failed");
return status;
}
+*/
-
// ****************************************************************************
// SETUP CMPI INSTANCE PROVIDER FUNCTION TABLE
// ****************************************************************************
@@ -714,9 +698,6 @@
If no additional init is required, specify "CMNoHook"
*/
-CMInstanceMIStub( , OMC_FooClass_Provider, _broker, Init(&mi));
-CMMethodMIStub( , OMC_FooClass_Provider, _broker, MethodInit(&mi));
-CMAssociationMIStub( , OMC_FooAssocClass_Provider, _broker, AssocInit(&mi));
+CMInstanceMIStub( , OMC_HostNameSettingData_Provider, _broker, Init(&mi));
+//CMMethodMIStub( , OMC_HostNameSettingData_Provider, _broker, MethodInit(&mi));
-
-
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|