Rework source layout in preparation for modular sudo.

This commit is contained in:
Todd C. Miller
2010-02-20 09:14:01 -05:00
parent 28c24027ec
commit e90fa482f9
151 changed files with 0 additions and 0 deletions

42
include/alloc.h Normal file
View File

@@ -0,0 +1,42 @@
/*
* Copyright (c) 2009 Todd C. Miller <Todd.Miller@courtesan.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* 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.
*/
#ifndef _SUDO_ALLOC_H
#define _SUDO_ALLOC_H
#ifdef __STDC__
# include <stdarg.h>
int easprintf(char **, const char *, ...) __printflike(2, 3);
int evasprintf(char **, const char *, va_list) __printflike(2, 0);
void efree(void *);
void *emalloc(size_t);
void *emalloc2(size_t, size_t);
void *erealloc(void *, size_t);
void *erealloc3(void *, size_t, size_t);
char *estrdup(const char *);
#else
# include <varargs.h>
int easprintf();
int evasprintf();
void efree();
void *emalloc();
void *emalloc2();
void *erealloc();
void *erealloc3();
char *estrdup();
#endif /* __STDC__ */
#endif /* _SUDO_ALLOC_H */

305
include/compat.h Normal file
View File

@@ -0,0 +1,305 @@
/*
* Copyright (c) 1996, 1998-2005, 2008
* Todd C. Miller <Todd.Miller@courtesan.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* 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_COMPAT_H
#define _SUDO_COMPAT_H
/*
* Macros that may be missing on some Operating Systems
*/
/* Deal with ANSI stuff reasonably. */
#ifndef __P
# if defined (__cplusplus) || defined (__STDC__)
# define __P(args) args
# else
# define __P(args) ()
# endif
#endif /* __P */
/* 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 <unistd.h> 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
/*
* These should be defined in <unistd.h> but not everyone has them.
*/
#ifndef SEEK_SET
# define SEEK_SET 0
#endif
#ifndef SEEK_CUR
# define SEEK_CUR 1
#endif
#ifndef SEEK_END
# define SEEK_END 2
#endif
/*
* BSD defines these in <sys/param.h> 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 __P((int));
# define isblank(_x) ((_x) == ' ' || (_x) == '\t')
#endif
/*
* Old BSD systems lack strchr(), strrchr(), memset() and memcpy()
*/
#if !defined(HAVE_STRCHR) && !defined(strchr)
# define strchr(_s, _c) index(_s, _c)
#endif
#if !defined(HAVE_STRRCHR) && !defined(strrchr)
# define strrchr(_s, _c) rindex(_s, _c)
#endif
#if !defined(HAVE_MEMCPY) && !defined(memcpy)
# define memcpy(_d, _s, _n) (bcopy(_s, _d, _n))
#endif
#if !defined(HAVE_MEMSET) && !defined(memset)
# define memset(_s, _x, _n) (bzero(_s, _n))
#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 */
/*
* Emulate POSIX signals via sigvec(2)
*/
#ifndef HAVE_SIGACTION
# define SA_ONSTACK SV_ONSTACK
# define SA_RESTART SV_INTERRUPT /* opposite effect */
# define SA_RESETHAND SV_RESETHAND
# define SA_NOCLDSTOP SV_NOCLDSTOP
# define sa_handler sv_handler
# define sa_mask sv_mask
# define sa_flags sv_flags
typedef struct sigvec sigaction_t;
typedef int sigset_t;
int sigaction __P((int sig, const sigaction_t *act, sigaction_t *oact));
int sigemptyset __P((sigset_t *));
int sigfillset __P((sigset_t *));
int sigaddset __P((sigset_t *, int));
int sigdelset __P((sigset_t *, int));
int sigismember __P((sigset_t *, int));
int sigprocmask __P((int, const sigset_t *, sigset_t *));
#endif
/*
* Extra sugar for POSIX signals to deal with the above emulation
* as well as the fact that SunOS has a SA_INTERRUPT flag.
*/
#ifdef HAVE_SIGACTION
# 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
#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 __P((void));
#endif /* HAVE___PROGNAME */
#endif /* !HAVE_GETPROGNAME */
#ifndef timespecclear
# define timespecclear(ts) (ts)->tv_sec = (ts)->tv_nsec = 0
#endif
#ifndef timespecisset
# define timespecisset(ts) ((ts)->tv_sec || (ts)->tv_nsec)
#endif
#ifndef timespecsub
# define timespecsub(minuend, subrahend, difference) \
do { \
(difference)->tv_sec = (minuend)->tv_sec - (subrahend)->tv_sec; \
(difference)->tv_nsec = (minuend)->tv_nsec - (subrahend)->tv_nsec; \
if ((difference)->tv_nsec < 0) { \
(difference)->tv_nsec += 1000000000L; \
(difference)->tv_sec--; \
} \
} while (0)
#endif
#ifndef timeradd
# define timeradd(tv1, tv2, total) \
do { \
(total)->tv_sec = (tv1)->tv_sec + (tv2)->tv_sec; \
(total)->tv_usec = (tv1)->tv_usec + (tv2)->tv_usec; \
if ((total)->tv_usec >= 1000000) { \
(total)->tv_sec++; \
(total)->tv_usec -= 1000000; \
} \
} while (0)
#endif
#ifndef timersub
# define timersub(minuend, subrahend, difference) \
do { \
(difference)->tv_sec = (minuend)->tv_sec - (subrahend)->tv_sec; \
(difference)->tv_usec = (minuend)->tv_usec - (subrahend)->tv_usec; \
if ((difference)->tv_usec < 0) { \
(difference)->tv_sec--; \
(difference)->tv_usec += 1000000; \
} \
} while (0)
#endif
#endif /* _SUDO_COMPAT_H */

