X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=compat.h;h=6a1a7cb9094c3141056a6b0917f2d1984d6b52da;hb=04402c11f42ab1ab88cfdd8b22b23f78efd81f75;hp=09f95e371ec91a0a83d79360ca9f9de357cd5dae;hpb=ca3ab12a66fc683cabf546fd405cfbf39ef9fb6f;p=debian%2Fsudo diff --git a/compat.h b/compat.h index 09f95e3..6a1a7cb 100644 --- a/compat.h +++ b/compat.h @@ -1,37 +1,23 @@ /* - * Copyright (c) 1996, 1998-2002 Todd C. Miller - * All rights reserved. + * Copyright (c) 1996, 1998-2004 Todd C. Miller * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: + * 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. * - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. + * 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. * - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. + * 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. * - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * 4. Products derived from this software may not be called "Sudo" nor - * may "Sudo" appear in their names without specific prior written - * permission from the author. - * - * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY - * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL - * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; - * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR - * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - * $Sudo: compat.h,v 1.63 2002/01/25 18:38:22 millert Exp $ + * $Sudo: compat.h,v 1.80 2004/09/10 16:31:15 millert Exp $ */ #ifndef _SUDO_COMPAT_H @@ -51,27 +37,32 @@ #endif /* __P */ /* - * Some systems (ie ISC V/386) do not define MAXPATHLEN even in param.h + * Some systems lack full limit definitions. */ -#ifndef MAXPATHLEN -# define MAXPATHLEN 1024 +#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 -/* - * Some systems do not define MAXHOSTNAMELEN. - */ #ifndef MAXHOSTNAMELEN # define MAXHOSTNAMELEN 64 #endif -/* - * 4.2BSD lacks FD_* macros (we only use FD_SET and FD_ZERO) - */ -#ifndef FD_SETSIZE -# define FD_SET(fd, fds) ((fds) -> fds_bits[0] |= (1 << (fd))) -# define FD_ZERO(fds) ((fds) -> fds_bits[0] = 0) -#endif /* !FD_SETSIZE */ - /* * Posix versions for those without... */ @@ -101,13 +92,6 @@ # define S_IRWXU 0000700 /* rwx for owner */ #endif /* S_IRWXU */ -/* - * In case this is not defined in or - */ -#ifndef howmany -# define howmany(x, y) (((x) + ((y) - 1)) / (y)) -#endif - /* * These should be defined in but not everyone has them. */ @@ -167,32 +151,6 @@ # define memset(_s, _x, _n) (bzero(_s, _n)) #endif -/* - * Emulate sete[ug]id() via setres[ug]id(2) or setre[ug]id(2) - */ -#ifndef HAVE_SETEUID -# ifdef __hpux -# define seteuid(_EUID) (setresuid((uid_t) -1, _EUID, (uid_t) -1)) -# else -# define seteuid(_EUID) (setreuid((uid_t) -1, _EUID)) -# endif /* __hpux */ -#endif /* HAVE_SETEUID */ -#ifndef HAVE_SETEGID -# ifdef __hpux -# define setegid(_EGID) (setresgid((gid_t) -1, _EGID, (gid_t) -1)) -# else -# define setegid(_EGID) (setregid((gid_t) -1, _EGID)) -# endif /* __hpux */ -#endif /* HAVE_SETEGID */ - -/* - * Emulate setreuid() for HP-UX via setresuid(2) - */ -#if !defined(HAVE_SETREUID) && defined(__hpux) -# define setreuid(_RUID, _EUID) (setresuid(_RUID, _EUID, (uid_t) -1)) -# define HAVE_SETREUID -#endif /* !HAVE_SETEUID && __hpux */ - /* * NCR's SVr4 has _innetgr(3) instead of innetgr(3) for some reason. */ @@ -237,20 +195,66 @@ int sigprocmask __P((int, const sigset_t *, sigset_t *)); # ifndef HAVE_SIGACTION_T typedef struct sigaction sigaction_t; # endif -# ifndef SA_INTERRUPT +# ifndef SA_INTERRUPT # define SA_INTERRUPT 0 # endif -# ifndef SA_RESTART +# ifndef SA_RESTART # define SA_RESTART 0 # endif #endif /* - * HP-UX 9.x has RLIMIT_* but no RLIM_INFINITY. - * Using -1 works because we only check for RLIM_INFINITY and do not set it. + * 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. */ -#ifndef RLIM_INFINITY -# define RLIM_INFINITY (-1) +#if !defined(HAVE_FUTIMES) && defined(HAVE_FUTIMESAT) +# define futimes(_f, _tv) futimesat(_f, NULL, _tv) +# define HAVE_FUTIMES +#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 HAVE_TIMESPEC +struct timespec { + time_t tv_sec; + long tv_nsec; +}; +#endif /* !HAVE_TIMESPEC */ + +#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 #endif /* _SUDO_COMPAT_H */