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 #ifndef IPTOS_DSCP_LE 100 # define IPTOS_DSCP_LE 0x01 101 #endif /* IPTOS_DSCP_LE */ 102 #ifndef IPTOS_PREC_CRITIC_ECP 103 # define IPTOS_PREC_CRITIC_ECP 0xa0 104 #endif 105 #ifndef IPTOS_PREC_INTERNETCONTROL 106 # define IPTOS_PREC_INTERNETCONTROL 0xc0 107 #endif 108 #ifndef IPTOS_PREC_NETCONTROL 109 # define IPTOS_PREC_NETCONTROL 0xe0 110 #endif 111 112 #ifndef PATH_MAX 113 # ifdef _POSIX_PATH_MAX 114 # define PATH_MAX _POSIX_PATH_MAX 115 # endif 116 #endif 117 118 #ifndef MAXPATHLEN 119 # ifdef PATH_MAX 120 # define MAXPATHLEN PATH_MAX 121 # else /* PATH_MAX */ 122 # define MAXPATHLEN 64 123 # endif /* PATH_MAX */ 124 #endif /* MAXPATHLEN */ 125 126 #ifndef HOST_NAME_MAX 127 # include "netdb.h" /* for MAXHOSTNAMELEN */ 128 # if defined(_POSIX_HOST_NAME_MAX) 129 # define HOST_NAME_MAX _POSIX_HOST_NAME_MAX 130 # elif defined(MAXHOSTNAMELEN) 131 # define HOST_NAME_MAX MAXHOSTNAMELEN 132 # else 133 # define HOST_NAME_MAX 255 134 # endif 135 #endif /* HOST_NAME_MAX */ 136 137 #if defined(HAVE_DECL_MAXSYMLINKS) && HAVE_DECL_MAXSYMLINKS == 0 138 # define MAXSYMLINKS 5 139 #endif 140 141 #ifndef STDIN_FILENO 142 # define STDIN_FILENO 0 143 #endif 144 #ifndef STDOUT_FILENO 145 # define STDOUT_FILENO 1 146 #endif 147 #ifndef STDERR_FILENO 148 # define STDERR_FILENO 2 149 #endif 150 151 #ifndef NGROUPS_MAX /* Disable groupaccess if NGROUP_MAX is not set */ 152 #ifdef NGROUPS 153 #define NGROUPS_MAX NGROUPS 154 #else 155 #define NGROUPS_MAX 0 156 #endif 157 #endif 158 159 #if defined(HAVE_DECL_O_NONBLOCK) && HAVE_DECL_O_NONBLOCK == 0 160 # define O_NONBLOCK 00004 /* Non Blocking Open */ 161 #endif 162 163 #ifndef S_IFSOCK 164 # define S_IFSOCK 0 165 #endif /* S_IFSOCK */ 166 167 #ifndef S_ISDIR 168 # define S_ISDIR(mode) (((mode) & (_S_IFMT)) == (_S_IFDIR)) 169 #endif /* S_ISDIR */ 170 171 #ifndef S_ISREG 172 # define S_ISREG(mode) (((mode) & (_S_IFMT)) == (_S_IFREG)) 173 #endif /* S_ISREG */ 174 175 #ifndef S_ISLNK 176 # define S_ISLNK(mode) (((mode) & S_IFMT) == S_IFLNK) 177 #endif /* S_ISLNK */ 178 179 #ifndef S_IXUSR 180 # define S_IXUSR 0000100 /* execute/search permission, */ 181 # define S_IXGRP 0000010 /* execute/search permission, */ 182 # define S_IXOTH 0000001 /* execute/search permission, */ 183 # define _S_IWUSR 0000200 /* write permission, */ 184 # define S_IWUSR _S_IWUSR /* write permission, owner */ 185 # define S_IWGRP 0000020 /* write permission, group */ 186 # define S_IWOTH 0000002 /* write permission, other */ 187 # define S_IRUSR 0000400 /* read permission, owner */ 188 # define S_IRGRP 0000040 /* read permission, group */ 189 # define S_IROTH 0000004 /* read permission, other */ 190 # define S_IRWXU 0000700 /* read, write, execute */ 191 # define S_IRWXG 0000070 /* read, write, execute */ 192 # define S_IRWXO 0000007 /* read, write, execute */ 193 #endif /* S_IXUSR */ 194 195 #if !defined(MAP_ANON) && defined(MAP_ANONYMOUS) 196 #define MAP_ANON MAP_ANONYMOUS 197 #endif 198 199 #ifndef MAP_FAILED 200 # define MAP_FAILED ((void *)-1) 201 #endif 202 203 /* 204 SCO Open Server 3 has INADDR_LOOPBACK defined in rpc/rpc.h but 205 including rpc/rpc.h breaks Solaris 6 206 */ 207 #ifndef INADDR_LOOPBACK 208 #define INADDR_LOOPBACK ((u_long)0x7f000001) 209 #endif 210 211 /* Types */ 212 213 /* If sys/types.h does not supply intXX_t, supply them ourselves */ 214 /* (or die trying) */ 215 216 #ifndef HAVE_U_INT 217 typedef unsigned int u_int; 218 #endif 219 220 #ifndef HAVE_INTXX_T 221 typedef signed char int8_t; 222 # if (SIZEOF_SHORT_INT == 2) 223 typedef short int int16_t; 224 # else 225 # error "16 bit int type not found." 226 # endif 227 # if (SIZEOF_INT == 4) 228 typedef int int32_t; 229 # else 230 # error "32 bit int type not found." 231 # endif 232 #endif 233 234 /* If sys/types.h does not supply u_intXX_t, supply them ourselves */ 235 #ifndef HAVE_U_INTXX_T 236 # ifdef HAVE_UINTXX_T 237 typedef uint8_t u_int8_t; 238 typedef uint16_t u_int16_t; 239 typedef uint32_t u_int32_t; 240 # define HAVE_U_INTXX_T 1 241 # else 242 typedef unsigned char u_int8_t; 243 # if (SIZEOF_SHORT_INT == 2) 244 typedef unsigned short int u_int16_t; 245 # else 246 # error "16 bit int type not found." 247 # endif 248 # if (SIZEOF_INT == 4) 249 typedef unsigned int u_int32_t; 250 # else 251 # error "32 bit int type not found." 252 # endif 253 # endif 254 #define __BIT_TYPES_DEFINED__ 255 #endif 256 257 #if !defined(LLONG_MIN) && defined(LONG_LONG_MIN) 258 #define LLONG_MIN LONG_LONG_MIN 259 #endif 260 #if !defined(LLONG_MAX) && defined(LONG_LONG_MAX) 261 #define LLONG_MAX LONG_LONG_MAX 262 #endif 263 264 #ifndef UINT32_MAX 265 # if defined(HAVE_DECL_UINT32_MAX) && (HAVE_DECL_UINT32_MAX == 0) 266 # if (SIZEOF_INT == 4) 267 # define UINT32_MAX UINT_MAX 268 # endif 269 # endif 270 #endif 271 272 /* 64-bit types */ 273 #ifndef HAVE_INT64_T 274 # if (SIZEOF_LONG_INT == 8) 275 typedef long int int64_t; 276 # else 277 # if (SIZEOF_LONG_LONG_INT == 8) 278 typedef long long int int64_t; 279 # endif 280 # endif 281 #endif 282 #ifndef HAVE_U_INT64_T 283 # if (SIZEOF_LONG_INT == 8) 284 typedef unsigned long int u_int64_t; 285 # else 286 # if (SIZEOF_LONG_LONG_INT == 8) 287 typedef unsigned long long int u_int64_t; 288 # endif 289 # endif 290 #endif 291 292 #ifndef HAVE_UINTXX_T 293 typedef u_int8_t uint8_t; 294 typedef u_int16_t uint16_t; 295 typedef u_int32_t uint32_t; 296 typedef u_int64_t uint64_t; 297 #endif 298 299 #ifndef HAVE_INTMAX_T 300 typedef long long intmax_t; 301 #endif 302 303 #ifndef HAVE_UINTMAX_T 304 typedef unsigned long long uintmax_t; 305 #endif 306 307 #if SIZEOF_TIME_T == SIZEOF_LONG_LONG_INT 308 # define SSH_TIME_T_MAX LLONG_MAX 309 #else 310 # define SSH_TIME_T_MAX INT_MAX 311 #endif 312 313 #ifndef HAVE_U_CHAR 314 typedef unsigned char u_char; 315 # define HAVE_U_CHAR 316 #endif /* HAVE_U_CHAR */ 317 318 #ifndef ULLONG_MAX 319 # define ULLONG_MAX ((unsigned long long)-1) 320 #endif 321 322 #ifndef SIZE_T_MAX 323 #define SIZE_T_MAX ULONG_MAX 324 #endif /* SIZE_T_MAX */ 325 326 #ifndef HAVE_SIZE_T 327 typedef unsigned int size_t; 328 # define HAVE_SIZE_T 329 # define SIZE_T_MAX UINT_MAX 330 #endif /* HAVE_SIZE_T */ 331 332 #ifndef SIZE_MAX 333 #define SIZE_MAX SIZE_T_MAX 334 #endif 335 336 #ifndef INT32_MAX 337 # if (SIZEOF_INT == 4) 338 # define INT32_MAX INT_MAX 339 # elif (SIZEOF_LONG == 4) 340 # define INT32_MAX LONG_MAX 341 # else 342 # error "need INT32_MAX" 343 # endif 344 #endif 345 346 #ifndef INT64_MAX 347 # if (SIZEOF_INT == 8) 348 # define INT64_MAX INT_MAX 349 # elif (SIZEOF_LONG == 8) 350 # define INT64_MAX LONG_MAX 351 # elif (SIZEOF_LONG_LONG_INT == 8) 352 # define INT64_MAX LLONG_MAX 353 # else 354 # error "need INT64_MAX" 355 # endif 356 #endif 357 358 #ifndef HAVE_SSIZE_T 359 typedef int ssize_t; 360 #define SSIZE_MAX INT_MAX 361 # define HAVE_SSIZE_T 362 #endif /* HAVE_SSIZE_T */ 363 364 #ifndef HAVE_CLOCK_T 365 typedef long clock_t; 366 # define HAVE_CLOCK_T 367 #endif /* HAVE_CLOCK_T */ 368 369 #ifndef HAVE_SA_FAMILY_T 370 typedef int sa_family_t; 371 # define HAVE_SA_FAMILY_T 372 #endif /* HAVE_SA_FAMILY_T */ 373 374 #ifndef HAVE_PID_T 375 typedef int pid_t; 376 # define HAVE_PID_T 377 #endif /* HAVE_PID_T */ 378 379 #ifndef HAVE_SIG_ATOMIC_T 380 typedef int sig_atomic_t; 381 # define HAVE_SIG_ATOMIC_T 382 #endif /* HAVE_SIG_ATOMIC_T */ 383 384 #ifndef HAVE_MODE_T 385 typedef int mode_t; 386 # define HAVE_MODE_T 387 #endif /* HAVE_MODE_T */ 388 389 #if !defined(HAVE_SS_FAMILY_IN_SS) && defined(HAVE___SS_FAMILY_IN_SS) 390 # define ss_family __ss_family 391 #endif /* !defined(HAVE_SS_FAMILY_IN_SS) && defined(HAVE_SA_FAMILY_IN_SS) */ 392 393 #ifndef HAVE_SYS_UN_H 394 struct sockaddr_un { 395 short sun_family; /* AF_UNIX */ 396 char sun_path[108]; /* path name (gag) */ 397 }; 398 #endif /* HAVE_SYS_UN_H */ 399 400 #ifndef HAVE_IN_ADDR_T 401 typedef u_int32_t in_addr_t; 402 #endif 403 #ifndef HAVE_IN_PORT_T 404 typedef u_int16_t in_port_t; 405 #endif 406 407 #if defined(BROKEN_SYS_TERMIO_H) && !defined(_STRUCT_WINSIZE) 408 #define _STRUCT_WINSIZE 409 struct winsize { 410 unsigned short ws_row; /* rows, in characters */ 411 unsigned short ws_col; /* columns, in character */ 412 unsigned short ws_xpixel; /* horizontal size, pixels */ 413 unsigned short ws_ypixel; /* vertical size, pixels */ 414 }; 415 #endif 416 417 /* bits needed for select that may not be in the system headers */ 418 #ifndef HAVE_FD_MASK 419 typedef unsigned long int fd_mask; 420 #endif 421 422 #if defined(HAVE_DECL_NFDBITS) && HAVE_DECL_NFDBITS == 0 423 # define NFDBITS (8 * sizeof(unsigned long)) 424 #endif 425 426 #if defined(HAVE_DECL_HOWMANY) && HAVE_DECL_HOWMANY == 0 427 # define howmany(x,y) (((x)+((y)-1))/(y)) 428 #endif 429 430 /* Paths */ 431 432 #ifndef _PATH_BSHELL 433 # define _PATH_BSHELL "/bin/sh" 434 #endif 435 436 #ifdef USER_PATH 437 # ifdef _PATH_STDPATH 438 # undef _PATH_STDPATH 439 # endif 440 # define _PATH_STDPATH USER_PATH 441 #endif 442 443 #ifndef _PATH_STDPATH 444 # define _PATH_STDPATH "/usr/bin:/bin:/usr/sbin:/sbin" 445 #endif 446 447 #ifndef SUPERUSER_PATH 448 # define SUPERUSER_PATH _PATH_STDPATH 449 #endif 450 451 #ifndef _PATH_DEVNULL 452 # define _PATH_DEVNULL "/dev/null" 453 #endif 454 455 /* user may have set a different path */ 456 #if defined(_PATH_MAILDIR) && defined(MAIL_DIRECTORY) 457 # undef _PATH_MAILDIR 458 #endif /* defined(_PATH_MAILDIR) && defined(MAIL_DIRECTORY) */ 459 460 #ifdef MAIL_DIRECTORY 461 # define _PATH_MAILDIR MAIL_DIRECTORY 462 #endif 463 464 #ifndef _PATH_NOLOGIN 465 # define _PATH_NOLOGIN "/etc/nologin" 466 #endif 467 468 /* Define this to be the path of the xauth program. */ 469 #ifdef XAUTH_PATH 470 #define _PATH_XAUTH XAUTH_PATH 471 #endif /* XAUTH_PATH */ 472 473 /* derived from XF4/xc/lib/dps/Xlibnet.h */ 474 #ifndef X_UNIX_PATH 475 # ifdef __hpux 476 # define X_UNIX_PATH "/var/spool/sockets/X11/%u" 477 # else 478 # define X_UNIX_PATH "/tmp/.X11-unix/X%u" 479 # endif 480 #endif /* X_UNIX_PATH */ 481 #define _PATH_UNIX_X X_UNIX_PATH 482 483 #ifndef _PATH_TTY 484 # define _PATH_TTY "/dev/tty" 485 #endif 486 487 /* Macros */ 488 489 #if defined(HAVE_LOGIN_GETCAPBOOL) && defined(HAVE_LOGIN_CAP_H) 490 # define HAVE_LOGIN_CAP 491 #endif 492 493 #ifndef MAX 494 # define MAX(a,b) (((a)>(b))?(a):(b)) 495 # define MIN(a,b) (((a)<(b))?(a):(b)) 496 #endif 497 498 #ifndef roundup 499 # define roundup(x, y) ((((x)+((y)-1))/(y))*(y)) 500 #endif 501 502 #ifndef timersub 503 #define timersub(a, b, result) \ 504 do { \ 505 (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \ 506 (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \ 507 if ((result)->tv_usec < 0) { \ 508 --(result)->tv_sec; \ 509 (result)->tv_usec += 1000000; \ 510 } \ 511 } while (0) 512 #endif 513 514 #ifndef TIMEVAL_TO_TIMESPEC 515 #define TIMEVAL_TO_TIMESPEC(tv, ts) { \ 516 (ts)->tv_sec = (tv)->tv_sec; \ 517 (ts)->tv_nsec = (tv)->tv_usec * 1000; \ 518 } 519 #endif 520 521 #ifndef TIMESPEC_TO_TIMEVAL 522 #define TIMESPEC_TO_TIMEVAL(tv, ts) { \ 523 (tv)->tv_sec = (ts)->tv_sec; \ 524 (tv)->tv_usec = (ts)->tv_nsec / 1000; \ 525 } 526 #endif 527 528 #ifndef timespeccmp 529 #define timespeccmp(tsp, usp, cmp) \ 530 (((tsp)->tv_sec == (usp)->tv_sec) ? \ 531 ((tsp)->tv_nsec cmp (usp)->tv_nsec) : \ 532 ((tsp)->tv_sec cmp (usp)->tv_sec)) 533 #endif 534 535 #ifndef __P 536 # define __P(x) x 537 #endif 538 539 #if !defined(IN6_IS_ADDR_V4MAPPED) 540 # define IN6_IS_ADDR_V4MAPPED(a) \ 541 ((((u_int32_t *) (a))[0] == 0) && (((u_int32_t *) (a))[1] == 0) && \ 542 (((u_int32_t *) (a))[2] == htonl (0xffff))) 543 #endif /* !defined(IN6_IS_ADDR_V4MAPPED) */ 544 545 #if !defined(__GNUC__) || (__GNUC__ < 2) 546 # define __attribute__(x) 547 #endif /* !defined(__GNUC__) || (__GNUC__ < 2) */ 548 549 #if !defined(HAVE_ATTRIBUTE__SENTINEL__) && !defined(__sentinel__) 550 # define __sentinel__ 551 #endif 552 553 #if !defined(HAVE_ATTRIBUTE__BOUNDED__) && !defined(__bounded__) 554 # define __bounded__(x, y, z) 555 #endif 556 557 #if !defined(HAVE_ATTRIBUTE__NONNULL__) && !defined(__nonnull__) 558 # define __nonnull__(x) 559 #endif 560 561 #ifndef OSSH_ALIGNBYTES 562 #define OSSH_ALIGNBYTES (sizeof(int) - 1) 563 #endif 564 #ifndef __CMSG_ALIGN 565 #define __CMSG_ALIGN(p) (((u_int)(p) + OSSH_ALIGNBYTES) &~ OSSH_ALIGNBYTES) 566 #endif 567 568 /* Length of the contents of a control message of length len */ 569 #ifndef CMSG_LEN 570 #define CMSG_LEN(len) (__CMSG_ALIGN(sizeof(struct cmsghdr)) + (len)) 571 #endif 572 573 /* Length of the space taken up by a padded control message of length len */ 574 #ifndef CMSG_SPACE 575 #define CMSG_SPACE(len) (__CMSG_ALIGN(sizeof(struct cmsghdr)) + __CMSG_ALIGN(len)) 576 #endif 577 578 /* given pointer to struct cmsghdr, return pointer to data */ 579 #ifndef CMSG_DATA 580 #define CMSG_DATA(cmsg) ((u_char *)(cmsg) + __CMSG_ALIGN(sizeof(struct cmsghdr))) 581 #endif /* CMSG_DATA */ 582 583 /* 584 * RFC 2292 requires to check msg_controllen, in case that the kernel returns 585 * an empty list for some reasons. 586 */ 587 #ifndef CMSG_FIRSTHDR 588 #define CMSG_FIRSTHDR(mhdr) \ 589 ((mhdr)->msg_controllen >= sizeof(struct cmsghdr) ? \ 590 (struct cmsghdr *)(mhdr)->msg_control : \ 591 (struct cmsghdr *)NULL) 592 #endif /* CMSG_FIRSTHDR */ 593 594 #if defined(HAVE_DECL_OFFSETOF) && HAVE_DECL_OFFSETOF == 0 595 # define offsetof(type, member) ((size_t) &((type *)0)->member) 596 #endif 597 598 /* Set up BSD-style BYTE_ORDER definition if it isn't there already */ 599 /* XXX: doesn't try to cope with strange byte orders (PDP_ENDIAN) */ 600 #ifndef BYTE_ORDER 601 # ifndef LITTLE_ENDIAN 602 # define LITTLE_ENDIAN 1234 603 # endif /* LITTLE_ENDIAN */ 604 # ifndef BIG_ENDIAN 605 # define BIG_ENDIAN 4321 606 # endif /* BIG_ENDIAN */ 607 # ifdef WORDS_BIGENDIAN 608 # define BYTE_ORDER BIG_ENDIAN 609 # else /* WORDS_BIGENDIAN */ 610 # define BYTE_ORDER LITTLE_ENDIAN 611 # endif /* WORDS_BIGENDIAN */ 612 #endif /* BYTE_ORDER */ 613 614 /* Function replacement / compatibility hacks */ 615 616 #if !defined(HAVE_GETADDRINFO) && (defined(HAVE_OGETADDRINFO) || defined(HAVE_NGETADDRINFO)) 617 # define HAVE_GETADDRINFO 618 #endif 619 620 #ifndef HAVE_GETOPT_OPTRESET 621 # undef getopt 622 # undef opterr 623 # undef optind 624 # undef optopt 625 # undef optreset 626 # undef optarg 627 # define getopt(ac, av, o) BSDgetopt(ac, av, o) 628 # define opterr BSDopterr 629 # define optind BSDoptind 630 # define optopt BSDoptopt 631 # define optreset BSDoptreset 632 # define optarg BSDoptarg 633 #endif 634 635 #if defined(BROKEN_GETADDRINFO) && defined(HAVE_GETADDRINFO) 636 # undef HAVE_GETADDRINFO 637 #endif 638 #if defined(BROKEN_GETADDRINFO) && defined(HAVE_FREEADDRINFO) 639 # undef HAVE_FREEADDRINFO 640 #endif 641 #if defined(BROKEN_GETADDRINFO) && defined(HAVE_GAI_STRERROR) 642 # undef HAVE_GAI_STRERROR 643 #endif 644 645 #if defined(HAVE_GETADDRINFO) 646 # if defined(HAVE_DECL_AI_NUMERICSERV) && HAVE_DECL_AI_NUMERICSERV == 0 647 # define AI_NUMERICSERV 0 648 # endif 649 #endif 650 651 #if defined(BROKEN_UPDWTMPX) && defined(HAVE_UPDWTMPX) 652 # undef HAVE_UPDWTMPX 653 #endif 654 655 #if defined(BROKEN_SHADOW_EXPIRE) && defined(HAS_SHADOW_EXPIRE) 656 # undef HAS_SHADOW_EXPIRE 657 #endif 658 659 #if defined(HAVE_OPENLOG_R) && defined(SYSLOG_DATA_INIT) && \ 660 defined(SYSLOG_R_SAFE_IN_SIGHAND) 661 # define DO_LOG_SAFE_IN_SIGHAND 662 #endif 663 664 #if !defined(HAVE_MEMMOVE) && defined(HAVE_BCOPY) 665 # define memmove(s1, s2, n) bcopy((s2), (s1), (n)) 666 #endif /* !defined(HAVE_MEMMOVE) && defined(HAVE_BCOPY) */ 667 668 #ifndef GETPGRP_VOID 669 # include <unistd.h> 670 # define getpgrp() getpgrp(0) 671 #endif 672 673 #ifdef USE_BSM_AUDIT 674 # define SSH_AUDIT_EVENTS 675 # define CUSTOM_SSH_AUDIT_EVENTS 676 #endif 677 678 #ifdef USE_LINUX_AUDIT 679 # define SSH_AUDIT_EVENTS 680 # define CUSTOM_SSH_AUDIT_EVENTS 681 #endif 682 683 #if !defined(HAVE___func__) && defined(HAVE___FUNCTION__) 684 # define __func__ __FUNCTION__ 685 #elif !defined(HAVE___func__) 686 # define __func__ "" 687 #endif 688 689 #if defined(KRB5) && !defined(HEIMDAL) 690 # define krb5_get_err_text(context,code) error_message(code) 691 #endif 692 693 /* Maximum number of file descriptors available */ 694 #ifdef HAVE_SYSCONF 695 # define SSH_SYSFDMAX sysconf(_SC_OPEN_MAX) 696 #else 697 # define SSH_SYSFDMAX 10000 698 #endif 699 700 #ifdef FSID_HAS_VAL 701 /* encode f_fsid into a 64 bit value */ 702 #define FSID_TO_ULONG(f) \ 703 ((((u_int64_t)(f).val[0] & 0xffffffffUL) << 32) | \ 704 ((f).val[1] & 0xffffffffUL)) 705 #elif defined(FSID_HAS___VAL) 706 #define FSID_TO_ULONG(f) \ 707 ((((u_int64_t)(f).__val[0] & 0xffffffffUL) << 32) | \ 708 ((f).__val[1] & 0xffffffffUL)) 709 #else 710 # define FSID_TO_ULONG(f) ((f)) 711 #endif 712 713 #if defined(__Lynx__) 714 /* 715 * LynxOS defines these in param.h which we do not want to include since 716 * it will also pull in a bunch of kernel definitions. 717 */ 718 # define ALIGNBYTES (sizeof(int) - 1) 719 # define ALIGN(p) (((unsigned)p + ALIGNBYTES) & ~ALIGNBYTES) 720 /* Missing prototypes on LynxOS */ 721 int snprintf (char *, size_t, const char *, ...); 722 int mkstemp (char *); 723 char *crypt (const char *, const char *); 724 int seteuid (uid_t); 725 int setegid (gid_t); 726 char *mkdtemp (char *); 727 int rresvport_af (int *, sa_family_t); 728 int innetgr (const char *, const char *, const char *, const char *); 729 #endif 730 731 /* 732 * Define this to use pipes instead of socketpairs for communicating with the 733 * client program. Socketpairs do not seem to work on all systems. 734 * 735 * configure.ac sets this for a few OS's which are known to have problems 736 * but you may need to set it yourself 737 */ 738 /* #define USE_PIPES 1 */ 739 740 /** 741 ** login recorder definitions 742 **/ 743 744 /* FIXME: put default paths back in */ 745 #ifndef UTMP_FILE 746 # ifdef _PATH_UTMP 747 # define UTMP_FILE _PATH_UTMP 748 # else 749 # ifdef CONF_UTMP_FILE 750 # define UTMP_FILE CONF_UTMP_FILE 751 # endif 752 # endif 753 #endif 754 #ifndef WTMP_FILE 755 # ifdef _PATH_WTMP 756 # define WTMP_FILE _PATH_WTMP 757 # else 758 # ifdef CONF_WTMP_FILE 759 # define WTMP_FILE CONF_WTMP_FILE 760 # endif 761 # endif 762 #endif 763 /* pick up the user's location for lastlog if given */ 764 #ifndef LASTLOG_FILE 765 # ifdef _PATH_LASTLOG 766 # define LASTLOG_FILE _PATH_LASTLOG 767 # else 768 # ifdef CONF_LASTLOG_FILE 769 # define LASTLOG_FILE CONF_LASTLOG_FILE 770 # endif 771 # endif 772 #endif 773 774 #if defined(HAVE_SHADOW_H) && !defined(DISABLE_SHADOW) 775 # define USE_SHADOW 776 #endif 777 778 /* The login() library function in libutil is first choice */ 779 #if defined(HAVE_LOGIN) && !defined(DISABLE_LOGIN) 780 # define USE_LOGIN 781 782 #else 783 /* Simply select your favourite login types. */ 784 /* Can't do if-else because some systems use several... <sigh> */ 785 # if !defined(DISABLE_UTMPX) 786 # define USE_UTMPX 787 # endif 788 # if defined(UTMP_FILE) && !defined(DISABLE_UTMP) 789 # define USE_UTMP 790 # endif 791 # if defined(WTMPX_FILE) && !defined(DISABLE_WTMPX) 792 # define USE_WTMPX 793 # endif 794 # if defined(WTMP_FILE) && !defined(DISABLE_WTMP) 795 # define USE_WTMP 796 # endif 797 798 #endif 799 800 #ifndef UT_LINESIZE 801 # define UT_LINESIZE 8 802 #endif 803 804 /* I hope that the presence of LASTLOG_FILE is enough to detect this */ 805 #if defined(LASTLOG_FILE) && !defined(DISABLE_LASTLOG) 806 # define USE_LASTLOG 807 #endif 808 809 #ifdef HAVE_OSF_SIA 810 # ifdef USE_SHADOW 811 # undef USE_SHADOW 812 # endif 813 # define CUSTOM_SYS_AUTH_PASSWD 1 814 #endif 815 816 #if defined(HAVE_LIBIAF) && defined(HAVE_SET_ID) && !defined(HAVE_SECUREWARE) 817 # define CUSTOM_SYS_AUTH_PASSWD 1 818 #endif 819 #if defined(HAVE_LIBIAF) && defined(HAVE_SET_ID) && !defined(BROKEN_LIBIAF) 820 # define USE_LIBIAF 821 #endif 822 823 /* HP-UX 11.11 */ 824 #ifdef BTMP_FILE 825 # define _PATH_BTMP BTMP_FILE 826 #endif 827 828 #if defined(USE_BTMP) && defined(_PATH_BTMP) 829 # define CUSTOM_FAILED_LOGIN 830 #endif 831 832 /** end of login recorder definitions */ 833 834 #ifdef BROKEN_GETGROUPS 835 # define getgroups(a,b) ((a)==0 && (b)==NULL ? NGROUPS_MAX : getgroups((a),(b))) 836 #endif 837 838 #ifndef IOV_MAX 839 # if defined(_XOPEN_IOV_MAX) 840 # define IOV_MAX _XOPEN_IOV_MAX 841 # elif defined(DEF_IOV_MAX) 842 # define IOV_MAX DEF_IOV_MAX 843 # else 844 # define IOV_MAX 16 845 # endif 846 #endif 847 848 #ifndef EWOULDBLOCK 849 # define EWOULDBLOCK EAGAIN 850 #endif 851 852 #ifndef INET6_ADDRSTRLEN /* for non IPv6 machines */ 853 #define INET6_ADDRSTRLEN 46 854 #endif 855 856 #ifndef SSH_IOBUFSZ 857 # define SSH_IOBUFSZ 8192 858 #endif 859 860 /* 861 * We want functions in openbsd-compat, if enabled, to override system ones. 862 * We no-op out the weak symbol definition rather than remove it to reduce 863 * future sync problems. Some compilers (eg Unixware) do not allow an 864 * empty statement, so we use a bogus function declaration. 865 */ 866 #define DEF_WEAK(x) void __ssh_compat_weak_##x(void) 867 868 /* 869 * Platforms that have arc4random_uniform() and not arc4random_stir() 870 * shouldn't need the latter. 871 */ 872 #if defined(HAVE_ARC4RANDOM) && defined(HAVE_ARC4RANDOM_UNIFORM) && \ 873 !defined(HAVE_ARC4RANDOM_STIR) 874 # define arc4random_stir() 875 #endif 876 877 #ifndef HAVE_VA_COPY 878 # ifdef HAVE___VA_COPY 879 # define va_copy(dest, src) __va_copy(dest, src) 880 # else 881 # define va_copy(dest, src) (dest) = (src) 882 # endif 883 #endif 884 885 #ifndef __predict_true 886 # if defined(__GNUC__) && \ 887 ((__GNUC__ > (2)) || (__GNUC__ == (2) && __GNUC_MINOR__ >= (96))) 888 # define __predict_true(exp) __builtin_expect(((exp) != 0), 1) 889 # define __predict_false(exp) __builtin_expect(((exp) != 0), 0) 890 # else 891 # define __predict_true(exp) ((exp) != 0) 892 # define __predict_false(exp) ((exp) != 0) 893 # endif /* gcc version */ 894 #endif /* __predict_true */ 895 896 #if defined(HAVE_GLOB_H) && defined(GLOB_HAS_ALTDIRFUNC) && \ 897 defined(GLOB_HAS_GL_MATCHC) && defined(GLOB_HAS_GL_STATV) && \ 898 defined(HAVE_DECL_GLOB_NOMATCH) && HAVE_DECL_GLOB_NOMATCH != 0 && \ 899 !defined(BROKEN_GLOB) 900 # define USE_SYSTEM_GLOB 901 #endif 902 903 /* 904 * sntrup761 uses variable length arrays and c99-style declarations after code, 905 * so only enable if the compiler supports them. 906 */ 907 #if defined(VARIABLE_LENGTH_ARRAYS) && defined(VARIABLE_DECLARATION_AFTER_CODE) 908 # define USE_SNTRUP761X25519 1 909 #endif 910 #endif /* _DEFINES_H */ 911