# HG changeset patch
# User Heidi Eckhart <heidieck(a)linux.vnet.ibm.com>
# Date 1200052160 -3600
# Node ID 90746174d66eb4d4ceb2b15633ff348a553ab908
# Parent 224b84cf00ac2e120d86e15d92ce50fddf6a0105
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 224b84cf00ac -r 90746174d66e src/Makefile.am
--- a/src/Makefile.am Fri Jan 11 12:49:19 2008 +0100
+++ b/src/Makefile.am Fri Jan 11 12:49:20 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 224b84cf00ac -r 90746174d66e src/Virt_ElementCapabilities.c
--- a/src/Virt_ElementCapabilities.c Fri Jan 11 12:49:19 2008 +0100
+++ b/src/Virt_ElementCapabilities.c Fri Jan 11 12:49:20 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,11 @@ static CMPIStatus pool_to_alloc(const CM
struct std_assoc_info *info,
struct inst_list *list)
{
- int ret;
+ CMPIStatus s = {CMPI_RC_OK, 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 +221,11 @@ 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 = enum_alloc_cap_instances(_BROKER,
+ ref,
+ NULL,
+ inst_id,
+ list);
out:
return s;