[PATCH 0 of 3] Enable VSSD to validate client given object path and Adopt changed to VSSD interface to ESD & SDS

# HG changeset patch # User Heidi Eckhart <heidieck@linux.vnet.ibm.com> # Date 1203507766 -3600 # Node ID c77500943eae17131c7d0522a99d16b3e2f43489 # Parent 60e38dd96ca6871856d64056305fc200d718b3a5 VSSD: validate client given object path wbemgi 'http://localhost:5988/root/virt:KVM_VirtualSystemSettingData.InstanceID="Xen:kvm1-f8"' on a KVM only system is returning an instance, but should not. wbemgi 'http://localhost:5988/root/virt:Xen_VirtualSystemSettingData.InstanceID="KVM:kvm1-f8"' on a KVM only system is seg faulting, but should not ;). Signed-off-by: Heidi Eckhart <heidieck@linux.vnet.ibm.com> diff -r 60e38dd96ca6 -r c77500943eae src/Virt_VSSD.c --- a/src/Virt_VSSD.c Tue Feb 19 15:29:52 2008 -0800 +++ b/src/Virt_VSSD.c Wed Feb 20 12:42:46 2008 +0100 @@ -135,42 +135,46 @@ static int instance_from_dom(virDomainPt return ret; } -CMPIInstance *get_vssd_instance(virDomainPtr dom, - const CMPIBroker *broker, - const CMPIObjectPath *ref) -{ - CMPIInstance *inst; - +static CMPIInstance *_get_vssd(const CMPIBroker *broker, + const CMPIObjectPath *reference, + virConnectPtr conn, + virDomainPtr dom, + CMPIStatus *s) +{ + CMPIInstance *inst = NULL; + inst = get_typed_instance(broker, - CLASSNAME(ref), + pfx_from_conn(conn), "VirtualSystemSettingData", - NAMESPACE(ref)); - - if (inst == NULL) - return NULL; - - if (instance_from_dom(dom, inst)) - return inst; - else - return NULL; -} - -static CMPIStatus enum_vssd(const CMPIObjectPath *reference, - const CMPIResult *results, - int names_only) + NAMESPACE(reference)); + + if (inst == NULL) { + cu_statusf(broker, s, + CMPI_RC_ERR_FAILED, + "Unable to init VirtualSystemSettingData instance"); + goto out; + } + + if (!instance_from_dom(dom, inst)) { + cu_statusf(broker, s, + CMPI_RC_ERR_FAILED, + "Unable to get VSSD instance from Domain"); + } + + out: + return inst; +} + +static CMPIStatus return_enum_vssd(const CMPIObjectPath *reference, + const CMPIResult *results, + bool names_only) { virConnectPtr conn; virDomainPtr *list; int count; int i; - CMPIStatus s; - const char *ns; - - if (!provider_is_responsible(_BROKER, reference, &s)) - return s; - - ns = NAMESPACE(reference); - + CMPIStatus s = {CMPI_RC_OK, NULL}; + conn = connect_by_classname(_BROKER, CLASSNAME(reference), &s); if (conn == NULL) return s; @@ -181,60 +185,90 @@ static CMPIStatus enum_vssd(const CMPIOb CMPI_RC_ERR_FAILED, "Failed to enumerate domains"); goto out; - } else if (count == 0) { - cu_statusf(_BROKER, &s, - CMPI_RC_OK, - ""); - goto out; - } + } else if (count == 0) + goto out; for (i = 0; i < count; i++) { - CMPIInstance *inst; - - inst = get_vssd_instance(list[i], _BROKER, reference); + CMPIInstance *inst = NULL; + + inst = _get_vssd(_BROKER, reference, conn, list[i], &s); + virDomainFree(list[i]); if (inst == NULL) continue; - + if (names_only) cu_return_instance_name(results, inst); else CMReturnInstance(results, inst); } - cu_statusf(_BROKER, &s, - CMPI_RC_OK, - ""); out: free(list); return s; - -} - -static CMPIInstance *get_vssd_for_name(const CMPIObjectPath *reference, - char *name) +} + +CMPIStatus get_vssd_by_name(const CMPIBroker *broker, + const CMPIObjectPath *reference, + const char *name, + CMPIInstance **_inst) { virConnectPtr conn; virDomainPtr dom; - CMPIStatus s; - CMPIInstance *inst = NULL; - - conn = connect_by_classname(_BROKER, CLASSNAME(reference), &s); - if (conn == NULL) - return NULL; - + CMPIStatus s = {CMPI_RC_OK, NULL}; + + 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) - goto out; - - inst = get_vssd_instance(dom, _BROKER, reference); - + if (dom == NULL) { + cu_statusf(broker, &s, + CMPI_RC_ERR_NOT_FOUND, + "No such instance (%s)", + name); + goto out; + } + + *_inst = _get_vssd(broker, reference, conn, dom, &s); + + virDomainFree(dom); + out: virConnectClose(conn); - virDomainFree(dom); - - return inst; + + return s; +} + +CMPIStatus get_vssd_by_ref(const CMPIBroker *broker, + const CMPIObjectPath *reference, + CMPIInstance **_inst) +{ + CMPIStatus s = {CMPI_RC_OK, NULL}; + char *name = NULL; + + if (!parse_instanceid(reference, NULL, &name)) { + cu_statusf(broker, &s, + CMPI_RC_ERR_NOT_FOUND, + "No such instance (InstanceID)"); + goto out; + } + + s = get_vssd_by_name(broker, reference, name, _inst); + if (s.rc != CMPI_RC_OK) + goto out; + + s = cu_validate_ref(broker, reference, *_inst); + + free(name); + + out: + return s; } static CMPIStatus EnumInstanceNames(CMPIInstanceMI *self, @@ -242,7 +276,7 @@ static CMPIStatus EnumInstanceNames(CMPI const CMPIResult *results, const CMPIObjectPath *reference) { - return enum_vssd(reference, results, 1); + return return_enum_vssd(reference, results, true); } static CMPIStatus EnumInstances(CMPIInstanceMI *self, @@ -251,7 +285,7 @@ static CMPIStatus EnumInstances(CMPIInst const CMPIObjectPath *reference, const char **properties) { - return enum_vssd(reference, results, 0); + return return_enum_vssd(reference, results, false); } static CMPIStatus GetInstance(CMPIInstanceMI *self, @@ -261,26 +295,15 @@ static CMPIStatus GetInstance(CMPIInstan const char **properties) { CMPIStatus s; - CMPIInstance *inst; - char *locid; - - if (!parse_instanceid(reference, NULL, &locid)) { - cu_statusf(_BROKER, &s, - CMPI_RC_ERR_FAILED, - "Invalid InstanceID specified"); - return s; - } - - inst = get_vssd_for_name(reference, locid); - if (inst) - CMReturnInstance(results, inst); - - cu_statusf(_BROKER, &s, - CMPI_RC_OK, - ""); - - free(locid); - + CMPIInstance *inst = NULL; + + s = get_vssd_by_ref(_BROKER, reference, &inst); + if (s.rc != CMPI_RC_OK) + goto out; + + CMReturnInstance(results, inst); + + out: return s; } diff -r 60e38dd96ca6 -r c77500943eae src/Virt_VSSD.h --- a/src/Virt_VSSD.h Tue Feb 19 15:29:52 2008 -0800 +++ b/src/Virt_VSSD.h Wed Feb 20 12:42:46 2008 +0100 @@ -21,8 +21,14 @@ #ifndef __VIRT_VSSD_H #define __VIRT_VSSD_H -CMPIInstance *get_vssd_instance(virDomainPtr dom, - const CMPIBroker *broker, - const CMPIObjectPath *ref); +CMPIStatus get_vssd_by_ref(const CMPIBroker *broker, + const CMPIObjectPath *reference, + CMPIInstance **_inst); + +CMPIStatus get_vssd_by_name(const CMPIBroker *broker, + const CMPIObjectPath *reference, + const char *name, + CMPIInstance **_inst); + #endif

