コード例 #1
0
static virDomainDefPtr
testSELinuxLoadDef(const char *testname)
{
    char *xmlfile = NULL;
    char *xmlstr = NULL;
    virDomainDefPtr def = NULL;
    size_t i;

    if (virAsprintf(&xmlfile, "%s/securityselinuxlabeldata/%s.xml",
                    abs_srcdir, testname) < 0) {
        virReportOOMError();
        goto cleanup;
    }

    if (virFileReadAll(xmlfile, 1024*1024, &xmlstr) < 0) {
        goto cleanup;
    }

    if (!(def = virDomainDefParseString(caps, xmlstr,
                                        QEMU_EXPECTED_VIRT_TYPES,
                                        0)))
        goto cleanup;

    for (i = 0 ; i < def->ndisks ; i++) {
        if (def->disks[i]->type != VIR_DOMAIN_DISK_TYPE_FILE &&
            def->disks[i]->type != VIR_DOMAIN_DISK_TYPE_BLOCK)
            continue;

        if (testSELinuxMungePath(&def->disks[i]->src) < 0)
            goto cleanup;
    }

    for (i = 0 ; i < def->nserials ; i++) {
        if (def->serials[i]->source.type != VIR_DOMAIN_CHR_TYPE_FILE &&
            def->serials[i]->source.type != VIR_DOMAIN_CHR_TYPE_PIPE &&
            def->serials[i]->source.type != VIR_DOMAIN_CHR_TYPE_DEV &&
            def->serials[i]->source.type != VIR_DOMAIN_CHR_TYPE_UNIX)
            continue;

        if (def->serials[i]->source.type == VIR_DOMAIN_CHR_TYPE_UNIX) {
            if (testSELinuxMungePath(&def->serials[i]->source.data.nix.path) < 0)
                goto cleanup;
        } else {
            if (testSELinuxMungePath(&def->serials[i]->source.data.file.path) < 0)
                goto cleanup;
        }
    }

    if (def->os.kernel &&
        testSELinuxMungePath(&def->os.kernel) < 0)
        goto cleanup;
    if (def->os.initrd &&
        testSELinuxMungePath(&def->os.initrd) < 0)
        goto cleanup;

cleanup:
    VIR_FREE(xmlfile);
    VIR_FREE(xmlstr);
    return def;
}
コード例 #2
0
static virDomainDefPtr
testSELinuxLoadDef(const char *testname)
{
    char *xmlfile = NULL;
    virDomainDefPtr def = NULL;
    size_t i;

    if (virAsprintf(&xmlfile, "%s/securityselinuxlabeldata/%s.xml",
                    abs_srcdir, testname) < 0)
        goto cleanup;

    if (!(def = virDomainDefParseFile(xmlfile, driver.caps, driver.xmlopt,
                                      NULL, 0)))
        goto cleanup;

    for (i = 0; i < def->ndisks; i++) {
        if (def->disks[i]->src->type != VIR_STORAGE_TYPE_FILE &&
            def->disks[i]->src->type != VIR_STORAGE_TYPE_BLOCK)
            continue;

        if (testSELinuxMungePath(&def->disks[i]->src->path) < 0)
            goto cleanup;
    }

    for (i = 0; i < def->nserials; i++) {
        if (def->serials[i]->source->type != VIR_DOMAIN_CHR_TYPE_FILE &&
            def->serials[i]->source->type != VIR_DOMAIN_CHR_TYPE_PIPE &&
            def->serials[i]->source->type != VIR_DOMAIN_CHR_TYPE_DEV &&
            def->serials[i]->source->type != VIR_DOMAIN_CHR_TYPE_UNIX)
            continue;

        if (def->serials[i]->source->type == VIR_DOMAIN_CHR_TYPE_UNIX) {
            if (testSELinuxMungePath(&def->serials[i]->source->data.nix.path) < 0)
                goto cleanup;
        } else {
            if (testSELinuxMungePath(&def->serials[i]->source->data.file.path) < 0)
                goto cleanup;
        }
    }

    if (def->os.kernel &&
        testSELinuxMungePath(&def->os.kernel) < 0)
        goto cleanup;
    if (def->os.initrd &&
        testSELinuxMungePath(&def->os.initrd) < 0)
        goto cleanup;

 cleanup:
    VIR_FREE(xmlfile);
    return def;
}