# HG changeset patch
# User Heidi Eckhart <heidieck(a)linux.vnet.ibm.com>
# Date 1203672857 -3600
# Node ID 644476f8ee52477f05fc3080baa517f697497eee
# Parent d72742466a8892154997d2f210cb9ceeff035962
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(a)linux.vnet.ibm.com>
diff -r d72742466a88 -r 644476f8ee52 src/Virt_VSSD.c
--- a/src/Virt_VSSD.c Tue Feb 19 15:29:52 2008 -0800
+++ b/src/Virt_VSSD.c Fri Feb 22 10:34:17 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) != 1) {
+ 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 d72742466a88 -r 644476f8ee52 src/Virt_VSSD.h
--- a/src/Virt_VSSD.h Tue Feb 19 15:29:52 2008 -0800
+++ b/src/Virt_VSSD.h Fri Feb 22 10:34:17 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