Skip to contentSkip to conversation

The third patch for systemd.

PATCH Daniel J Walsh 1 participant 1 message Jul 26, 2010 SELinux security module

lore
Share & tools
lore
#0 lore raw

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

This patch makes SELinux optional and moves all of the functions to util.c.

Covers them under a wraper of label_*.

Also switches out matchpathcon for selabel calls. -----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.14 (GNU/Linux)
Comment: Using GnuPG with Fedora - http://enigmail.mozdev.org/

iEYEARECAAYFAkxN8bQACgkQrlYvE4MpobNcPgCcCCyDg6UcBQQLnJRO0E/RJs6m LS4AnA/48iOpNqhk53OItY8RxWlXYbzZ
=H8yt
-----END PGP SIGNATURE-----

configure.ac +16 -5
index 14622e4..e17f129 100644
@@ -105,15 +105,26 @@ PKG_CHECK_MODULES(DBUS, [ dbus-1 >= 1.3.2 ])
 AC_SUBST(DBUS_CFLAGS)
 AC_SUBST(DBUS_LIBS)
 
-PKG_CHECK_MODULES(SELINUX, [ libselinux ])
-AC_SUBST(SELINUX_CFLAGS)
-AC_SUBST(SELINUX_LIBS)
-AC_SEARCH_LIBS([is_selinux_enabled], [selinux], [], [AC_MSG_ERROR([*** libselinux library not found])])
-
 PKG_CHECK_MODULES(DBUSGLIB, [ dbus-glib-1 ])
 AC_SUBST(DBUSGLIB_CFLAGS)
 AC_SUBST(DBUSGLIB_LIBS)
 
+have_selinux=no
+AC_ARG_ENABLE(selinux, AS_HELP_STRING([--disable-selinux], [disable SELINUX support]))
+if test "x$enable_selinux" != "xno"; then
+	# not using PKG_CHECK_MODULES as for some reason libselinux didn't
+	# install any pkg-config modules here
+	AC_SEARCH_LIBS([getcon], [selinux],
+                [AC_DEFINE(HAVE_SELINUX, 1, [Define if SELINUX is available]) have_selinux=yes],
+		have_selinux=no)
+        AC_SUBST(SELINUX_CFLAGS)
+        AC_SUBST(SELINUX_LIBS)
+        if test "x$have_selinux" = xno -a "x$enable_selinux" = xyes; then
+             AC_MSG_ERROR([*** selinux support requested but libraries not found])
+        fi
+fi
+AM_CONDITIONAL(HAVE_SELINUX, [test "$have_selinux" = "yes"])
+
 AC_ARG_ENABLE([tcpwrap],
         AS_HELP_STRING([--disable-tcpwrap],[Disable optional TCP wrappers support]),
                 [case "${enableval}" in
src/main.c +5 -0
index e67d222..99b8811 100644
@@ -836,6 +836,9 @@ int main(int argc, char *argv[]) {
                 return 1;
         }
 
+	if (label_init() < 0)
+		return 1;
+
         log_show_color(isatty(STDERR_FILENO) > 0);
         log_show_location(false);
         log_set_max_level(LOG_INFO);
@@ -1113,5 +1116,7 @@ finish:
         if (getpid() == 1)
                 freeze();
 
+	label_finish();
+
         return retval;
 }
src/socket-util.c +6 -8
index 3a00fcf..d1f3e7b 100644
@@ -29,7 +29,6 @@
 #include <net/if.h>
 #include <sys/types.h>
 #include <sys/stat.h>
-#include <selinux/selinux.h>
 
 #include "macro.h"
 #include "util.h"
@@ -306,7 +305,7 @@ int socket_address_listen(
                 bool free_bind,
                 mode_t directory_mode,
                 mode_t socket_mode,
-                security_context_t scon,
+                const char *label,
                 int *ret) {
 
         int r, fd, one;
@@ -316,16 +315,15 @@ int socket_address_listen(
         if ((r = socket_address_verify(a)) < 0)
                 return r;
 
-        if (setsockcreatecon(scon) < 0) {
-                log_error("Failed to set SELinux context (%s) on socket: %m", scon);
-                if (security_getenforce() == 1)
-                        return -errno;
-        }
+	r = label_socket_set(label);
+	if (r < 0)
+		return r;
 
         fd = socket(socket_address_family(a), a->type | SOCK_NONBLOCK | SOCK_CLOEXEC, 0);
         r = fd < 0 ? -errno : 0;
 
-        setsockcreatecon(NULL);
+	
+	label_socket_clear();
 
         if (r < 0)
                 return r;
src/socket-util.h +1 -2
index 841570f..86c9e47 100644
@@ -26,7 +26,6 @@
 #include <netinet/in.h>
 #include <sys/un.h>
 #include <net/if.h>
-#include <selinux/selinux.h>
 
 #include "macro.h"
 #include "util.h"
@@ -72,7 +71,7 @@ int socket_address_listen(
                 bool free_bind,
                 mode_t directory_mode,
                 mode_t socket_mode,
-                security_context_t scon,
+                const char *label,
                 int *ret);
 
 bool socket_address_is(const SocketAddress *a, const char *s, int type);
src/socket.c +12 -81

168 lines not on this page · raw message

src/util.c +217 -3

250 lines not on this page · raw message

src/util.h +9 -0
index 782adb8..dbfbc28 100644
@@ -360,4 +360,13 @@ int ip_tos_from_string(const char *s);
 const char *signal_to_string(int i);
 int signal_from_string(const char *s);
 
+int label_init(void);
+void label_finish(void);
+int label_socket_set(const char *label);
+void label_socket_clear(void);
+int label_fifofile_set(const char *label, const char *path);
+void label_file_clear(void);
+void label_free(const char *label);
+int label_get_socket_label_from_exe(const char *exe, char **label);
+
 #endif