X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ianmdlvl/git?a=blobdiff_plain;f=udev%2Flib%2Flibudev.c;h=3f7d0e547e61a774f5ff4c07d00dd2d97ac235cd;hb=9925ab0451b307b5766b12134bdc178e4c89f297;hp=04ad26c6fbc5ec076eb77ea16ee35bc7758d9823;hpb=3eb46ec6ddeb31d9886ebb736d1d7b3534d2f354;p=elogind.git
diff --git a/udev/lib/libudev.c b/udev/lib/libudev.c
index 04ad26c6f..3f7d0e547 100644
--- a/udev/lib/libudev.c
+++ b/udev/lib/libudev.c
@@ -17,8 +17,6 @@
* along with this program. If not, see .
*/
-#include "config.h"
-
#include
#include
#include
@@ -27,9 +25,6 @@
#include
#include
#include
-#ifdef USE_SELINUX
-#include
-#endif
#include "libudev.h"
#include "libudev-private.h"
@@ -39,14 +34,11 @@ struct udev {
void (*log_fn)(struct udev *udev,
int priority, const char *file, int line, const char *fn,
const char *format, va_list args);
+ void *userdata;
char *sys_path;
char *dev_path;
char *rules_path;
int log_priority;
-#ifdef USE_SELINUX
- int selinux_enabled;
- security_context_t selinux_prev_scontext;
-#endif
int run;
};
@@ -72,77 +64,18 @@ static void log_stderr(struct udev *udev,
vfprintf(stderr, format, args);
}
-static void selinux_init(struct udev *udev)
-{
-#ifdef USE_SELINUX
- /*
- * record the present security context, for file-creation
- * restoration creation purposes.
- */
- udev->selinux_enabled = (is_selinux_enabled() > 0);
- info(udev, "selinux=%i\n", udev->selinux_enabled);
- if (udev->selinux_enabled) {
- matchpathcon_init_prefix(NULL, udev_get_dev_path(udev));
- if (getfscreatecon(&udev->selinux_prev_scontext) < 0) {
- err(udev, "getfscreatecon failed\n");
- udev->selinux_prev_scontext = NULL;
- }
- }
-#endif
-}
-
-static void selinux_exit(struct udev *udev)
-{
-#ifdef USE_SELINUX
- if (udev->selinux_enabled) {
- freecon(udev->selinux_prev_scontext);
- udev->selinux_prev_scontext = NULL;
- }
-#endif
-}
-
-void udev_selinux_lsetfilecon(struct udev *udev, const char *file, unsigned int mode)
-{
-#ifdef USE_SELINUX
- if (udev->selinux_enabled) {
- security_context_t scontext = NULL;
-
- if (matchpathcon(file, mode, &scontext) < 0) {
- err(udev, "matchpathcon(%s) failed\n", file);
- return;
- }
- if (lsetfilecon(file, scontext) < 0)
- err(udev, "setfilecon %s failed: %s\n", file, strerror(errno));
- freecon(scontext);
- }
-#endif
-}
-
-void udev_selinux_setfscreatecon(struct udev *udev, const char *file, unsigned int mode)
+void *udev_get_userdata(struct udev *udev)
{
-#ifdef USE_SELINUX
- if (udev->selinux_enabled) {
- security_context_t scontext = NULL;
-
- if (matchpathcon(file, mode, &scontext) < 0) {
- err(udev, "matchpathcon(%s) failed\n", file);
- return;
- }
- if (setfscreatecon(scontext) < 0)
- err(udev, "setfscreatecon %s failed: %s\n", file, strerror(errno));
- freecon(scontext);
- }
-#endif
+ if (udev == NULL)
+ return NULL;
+ return udev->userdata;
}
-void udev_selinux_resetfscreatecon(struct udev *udev)
+void udev_set_userdata(struct udev *udev, void *userdata)
{
-#ifdef USE_SELINUX
- if (udev->selinux_enabled) {
- if (setfscreatecon(udev->selinux_prev_scontext) < 0)
- err(udev, "setfscreatecon failed: %s\n", strerror(errno));
- }
-#endif
+ if (udev == NULL)
+ return;
+ udev->userdata = userdata;
}
/**
@@ -294,7 +227,6 @@ struct udev *udev_new(void)
if (udev->dev_path == NULL || udev->sys_path == NULL)
goto err;
- selinux_init(udev);
info(udev, "context %p created\n", udev);
info(udev, "log_priority=%d\n", udev->log_priority);
info(udev, "config_file='%s'\n", config_file);
@@ -342,7 +274,6 @@ void udev_unref(struct udev *udev)
udev->refcount--;
if (udev->refcount > 0)
return;
- selinux_exit(udev);
free(udev->dev_path);
free(udev->sys_path);
free(udev->rules_path);
@@ -355,8 +286,7 @@ void udev_unref(struct udev *udev)
* @udev: udev library context
* @log_fn: function to be called for logging messages
*
- * The built-in logging, which writes to stderr if the
- * LIBUDEV_DEBUG environment variable is set, can be
+ * The built-in logging, which writes to stderr, it can be
* overridden by a custom function, to plug log messages
* into the users logging functionality.
*