1 /*
2  * Copyright (c) 1999-2003 Damien Miller.  All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  * 1. Redistributions of source code must retain the above copyright
8  *    notice, this list of conditions and the following disclaimer.
9  * 2. Redistributions in binary form must reproduce the above copyright
10  *    notice, this list of conditions and the following disclaimer in the
11  *    documentation and/or other materials provided with the distribution.
12  *
13  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
14  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
15  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
16  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
17  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
19  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
20  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
23  */
24 
25 #ifndef _DEFINES_H
26 #define _DEFINES_H
27 
28 /* Constants */
29 
30 #if defined(HAVE_DECL_SHUT_RD) && HAVE_DECL_SHUT_RD == 0
31 enum
32 {
33   SHUT_RD = 0,		/* No more receptions.  */
34   SHUT_WR,			/* No more transmissions.  */
35   SHUT_RDWR			/* No more receptions or transmissions.  */
36 };
37 # define SHUT_RD   SHUT_RD
38 # define SHUT_WR   SHUT_WR
39 # define SHUT_RDWR SHUT_RDWR
40 #endif
41 
42 /*
43  * Cygwin doesn't really have a notion of reserved ports.  It is still
44  * is useful on the client side so for compatibility it defines as 1024 via
45  * netinet/in.h inside an enum.  We * don't actually want that restriction
46  * so we want to set that to zero, but we can't do it direct in config.h
47  * because it'll cause a conflicting definition the first time we include
48  * netinet/in.h.
49  */
50 
51 #ifdef HAVE_CYGWIN
52 #define IPPORT_RESERVED 0
53 #endif
54 
55 /*
56  * Definitions for IP type of service (ip_tos)
57  */
58 #include <netinet/in_systm.h>
59 #include <netinet/ip.h>
60 #ifndef IPTOS_LOWDELAY
61 # define IPTOS_LOWDELAY          0x10
62 # define IPTOS_THROUGHPUT        0x08
63 # define IPTOS_RELIABILITY       0x04
64 # define IPTOS_LOWCOST           0x02
65 # define IPTOS_MINCOST           IPTOS_LOWCOST
66 #endif /* IPTOS_LOWDELAY */
67 
68 /*
69  * Definitions for DiffServ Codepoints as per RFC2474
70  */
71 #ifndef IPTOS_DSCP_AF11
72 # define	IPTOS_DSCP_AF11		0x28
73 # define	IPTOS_DSCP_AF12		0x30
74 # define	IPTOS_DSCP_AF13		0x38
75 # define	IPTOS_DSCP_AF21		0x48
76 # define	IPTOS_DSCP_AF22		0x50
77 # define	IPTOS_DSCP_AF23		0x58
78 # define	IPTOS_DSCP_AF31		0x68
79 # define	IPTOS_DSCP_AF32		0x70
80 # define	IPTOS_DSCP_AF33		0x78
81 # define	IPTOS_DSCP_AF41		0x88
82 # define	IPTOS_DSCP_AF42		0x90
83 # define	IPTOS_DSCP_AF43		0x98
84 # define	IPTOS_DSCP_EF		0xb8
85 #endif /* IPTOS_DSCP_AF11 */
86 #ifndef IPTOS_DSCP_CS0
87 # define	IPTOS_DSCP_CS0		0x00
88 # define	IPTOS_DSCP_CS1		0x20
89 # define	IPTOS_DSCP_CS2		0x40
90 # define	IPTOS_DSCP_CS3		0x60
91 # define	IPTOS_DSCP_CS4		0x80
92 # define	IPTOS_DSCP_CS5		0xa0
93 # define	IPTOS_DSCP_CS6		0xc0
94 # define	IPTOS_DSCP_CS7		0xe0
95 #endif /* IPTOS_DSCP_CS0 */
96 #ifndef IPTOS_DSCP_EF
97 # define	IPTOS_DSCP_EF		0xb8
98 #endif /* IPTOS_DSCP_EF */
99 
100 #ifndef PATH_MAX
101 # ifdef _POSIX_PATH_MAX
102 # define PATH_MAX _POSIX_PATH_MAX
103 # endif
104 #endif
105 
106 #ifndef MAXPATHLEN
107 # ifdef PATH_MAX
108 #  define MAXPATHLEN PATH_MAX
109 # else /* PATH_MAX */
110 #  define MAXPATHLEN 64
111 /* realpath uses a fixed buffer of size MAXPATHLEN, so force use of ours */
112 #  ifndef BROKEN_REALPATH
113 #   define BROKEN_REALPATH 1
114 #  endif /* BROKEN_REALPATH */
115 # endif /* PATH_MAX */
116 #endif /* MAXPATHLEN */
117 
118 #ifndef HOST_NAME_MAX
119 # include "netdb.h" /* for MAXHOSTNAMELEN */
120 # if defined(_POSIX_HOST_NAME_MAX)
121 #  define HOST_NAME_MAX _POSIX_HOST_NAME_MAX
122 # elif defined(MAXHOSTNAMELEN)
123 #  define HOST_NAME_MAX MAXHOSTNAMELEN
124 # else
125 #  define HOST_NAME_MAX	255
126 # endif
127 #endif /* HOST_NAME_MAX */
128 
129 #if defined(HAVE_DECL_MAXSYMLINKS) && HAVE_DECL_MAXSYMLINKS == 0
130 # define MAXSYMLINKS 5
131 #endif
132 
133 #ifndef STDIN_FILENO
134 # define STDIN_FILENO    0
135 #endif
136 #ifndef STDOUT_FILENO
137 # define STDOUT_FILENO   1
138 #endif
139 #ifndef STDERR_FILENO
140 # define STDERR_FILENO   2
141 #endif
142 
143 #ifndef NGROUPS_MAX	/* Disable groupaccess if NGROUP_MAX is not set */
144 #ifdef NGROUPS
145 #define NGROUPS_MAX NGROUPS
146 #else
147 #define NGROUPS_MAX 0
148 #endif
149 #endif
150 
151 #if defined(HAVE_DECL_O_NONBLOCK) && HAVE_DECL_O_NONBLOCK == 0
152 # define O_NONBLOCK      00004	/* Non Blocking Open */
153 #endif
154 
155 #ifndef S_IFSOCK
156 # define S_IFSOCK 0
157 #endif /* S_IFSOCK */
158 
159 #ifndef S_ISDIR
160 # define S_ISDIR(mode)	(((mode) & (_S_IFMT)) == (_S_IFDIR))
161 #endif /* S_ISDIR */
162 
163 #ifndef S_ISREG
164 # define S_ISREG(mode)	(((mode) & (_S_IFMT)) == (_S_IFREG))
165 #endif /* S_ISREG */
166 
167 #ifndef S_ISLNK
168 # define S_ISLNK(mode)	(((mode) & S_IFMT) == S_IFLNK)
169 #endif /* S_ISLNK */
170 
171 #ifndef S_IXUSR
172 # define S_IXUSR			0000100	/* execute/search permission, */
173 # define S_IXGRP			0000010	/* execute/search permission, */
174 # define S_IXOTH			0000001	/* execute/search permission, */
175 # define _S_IWUSR			0000200	/* write permission, */
176 # define S_IWUSR			_S_IWUSR	/* write permission, owner */
177 # define S_IWGRP			0000020	/* write permission, group */
178 # define S_IWOTH			0000002	/* write permission, other */
179 # define S_IRUSR			0000400	/* read permission, owner */
180 # define S_IRGRP			0000040	/* read permission, group */
181 # define S_IROTH			0000004	/* read permission, other */
182 # define S_IRWXU			0000700	/* read, write, execute */
183 # define S_IRWXG			0000070	/* read, write, execute */
184 # define S_IRWXO			0000007	/* read, write, execute */
185 #endif /* S_IXUSR */
186 
187 #if !defined(MAP_ANON) && defined(MAP_ANONYMOUS)
188 #define MAP_ANON MAP_ANONYMOUS
189 #endif
190 
191 #ifndef MAP_FAILED
192 # define MAP_FAILED ((void *)-1)
193 #endif
194 
195 /*
196 SCO Open Server 3 has INADDR_LOOPBACK defined in rpc/rpc.h but
197 including rpc/rpc.h breaks Solaris 6
198 */
199 #ifndef INADDR_LOOPBACK
200 #define INADDR_LOOPBACK ((u_long)0x7f000001)
201 #endif
202 
203 /* Types */
204 
205 /* If sys/types.h does not supply intXX_t, supply them ourselves */
206 /* (or die trying) */
207 
208 #ifndef HAVE_U_INT
209 typedef unsigned int u_int;
210 #endif
211 
212 #ifndef HAVE_INTXX_T
213 typedef signed char int8_t;
214 # if (SIZEOF_SHORT_INT == 2)
215 typedef short int int16_t;
216 # else
217 #  ifdef _UNICOS
218 #   if (SIZEOF_SHORT_INT == 4)
219 typedef short int16_t;
220 #   else
221 typedef long  int16_t;
222 #   endif
223 #  else
224 #   error "16 bit int type not found."
225 #  endif /* _UNICOS */
226 # endif
227 # if (SIZEOF_INT == 4)
228 typedef int int32_t;
229 # else
230 #  ifdef _UNICOS
231 typedef long  int32_t;
232 #  else
233 #   error "32 bit int type not found."
234 #  endif /* _UNICOS */
235 # endif
236 #endif
237 
238 /* If sys/types.h does not supply u_intXX_t, supply them ourselves */
239 #ifndef HAVE_U_INTXX_T
240 # ifdef HAVE_UINTXX_T
241 typedef uint8_t u_int8_t;
242 typedef uint16_t u_int16_t;
243 typedef uint32_t u_int32_t;
244 # define HAVE_U_INTXX_T 1
245 # else
246 typedef unsigned char u_int8_t;
247 #  if (SIZEOF_SHORT_INT == 2)
248 typedef unsigned short int u_int16_t;
249 #  else
250 #   ifdef _UNICOS
251 #    if (SIZEOF_SHORT_INT == 4)
252 typedef unsigned short u_int16_t;
253 #    else
254 typedef unsigned long  u_int16_t;
255 #    endif
256 #   else
257 #    error "16 bit int type not found."
258 #   endif
259 #  endif
260 #  if (SIZEOF_INT == 4)
261 typedef unsigned int u_int32_t;
262 #  else
263 #   ifdef _UNICOS
264 typedef unsigned long  u_int32_t;
265 #   else
266 #    error "32 bit int type not found."
267 #   endif
268 #  endif
269 # endif
270 #define __BIT_TYPES_DEFINED__
271 #endif
272 
273 /* 64-bit types */
274 #ifndef HAVE_INT64_T
275 # if (SIZEOF_LONG_INT == 8)
276 typedef long int int64_t;
277 # else
278 #  if (SIZEOF_LONG_LONG_INT == 8)
279 typedef long long int int64_t;
280 #  endif
281 # endif
282 #endif
283 #ifndef HAVE_U_INT64_T
284 # if (SIZEOF_LONG_INT == 8)
285 typedef unsigned long int u_int64_t;
286 # else
287 #  if (SIZEOF_LONG_LONG_INT == 8)
288 typedef unsigned long long int u_int64_t;
289 #  endif
290 # endif
291 #endif
292 
293 #ifndef HAVE_UINTXX_T
294 typedef u_int8_t uint8_t;
295 typedef u_int16_t uint16_t;
296 typedef u_int32_t uint32_t;
297 typedef u_int64_t uint64_t;
298 #endif
299 
300 #ifndef HAVE_INTMAX_T
301 typedef long long intmax_t;
302 #endif
303 
304 #ifndef HAVE_UINTMAX_T
305 typedef unsigned long long uintmax_t;
306 #endif
307 
308 #ifndef HAVE_U_CHAR
309 typedef unsigned char u_char;
310 # define HAVE_U_CHAR
311 #endif /* HAVE_U_CHAR */
312 
313 #ifndef ULLONG_MAX
314 # define ULLONG_MAX ((unsigned long long)-1)
315 #endif
316 
317 #ifndef SIZE_T_MAX
318 #define SIZE_T_MAX ULONG_MAX
319 #endif /* SIZE_T_MAX */
320 
321 #ifndef HAVE_SIZE_T
322 typedef unsigned int size_t;
323 # define HAVE_SIZE_T
324 # define SIZE_T_MAX UINT_MAX
325 #endif /* HAVE_SIZE_T */
326 
327 #ifndef SIZE_MAX
328 #define SIZE_MAX SIZE_T_MAX
329 #endif
330 
331 #ifndef HAVE_SSIZE_T
332 typedef int ssize_t;
333 # define HAVE_SSIZE_T
334 #endif /* HAVE_SSIZE_T */
335 
336 #ifndef HAVE_CLOCK_T
337 typedef long clock_t;
338 # define HAVE_CLOCK_T
339 #endif /* HAVE_CLOCK_T */
340 
341 #ifndef HAVE_SA_FAMILY_T
342 typedef int sa_family_t;
343 # define HAVE_SA_FAMILY_T
344 #endif /* HAVE_SA_FAMILY_T */
345 
346 #ifndef HAVE_PID_T
347 typedef int pid_t;
348 # define HAVE_PID_T
349 #endif /* HAVE_PID_T */
350 
351 #ifndef HAVE_SIG_ATOMIC_T
352 typedef int sig_atomic_t;
353 # define HAVE_SIG_ATOMIC_T
354 #endif /* HAVE_SIG_ATOMIC_T */
355 
356 #ifndef HAVE_MODE_T
357 typedef int mode_t;
358 # define HAVE_MODE_T
359 #endif /* HAVE_MODE_T */
360 
361 #if !defined(HAVE_SS_FAMILY_IN_SS) && defined(HAVE___SS_FAMILY_IN_SS)
362 # define ss_family __ss_family
363 #endif /* !defined(HAVE_SS_FAMILY_IN_SS) && defined(HAVE_SA_FAMILY_IN_SS) */
364 
365 #ifndef HAVE_SYS_UN_H
366 struct	sockaddr_un {
367 	short	sun_family;		/* AF_UNIX */
368 	char	sun_path[108];		/* path name (gag) */
369 };
370 #endif /* HAVE_SYS_UN_H */
371 
372 #ifndef HAVE_IN_ADDR_T
373 typedef u_int32_t	in_addr_t;
374 #endif
375 #ifndef HAVE_IN_PORT_T
376 typedef u_int16_t	in_port_t;
377 #endif
378 
379 #if defined(BROKEN_SYS_TERMIO_H) && !defined(_STRUCT_WINSIZE)
380 #define _STRUCT_WINSIZE
381 struct winsize {
382       unsigned short ws_row;          /* rows, in characters */
383       unsigned short ws_col;          /* columns, in character */
384       unsigned short ws_xpixel;       /* horizontal size, pixels */
385       unsigned short ws_ypixel;       /* vertical size, pixels */
386 };
387 #endif
388 
389 /* bits needed for select that may not be in the system headers */
390 #ifndef HAVE_FD_MASK
391  typedef unsigned long int	fd_mask;
392 #endif
393 
394 #if defined(HAVE_DECL_NFDBITS) && HAVE_DECL_NFDBITS == 0
395 # define	NFDBITS (8 * sizeof(unsigned long))
396 #endif
397 
398 #if defined(HAVE_DECL_HOWMANY) && HAVE_DECL_HOWMANY == 0
399 # define howmany(x,y)	(((x)+((y)-1))/(y))
400 #endif
401 
402 /* Paths */
403 
404 #ifndef _PATH_BSHELL
405 # define _PATH_BSHELL "/bin/sh"
406 #endif
407 
408 #ifdef USER_PATH
409 # ifdef _PATH_STDPATH
410 #  undef _PATH_STDPATH
411 # endif
412 # define _PATH_STDPATH USER_PATH
413 #endif
414 
415 #ifndef _PATH_STDPATH
416 # define _PATH_STDPATH "/usr/bin:/bin:/usr/sbin:/sbin"
417 #endif
418 
419 #ifndef SUPERUSER_PATH
420 # define SUPERUSER_PATH	_PATH_STDPATH
421 #endif
422 
423 #ifndef _PATH_DEVNULL
424 # define _PATH_DEVNULL "/dev/null"
425 #endif
426 
427 /* user may have set a different path */
428 #if defined(_PATH_MAILDIR) && defined(MAIL_DIRECTORY)
429 # undef _PATH_MAILDIR
430 #endif /* defined(_PATH_MAILDIR) && defined(MAIL_DIRECTORY) */
431 
432 #ifdef MAIL_DIRECTORY
433 # define _PATH_MAILDIR MAIL_DIRECTORY
434 #endif
435 
436 #ifndef _PATH_NOLOGIN
437 # define _PATH_NOLOGIN "/etc/nologin"
438 #endif
439 
440 /* Define this to be the path of the xauth program. */
441 #ifdef XAUTH_PATH
442 #define _PATH_XAUTH XAUTH_PATH
443 #endif /* XAUTH_PATH */
444 
445 /* derived from XF4/xc/lib/dps/Xlibnet.h */
446 #ifndef X_UNIX_PATH
447 #  ifdef __hpux
448 #    define X_UNIX_PATH "/var/spool/sockets/X11/%u"
449 #  else
450 #    define X_UNIX_PATH "/tmp/.X11-unix/X%u"
451 #  endif
452 #endif /* X_UNIX_PATH */
453 #define _PATH_UNIX_X X_UNIX_PATH
454 
455 #ifndef _PATH_TTY
456 # define _PATH_TTY "/dev/tty"
457 #endif
458 
459 /* Macros */
460 
461 #if defined(HAVE_LOGIN_GETCAPBOOL) && defined(HAVE_LOGIN_CAP_H)
462 # define HAVE_LOGIN_CAP
463 #endif
464 
465 #ifndef MAX
466 # define MAX(a,b) (((a)>(b))?(a):(b))
467 # define MIN(a,b) (((a)<(b))?(a):(b))
468 #endif
469 
470 #ifndef roundup
471 # define roundup(x, y)   ((((x)+((y)-1))/(y))*(y))
472 #endif
473 
474 #ifndef timersub
475 #define timersub(a, b, result)					\
476    do {								\
477       (result)->tv_sec = (a)->tv_sec - (b)->tv_sec;		\
478       (result)->tv_usec = (a)->tv_usec - (b)->tv_usec;		\
479       if ((result)->tv_usec < 0) {				\
480 	 --(result)->tv_sec;					\
481 	 (result)->tv_usec += 1000000;				\
482       }								\
483    } while (0)
484 #endif
485 
486 #ifndef TIMEVAL_TO_TIMESPEC
487 #define	TIMEVAL_TO_TIMESPEC(tv, ts) {					\
488 	(ts)->tv_sec = (tv)->tv_sec;					\
489 	(ts)->tv_nsec = (tv)->tv_usec * 1000;				\
490 }
491 #endif
492 
493 #ifndef TIMESPEC_TO_TIMEVAL
494 #define	TIMESPEC_TO_TIMEVAL(tv, ts) {					\
495 	(tv)->tv_sec = (ts)->tv_sec;					\
496 	(tv)->tv_usec = (ts)->tv_nsec / 1000;				\
497 }
498 #endif
499 
500 #ifndef __P
501 # define __P(x) x
502 #endif
503 
504 #if !defined(IN6_IS_ADDR_V4MAPPED)
505 # define IN6_IS_ADDR_V4MAPPED(a) \
506 	((((u_int32_t *) (a))[0] == 0) && (((u_int32_t *) (a))[1] == 0) && \
507 	 (((u_int32_t *) (a))[2] == htonl (0xffff)))
508 #endif /* !defined(IN6_IS_ADDR_V4MAPPED) */
509 
510 #if !defined(__GNUC__) || (__GNUC__ < 2)
511 # define __attribute__(x)
512 #endif /* !defined(__GNUC__) || (__GNUC__ < 2) */
513 
514 #if !defined(HAVE_ATTRIBUTE__SENTINEL__) && !defined(__sentinel__)
515 # define __sentinel__
516 #endif
517 
518 #if !defined(HAVE_ATTRIBUTE__BOUNDED__) && !defined(__bounded__)
519 # define __bounded__(x, y, z)
520 #endif
521 
522 #if !defined(HAVE_ATTRIBUTE__NONNULL__) && !defined(__nonnull__)
523 # define __nonnull__(x)
524 #endif
525 
526 #ifndef OSSH_ALIGNBYTES
527 #define OSSH_ALIGNBYTES	(sizeof(int) - 1)
528 #endif
529 #ifndef __CMSG_ALIGN
530 #define	__CMSG_ALIGN(p) (((u_int)(p) + OSSH_ALIGNBYTES) &~ OSSH_ALIGNBYTES)
531 #endif
532 
533 /* Length of the contents of a control message of length len */
534 #ifndef CMSG_LEN
535 #define	CMSG_LEN(len)	(__CMSG_ALIGN(sizeof(struct cmsghdr)) + (len))
536 #endif
537 
538 /* Length of the space taken up by a padded control message of length len */
539 #ifndef CMSG_SPACE
540 #define	CMSG_SPACE(len)	(__CMSG_ALIGN(sizeof(struct cmsghdr)) + __CMSG_ALIGN(len))
541 #endif
542 
543 /* given pointer to struct cmsghdr, return pointer to data */
544 #ifndef CMSG_DATA
545 #define CMSG_DATA(cmsg) ((u_char *)(cmsg) + __CMSG_ALIGN(sizeof(struct cmsghdr)))
546 #endif /* CMSG_DATA */
547 
548 /*
549  * RFC 2292 requires to check msg_controllen, in case that the kernel returns
550  * an empty list for some reasons.
551  */
552 #ifndef CMSG_FIRSTHDR
553 #define CMSG_FIRSTHDR(mhdr) \
554 	((mhdr)->msg_controllen >= sizeof(struct cmsghdr) ? \
555 	 (struct cmsghdr *)(mhdr)->msg_control : \
556 	 (struct cmsghdr *)NULL)
557 #endif /* CMSG_FIRSTHDR */
558 
559 #if defined(HAVE_DECL_OFFSETOF) && HAVE_DECL_OFFSETOF == 0
560 # define offsetof(type, member) ((size_t) &((type *)0)->member)
561 #endif
562 
563 /* Set up BSD-style BYTE_ORDER definition if it isn't there already */
564 /* XXX: doesn't try to cope with strange byte orders (PDP_ENDIAN) */
565 #ifndef BYTE_ORDER
566 # ifndef LITTLE_ENDIAN
567 #  define LITTLE_ENDIAN  1234
568 # endif /* LITTLE_ENDIAN */
569 # ifndef BIG_ENDIAN
570 #  define BIG_ENDIAN     4321
571 # endif /* BIG_ENDIAN */
572 # ifdef WORDS_BIGENDIAN
573 #  define BYTE_ORDER BIG_ENDIAN
574 # else /* WORDS_BIGENDIAN */
575 #  define BYTE_ORDER LITTLE_ENDIAN
576 # endif /* WORDS_BIGENDIAN */
577 #endif /* BYTE_ORDER */
578 
579 /* Function replacement / compatibility hacks */
580 
581 #if !defined(HAVE_GETADDRINFO) && (defined(HAVE_OGETADDRINFO) || defined(HAVE_NGETADDRINFO))
582 # define HAVE_GETADDRINFO
583 #endif
584 
585 #ifndef HAVE_GETOPT_OPTRESET
586 # undef getopt
587 # undef opterr
588 # undef optind
589 # undef optopt
590 # undef optreset
591 # undef optarg
592 # define getopt(ac, av, o)  BSDgetopt(ac, av, o)
593 # define opterr             BSDopterr
594 # define optind             BSDoptind
595 # define optopt             BSDoptopt
596 # define optreset           BSDoptreset
597 # define optarg             BSDoptarg
598 #endif
599 
600 #if defined(BROKEN_GETADDRINFO) && defined(HAVE_GETADDRINFO)
601 # undef HAVE_GETADDRINFO
602 #endif
603 #if defined(BROKEN_GETADDRINFO) && defined(HAVE_FREEADDRINFO)
604 # undef HAVE_FREEADDRINFO
605 #endif
606 #if defined(BROKEN_GETADDRINFO) && defined(HAVE_GAI_STRERROR)
607 # undef HAVE_GAI_STRERROR
608 #endif
609 
610 #if defined(HAVE_GETADDRINFO)
611 # if defined(HAVE_DECL_AI_NUMERICSERV) && HAVE_DECL_AI_NUMERICSERV == 0
612 #   define AI_NUMERICSERV	0
613 # endif
614 #endif
615 
616 #if defined(BROKEN_UPDWTMPX) && defined(HAVE_UPDWTMPX)
617 # undef HAVE_UPDWTMPX
618 #endif
619 
620 #if defined(BROKEN_SHADOW_EXPIRE) && defined(HAS_SHADOW_EXPIRE)
621 # undef HAS_SHADOW_EXPIRE
622 #endif
623 
624 #if defined(HAVE_OPENLOG_R) && defined(SYSLOG_DATA_INIT) && \
625     defined(SYSLOG_R_SAFE_IN_SIGHAND)
626 # define DO_LOG_SAFE_IN_SIGHAND
627 #endif
628 
629 #if !defined(HAVE_MEMMOVE) && defined(HAVE_BCOPY)
630 # define memmove(s1, s2, n) bcopy((s2), (s1), (n))
631 #endif /* !defined(HAVE_MEMMOVE) && defined(HAVE_BCOPY) */
632 
633 #ifndef GETPGRP_VOID
634 # include <unistd.h>
635 # define getpgrp() getpgrp(0)
636 #endif
637 
638 #ifdef USE_BSM_AUDIT
639 # define SSH_AUDIT_EVENTS
640 # define CUSTOM_SSH_AUDIT_EVENTS
641 #endif
642 
643 #ifdef USE_LINUX_AUDIT
644 # define SSH_AUDIT_EVENTS
645 # define CUSTOM_SSH_AUDIT_EVENTS
646 #endif
647 
648 #if !defined(HAVE___func__) && defined(HAVE___FUNCTION__)
649 #  define __func__ __FUNCTION__
650 #elif !defined(HAVE___func__)
651 #  define __func__ ""
652 #endif
653 
654 #if defined(KRB5) && !defined(HEIMDAL)
655 #  define krb5_get_err_text(context,code) error_message(code)
656 #endif
657 
658 #if defined(SKEYCHALLENGE_4ARG)
659 # define _compat_skeychallenge(a,b,c,d) skeychallenge(a,b,c,d)
660 #else
661 # define _compat_skeychallenge(a,b,c,d) skeychallenge(a,b,c)
662 #endif
663 
664 /* Maximum number of file descriptors available */
665 #ifdef HAVE_SYSCONF
666 # define SSH_SYSFDMAX sysconf(_SC_OPEN_MAX)
667 #else
668 # define SSH_SYSFDMAX 10000
669 #endif
670 
671 #ifdef FSID_HAS_VAL
672 /* encode f_fsid into a 64 bit value  */
673 #define FSID_TO_ULONG(f) \
674 	((((u_int64_t)(f).val[0] & 0xffffffffUL) << 32) | \
675 	    ((f).val[1] & 0xffffffffUL))
676 #elif defined(FSID_HAS___VAL)
677 #define FSID_TO_ULONG(f) \
678 	((((u_int64_t)(f).__val[0] & 0xffffffffUL) << 32) | \
679 	    ((f).__val[1] & 0xffffffffUL))
680 #else
681 # define FSID_TO_ULONG(f) ((f))
682 #endif
683 
684 #if defined(__Lynx__)
685  /*
686   * LynxOS defines these in param.h which we do not want to include since
687   * it will also pull in a bunch of kernel definitions.
688   */
689 # define ALIGNBYTES (sizeof(int) - 1)
690 # define ALIGN(p) (((unsigned)p + ALIGNBYTES) & ~ALIGNBYTES)
691   /* Missing prototypes on LynxOS */
692   int snprintf (char *, size_t, const char *, ...);
693   int mkstemp (char *);
694   char *crypt (const char *, const char *);
695   int seteuid (uid_t);
696   int setegid (gid_t);
697   char *mkdtemp (char *);
698   int rresvport_af (int *, sa_family_t);
699   int innetgr (const char *, const char *, const char *, const char *);
700 #endif
701 
702 /*
703  * Define this to use pipes instead of socketpairs for communicating with the
704  * client program.  Socketpairs do not seem to work on all systems.
705  *
706  * configure.ac sets this for a few OS's which are known to have problems
707  * but you may need to set it yourself
708  */
709 /* #define USE_PIPES 1 */
710 
711 /**
712  ** login recorder definitions
713  **/
714 
715 /* FIXME: put default paths back in */
716 #ifndef UTMP_FILE
717 #  ifdef _PATH_UTMP
718 #    define UTMP_FILE _PATH_UTMP
719 #  else
720 #    ifdef CONF_UTMP_FILE
721 #      define UTMP_FILE CONF_UTMP_FILE
722 #    endif
723 #  endif
724 #endif
725 #ifndef WTMP_FILE
726 #  ifdef _PATH_WTMP
727 #    define WTMP_FILE _PATH_WTMP
728 #  else
729 #    ifdef CONF_WTMP_FILE
730 #      define WTMP_FILE CONF_WTMP_FILE
731 #    endif
732 #  endif
733 #endif
734 /* pick up the user's location for lastlog if given */
735 #ifndef LASTLOG_FILE
736 #  ifdef _PATH_LASTLOG
737 #    define LASTLOG_FILE _PATH_LASTLOG
738 #  else
739 #    ifdef CONF_LASTLOG_FILE
740 #      define LASTLOG_FILE CONF_LASTLOG_FILE
741 #    endif
742 #  endif
743 #endif
744 
745 #if defined(HAVE_SHADOW_H) && !defined(DISABLE_SHADOW)
746 # define USE_SHADOW
747 #endif
748 
749 /* The login() library function in libutil is first choice */
750 #if defined(HAVE_LOGIN) && !defined(DISABLE_LOGIN)
751 #  define USE_LOGIN
752 
753 #else
754 /* Simply select your favourite login types. */
755 /* Can't do if-else because some systems use several... <sigh> */
756 #  if !defined(DISABLE_UTMPX)
757 #    define USE_UTMPX
758 #  endif
759 #  if defined(UTMP_FILE) && !defined(DISABLE_UTMP)
760 #    define USE_UTMP
761 #  endif
762 #  if defined(WTMPX_FILE) && !defined(DISABLE_WTMPX)
763 #    define USE_WTMPX
764 #  endif
765 #  if defined(WTMP_FILE) && !defined(DISABLE_WTMP)
766 #    define USE_WTMP
767 #  endif
768 
769 #endif
770 
771 #ifndef UT_LINESIZE
772 # define UT_LINESIZE 8
773 #endif
774 
775 /* I hope that the presence of LASTLOG_FILE is enough to detect this */
776 #if defined(LASTLOG_FILE) && !defined(DISABLE_LASTLOG)
777 #  define USE_LASTLOG
778 #endif
779 
780 #ifdef HAVE_OSF_SIA
781 # ifdef USE_SHADOW
782 #  undef USE_SHADOW
783 # endif
784 # define CUSTOM_SYS_AUTH_PASSWD 1
785 #endif
786 
787 #if defined(HAVE_LIBIAF) && defined(HAVE_SET_ID) && !defined(HAVE_SECUREWARE)
788 # define CUSTOM_SYS_AUTH_PASSWD 1
789 #endif
790 #if defined(HAVE_LIBIAF) && defined(HAVE_SET_ID) && !defined(BROKEN_LIBIAF)
791 # define USE_LIBIAF
792 #endif
793 
794 /* HP-UX 11.11 */
795 #ifdef BTMP_FILE
796 # define _PATH_BTMP BTMP_FILE
797 #endif
798 
799 #if defined(USE_BTMP) && defined(_PATH_BTMP)
800 # define CUSTOM_FAILED_LOGIN
801 #endif
802 
803 /** end of login recorder definitions */
804 
805 #ifdef BROKEN_GETGROUPS
806 # define getgroups(a,b) ((a)==0 && (b)==NULL ? NGROUPS_MAX : getgroups((a),(b)))
807 #endif
808 
809 #if defined(HAVE_MMAP) && defined(BROKEN_MMAP)
810 # undef HAVE_MMAP
811 #endif
812 
813 #ifndef IOV_MAX
814 # if defined(_XOPEN_IOV_MAX)
815 #  define	IOV_MAX		_XOPEN_IOV_MAX
816 # elif defined(DEF_IOV_MAX)
817 #  define	IOV_MAX		DEF_IOV_MAX
818 # else
819 #  define	IOV_MAX		16
820 # endif
821 #endif
822 
823 #ifndef EWOULDBLOCK
824 # define EWOULDBLOCK EAGAIN
825 #endif
826 
827 #ifndef INET6_ADDRSTRLEN	/* for non IPv6 machines */
828 #define INET6_ADDRSTRLEN 46
829 #endif
830 
831 #ifndef SSH_IOBUFSZ
832 # define SSH_IOBUFSZ 8192
833 #endif
834 
835 /*
836  * We want functions in openbsd-compat, if enabled, to override system ones.
837  * We no-op out the weak symbol definition rather than remove it to reduce
838  * future sync problems.
839  */
840 #define DEF_WEAK(x)
841 
842 /*
843  * Platforms that have arc4random_uniform() and not arc4random_stir()
844  * shouldn't need the latter.
845  */
846 #if defined(HAVE_ARC4RANDOM) && defined(HAVE_ARC4RANDOM_UNIFORM) && \
847     !defined(HAVE_ARC4RANDOM_STIR)
848 # define arc4random_stir()
849 #endif
850 
851 #ifndef HAVE_VA_COPY
852 # ifdef HAVE___VA_COPY
853 #  define va_copy(dest, src) __va_copy(dest, src)
854 # else
855 #  define va_copy(dest, src) (dest) = (src)
856 # endif
857 #endif
858 
859 #ifndef __predict_true
860 # if defined(__GNUC__) && \
861      ((__GNUC__ > (2)) || (__GNUC__ == (2) && __GNUC_MINOR__ >= (96)))
862 #  define __predict_true(exp)     __builtin_expect(((exp) != 0), 1)
863 #  define __predict_false(exp)    __builtin_expect(((exp) != 0), 0)
864 # else
865 #  define __predict_true(exp)     ((exp) != 0)
866 #  define __predict_false(exp)    ((exp) != 0)
867 # endif /* gcc version */
868 #endif /* __predict_true */
869 
870 #if defined(HAVE_GLOB_H) && defined(GLOB_HAS_ALTDIRFUNC) && \
871     defined(GLOB_HAS_GL_MATCHC) && defined(GLOB_HAS_GL_STATV) && \
872     defined(HAVE_DECL_GLOB_NOMATCH) &&  HAVE_DECL_GLOB_NOMATCH != 0 && \
873     !defined(BROKEN_GLOB)
874 # define USE_SYSTEM_GLOB
875 #endif
876 
877 #endif /* _DEFINES_H */
878