[PATCH 0 of 2] SD: check client given object path

To enable the check of the client's given object path for Devices, the first tiny reorg in the Device provider is necessary. Thereby the get_device() function is made available for external use. The second patch fixes the missing check of the client's given object in SystemDevice provider - for both directions.

# HG changeset patch # User Heidi Eckhart <heidieck@linux.vnet.ibm.com> # Date 1202214821 -3600 # Node ID 9163192a3407b4b0f02ab15d291830f52b5261fa # Parent 0bbd401701982deb19263023b560415a2cb69360 Device: make get_device() function available for use by SD assoc Signed-off-by: Heidi Eckhart <heidieck@linux.vnet.ibm.com> diff -r 0bbd40170198 -r 9163192a3407 src/Virt_Device.c --- a/src/Virt_Device.c Tue Feb 05 11:53:19 2008 +0100 +++ b/src/Virt_Device.c Tue Feb 05 13:33:41 2008 +0100 @@ -451,47 +451,70 @@ CMPIInstance *instance_from_devid(const return instance; } -static CMPIStatus get_device(const CMPIObjectPath *reference, - const CMPIResult *results, - const char *devid) +CMPIStatus get_device(const CMPIBroker *broker, + const CMPIObjectPath *reference, + CMPIInstance **_inst) { CMPIStatus s = {CMPI_RC_OK, NULL}; virConnectPtr conn; CMPIInstance *inst; const char *cn; + const char *devid; cn = CLASSNAME(reference); - conn = connect_by_classname(_BROKER, cn, &s); + conn = connect_by_classname(broker, cn, &s); if (conn == NULL) { - cu_statusf(_BROKER, &s, + cu_statusf(broker, &s, CMPI_RC_ERR_NOT_FOUND, "No such instance"); goto out; - } - - inst = instance_from_devid(_BROKER, + } + + if (cu_get_str_path(reference, "DeviceID", &devid) != CMPI_RC_OK) { + cu_statusf(broker, &s, + CMPI_RC_ERR_FAILED, + "No DeviceID specified"); + goto out; + } + + inst = instance_from_devid(broker, conn, devid, NAMESPACE(reference), device_type_from_classname(cn)); if (inst == NULL) { - cu_statusf(_BROKER, &s, + cu_statusf(broker, &s, CMPI_RC_ERR_NOT_FOUND, "No such instance (%s)", devid); goto out; } - s = cu_validate_ref(_BROKER, reference, inst); + s = cu_validate_ref(broker, reference, inst); if (s.rc != CMPI_RC_OK) goto out; - CMReturnInstance(results, inst); + *_inst = inst; out: virConnectClose(conn); return s; +} + +static CMPIStatus return_device(const CMPIResult *results, + const CMPIObjectPath *reference) +{ + CMPIStatus s = {CMPI_RC_OK, NULL}; + CMPIInstance *inst = NULL; + + s = get_device(_BROKER, reference, &inst); + if (s.rc != CMPI_RC_OK || inst == NULL) + return s; + + CMReturnInstance(results, inst); + + return s; } static CMPIStatus EnumInstanceNames(CMPIInstanceMI *self, @@ -517,19 +540,7 @@ static CMPIStatus GetInstance(CMPIInstan const CMPIObjectPath *reference, const char **properties) { - const char *devid; - - if (cu_get_str_path(reference, "DeviceID", &devid) != CMPI_RC_OK) { - CMPIStatus s; - - cu_statusf(_BROKER, &s, - CMPI_RC_ERR_FAILED, - "No DeviceID specified"); - - return s; - } - - return get_device(reference, results, devid); + return return_device(results, reference); } DEFAULT_CI(); diff -r 0bbd40170198 -r 9163192a3407 src/Virt_Device.h --- a/src/Virt_Device.h Tue Feb 05 11:53:19 2008 +0100 +++ b/src/Virt_Device.h Tue Feb 05 13:33:41 2008 +0100 @@ -42,6 +42,19 @@ int dom_devices(const CMPIBroker *broker struct inst_list *list); /** + * Returns the device instance defined by the reference + * + * @param broker A pointer to the CIM broker + * @param reference The object path identifying the instance + * @param inst Contains the pointer to the instance in case + * of success + * @returns CMPIStatus of the operation + */ +CMPIStatus get_device(const CMPIBroker *broker, + const CMPIObjectPath *reference, + CMPIInstance **_inst); + +/** * Return a device instance for a given devid * * @param broker A pointer to the CIM broker

# HG changeset patch # User Heidi Eckhart <heidieck@linux.vnet.ibm.com> # Date 1202215071 -3600 # Node ID 360734df2cd2eabbc2a2a9095a95d022f6c4130f # Parent 9163192a3407b4b0f02ab15d291830f52b5261fa SD: does not check client given object path wbemrin -arc CIM_SystemDevice 'http://localhost/root/virt:KVM_ComputerSystem.CreationClassName="KVM_ComputerSystem",Name="wrong"' returns nothing instead of NOT_FOUND. The object path for devices is also not checked. Signed-off-by: Heidi Eckhart <heidieck@linux.vnet.ibm.com> diff -r 9163192a3407 -r 360734df2cd2 src/Virt_SystemDevice.c --- a/src/Virt_SystemDevice.c Tue Feb 05 13:33:41 2008 +0100 +++ b/src/Virt_SystemDevice.c Tue Feb 05 13:37:51 2008 +0100 @@ -134,10 +134,15 @@ static CMPIStatus sys_to_dev(const CMPIO { const char *host = NULL; CMPIStatus s = {CMPI_RC_OK, NULL}; + CMPIInstance *inst = NULL; int ret; if (!match_hypervisor_prefix(ref, info)) return s; + + s = get_domain(_BROKER, ref, &inst); + if (s.rc != CMPI_RC_OK) + goto out; if (cu_get_str_path(ref, "Name", &host) != CMPI_RC_OK) { cu_statusf(_BROKER, &s, @@ -171,10 +176,15 @@ static CMPIStatus dev_to_sys(const CMPIO char *host = NULL; char *dev = NULL; CMPIInstance *sys; + CMPIInstance *inst = NULL; CMPIStatus s = {CMPI_RC_OK, NULL}; if (!match_hypervisor_prefix(ref, info)) return s; + + s = get_device(_BROKER, ref, &inst); + if (s.rc != CMPI_RC_OK) + goto out; if (cu_get_str_path(ref, "DeviceID", &devid) != CMPI_RC_OK) { cu_statusf(_BROKER, &s,

Heidi Eckhart wrote:
To enable the check of the client's given object path for Devices, the first tiny reorg in the Device provider is necessary. Thereby the get_device() function is made available for external use. The second patch fixes the missing check of the client's given object in SystemDevice provider - for both directions.
This looks fine and tested fine for me. +1 -- Kaitlin Rupert IBM Linux Technology Center kaitlin@linux.vnet.ibm.com
participants (2)
-
Heidi Eckhart
-
Kaitlin Rupert