Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/external/bsd/cron Apply selected patches from OpenWall:



details:   https://anonhg.NetBSD.org/src/rev/c1e3448dd4f4
branches:  trunk
changeset: 824582:c1e3448dd4f4
user:      christos <christos%NetBSD.org@localhost>
date:      Fri Jun 09 17:36:29 2017 +0000

description:
Apply selected patches from OpenWall:
    http://cvsweb.openwall.com/cgi/cvsweb.cgi/Owl/packages/vixie-cron/

1. Add PAM support.
2. Sanitize children process reaping
3. futimens when we have an fd
4. close_all for crontab(8)
5. use a table for spool dirs instead of duplicating code.
6. handle errors from process_exit()
7. Add ENABLE_FIX_DIRECTORIES ifdef and enable it by default for compat
8. Avoid using fd's < STDERR

Not applied:
1. no xfork (no setresuid)
2. did not do the lstat before open.
3. did not enable cron group

diffstat:

 external/bsd/cron/bin/cron/Makefile    |    9 +-
 external/bsd/cron/bin/crontab/Makefile |    4 +-
 external/bsd/cron/dist/Makefile        |    4 +-
 external/bsd/cron/dist/closeall.c      |   34 ++++++++
 external/bsd/cron/dist/config.h        |    8 +-
 external/bsd/cron/dist/cron.c          |   17 ++--
 external/bsd/cron/dist/crontab.c       |   13 ++-
 external/bsd/cron/dist/database.c      |   82 +++++++++++--------
 external/bsd/cron/dist/do_command.c    |  131 ++++++++++++++++++++------------
 external/bsd/cron/dist/funcs.h         |   11 ++-
 external/bsd/cron/dist/misc.c          |   36 ++++++++-
 external/bsd/cron/dist/pam_auth.c      |  121 ++++++++++++++++++++++++++++++
 external/bsd/cron/dist/popen.c         |    9 +-
 13 files changed, 368 insertions(+), 111 deletions(-)

diffs (truncated from 951 to 300 lines):

diff -r cafbebafcc8f -r c1e3448dd4f4 external/bsd/cron/bin/cron/Makefile
--- a/external/bsd/cron/bin/cron/Makefile       Fri Jun 09 17:29:03 2017 +0000
+++ b/external/bsd/cron/bin/cron/Makefile       Fri Jun 09 17:36:29 2017 +0000
@@ -1,11 +1,12 @@
-#      $NetBSD: Makefile,v 1.3 2012/06/22 20:32:34 abs Exp $
+#      $NetBSD: Makefile,v 1.4 2017/06/09 17:36:29 christos Exp $
 
 BINDIR=        /usr/sbin
 PROG=  cron
 SRCS=  cron.c database.c do_command.c entry.c env.c job.c \
-       misc.c popen.c pw_dup.c user.c
-CPPFLAGS+=-I${.CURDIR} -DLOGIN_CAP
-LDADD+=-lutil
+       misc.c pam_auth.c popen.c pw_dup.c user.c
+CPPFLAGS+=-I${.CURDIR} -DLOGIN_CAP -DUSE_PAM
+DPADD+=${LIBPAM} ${LIBUTIL}
+LDADD+=-lpam -lutil
 MAN=   cron.8
 
 CWARNFLAGS.clang+=     -Wno-string-plus-int
diff -r cafbebafcc8f -r c1e3448dd4f4 external/bsd/cron/bin/crontab/Makefile
--- a/external/bsd/cron/bin/crontab/Makefile    Fri Jun 09 17:29:03 2017 +0000
+++ b/external/bsd/cron/bin/crontab/Makefile    Fri Jun 09 17:36:29 2017 +0000
@@ -1,10 +1,10 @@
-#      $NetBSD: Makefile,v 1.2 2010/05/07 21:54:07 christos Exp $
+#      $NetBSD: Makefile,v 1.3 2017/06/09 17:36:29 christos Exp $
 
 .include <bsd.own.mk>
 
 USE_FORT?= yes # setuid
 PROG=  crontab
