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