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 * Copyright 2010 Sun Microsystems, Inc. All rights reserved. 26 * Use is subject to license terms. 27 */ 28 29 #ifndef _DEFINES_H 30 #define _DEFINES_H 31 32 #ifdef __cplusplus 33 extern "C" { 34 #endif 35 36 /* $Id: defines.h,v 1.96 2002/09/26 00:38:48 tim Exp $ */ 37 38 39 /* Constants */ 40 #ifndef SHUT_RDWR 41 enum 42 { 43 SHUT_RD = 0, /* No more receptions. */ 44 SHUT_WR, /* No more transmissions. */ 45 SHUT_RDWR /* No more receptions or transmissions. */ 46 }; 47 #define SHUT_RD SHUT_RD 48 #define SHUT_WR SHUT_WR 49 #define SHUT_RDWR SHUT_RDWR 50 #endif 51 52 #ifndef IPTOS_LOWDELAY 53 #define IPTOS_LOWDELAY 0x10 54 #define IPTOS_THROUGHPUT 0x08 55 #define IPTOS_RELIABILITY 0x04 56 #define IPTOS_LOWCOST 0x02 57 #define IPTOS_MINCOST IPTOS_LOWCOST 58 #endif /* IPTOS_LOWDELAY */ 59 60 #ifndef MAXPATHLEN 61 #ifdef PATH_MAX 62 #define MAXPATHLEN PATH_MAX 63 #else /* PATH_MAX */ 64 #define MAXPATHLEN 64 /* Should be safe */ 65 #endif /* PATH_MAX */ 66 #endif /* MAXPATHLEN */ 67 68 #ifndef STDIN_FILENO 69 #define STDIN_FILENO 0 70 #endif 71 72 #ifndef STDOUT_FILENO 73 #define STDOUT_FILENO 1 74 #endif 75 76 #ifndef STDERR_FILENO 77 #define STDERR_FILENO 2 78 #endif 79 80 /* Disable groupaccess if NGROUPS_UMAX, NGROUPS_MAX and NGROUPS are not set */ 81 #ifndef NGROUPS_UMAX 82 #ifdef NGROUPS_MAX 83 #define NGROUPS_UMAX NGROUPS_MAX 84 #elif defined(NGROUPS) 85 #define NGROUPS_UMAX NGROUPS 86 #else 87 #define NGROUPS_UMAX 0 88 #endif 89 #endif 90 91 #ifndef O_NONBLOCK /* Non Blocking Open */ 92 #define O_NONBLOCK 00004 93 #endif 94 95 #ifndef S_ISDIR 96 #define S_ISDIR(mode) (((mode) & (_S_IFMT)) == (_S_IFDIR)) 97 #endif /* S_ISDIR */ 98 99 #ifndef S_ISREG 100 #define S_ISREG(mode) (((mode) & (_S_IFMT)) == (_S_IFREG)) 101 #endif /* S_ISREG */ 102 103 #ifndef S_ISLNK 104 #define S_ISLNK(mode) (((mode) & S_IFMT) == S_IFLNK) 105 #endif /* S_ISLNK */ 106 107 #ifndef S_IXUSR 108 #define S_IXUSR 0000100 /* execute/search permission, */ 109 #define S_IXGRP 0000010 /* execute/search permission, */ 110 #define S_IXOTH 0000001 /* execute/search permission, */ 111 #define _S_IWUSR 0000200 /* write permission, */ 112 #define S_IWUSR _S_IWUSR /* write permission, owner */ 113 #define S_IWGRP 0000020 /* write permission, group */ 114 #define S_IWOTH 0000002 /* write permission, other */ 115 #define S_IRUSR 0000400 /* read permission, owner */ 116 #define S_IRGRP 0000040 /* read permission, group */ 117 #define S_IROTH 0000004 /* read permission, other */ 118 #define S_IRWXU 0000700 /* read, write, execute */ 119 #define S_IRWXG 0000070 /* read, write, execute */ 120 #define S_IRWXO 0000007 /* read, write, execute */ 121 #endif /* S_IXUSR */ 122 123 #if !defined(MAP_ANON) && defined(MAP_ANONYMOUS) 124 #define MAP_ANON MAP_ANONYMOUS 125 #endif 126 127 #ifndef MAP_FAILED 128 #define MAP_FAILED ((void *)-1) 129 #endif 130 131 /* *-*-nto-qnx doesn't define this constant in the system headers */ 132 #ifdef MISSING_NFDBITS 133 #define NFDBITS (8 * sizeof (unsigned long)) 134 #endif 135 136 /* 137 * SCO Open Server 3 has INADDR_LOOPBACK defined in rpc/rpc.h but including 138 * rpc/rpc.h breaks Solaris 6 139 */ 140 #ifndef INADDR_LOOPBACK 141 #define INADDR_LOOPBACK ((ulong_t)0x7f000001) 142 #endif 143 144 /* Types */ 145 146 /* 147 * If sys/types.h does not supply intXX_t, supply them ourselves (or die trying) 148 */ 149 #ifndef HAVE_U_INT 150 /* for now, we can't remove u_int without changing almost all other files */ 151 /* CSTYLED */ 152 typedef unsigned int u_int; 153 #endif 154 155 #ifndef HAVE_INTXX_T 156 #if (SIZEOF_CHAR == 1) 157 typedef char int8_t; 158 #else 159 #error "8 bit int type not found." 160 #endif 161 #if (SIZEOF_SHORT_INT == 2) 162 typedef short int int16_t; 163 #else 164 #ifdef _UNICOS 165 #if (SIZEOF_SHORT_INT == 4) 166 typedef short int16_t; 167 #else 168 typedef long int16_t; 169 #endif 170 #else 171 #error "16 bit int type not found." 172 #endif /* _UNICOS */ 173 #endif 174 #if (SIZEOF_INT == 4) 175 typedef int int32_t; 176 #else 177 #ifdef _UNICOS 178 typedef long int32_t; 179 #else 180 #error "32 bit int type not found." 181 #endif /* _UNICOS */ 182 #endif 183 #endif 184 185 /* If sys/types.h does not supply u_intXX_t, supply them ourselves */ 186 #ifndef HAVE_U_INTXX_T 187 #ifdef HAVE_UINTXX_T 188 typedef uint8_t u_int8_t; 189 typedef uint16_t u_int16_t; 190 typedef uint32_t u_int32_t; 191 #define HAVE_U_INTXX_T 1 192 #else 193 #if (SIZEOF_CHAR == 1) 194 typedef unsigned char u_int8_t; 195 #else 196 #error "8 bit int type not found." 197 #endif 198 #if (SIZEOF_SHORT_INT == 2) 199 typedef unsigned short int u_int16_t; 200 #else 201 #ifdef _UNICOS 202 #if (SIZEOF_SHORT_INT == 4) 203 typedef unsigned short u_int16_t; 204 #else 205 typedef unsigned long u_int16_t; 206 #endif 207 #else 208 #error "16 bit int type not found." 209 #endif 210 #endif 211 #if (SIZEOF_INT == 4) 212 typedef unsigned int u_int32_t; 213 #else 214 #ifdef _UNICOS 215 typedef unsigned long u_int32_t; 216 #else 217 #error "32 bit int type not found." 218 #endif 219 #endif 220 #endif 221 #define __BIT_TYPES_DEFINED__ 222 #endif 223 224 /* 64-bit types */ 225 #ifndef HAVE_INT64_T 226 #if (SIZEOF_LONG_INT == 8) 227 typedef long int int64_t; 228 #define HAVE_INT64_T 1 229 #else 230 #if (SIZEOF_LONG_LONG_INT == 8) 231 typedef long long int int64_t; 232 #define HAVE_INT64_T 1 233 #endif 234 #endif 235 #endif 236 237 #ifndef HAVE_U_INT64_T 238 #if (SIZEOF_LONG_INT == 8) 239 typedef unsigned long int u_int64_t; 240 #define HAVE_U_INT64_T 1 241 #else 242 #if (SIZEOF_LONG_LONG_INT == 8) 243 typedef unsigned long long int u_int64_t; 244 #define HAVE_U_INT64_T 1 245 #endif 246 #endif 247 #endif 248 249 #if !defined(HAVE_LONG_LONG_INT) && (SIZEOF_LONG_LONG_INT == 8) 250 #define HAVE_LONG_LONG_INT 1 251 #endif 252 253 #ifndef HAVE_U_CHAR 254 /* for now, we can't remove u_char without changing almost all other files */ 255 /* CSTYLED */ 256 typedef unsigned char u_char; 257 #define HAVE_U_CHAR 258 #endif /* HAVE_U_CHAR */ 259 260 #ifndef SIZE_T_MAX 261 #define SIZE_T_MAX ULONG_MAX 262 #endif /* SIZE_T_MAX */ 263 264 #ifndef HAVE_SIZE_T 265 typedef unsigned int size_t; 266 #define HAVE_SIZE_T 267 #endif /* HAVE_SIZE_T */ 268 269 #ifndef HAVE_SSIZE_T 270 typedef int ssize_t; 271 #define HAVE_SSIZE_T 272 #endif /* HAVE_SSIZE_T */ 273 274 #ifndef HAVE_CLOCK_T 275 typedef long clock_t; 276 #define HAVE_CLOCK_T 277 #endif /* HAVE_CLOCK_T */ 278 279 #ifndef HAVE_SA_FAMILY_T 280 typedef int sa_family_t; 281 #define HAVE_SA_FAMILY_T 282 #endif /* HAVE_SA_FAMILY_T */ 283 284 #ifndef HAVE_PID_T 285 typedef int pid_t; 286 #define HAVE_PID_T 287 #endif /* HAVE_PID_T */ 288 289 #ifndef HAVE_SIG_ATOMIC_T 290 typedef int sig_atomic_t; 291 #define HAVE_SIG_ATOMIC_T 292 #endif /* HAVE_SIG_ATOMIC_T */ 293 294 #ifndef HAVE_MODE_T 295 typedef int mode_t; 296 #define HAVE_MODE_T 297 #endif /* HAVE_MODE_T */ 298 299 #if !defined(HAVE_SS_FAMILY_IN_SS) && defined(HAVE___SS_FAMILY_IN_SS) 300 #define ss_family __ss_family 301 #endif /* !defined(HAVE_SS_FAMILY_IN_SS) && defined(HAVE_SA_FAMILY_IN_SS) */ 302 303 #ifndef HAVE_SYS_UN_H 304 struct sockaddr_un { 305 short sun_family; /* AF_UNIX */ 306 char sun_path[108]; /* path name (gag) */ 307 }; 308 #endif /* HAVE_SYS_UN_H */ 309 310 #if defined(BROKEN_SYS_TERMIO_H) && !defined(_STRUCT_WINSIZE) 311 #define _STRUCT_WINSIZE 312 struct winsize { 313 unsigned short ws_row; /* rows, in characters */ 314 unsigned short ws_col; /* columns, in character */ 315 unsigned short ws_xpixel; /* horizontal size, pixels */ 316 unsigned short ws_ypixel; /* vertical size, pixels */ 317 }; 318 #endif 319 320 /* *-*-nto-qnx does not define this type in the system headers */ 321 #ifdef MISSING_FD_MASK 322 typedef unsigned long int fd_mask; 323 #endif 324 325 /* Paths */ 326 327 #ifndef _PATH_BSHELL 328 #define _PATH_BSHELL "/bin/sh" 329 #endif 330 331 #ifndef _PATH_CSHELL 332 #define _PATH_CSHELL "/bin/csh" 333 #endif 334 335 #ifndef _PATH_SHELLS 336 #define _PATH_SHELLS "/etc/shells" 337 #endif 338 339 #ifdef USER_PATH 340 #ifdef _PATH_STDPATH 341 #undef _PATH_STDPATH 342 #endif 343 #define _PATH_STDPATH USER_PATH 344 #endif 345 346 #ifndef _PATH_STDPATH 347 #define _PATH_STDPATH "/usr/bin" 348 #endif 349 350 #ifndef _PATH_DEVNULL 351 #define _PATH_DEVNULL "/dev/null" 352 #endif 353 354 #ifndef MAIL_DIRECTORY 355 #define MAIL_DIRECTORY "/var/spool/mail" 356 #endif 357 358 #ifndef MAILDIR 359 #define MAILDIR MAIL_DIRECTORY 360 #endif 361 362 #if !defined(_PATH_MAILDIR) && defined(MAILDIR) 363 #define _PATH_MAILDIR MAILDIR 364 #endif /* !defined(_PATH_MAILDIR) && defined(MAILDIR) */ 365 366 #ifndef _PATH_RSH 367 #ifdef RSH_PATH 368 #define _PATH_RSH RSH_PATH 369 #else /* RSH_PATH */ 370 #define _PATH_RSH "/usr/bin/rsh" 371 #endif /* RSH_PATH */ 372 #endif /* _PATH_RSH */ 373 374 #ifndef _PATH_NOLOGIN 375 #define _PATH_NOLOGIN "/etc/nologin" 376 #endif 377 378 /* Define this to be the path of the xauth program. */ 379 #ifdef XAUTH_PATH 380 #define _PATH_XAUTH XAUTH_PATH 381 #endif /* XAUTH_PATH */ 382 383 /* derived from XF4/xc/lib/dps/Xlibnet.h */ 384 #ifndef X_UNIX_PATH 385 #ifdef __hpux 386 #define X_UNIX_PATH "/var/spool/sockets/X11/%u" 387 #else 388 #define X_UNIX_PATH "/tmp/.X11-unix/X%u" 389 #endif 390 #endif /* X_UNIX_PATH */ 391 392 #define _PATH_UNIX_X X_UNIX_PATH 393 394 #ifndef _PATH_TTY 395 #define _PATH_TTY "/dev/tty" 396 #endif 397 398 /* Macros */ 399 400 #ifndef MAX 401 #define MAX(a, b) (((a) > (b)) ? (a) : (b)) 402 #define MIN(a, b) (((a) < (b)) ? (a) : (b)) 403 #endif 404 405 #ifndef roundup 406 #define roundup(x, y) ((((x) + ((y) - 1)) / (y)) * (y)) 407 #endif 408 409 #ifndef timersub 410 #define timersub(a, b, result) \ 411 do { \ 412 (result)->tv_sec = (a)->tv_sec - (b)->tv_sec; \ 413 (result)->tv_usec = (a)->tv_usec - (b)->tv_usec; \ 414 if ((result)->tv_usec < 0) { \ 415 --(result)->tv_sec; \ 416 (result)->tv_usec += 1000000; \ 417 } \ 418 } while (0) 419 #endif 420 421 #ifndef __P 422 #define __P(x) x 423 #endif 424 425 #if !defined(IN6_IS_ADDR_V4MAPPED) 426 #define IN6_IS_ADDR_V4MAPPED(a) \ 427 ((((u_int32_t *)(a))[0] == 0) && (((u_int32_t *)(a))[1] == 0) && \ 428 (((u_int32_t *)(a))[2] == htonl(0xffff))) 429 #endif /* !defined(IN6_IS_ADDR_V4MAPPED) */ 430 431 #if !defined(__GNUC__) || (__GNUC__ < 2) 432 #define __attribute__(x) 433 #endif /* !defined(__GNUC__) || (__GNUC__ < 2) */ 434 435 #if !defined(HAVE_ATTRIBUTE__BOUNDED__) && !defined(__bounded__) 436 #define __bounded__(x, y, z) 437 #endif 438 439 /* *-*-nto-qnx doesn't define this macro in the system headers */ 440 #ifdef MISSING_HOWMANY 441 #define howmany(x, y) (((x) + ((y) - 1)) / (y)) 442 #endif 443 444 #ifndef OSSH_ALIGNBYTES 445 #define OSSH_ALIGNBYTES (sizeof (int) - 1) 446 #endif 447 448 #ifndef __CMSG_ALIGN 449 #define __CMSG_ALIGN(p) (((uint_t)(p) + OSSH_ALIGNBYTES) &~ OSSH_ALIGNBYTES) 450 #endif 451 452 /* Length of the contents of a control message of length len */ 453 #ifndef CMSG_LEN 454 #define CMSG_LEN(len) (__CMSG_ALIGN(sizeof (struct cmsghdr)) + (len)) 455 #endif 456 457 /* Length of the space taken up by a padded control message of length len */ 458 #ifndef CMSG_SPACE 459 #define CMSG_SPACE(len) \ 460 (__CMSG_ALIGN(sizeof (struct cmsghdr)) + __CMSG_ALIGN(len)) 461 #endif 462 463 /* Function replacement / compatibility hacks */ 464 465 #if !defined(HAVE_GETADDRINFO) && (defined(HAVE_OGETADDRINFO) || \ 466 defined(HAVE_NGETADDRINFO)) 467 #define HAVE_GETADDRINFO 468 #endif 469 470 #ifndef HAVE_GETOPT_OPTRESET 471 #undef getopt 472 #undef opterr 473 #undef optind 474 #undef optopt 475 #undef optreset 476 #undef optarg 477 #define getopt(ac, av, o) BSDgetopt(ac, av, o) 478 #define opterr BSDopterr 479 #define optind BSDoptind 480 #define optopt BSDoptopt 481 #define optreset BSDoptreset 482 #define optarg BSDoptarg 483 #endif 484 485 /* In older versions of libpam, pam_strerror takes a single argument */ 486 #ifdef HAVE_OLD_PAM 487 #define PAM_STRERROR(a, b) pam_strerror((b)) 488 #else 489 #define PAM_STRERROR(a, b) pam_strerror((a), (b)) 490 #endif 491 492 #ifdef PAM_SUN_CODEBASE 493 #define PAM_MSG_MEMBER(msg, n, member) ((*(msg))[(n)].member) 494 #else 495 #define PAM_MSG_MEMBER(msg, n, member) ((msg)[(n)]->member) 496 #endif 497 498 #if defined(BROKEN_GETADDRINFO) && defined(HAVE_GETADDRINFO) 499 #undef HAVE_GETADDRINFO 500 #endif 501 502 #if defined(BROKEN_GETADDRINFO) && defined(HAVE_FREEADDRINFO) 503 #undef HAVE_FREEADDRINFO 504 #endif 505 506 #if defined(BROKEN_GETADDRINFO) && defined(HAVE_GAI_STRERROR) 507 #undef HAVE_GAI_STRERROR 508 #endif 509 510 #if !defined(HAVE_MEMMOVE) && defined(HAVE_BCOPY) 511 #define memmove(s1, s2, n) bcopy((s2), (s1), (n)) 512 #endif /* !defined(HAVE_MEMMOVE) && defined(HAVE_BCOPY) */ 513 514 #if defined(HAVE_VHANGUP) && !defined(HAVE_DEV_PTMX) 515 #define USE_VHANGUP 516 #endif /* defined(HAVE_VHANGUP) && !defined(HAVE_DEV_PTMX) */ 517 518 #ifndef GETPGRP_VOID 519 #define getpgrp() getpgrp(0) 520 #endif 521 522 /* OPENSSL_free() is Free() in versions before OpenSSL 0.9.6 */ 523 #if !defined(OPENSSL_VERSION_NUMBER) || (OPENSSL_VERSION_NUMBER < 0x0090600f) 524 #define OPENSSL_free(x) Free(x) 525 #endif 526 527 #if !defined(HAVE___func__) && defined(HAVE___FUNCTION__) 528 #define __func__ __FUNCTION__ 529 #elif !defined(HAVE___func__) 530 #define __func__ "" 531 #endif 532 533 /* 534 * login recorder definitions 535 */ 536 537 /* FIXME: put default paths back in */ 538 #ifndef UTMP_FILE 539 #ifdef _PATH_UTMP 540 #define UTMP_FILE _PATH_UTMP 541 #else 542 #ifdef CONF_UTMP_FILE 543 #define UTMP_FILE CONF_UTMP_FILE 544 #endif 545 #endif 546 #endif 547 548 #ifndef WTMP_FILE 549 #ifdef _PATH_WTMP 550 #define WTMP_FILE _PATH_WTMP 551 #else 552 #ifdef CONF_WTMP_FILE 553 #define WTMP_FILE CONF_WTMP_FILE 554 #endif 555 #endif 556 #endif 557 558 /* pick up the user's location for lastlog if given */ 559 #ifndef LASTLOG_FILE 560 #ifdef _PATH_LASTLOG 561 #define LASTLOG_FILE _PATH_LASTLOG 562 #else 563 #ifdef CONF_LASTLOG_FILE 564 #define LASTLOG_FILE CONF_LASTLOG_FILE 565 #endif 566 #endif 567 #endif 568 569 /* The login() library function in libutil is first choice */ 570 #if defined(HAVE_LOGIN) && !defined(DISABLE_LOGIN) 571 #define USE_LOGIN 572 #else 573 /* Simply select your favourite login types. */ 574 /* Can't do if-else because some systems use several... <sigh> */ 575 #if defined(UTMPX_FILE) && !defined(DISABLE_UTMPX) 576 #define USE_UTMPX 577 #endif 578 #if defined(UTMP_FILE) && !defined(DISABLE_UTMP) 579 #define USE_UTMP 580 #endif 581 #if defined(WTMPX_FILE) && !defined(DISABLE_WTMPX) 582 #define USE_WTMPX 583 #endif 584 #if defined(WTMP_FILE) && !defined(DISABLE_WTMP) 585 #define USE_WTMP 586 #endif 587 #endif 588 589 /* I hope that the presence of LASTLOG_FILE is enough to detect this */ 590 #if defined(LASTLOG_FILE) && !defined(DISABLE_LASTLOG) 591 #define USE_LASTLOG 592 #endif 593 594 /* end of login recorder definitions */ 595 596 #ifdef __cplusplus 597 } 598 #endif 599 600 #endif /* _DEFINES_H */