34
include/error.h Normal file
View File

@@ -0,0 +1,34 @@
/*
* Copyright (c) 2004 Todd C. Miller <Todd.Miller@courtesan.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* 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.
*/
#ifndef _SUDO_ERROR_H_
#define _SUDO_ERROR_H_
#ifdef __STDC__
# include <stdarg.h>
void error(int, const char *, ...) __attribute__((__noreturn__));
void errorx(int, const char *, ...) __attribute__((__noreturn__));
void warning(const char *, ...);
void warningx(const char *, ...);
#else
# include <varargs.h>
void error() __attribute__((__noreturn__));
void errorx() __attribute__((__noreturn__));
void warning();
void warningx();
#endif /* __STDC__ */
#endif /* _SUDO_ERROR_H_ */

39
include/lbuf.h Normal file
View File

@@ -0,0 +1,39 @@
/*
* Copyright (c) 2007 Todd C. Miller <Todd.Miller@courtesan.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* 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.
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef _SUDO_LBUF_H
#define _SUDO_LBUF_H
/*
* Line buffer struct.
*/
struct lbuf {
char *buf;
int continuation;
int indent;
int len;
int size;
};
void lbuf_init __P((struct lbuf *, char *, int, int));
void lbuf_destroy __P((struct lbuf *));
void lbuf_append __P((struct lbuf *, ...));
void lbuf_append_quoted __P((struct lbuf *, const char *, ...));
void lbuf_print __P((struct lbuf *));
#endif /* _SUDO_LBUF_H */

83
include/list.h Normal file
View File

@@ -0,0 +1,83 @@
/*
* Copyright (c) 2007 Todd C. Miller <Todd.Miller@courtesan.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* 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.
*/
#ifndef _SUDO_LIST_H
#define _SUDO_LIST_H
/*
* Convenience macro for declaring a list head.
*/
#ifdef __STDC__
#define TQ_DECLARE(n) \
struct n##_list { \
struct n *first; \
struct n *last; \
};
#else
#define TQ_DECLARE(n) \
struct n/**/_list { \
struct n *first; \
struct n *last; \
};
#endif
/*
* Foreach loops: forward and reverse
*/
#undef tq_foreach_fwd
#define tq_foreach_fwd(h, v) \
for ((v) = (h)->first; (v) != NULL; (v) = (v)->next)
#undef tq_foreach_rev
#define tq_foreach_rev(h, v) \
for ((v) = (h)->last; (v) != NULL; (v) = (v)->prev)
/*
* Init a list head.
*/
#undef tq_init
#define tq_init(h) do { \
(h)->first = NULL; \
(h)->last = NULL; \
} while (0)
/*
* Simple macros to avoid exposing first/last and prev/next.
*/
#undef tq_empty
#define tq_empty(h) ((h)->first == NULL)
#undef tq_first
#define tq_first(h) ((h)->first)
#undef tq_last
#define tq_last(h) ((h)->last)
#undef list_next
#define list_next(e) ((e)->next)
#undef list_prev
#define list_prev(e) ((e)->prev)
/*
* Prototypes for list.c
*/
void *tq_pop __P((void *));
void tq_append __P((void *, void *));
void list_append __P((void *, void *));
void list2tq __P((void *, void *));
#endif /* _SUDO_LIST_H */

84
include/missing.h Normal file
View File

@@ -0,0 +1,84 @@
/*
* Copyright (c) 2009 Todd C. Miller <Todd.Miller@courtesan.com>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* 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.
*/
#ifndef _SUDO_MISSING_H
#define _SUDO_MISSING_H
/* Functions "missing" from libc. */
struct timeval;
struct timespec;
#ifndef HAVE_CLOSEFROM
void closefrom __P((int));
#endif
#ifndef HAVE_GETCWD
char *getcwd __P((char *, size_t size));
#endif
#ifndef HAVE_GETLINE
ssize_t getline __P((char **, size_t *, FILE *));
#endif
#ifndef HAVE_UTIMES
int utimes __P((const char *, const struct timeval *));
#endif
#ifdef HAVE_FUTIME
int futimes __P((int, const struct timeval *));
#endif
#ifndef HAVE_SNPRINTF
int snprintf __P((char *, size_t, const char *, ...))
__printflike(3, 4);
#endif
#ifndef HAVE_VSNPRINTF
int vsnprintf __P((char *, size_t, const char *, va_list))
__printflike(3, 0);
#endif
#ifndef HAVE_ASPRINTF
int asprintf __P((char **, const char *, ...))
__printflike(2, 3);
#endif
#ifndef HAVE_VASPRINTF
int vasprintf __P((char **, const char *, va_list))
__printflike(2, 0);
#endif
#ifndef HAVE_STRCASECMP
int strcasecmp __P((const char *, const char *));
#endif
#ifndef HAVE_STRLCAT
size_t strlcat __P((char *, const char *, size_t));
#endif
#ifndef HAVE_STRLCPY
size_t strlcpy __P((char *, const char *, size_t));
#endif
#ifndef HAVE_MEMRCHR
void *memrchr __P((const void *, int, size_t));
#endif
#ifndef HAVE_MKSTEMP
int mkstemp __P((char *));
#endif
#ifndef HAVE_NANOSLEEP
int nanosleep __P((const struct timespec *, struct timespec *));
#endif
#ifndef HAVE_SETENV
int setenv __P((const char *, const char *, int));
#endif
#ifndef HAVE_UNSETENV
int unsetenv __P((const char *));
#endif
#ifdef HAVE_SYS_SIGLIST
char *strsignal __P((int));
#endif
#endif /* _SUDO_MISSING_H */