[PATCH 0 of 2] Enable ELEC to validate client given object path and Adopt changed to ELEC interface to EC

ELEC does now take care of the client given object path. The resulting interface changes have been adopted to EC by the second patch

# HG changeset patch # User Heidi Eckhart <heidieck@linux.vnet.ibm.com> # Date 1203594741 -3600 # Node ID 0edc1241e58d872c251473c424758a425efa19b6 # Parent 163ff2951cfcabe676535d6fcfe1c84f65271ba4 ELEC: seg faults by wrong client given object path wbemgi 'http://localhost:5988/root/virt:KVM_EnabledLogicalElementCapabilities.InstanceID="wrong"' seg faults wbemgi 'http://localhost:5988/root/virt:Xen_EnabledLogicalElementCapabilities.InstanceID="kvm1-f8"' seg faults on a KVM only system Signed-off-by: Heidi Eckhart <heidieck@linux.vnet.ibm.com> diff -r 163ff2951cfc -r 0edc1241e58d src/Virt_EnabledLogicalElementCapabilities.c --- a/src/Virt_EnabledLogicalElementCapabilities.c Wed Feb 20 13:13:58 2008 +0100 +++ b/src/Virt_EnabledLogicalElementCapabilities.c Thu Feb 21 12:52:21 2008 +0100 @@ -46,26 +46,33 @@ enum {ENABLED = 2, QUIESCE, REBOOT, RESET}; - - - -static CMPIStatus set_inst_properties(const CMPIBroker *broker, - CMPIInstance *inst, - const char *classname, - const char *sys_name) -{ - CMPIStatus s = {CMPI_RC_OK, NULL}; + +static CMPIInstance *_get_elec(const CMPIBroker *broker, + const CMPIObjectPath *reference, + virConnectPtr conn, + const char *name, + CMPIStatus *s) +{ + CMPIInstance *inst = NULL; CMPIArray *array; uint16_t element; int edit_name = 0; - - CMSetProperty(inst, "CreationClassName", - (CMPIValue *)classname, CMPI_chars); - - CMSetProperty(inst, "InstanceID", (CMPIValue *)sys_name, CMPI_chars); - - array = CMNewArray(broker, 5, CMPI_uint16, &s); - if ((s.rc != CMPI_RC_OK) || CMIsNullObject(array)) + + inst = get_typed_instance(broker, + pfx_from_conn(conn), + "EnabledLogicalElementCapabilities", + NAMESPACE(reference)); + if (inst == NULL) { + cu_statusf(broker, s, + CMPI_RC_ERR_FAILED, + "Unable to init EnabledLogicalElementCapabilities instance"); + goto out; + } + + CMSetProperty(inst, "InstanceID", (CMPIValue *)name, CMPI_chars); + + array = CMNewArray(broker, 5, CMPI_uint16, s); + if ((s->rc != CMPI_RC_OK) || CMIsNullObject(array)) goto out; element = (uint16_t)ENABLED; @@ -88,56 +95,14 @@ static CMPIStatus set_inst_properties(co CMSetProperty(inst, "ElementNameEditSupported", (CMPIValue *)&edit_name, CMPI_boolean); - out: - return s; -} - -CMPIStatus get_ele_cap(const CMPIBroker *broker, - const CMPIObjectPath *ref, - const char *sys_name, - CMPIInstance **inst) -{ - CMPIStatus s; - CMPIObjectPath *op; - char *classname = NULL; - - classname = get_typed_class(CLASSNAME(ref), - "EnabledLogicalElementCapabilities"); - if (classname == NULL) { - cu_statusf(broker, &s, - CMPI_RC_ERR_FAILED, - "Invalid class"); - goto out; - } - - op = CMNewObjectPath(broker, NAMESPACE(ref), classname, &s); - if ((s.rc != CMPI_RC_OK) || CMIsNullObject(op)) { - cu_statusf(broker, &s, - CMPI_RC_ERR_FAILED, - "Cannot get object path for ELECapabilities"); - goto out; - } - - *inst = CMNewInstance(broker, op, &s); - if ((s.rc != CMPI_RC_OK) || (CMIsNullObject(*inst))) { - cu_statusf(broker, &s, - CMPI_RC_ERR_FAILED, - "Failed to instantiate HostSystem"); - goto out; - } - - s = set_inst_properties(broker, *inst, classname, sys_name); - - out: - free(classname); - - return s; -} - -static CMPIStatus return_ele_cap(const CMPIObjectPath *ref, - const CMPIResult *results, - int names_only, - const char *id) + + out: + return inst; +} + +static CMPIStatus return_enum_elec(const CMPIObjectPath *ref, + const CMPIResult *results, + bool names_only) { CMPIStatus s = {CMPI_RC_OK, NULL}; CMPIInstance *inst = NULL; @@ -154,7 +119,7 @@ static CMPIStatus return_ele_cap(const C count = get_domain_list(conn, &list); if (count <= 0) goto out; - + for (i = 0; i < count; i++) { name = virDomainGetName(list[i]); if (name == NULL) { @@ -163,31 +128,84 @@ static CMPIStatus return_ele_cap(const C "Unable to get domain names"); goto end; } - - if (id && (!STREQ(name, id))) - goto end; - - s = get_ele_cap(_BROKER, ref, name, &inst); + + inst = _get_elec(_BROKER, ref, conn, name, &s); if (s.rc != CMPI_RC_OK) goto end; - + if (names_only) cu_return_instance_name(results, inst); else CMReturnInstance(results, inst); - - end: + + end: virDomainFree(list[i]); - - if ((s.rc != CMPI_RC_OK) || (id && (STREQ(name, id)))) - goto out; } out: free(list); - virConnectClose(conn); + return s; +} + +CMPIStatus get_elec_by_name(const CMPIBroker *broker, + const CMPIObjectPath *reference, + const char *name, + CMPIInstance **_inst) +{ + CMPIStatus s = {CMPI_RC_OK, NULL}; + virConnectPtr conn; + virDomainPtr dom; + + conn = connect_by_classname(broker, CLASSNAME(reference), &s); + if (conn == NULL) { + cu_statusf(broker, &s, + CMPI_RC_ERR_NOT_FOUND, + "No such instance"); + goto out; + } + + dom = virDomainLookupByName(conn, name); + if (dom == NULL) { + cu_statusf(broker, &s, + CMPI_RC_ERR_NOT_FOUND, + "No such instance (%s)", + name); + goto out; + } + + *_inst = _get_elec(broker, reference, conn, name, &s); + + virDomainFree(dom); + + out: + virConnectClose(conn); + + return s; +} + +CMPIStatus get_elec_by_ref(const CMPIBroker *broker, + const CMPIObjectPath *reference, + CMPIInstance **_inst) +{ + CMPIStatus s = {CMPI_RC_OK, NULL}; + const char *name; + + if (cu_get_str_path(reference, "InstanceID", &name) != CMPI_RC_OK) { + cu_statusf(broker, &s, + CMPI_RC_ERR_FAILED, + "No InstanceID specified"); + goto out; + } + + s = get_elec_by_name(broker, reference, name, _inst); + if (s.rc != CMPI_RC_OK) + goto out; + + s = cu_validate_ref(broker, reference, *_inst); + + out: return s; } @@ -196,7 +214,7 @@ static CMPIStatus EnumInstanceNames(CMPI const CMPIResult *results, const CMPIObjectPath *reference) { - return return_ele_cap(reference, results, 1, NULL); + return return_enum_elec(reference, results, true); } static CMPIStatus EnumInstances(CMPIInstanceMI *self, @@ -206,7 +224,7 @@ static CMPIStatus EnumInstances(CMPIInst const char **properties) { - return return_ele_cap(reference, results, 0, NULL); + return return_enum_elec(reference, results, false); } static CMPIStatus GetInstance(CMPIInstanceMI *self, @@ -216,16 +234,16 @@ static CMPIStatus GetInstance(CMPIInstan const char **properties) { CMPIStatus s = {CMPI_RC_OK, NULL}; - const char* id; - - if (cu_get_str_path(reference, "InstanceID", &id) != CMPI_RC_OK) { - cu_statusf(_BROKER, &s, - CMPI_RC_ERR_FAILED, - "No InstanceID specified"); - return s; - } - - return return_ele_cap(reference, results, 0, id); + CMPIInstance *inst = NULL; + + s = get_elec_by_ref(_BROKER, reference, &inst); + if (s.rc != CMPI_RC_OK) + goto out; + + CMReturnInstance(results, inst); + + out: + return s; } DEFAULT_CI(); diff -r 163ff2951cfc -r 0edc1241e58d src/Virt_EnabledLogicalElementCapabilities.h --- a/src/Virt_EnabledLogicalElementCapabilities.h Wed Feb 20 13:13:58 2008 +0100 +++ b/src/Virt_EnabledLogicalElementCapabilities.h Thu Feb 21 12:52:21 2008 +0100 @@ -18,10 +18,15 @@ * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -CMPIStatus get_ele_cap(const CMPIBroker *broker, - const CMPIObjectPath *ref, - const char *sys_name, - CMPIInstance **inst); +CMPIStatus get_elec_by_name(const CMPIBroker *broker, + const CMPIObjectPath *reference, + const char *name, + CMPIInstance **_inst); + +CMPIStatus get_elec_by_ref(const CMPIBroker *broker, + const CMPIObjectPath *reference, + CMPIInstance **_inst); + /* * Local Variables: * mode: C