-SRCS=  crontab.c misc.c entry.c env.c pw_dup.c
+SRCS=  crontab.c misc.c entry.c env.c pw_dup.c closeall.c
 CPPFLAGS+=-I${.CURDIR} -DDEBUGGING=1
 BINOWN =root
 BINMODE=4555
diff -r cafbebafcc8f -r c1e3448dd4f4 external/bsd/cron/dist/Makefile
--- a/external/bsd/cron/dist/Makefile   Fri Jun 09 17:29:03 2017 +0000
+++ b/external/bsd/cron/dist/Makefile   Fri Jun 09 17:36:29 2017 +0000
@@ -86,14 +86,14 @@
 HEADERS                =       bitstring.h cron.h config.h pathnames.h externs.h \
                        macros.h structs.h funcs.h globals.h
 SOURCES                =       cron.c crontab.c database.c do_command.c entry.c \
-                       env.c job.c user.c popen.c misc.c pw_dup.c
+                       env.c job.c user.c popen.c misc.c pam_auth.c pw_dup.c
 SHAR_SOURCE    =       $(INFOS) $(MANPAGES) Makefile $(HEADERS) $(SOURCES)
 LINT_CRON      =       cron.c database.c user.c entry.c \
                        misc.c job.c do_command.c env.c popen.c pw_dup.c
 LINT_CRONTAB   =       crontab.c misc.c entry.c env.c
 CRON_OBJ       =       cron.o database.o user.o entry.o job.o do_command.o \
                        misc.o env.o popen.o pw_dup.o
-CRONTAB_OBJ    =       crontab.o misc.o entry.o env.o pw_dup.o
+CRONTAB_OBJ    =       crontab.o misc.o entry.o env.o pw_dup.o closeall.o
 
 all            :       cron crontab
 
diff -r cafbebafcc8f -r c1e3448dd4f4 external/bsd/cron/dist/closeall.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/external/bsd/cron/dist/closeall.c Fri Jun 09 17:36:29 2017 +0000
@@ -0,0 +1,34 @@
+#include <unistd.h>
+#include <errno.h>
+#include <fcntl.h>
+
+#ifdef __linux__
+#include <linux/limits.h>
+#endif
+
+#include "cron.h"
+
+int close_all(int start)
+{
+#ifdef F_CLOSEM
+       return fcntl(start, F_CLOSEM);
+#else
+       int fd, max;
+
+       max = sysconf(_SC_OPEN_MAX);
+       if (max <= 0)
+               return -1;
+
+#ifdef __linux__
+       if (max < NR_OPEN)
+               max = NR_OPEN;
+#endif
+
+       for (fd = start; fd < max; fd++) {
+               if (close(fd) && errno != EBADF)
+                       return -1;
+       }
+
+       return 0;
+#endif
+}
diff -r cafbebafcc8f -r c1e3448dd4f4 external/bsd/cron/dist/config.h
--- a/external/bsd/cron/dist/config.h   Fri Jun 09 17:29:03 2017 +0000
+++ b/external/bsd/cron/dist/config.h   Fri Jun 09 17:36:29 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: config.h,v 1.4 2012/11/03 15:39:23 christos Exp $      */
+/*     $NetBSD: config.h,v 1.5 2017/06/09 17:36:30 christos Exp $      */
 
 /* Copyright 1988,1990,1993,1994 by Paul Vixie
  * All rights reserved
@@ -94,6 +94,7 @@
 #define HAVE_FCHOWN            /*-*/
 #define HAVE_UTIMES            /*-*/
 #define HAVE_UTIMENSAT
+#define HAVE_FUTIMENS
 #define _INCOMPLETE_XOPEN_C063
 
                        /* if your OS supports a BSD-style login.conf file */
