[PATCH 0 of 2] (#2) Make VSMigrationService validate reference keys

# HG changeset patch # User Dan Smith <danms@us.ibm.com> # Date 1201194986 28800 # Node ID b0b9833dfa219a3e9a7898c0b6f5bab7afaf460a # Parent adf18661f7948a0287a4586d97572793e8e03826 Add ref class/prefix compare to misc_util Signed-off-by: Dan Smith <danms@us.ibm.com> diff -r adf18661f794 -r b0b9833dfa21 libxkutil/misc_util.c --- a/libxkutil/misc_util.c Thu Jan 24 12:56:45 2008 +0100 +++ b/libxkutil/misc_util.c Thu Jan 24 09:16:26 2008 -0800 @@ -435,6 +435,60 @@ bool libvirt_cim_init(void) return virInitialize == 0; } +bool check_refs_pfx_match(const CMPIObjectPath *refa, + const CMPIObjectPath *refb) +{ + bool result = false; + const char *refa_cn; + const char *refb_cn; + const char *ccn; + char *refa_pfx = NULL; + char *refb_pfx = NULL; + + refa_cn = CLASSNAME(refa); + refb_cn = CLASSNAME(refb); + + if ((refa_cn == NULL) || (refb_cn == NULL)) { + CU_DEBUG("Error getting ref classes %s:%s", + refa_cn, refb_cn); + goto out; + } + + refa_pfx = class_prefix_name(refa_cn); + refb_pfx = class_prefix_name(refb_cn); + + if ((refa_pfx == NULL) || (refb_pfx == NULL)) { + CU_DEBUG("Error getting ref prefixes %s:%s %s:%s", + refa_pfx, refb_pfx, + refa_cn, refb_cn); + goto out; + } + + if (!STREQC(refa_pfx, refb_pfx)) { + CU_DEBUG("Ref mismatch: %s != %s", + refa_pfx, + refb_pfx); + goto out; + } + + if (cu_get_str_path(refb, "CreationClassName", &ccn) == CMPI_RC_OK) { + if (!STREQC(ccn, refb_cn)) { + CU_DEBUG("ClassName(%s) != CreationClassName(%s)", + refb_cn, + ccn); + goto out; + } + } + + result = true; + + out: + free(refa_pfx); + free(refb_pfx); + + return result; +} + /* * Local Variables: * mode: C diff -r adf18661f794 -r b0b9833dfa21 libxkutil/misc_util.h --- a/libxkutil/misc_util.h Thu Jan 24 12:56:45 2008 +0100 +++ b/libxkutil/misc_util.h Thu Jan 24 09:16:26 2008 -0800 @@ -115,6 +115,8 @@ CMPIInstance *make_reference(const CMPIB struct std_assoc_info *info, struct std_assoc *assoc); +bool check_refs_pfx_match(const CMPIObjectPath *refa, + const CMPIObjectPath *refb); #define LIBVIRT_CIM_DEFAULT_MAKEREF() \ static CMPIInstance* make_ref(const CMPIObjectPath *source_ref, \

# HG changeset patch # User Dan Smith <danms@us.ibm.com> # Date 1201212668 28800 # Node ID b8f454a12678a26c1a93d803b7b2d29e40c4b0b4 # Parent b0b9833dfa219a3e9a7898c0b6f5bab7afaf460a Check CreationClassName in MigrationService Signed-off-by: Dan Smith <danms@us.ibm.com> diff -r b0b9833dfa21 -r b8f454a12678 src/Virt_VSMigrationService.c --- a/src/Virt_VSMigrationService.c Thu Jan 24 09:16:26 2008 -0800 +++ b/src/Virt_VSMigrationService.c Thu Jan 24 14:11:08 2008 -0800 @@ -204,6 +204,14 @@ static CMPIStatus vs_migratable_host(CMP return s; } + if (!check_refs_pfx_match(ref, system)) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Invalid REF in ComputerSystem"); + METHOD_RETURN(results, 1); + return s; + } + return vs_migratable(ref, name, dhost, results); } @@ -235,6 +243,14 @@ static CMPIStatus vs_migratable_system(C cu_statusf(_BROKER, &s, CMPI_RC_ERR_FAILED, "Missing key (Name) in ComputerSystem"); + METHOD_RETURN(results, 1); + return s; + } + + if (!check_refs_pfx_match(ref, sys)) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Invalid REF in ComputerSystem"); METHOD_RETURN(results, 1); return s; } @@ -549,6 +565,14 @@ static CMPIStatus migrate_vs_host(CMPIMe return s; } + if (!check_refs_pfx_match(ref, system)) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Invalid REF in ComputerSystem"); + METHOD_RETURN(results, 1); + return s; + } + return migrate_do(ref, ctx, name, dhost, results, argsout); } @@ -580,6 +604,14 @@ static CMPIStatus migrate_vs_system(CMPI cu_statusf(_BROKER, &s, CMPI_RC_ERR_FAILED, "Missing key (Name) in ComputerSystem"); + METHOD_RETURN(results, 1); + return s; + } + + if (!check_refs_pfx_match(ref, sys)) { + cu_statusf(_BROKER, &s, + CMPI_RC_ERR_FAILED, + "Invalid REF in ComputerSystem"); METHOD_RETURN(results, 1); return s; }

Dan Smith wrote:
Remove extra debug /.
_______________________________________________ Libvirt-cim mailing list Libvirt-cim@redhat.com https://www.redhat.com/mailman/listinfo/libvirt-cim
This looks good for me ... +1 -- Regards Heidi Eckhart Software Engineer IBM Linux Technology Center - Open Hypervisor
participants (3)
-
Dan Smith
-
Heidi Eckhart
-
Kaitlin Rupert