HE> + s = get_elec_by_name(broker, reference, name, _inst); HE> + if (s.rc != CMPI_RC_OK) HE> + goto out; HE> + HE> + s = cu_validate_ref(broker, reference, *_inst); HE> + Assuming the caller checks the status, there shouldn't be an issue, but maybe we shouldn't set _inst until we've validated the path? -- Dan Smith IBM Linux Technology Center Open Hypervisor Team email: danms@us.ibm.com

Dan Smith wrote:
HE> + s = get_elec_by_name(broker, reference, name, _inst); HE> + if (s.rc != CMPI_RC_OK) HE> + goto out; HE> + HE> + s = cu_validate_ref(broker, reference, *_inst); HE> +
Assuming the caller checks the status, there shouldn't be an issue, but maybe we shouldn't set _inst until we've validated the path?
Yes, you are absolutely right. I've changed this in the patches for ELEC, RASD and VSSD. -- Regards Heidi Eckhart Software Engineer IBM Linux Technology Center - Open Hypervisor

# HG changeset patch # User Heidi Eckhart <heidieck@linux.vnet.ibm.com> # Date 1203594913 -3600 # Node ID 6fffc34df9c9b5cd1915f1fdd9f196b1f12a2477 # Parent 0edc1241e58d872c251473c424758a425efa19b6 EC: adopt interface changes to ELEC Signed-off-by: Heidi Eckhart <heidieck@linux.vnet.ibm.com> diff -r 0edc1241e58d -r 6fffc34df9c9 src/Virt_ElementCapabilities.c --- a/src/Virt_ElementCapabilities.c Thu Feb 21 12:52:21 2008 +0100 +++ b/src/Virt_ElementCapabilities.c Thu Feb 21 12:55:13 2008 +0100 @@ -216,7 +216,7 @@ static CMPIStatus cs_to_cap(const CMPIOb goto out; } - s = get_ele_cap(_BROKER, ref, sys_name, &inst); + s = get_elec_by_name(_BROKER, ref, sys_name, &inst); if (s.rc == CMPI_RC_OK) inst_list_add(list, inst); @@ -234,6 +234,10 @@ static CMPIStatus cap_to_cs(const CMPIOb CMPIStatus s = {CMPI_RC_OK, NULL}; if (!match_hypervisor_prefix(ref, info)) + goto out; + + s = get_elec_by_ref(_BROKER, ref, &inst); + if (s.rc != CMPI_RC_OK) goto out; if (cu_get_str_path(ref, "InstanceID", &inst_id) != CMPI_RC_OK) {
participants (3)
-
Dan Smith
-
Heidi Eckhart
-
Kaitlin Rupert