Blame SOURCES/at-3.1.13-selinux.patch

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