@@ -108,6 +109,11 @@
                         * If this is not defined then crontab and at
                         * must be setuid root.
                         */
+                       /* if your os supports PAM authentication */
+/*#define USE_PAM                      */
+
 /*#define CRON_GROUP   "crontab"       */
 
+#define ENABLE_FIX_DIRECTORIES
+
 #define MAXTABSIZE_DEFAULT     (1024*256)
diff -r cafbebafcc8f -r c1e3448dd4f4 external/bsd/cron/dist/cron.c
--- a/external/bsd/cron/dist/cron.c     Fri Jun 09 17:29:03 2017 +0000
+++ b/external/bsd/cron/dist/cron.c     Fri Jun 09 17:36:29 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: cron.c,v 1.9 2014/09/07 13:34:12 joerg Exp $   */
+/*     $NetBSD: cron.c,v 1.10 2017/06/09 17:36:30 christos Exp $       */
 
 /* Copyright 1988,1990,1993,1994 by Paul Vixie
  * All rights reserved
@@ -25,7 +25,7 @@
 #if 0
 static char rcsid[] = "Id: cron.c,v 1.12 2004/01/23 18:56:42 vixie Exp";
 #else
-__RCSID("$NetBSD: cron.c,v 1.9 2014/09/07 13:34:12 joerg Exp $");
+__RCSID("$NetBSD: cron.c,v 1.10 2017/06/09 17:36:30 christos Exp $");
 #endif
 #endif
 
@@ -511,11 +511,10 @@
 
 static void
 sigchld_reaper(void) {
-       WAIT_T waiter;
-       PID_T pid;
+       for (;;) {
+               WAIT_T waiter;
+               PID_T pid = waitpid(-1, &waiter, WNOHANG);
 
-       do {
-               pid = waitpid(-1, &waiter, WNOHANG);
                switch (pid) {
                case -1:
                        if (errno == EINTR)
@@ -523,19 +522,19 @@
                        Debug(DPROC,
                              ("[%ld] sigchld...no children\n",
                               (long)getpid()));
-                       break;
+                       return;
                case 0:
                        Debug(DPROC,
                              ("[%ld] sigchld...no dead kids\n",
                               (long)getpid()));
-                       break;
+                       return;
                default:
                        Debug(DPROC,
                              ("[%ld] sigchld...pid #%ld died, stat=%d\n",
                               (long)getpid(), (long)pid, WEXITSTATUS(waiter)));
                        break;
                }
-       } while (pid > 0);
+       }
 }
 
 static void
diff -r cafbebafcc8f -r c1e3448dd4f4 external/bsd/cron/dist/crontab.c
--- a/external/bsd/cron/dist/crontab.c  Fri Jun 09 17:29:03 2017 +0000
+++ b/external/bsd/cron/dist/crontab.c  Fri Jun 09 17:36:29 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: crontab.c,v 1.13 2015/01/04 18:45:17 joerg Exp $       */
+/*     $NetBSD: crontab.c,v 1.14 2017/06/09 17:36:30 christos Exp $    */
 
 /* Copyright 1988,1990,1993,1994 by Paul Vixie
  * All rights reserved
@@ -25,7 +25,7 @@
 #if 0
 static char rcsid[] = "Id: crontab.c,v 1.12 2004/01/23 18:56:42 vixie Exp";
 #else
-__RCSID("$NetBSD: crontab.c,v 1.13 2015/01/04 18:45:17 joerg Exp $");
+__RCSID("$NetBSD: crontab.c,v 1.14 2017/06/09 17:36:30 christos Exp $");
 #endif
 #endif
 
@@ -429,7 +429,11 @@
        if (fflush(NewCrontab) < OK) {
                err(ERROR_EXIT, "cannot flush output for `%s'", Filename);
        }
+#ifdef HAVE_FUTIMENS
+       if (futimens(t, ts) == -1)
+#else
        if (change_time(Filename, ts) == -1)
+#endif
                err(ERROR_EXIT, "cannot set time info for `%s'", Filename);
  again:
        rewind(NewCrontab);
@@ -465,6 +469,9 @@
                if (setuid(MY_UID(pw)) < 0) {
                        err(ERROR_EXIT, "cannot setuid(getuid())");
                }
+               if (close_all(3)) {
+                       err(ERROR_EXIT, "cannot close files");
+               }
                if (chdir(_PATH_TMP) < 0) {
                        err(ERROR_EXIT, "cannot chdir to `%s'", _PATH_TMP);
                }
@@ -682,7 +689,7 @@
            "# (%s installed on %-24.24s)\n", Filename, ctime(&now));
        (void)fprintf(tmp,
            "# (Cron version %s -- %s)\n", CRON_VERSION,
-           "$NetBSD: crontab.c,v 1.13 2015/01/04 18:45:17 joerg Exp $");
+           "$NetBSD: crontab.c,v 1.14 2017/06/09 17:36:30 christos Exp $");
 
        /* copy the crontab to the tmp
         */
