[Libvirt-cim] [PATCH 1 of 2] Update get_vsms() in VSMS to validate reference

Kaitlin Rupert kaitlin at linux.vnet.ibm.com
Wed Feb 13 16:17:35 UTC 2008


# HG changeset patch
# User Kaitlin Rupert <karupert at us.ibm.com>
# Date 1202919247 28800
# Node ID 88e4cf39a5b342606d6a126c429eb9f0f1c38ab8
# Parent  be18b4c2084a6b2b1f1c3a1cdae25a98034d7d54
Update get_vsms() in VSMS to validate reference.

Also change names_only from an int to a bool.

Signed-off-by: Kaitlin Rupert <karupert at us.ibm.com>

diff -r be18b4c2084a -r 88e4cf39a5b3 src/Virt_VirtualSystemManagementService.c
--- a/src/Virt_VirtualSystemManagementService.c	Tue Feb 12 15:39:52 2008 -0800
+++ b/src/Virt_VirtualSystemManagementService.c	Wed Feb 13 08:14:07 2008 -0800
@@ -1161,7 +1161,8 @@ STDIM_MethodMIStub(, Virt_VirtualSystemM
 
 CMPIStatus get_vsms(const CMPIObjectPath *reference,
                     CMPIInstance **_inst,
-                    const CMPIBroker *broker)
+                    const CMPIBroker *broker,
+                    bool is_get_inst)
 { 
         CMPIStatus s = {CMPI_RC_OK, NULL};
         CMPIInstance *inst = NULL;
@@ -1171,8 +1172,14 @@ CMPIStatus get_vsms(const CMPIObjectPath
 
         *_inst = NULL;
         conn = connect_by_classname(broker, CLASSNAME(reference), &s);
-        if (conn == NULL)
+        if (conn == NULL) {
+                if (is_get_inst)
+                        cu_statusf(broker, &s,
+                                   CMPI_RC_ERR_NOT_FOUND,
+                                   "No such instance");
+
                 return s;
+        }
 
         inst = get_typed_instance(broker,
                                   pfx_from_conn(conn),
@@ -1207,6 +1214,12 @@ CMPIStatus get_vsms(const CMPIObjectPath
         CMSetProperty(inst, "SystemCreationClassName",
                       (CMPIValue *)ccname, CMPI_chars);
 
+        if (is_get_inst) {
+                s = cu_validate_ref(broker, reference, inst);
+                if (s.rc != CMPI_RC_OK)
+                        goto out;
+        }
+
         CMSetStatus(&s, CMPI_RC_OK);
 
  out:
@@ -1218,12 +1231,13 @@ CMPIStatus get_vsms(const CMPIObjectPath
 
 static CMPIStatus return_vsms(const CMPIObjectPath *reference,
                               const CMPIResult *results,
-                              int name_only)
+                              bool name_only,
+                              bool is_get_inst)
 {
         CMPIStatus s = {CMPI_RC_OK, NULL};
         CMPIInstance *inst;
 
-        s = get_vsms(reference, &inst, _BROKER);
+        s = get_vsms(reference, &inst, _BROKER, is_get_inst);
         if (s.rc != CMPI_RC_OK || inst == NULL)
                 goto out;
 
@@ -1240,7 +1254,7 @@ static CMPIStatus EnumInstanceNames(CMPI
                                     const CMPIResult *results,
                                     const CMPIObjectPath *reference)
 {
-        return return_vsms(reference, results, 1);
+        return return_vsms(reference, results, true, false);
 }
 
 static CMPIStatus EnumInstances(CMPIInstanceMI *self,
@@ -1250,7 +1264,7 @@ static CMPIStatus EnumInstances(CMPIInst
                                 const char **properties)
 {
 
-        return return_vsms(reference, results, 0);
+        return return_vsms(reference, results, false, false);
 }
 
 static CMPIStatus GetInstance(CMPIInstanceMI *self,
@@ -1259,25 +1273,7 @@ static CMPIStatus GetInstance(CMPIInstan
                               const CMPIObjectPath *ref,
                               const char **properties)
 {
-        CMPIInstance *inst;
-        CMPIStatus s;
-        const char *prop;
-
-        s = get_vsms(ref, &inst, _BROKER);
-        if (s.rc != CMPI_RC_OK)
-                return s;
-
-        prop = cu_compare_ref(ref, inst);
-        if (prop != NULL) {
-                cu_statusf(_BROKER, &s,
-                           CMPI_RC_ERR_NOT_FOUND,
-                           "No such instance (%s)", prop);
-        } else {
-                CMSetStatus(&s, CMPI_RC_OK);
-                CMReturnInstance(results, inst);
-        }
-
-        return s;
+        return return_vsms(ref, results, false, true);
 }
 
 DEFAULT_CI();
diff -r be18b4c2084a -r 88e4cf39a5b3 src/Virt_VirtualSystemManagementService.h
--- a/src/Virt_VirtualSystemManagementService.h	Tue Feb 12 15:39:52 2008 -0800
+++ b/src/Virt_VirtualSystemManagementService.h	Wed Feb 13 08:14:07 2008 -0800
@@ -21,4 +21,5 @@
 
 CMPIStatus get_vsms(const CMPIObjectPath *reference,
                     CMPIInstance **_inst,
-                    const CMPIBroker *broker);
+                    const CMPIBroker *broker,
+                    bool is_get_inst);




More information about the Libvirt-cim mailing list