|
|
973edf |
diff -up at-3.1.13/atd.c.selinux at-3.1.13/atd.c
|
|
|
973edf |
--- at-3.1.13/atd.c.selinux 2012-11-01 15:11:21.368772308 +0100
|
|
|
973edf |
+++ at-3.1.13/atd.c 2012-11-01 15:13:16.809162818 +0100
|
|
|
973edf |
@@ -83,6 +83,14 @@
|
|
|
973edf |
#include "getloadavg.h"
|
|
|
973edf |
#endif
|
|
|
973edf |
|
|
|
973edf |
+#ifdef WITH_SELINUX
|
|
|
973edf |
+#include <selinux/selinux.h>
|
|
|
973edf |
+#include <selinux/get_context_list.h>
|
|
|
973edf |
+int selinux_enabled=0;
|
|
|
973edf |
+#include <selinux/flask.h>
|
|
|
973edf |
+#include <selinux/av_permissions.h>
|
|
|
973edf |
+#endif
|
|
|
973edf |
+
|
|
|
973edf |
#ifndef LOG_ATD
|
|
|
973edf |
#define LOG_ATD LOG_DAEMON
|
|
|
973edf |
#endif
|
|
|
973edf |
@@ -202,6 +210,68 @@ myfork()
|
|
|
973edf |
#define ATD_MAIL_NAME "mailx"
|
|
|
973edf |
#endif
|
|
|
973edf |
|
|
|
973edf |
+#ifdef WITH_SELINUX
|
|
|
973edf |
+static int set_selinux_context(const char *name, const char *filename) {
|
|
|
973edf |
+ security_context_t user_context=NULL;
|
|
|
973edf |
+ security_context_t file_context=NULL;
|
|
|
973edf |
+ struct av_decision avd;
|
|
|
973edf |
+ int retval=-1;
|
|
|
973edf |
+ char *seuser=NULL;
|
|
|
973edf |
+ char *level=NULL;
|
|
|
973edf |
+
|
|
|
973edf |
+ if (getseuserbyname(name, &seuser, &level) == 0) {
|
|
|
973edf |
+ retval=get_default_context_with_level(seuser, level, NULL, &user_context);
|
|
|
973edf |
+ free(seuser);
|
|
|
973edf |
+ free(level);
|
|
|
973edf |
+ if (retval) {
|
|
|
973edf |
+ if (security_getenforce()==1) {
|
|
|
973edf |
+ perr("execle: couldn't get security context for user %s\n", name);
|
|
|
973edf |
+ } else {
|
|
|
973edf |
+ syslog(LOG_ERR, "execle: couldn't get security context for user %s\n", name);
|
|
|
973edf |
+ return -1;
|
|
|
973edf |
+ }
|
|
|
973edf |
+ }
|
|
|
973edf |
+ }
|
|
|
973edf |
+
|
|
|
973edf |
+ /*
|
|
|
973edf |
+ * Since crontab files are not directly executed,
|
|
|
973edf |
+ * crond must ensure that the crontab file has
|
|
|
973edf |
+ * a context that is appropriate for the context of
|
|
|
973edf |
+ * the user cron job. It performs an entrypoint
|
|
|
973edf |
+ * permission check for this purpose.
|
|
|
973edf |
+ */
|
|
|
973edf |
+ if (fgetfilecon(STDIN_FILENO, &file_context) < 0)
|
|
|
973edf |
+ perr("fgetfilecon FAILED %s", filename);
|
|
|
973edf |
+
|
|
|
973edf |
+ retval = security_compute_av(user_context,
|
|
|
973edf |
+ file_context,
|
|
|
973edf |
+ SECCLASS_FILE,
|
|
|
973edf |
+ FILE__ENTRYPOINT,
|
|
|
973edf |
+ &avd);
|
|
|
973edf |
+ freecon(file_context);
|
|
|
973edf |
+ if (retval || ((FILE__ENTRYPOINT & avd.allowed) != FILE__ENTRYPOINT)) {
|
|
|
973edf |
+ if (security_getenforce()==1) {
|
|
|
973edf |
+ perr("Not allowed to set exec context to %s for user %s\n", user_context,name);
|
|
|
973edf |
+ } else {
|
|
|
973edf |
+ syslog(LOG_ERR, "Not allowed to set exec context to %s for user %s\n", user_context,name);
|
|
|
973edf |
+ retval = -1;
|
|
|
973edf |
+ goto err;
|
|
|
973edf |
+ }
|
|
|
973edf |
+ }
|
|
|
973edf |
+ if (setexeccon(user_context) < 0) {
|
|
|
973edf |
+ if (security_getenforce()==1) {
|
|
|
973edf |
+ perr("Could not set exec context to %s for user %s\n", user_context,name);
|
|
|
973edf |
+ retval = -1;
|
|
|
973edf |
+ } else {
|
|
|
973edf |
+ syslog(LOG_ERR, "Could not set exec context to %s for user %s\n", user_context,name);
|
|
|
973edf |
+ }
|
|
|
973edf |
+ }
|
|
|
973edf |
+ err:
|
|
|
973edf |
+ freecon(user_context);
|
|
|
973edf |
+ return 0;
|
|
|
973edf |
+}
|
|
|
973edf |
+#endif
|
|
|
973edf |
+
|
|
|
973edf |
static void
|
|
|
973edf |
run_file(const char *filename, uid_t uid, gid_t gid)
|
|
|
973edf |
{
|
|
|
973edf |
@@ -446,9 +516,23 @@ run_file(const char *filename, uid_t uid
|
|
|
973edf |
perr("Cannot reset signal handler to default");
|
|
|
973edf |
|
|
|
973edf |
chdir("/");
|
|
|
973edf |
-
|
|
|
973edf |
+#ifdef WITH_SELINUX
|
|
|
973edf |
+ if (selinux_enabled > 0) {
|
|
|
973edf |
+ if (set_selinux_context(pentry->pw_name, filename) < 0)
|
|
|
973edf |
+ perr("SELinux Failed to set context\n");
|
|
|
973edf |
+ }
|
|
|
973edf |
+#endif
|
|
|
973edf |
if (execle("/bin/sh", "sh", (char *) NULL, nenvp) != 0)
|
|
|
973edf |
perr("Exec failed for /bin/sh");
|
|
|
973edf |
+//add for fedora
|
|
|
973edf |
+#ifdef WITH_SELINUX
|
|
|
973edf |
+ if (selinux_enabled>0)
|
|
|
973edf |
+ if (setexeccon(NULL) < 0)
|
|
|
973edf |
+ if (security_getenforce()==1)
|
|
|
973edf |
+ perr("Could not resset exec context for user %s\n", pentry->pw_name);
|
|
|
973edf |
+#endif
|
|
|
973edf |
+//end
|
|
|
973edf |
+//add for fedora
|
|
|
973edf |
#ifdef WITH_PAM
|
|
|
973edf |
if ( ( nenvp != &nul ) && (pam_envp != 0L) && (*pam_envp != 0L))
|
|
|
973edf |
{
|
|
|
973edf |
@@ -751,6 +835,10 @@ main(int argc, char *argv[])
|
|
|
973edf |
struct passwd *pwe;
|
|
|
973edf |
struct group *ge;
|
|
|
973edf |
|
|
|
973edf |
+#ifdef WITH_SELINUX
|
|
|
973edf |
+ selinux_enabled=is_selinux_enabled();
|
|
|
973edf |
+#endif
|
|
|
973edf |
+
|
|
|
973edf |
/* We don't need root privileges all the time; running under uid and gid
|
|
|
973edf |
* daemon is fine.
|
|
|
973edf |
*/
|
|
|
973edf |
diff -up at-3.1.13/config.h.in.selinux at-3.1.13/config.h.in
|
|
|
973edf |
--- at-3.1.13/config.h.in.selinux 2012-11-01 15:11:21.368772308 +0100
|
|
|
973edf |
+++ at-3.1.13/config.h.in 2012-11-01 15:11:21.371772392 +0100
|
|
|
973edf |
@@ -71,6 +71,9 @@
|
|
|
973edf |
/* Define if you are building with_pam */
|
|
|
973edf |
#undef WITH_PAM
|
|
|
973edf |
|
|
|
973edf |
+/* Define if you are building with_selinux */
|
|
|
973edf |
+#undef WITH_SELINUX
|
|
|
973edf |
+
|
|
|
973edf |
/* Define to 1 if you have the `pstat_getdynamic' function. */
|
|
|
973edf |
#undef HAVE_PSTAT_GETDYNAMIC
|
|
|
973edf |
|
|
|
973edf |
diff -up at-3.1.13/configure.ac.selinux at-3.1.13/configure.ac
|
|
|
973edf |
--- at-3.1.13/configure.ac.selinux 2012-11-01 15:11:21.369772335 +0100
|
|
|
973edf |
+++ at-3.1.13/configure.ac 2012-11-01 15:11:21.372772420 +0100
|
|
|
973edf |
@@ -266,5 +266,13 @@ AC_ARG_WITH(daemon_groupname,
|
|
|
973edf |
)
|
|
|
973edf |
AC_SUBST(DAEMON_GROUPNAME)
|
|
|
973edf |
|
|
|
973edf |
+AC_ARG_WITH(selinux,
|
|
|
973edf |
+[ --with-selinux Define to run with selinux],
|
|
|
973edf |
+AC_DEFINE(WITH_SELINUX),
|
|
|
973edf |
+)
|
|
|
973edf |
+AC_CHECK_LIB(selinux, is_selinux_enabled, SELINUXLIB=-lselinux)
|
|
|
973edf |
+AC_SUBST(SELINUXLIB)
|
|
|
973edf |
+AC_SUBST(WITH_SELINUX)
|
|
|
973edf |
+
|
|
|
973edf |
AC_CONFIG_FILES(Makefile atrun atd.8 atrun.8 at.1 at.allow.5 batch)
|
|
|
973edf |
AC_OUTPUT
|
|
|
973edf |
diff -up at-3.1.13/Makefile.in.selinux at-3.1.13/Makefile.in
|
|
|
973edf |
--- at-3.1.13/Makefile.in.selinux 2012-11-01 15:11:21.361772115 +0100
|
|
|
973edf |
+++ at-3.1.13/Makefile.in 2012-11-01 15:11:21.372772420 +0100
|
|
|
973edf |
@@ -39,6 +39,8 @@ LIBS = @LIBS@
|
|
|
973edf |
LIBOBJS = @LIBOBJS@
|
|
|
973edf |
INSTALL = @INSTALL@
|
|
|
973edf |
PAMLIB = @PAMLIB@
|
|
|
973edf |
+SELINUXLIB = @SELINUXLIB@
|
|
|
973edf |
+
|
|
|
973edf |
|
|
|
973edf |
CLONES = atq atrm
|
|
|
973edf |
ATOBJECTS = at.o panic.o perm.o posixtm.o y.tab.o lex.yy.o
|