summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichal Minar <miminar@redhat.com>2014-04-18 15:26:48 +0200
committerMichal Minar <miminar@redhat.com>2014-06-20 14:02:42 +0200
commitfae157954dd9b954080f0f83d3ad9979f850c26b (patch)
treefec3cec5ffec0830e44e369f70ce104083ba21d5
parentcc85c3e2903b28379a4bbdea477ab4afcb8878a2 (diff)
downloadopenlmi-providers-fae157954dd9b954080f0f83d3ad9979f850c26b.tar.gz
openlmi-providers-fae157954dd9b954080f0f83d3ad9979f850c26b.tar.xz
openlmi-providers-fae157954dd9b954080f0f83d3ad9979f850c26b.zip
common: added utility function
Added function for checking computer system instance name. This is usefull particularly in methods expecting an instance of CIM_ComputerSystem passed as a parameter and needing to check whether it matches current system.
-rw-r--r--src/libs/libopenlmi/openlmi.c68
-rw-r--r--src/libs/libopenlmi/openlmi.h7
2 files changed, 75 insertions, 0 deletions
diff --git a/src/libs/libopenlmi/openlmi.c b/src/libs/libopenlmi/openlmi.c
index 1259fbc..958a7ef 100644
--- a/src/libs/libopenlmi/openlmi.c
+++ b/src/libs/libopenlmi/openlmi.c
@@ -123,11 +123,79 @@ static bool get_computer_system(const CMPIBroker *cb, const CMPIContext *ctx)
return true;
}
+static bool lmi_is_this_system(const char *system_name)
+{
+ // TODO accept also aliases and FQDNs
+ return strcmp(system_name, _system_name) == 0;
+}
+
+
CMPIObjectPath *lmi_get_computer_system(void)
{
return _computer_system;
}
+bool lmi_check_computer_system(const CMPIObjectPath *computer_system)
+{
+ CMPIString *nsa = NULL;
+ CMPIString *nsb = NULL;
+ CMPIString *cls_name = NULL;
+ CMPIData data;
+ CMPIObjectPath *our = lmi_get_computer_system();
+ CMPIStatus status = {CMPI_RC_OK, NULL};
+
+ if (!our) {
+ lmi_error("Memory allocation failed");
+ return false;
+ }
+ if (!(nsb = CMGetNameSpace(computer_system, NULL)))
+ return false;
+ if (!(nsa = CMGetNameSpace(our, NULL)))
+ return false;
+ if (strcmp(CMGetCharsPtr(nsa, NULL), CMGetCharsPtr(nsb, NULL))) {
+ lmi_warn("Namespace of computer system does not match.");
+ return false;
+ }
+ if ((cls_name = CMGetClassName(our, NULL)) == NULL)
+ return false;
+ if (!CMClassPathIsA(_cb, computer_system,
+ CMGetCharsPtr(cls_name, NULL), NULL)) {
+ lmi_warn("Computer system class \"%s\" does not inherit from \"%s\".",
+ CMGetCharsPtr(CMGetClassName(computer_system, NULL), NULL),
+ CMGetCharsPtr(cls_name, NULL));
+ return false;
+ }
+ data = CMGetKey(computer_system, "CreationClassName", &status);
+ if (status.rc || data.type != CMPI_string ||
+ (data.state != CMPI_goodValue && data.state != CMPI_keyValue))
+ {
+ lmi_warn("Missing CreationClassName property in computer system"
+ " instance (status=%u, data.type=%u, data.state=%u).",
+ status.rc, data.type, data.state);
+ return false;
+ }
+ if (!CMClassPathIsA(_cb, computer_system,
+ CMGetCharsPtr(data.value.string, NULL), &status)) {
+ lmi_warn("Bad CreationClassName property in computer system"
+ " instance.");
+ return false;
+ }
+ data = CMGetKey(computer_system, "Name", &status);
+ if (status.rc || data.type != CMPI_string ||
+ (data.state != CMPI_goodValue && data.state != CMPI_keyValue))
+ {
+ lmi_warn("Missing Name property in computer system instance.");
+ return false;
+ }
+ if (!lmi_is_this_system(CMGetCharsPtr(data.value.string, NULL))) {
+ lmi_warn("Name \"%s\" of computer system do no match this system \"%s\".",
+ CMGetCharsPtr(data.value.string, NULL));
+ return false;
+ }
+
+ return true;
+}
+
const char *lmi_get_system_name(void)
{
return _system_name;
diff --git a/src/libs/libopenlmi/openlmi.h b/src/libs/libopenlmi/openlmi.h
index 3609489..7f2158b 100644
--- a/src/libs/libopenlmi/openlmi.h
+++ b/src/libs/libopenlmi/openlmi.h
@@ -88,6 +88,13 @@ typedef struct {
CMPIObjectPath *lmi_get_computer_system(void);
/**
+ * Check object path of CIM_ComputerSystem.
+ *
+ * @return true, if the object path matches this computer system.
+ */
+bool lmi_check_computer_system(const CMPIObjectPath *computer_system);
+
+/**
* This function returns system name for the computer system
*
* @note Use this in the SystemName property of all provider created instances.