PageRenderTime 62ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

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

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