From 5290876dbc2d03efb233a5ecb1f9dd1a48c78a68 Mon Sep 17 00:00:00 2001 From: Martin Kletzander Date: Mon, 17 Aug 2015 10:43:43 -0700 Subject: [PATCH] security: Add virSecurityDomainSetDirLabel That function can be used for setting security labels on arbitrary directories. Signed-off-by: Martin Kletzander (cherry picked from commit f65a2a12f4b9ab6144a979774f0486cdc4f7a60a) --- src/libvirt_private.syms | 1 + src/security/security_driver.h | 5 +++++ src/security/security_manager.c | 17 +++++++++++++++++ src/security/security_manager.h | 4 ++++ 4 files changed, 27 insertions(+) diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms index c72c2f9d4c..bb34cbaa57 100644 --- a/src/libvirt_private.syms +++ b/src/libvirt_private.syms @@ -1021,6 +1021,7 @@ virSecurityDriverLookup; # security/security_manager.h virSecurityManagerCheckAllLabel; virSecurityManagerClearSocketLabel; +virSecurityManagerDomainSetDirLabel; virSecurityManagerGenLabel; virSecurityManagerGetBaseLabel; virSecurityManagerGetDOI; diff --git a/src/security/security_driver.h b/src/security/security_driver.h index f0dca09177..784b0dee65 100644 --- a/src/security/security_driver.h +++ b/src/security/security_driver.h @@ -118,6 +118,9 @@ typedef int (*virSecurityDomainSetImageLabel) (virSecurityManagerPtr mgr, typedef int (*virSecurityDomainRestoreImageLabel) (virSecurityManagerPtr mgr, virDomainDefPtr def, virStorageSourcePtr src); +typedef int (*virSecurityDomainSetDirLabel) (virSecurityManagerPtr mgr, + virDomainDefPtr def, + const char *path); struct _virSecurityDriver { @@ -168,6 +171,8 @@ struct _virSecurityDriver { virSecurityDomainSetHugepages domainSetSecurityHugepages; virSecurityDriverGetBaseLabel getBaseLabel; + + virSecurityDomainSetDirLabel domainSetDirLabel; }; virSecurityDriverPtr virSecurityDriverLookup(const char *name, diff --git a/src/security/security_manager.c b/src/security/security_manager.c index f533571e39..28d7dfd0c0 100644 --- a/src/security/security_manager.c +++ b/src/security/security_manager.c @@ -1006,3 +1006,20 @@ virSecurityManagerSetHugepages(virSecurityManagerPtr mgr, return 0; } + + +int +virSecurityManagerDomainSetDirLabel(virSecurityManagerPtr mgr, + virDomainDefPtr vm, + const char *path) +{ + if (mgr->drv->domainSetDirLabel) { + int ret; + virObjectLock(mgr); + ret = mgr->drv->domainSetDirLabel(mgr, vm, path); + virObjectUnlock(mgr); + return ret; + } + + return 0; +} diff --git a/src/security/security_manager.h b/src/security/security_manager.h index 2b4353e56d..53e56f684a 100644 --- a/src/security/security_manager.h +++ b/src/security/security_manager.h @@ -153,4 +153,8 @@ int virSecurityManagerRestoreImageLabel(virSecurityManagerPtr mgr, virDomainDefPtr vm, virStorageSourcePtr src); +int virSecurityManagerDomainSetDirLabel(virSecurityManagerPtr mgr, + virDomainDefPtr vm, + const char *path); + #endif /* VIR_SECURITY_MANAGER_H__ */