# HG changeset patch
# User Kaitlin Rupert <karupert(a)us.ibm.com>
# Date 1203463635 28800
# Node ID 0d38670abc3cd4be2560daddbd038ebce630f3fb
# Parent 95c56a7a865df18bbdf1066d8b04d5d4b75e7d44
Add reference validation to get_migration_service().
Adds reference validation to VirtualSystemMigrationService.
Updates:
-Initialize inst to NULL in return_vsms() to prevent seg fault
-Use pfx_from_conn() in get_migration_service() instead of CLASSNAME(ref)
Signed-off-by: Kaitlin Rupert <karupert(a)us.ibm.com>
diff -r 95c56a7a865d -r 0d38670abc3c src/Virt_VSMigrationService.c
--- a/src/Virt_VSMigrationService.c Tue Feb 19 08:39:04 2008 -0800
+++ b/src/Virt_VSMigrationService.c Tue Feb 19 15:27:15 2008 -0800
@@ -755,15 +755,26 @@ STDIM_MethodMIStub(, Virt_VSMigrationSer
CMPIStatus get_migration_service(const CMPIObjectPath *ref,
CMPIInstance **_inst,
- const CMPIBroker *broker)
+ const CMPIBroker *broker,
+ bool is_get_inst)
{
CMPIInstance *inst;
CMPIStatus s = {CMPI_RC_OK, NULL};
+ virConnectPtr conn = NULL;
const char *name = NULL;
const char *ccname = NULL;
+ conn = connect_by_classname(broker, CLASSNAME(ref), &s);
+ if (conn == NULL) {
+ if (is_get_inst)
+ cu_statusf(broker, &s,
+ CMPI_RC_ERR_NOT_FOUND,
+ "No such instance");
+ goto out;
+ }
+
inst = get_typed_instance(broker,
- CLASSNAME(ref),
+ pfx_from_conn(conn),
"VirtualSystemMigrationService",
NAMESPACE(ref));
if (inst == NULL) {
@@ -793,6 +804,12 @@ CMPIStatus get_migration_service(const C
CMSetProperty(inst, "SystemCreationClassName",
(CMPIValue *)ccname, CMPI_chars);
+ if (is_get_inst) {
+ s = cu_validate_ref(broker, ref, inst);
+ if (s.rc != CMPI_RC_OK)
+ goto out;
+ }
+
cu_statusf(broker, &s,
CMPI_RC_OK,
"");
@@ -800,24 +817,28 @@ CMPIStatus get_migration_service(const C
*_inst = inst;
out:
+ virConnectClose(conn);
+
return s;
}
static CMPIStatus return_vsms(const CMPIObjectPath *ref,
const CMPIResult *results,
- bool name_only)
-{
- CMPIInstance *inst;
- CMPIStatus s;
-
- s = get_migration_service(ref, &inst, _BROKER);
- if (s.rc == CMPI_RC_OK) {
- if (name_only)
- cu_return_instance_name(results, inst);
- else
- CMReturnInstance(results, inst);
- }
-
+ bool name_only,
+ bool is_get_inst)
+{
+ CMPIInstance *inst = NULL;
+ CMPIStatus s;
+
+ s = get_migration_service(ref, &inst, _BROKER, is_get_inst);
+ if ((s.rc != CMPI_RC_OK) || (inst == NULL))
+ goto out;
+
+ if (name_only)
+ cu_return_instance_name(results, inst);
+ else
+ CMReturnInstance(results, inst);
+ out:
return s;
}
@@ -826,7 +847,7 @@ static CMPIStatus EnumInstanceNames(CMPI
const CMPIResult *results,
const CMPIObjectPath *ref)
{
- return return_vsms(ref, results, true);
+ return return_vsms(ref, results, true, false, false);
}
static CMPIStatus EnumInstances(CMPIInstanceMI *self,
@@ -836,7 +857,7 @@ static CMPIStatus EnumInstances(CMPIInst
const char **properties)
{
- return return_vsms(ref, results, false);
+ return return_vsms(ref, results, false, false, false);
}
@@ -846,24 +867,7 @@ static CMPIStatus GetInstance(CMPIInstan
const CMPIObjectPath *ref,
const char **properties)
{
- CMPIInstance *inst;
- CMPIStatus s;
- const char *prop;
-
- s = get_migration_service(ref, &inst, _BROKER);
- if (s.rc != CMPI_RC_OK)
- return s;
-
- prop = cu_compare_ref(ref, inst);
- if (prop != NULL) {
- cu_statusf(_BROKER, &s,
- CMPI_RC_ERR_NOT_FOUND,
- "No such instance (%s)", prop);
- } else {
- CMReturnInstance(results, inst);
- }
-
- return s;
+ return return_vsms(ref, results, false, true, true);
}
DEFAULT_CI();
diff -r 95c56a7a865d -r 0d38670abc3c src/Virt_VSMigrationService.h
--- a/src/Virt_VSMigrationService.h Tue Feb 19 08:39:04 2008 -0800
+++ b/src/Virt_VSMigrationService.h Tue Feb 19 15:27:15 2008 -0800
@@ -21,7 +21,8 @@
CMPIStatus get_migration_service(const CMPIObjectPath *reference,
CMPIInstance **_inst,
- const CMPIBroker *broker);
+ const CMPIBroker *broker,
+ bool is_get_inst);
/*
* Local Variables: