[PATCH 0 of 2] #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 diff to patch set 1: - fixed get_elec_by_name and get_elec_by_ref to only return a valid instance pointer in case of success

# HG changeset patch # User Heidi Eckhart <heidieck@linux.vnet.ibm.com> # Date 1203934188 -3600 # Node ID 631eee1e6165c349e37e9552ff65c95726f72e4b # Parent 89ecbeb1ae6bd6a79bf9b0403a3f638c8732f2c7 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 89ecbeb1ae6b -r 631eee1e6165 src/Virt_EnabledLogicalElementCapabilities.c --- a/src/Virt_EnabledLogicalElementCapabilities.c Mon Feb 25 11:09:47 2008 +0100 +++ b/src/Virt_EnabledLogicalElementCapabilities.c Mon Feb 25 11:09:48 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,93 @@ 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}; + CMPIInstance *inst = 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); + if (s.rc != CMPI_RC_OK) + goto out; + + *_inst = inst; + + out: + virConnectClose(conn); + + return s; +} + +CMPIStatus get_elec_by_ref(const CMPIBroker *broker, + const CMPIObjectPath *reference, + CMPIInstance **_inst) +{ + CMPIStatus s = {CMPI_RC_OK, NULL}; + CMPIInstance *inst = 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); + if (s.rc != CMPI_RC_OK) + goto out; + + *_inst = inst; + + out: return s; } @@ -196,7 +223,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 +233,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 +243,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 89ecbeb1ae6b -r 631eee1e6165 src/Virt_EnabledLogicalElementCapabilities.h --- a/src/Virt_EnabledLogicalElementCapabilities.h Mon Feb 25 11:09:47 2008 +0100 +++ b/src/Virt_EnabledLogicalElementCapabilities.h Mon Feb 25 11:09:48 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> - HE> + You're *adding* a line with leading whitespace here. Please remove it. HE> - HE> + Here too. HE> - HE> - end: HE> + HE> + end: I think the 'end' placement was correct before, wasn't it? You're also adding a line with leading whitespace here. -- Dan Smith IBM Linux Technology Center Open Hypervisor Team email: danms@us.ibm.com

# HG changeset patch # User Heidi Eckhart <heidieck@linux.vnet.ibm.com> # Date 1203934189 -3600 # Node ID 875e54efe5feb2f65572c0b4d786081506e65cc8 # Parent 631eee1e6165c349e37e9552ff65c95726f72e4b EC: adopt interface changes to ELEC Signed-off-by: Heidi Eckhart <heidieck@linux.vnet.ibm.com> diff -r 631eee1e6165 -r 875e54efe5fe src/Virt_ElementCapabilities.c --- a/src/Virt_ElementCapabilities.c Mon Feb 25 11:09:48 2008 +0100 +++ b/src/Virt_ElementCapabilities.c Mon Feb 25 11:09:49 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 (2)
-
Dan Smith
-
Heidi Eckhart