[Libvirt-cim] [PATCH 1 of 2] HostSystem: check if input ref is valid

Heidi Eckhart heidieck at linux.vnet.ibm.com
Mon Jan 28 10:44:18 UTC 2008


# HG changeset patch
# User Heidi Eckhart <heidieck at linux.vnet.ibm.com>
# Date 1201520573 -3600
# Node ID a888712b0cd510c36c2262cce82fa132c51a35a4
# Parent  adf18661f7948a0287a4586d97572793e8e03826
HostSystem: check if input ref is valid
Signed-off-by: Heidi Eckhart <heidieck at linux.vnet.ibm.com>

diff -r adf18661f794 -r a888712b0cd5 src/Virt_HostSystem.c
--- a/src/Virt_HostSystem.c	Thu Jan 24 12:56:45 2008 +0100
+++ b/src/Virt_HostSystem.c	Mon Jan 28 12:42:53 2008 +0100
@@ -112,19 +112,35 @@ CMPIStatus get_host_cs(const CMPIBroker 
 
 static CMPIStatus return_host_cs(const CMPIObjectPath *reference,
                                  const CMPIResult *results,
-                                 int name_only)
+                                 bool name_only,
+                                 bool getInstance)
 {
         CMPIStatus s = {CMPI_RC_OK, NULL};
         CMPIInstance *instance;
 
         s = get_host_cs(_BROKER, reference, &instance);
-        if (s.rc != CMPI_RC_OK || instance == NULL)
-                goto out;
+        if (s.rc != CMPI_RC_OK)
+                goto out;
+
+        if (instance == NULL) {
+                if (getInstance)
+                        cu_statusf(_BROKER, &s,
+                                   CMPI_RC_ERR_NOT_FOUND,
+                                   "No such instance");
+                goto out;
+        }
+
+        if (getInstance) {
+                s = cu_validate_ref(_BROKER, reference, instance);
+                if (s.rc != CMPI_RC_OK)
+                        goto out;
+        }
 
         if (name_only)
                 cu_return_instance_name(results, instance);
         else
                 CMReturnInstance(results, instance);
+
  out:
         return s;
 }
@@ -164,7 +180,10 @@ static CMPIStatus EnumInstanceNames(CMPI
                                     const CMPIResult *results,
                                     const CMPIObjectPath *reference)
 {
-        return return_host_cs(reference, results, 1);
+        return return_host_cs(reference,
+                              results,
+                              true,
+                              false);
 }
 
 static CMPIStatus EnumInstances(CMPIInstanceMI *self,
@@ -174,7 +193,10 @@ static CMPIStatus EnumInstances(CMPIInst
                                 const char **properties)
 {
 
-        return return_host_cs(reference, results, 0);
+        return return_host_cs(reference,
+                              results,
+                              false,
+                              false);
 }
 
 static CMPIStatus GetInstance(CMPIInstanceMI *self,
@@ -183,7 +205,10 @@ static CMPIStatus GetInstance(CMPIInstan
                               const CMPIObjectPath *reference,
                               const char **properties)
 {
-        return return_host_cs(reference, results, 0);
+        return return_host_cs(reference,
+                              results,
+                              false,
+                              true);
 }
 
 DEFAULT_CI();




More information about the Libvirt-cim mailing list