defines.h 22 KB

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