From f454727bb848d341b0fb3faabd35a8a75e65773a Mon Sep 17 00:00:00 2001 From: "Todd C. Miller" Date: Mon, 16 Aug 2010 14:05:44 -0400 Subject: [PATCH] Merge compat.h and missing.h into missing.h --- MANIFEST | 1 - common/Makefile.in | 16 +- common/aix.c | 2 +- common/alloc.c | 1 - common/atobool.c | 1 - common/fileops.c | 1 - common/fmt_string.c | 2 +- common/lbuf.c | 3 +- common/list.c | 2 +- common/term.c | 2 +- common/zero_bytes.c | 2 +- compat/Makefile.in | 39 +++-- compat/closefrom.c | 2 +- compat/fnmatch.c | 2 +- compat/getcwd.c | 2 +- compat/getgrouplist.c | 2 +- compat/getline.c | 2 +- compat/getprogname.c | 2 +- compat/glob.c | 2 +- compat/isblank.c | 2 +- compat/memrchr.c | 2 +- compat/mksiglist.c | 4 +- compat/mkstemps.c | 2 +- compat/nanosleep.c | 2 +- compat/setenv.c | 2 +- compat/snprintf.c | 2 +- compat/strlcat.c | 3 +- compat/strlcpy.c | 2 +- compat/strsignal.c | 2 +- compat/unsetenv.c | 2 +- compat/utimes.c | 2 +- include/compat.h | 70 +++++++- include/missing.h | 247 +++++++++++++++++++++++++++- plugins/sample/sample_plugin.c | 1 - plugins/sample_group/getgrent.c | 1 - plugins/sample_group/sample_group.c | 1 - plugins/sudoers/Makefile.in | 18 +- plugins/sudoers/audit.c | 2 +- plugins/sudoers/boottime.c | 1 - plugins/sudoers/getdate.c | 2 +- plugins/sudoers/getdate.y | 2 +- plugins/sudoers/linux_audit.c | 3 +- plugins/sudoers/plugin_error.c | 2 +- plugins/sudoers/sudoers.h | 3 +- plugins/sudoers/sudoreplay.c | 3 +- plugins/sudoers/timestr.c | 2 +- src/Makefile.in | 13 +- src/error.c | 2 +- src/sesh.c | 2 +- src/sudo.h | 3 +- src/sudo_noexec.c | 2 +- src/ttysize.c | 2 +- 52 files changed, 392 insertions(+), 103 deletions(-) diff --git a/MANIFEST b/MANIFEST index b2f0d42e2..7c43181c7 100644 --- a/MANIFEST +++ b/MANIFEST @@ -84,7 +84,6 @@ doc/visudo.man.in doc/visudo.pod include/Makefile.in include/alloc.h -include/compat.h include/error.h include/fileops.h include/lbuf.h diff --git a/common/Makefile.in b/common/Makefile.in index 815eb5a47..392dc0502 100644 --- a/common/Makefile.in +++ b/common/Makefile.in @@ -59,15 +59,15 @@ libcommon.la: $(LTOBJS) $(LIBTOOL) --mode=link $(CC) -o $@ $(LTOBJS) -no-install # Dependencies -aix.lo: $(srcdir)/aix.c $(incdir)/compat.h $(incdir)/alloc.h $(incdir)/error.h $(top_builddir)/config.h -alloc.lo: $(srcdir)/alloc.c $(incdir)/compat.h $(incdir)/alloc.h $(incdir)/error.h $(top_builddir)/config.h -atobool.lo: $(srcdir)/atobool.c $(incdir)/compat.h $(incdir)/missing.h $(top_builddir)/config.h +aix.lo: $(srcdir)/aix.c $(incdir)/missing.h $(incdir)/alloc.h $(incdir)/error.h $(top_builddir)/config.h +alloc.lo: $(srcdir)/alloc.c $(incdir)/missing.h $(incdir)/alloc.h $(incdir)/error.h $(top_builddir)/config.h +atobool.lo: $(srcdir)/atobool.c $(incdir)/missing.h $(incdir)/missing.h $(top_builddir)/config.h fileops.lo: $(srcdir)/fileops.c $(incdir)/fileops.h $(top_builddir)/config.h -fmt_string.lo: $(srcdir)/fmt_string.c $(incdir)/compat.h $(top_builddir)/config.h -lbuf.lo: $(srcdir)/lbuf.c $(incdir)/compat.h $(incdir)/alloc.h $(incdir)/error.h $(incdir)/missing.h $(incdir)/lbuf.h $(top_builddir)/config.h -list.lo: $(srcdir)/list.c $(incdir)/compat.h $(incdir)/list.h $(incdir)/error.h $(top_builddir)/config.h -term.lo: $(srcdir)/term.c $(incdir)/compat.h $(top_builddir)/config.h -zero_bytes.lo: $(srcdir)/zero_bytes.c $(incdir)/compat.h $(top_builddir)/config.h +fmt_string.lo: $(srcdir)/fmt_string.c $(incdir)/missing.h $(top_builddir)/config.h +lbuf.lo: $(srcdir)/lbuf.c $(incdir)/missing.h $(incdir)/alloc.h $(incdir)/error.h $(incdir)/missing.h $(incdir)/lbuf.h $(top_builddir)/config.h +list.lo: $(srcdir)/list.c $(incdir)/missing.h $(incdir)/list.h $(incdir)/error.h $(top_builddir)/config.h +term.lo: $(srcdir)/term.c $(incdir)/missing.h $(top_builddir)/config.h +zero_bytes.lo: $(srcdir)/zero_bytes.c $(incdir)/missing.h $(top_builddir)/config.h install: diff --git a/common/aix.c b/common/aix.c index 90f907e13..b02296ec5 100644 --- a/common/aix.c +++ b/common/aix.c @@ -31,7 +31,7 @@ #include #include -#include "compat.h" +#include "missing.h" #include "alloc.h" #include "error.h" diff --git a/common/alloc.c b/common/alloc.c index 016ad9297..ef11c1794 100644 --- a/common/alloc.c +++ b/common/alloc.c @@ -45,7 +45,6 @@ # include #endif -#include #include #include #include diff --git a/common/atobool.c b/common/atobool.c index 77211e685..b056489af 100644 --- a/common/atobool.c +++ b/common/atobool.c @@ -38,7 +38,6 @@ # include #endif /* HAVE_STRINGS_H */ -#include #include int diff --git a/common/fileops.c b/common/fileops.c index 8659a096d..fe319ebea 100644 --- a/common/fileops.c +++ b/common/fileops.c @@ -47,7 +47,6 @@ # include #endif -#include #include #include diff --git a/common/fmt_string.c b/common/fmt_string.c index ae476320d..5ece309f1 100644 --- a/common/fmt_string.c +++ b/common/fmt_string.c @@ -38,7 +38,7 @@ # include #endif /* HAVE_STRINGS_H */ -#include +#include /* * Allocate storage for a name=value string and return it. diff --git a/common/lbuf.c b/common/lbuf.c index c20e3603d..ce5213068 100644 --- a/common/lbuf.c +++ b/common/lbuf.c @@ -42,10 +42,9 @@ #include #include -#include +#include #include #include -#include #include void diff --git a/common/list.c b/common/list.c index 3a8341af4..88f8bdd91 100644 --- a/common/list.c +++ b/common/list.c @@ -29,7 +29,7 @@ # endif #endif /* STDC_HEADERS */ -#include +#include #include #ifdef DEBUG # include diff --git a/common/term.c b/common/term.c index bbde495e1..26069d2c1 100644 --- a/common/term.c +++ b/common/term.c @@ -38,7 +38,7 @@ #endif /* HAVE_STRINGS_H */ #include -#include +#include #ifndef TCSASOFT # define TCSASOFT 0 diff --git a/common/zero_bytes.c b/common/zero_bytes.c index 03d2b8c5c..21041673f 100644 --- a/common/zero_bytes.c +++ b/common/zero_bytes.c @@ -18,7 +18,7 @@ #include #include -#include +#include /* * Like bzero(3) but with a volatile pointer. The hope is that diff --git a/compat/Makefile.in b/compat/Makefile.in index 5d0cd00f6..1b04b0652 100644 --- a/compat/Makefile.in +++ b/compat/Makefile.in @@ -66,33 +66,32 @@ libreplace.la: $(LTLIBOBJS) siglist.c: mksiglist ./mksiglist > $@ -mksiglist: $(srcdir)/mksiglist.c $(srcdir)/mksiglist.h $(incdir)/compat.h $(top_builddir)/config.h +mksiglist: $(srcdir)/mksiglist.c $(srcdir)/mksiglist.h $(incdir)/missing.h $(top_builddir)/config.h $(CC) $(CPPFLAGS) $(CFLAGS) $(DEFS) $(srcdir)/mksiglist.c -o $@ @DEV@$(srcdir)/mksiglist.h: $(srcdir)/siglist.in @DEV@ awk 'BEGIN {print "/* public domain */\n"} /^ [A-Z]/ {printf("#ifdef SIG%s\n if (my_sys_siglist[SIG%s] == NULL)\n\tmy_sys_siglist[SIG%s] = \"%s\";\n#endif\n", $$1, $$1, $$1, substr($$0, 13))}' < $(srcdir)/siglist.in > $@ -siglist.lo: siglist.c $(incdir)/compat.h $(top_builddir)/config.h +siglist.lo: siglist.c $(incdir)/missing.h $(top_builddir)/config.h # Dependencies -closefrom.lo: $(compat)/closefrom.c $(incdir)/compat.h $(top_builddir)/config.h -fnmatch.lo: $(compat)/fnmatch.c $(compat)/fnmatch.h $(compat)/charclass.h $(incdir)/compat.h $(top_builddir)/config.h -getcwd.lo: $(compat)/getcwd.c $(incdir)/compat.h $(top_builddir)/config.h -getline.lo: $(compat)/getline.c $(incdir)/compat.h $(top_builddir)/config.h -getprogname.lo: $(compat)/getprogname.c $(incdir)/compat.h $(top_builddir)/config.h -glob.lo: $(compat)/glob.c $(compat)/glob.h $(compat)/charclass.h $(incdir)/compat.h $(top_builddir)/config.h -isblank.lo: $(compat)/isblank.c $(incdir)/compat.h $(top_builddir)/config.h -memrchr.lo: $(compat)/memrchr.c $(incdir)/compat.h $(top_builddir)/config.h -mkstemps.lo: $(compat)/mkstemps.c $(incdir)/compat.h $(top_builddir)/config.h -nanosleep.lo: $(compat)/nanosleep.c $(incdir)/compat.h $(top_builddir)/config.h -sigaction.lo: $(compat)/sigaction.c $(incdir)/compat.h $(incdir)/compat.h -snprintf.lo: $(compat)/snprintf.c $(incdir)/compat.h $(top_builddir)/config.h -strcasecmp.lo: $(compat)/strcasecmp.c $(incdir)/compat.h $(top_builddir)/config.h -strerror.lo: $(compat)/strerror.c $(incdir)/compat.h $(top_builddir)/config.h -strlcat.lo: $(compat)/strlcat.c $(incdir)/compat.h $(top_builddir)/config.h -strlcpy.lo: $(compat)/strlcpy.c $(incdir)/compat.h $(top_builddir)/config.h -strsignal.lo: $(compat)/strsignal.c $(incdir)/compat.h $(top_builddir)/config.h -utimes.lo: $(compat)/utimes.c $(incdir)/compat.h $(compat)/utime.h $(top_builddir)/config.h +closefrom.lo: $(compat)/closefrom.c $(incdir)/missing.h $(top_builddir)/config.h +fnmatch.lo: $(compat)/fnmatch.c $(compat)/fnmatch.h $(compat)/charclass.h $(incdir)/missing.h $(top_builddir)/config.h +getcwd.lo: $(compat)/getcwd.c $(incdir)/missing.h $(top_builddir)/config.h +getline.lo: $(compat)/getline.c $(incdir)/missing.h $(top_builddir)/config.h +getprogname.lo: $(compat)/getprogname.c $(incdir)/missing.h $(top_builddir)/config.h +glob.lo: $(compat)/glob.c $(compat)/glob.h $(compat)/charclass.h $(incdir)/missing.h $(top_builddir)/config.h +isblank.lo: $(compat)/isblank.c $(incdir)/missing.h $(top_builddir)/config.h +memrchr.lo: $(compat)/memrchr.c $(incdir)/missing.h $(top_builddir)/config.h +mkstemps.lo: $(compat)/mkstemps.c $(incdir)/missing.h $(top_builddir)/config.h +nanosleep.lo: $(compat)/nanosleep.c $(incdir)/missing.h $(top_builddir)/config.h +snprintf.lo: $(compat)/snprintf.c $(incdir)/missing.h $(top_builddir)/config.h +strcasecmp.lo: $(compat)/strcasecmp.c $(incdir)/missing.h $(top_builddir)/config.h +strerror.lo: $(compat)/strerror.c $(incdir)/missing.h $(top_builddir)/config.h +strlcat.lo: $(compat)/strlcat.c $(incdir)/missing.h $(top_builddir)/config.h +strlcpy.lo: $(compat)/strlcpy.c $(incdir)/missing.h $(top_builddir)/config.h +strsignal.lo: $(compat)/strsignal.c $(incdir)/missing.h $(top_builddir)/config.h +utimes.lo: $(compat)/utimes.c $(incdir)/missing.h $(compat)/utime.h $(top_builddir)/config.h install: diff --git a/compat/closefrom.c b/compat/closefrom.c index 1f00e1231..a91e4578b 100644 --- a/compat/closefrom.c +++ b/compat/closefrom.c @@ -47,7 +47,7 @@ # endif #endif -#include +#include #ifndef HAVE_FCNTL_CLOSEM # ifndef HAVE_DIRFD diff --git a/compat/fnmatch.c b/compat/fnmatch.c index 512272381..23e61c988 100644 --- a/compat/fnmatch.c +++ b/compat/fnmatch.c @@ -47,7 +47,7 @@ # include #endif /* HAVE_STRINGS_H */ -#include +#include #include "fnmatch.h" #include "charclass.h" diff --git a/compat/getcwd.c b/compat/getcwd.c index 83a3e8fd8..d70c6af2b 100644 --- a/compat/getcwd.c +++ b/compat/getcwd.c @@ -71,7 +71,7 @@ # endif #endif -#include +#include #define ISDOT(dp) \ (dp->d_name[0] == '.' && (dp->d_name[1] == '\0' || \ diff --git a/compat/getgrouplist.c b/compat/getgrouplist.c index 5996471aa..165878913 100644 --- a/compat/getgrouplist.c +++ b/compat/getgrouplist.c @@ -34,7 +34,7 @@ #endif /* HAVE_STRINGS_H */ #include -#include +#include /* * BSD-compatible getgrouplist(3) using getgrent(3) diff --git a/compat/getline.c b/compat/getline.c index 2933e846c..93f4952e7 100644 --- a/compat/getline.c +++ b/compat/getline.c @@ -35,7 +35,7 @@ #endif /* HAVE_STRINGS_H */ #include -#include +#include #ifndef LINE_MAX # define LINE_MAX 2048 diff --git a/compat/getprogname.c b/compat/getprogname.c index 8b7602a2e..2de1333d4 100644 --- a/compat/getprogname.c +++ b/compat/getprogname.c @@ -18,7 +18,7 @@ #include #include -#include +#include static const char *progname = "sudo"; diff --git a/compat/glob.c b/compat/glob.c index 267effb04..b09cfe5f5 100644 --- a/compat/glob.c +++ b/compat/glob.c @@ -95,7 +95,7 @@ #include #include -#include +#include #include "glob.h" #include "charclass.h" diff --git a/compat/isblank.c b/compat/isblank.c index 42ab126c4..64448b0e1 100644 --- a/compat/isblank.c +++ b/compat/isblank.c @@ -15,7 +15,7 @@ */ #include -#include +#include #undef isblank int diff --git a/compat/memrchr.c b/compat/memrchr.c index d2dd1e684..9b5cc9c8e 100644 --- a/compat/memrchr.c +++ b/compat/memrchr.c @@ -16,7 +16,7 @@ #include #include -#include +#include /* * Reverse memchr() diff --git a/compat/mksiglist.c b/compat/mksiglist.c index d9ba37073..003e53166 100644 --- a/compat/mksiglist.c +++ b/compat/mksiglist.c @@ -28,7 +28,7 @@ #endif /* STDC_HEADERS */ #include -#include +#include int main(int argc, char *argv[]) @@ -40,7 +40,7 @@ main(int argc, char *argv[]) printf("#include \n"); printf("#include \n"); - printf("#include \n\n"); + printf("#include \n\n"); printf("const char *const my_sys_siglist[NSIG] = {\n"); for (i = 0; i < NSIG; i++) { if (my_sys_siglist[i] != NULL) { diff --git a/compat/mkstemps.c b/compat/mkstemps.c index d707f40e2..3026ce0b6 100644 --- a/compat/mkstemps.c +++ b/compat/mkstemps.c @@ -36,7 +36,7 @@ # include #endif -#include +#include static unsigned int get_random(void); static void seed_random(void); diff --git a/compat/nanosleep.c b/compat/nanosleep.c index bc0ecb70b..63620cd27 100644 --- a/compat/nanosleep.c +++ b/compat/nanosleep.c @@ -29,7 +29,7 @@ #endif #include -#include +#include int nanosleep(const struct timespec *ts, struct timespec *rts) diff --git a/compat/setenv.c b/compat/setenv.c index a5c06e0fd..ae9576c76 100644 --- a/compat/setenv.c +++ b/compat/setenv.c @@ -38,7 +38,7 @@ #endif /* HAVE_MALLOC_H && !STDC_HEADERS */ #include -#include +#include int setenv(const char *var, const char *val, int overwrite) diff --git a/compat/snprintf.c b/compat/snprintf.c index f5f5949d9..7de9145bd 100644 --- a/compat/snprintf.c +++ b/compat/snprintf.c @@ -71,7 +71,7 @@ #include #include -#include +#include static int xxxprintf(char **, size_t, int, const char *, va_list); diff --git a/compat/strlcat.c b/compat/strlcat.c index 092e5cc65..a24ef49e6 100644 --- a/compat/strlcat.c +++ b/compat/strlcat.c @@ -21,8 +21,7 @@ #include #include -#include - +#include /* * Appends src to string dst of size siz (unlike strncat, siz is the diff --git a/compat/strlcpy.c b/compat/strlcpy.c index 0d5d78994..9432e9304 100644 --- a/compat/strlcpy.c +++ b/compat/strlcpy.c @@ -20,7 +20,7 @@ #include #include -#include +#include /* * Copy src to string dst of size siz. At most siz-1 characters diff --git a/compat/strsignal.c b/compat/strsignal.c index a2c7a8875..76e3f9d1c 100644 --- a/compat/strsignal.c +++ b/compat/strsignal.c @@ -18,7 +18,7 @@ #include #include -#include +#include #if defined(HAVE_DECL_SYS_SIGLIST) && HAVE_DECL_SYS_SIGLIST == 1 # define my_sys_siglist sys_siglist diff --git a/compat/unsetenv.c b/compat/unsetenv.c index df4082922..6304d38fd 100644 --- a/compat/unsetenv.c +++ b/compat/unsetenv.c @@ -35,7 +35,7 @@ #endif /* HAVE_STRINGS_H */ #include -#include +#include extern char **environ; /* global environment */ diff --git a/compat/utimes.c b/compat/utimes.c index b727764e5..f4aa2d4e5 100644 --- a/compat/utimes.c +++ b/compat/utimes.c @@ -30,7 +30,7 @@ # include "utime.h" #endif -#include +#include #ifndef HAVE_UTIMES /* diff --git a/include/compat.h b/include/compat.h index 333a88069..2ca605c5e 100644 --- a/include/compat.h +++ b/include/compat.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 1996, 1998-2005, 2008, 2010 + * Copyright (c) 1996, 1998-2005, 2008, 2009-2010 * Todd C. Miller * * Permission to use, copy, modify, and distribute this software for any @@ -19,11 +19,11 @@ * Materiel Command, USAF, under agreement number F39502-99-1-0512. */ -#ifndef _SUDO_COMPAT_H -#define _SUDO_COMPAT_H +#ifndef _SUDO_MISSING_H +#define _SUDO_MISSING_H /* - * Macros that may be missing on some Operating Systems + * Macros and functions that may be missing on some operating systems. */ /* Define away __attribute__ for non-gcc or old gcc */ @@ -261,4 +261,64 @@ void setprogname(const char *); # endif #endif /* HAVE_SETEUID */ -#endif /* _SUDO_COMPAT_H */ +#include +#include + +/* Functions "missing" from libc. */ + +struct timeval; +struct timespec; + +#ifndef HAVE_CLOSEFROM +void closefrom(int); +#endif +#ifndef HAVE_GETCWD +char *getcwd(char *, size_t size); +#endif +#ifndef HAVE_GETLINE +ssize_t getline(char **, size_t *, FILE *); +#endif +#ifndef HAVE_UTIMES +int utimes(const char *, const struct timeval *); +#endif +#ifdef HAVE_FUTIME +int futimes(int, const struct timeval *); +#endif +#ifndef HAVE_SNPRINTF +int snprintf(char *, size_t, const char *, ...) __printflike(3, 4); +#endif +#ifndef HAVE_VSNPRINTF +int vsnprintf(char *, size_t, const char *, va_list) __printflike(3, 0); +#endif +#ifndef HAVE_ASPRINTF +int asprintf(char **, const char *, ...) __printflike(2, 3); +#endif +#ifndef HAVE_VASPRINTF +int vasprintf(char **, const char *, va_list) __printflike(2, 0); +#endif +#ifndef HAVE_STRLCAT +size_t strlcat(char *, const char *, size_t); +#endif +#ifndef HAVE_STRLCPY +size_t strlcpy(char *, const char *, size_t); +#endif +#ifndef HAVE_MEMRCHR +void *memrchr(const void *, int, size_t); +#endif +#ifndef HAVE_MKSTEMPS +int mkstemps(char *, int); +#endif +#ifndef HAVE_NANOSLEEP +int nanosleep(const struct timespec *, struct timespec *); +#endif +#ifndef HAVE_SETENV +int setenv(const char *, const char *, int); +#endif +#ifndef HAVE_UNSETENV +int unsetenv(const char *); +#endif +#ifndef HAVE_STRSIGNAL +char *strsignal(int); +#endif + +#endif /* _SUDO_MISSING_H */ diff --git a/include/missing.h b/include/missing.h index 844023b4a..2ca605c5e 100644 --- a/include/missing.h +++ b/include/missing.h @@ -1,5 +1,6 @@ /* - * Copyright (c) 2009-2010 Todd C. Miller + * Copyright (c) 1996, 1998-2005, 2008, 2009-2010 + * Todd C. Miller * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -12,11 +13,255 @@ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + * + * Sponsored in part by the Defense Advanced Research Projects + * Agency (DARPA) and Air Force Research Laboratory, Air Force + * Materiel Command, USAF, under agreement number F39502-99-1-0512. */ #ifndef _SUDO_MISSING_H #define _SUDO_MISSING_H +/* + * Macros and functions that may be missing on some operating systems. + */ + +/* Define away __attribute__ for non-gcc or old gcc */ +#if !defined(__GNUC__) || __GNUC__ < 2 || __GNUC__ == 2 && __GNUC_MINOR__ < 5 +# define __attribute__(x) +#endif + +/* For silencing gcc warnings about rcsids */ +#ifndef __unused +# if defined(__GNUC__) && (__GNUC__ > 2 || __GNUC__ == 2 && __GNUC_MINOR__ > 7) +# define __unused __attribute__((__unused__)) +# else +# define __unused +# endif +#endif + +/* For catching format string mismatches */ +#ifndef __printflike +# if defined(__GNUC__) && (__GNUC__ > 2 || __GNUC__ == 2 && __GNUC_MINOR__ >= 7) +# define __printflike(f, v) __attribute__((__format__ (__printf__, f, v))) +# else +# define __printflike(f, v) +# endif +#endif + +/* + * Some systems lack full limit definitions. + */ +#ifndef OPEN_MAX +# define OPEN_MAX 256 +#endif + +#ifndef INT_MAX +# define INT_MAX 0x7fffffff +#endif + +#ifndef PATH_MAX +# ifdef MAXPATHLEN +# define PATH_MAX MAXPATHLEN +# else +# ifdef _POSIX_PATH_MAX +# define PATH_MAX _POSIX_PATH_MAX +# else +# define PATH_MAX 1024 +# endif +# endif +#endif + +#ifndef MAXHOSTNAMELEN +# define MAXHOSTNAMELEN 64 +#endif + +/* + * Posix versions for those without... + */ +#ifndef _S_IFMT +# define _S_IFMT S_IFMT +#endif /* _S_IFMT */ +#ifndef _S_IFREG +# define _S_IFREG S_IFREG +#endif /* _S_IFREG */ +#ifndef _S_IFDIR +# define _S_IFDIR S_IFDIR +#endif /* _S_IFDIR */ +#ifndef _S_IFLNK +# define _S_IFLNK S_IFLNK +#endif /* _S_IFLNK */ +#ifndef S_ISREG +# define S_ISREG(m) (((m) & _S_IFMT) == _S_IFREG) +#endif /* S_ISREG */ +#ifndef S_ISDIR +# define S_ISDIR(m) (((m) & _S_IFMT) == _S_IFDIR) +#endif /* S_ISDIR */ + +/* + * Some OS's may not have this. + */ +#ifndef S_IRWXU +# define S_IRWXU 0000700 /* rwx for owner */ +#endif /* S_IRWXU */ + +/* + * These should be defined in but not everyone has them. + */ +#ifndef STDIN_FILENO +# define STDIN_FILENO 0 +#endif +#ifndef STDOUT_FILENO +# define STDOUT_FILENO 1 +#endif +#ifndef STDERR_FILENO +# define STDERR_FILENO 2 +#endif + +/* + * BSD defines these in but others may not. + */ +#ifndef MIN +# define MIN(a,b) (((a)<(b))?(a):(b)) +#endif +#ifndef MAX +# define MAX(a,b) (((a)>(b))?(a):(b)) +#endif + +/* + * Simple isblank() macro and function for systems without it. + */ +#ifndef HAVE_ISBLANK +int isblank(int); +# define isblank(_x) ((_x) == ' ' || (_x) == '\t') +#endif + +/* + * NCR's SVr4 has _innetgr(3) instead of innetgr(3) for some reason. + */ +#ifdef HAVE__INNETGR +# define innetgr(n, h, u, d) (_innetgr(n, h, u, d)) +# define HAVE_INNETGR 1 +#endif /* HAVE__INNETGR */ + +/* + * On POSIX systems, O_NOCTTY is the default so some OS's may lack this define. + */ +#ifndef O_NOCTTY +# define O_NOCTTY 0 +#endif /* O_NOCTTY */ + +/* + * Add IRIX-like sigaction_t for those without it. + * SA_RESTART is not required by POSIX; SunOS has SA_INTERRUPT instead. + */ +#ifndef HAVE_SIGACTION_T +typedef struct sigaction sigaction_t; +#endif +#ifndef SA_INTERRUPT +# define SA_INTERRUPT 0 +#endif +#ifndef SA_RESTART +# define SA_RESTART 0 +#endif + +/* + * If dirfd() does not exists, hopefully dd_fd does. + */ +#if !defined(HAVE_DIRFD) && defined(HAVE_DD_FD) +# define dirfd(_d) ((_d)->dd_fd) +# define HAVE_DIRFD +#endif + +/* + * Define futimes() in terms of futimesat() if needed. + */ +#if !defined(HAVE_FUTIMES) && defined(HAVE_FUTIMESAT) +# define futimes(_f, _tv) futimesat(_f, NULL, _tv) +# define HAVE_FUTIMES +#endif + +#if !defined(HAVE_KILLPG) && !defined(killpg) +# define killpg(s) kill(-(s)) +#endif + +/* + * If we lack getprogname(), emulate with __progname if possible. + * Otherwise, add a prototype for use with our own getprogname.c. + */ +#ifndef HAVE_GETPROGNAME +# ifdef HAVE___PROGNAME +extern const char *__progname; +# define getprogname() (__progname) +# else +const char *getprogname(void); +void setprogname(const char *); +#endif /* HAVE___PROGNAME */ +#endif /* !HAVE_GETPROGNAME */ + +#ifndef timevalclear +# define timevalclear(tv) ((tv)->tv_sec = (tv)->tv_usec = 0) +#endif +#ifndef timevalisset +# define timevalisset(tv) ((tv)->tv_sec || (tv)->tv_usec) +#endif +#ifndef timevalcmp +# define timevalcmp(tv1, tv2, op) \ + (((tv1)->tv_sec == (tv2)->tv_sec) ? \ + ((tv1)->tv_usec op (tv2)->tv_usec) : \ + ((tv1)->tv_sec op (tv2)->tv_sec)) +#endif +#ifndef timevaladd +# define timevaladd(tv1, tv2) \ + do { \ + (tv1)->tv_sec += (tv2)->tv_sec; \ + (tv1)->tv_usec += (tv2)->tv_usec; \ + if ((tv1)->tv_usec >= 1000000) { \ + (tv1)->tv_sec++; \ + (tv1)->tv_usec -= 1000000; \ + } \ + } while (0) +#endif +#ifndef timevalsub +# define timevalsub(tv1, tv2) \ + do { \ + (tv1)->tv_sec -= (tv2)->tv_sec; \ + (tv1)->tv_usec -= (tv2)->tv_usec; \ + if ((tv1)->tv_usec < 0) { \ + (tv1)->tv_sec--; \ + (tv1)->tv_usec += 1000000; \ + } \ + } while (0) +#endif + +/* Not all systems define NSIG in signal.h */ +#if !defined(NSIG) +# if defined(_NSIG) +# define NSIG _NSIG +# elif defined(__NSIG) +# define NSIG __NSIG +# else +# define NSIG 64 +# endif +#endif + +#ifndef WCOREDUMP +# define WCOREDUMP(x) ((x) & 0x80) +#endif + +#ifndef HAVE_SETEUID +# if defined(HAVE_SETRESUID) +# define seteuid(u) setresuid(-1, (u), -1) +# define setegid(g) setresgid(-1, (g), -1) +# define HAVE_SETEUID 1 +# elif defined(HAVE_SETREUID) +# define seteuid(u) setreuid(-1, (u)) +# define setegid(g) setregid(-1, (g)) +# define HAVE_SETEUID 1 +# endif +#endif /* HAVE_SETEUID */ + +#include #include /* Functions "missing" from libc. */ diff --git a/plugins/sample/sample_plugin.c b/plugins/sample/sample_plugin.c index a8bb09be0..a8a08c037 100644 --- a/plugins/sample/sample_plugin.c +++ b/plugins/sample/sample_plugin.c @@ -50,7 +50,6 @@ #include #include -#include #include #include diff --git a/plugins/sample_group/getgrent.c b/plugins/sample_group/getgrent.c index f2a65f4cd..4c4225bb8 100644 --- a/plugins/sample_group/getgrent.c +++ b/plugins/sample_group/getgrent.c @@ -45,7 +45,6 @@ #include #include -#include #include #ifndef LINE_MAX diff --git a/plugins/sample_group/sample_group.c b/plugins/sample_group/sample_group.c index f8b36f952..d44179559 100644 --- a/plugins/sample_group/sample_group.c +++ b/plugins/sample_group/sample_group.c @@ -49,7 +49,6 @@ #include #include -#include #include /* diff --git a/plugins/sudoers/Makefile.in b/plugins/sudoers/Makefile.in index 6110a8ecd..ff9242943 100644 --- a/plugins/sudoers/Makefile.in +++ b/plugins/sudoers/Makefile.in @@ -118,10 +118,10 @@ TEST_OBJS = interfaces.o testsudoers.o tsgetgrpw.o error.o group_plugin.o VERSION = @PACKAGE_VERSION@ PACKAGE_TARNAME = @PACKAGE_TARNAME@ -SUDODEP = $(srcdir)/sudoers.h $(incdir)/compat.h \ - $(srcdir)/defaults.h $(incdir)/error.h $(incdir)/list.h \ - $(srcdir)/logging.h $(incdir)/missing.h $(srcdir)/sudo_nss.h \ - $(devdir)/def_data.h $(top_builddir)/pathnames.h $(top_builddir)/config.h +SUDODEP = $(srcdir)/sudoers.h $(srcdir)/defaults.h $(incdir)/error.h \ + $(incdir)/list.h $(srcdir)/logging.h $(incdir)/missing.h \ + $(srcdir)/sudo_nss.h $(devdir)/def_data.h \ + $(top_builddir)/pathnames.h $(top_builddir)/config.h AUTHDEP = $(SUDODEP) $(authdir)/sudo_auth.h @@ -211,11 +211,11 @@ redblack.lo: $(srcdir)/redblack.c $(SUDODEP) $(srcdir)/redblack.h set_perms.lo: $(srcdir)/set_perms.c $(SUDODEP) sudo_nss.lo: $(srcdir)/sudo_nss.c $(SUDODEP) sudoers.lo: $(srcdir)/sudoers.c $(SUDODEP) $(srcdir)/interfaces.h -timestr.lo: $(srcdir)/timestr.c $(incdir)/compat.h $(top_builddir)/config.h +timestr.lo: $(srcdir)/timestr.c $(incdir)/missing.h $(top_builddir)/config.h toke.lo: $(devdir)/toke.c $(SUDODEP) $(srcdir)/parse.h $(incdir)/list.h $(devdir)/gram.h $(LIBTOOL) --mode=compile $(CC) -c $(CPPFLAGS) $(CFLAGS) $(DEFS) $(devdir)/toke.c tsgetgrpw.lo: $(srcdir)/tsgetgrpw.c $(SUDODEP) -plugin_error.lo: $(srcdir)/plugin_error.c $(incdir)/error.h $(incdir)/compat.h $(top_builddir)/config.h +plugin_error.lo: $(srcdir)/plugin_error.c $(incdir)/error.h $(incdir)/missing.h $(top_builddir)/config.h # Auth dependencies sudo_auth.lo: $(authdir)/sudo_auth.c $(AUTHDEP) $(INSDEP) @@ -235,14 +235,14 @@ securid5.lo: $(authdir)/securid5.c $(AUTHDEP) sia.lo: $(authdir)/sia.c $(AUTHDEP) # Command dependencies (sudoreplay, testsudoers, visudo) -error.o: $(top_srcdir)/src/error.c $(incdir)/error.h $(incdir)/compat.h $(top_builddir)/config.h +error.o: $(top_srcdir)/src/error.c $(incdir)/error.h $(incdir)/missing.h $(top_builddir)/config.h $(CC) -c $(CPPFLAGS) $(CFLAGS) $(DEFS) $(top_srcdir)/src/error.c find_path.o: find_path.lo -getdate.o: $(devdir)/getdate.c $(incdir)/compat.h $(top_builddir)/config.h +getdate.o: $(devdir)/getdate.c $(incdir)/missing.h $(top_builddir)/config.h $(CC) -c $(CPPFLAGS) $(CFLAGS) $(DEFS) $(devdir)/getdate.c goodpath.o: goodpath.lo interfaces.o: interfaces.lo -sudoreplay.o: $(srcdir)/sudoreplay.c $(incdir)/alloc.h $(incdir)/compat.h $(incdir)/error.h $(incdir)/missing.h $(top_builddir)/config.h +sudoreplay.o: $(srcdir)/sudoreplay.c $(incdir)/alloc.h $(incdir)/missing.h $(incdir)/error.h $(incdir)/missing.h $(top_builddir)/config.h testsudoers.o: $(srcdir)/testsudoers.c $(SUDODEP) $(srcdir)/parse.h $(incdir)/list.h $(srcdir)/interfaces.h $(devdir)/gram.h tsgetgrpw.o: $(srcdir)/tsgetgrpw.c $(SUDODEP) visudo.o: $(srcdir)/visudo.c $(SUDODEP) $(devdir)/gram.h diff --git a/plugins/sudoers/audit.c b/plugins/sudoers/audit.c index b05a02ac0..edb1dae0a 100644 --- a/plugins/sudoers/audit.c +++ b/plugins/sudoers/audit.c @@ -28,7 +28,7 @@ #endif /* STDC_HEADERS */ #include -#include +#include #include "logging.h" #ifdef HAVE_BSM_AUDIT diff --git a/plugins/sudoers/boottime.c b/plugins/sudoers/boottime.c index 237bd8ea5..c4787b2b9 100644 --- a/plugins/sudoers/boottime.c +++ b/plugins/sudoers/boottime.c @@ -47,7 +47,6 @@ # include #endif -#include #include /* diff --git a/plugins/sudoers/getdate.c b/plugins/sudoers/getdate.c index 172add56c..c9dee68b0 100644 --- a/plugins/sudoers/getdate.c +++ b/plugins/sudoers/getdate.c @@ -50,7 +50,7 @@ #endif #include -#include +#include #define EPOCH 1970 diff --git a/plugins/sudoers/getdate.y b/plugins/sudoers/getdate.y index a40d78418..23ab34c0b 100644 --- a/plugins/sudoers/getdate.y +++ b/plugins/sudoers/getdate.y @@ -39,7 +39,7 @@ #endif #include -#include +#include #define EPOCH 1970 diff --git a/plugins/sudoers/linux_audit.c b/plugins/sudoers/linux_audit.c index b18a3c2e3..a623307e6 100644 --- a/plugins/sudoers/linux_audit.c +++ b/plugins/sudoers/linux_audit.c @@ -31,10 +31,9 @@ #include #include -#include +#include #include #include -#include #include /* diff --git a/plugins/sudoers/plugin_error.c b/plugins/sudoers/plugin_error.c index 365c51c07..65d11433d 100644 --- a/plugins/sudoers/plugin_error.c +++ b/plugins/sudoers/plugin_error.c @@ -21,7 +21,7 @@ #include #include -#include +#include #include #include #include diff --git a/plugins/sudoers/sudoers.h b/plugins/sudoers/sudoers.h index 902508773..1abcce676 100644 --- a/plugins/sudoers/sudoers.h +++ b/plugins/sudoers/sudoers.h @@ -24,12 +24,11 @@ #include #include -#include +#include #include #include #include #include -#include #include "defaults.h" #include "logging.h" #include "sudo_nss.h" diff --git a/plugins/sudoers/sudoreplay.c b/plugins/sudoers/sudoreplay.c index 1f7e3d4aa..33df8c252 100644 --- a/plugins/sudoers/sudoreplay.c +++ b/plugins/sudoers/sudoreplay.c @@ -85,10 +85,9 @@ #include -#include +#include #include #include -#include #ifndef LINE_MAX # define LINE_MAX 2048 diff --git a/plugins/sudoers/timestr.c b/plugins/sudoers/timestr.c index 740dccdf4..bdcf00935 100644 --- a/plugins/sudoers/timestr.c +++ b/plugins/sudoers/timestr.c @@ -28,7 +28,7 @@ #endif /* STDC_HEADERS */ #include -#include +#include char *get_timestr(time_t, int); diff --git a/src/Makefile.in b/src/Makefile.in index 8bda53446..4bdd9a518 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -80,9 +80,8 @@ LIBOBJDIR = $(top_builddir)/@ac_config_libobj_dir@/ VERSION = @PACKAGE_VERSION@ SUDODEP = $(srcdir)/sudo.h $(incdir)/sudo_plugin.h $(incdir)/alloc.h \ - $(incdir)/compat.h $(incdir)/error.h $(incdir)/list.h \ - $(incdir)/missing.h $(top_builddir)/pathnames.h \ - $(top_builddir)/config.h + $(incdir)/error.h $(incdir)/list.h $(incdir)/missing.h \ + $(top_builddir)/pathnames.h $(top_builddir)/config.h all: $(PROGS) @@ -106,19 +105,19 @@ sesh: sesh.o # Dependencies # XXX - SUDODEP is overkill for some of these conversation.o: $(srcdir)/conversation.c $(SUDODEP) -error.o: $(srcdir)/error.c $(incdir)/compat.h $(incdir)/error.h $(top_builddir)/config.h +error.o: $(srcdir)/error.c $(incdir)/missing.h $(incdir)/error.h $(top_builddir)/config.h exec.o: $(srcdir)/exec.c $(SUDODEP) $(srcdir)/sudo_exec.h exec_pty.o: $(srcdir)/exec_pty.c $(SUDODEP) $(srcdir)/sudo_exec.h get_pty.o: $(srcdir)/get_pty.c $(SUDODEP) load_plugins.o: $(srcdir)/load_plugins.c $(SUDODEP) parse_args.o: $(srcdir)/parse_args.c sudo_usage.h $(SUDODEP) selinux.o: $(srcdir)/selinux.c $(SUDODEP) -sesh.o: $(srcdir)/sesh.c $(incdir)/compat.h $(top_builddir)/config.h +sesh.o: $(srcdir)/sesh.c $(incdir)/missing.h $(top_builddir)/config.h sudo.o: $(srcdir)/sudo.c $(SUDODEP) sudo_edit.o: $(srcdir)/sudo_edit.c $(SUDODEP) -sudo_noexec.lo: $(srcdir)/sudo_noexec.c $(incdir)/compat.h $(top_builddir)/config.h +sudo_noexec.lo: $(srcdir)/sudo_noexec.c $(incdir)/missing.h $(top_builddir)/config.h tgetpass.o: $(srcdir)/tgetpass.c $(SUDODEP) -ttysize.o: $(srcdir)/ttysize.c $(incdir)/compat.h $(top_builddir)/config.h +ttysize.o: $(srcdir)/ttysize.c $(incdir)/missing.h $(top_builddir)/config.h install: install-dirs install-binaries @INSTALL_NOEXEC@ diff --git a/src/error.c b/src/error.c index 77ed00e1e..62b720229 100644 --- a/src/error.c +++ b/src/error.c @@ -20,7 +20,7 @@ #include #include -#include +#include #include "error.h" static void _warning(int, const char *, va_list); diff --git a/src/sesh.c b/src/sesh.c index 0770c5ce2..e85d80bd0 100644 --- a/src/sesh.c +++ b/src/sesh.c @@ -27,7 +27,7 @@ #include #include -#include +#include int main (int argc, char *argv[]) diff --git a/src/sudo.h b/src/sudo.h index 07e43cb8a..d83174c9d 100644 --- a/src/sudo.h +++ b/src/sudo.h @@ -27,12 +27,11 @@ #include #include -#include +#include #include #include #include #include -#include #ifdef __TANDEM # define ROOT_UID 65535 diff --git a/src/sudo_noexec.c b/src/sudo_noexec.c index 27677cab5..9b51f4f82 100644 --- a/src/sudo_noexec.c +++ b/src/sudo_noexec.c @@ -22,7 +22,7 @@ #endif #include -#include +#include /* * Dummy versions of the execve() family of syscalls. We don't need diff --git a/src/ttysize.c b/src/ttysize.c index 9e1afbf0f..3553dbbc7 100644 --- a/src/ttysize.c +++ b/src/ttysize.c @@ -34,7 +34,7 @@ #endif /* HAVE_UNISTD_H */ #include -#include +#include #if !defined(TIOCGSIZE) && defined(TIOCGWINSZ) # define TIOCGSIZE TIOCGWINSZ