[PATCH 0/2] test_driver: Implement some Security related APIs

Luke Yue (2): test_driver: Implement virNodeGetSecurityModel test_driver: Implement virDomainGetSecurityLabel src/test/test_driver.c | 63 ++++++++++++++++++++++++++++++++++++++++++ tests/virshtest.c | 4 +++ 2 files changed, 67 insertions(+) -- 2.31.1

Signed-off-by: Luke Yue <lukedyue@gmail.com> --- src/test/test_driver.c | 32 ++++++++++++++++++++++++++++++++ tests/virshtest.c | 2 ++ 2 files changed, 34 insertions(+) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index ea5a5005e7..2651301629 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -4963,6 +4963,7 @@ static int testDomainBlockStats(virDomainPtr domain, } + static int testDomainInterfaceAddressFromNet(testDriver *driver, const virDomainNetDef *net, @@ -5006,6 +5007,36 @@ testDomainInterfaceAddressFromNet(testDriver *driver, return ret; } +static int +testNodeGetSecurityModel(virConnectPtr conn, + virSecurityModelPtr secmodel) +{ + testDriver *driver = conn->privateData; + + memset(secmodel, 0, sizeof(*secmodel)); + + if (driver->caps->host.nsecModels == 0 || + driver->caps->host.secModels[0].model == NULL) + return 0; + + if (virStrcpy(secmodel->model, driver->caps->host.secModels[0].model, + VIR_SECURITY_MODEL_BUFLEN) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("security model string exceeds max %d bytes"), + VIR_SECURITY_MODEL_BUFLEN - 1); + return -1; + } + + if (virStrcpy(secmodel->doi, driver->caps->host.secModels[0].doi, + VIR_SECURITY_DOI_BUFLEN) < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("security DOI string exceeds max %d bytes"), + VIR_SECURITY_DOI_BUFLEN - 1); + return -1; + } + + return 0; +} static int testDomainInterfaceAddresses(virDomainPtr dom, @@ -9295,6 +9326,7 @@ static virHypervisorDriver testHypervisorDriver = { .domainGetVcpus = testDomainGetVcpus, /* 0.7.3 */ .domainGetVcpuPinInfo = testDomainGetVcpuPinInfo, /* 1.2.18 */ .domainGetMaxVcpus = testDomainGetMaxVcpus, /* 0.7.3 */ + .nodeGetSecurityModel = testNodeGetSecurityModel, /* 7.5.0 */ .domainGetXMLDesc = testDomainGetXMLDesc, /* 0.1.4 */ .domainSetMemoryParameters = testDomainSetMemoryParameters, /* 5.6.0 */ .domainGetMemoryParameters = testDomainGetMemoryParameters, /* 5.6.0 */ diff --git a/tests/virshtest.c b/tests/virshtest.c index add33215b7..119b2ef54d 100644 --- a/tests/virshtest.c +++ b/tests/virshtest.c @@ -34,6 +34,8 @@ Used memory: 131072 KiB\n\ Persistent: yes\n\ Autostart: disable\n\ Managed save: no\n\ +Security model: testSecurity\n\ +Security DOI: \n\ \n"; static const char *domuuid_fc4 = DOM_UUID "\n\n"; static const char *domid_fc4 = "2\n\n"; -- 2.31.1

On Mon, Jun 07, 2021 at 03:38:18PM +0800, Luke Yue wrote:
Signed-off-by: Luke Yue <lukedyue@gmail.com> --- src/test/test_driver.c | 32 ++++++++++++++++++++++++++++++++ tests/virshtest.c | 2 ++ 2 files changed, 34 insertions(+)
diff --git a/src/test/test_driver.c b/src/test/test_driver.c index ea5a5005e7..2651301629 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -4963,6 +4963,7 @@ static int testDomainBlockStats(virDomainPtr domain, }
+
Spurious change. Other than that Reviewed-by: Martin Kletzander <mkletzan@redhat.com>

Signed-off-by: Luke Yue <lukedyue@gmail.com> --- src/test/test_driver.c | 31 +++++++++++++++++++++++++++++++ tests/virshtest.c | 2 ++ 2 files changed, 33 insertions(+) diff --git a/src/test/test_driver.c b/src/test/test_driver.c index 2651301629..611ec6d7ec 100644 --- a/src/test/test_driver.c +++ b/src/test/test_driver.c @@ -5007,6 +5007,36 @@ testDomainInterfaceAddressFromNet(testDriver *driver, return ret; } +static int +testDomainGetSecurityLabel(virDomainPtr dom, + virSecurityLabelPtr seclabel) +{ + virDomainObj *vm; + int ret = -1; + + memset(seclabel, 0, sizeof(*seclabel)); + + if (!(vm = testDomObjFromDomain(dom))) + return -1; + + if (virDomainObjIsActive(vm)) { + if (virStrcpyStatic(seclabel->label, "libvirt-test") < 0) { + virReportError(VIR_ERR_INTERNAL_ERROR, + _("security label exceeds maximum: %zu"), + sizeof(seclabel->label) - 1); + goto cleanup; + } + + seclabel->enforcing = 1; + } + + ret = 0; + + cleanup: + virDomainObjEndAPI(&vm); + return ret; +} + static int testNodeGetSecurityModel(virConnectPtr conn, virSecurityModelPtr secmodel) @@ -9326,6 +9356,7 @@ static virHypervisorDriver testHypervisorDriver = { .domainGetVcpus = testDomainGetVcpus, /* 0.7.3 */ .domainGetVcpuPinInfo = testDomainGetVcpuPinInfo, /* 1.2.18 */ .domainGetMaxVcpus = testDomainGetMaxVcpus, /* 0.7.3 */ + .domainGetSecurityLabel = testDomainGetSecurityLabel, /* 7.5.0 */ .nodeGetSecurityModel = testNodeGetSecurityModel, /* 7.5.0 */ .domainGetXMLDesc = testDomainGetXMLDesc, /* 0.1.4 */ .domainSetMemoryParameters = testDomainSetMemoryParameters, /* 5.6.0 */ diff --git a/tests/virshtest.c b/tests/virshtest.c index 119b2ef54d..c1974c46cb 100644 --- a/tests/virshtest.c +++ b/tests/virshtest.c @@ -21,6 +21,7 @@ main(void) #else # define DOM_UUID "ef861801-45b9-11cb-88e3-afbfe5370493" +# define SECURITY_LABEL "libvirt-test (enforcing)" static const char *dominfo_fc4 = "\ Id: 2\n\ @@ -36,6 +37,7 @@ Autostart: disable\n\ Managed save: no\n\ Security model: testSecurity\n\ Security DOI: \n\ +Security label: " SECURITY_LABEL "\n\ \n"; static const char *domuuid_fc4 = DOM_UUID "\n\n"; static const char *domid_fc4 = "2\n\n"; -- 2.31.1
participants (2)
-
Luke Yue
-
Martin Kletzander