PageRenderTime 58ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/amanda/tags/amanda252p1/common-src/amanda.h

#
C Header | 1597 lines | 1229 code | 111 blank | 257 comment | 62 complexity | e01f124af48ecc85c391b69e636c4c6d MD5 | raw file
  1. /*
  2. * Amanda, The Advanced Maryland Automatic Network Disk Archiver
  3. * Copyright (c) 1991-1999 University of Maryland at College Park
  4. * All Rights Reserved.
  5. *
  6. * Permission to use, copy, modify, distribute, and sell this software and its
  7. * documentation for any purpose is hereby granted without fee, provided that
  8. * the above copyright notice appear in all copies and that both that
  9. * copyright notice and this permission notice appear in supporting
  10. * documentation, and that the name of U.M. not be used in advertising or
  11. * publicity pertaining to distribution of the software without specific,
  12. * written prior permission. U.M. makes no representations about the
  13. * suitability of this software for any purpose. It is provided "as is"
  14. * without express or implied warranty.
  15. *
  16. * U.M. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
  17. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL U.M.
  18. * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  19. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  20. * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  21. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  22. *
  23. * Authors: the Amanda Development Team. Its members are listed in a
  24. * file named AUTHORS, in the root directory of this distribution.
  25. */
  26. /*
  27. * $Id: amanda.h,v 1.131 2006/07/25 18:27:56 martinea Exp $
  28. *
  29. * the central header file included by all amanda sources
  30. */
  31. #ifndef AMANDA_H
  32. #define AMANDA_H
  33. #ifdef HAVE_CONFIG_H
  34. #include "config.h"
  35. #endif
  36. /*
  37. * Force large file source even if configure guesses wrong.
  38. */
  39. #ifndef _LARGE_FILE_SOURCE
  40. #define _LARGE_FILES 1
  41. #endif
  42. #ifndef _LARGEFILE64_SOURCE
  43. #define _LARGEFILE64_SOURCE 1
  44. #endif
  45. #ifndef _FILE_OFFSET_BITS
  46. #define _FILE_OFFSET_BITS 64
  47. #endif
  48. #ifdef HAVE_SYS_TYPES_H
  49. # include <sys/types.h>
  50. #endif
  51. /*
  52. * I would prefer that each Amanda module include only those system headers
  53. * that are locally needed, but on most Unixes the system header files are not
  54. * protected against multiple inclusion, so this can lead to problems.
  55. *
  56. * Also, some systems put key files in different places, so by including
  57. * everything here the rest of the system is isolated from such things.
  58. */
  59. #ifdef HAVE_ALLOCA_H
  60. # include <alloca.h>
  61. #endif
  62. /* from the autoconf documentation */
  63. #ifdef HAVE_DIRENT_H
  64. # include <dirent.h>
  65. # define NAMLEN(dirent) strlen((dirent)->d_name)
  66. #else
  67. # define dirent direct
  68. # define NAMLEN(dirent) (dirent)->d_namlen
  69. # if HAVE_SYS_NDIR_H
  70. # include <sys/ndir.h>
  71. # endif
  72. # if HAVE_SYS_DIR_H
  73. # include <sys/dir.h>
  74. # endif
  75. # if HAVE_NDIR_H
  76. # include <ndir.h>
  77. # endif
  78. #endif
  79. #ifdef HAVE_FCNTL_H
  80. # include <fcntl.h>
  81. #endif
  82. #ifdef HAVE_GRP_H
  83. # include <grp.h>
  84. #endif
  85. #if defined(USE_DB_H)
  86. # include <db.h>
  87. #else
  88. #if defined(USE_DBM_H)
  89. # include <dbm.h>
  90. #else
  91. #if defined(USE_GDBM_H)
  92. # include <gdbm.h>
  93. #else
  94. #if defined(USE_NDBM_H)
  95. # include <ndbm.h>
  96. #endif
  97. #endif
  98. #endif
  99. #endif
  100. #ifdef HAVE_NETDB_H
  101. # include <netdb.h>
  102. #endif
  103. #ifdef TIME_WITH_SYS_TIME
  104. # include <sys/time.h>
  105. # include <time.h>
  106. #else
  107. # ifdef HAVE_SYS_TIME_H
  108. # include <sys/time.h>
  109. # else
  110. # include <time.h>
  111. # endif
  112. #endif
  113. #ifdef HAVE_LIBC_H
  114. # include <libc.h>
  115. #endif
  116. #ifdef HAVE_STDLIB_H
  117. # include <stdlib.h>
  118. #endif
  119. #ifdef HAVE_LIBGEN_H
  120. # include <libgen.h>
  121. #endif
  122. #ifdef HAVE_STRING_H
  123. # include <string.h>
  124. #endif
  125. #ifdef HAVE_STRINGS_H
  126. # include <strings.h>
  127. #endif
  128. #ifdef HAVE_SYSLOG_H
  129. # include <syslog.h>
  130. #endif
  131. #ifdef HAVE_MATH_H
  132. # include <math.h>
  133. #endif
  134. #ifdef HAVE_SYS_FILE_H
  135. # include <sys/file.h>
  136. #endif
  137. #ifdef HAVE_SYS_IOCTL_H
  138. # include <sys/ioctl.h>
  139. #endif
  140. #ifdef HAVE_LIMITS_H
  141. #include <limits.h>
  142. #endif
  143. #ifdef HAVE_SYS_PARAM_H
  144. # include <sys/param.h>
  145. #endif
  146. #if defined(HAVE_SYS_IPC_H) && defined(HAVE_SYS_SHM_H)
  147. # include <sys/ipc.h>
  148. # include <sys/shm.h>
  149. #else
  150. # ifdef HAVE_SYS_MMAN_H
  151. # include <sys/mman.h>
  152. # endif
  153. #endif
  154. #ifdef HAVE_SYS_SELECT_H
  155. # include <sys/select.h>
  156. #endif
  157. #ifdef HAVE_SYS_STAT_H
  158. # include <sys/stat.h>
  159. #endif
  160. #ifdef HAVE_SYS_UIO_H
  161. # include <sys/uio.h>
  162. #else
  163. struct iovec {
  164. void *iov_base;
  165. int iov_len;
  166. };
  167. #endif
  168. #ifdef HAVE_WAIT_H
  169. # include <wait.h>
  170. #endif
  171. #ifdef HAVE_SYS_WAIT_H
  172. # include <sys/wait.h>
  173. #endif
  174. #ifdef HAVE_STDARG_H
  175. #include <stdarg.h>
  176. #endif
  177. #ifdef WAIT_USES_INT
  178. typedef int amwait_t;
  179. # ifndef WEXITSTATUS
  180. # define WEXITSTATUS(stat_val) (*(unsigned*)&(stat_val) >> 8)
  181. # endif
  182. # ifndef WTERMSIG
  183. # define WTERMSIG(stat_val) (*(unsigned*)&(stat_val) & 0x7F)
  184. # endif
  185. # ifndef WIFEXITED
  186. # define WIFEXITED(stat_val) ((*(unsigned*)&(stat_val) & 255) == 0)
  187. # endif
  188. #else
  189. # ifdef WAIT_USES_UNION
  190. typedef union wait amwait_t;
  191. # ifndef WEXITSTATUS
  192. # define WEXITSTATUS(stat_val) (((amwait_t*)&(stat_val))->w_retcode)
  193. # endif
  194. # ifndef WTERMSIG
  195. # define WTERMSIG(stat_val) (((amwait_t*)&(stat_val))->w_termsig)
  196. # endif
  197. # ifndef WIFEXITED
  198. # define WIFEXITED(stat_val) (WTERMSIG(stat_val) == 0)
  199. # endif
  200. # else
  201. typedef int amwait_t;
  202. # ifndef WEXITSTATUS
  203. # define WEXITSTATUS(stat_val) (*(unsigned*)&(stat_val) >> 8)
  204. # endif
  205. # ifndef WTERMSIG
  206. # define WTERMSIG(stat_val) (*(unsigned*)&(stat_val) & 0x7F)
  207. # endif
  208. # ifndef WIFEXITED
  209. # define WIFEXITED(stat_val) ((*(unsigned*)&(stat_val) & 255) == 0)
  210. # endif
  211. # endif
  212. #endif
  213. #ifndef WIFSIGNALED
  214. # define WIFSIGNALED(stat_val) (WTERMSIG(stat_val) != 0)
  215. #endif
  216. #ifdef HAVE_UNISTD_H
  217. # include <unistd.h>
  218. #endif
  219. #include <ctype.h>
  220. #include <errno.h>
  221. #include <netinet/in.h>
  222. #include <pwd.h>
  223. #include <signal.h>
  224. #include <setjmp.h>
  225. #include <stdio.h>
  226. #include <sys/resource.h>
  227. #include <sys/socket.h>
  228. #if !defined(CONFIGURE_TEST)
  229. # include "amanda-int.h"
  230. #endif
  231. #ifdef HAVE_ARPA_INET_H
  232. #include <arpa/inet.h>
  233. #endif
  234. #ifndef HAVE_SOCKADDR_STORAGE
  235. # define sockaddr_storage sockaddr_in
  236. # define ss_family sin_family
  237. #endif
  238. #ifndef INET_ADDRSTRLEN
  239. #define INET_ADDRSTRLEN 16
  240. #endif
  241. /* Calculate the length of the data in a struct sockaddr_storage.
  242. * THIS IS A HACK.
  243. *
  244. * To be truly portable, the length of an address should be passed
  245. * in a companion variable. When such lengths are available
  246. * everywhere they are needed, this macro should be removed.
  247. */
  248. #ifdef WORKING_IPV6
  249. # define SS_LEN(ss) (((struct sockaddr *)(ss))->sa_family==AF_INET6?sizeof(struct sockaddr_in6):sizeof(struct sockaddr_in))
  250. #else
  251. # define SS_LEN(ss) (sizeof(struct sockaddr_in))
  252. #endif
  253. /* AF_NATIVE is the "best" address family we support, backward compatible
  254. * through to AF_INET.
  255. */
  256. #ifdef WORKING_IPV6
  257. #define AF_NATIVE AF_INET6
  258. #else
  259. #define AF_NATIVE AF_INET
  260. #endif
  261. /* SS_INIT(ss, family) initializes ss to all zeroes (as directed by RFC),
  262. * and sets its ss_family as specified
  263. */
  264. #define SS_INIT(ss, family) do { \
  265. memset((ss), 0, sizeof(*(ss))); \
  266. (ss)->ss_family = (family); \
  267. } while (0);
  268. /* SS_SET_INADDR_ANY(ss) sets ss to the family-appropriate equivalent of
  269. * INADDR_ANY, a wildcard address and port.
  270. */
  271. #ifdef WORKING_IPV6
  272. #define SS_SET_INADDR_ANY(ss) do { \
  273. switch ((ss)->ss_family) { \
  274. case AF_INET6: \
  275. ((struct sockaddr_in6 *)(ss))->sin6_flowinfo = 0; \
  276. ((struct sockaddr_in6 *)(ss))->sin6_addr = in6addr_any; \
  277. break; \
  278. case AF_INET: \
  279. ((struct sockaddr_in *)(ss))->sin_addr.s_addr = INADDR_ANY; \
  280. break; \
  281. } \
  282. } while (0);
  283. #else
  284. #define SS_SET_INADDR_ANY(ss) do { \
  285. ((struct sockaddr_in *)(ss))->sin_addr.s_addr = INADDR_ANY; \
  286. } while (0);
  287. #endif
  288. /* Set/get the port in a sockaddr_storage that already has an family */
  289. #ifdef WORKING_IPV6
  290. #define SS_SET_PORT(ss, port) \
  291. switch ((ss)->ss_family) { \
  292. case AF_INET: \
  293. ((struct sockaddr_in *)(ss))->sin_port = (in_port_t)htons((port)); \
  294. break; \
  295. case AF_INET6: \
  296. ((struct sockaddr_in6 *)(ss))->sin6_port = (in_port_t)htons((port)); \
  297. break; \
  298. default: assert(0); \
  299. }
  300. #else
  301. #define SS_SET_PORT(ss, port) \
  302. ((struct sockaddr_in *)(ss))->sin_port = (in_port_t)htons((port));
  303. #endif
  304. #ifdef WORKING_IPV6
  305. #define SS_GET_PORT(ss) (ntohs( \
  306. (ss)->ss_family == AF_INET6? \
  307. ((struct sockaddr_in6 *)(ss))->sin6_port \
  308. :((struct sockaddr_in *)(ss))->sin_port))
  309. #else
  310. #define SS_GET_PORT(ss) (ntohs( \
  311. ((struct sockaddr_in *)(ss))->sin_port))
  312. #endif
  313. /*
  314. * The dbmalloc package comes from:
  315. *
  316. * http://www.clark.net/pub/dickey/dbmalloc/dbmalloc.tar.gz
  317. *
  318. * or
  319. *
  320. * ftp://gatekeeper.dec.com/pub/usenet/comp.sources.misc/volume32/dbmalloc/
  321. *
  322. * The following functions are sprinkled through the code, but are
  323. * disabled unless USE_DBMALLOC is defined:
  324. *
  325. * malloc_enter(char *) -- stack trace for malloc reports
  326. * malloc_leave(char *) -- stack trace for malloc reports
  327. * malloc_mark(void *) -- mark an area as never to be free-d
  328. * malloc_chain_check(void) -- check the malloc area now
  329. * malloc_dump(int fd) -- report the malloc contents to a file descriptor
  330. * malloc_list(int fd, ulong a, ulong b) -- report memory activated since
  331. * history stamp a that is still active as of stamp b (leak check)
  332. * malloc_inuse(ulong *h) -- create history stamp h and return the amount
  333. * of memory currently in use.
  334. */
  335. #ifdef USE_DBMALLOC
  336. #include "dbmalloc.h"
  337. #else
  338. #define malloc_enter(func) ((void)0)
  339. #define malloc_leave(func) ((void)0)
  340. #define malloc_mark(ptr) ((void)0)
  341. #define malloc_chain_check() ((void)0)
  342. #define malloc_dump(fd) ((void)0)
  343. #define malloc_list(a,b,c) ((void)0)
  344. #define malloc_inuse(hist) (*(hist) = 0, 0)
  345. #define dbmalloc_caller_loc(x,y) (x)
  346. #endif
  347. #if !defined(HAVE_SIGACTION) && defined(HAVE_SIGVEC)
  348. /* quick'n'dirty hack for NextStep31 */
  349. # define sa_flags sv_flags
  350. # define sa_handler sv_handler
  351. # define sa_mask sv_mask
  352. # define sigaction sigvec
  353. # define sigemptyset(mask) /* no way to clear pending signals */
  354. #endif
  355. /*
  356. * Most Unixen declare errno in <errno.h>, some don't. Some multithreaded
  357. * systems have errno as a per-thread macro. So, we have to be careful.
  358. */
  359. #ifndef errno
  360. extern int errno;
  361. #endif
  362. /*
  363. * Some compilers have int for type of sizeof() some use size_t.
  364. * size_t is the one we want...
  365. */
  366. #define SIZEOF(x) (size_t)sizeof(x)
  367. /*
  368. * Some older BSD systems don't have these FD_ macros, so if not, provide them.
  369. */
  370. #if !defined(FD_SET) || defined(LINT) || defined(__lint)
  371. # undef FD_SETSIZE
  372. # define FD_SETSIZE (int)(SIZEOF(fd_set) * CHAR_BIT)
  373. # undef FD_SET
  374. # define FD_SET(n, p) (((fd_set *)(p))->fds_bits[(n)/WORD_BIT] |= (int)((1 << ((n) % WORD_BIT))))
  375. # undef FD_CLR
  376. # define FD_CLR(n, p) (((fd_set *)(p))->fds_bits[(n)/WORD_BIT] &= (int)(~(1 << ((n) % WORD_BIT))))
  377. # undef FD_ISSET
  378. # define FD_ISSET(n, p) (((fd_set *)(p))->fds_bits[(n)/WORD_BIT] & (1 << ((n) % WORD_BIT)))
  379. # undef FD_ZERO
  380. # define FD_ZERO(p) memset((p), 0, SIZEOF(*(p)))
  381. #endif
  382. #ifndef FD_COPY
  383. # define FD_COPY(p, q) memcpy((q), (p), SIZEOF(*(p)))
  384. #endif
  385. /*
  386. * Define MAX_HOSTNAME_LENGTH as the size of arrays to hold hostname's.
  387. */
  388. #undef MAX_HOSTNAME_LENGTH
  389. #define MAX_HOSTNAME_LENGTH 1025
  390. /*
  391. * If void is broken, substitute char.
  392. */
  393. #ifdef BROKEN_VOID
  394. # define void char
  395. #endif
  396. #define stringize(x) #x
  397. #define stringconcat(x, y) x ## y
  398. /*
  399. * So that we can use GNUC attributes (such as to get -Wall warnings
  400. * for printf-like functions). Only do this in gcc 2.7 or later ...
  401. * it may work on earlier stuff, but why chance it.
  402. */
  403. #if !defined(__GNUC__) || __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7) || defined(S_SPLINT_S) || defined(LINT) || defined(__lint)
  404. #undef __attribute__
  405. #define __attribute__(__x)
  406. #endif
  407. /*
  408. * assertions, but call error() instead of abort
  409. */
  410. #ifndef ASSERTIONS
  411. #define assert(exp) ((void)0)
  412. #else /* ASSERTIONS */
  413. #define assert(exp) do { \
  414. if (!(exp)) { \
  415. onerror(abort); \
  416. error("assert: %s false, file %s, line %d", \
  417. stringize(exp), __FILE__, __LINE__); \
  418. /*NOTREACHED*/ \
  419. } \
  420. } while (0)
  421. #endif /* ASSERTIONS */
  422. /*
  423. * print debug output, else compile to nothing.
  424. */
  425. #ifdef DEBUG_CODE /* { */
  426. # define dbopen(a) debug_open(a)
  427. # define dbreopen(a,b) debug_reopen(a,b)
  428. # define dbrename(a,b) debug_rename(a,b)
  429. # define dbclose() debug_close()
  430. # define dbprintf(p) (debug_printf p)
  431. # define dbfd() debug_fd()
  432. # define dbfp() debug_fp()
  433. # define dbfn() debug_fn()
  434. extern void debug_open(char *subdir);
  435. extern void debug_reopen(char *file, char *notation);
  436. extern void debug_rename(char *config, char *subdir);
  437. extern void debug_close(void);
  438. extern void debug_printf(const char *format, ...)
  439. __attribute__ ((format (printf, 1, 2)));
  440. extern int debug_fd(void);
  441. extern FILE * debug_fp(void);
  442. extern char * debug_fn(void);
  443. extern void set_debug_prefix_pid(pid_t);
  444. extern char *debug_prefix(char *);
  445. extern char *debug_prefix_time(char *);
  446. #else /* }{ */
  447. # define dbopen(a)
  448. # define dbreopen(a,b)
  449. # define dbrename(a,b)
  450. # define dbclose()
  451. # define dbprintf(p)
  452. # define dbfd() (-1)
  453. # define dbfp() NULL
  454. # define dbfn() NULL
  455. # define set_debug_prefix_pid(x)
  456. # define debug_prefix(x) get_pname()
  457. # define debug_prefix_time(x) get_pname()
  458. #endif /* } */
  459. /* amanda #days calculation, with roundoff */
  460. #define SECS_PER_DAY (24*60*60)
  461. #define days_diff(a, b) (int)(((b) - (a) + SECS_PER_DAY/2) / SECS_PER_DAY)
  462. /* Global constants. */
  463. #ifndef AMANDA_SERVICE_NAME
  464. #define AMANDA_SERVICE_NAME "amanda"
  465. #endif
  466. #ifndef KAMANDA_SERVICE_NAME
  467. #define KAMANDA_SERVICE_NAME "kamanda"
  468. #endif
  469. #ifndef SERVICE_SUFFIX
  470. #define SERVICE_SUFFIX ""
  471. #endif
  472. #ifndef AMANDA_SERVICE_DEFAULT
  473. #define AMANDA_SERVICE_DEFAULT ((in_port_t)10080)
  474. #endif
  475. #ifndef KAMANDA_SERVICE_DEFAULT
  476. #define KAMANDA_SERVICE_DEFAULT ((in_port_t)10081)
  477. #endif
  478. #define am_round(v,u) ((((v) + (u) - 1) / (u)) * (u))
  479. #define am_floor(v,u) (((v) / (u)) * (u))
  480. /* Holding disk block size. Do not even think about changint this! :-) */
  481. #define DISK_BLOCK_KB 32
  482. #define DISK_BLOCK_BYTES (DISK_BLOCK_KB * 1024)
  483. /* Maximum size of a tape block */
  484. /* MAX_TAPE_BLOCK_KB is defined in config.h */
  485. /* by configure --with-maxtapeblocksize */
  486. #define MAX_TAPE_BLOCK_BYTES (MAX_TAPE_BLOCK_KB*1024)
  487. /* Maximum length of tape label, plus one for null-terminator. */
  488. #define MAX_TAPE_LABEL_LEN (10240)
  489. #define MAX_TAPE_LABEL_BUF (MAX_TAPE_LABEL_LEN+1)
  490. #define MAX_TAPE_LABEL_FMT "%10240s"
  491. /* Define miscellaneous amanda functions. */
  492. #define ERR_INTERACTIVE 1
  493. #define ERR_SYSLOG 2
  494. #define ERR_AMANDALOG 4
  495. extern void set_logerror(void (*f)(char *));
  496. extern void set_pname(char *pname);
  497. extern char *get_pname(void);
  498. extern int erroutput_type;
  499. extern void error(const char *format, ...)
  500. __attribute__ ((format (printf, 1, 2), noreturn));
  501. extern void errordump(const char *format, ...)
  502. __attribute__ ((format (printf, 1, 2), noreturn));
  503. extern int onerror(void (*errf)(void));
  504. extern void *debug_alloc (const char *c, int l, size_t size);
  505. extern void *debug_newalloc (const char *c, int l, void *old, size_t size);
  506. extern char *debug_stralloc (const char *c, int l, const char *str);
  507. extern char *debug_newstralloc(const char *c, int l, char *oldstr,
  508. const char *newstr);
  509. extern const char *debug_caller_loc (const char *file, int line);
  510. extern int debug_alloc_push (char *file, int line);
  511. extern void debug_alloc_pop (void);
  512. #define alloc(s) debug_alloc(__FILE__, __LINE__, (s))
  513. #define newalloc(p,s) debug_newalloc(__FILE__, __LINE__, (p), (s))
  514. #define stralloc(s) debug_stralloc(__FILE__, __LINE__, (s))
  515. #define newstralloc(p,s) debug_newstralloc(__FILE__, __LINE__, (p), (s))
  516. /*
  517. * Voodoo time. We want to be able to mark these calls with the source
  518. * line, but CPP does not handle variable argument lists so we cannot
  519. * do what we did above (e.g. for alloc()).
  520. *
  521. * What we do is call a function to save the file and line number
  522. * and have it return "false". That triggers the "?" operator to
  523. * the right side of the ":" which is a call to the debug version of
  524. * vstralloc/newvstralloc but without parameters. The compiler gets
  525. * those from the next input tokens:
  526. *
  527. * xx = vstralloc(a,b,NULL);
  528. *
  529. * becomes:
  530. *
  531. * xx = debug_alloc_push(__FILE__,__LINE__)?0:debug_vstralloc(a,b,NULL);
  532. *
  533. * This works as long as vstralloc/newvstralloc are not part of anything
  534. * very complicated. Assignment is fine, as is an argument to another
  535. * function (but you should not do that because it creates a memory leak).
  536. * This will not work in arithmetic or comparison, but it is unlikely
  537. * they are used like that.
  538. *
  539. * xx = vstralloc(a,b,NULL); OK
  540. * return vstralloc(j,k,NULL); OK
  541. * sub(a, vstralloc(g,h,NULL), z); OK, but a leak
  542. * if(vstralloc(s,t,NULL) == NULL) { ... NO, but unneeded
  543. * xx = vstralloc(x,y,NULL) + 13; NO, but why do it?
  544. */
  545. #define vstralloc debug_alloc_push(__FILE__,__LINE__)?0:debug_vstralloc
  546. #define newvstralloc debug_alloc_push(__FILE__,__LINE__)?0:debug_newvstralloc
  547. #define vstrallocf debug_alloc_push(__FILE__,__LINE__)?0:debug_vstrallocf
  548. extern char *debug_vstralloc(const char *str, ...);
  549. extern char *debug_newvstralloc(char *oldstr, const char *newstr, ...);
  550. extern char *debug_vstrallocf(const char *fmt, ...)
  551. __attribute__ ((format (printf, 1, 2)));
  552. #define stralloc2(s1,s2) vstralloc((s1),(s2),NULL)
  553. #define newstralloc2(p,s1,s2) newvstralloc((p),(s1),(s2),NULL)
  554. /* Usage: vstrextend(foo, "bar, "baz", NULL). Extends the existing
  555. * string, or allocates a brand new one. */
  556. extern char *vstrextend(char **oldstr, ...);
  557. extern /*@only@*/ /*@null@*/ char *debug_agets(const char *c, int l, FILE *file);
  558. extern /*@only@*/ /*@null@*/ char *debug_areads(const char *c, int l, int fd);
  559. #define agets(f) debug_agets(__FILE__,__LINE__,(f))
  560. #define areads(f) debug_areads(__FILE__,__LINE__,(f))
  561. extern int debug_amtable_alloc(const char *file,
  562. int line,
  563. void **table,
  564. size_t *current,
  565. size_t elsize,
  566. size_t count,
  567. int bump,
  568. void (*init_func)(void *));
  569. #define amtable_alloc(t,c,s,n,b,f) debug_amtable_alloc(__FILE__, \
  570. __LINE__, \
  571. (t), \
  572. (c), \
  573. (s), \
  574. (n), \
  575. (b), \
  576. (f))
  577. extern void amtable_free(void **table, size_t *current);
  578. extern uid_t client_uid;
  579. extern gid_t client_gid;
  580. void safe_fd(int fd_start, int fd_count);
  581. void safe_cd(void);
  582. void save_core(void);
  583. char ** safe_env(void);
  584. char * validate_regexp(const char *regex);
  585. char * validate_glob(const char *glob);
  586. char * clean_regex(const char *regex);
  587. int match(const char *regex, const char *str);
  588. int match_glob(const char *glob, const char *str);
  589. char * glob_to_regex(const char *glob);
  590. int match_tar(const char *glob, const char *str);
  591. char * tar_to_regex(const char *glob);
  592. int match_host(const char *glob, const char *host);
  593. int match_disk(const char *glob, const char *disk);
  594. int match_datestamp(const char *dateexp, const char *datestamp);
  595. int match_level(const char *levelexp, const char *level);
  596. time_t unctime(char *timestr);
  597. ssize_t areads_dataready(int fd);
  598. void areads_relbuf(int fd);
  599. /*
  600. * amfree(ptr) -- if allocated, release space and set ptr to NULL.
  601. *
  602. * In general, this should be called instead of just free(), unless
  603. * the very next source line sets the pointer to a new value.
  604. */
  605. #define amfree(ptr) do { \
  606. if((ptr) != NULL) { \
  607. int e__errno = errno; \
  608. free(ptr); \
  609. (ptr) = NULL; \
  610. errno = e__errno; \
  611. (void)(ptr); /* Fix value never used warning at end of routines */ \
  612. } \
  613. } while (0)
  614. #define strappend(s1,s2) do { \
  615. char *t_t_t = (s1) ? stralloc2((s1),(s2)) : stralloc((s2)); \
  616. amfree((s1)); \
  617. (s1) = t_t_t; \
  618. } while(0)
  619. /*
  620. * "Safe" close macros. Close the object then set it to a value that
  621. * will cause an error if referenced.
  622. *
  623. * aclose(fd) -- close a file descriptor and set it to -1.
  624. * afclose(f) -- close a stdio file and set it to NULL.
  625. * apclose(p) -- close a stdio pipe file and set it to NULL.
  626. *
  627. * Note: be careful not to do the following:
  628. *
  629. * for(fd = low; fd < high; fd++) {
  630. * aclose(fd);
  631. * }
  632. *
  633. * Since aclose() sets the argument to -1, this will loop forever.
  634. * Just copy fd to a temp variable and use that with aclose().
  635. *
  636. * Aclose() interacts with areads() to inform it to release any buffer
  637. * it has outstanding on the file descriptor.
  638. */
  639. #define aclose(fd) do { \
  640. if((fd) >= 0) { \
  641. close(fd); \
  642. areads_relbuf(fd); \
  643. } \
  644. (fd) = -1; \
  645. (void)(fd); /* Fix value never used warning at end of routines */ \
  646. } while(0)
  647. #define afclose(f) do { \
  648. if((f) != NULL) { \
  649. fclose(f); \
  650. (f) = NULL; \
  651. (void)(f); /* Fix value never used warning at end of routines */ \
  652. } \
  653. } while(0)
  654. #define apclose(p) do { \
  655. if((p) != NULL) { \
  656. pclose(p); \
  657. (p) = NULL; \
  658. (void)(p); /* Fix value never used warning at end of routines */ \
  659. } \
  660. } while(0)
  661. /*
  662. * Return the number of elements in an array.
  663. */
  664. #define am_countof(a) (int)(SIZEOF(a) / SIZEOF((a)[0]))
  665. /*
  666. * min/max. Don't do something like
  667. *
  668. * x = min(y++, z);
  669. *
  670. * because the increment will be duplicated.
  671. */
  672. #undef min
  673. #undef max
  674. #define min(a, b) ((a) < (b) ? (a) : (b))
  675. #define max(a, b) ((a) > (b) ? (a) : (b))
  676. /*
  677. * Utility bitmask manipulation macros.
  678. */
  679. #define SET(t, f) ((t) |= (f))
  680. #define CLR(t, f) ((t) &= ~((unsigned)(f)))
  681. #define ISSET(t, f) ((t) & (f))
  682. /*
  683. * Utility string macros. All assume a variable holds the current
  684. * character and the string pointer points to the next character to
  685. * be processed. Typical setup is:
  686. *
  687. * s = buffer;
  688. * ch = *s++;
  689. * skip_whitespace(s, ch);
  690. * ...
  691. *
  692. * If you advance the pointer "by hand" to skip over something, do
  693. * it like this:
  694. *
  695. * s += some_amount;
  696. * ch = s[-1];
  697. *
  698. * Note that ch has the character at the end of the just skipped field.
  699. * It is often useful to terminate a string, make a copy, then restore
  700. * the input like this:
  701. *
  702. * skip_whitespace(s, ch);
  703. * fp = s-1; ## save the start
  704. * skip_nonwhitespace(s, ch); ## find the end
  705. * p[-1] = '\0'; ## temporary terminate
  706. * field = stralloc(fp); ## make a copy
  707. * p[-1] = ch; ## restore the input
  708. *
  709. * The scanning macros are:
  710. *
  711. * skip_whitespace (ptr, var)
  712. * -- skip whitespace, but stops at a newline
  713. * skip_non_whitespace (ptr, var)
  714. * -- skip non whitespace
  715. * skip_non_whitespace_cs (ptr, var)
  716. * -- skip non whitespace, stop at comment
  717. * skip_integer (ptr, var)
  718. * -- skip an integer field
  719. * skip_line (ptr, var)
  720. * -- skip just past the next newline
  721. * strncmp_const (str, const_str)
  722. * -- compare str to const_str, a string constant
  723. * strncmp_const_skip (str, const_var, ptr, var)
  724. * -- like strncmp_const, but skip the string if a match is
  725. * found; this macro only tests for equality, discarding
  726. * ordering information.
  727. *
  728. * where:
  729. *
  730. * ptr -- string pointer
  731. * var -- current character
  732. *
  733. * These macros copy a non-whitespace field to a new buffer, and should
  734. * only be used if dynamic allocation is impossible (fixed size buffers
  735. * are asking for trouble):
  736. *
  737. * copy_string (ptr, var, field, len, fldptr)
  738. * -- copy a non-whitespace field
  739. * copy_string_cs (ptr, var, field, len, fldptr)
  740. * -- copy a non-whitespace field, stop at comment
  741. *
  742. * where:
  743. *
  744. * ptr -- string pointer
  745. * var -- current character
  746. * field -- area to copy to
  747. * len -- length of area (needs room for null byte)
  748. * fldptr -- work pointer used in move
  749. * if NULL on exit, the field was too small for the input
  750. */
  751. #define STR_SIZE 4096 /* a generic string buffer size */
  752. #define NUM_STR_SIZE 128 /* a generic number buffer size */
  753. #define skip_whitespace(ptr,c) do { \
  754. while((c) != '\n' && isspace(c)) (c) = *(ptr)++; \
  755. } while(0)
  756. #define skip_non_whitespace(ptr,c) do { \
  757. while((c) != '\0' && !isspace(c)) (c) = *(ptr)++; \
  758. } while(0)
  759. #define skip_non_whitespace_cs(ptr,c) do { \
  760. while((c) != '\0' && (c) != '#' && !isspace(c)) (c) = *(ptr)++; \
  761. } while(0)
  762. #define skip_non_integer(ptr,c) do { \
  763. while((c) != '\0' && !isdigit(c)) (c) = *(ptr)++; \
  764. } while(0)
  765. #define skip_integer(ptr,c) do { \
  766. if((c) == '+' || (c) == '-') (c) = *(ptr)++; \
  767. while(isdigit(c)) (c) = *(ptr)++; \
  768. } while(0)
  769. #define skip_quoted_string(ptr, c) do { \
  770. int iq = 0; \
  771. while (((c) != '\0') && !((iq == 0) && isspace(c))) { \
  772. if ((c) == '"') { \
  773. iq = !iq; \
  774. } else if (((c) == '\\') && (*(ptr) == '"')) { \
  775. (ptr)++; \
  776. } \
  777. (c) = *(ptr)++; \
  778. } \
  779. } while (0)
  780. #define skip_quoted_line(ptr, c) do { \
  781. int iq = 0; \
  782. while((c) && !((iq == 0) && ((c) == '\n'))) { \
  783. if ((c) == '"') \
  784. iq = !iq; \
  785. (c) = *(ptr)++; \
  786. } \
  787. if(c) \
  788. (c) = *(ptr)++; \
  789. } while(0)
  790. #define skip_line(ptr,c) do { \
  791. while((c) && (c) != '\n') \
  792. (c) = *(ptr)++; \
  793. if(c) \
  794. (c) = *(ptr)++; \
  795. } while(0)
  796. #define copy_string(ptr,c,f,l,fp) do { \
  797. (fp) = (f); \
  798. while((c) != '\0' && !isspace(c)) { \
  799. if((fp) >= (f) + (l) - 1) { \
  800. *(fp) = '\0'; \
  801. (fp) = NULL; \
  802. (void)(fp); /* Fix value never used warning at end of routines */ \
  803. break; \
  804. } \
  805. *(fp)++ = (c); \
  806. (c) = *(ptr)++; \
  807. } \
  808. if(fp) \
  809. *fp = '\0'; \
  810. } while(0)
  811. #define copy_string_cs(ptr,c,f,l,fp) do { \
  812. (fp) = (f); \
  813. while((c) != '\0' && (c) != '#' && !isspace(c)) { \
  814. if((fp) >= (f) + (l) - 1) { \
  815. *(fp) = '\0'; \
  816. (fp) = NULL; \
  817. break; \
  818. } \
  819. *(fp)++ = (c); \
  820. (c) = *(ptr)++; \
  821. } \
  822. if(fp) *fp = '\0'; \
  823. } while(0)
  824. #define is_dot_or_dotdot(s) \
  825. ((s)[0] == '.' \
  826. && ((s)[1] == '\0' \
  827. || ((s)[1] == '.' && (s)[2] == '\0')))
  828. #define strncmp_const(str, cnst) \
  829. strncmp((str), (cnst), sizeof((cnst))-1)
  830. /* (have to roll this up in an expression, so it can be used in if()) */
  831. #define strncmp_const_skip(str, cnst, ptr, var) \
  832. ((strncmp((str), (cnst), sizeof((cnst))-1) == 0)? \
  833. ((ptr)+=sizeof((cnst))-1, (var)=(ptr)[-1], 0) \
  834. :1)
  835. /* from amflock.c */
  836. extern int amflock(int fd, char *resource);
  837. extern int amroflock(int fd, char *resource);
  838. extern int amfunlock(int fd, char *resource);
  839. /* from file.c */
  840. extern int mkpdir(char *file, mode_t mode, uid_t uid, gid_t gid);
  841. extern int rmpdir(char *file, char *topdir);
  842. extern char *sanitise_filename(char *inp);
  843. extern char *old_sanitise_filename(char *inp);
  844. /* from old bsd-security.c */
  845. extern int debug;
  846. extern int check_security(struct sockaddr_storage *, char *, unsigned long, char **);
  847. /*
  848. * Handle functions which are not always declared on all systems. This
  849. * stops gcc -Wall and lint from complaining.
  850. */
  851. /* AIX #defines accept, and provides a prototype for the alternate name */
  852. #if !defined(HAVE_ACCEPT_DECL) && !defined(accept)
  853. extern int accept(int s, struct sockaddr *addr, socklen_t *addrlen);
  854. #endif
  855. #ifndef HAVE_ATOF_DECL
  856. extern double atof(const char *ptr);
  857. #endif
  858. #ifndef HAVE_BCOPY
  859. # define bcopy(from,to,n) ((void)memmove((to), (from), (n)))
  860. #else
  861. # ifndef HAVE_BCOPY_DECL
  862. extern void bcopy(const void *s1, void *s2, size_t n);
  863. # endif
  864. #endif
  865. #ifndef HAVE_BIND_DECL
  866. extern int bind(int s, const struct sockaddr *name, socklen_t namelen);
  867. #endif
  868. #ifndef HAVE_BZERO
  869. #define bzero(s,n) ((void)memset((s),0,(n)))
  870. #else
  871. # ifndef HAVE_BZERO_DECL
  872. extern void bzero(void *s, size_t n);
  873. # endif
  874. #endif
  875. #ifndef HAVE_CLOSELOG_DECL
  876. extern void closelog(void);
  877. #endif
  878. #ifndef HAVE_CONNECT_DECL
  879. extern int connect(int s, struct sockaddr *name, socklen_t namelen);
  880. #endif
  881. #if !defined(TEXTDB) && !defined(HAVE_DBM_OPEN_DECL)
  882. #undef DBM_INSERT
  883. #define DBM_INSERT 0
  884. #undef DBM_REPLACE
  885. #define DBM_REPLACE 1
  886. typedef struct {
  887. int dummy[10];
  888. } DBM;
  889. #ifndef HAVE_STRUCT_DATUM
  890. typedef struct {
  891. char *dptr;
  892. int dsize;
  893. } datum;
  894. #endif
  895. extern DBM *dbm_open(char *file, int flags, int mode);
  896. extern void dbm_close(DBM *db);
  897. extern datum dbm_fetch(DBM *db, datum key);
  898. extern datum dbm_firstkey(DBM *db);
  899. extern datum dbm_nextkey(DBM *db);
  900. extern int dbm_delete(DBM *db, datum key);
  901. extern int dbm_store(DBM *db, datum key, datum content, int flg);
  902. #endif
  903. #ifndef HAVE_FCLOSE_DECL
  904. extern int fclose(FILE *stream);
  905. #endif
  906. #ifndef HAVE_FFLUSH_DECL
  907. extern int fflush(FILE *stream);
  908. #endif
  909. #ifndef HAVE_FPRINTF_DECL
  910. extern int fprintf(FILE *stream, const char *format, ...);
  911. #endif
  912. #ifndef HAVE_FPUTC_DECL
  913. extern int fputc(int c, FILE *stream);
  914. #endif
  915. #ifndef HAVE_FPUTS_DECL
  916. extern int fputs(const char *s, FILE *stream);
  917. #endif
  918. #ifndef HAVE_FREAD_DECL
  919. extern size_t fread(void *ptr, size_t size, size_t nitems, FILE *stream);
  920. #endif
  921. #ifndef HAVE_FSEEK_DECL
  922. extern int fseek(FILE *stream, long offset, int ptrname);
  923. #endif
  924. #ifndef HAVE_FWRITE_DECL
  925. extern size_t fwrite(const void *ptr, size_t size, size_t nitems,
  926. FILE *stream);
  927. #endif
  928. #ifndef HAVE_GETHOSTNAME_DECL
  929. extern int gethostname(char *name, int namelen);
  930. #endif
  931. #ifndef HAVE_GETOPT_DECL
  932. extern char *optarg;
  933. extern int getopt(int argc, char * const *argv, const char *optstring);
  934. #endif
  935. /* AIX #defines getpeername, and provides a prototype for the alternate name */
  936. #if !defined(HAVE_GETPEERNAME_DECL) && !defined(getpeername)
  937. extern int getpeername(int s, struct sockaddr *name, socklen_t *namelen);
  938. #endif
  939. /* AIX #defines getsockname, and provides a prototype for the alternate name */
  940. #if !defined(HAVE_GETSOCKNAME_DECL) && !defined(getsockname)
  941. extern int getsockname(int s, struct sockaddr *name, socklen_t *namelen);
  942. #endif
  943. #ifndef HAVE_GETSOCKOPT_DECL
  944. extern int getsockopt(int s, int level, int optname, char *optval,
  945. socklen_t *optlen);
  946. #endif
  947. #ifndef HAVE_GETTIMEOFDAY_DECL
  948. # ifdef HAVE_TWO_ARG_GETTIMEOFDAY
  949. extern int gettimeofday(struct timeval *tp, struct timezone *tzp);
  950. # else
  951. extern int gettimeofday(struct timeval *tp);
  952. # endif
  953. #endif
  954. #ifndef HAVE_INITGROUPS
  955. # define initgroups(name,basegid) 0
  956. #else
  957. # ifndef HAVE_INITGROUPS_DECL
  958. extern int initgroups(const char *name, gid_t basegid);
  959. # endif
  960. #endif
  961. #ifndef HAVE_IOCTL_DECL
  962. extern int ioctl(int fildes, int request, ...);
  963. #endif
  964. #ifndef isnormal
  965. #ifndef HAVE_ISNORMAL
  966. #define isnormal(f) (((f) < 0.0) || ((f) > 0.0))
  967. #endif
  968. #endif
  969. #ifndef HAVE_LISTEN_DECL
  970. extern int listen(int s, int backlog);
  971. #endif
  972. #ifndef HAVE_LSTAT_DECL
  973. extern int lstat(const char *path, struct stat *buf);
  974. #endif
  975. #ifndef HAVE_MALLOC_DECL
  976. extern void *malloc (size_t size);
  977. #endif
  978. #ifndef HAVE_MEMMOVE_DECL
  979. #ifdef HAVE_MEMMOVE
  980. extern void *memmove(void *to, const void *from, size_t n);
  981. #else
  982. extern char *memmove(char *to, /*const*/ char *from, size_t n);
  983. #endif
  984. #endif
  985. #ifndef HAVE_MEMSET_DECL
  986. extern void *memset(void *s, int c, size_t n);
  987. #endif
  988. #ifndef HAVE_MKTEMP_DECL
  989. extern char *mktemp(char *template);
  990. #endif
  991. #ifndef HAVE_MKSTEMP_DECL
  992. extern int mkstemp(char *template);
  993. #endif
  994. #ifndef HAVE_MKTIME_DECL
  995. extern time_t mktime(struct tm *timeptr);
  996. #endif
  997. #ifndef HAVE_OPENLOG_DECL
  998. #ifdef LOG_AUTH
  999. extern void openlog(const char *ident, int logopt, int facility);
  1000. #else
  1001. extern void openlog(const char *ident, int logopt);
  1002. #endif
  1003. #endif
  1004. #ifndef HAVE_PCLOSE_DECL
  1005. extern int pclose(FILE *stream);
  1006. #endif
  1007. #ifndef HAVE_PERROR_DECL
  1008. extern void perror(const char *s);
  1009. #endif
  1010. #ifndef HAVE_PRINTF_DECL
  1011. extern int printf(const char *format, ...);
  1012. #endif
  1013. #ifndef HAVE_PUTS_DECL
  1014. extern int puts(const char *s);
  1015. #endif
  1016. #ifndef HAVE_REALLOC_DECL
  1017. extern void *realloc(void *ptr, size_t size);
  1018. #endif
  1019. /* AIX #defines recvfrom, and provides a prototype for the alternate name */
  1020. #if !defined(HAVE_RECVFROM_DECL) && !defined(recvfrom)
  1021. extern int recvfrom(int s, char *buf, int len, int flags,
  1022. struct sockaddr *from, socklen_t *fromlen);
  1023. #endif
  1024. #ifndef HAVE_REMOVE_DECL
  1025. extern int remove(const char *path);
  1026. #endif
  1027. #ifndef HAVE_RENAME_DECL
  1028. extern int rename(const char *old, const char *new);
  1029. #endif
  1030. #ifndef HAVE_REWIND_DECL
  1031. extern void rewind(FILE *stream);
  1032. #endif
  1033. #ifndef HAVE_RUSEROK_DECL
  1034. extern int ruserok(const char *rhost, int suser,
  1035. const char *ruser, const char *luser);
  1036. #endif
  1037. #ifndef HAVE_SELECT_DECL
  1038. extern int select(int nfds,
  1039. SELECT_ARG_TYPE *readfds,
  1040. SELECT_ARG_TYPE *writefds,
  1041. SELECT_ARG_TYPE *exceptfds,
  1042. struct timeval *timeout);
  1043. #endif
  1044. #ifndef HAVE_SENDTO_DECL
  1045. extern int sendto(int s, const char *msg, int len, int flags,
  1046. const struct sockaddr *to, int tolen);
  1047. #endif
  1048. #ifdef HAVE_SETRESGID
  1049. #define setegid(x) setresgid((gid_t)-1,(x),(gid_t)-1)
  1050. #ifndef HAVE_SETRESGID_DECL
  1051. extern int setresgid(gid_t rgid, gid_t egid, gid_t sgid);
  1052. #endif
  1053. #else
  1054. #ifndef HAVE_SETEGID_DECL
  1055. extern int setegid(gid_t egid);
  1056. #endif
  1057. #endif
  1058. #ifdef HAVE_SETRESUID
  1059. #define seteuid(x) setresuid((uid_t)-1,(x),(uid_t)-1)
  1060. #ifndef HAVE_SETRESUID_DECL
  1061. extern int setresuid(uid_t ruid, uid_t euid, uid_t suid);
  1062. #endif
  1063. #else
  1064. #ifndef HAVE_SETEUID_DECL
  1065. extern int seteuid(uid_t euid);
  1066. #endif
  1067. #endif
  1068. #ifndef HAVE_SETPGID_DECL
  1069. #ifdef HAVE_SETPGID
  1070. extern int setpgid(pid_t pid, pid_t pgid);
  1071. #endif
  1072. #endif
  1073. #ifndef HAVE_SETPGRP_DECL
  1074. #ifdef SETPGRP_VOID
  1075. extern pid_t setpgrp(void);
  1076. #else
  1077. extern pid_t setpgrp(pid_t pgrp, pid_t pid);
  1078. #endif
  1079. #endif
  1080. #ifndef HAVE_SETSOCKOPT_DECL
  1081. extern int setsockopt(int s, int level, int optname,
  1082. const char *optval, int optlen);
  1083. #endif
  1084. #ifdef HAVE_SHMGET
  1085. #ifndef HAVE_SHMAT_DECL
  1086. extern void *shmat(int shmid, const SHM_ARG_TYPE *shmaddr, int shmflg);
  1087. #endif
  1088. #ifndef HAVE_SHMCTL_DECL
  1089. extern int shmctl(int shmid, int cmd, struct shmid_ds *buf);
  1090. #endif
  1091. #ifndef HAVE_SHMDT_DECL
  1092. extern int shmdt(SHM_ARG_TYPE *shaddr);
  1093. #endif
  1094. #ifndef HAVE_SHMGET_DECL
  1095. extern int shmget(key_t key, size_t size, int shmflg);
  1096. #endif
  1097. #endif
  1098. #ifndef HAVE_SNPRINTF_DECL
  1099. #include "arglist.h"
  1100. int snprintf(char *buf, size_t len, const char *format,...)
  1101. __attribute__((format(printf,3,4)));
  1102. #endif
  1103. #ifndef HAVE_VSNPRINTF_DECL
  1104. #include "arglist.h"
  1105. int vsnprintf(char *buf, size_t len, const char *format, va_list ap);
  1106. #endif
  1107. #ifndef HAVE_SOCKET_DECL
  1108. extern int socket(int domain, int type, int protocol);
  1109. #endif
  1110. #ifndef HAVE_SOCKETPAIR_DECL
  1111. extern int socketpair(int domain, int type, int protocol, int sv[2]);
  1112. #endif
  1113. #ifndef HAVE_SSCANF_DECL
  1114. extern int sscanf(const char *s, const char *format, ...);
  1115. #endif
  1116. #ifndef HAVE_STRCASECMP_DECL
  1117. extern int strcasecmp(const char *s1, const char *s2);
  1118. #endif
  1119. #ifndef HAVE_STRERROR_DECL
  1120. extern char *strerror(int errnum);
  1121. #endif
  1122. #ifndef HAVE_STRFTIME_DECL
  1123. extern size_t strftime(char *s, size_t maxsize, const char *format,
  1124. const struct tm *timeptr);
  1125. #endif
  1126. #ifndef HAVE_STRNCASECMP_DECL
  1127. extern int strncasecmp(const char *s1, const char *s2, int n);
  1128. #endif
  1129. #ifndef HAVE_SYSLOG_DECL
  1130. extern void syslog(int priority, const char *logstring, ...)
  1131. __attribute__ ((format (printf, 2, 3)));
  1132. #endif
  1133. #ifndef HAVE_SYSTEM_DECL
  1134. extern int system(const char *string);
  1135. #endif
  1136. #ifndef HAVE_TIME_DECL
  1137. extern time_t time(time_t *tloc);
  1138. #endif
  1139. #ifndef HAVE_TOLOWER_DECL
  1140. extern int tolower(int c);
  1141. #endif
  1142. #ifndef HAVE_TOUPPER_DECL
  1143. extern int toupper(int c);
  1144. #endif
  1145. #ifndef HAVE_UNGETC_DECL
  1146. extern int ungetc(int c, FILE *stream);
  1147. #endif
  1148. #ifndef HAVE_VFPRINTF_DECL
  1149. #include "arglist.h"
  1150. extern int vfprintf(FILE *stream, const char *format, va_list ap);
  1151. #endif
  1152. #ifndef HAVE_VPRINTF_DECL
  1153. #include "arglist.h"
  1154. extern int vprintf(const char *format, va_list ap);
  1155. #endif
  1156. /* GNULIB include */
  1157. #ifndef CONFIGURE_TEST
  1158. #include "getaddrinfo.h"
  1159. #include "inet_ntop.h"
  1160. #endif
  1161. #if !defined(S_ISCHR) && defined(_S_IFCHR) && defined(_S_IFMT)
  1162. #define S_ISCHR(mode) (((mode) & _S_IFMT) == _S_IFCHR)
  1163. #endif
  1164. #if !defined(S_ISREG) && defined(_S_IFREG) && defined(_S_IFMT)
  1165. #define S_ISREG(mode) (((mode) & _S_IFMT) == _S_IFREG)
  1166. #endif
  1167. #ifndef HAVE_WAITPID
  1168. #ifdef HAVE_WAIT4
  1169. #define waitpid(pid,status,options) wait4(pid,status,options,0)
  1170. #else
  1171. extern pid_t waitpid(pid_t pid, amwait_t *stat_loc, int options);
  1172. #endif
  1173. #endif
  1174. #ifndef HAVE_WRITEV_DECL
  1175. extern ssize_t writev(int fd, const struct iovec *iov, int iovcnt);
  1176. #endif
  1177. #ifndef STDIN_FILENO
  1178. #define STDIN_FILENO 0
  1179. #endif
  1180. #ifndef STDOUT_FILENO
  1181. #define STDOUT_FILENO 1
  1182. #endif
  1183. #ifndef STDERR_FILENO
  1184. #define STDERR_FILENO 2
  1185. #endif
  1186. /* S_ISDIR is not defined on Nextstep */
  1187. #ifndef S_ISDIR
  1188. #if defined(_S_IFMT) && defined(_S_IFDIR)
  1189. #define S_ISDIR(mode) (((mode) & (_S_IFMT)) == (_S_IFDIR))
  1190. #else
  1191. #error Don t know how to define S_ISDIR
  1192. #endif
  1193. #endif
  1194. #if SIZEOF_SIZE_T == SIZEOF_INT
  1195. # define SIZE_T_FMT "%u"
  1196. # define SIZE_T_FMT_TYPE unsigned
  1197. # define SIZE_T_ATOI (size_t)atoi
  1198. # ifndef SIZE_MAX
  1199. # define SIZE_MAX UINT_MAX
  1200. # endif
  1201. #else
  1202. # define SIZE_T_FMT "%lu"
  1203. # define SIZE_T_FMT_TYPE unsigned long
  1204. # define SIZE_T_ATOI (size_t)atol
  1205. # ifndef SIZE_MAX
  1206. # define SIZE_MAX ULONG_MAX
  1207. # endif
  1208. #endif
  1209. #if SIZEOF_SSIZE_T == SIZEOF_INT
  1210. # define SSIZE_T_FMT "%d"
  1211. # define SSIZE_T_FMT_TYPE int
  1212. # define SSIZE_T_ATOI (ssize_t)atoi
  1213. # ifndef SSIZE_MAX
  1214. # define SSIZE_MAX INT_MAX
  1215. # endif
  1216. # ifndef SSIZE_MIN
  1217. # define SSIZE_MIN INT_MIN
  1218. # endif
  1219. #else
  1220. # define SSIZE_T_FMT "%ld"
  1221. # define SSIZE_T_FMT_TYPE long
  1222. # define SSIZE_T_ATOI (ssize_t)atol
  1223. # ifndef SSIZE_MAX
  1224. # define SSIZE_MAX LONG_MAX
  1225. # endif
  1226. # ifndef SSIZE_MIN
  1227. # define SSIZE_MIN LONG_MIN
  1228. # endif
  1229. #endif
  1230. #if SIZEOF_TIME_T == SIZEOF_INT
  1231. # define TIME_T_FMT "%u"
  1232. # define TIME_T_FMT_TYPE unsigned
  1233. # define TIME_T_ATOI (time_t)atoi
  1234. # ifndef TIME_MAX
  1235. # define TIME_MAX UINT_MAX
  1236. # endif
  1237. #else
  1238. # define TIME_T_FMT "%lu"
  1239. # define TIME_T_FMT_TYPE unsigned long
  1240. # define TIME_T_ATOI (time_t)atol
  1241. # ifndef TIME_MAX
  1242. # define TIME_MAX ULONG_MAX
  1243. # endif
  1244. #endif
  1245. #if SIZEOF_OFF_T > SIZEOF_LONG
  1246. # define OFF_T_FMT LL_FMT
  1247. # define OFF_T_RFMT LL_RFMT
  1248. # define OFF_T_FMT_TYPE long long
  1249. # ifdef HAVE_ATOLL
  1250. # define OFF_T_ATOI (off_t)atoll
  1251. # else
  1252. # define OFF_T_ATOI (off_t)atol
  1253. # endif
  1254. # ifdef HAVE_STRTOLL
  1255. # define OFF_T_STRTOL (off_t)strtoll
  1256. # else
  1257. # define OFF_T_STRTOL (off_t)strtol
  1258. # endif
  1259. #else
  1260. # if SIZEOF_OFF_T == SIZEOF_LONG
  1261. # define OFF_T_FMT "%ld"
  1262. # define OFF_T_RFMT "ld"
  1263. # define OFF_T_FMT_TYPE long
  1264. # define OFF_T_ATOI (off_t)atol
  1265. # define OFF_T_STRTOL (off_t)strtol
  1266. # else
  1267. # define OFF_T_FMT "%d"
  1268. # define OFF_T_RFMT "d"
  1269. # define OFF_T_FMT_TYPE int
  1270. # define OFF_T_ATOI (off_t)atoi
  1271. # define OFF_T_STRTOL (off_t)strtol
  1272. # endif
  1273. #endif
  1274. #if SIZEOF_OFF_T == 8
  1275. # ifdef OFF_MAX
  1276. # define AM64_MAX (off_t)(OFF_MAX)
  1277. # else
  1278. # define AM64_MAX (off_t)(9223372036854775807LL)
  1279. # endif
  1280. # ifdef OFF_MIN
  1281. # define AM64_MIN (off_t)(OFF_MIN)
  1282. # else
  1283. # define AM64_MIN (off_t)(-9223372036854775807LL -1LL)
  1284. # endif
  1285. # define AM64_FMT OFF_T_FMT
  1286. #else
  1287. #if SIZEOF_LONG == 8
  1288. # ifdef LONG_MAX
  1289. # define AM64_MAX (off_t)(LONG_MAX)
  1290. # else
  1291. # define AM64_MAX (off_t)9223372036854775807L
  1292. # endif
  1293. # ifdef LONG_MIN
  1294. # define AM64_MIN (off_t)(LONG_MIN)
  1295. # else
  1296. # define AM64_MIN (off_t)(-9223372036854775807L -1L)
  1297. # endif
  1298. # define AM64_FMT "%ld"
  1299. #else
  1300. #if SIZEOF_LONG_LONG == 8
  1301. # ifdef LONG_LONG_MAX
  1302. # define AM64_MAX (off_t)(LONG_LONG_MAX)
  1303. # else
  1304. # define AM64_MAX (off_t)9223372036854775807LL
  1305. # endif
  1306. # ifdef LONG_LONG_MIN
  1307. # define AM64_MIN (off_t)(LONG_LONG_MIN)
  1308. # else
  1309. # define AM64_MIN (off_t)(-9223372036854775807LL -1LL)
  1310. # endif
  1311. # define AM64_FMT LL_FMT
  1312. #else
  1313. #if SIZEOF_INTMAX_T == 8
  1314. # ifdef INTMAX_MAX
  1315. # define AM64_MAX (off_t)(INTMAX_MAX)
  1316. # else
  1317. # define AM64_MAX (off_t)9223372036854775807LL
  1318. # endif
  1319. # ifdef INTMAX_MIN
  1320. # define AM64_MIN (off_t)(INTMAX_MIN)
  1321. # else
  1322. # define AM64_MIN (off_t)(-9223372036854775807LL -1LL)
  1323. # endif
  1324. # define AM64_FMT LL_FMT
  1325. #else /* no 64 bits type found, use long. */
  1326. # ifdef LONG_MAX
  1327. # define AM64_MAX (off_t)(LONG_MAX)
  1328. # else
  1329. # define AM64_MAX (off_t)2147483647
  1330. # endif
  1331. # ifdef LONG_MIN
  1332. # define AM64_MIN (off_t)(LONG_MIN)
  1333. # else
  1334. # define AM64_MIN (off_t)(-2147483647 -1)
  1335. # endif
  1336. # define AM64_FMT "%ld"
  1337. #endif
  1338. #endif
  1339. #endif
  1340. #endif
  1341. #ifdef HAVE_LIBREADLINE
  1342. # ifdef HAVE_READLINE_READLINE_H
  1343. # include <readline/readline.h>
  1344. # ifdef HAVE_READLINE_HISTORY_H
  1345. # include <readline/history.h>
  1346. # endif
  1347. # else
  1348. # ifdef HAVE_READLINE_H
  1349. # include <readline.h>
  1350. # ifdef HAVE_HISTORY_H
  1351. # include <history.h>
  1352. # endif
  1353. # else
  1354. # undef HAVE_LIBREADLINE
  1355. # endif
  1356. # endif
  1357. #else
  1358. char * readline(const char *prompt);
  1359. void add_history(const char *line);
  1360. #endif
  1361. #define BIND_CYCLE_RETRIES 120 /* Total of 30 minutes */
  1362. #define DBG_SUBDIR_SERVER "server"
  1363. #define DBG_SUBDIR_CLIENT "client"
  1364. #define DBG_SUBDIR_AMANDAD "amandad"
  1365. #define MAX_DUMPERS 63
  1366. #ifndef NI_MAXHOST
  1367. #define NI_MAXHOST 1025
  1368. #endif
  1369. #define _(x) x
  1370. #ifndef AI_V4MAPPED
  1371. #define AI_V4MAPPED 0
  1372. #endif
  1373. #ifndef AI_ALL
  1374. #define AI_ALL 0
  1375. #endif
  1376. #endif /* !AMANDA_H */