diff -r cafbebafcc8f -r c1e3448dd4f4 external/bsd/cron/dist/database.c
--- a/external/bsd/cron/dist/database.c Fri Jun 09 17:29:03 2017 +0000
+++ b/external/bsd/cron/dist/database.c Fri Jun 09 17:36:29 2017 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: database.c,v 1.8 2012/12/24 19:30:46 christos Exp $    */
+/*     $NetBSD: database.c,v 1.9 2017/06/09 17:36:30 christos Exp $    */
 
 /* Copyright 1988,1990,1993,1994 by Paul Vixie
  * All rights reserved
@@ -25,7 +25,7 @@
 #if 0
 static char rcsid[] = "Id: database.c,v 1.7 2004/01/23 18:56:42 vixie Exp";
 #else
-__RCSID("$NetBSD: database.c,v 1.8 2012/12/24 19:30:46 christos Exp $");
+__RCSID("$NetBSD: database.c,v 1.9 2017/06/09 17:36:30 christos Exp $");
 #endif
 #endif
 
@@ -36,16 +36,33 @@
 
 #define TMAX(a,b) ((a)>(b)?(a):(b))
 
+struct spooldir {
+       const char *path;
+       const char *uname;
+       const char *fname;
+       struct stat st;
+};
+
+static struct spooldir spools[] = {
+       { .path = SPOOL_DIR, },
+       { .path = CROND_DIR, .uname = "root", .fname = "*system*", },
+       { .path = NULL, }
+};
+
 static void            process_crontab(const char *, const char *,
                                        const char *, struct stat *,
                                        cron_db *, cron_db *);
 
 static void
-process_dir(const char *dname, struct stat *st, int sys, cron_db *new_db,
-    cron_db *old_db)
+process_dir(struct spooldir *sp, cron_db *new_db, cron_db *old_db)
 {
        DIR *dir;
        DIR_T *dp;
+       const char *dname = sp->path;
+       struct stat *st = &sp->st;
+
+       if (st->st_mtime == 0)
+               return;
 
        /* we used to keep this dir open all the time, for the sake of
         * efficiency.  however, we need to close it in every fork, and
@@ -109,40 +126,41 @@
                        continue;
                }
 
-               process_crontab(sys ? "root" : fname, sys ? "*system*" :
-                               fname, tabname, st, new_db, old_db);
+               process_crontab(sp->uname ? sp->uname : fname,
+                               sp->fname ? sp->fname : fname,
+                               tabname, st, new_db, old_db);
        }
        (void)closedir(dir);
 }
 
 void
 load_database(cron_db *old_db) {
-       struct stat spool_stat, syscron_stat, crond_stat;
+       struct stat syscron_stat;
        cron_db new_db;



Home | Main Index | Thread Index | Old Index