*/
#include <config.h>
#include <selinux/selinux.h>
+#include <selinux/label.h>
#include <selinux/context.h>
#include <sys/types.h>
#include <sys/stat.h>
{
struct stat buf;
security_context_t fcon = NULL;
+ struct selabel_handle *handle = NULL;
int rc = -1;
char *newpath = NULL;
char ebuf[1024];
goto err;
}
- if (matchpathcon(newpath, buf.st_mode, &fcon) == 0) {
- rc = SELinuxSetFilecon(newpath, fcon);
+ if ((handle = selabel_open(SELABEL_CTX_FILE, NULL, 0)) == NULL ||
+ selabel_lookup(handle, &fcon, newpath, buf.st_mode) < 0) {
+ VIR_WARN("cannot lookup default selinux label for %s", newpath);
} else {
- VIR_WARN("cannot lookup default selinux label for %s",
- newpath);
+ rc = SELinuxSetFilecon(newpath, fcon);
}
err:
+ if (handle)
+ selabel_close(handle);
freecon(fcon);
VIR_FREE(newpath);
return rc;