# HG changeset patch
# User Heidi Eckhart <heidieck(a)linux.vnet.ibm.com>
# Date 1199971253 -3600
# Node ID d4471d3ac4766af68f6bf151813f0ec246b0e409
# Parent fd476f08b35e235ba7e50d326e5602018ebc3730
EC: Validation of client given object path missing
The validation of the client's given ResourcePool object
path is missing. Instead the submitted InstanceID is
taken as value for the AllocationCapabilities InstanceID.
wbemain -ac CIM_ElementCapabilities
'http://localhost/root/virt:KVM_DiskPool.InstanceID="notthere"'
returns
localhost:5988/root/virt:KVM_AllocationCapabilities.InstanceID="notthere"
Signed-off-by: Heidi Eckhart <heidieck(a)linux.vnet.ibm.com>
diff -r fd476f08b35e -r d4471d3ac476 src/Makefile.am
--- a/src/Makefile.am Thu Jan 10 14:20:52 2008 +0100
+++ b/src/Makefile.am Thu Jan 10 14:20:53 2008 +0100
@@ -89,17 +89,18 @@ libVirt_ElementConformsToProfile_la_LIBA
libVirt_EnabledLogicalElementCapabilities_la_SOURCES =
Virt_EnabledLogicalElementCapabilities.c
+libVirt_AllocationCapabilities_la_DEPENDENCIES = libVirt_DevicePool.la
+libVirt_AllocationCapabilities_la_SOURCES = Virt_AllocationCapabilities.c
+libVirt_AllocationCapabilities_la_LIBADD = -lVirt_DevicePool
+
libVirt_ElementCapabilities_la_DEPENDENCIES =
libVirt_VirtualSystemManagementCapabilities.la
libVirt_EnabledLogicalElementCapabilities.la libVirt_ComputerSystem.la
libVirt_HostSystem.la libVirt_VSMigrationCapabilities.la
libVirt_ElementCapabilities_la_SOURCES = Virt_ElementCapabilities.c
libVirt_ElementCapabilities_la_LIBADD = -lVirt_VirtualSystemManagementCapabilities \
-lVirt_EnabledLogicalElementCapabilities \
-lVirt_ComputerSystem \
-lVirt_HostSystem \
- -lVirt_VSMigrationCapabilities
-
-libVirt_AllocationCapabilities_la_DEPENDENCIES = libVirt_DevicePool.la
-libVirt_AllocationCapabilities_la_SOURCES = Virt_AllocationCapabilities.c
-libVirt_AllocationCapabilities_la_LIBADD = -lVirt_DevicePool
+ -lVirt_VSMigrationCapabilities \
+ -lVirt_AllocationCapabilities
libVirt_SettingsDefineCapabilities_la_DEPENDENCIES = libVirt_RASD.la
libVirt_DevicePool.la
libVirt_SettingsDefineCapabilities_la_SOURCES = Virt_SettingsDefineCapabilities.c
diff -r fd476f08b35e -r d4471d3ac476 src/Virt_ElementCapabilities.c
--- a/src/Virt_ElementCapabilities.c Thu Jan 10 14:20:52 2008 +0100
+++ b/src/Virt_ElementCapabilities.c Thu Jan 10 14:20:53 2008 +0100
@@ -37,6 +37,7 @@
#include "Virt_ComputerSystem.h"
#include "Virt_HostSystem.h"
#include "Virt_VSMigrationCapabilities.h"
+#include "Virt_AllocationCapabilities.h"
/* Associate an XXX_Capabilities to the proper XXX_ManagedElement.
*
@@ -46,6 +47,37 @@
*/
const static CMPIBroker *_BROKER;
+
+static CMPIStatus validate_host_caps_ref(const CMPIObjectPath *ref)
+{
+ CMPIStatus s = {CMPI_RC_OK, NULL};
+ CMPIInstance *inst;
+ const char *prop;
+ char* classname;
+
+ classname = class_base_name(CLASSNAME(ref));
+
+ if (STREQC(classname, "VirtualSystemManagementCapabilities")) {
+ s = get_vsm_cap(_BROKER, ref, &inst);
+ } else if (STREQC(classname, "VirtualSystemMigrationCapabilities")) {
+ s = get_migration_caps(ref, &inst, _BROKER);
+ }
+
+ if (s.rc != CMPI_RC_OK)
+ goto out;
+
+ prop = cu_compare_ref(ref, inst);
+ if (prop != NULL) {
+ cu_statusf(_BROKER, &s,
+ CMPI_RC_ERR_NOT_FOUND,
+ "No such instance (%s)", prop);
+ }
+
+ out:
+ free(classname);
+
+ return s;
+}
static CMPIStatus sys_to_cap(const CMPIObjectPath *ref,
struct std_assoc_info *info,
@@ -53,22 +85,13 @@ static CMPIStatus sys_to_cap(const CMPIO
{
CMPIInstance *inst;
CMPIStatus s = {CMPI_RC_OK, NULL};
- const char *prop;
-
- if (!match_hypervisor_prefix(ref, info))
- return s;
-
- s = get_host_cs(_BROKER, ref, &inst);
- if (s.rc != CMPI_RC_OK)
- goto out;
-
- prop = cu_compare_ref(ref, inst);
- if (prop != NULL) {
- cu_statusf(_BROKER, &s,
- CMPI_RC_ERR_FAILED,
- "No such HostSystem (%s)", prop);
- goto out;
- }
+
+ if (!match_hypervisor_prefix(ref, info))
+ goto out;
+
+ s = validate_host_ref(_BROKER, ref);
+ if (s.rc != CMPI_RC_OK)
+ goto out;
s = get_vsm_cap(_BROKER, ref, &inst);
if (s.rc == CMPI_RC_OK)
@@ -90,7 +113,11 @@ static CMPIStatus cap_to_sys(const CMPIO
CMPIStatus s = {CMPI_RC_OK, NULL};
if (!match_hypervisor_prefix(ref, info))
- return s;
+ goto out;
+
+ s = validate_host_caps_ref(ref);
+ if (s.rc != CMPI_RC_OK)
+ goto out;
s = get_host_cs(_BROKER, ref, &inst);
if (s.rc != CMPI_RC_OK)
@@ -111,7 +138,11 @@ static CMPIStatus cs_to_cap(const CMPIOb
const char *sys_name = NULL;
if (!match_hypervisor_prefix(ref, info))
- return s;
+ goto out;
+
+ s = validate_domain_ref(_BROKER, ref);
+ if (s.rc != CMPI_RC_OK)
+ goto out;
if (cu_get_str_path(ref, "Name", &sys_name) != CMPI_RC_OK) {
cu_statusf(_BROKER, &s,
@@ -138,26 +169,30 @@ static CMPIStatus cap_to_cs(const CMPIOb
CMPIStatus s = {CMPI_RC_OK, NULL};
if (!match_hypervisor_prefix(ref, info))
- return s;
+ goto out;
if (cu_get_str_path(ref, "InstanceID", &inst_id) != CMPI_RC_OK) {
cu_statusf(_BROKER, &s,
CMPI_RC_ERR_FAILED,
"Could not get InstanceID");
- goto error1;
+ goto out;
}
conn = connect_by_classname(_BROKER, CLASSNAME(ref), &s);
if (s.rc != CMPI_RC_OK)
- goto error1;
+ goto out;
inst = instance_from_name(_BROKER, conn, inst_id, ref);
if (inst)
inst_list_add(list, inst);
-
+ else
+ cu_statusf(_BROKER, &s,
+ CMPI_RC_ERR_NOT_FOUND,
+ "No such instance (%s)", inst_id);
+
virConnectClose(conn);
- error1:
-
+
+ out:
return s;
}
@@ -173,14 +208,12 @@ static CMPIStatus pool_to_alloc(const CM
struct std_assoc_info *info,
struct inst_list *list)
{
- int ret;
+ CMPIStatus s = {CMPI_RC_OK, NULL};
+ CMPIInstance *inst = NULL;
const char *inst_id;
- uint16_t type;
- CMPIInstance *inst = NULL;
- CMPIStatus s = {CMPI_RC_OK};
-
- if (!match_hypervisor_prefix(ref, info))
- return s;
+
+ if (!match_hypervisor_prefix(ref, info))
+ goto out;
if (cu_get_str_path(ref, "InstanceID", &inst_id) != CMPI_RC_OK) {
cu_statusf(_BROKER, &s,
@@ -189,22 +222,16 @@ static CMPIStatus pool_to_alloc(const CM
goto out;
}
- inst = get_typed_instance(_BROKER,
- CLASSNAME(ref),
- "AllocationCapabilities",
- NAMESPACE(ref));
- CMSetProperty(inst, "InstanceID", inst_id, CMPI_chars);
-
- ret = cu_get_u16_path(ref, "ResourceType", &type);
- if (ret != 1) {
- cu_statusf(_BROKER, &s,
- CMPI_RC_ERR_FAILED,
- "Could not get ResourceType");
- goto out;
- }
- CMSetProperty(inst, "ResourceType", &type, CMPI_uint16);
-
- inst_list_add(list, inst);
+ s = alloc_cap_instances(_BROKER,
+ ref,
+ NULL,
+ false,
+ NULL,
+ inst_id,
+ &inst);
+
+ if (inst)
+ inst_list_add(list, inst);
out:
return s;