#include <errno.h>
#include <selinux/selinux.h>
+#include "udev.h"
#include "udev_selinux.h"
-#include "logging.h"
static security_context_t prev_scontext = NULL;
int size;
char *media = NULL;
- if (!(mode && S_IFBLK))
+ if (!(mode & S_IFBLK))
return NULL;
snprintf(procfile, PATH_MAX, "/proc/ide/%s/media", devname);
if (ret < 0)
if (matchpathcon(file, mode, &scontext) < 0) {
- dbg("matchpathcon(%s) failed\n", file);
+ err("matchpathcon(%s) failed\n", file);
return;
}
if (setfilecon(file, scontext) < 0)
- dbg("setfiles %s failed with error '%s'", file, strerror(errno));
+ err("setfilecon %s failed: %s", file, strerror(errno));
freecon(scontext);
}
if (ret < 0)
if (matchpathcon(file, mode, &scontext) < 0) {
- dbg("matchpathcon(%s) failed\n", file);
+ err("matchpathcon(%s) failed\n", file);
return;
}
if (setfscreatecon(scontext) < 0)
- dbg("setfiles %s failed with error '%s'", file, strerror(errno));
+ err("setfscreatecon %s failed: %s", file, strerror(errno));
freecon(scontext);
}
}
+void selinux_resetfscreatecon(void)
+{
+ if (is_selinux_running()) {
+ if (setfscreatecon(prev_scontext) < 0)
+ err("setfscreatecon failed: %s", strerror(errno));
+ }
+}
+
void selinux_init(void)
{
/*
* restoration creation purposes.
*/
if (is_selinux_running()) {
- if (getfscreatecon(&prev_scontext) < 0)
- dbg("getfscreatecon failed\n");
-
- prev_scontext = NULL;
+ matchpathcon_init_prefix(NULL, udev_root);
+ if (getfscreatecon(&prev_scontext) < 0) {
+ err("getfscreatecon failed\n");
+ prev_scontext = NULL;
+ }
}
}
-void selinux_restore(void)
+void selinux_exit(void)
{
- if (is_selinux_running()) {
- /* reset the file create context to its former glory */
- if (setfscreatecon(prev_scontext) < 0)
- dbg("setfscreatecon failed\n");
-
- if (prev_scontext) {
- freecon(prev_scontext);
- prev_scontext = NULL;
- }
+ if (is_selinux_running() && prev_scontext) {
+ freecon(prev_scontext);
+ prev_scontext = NULL;
}
}