[PATCH 0 of 2] #2 - Validate client given object path in HostedService provider

Diff to #1 (HS: returns results for wrong object path): - moved validate_host_ref() function to HostSystem provider for global availability - fixed style issues

# HG changeset patch # User Heidi Eckhart <heidieck@linux.vnet.ibm.com> # Date 1199869322 -3600 # Node ID ee811a7e50179f019cda5267e27f44faa4a1f353 # Parent 10d141f683370b6f04637bb9ad059bbd92051ce0 Add function to validate the client given object path Signed-off-by: Heidi Eckhart <heidieck@linux.vnet.ibm.com> diff -r 10d141f68337 -r ee811a7e5017 src/Virt_HostSystem.c --- a/src/Virt_HostSystem.c Tue Jan 08 10:51:44 2008 -0800 +++ b/src/Virt_HostSystem.c Wed Jan 09 10:02:02 2008 +0100 @@ -35,6 +35,25 @@ #include "Virt_HostSystem.h" const static CMPIBroker *_BROKER; + +CMPIStatus validate_host_ref(const CMPIBroker *broker, + const CMPIObjectPath *ref) +{ + CMPIStatus s = {CMPI_RC_OK, NULL}; + CMPIInstance *inst; + const char *prop; + + s = get_host_cs(broker, ref, &inst); + + prop = cu_compare_ref(ref, inst); + if (prop != NULL) { + cu_statusf(broker, &s, + CMPI_RC_ERR_NOT_FOUND, + "No such instance (%s)", prop); + } + + return s; +} static int set_host_system_properties(CMPIInstance *instance) { diff -r 10d141f68337 -r ee811a7e5017 src/Virt_HostSystem.h --- a/src/Virt_HostSystem.h Tue Jan 08 10:51:44 2008 -0800 +++ b/src/Virt_HostSystem.h Wed Jan 09 10:02:02 2008 +0100 @@ -29,4 +29,8 @@ CMPIStatus get_host_system_properties(co const char **ccname, const CMPIObjectPath *ref, const CMPIBroker *broker); + +CMPIStatus validate_host_ref(const CMPIBroker *broker, + const CMPIObjectPath *ref); + #endif

# HG changeset patch # User Heidi Eckhart <heidieck@linux.vnet.ibm.com> # Date 1199869324 -3600 # Node ID ad0ca904d4cb6184c5ae0002891fa22f336dcce0 # Parent ee811a7e50179f019cda5267e27f44faa4a1f353 HS: returns results for wrong object path The client given reference was not checked for existance in both directions (from HostSystem to Service and reverse) and the call returned wrong results. Now NOT_FOUND is returned in case of a wrong object path. Examples: wbemcli ain -ac KVM_HostedService 'http://localhost/root/virt:KVM_ResourcePoolConfigurationService.CreationClassName="wrong",wrong="wrong"' wbemcli ain -ac KVM_HostedService 'http://localhost/root/virt:KVM_HostSystem.CreationClassName="KVM_HostSystem",Name="notthere"' Diff to #1: - fixed style issues - validate_host_ref() now in HostSystem provider Signed-off-by: Heidi Eckhart <heidieck@linux.vnet.ibm.com> diff -r ee811a7e5017 -r ad0ca904d4cb src/Makefile.am --- a/src/Makefile.am Wed Jan 09 10:02:02 2008 +0100 +++ b/src/Makefile.am Wed Jan 09 10:02:04 2008 +0100 @@ -135,9 +135,9 @@ libVirt_ElementAllocatedFromPool_la_SOUR libVirt_ElementAllocatedFromPool_la_SOURCES = Virt_ElementAllocatedFromPool.c libVirt_ElementAllocatedFromPool_la_LIBADD = -lVirt_DevicePool -lVirt_Device -libVirt_HostedService_la_DEPENDENCIES = libVirt_VirtualSystemManagementService.la libVirt_ResourcePoolConfigurationService.la libVirt_VSMigrationService.la +libVirt_HostedService_la_DEPENDENCIES = libVirt_VirtualSystemManagementService.la libVirt_ResourcePoolConfigurationService.la libVirt_VSMigrationService.la libVirt_HostSystem.la libVirt_HostedService_la_SOURCES = Virt_HostedService.c -libVirt_HostedService_la_LIBADD = -lVirt_VirtualSystemManagementService -lVirt_ResourcePoolConfigurationService -lVirt_VSMigrationService +libVirt_HostedService_la_LIBADD = -lVirt_VirtualSystemManagementService -lVirt_ResourcePoolConfigurationService -lVirt_VSMigrationService -lVirt_HostSystem libVirt_ElementSettingData_la_DEPENDENCIES = libVirt_VSSD.la libVirt_RASD.la libVirt_ElementSettingData_la_SOURCES = Virt_ElementSettingData.c diff -r ee811a7e5017 -r ad0ca904d4cb src/Virt_HostedService.c --- a/src/Virt_HostedService.c Wed Jan 09 10:02:02 2008 +0100 +++ b/src/Virt_HostedService.c Wed Jan 09 10:02:04 2008 +0100 @@ -37,6 +37,39 @@ const static CMPIBroker *_BROKER; +static CMPIStatus validate_service_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, "VirtualSystemManagementService")) { + s = get_vsms(ref, &inst, _BROKER); + } else if (STREQC(classname, "ResourcePoolConfigurationService")) { + s = rpcs_instance(ref, &inst, _BROKER); + } else if (STREQC(classname, "VirtualSystemMigrationService")) { + s = get_migration_service(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 service_to_host(const CMPIObjectPath *ref, struct std_assoc_info *info, struct inst_list *list) @@ -45,6 +78,10 @@ static CMPIStatus service_to_host(const CMPIInstance *instance; if (!match_hypervisor_prefix(ref, info)) + return s; + + s = validate_service_ref(ref); + if (s.rc != CMPI_RC_OK) return s; s = get_host_cs(_BROKER, ref, &instance); @@ -62,6 +99,10 @@ static CMPIStatus host_to_service(const CMPIInstance *inst; if (!match_hypervisor_prefix(ref, info)) + return s; + + s = validate_host_ref(_BROKER, ref); + if (s.rc != CMPI_RC_OK) return s; s = rpcs_instance(ref, &inst, _BROKER);
participants (2)
-
Heidi Eckhart
-
Kaitlin Rupert