|
Daniel P. Berrange |
afdaf5 |
diff -rup libvirt-0.6.2/src/security_selinux.c libvirt-0.6.2.new/src/security_selinux.c
|
|
Daniel P. Berrange |
afdaf5 |
--- libvirt-0.6.2/src/security_selinux.c 2009-04-03 15:36:56.000000000 +0100
|
|
Daniel P. Berrange |
afdaf5 |
+++ libvirt-0.6.2.new/src/security_selinux.c 2009-05-05 13:39:42.000000000 +0100
|
|
Daniel P. Berrange |
afdaf5 |
@@ -24,11 +24,12 @@
|
|
Daniel P. Berrange |
afdaf5 |
#include "virterror_internal.h"
|
|
Daniel P. Berrange |
afdaf5 |
#include "util.h"
|
|
Daniel P. Berrange |
afdaf5 |
#include "memory.h"
|
|
Daniel P. Berrange |
afdaf5 |
-
|
|
Daniel P. Berrange |
afdaf5 |
+#include "logging.h"
|
|
Daniel P. Berrange |
afdaf5 |
|
|
Daniel P. Berrange |
afdaf5 |
#define VIR_FROM_THIS VIR_FROM_SECURITY
|
|
Daniel P. Berrange |
afdaf5 |
|
|
Daniel P. Berrange |
afdaf5 |
static char default_domain_context[1024];
|
|
Daniel P. Berrange |
afdaf5 |
+static char default_content_context[1024];
|
|
Daniel P. Berrange |
afdaf5 |
static char default_image_context[1024];
|
|
Daniel P. Berrange |
afdaf5 |
#define SECURITY_SELINUX_VOID_DOI "0"
|
|
Daniel P. Berrange |
afdaf5 |
#define SECURITY_SELINUX_NAME "selinux"
|
|
Daniel P. Berrange |
afdaf5 |
@@ -148,8 +149,13 @@ SELinuxInitialize(virConnectPtr conn)
|
|
Daniel P. Berrange |
afdaf5 |
close(fd);
|
|
Daniel P. Berrange |
afdaf5 |
|
|
Daniel P. Berrange |
afdaf5 |
ptr = strchrnul(default_image_context, '\n');
|
|
Daniel P. Berrange |
afdaf5 |
- *ptr = '\0';
|
|
Daniel P. Berrange |
afdaf5 |
-
|
|
Daniel P. Berrange |
afdaf5 |
+ if (*ptr == '\n') {
|
|
Daniel P. Berrange |
afdaf5 |
+ *ptr = '\0';
|
|
Daniel P. Berrange |
afdaf5 |
+ strcpy(default_content_context, ptr+1);
|
|
Daniel P. Berrange |
afdaf5 |
+ ptr = strchrnul(default_content_context, '\n');
|
|
Daniel P. Berrange |
afdaf5 |
+ if (*ptr == '\n')
|
|
Daniel P. Berrange |
afdaf5 |
+ *ptr = '\0';
|
|
Daniel P. Berrange |
afdaf5 |
+ }
|
|
Daniel P. Berrange |
afdaf5 |
return 0;
|
|
Daniel P. Berrange |
afdaf5 |
}
|
|
Daniel P. Berrange |
afdaf5 |
|
|
Daniel P. Berrange |
afdaf5 |
@@ -275,6 +281,8 @@ SELinuxSetFilecon(virConnectPtr conn, co
|
|
Daniel P. Berrange |
afdaf5 |
{
|
|
Daniel P. Berrange |
afdaf5 |
char ebuf[1024];
|
|
Daniel P. Berrange |
afdaf5 |
|
|
Daniel P. Berrange |
afdaf5 |
+ VIR_INFO("Setting SELinux context on '%s' to '%s'", path, tcon);
|
|
Daniel P. Berrange |
afdaf5 |
+
|
|
Daniel P. Berrange |
afdaf5 |
if(setfilecon(path, tcon) < 0) {
|
|
Daniel P. Berrange |
afdaf5 |
virSecurityReportError(conn, VIR_ERR_ERROR,
|
|
Daniel P. Berrange |
afdaf5 |
_("%s: unable to set security context "
|
|
Daniel P. Berrange |
afdaf5 |
@@ -299,6 +307,8 @@ SELinuxRestoreSecurityImageLabel(virConn
|
|
Daniel P. Berrange |
afdaf5 |
char *newpath = NULL;
|
|
Daniel P. Berrange |
afdaf5 |
const char *path = disk->src;
|
|
Daniel P. Berrange |
afdaf5 |
|
|
Daniel P. Berrange |
afdaf5 |
+ /* Don't restore labels on readoly/shared disks, because
|
|
Daniel P. Berrange |
afdaf5 |
+ * other VMs may still be accessing these */
|
|
Daniel P. Berrange |
afdaf5 |
if (disk->readonly || disk->shared)
|
|
Daniel P. Berrange |
afdaf5 |
return 0;
|
|
Daniel P. Berrange |
afdaf5 |
|
|
Daniel P. Berrange |
afdaf5 |
@@ -328,8 +338,13 @@ SELinuxSetSecurityImageLabel(virConnectP
|
|
Daniel P. Berrange |
afdaf5 |
{
|
|
Daniel P. Berrange |
afdaf5 |
const virSecurityLabelDefPtr secdef = &vm->def->seclabel;
|
|
Daniel P. Berrange |
afdaf5 |
|
|
Daniel P. Berrange |
afdaf5 |
- if (secdef->imagelabel)
|
|
Daniel P. Berrange |
afdaf5 |
+ if (disk->shared) {
|
|
Daniel P. Berrange |
afdaf5 |
+ return SELinuxSetFilecon(conn, disk->src, default_image_context);
|
|
Daniel P. Berrange |
afdaf5 |
+ } else if (disk->readonly) {
|
|
Daniel P. Berrange |
afdaf5 |
+ return SELinuxSetFilecon(conn, disk->src, default_content_context);
|
|
Daniel P. Berrange |
afdaf5 |
+ } else if (secdef->imagelabel) {
|
|
Daniel P. Berrange |
afdaf5 |
return SELinuxSetFilecon(conn, disk->src, secdef->imagelabel);
|
|
Daniel P. Berrange |
afdaf5 |
+ }
|
|
Daniel P. Berrange |
afdaf5 |
|
|
Daniel P. Berrange |
afdaf5 |
return 0;
|
|
Daniel P. Berrange |
afdaf5 |
}
|
|
Daniel P. Berrange |
afdaf5 |
@@ -403,9 +418,6 @@ SELinuxSetSecurityLabel(virConnectPtr co
|
|
Daniel P. Berrange |
afdaf5 |
|
|
Daniel P. Berrange |
afdaf5 |
if (secdef->imagelabel) {
|
|
Daniel P. Berrange |
afdaf5 |
for (i = 0 ; i < vm->def->ndisks ; i++) {
|
|
Daniel P. Berrange |
afdaf5 |
- if (vm->def->disks[i]->readonly ||
|
|
Daniel P. Berrange |
afdaf5 |
- vm->def->disks[i]->shared) continue;
|
|
Daniel P. Berrange |
afdaf5 |
-
|
|
Daniel P. Berrange |
afdaf5 |
if (SELinuxSetSecurityImageLabel(conn, vm, vm->def->disks[i]) < 0)
|
|
Daniel P. Berrange |
afdaf5 |
return -1;
|
|
Daniel P. Berrange |
afdaf5 |
}
|