2 * Copyright (c) 1996, 1998-2002 Todd C. Miller <Todd.Miller@courtesan.com>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * 3. The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
19 * 4. Products derived from this software may not be called "Sudo" nor
20 * may "Sudo" appear in their names without specific prior written
21 * permission from the author.
23 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
24 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
25 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
26 * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
27 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
28 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
29 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
30 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
31 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
32 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 * $Sudo: compat.h,v 1.63 2002/01/25 18:38:22 millert Exp $
37 #ifndef _SUDO_COMPAT_H
38 #define _SUDO_COMPAT_H
41 * Macros that may be missing on some Operating Systems
44 /* Deal with ANSI stuff reasonably. */
46 # if defined (__cplusplus) || defined (__STDC__)
47 # define __P(args) args
54 * Some systems (ie ISC V/386) do not define MAXPATHLEN even in param.h
57 # define MAXPATHLEN 1024
61 * Some systems do not define MAXHOSTNAMELEN.
63 #ifndef MAXHOSTNAMELEN
64 # define MAXHOSTNAMELEN 64
68 * 4.2BSD lacks FD_* macros (we only use FD_SET and FD_ZERO)
71 # define FD_SET(fd, fds) ((fds) -> fds_bits[0] |= (1 << (fd)))
72 # define FD_ZERO(fds) ((fds) -> fds_bits[0] = 0)
73 #endif /* !FD_SETSIZE */
76 * Posix versions for those without...
79 # define _S_IFMT S_IFMT
82 # define _S_IFREG S_IFREG
85 # define _S_IFDIR S_IFDIR
88 # define _S_IFLNK S_IFLNK
91 # define S_ISREG(m) (((m) & _S_IFMT) == _S_IFREG)
94 # define S_ISDIR(m) (((m) & _S_IFMT) == _S_IFDIR)
98 * Some OS's may not have this.
101 # define S_IRWXU 0000700 /* rwx for owner */
105 * In case this is not defined in <sys/types.h> or <sys/select.h>
108 # define howmany(x, y) (((x) + ((y) - 1)) / (y))
112 * These should be defined in <unistd.h> but not everyone has them.
115 # define STDIN_FILENO 0
117 #ifndef STDOUT_FILENO
118 # define STDOUT_FILENO 1
120 #ifndef STDERR_FILENO
121 # define STDERR_FILENO 2
125 * These should be defined in <unistd.h> but not everyone has them.
138 * BSD defines these in <sys/param.h> but others may not.
141 # define MIN(a,b) (((a)<(b))?(a):(b))
144 # define MAX(a,b) (((a)>(b))?(a):(b))
148 * Simple isblank() macro for systems without it.
151 # define isblank(_x) ((_x) == ' ' || (_x) == '\t')
155 * Old BSD systems lack strchr(), strrchr(), memset() and memcpy()
157 #if !defined(HAVE_STRCHR) && !defined(strchr)
158 # define strchr(_s, _c) index(_s, _c)
160 #if !defined(HAVE_STRRCHR) && !defined(strrchr)
161 # define strrchr(_s, _c) rindex(_s, _c)
163 #if !defined(HAVE_MEMCPY) && !defined(memcpy)
164 # define memcpy(_d, _s, _n) (bcopy(_s, _d, _n))
166 #if !defined(HAVE_MEMSET) && !defined(memset)
167 # define memset(_s, _x, _n) (bzero(_s, _n))
171 * Emulate sete[ug]id() via setres[ug]id(2) or setre[ug]id(2)
175 # define seteuid(_EUID) (setresuid((uid_t) -1, _EUID, (uid_t) -1))
177 # define seteuid(_EUID) (setreuid((uid_t) -1, _EUID))
179 #endif /* HAVE_SETEUID */
182 # define setegid(_EGID) (setresgid((gid_t) -1, _EGID, (gid_t) -1))
184 # define setegid(_EGID) (setregid((gid_t) -1, _EGID))
186 #endif /* HAVE_SETEGID */
189 * Emulate setreuid() for HP-UX via setresuid(2)
191 #if !defined(HAVE_SETREUID) && defined(__hpux)
192 # define setreuid(_RUID, _EUID) (setresuid(_RUID, _EUID, (uid_t) -1))
193 # define HAVE_SETREUID
194 #endif /* !HAVE_SETEUID && __hpux */
197 * NCR's SVr4 has _innetgr(3) instead of innetgr(3) for some reason.
200 # define innetgr(n, h, u, d) (_innetgr(n, h, u, d))
201 # define HAVE_INNETGR 1
202 #endif /* HAVE__INNETGR */
205 * On POSIX systems, O_NOCTTY is the default so some OS's may lack this define.
209 #endif /* O_NOCTTY */
212 * Emulate POSIX signals via sigvec(2)
214 #ifndef HAVE_SIGACTION
215 # define SA_ONSTACK SV_ONSTACK
216 # define SA_RESTART SV_INTERRUPT /* opposite effect */
217 # define SA_RESETHAND SV_RESETHAND
218 # define sa_handler sv_handler
219 # define sa_mask sv_mask
220 # define sa_flags sv_flags
221 typedef struct sigvec sigaction_t;
222 typedef int sigset_t;
223 int sigaction __P((int sig, const sigaction_t *act, sigaction_t *oact));
224 int sigemptyset __P((sigset_t *));
225 int sigfillset __P((sigset_t *));
226 int sigaddset __P((sigset_t *, int));
227 int sigdelset __P((sigset_t *, int));
228 int sigismember __P((sigset_t *, int));
229 int sigprocmask __P((int, const sigset_t *, sigset_t *));
233 * Extra sugar for POSIX signals to deal with the above emulation
234 * as well as the fact that SunOS has a SA_INTERRUPT flag.
236 #ifdef HAVE_SIGACTION
237 # ifndef HAVE_SIGACTION_T
238 typedef struct sigaction sigaction_t;
240 # ifndef SA_INTERRUPT
241 # define SA_INTERRUPT 0
244 # define SA_RESTART 0
249 * HP-UX 9.x has RLIMIT_* but no RLIM_INFINITY.
250 * Using -1 works because we only check for RLIM_INFINITY and do not set it.
252 #ifndef RLIM_INFINITY
253 # define RLIM_INFINITY (-1)
256 #endif /* _SUDO_COMPAT_H */