mirror of
https://github.com/libvirt/libvirt.git
synced 2025-02-25 18:55:26 -06:00
Improve security label error reporting & verification (Dan Walsh)
This commit is contained in:
@@ -15,6 +15,7 @@ nodedevxml2xmltest
|
||||
nodeinfotest
|
||||
statstest
|
||||
qparamtest
|
||||
seclabeltest
|
||||
*.gcda
|
||||
*.gcno
|
||||
*.exe
|
||||
|
||||
1
tests/.gitignore
vendored
1
tests/.gitignore
vendored
@@ -15,6 +15,7 @@ nodedevxml2xmltest
|
||||
nodeinfotest
|
||||
statstest
|
||||
qparamtest
|
||||
seclabeltest
|
||||
*.gcda
|
||||
*.gcno
|
||||
*.exe
|
||||
|
||||
@@ -64,6 +64,10 @@ if WITH_QEMU
|
||||
noinst_PROGRAMS += qemuxml2argvtest qemuxml2xmltest
|
||||
endif
|
||||
|
||||
if WITH_SECDRIVER_SELINUX
|
||||
noinst_PROGRAMS += seclabeltest
|
||||
endif
|
||||
|
||||
noinst_PROGRAMS += nodedevxml2xmltest
|
||||
|
||||
test_scripts = \
|
||||
@@ -114,6 +118,10 @@ if WITH_QEMU
|
||||
TESTS += qemuxml2argvtest qemuxml2xmltest
|
||||
endif
|
||||
|
||||
if WITH_SECDRIVER_SELINUX
|
||||
TESTS += seclabeltest
|
||||
endif
|
||||
|
||||
TESTS += nodedevxml2xmltest
|
||||
|
||||
path_add = $$abs_top_builddir/src$(PATH_SEPARATOR)$$abs_top_builddir/qemud
|
||||
@@ -203,6 +211,14 @@ statstest_SOURCES = \
|
||||
statstest.c testutils.h testutils.c
|
||||
statstest_LDADD = $(LDADDS)
|
||||
|
||||
if WITH_SECDRIVER_SELINUX
|
||||
seclabeltest_SOURCES = \
|
||||
seclabeltest.c
|
||||
seclabeltest_LDADD = ../src/libvirt_driver_security.la $(LDADDS)
|
||||
else
|
||||
EXTRA_DIST += seclabeltest.c
|
||||
endif
|
||||
|
||||
qparamtest_SOURCES = \
|
||||
qparamtest.c testutils.h testutils.c
|
||||
qparamtest_LDADD = $(LDADDS)
|
||||
|
||||
45
tests/seclabeltest.c
Normal file
45
tests/seclabeltest.c
Normal file
@@ -0,0 +1,45 @@
|
||||
#include <config.h>
|
||||
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include "security.h"
|
||||
|
||||
int
|
||||
main (int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED)
|
||||
{
|
||||
int ret;
|
||||
|
||||
const char *doi, *model;
|
||||
virSecurityDriverPtr security_drv;
|
||||
|
||||
ret = virSecurityDriverStartup (&security_drv, "selinux");
|
||||
if (ret == -1)
|
||||
{
|
||||
fprintf (stderr, "Failed to start security driver");
|
||||
exit (-1);
|
||||
}
|
||||
/* No security driver wanted to be enabled: just return */
|
||||
if (ret == -2)
|
||||
return 0;
|
||||
|
||||
model = virSecurityDriverGetModel (security_drv);
|
||||
if (!model)
|
||||
{
|
||||
fprintf (stderr, "Failed to copy secModel model: %s",
|
||||
strerror (errno));
|
||||
exit (-1);
|
||||
}
|
||||
|
||||
doi = virSecurityDriverGetDOI (security_drv);
|
||||
if (!doi)
|
||||
{
|
||||
fprintf (stderr, "Failed to copy secModel DOI: %s",
|
||||
strerror (errno));
|
||||
exit (-1);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user