Heidi Eckhart wrote:
# HG changeset patch # User Heidi Eckhart <heidieck@linux.vnet.ibm.com> # Date 1203507766 -3600 # Node ID c77500943eae17131c7d0522a99d16b3e2f43489 # Parent 60e38dd96ca6871856d64056305fc200d718b3a5 VSSD: validate client given object path
wbemgi 'http://localhost:5988/root/virt:KVM_VirtualSystemSettingData.InstanceID="Xen:kvm1-f8"' on a KVM only system is returning an instance, but should not.
wbemgi 'http://localhost:5988/root/virt:Xen_VirtualSystemSettingData.InstanceID="KVM:kvm1-f8"' on a KVM only system is seg faulting, but should not ;).
Signed-off-by: Heidi Eckhart <heidieck@linux.vnet.ibm.com>
diff -r 60e38dd96ca6 -r c77500943eae src/Virt_VSSD.c
- -static CMPIStatus enum_vssd(const CMPIObjectPath *reference, - const CMPIResult *results, - int names_only) + NAMESPACE(reference)); + + if (inst == NULL) { + cu_statusf(broker, s, + CMPI_RC_ERR_FAILED, + "Unable to init VirtualSystemSettingData instance"); + goto out; + } + + if (!instance_from_dom(dom, inst)) {
Probably not worth a resend, but since instance_from_dom() returns an int, this should be if (!instance_from_dom(dom, inst) != 1) {
+ + s = cu_validate_ref(broker, reference, *_inst);
If we encounter an error here, do we need to set a status message?
+ + free(name); + + out: + return s; -- Kaitlin Rupert IBM Linux Technology Center kaitlin@linux.vnet.ibm.com

Kaitlin Rupert wrote:
Heidi Eckhart wrote:
+ } + + if (!instance_from_dom(dom, inst)) {
Probably not worth a resend, but since instance_from_dom() returns an int, this should be if (!instance_from_dom(dom, inst) != 1) { sure ... I will resend again :) ... sorry, was too fast with my resend #2 and will create a #3 (oops)
+ + s = cu_validate_ref(broker, reference, *_inst);
If we encounter an error here, do we need to set a status message?
The correct status is set by cu_validate_ref() and directly returned to the client. So this is not necessary here. -- Regards Heidi Eckhart Software Engineer IBM Linux Technology Center - Open Hypervisor

# HG changeset patch # User Heidi Eckhart <heidieck@linux.vnet.ibm.com> # Date 1203508871 -3600 # Node ID 4a89baa025dfffc42cdd5f15c725b7b42fcb1212 # Parent c77500943eae17131c7d0522a99d16b3e2f43489 ESD: adopt interface changes in VSSD Signed-off-by: Heidi Eckhart <heidieck@linux.vnet.ibm.com> diff -r c77500943eae -r 4a89baa025df src/Virt_ElementSettingData.c --- a/src/Virt_ElementSettingData.c Wed Feb 20 12:42:46 2008 +0100 +++ b/src/Virt_ElementSettingData.c Wed Feb 20 13:01:11 2008 +0100 @@ -41,47 +41,20 @@ static CMPIStatus vssd_to_vssd(const CMP { CMPIStatus s = {CMPI_RC_OK, NULL}; CMPIInstance *inst; - virConnectPtr conn = NULL; - virDomainPtr dom = NULL; - char *host = NULL; - + if (!match_hypervisor_prefix(ref, info)) return s; - if (!parse_instanceid(ref, NULL, &host)) { - cu_statusf(_BROKER, &s, - CMPI_RC_ERR_FAILED, - "Unable to get system name"); - goto out; - } - - conn = connect_by_classname(_BROKER, CLASSNAME(ref), &s); - if (conn == NULL) - goto out; - - dom = virDomainLookupByName(conn, host); - if (dom == NULL) { - cu_statusf(_BROKER, &s, - CMPI_RC_ERR_FAILED, - "No such system `%s'", host); - goto out; - } - - inst = get_vssd_instance(dom, _BROKER, ref); - if (inst == NULL) { - cu_statusf(_BROKER, &s, - CMPI_RC_ERR_FAILED, - "Error getting VSSD for `%s'", host); - goto out; - } - + /* Special association case: + * VSSD instance is pointing to itself + */ + s = get_vssd_by_ref(_BROKER, ref, &inst); + if (s.rc != CMPI_RC_OK) + goto out; + inst_list_add(list, inst); - + out: - virDomainFree(dom); - virConnectClose(conn); - free(host); - return s; }

# HG changeset patch # User Heidi Eckhart <heidieck@linux.vnet.ibm.com> # Date 1203509638 -3600 # Node ID 163ff2951cfcabe676535d6fcfe1c84f65271ba4 # Parent 4a89baa025dfffc42cdd5f15c725b7b42fcb1212 SDS: adopt interface changes in VSSD Signed-off-by: Heidi Eckhart <heidieck@linux.vnet.ibm.com> diff -r 4a89baa025df -r 163ff2951cfc src/Virt_SettingsDefineState.c --- a/src/Virt_SettingsDefineState.c Wed Feb 20 13:01:11 2008 +0100 +++ b/src/Virt_SettingsDefineState.c Wed Feb 20 13:13:58 2008 +0100 @@ -196,18 +196,16 @@ static CMPIStatus vs_to_vssd(const CMPIO struct std_assoc_info *info, struct inst_list *list) { - virConnectPtr conn = NULL; - virDomainPtr dom = NULL; + CMPIStatus s = {CMPI_RC_OK, NULL}; + CMPIInstance *inst; const char *name; - CMPIInstance *vssd; - CMPIStatus s = {CMPI_RC_OK, NULL}; - + if (!match_hypervisor_prefix(ref, info)) return s; - - conn = connect_by_classname(_BROKER, CLASSNAME(ref), &s); - if (conn == NULL) - return s; + + s = get_domain(_BROKER, ref, &inst); + if (s.rc != CMPI_RC_OK) + goto out; if (cu_get_str_path(ref, "Name", &name) != CMPI_RC_OK) { cu_statusf(_BROKER, &s, @@ -215,28 +213,15 @@ static CMPIStatus vs_to_vssd(const CMPIO "Missing Name property"); goto out; } - - dom = virDomainLookupByName(conn, name); - if (dom == NULL) { - cu_statusf(_BROKER, &s, - CMPI_RC_ERR_FAILED, - "No such domain `%s'", name); - goto out; - } - - vssd = get_vssd_instance(dom, _BROKER, ref); - if (vssd != NULL) - inst_list_add(list, vssd); - - cu_statusf(_BROKER, &s, - CMPI_RC_OK, - ""); - out: - virDomainFree(dom); - virConnectClose(conn); - + + s = get_vssd_by_name(_BROKER, ref, name, &inst); + if (s.rc != CMPI_RC_OK) + goto out; + + inst_list_add(list, inst); + + out: return s; - } static CMPIStatus vssd_to_vs(const CMPIObjectPath *ref, @@ -250,9 +235,14 @@ static CMPIStatus vssd_to_vs(const CMPIO virConnectPtr conn = NULL; CMPIStatus s = {CMPI_RC_OK, NULL}; CMPIInstance *cs; + CMPIInstance *inst; if (!match_hypervisor_prefix(ref, info)) return s; + + s = get_vssd_by_ref(_BROKER, ref, &inst); + if (s.rc != CMPI_RC_OK) + goto out; if (cu_get_str_path(ref, "InstanceID", &id) != CMPI_RC_OK) { cu_statusf(_BROKER, &s,

I'm unable to build with this set applied because VSSDC calls get_vssd_instance(). Otherwise, this set looks good. Awesome job on cleaning up ESD and SDS. -- Kaitlin Rupert IBM Linux Technology Center kaitlin@linux.vnet.ibm.com

Kaitlin Rupert wrote:
I'm unable to build with this set applied because VSSDC calls get_vssd_instance().
That's a very good point ! I was too inattentive when patching the association providers. -- Regards Heidi Eckhart Software Engineer IBM Linux Technology Center - Open Hypervisor
participants (2)
-
Heidi Eckhart
-
Kaitlin Rupert