PageRenderTime 66ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 1ms

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

#
C Header | 1253 lines | 1003 code | 90 blank | 160 comment | 44 complexity | ec3a663bb09b49d3cd37f3e0639d890a 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. #include <glib.h>
  34. #include <glib/gprintf.h>
  35. #include "amflock.h"
  36. #ifdef HAVE_CONFIG_H
  37. /* use a relative path here to avoid conflicting with Perl's config.h. */
  38. #include "../config/config.h"
  39. #endif
  40. /*
  41. * Force large file source even if configure guesses wrong.
  42. */
  43. #ifndef _LARGE_FILE_SOURCE
  44. #define _LARGE_FILES 1
  45. #endif
  46. #ifndef _LARGEFILE64_SOURCE
  47. #define _LARGEFILE64_SOURCE 1
  48. #endif
  49. #ifndef _FILE_OFFSET_BITS
  50. #define _FILE_OFFSET_BITS 64
  51. #endif
  52. #ifdef HAVE_SYS_TYPES_H
  53. # include <sys/types.h>
  54. #endif
  55. /* gnulib creates this header locally if the system doesn't provide it */
  56. #include <stdint.h>
  57. /*
  58. * I would prefer that each Amanda module include only those system headers
  59. * that are locally needed, but on most Unixes the system header files are not
  60. * protected against multiple inclusion, so this can lead to problems.
  61. *
  62. * Also, some systems put key files in different places, so by including
  63. * everything here the rest of the system is isolated from such things.
  64. */
  65. #ifdef HAVE_ALLOCA_H
  66. # include <alloca.h>
  67. #endif
  68. /* from the autoconf documentation */
  69. #ifdef HAVE_DIRENT_H
  70. # include <dirent.h>
  71. # define NAMLEN(dirent) strlen((dirent)->d_name)
  72. #else
  73. # define dirent direct
  74. # define NAMLEN(dirent) (dirent)->d_namlen
  75. # if HAVE_SYS_NDIR_H
  76. # include <sys/ndir.h>
  77. # endif
  78. # if HAVE_SYS_DIR_H
  79. # include <sys/dir.h>
  80. # endif
  81. # if HAVE_NDIR_H
  82. # include <ndir.h>
  83. # endif
  84. #endif
  85. #ifdef ENABLE_NLS
  86. # include <libintl.h>
  87. # include <locale.h>
  88. # define plural(String1, String2, Count) \
  89. (((Count) == 1) ? (String1) : (String2))
  90. #else
  91. # define plural(String1, String2, Count) \
  92. (((Count) == 1) ? (String1) : (String2))
  93. # define setlocale(Which, Locale)
  94. # define textdomain(Domain)
  95. # define bindtextdomain(Package, Directory)
  96. # define gettext(String) String
  97. # define dgettext(Domain, String) String
  98. # define dcgettext(Domain, String, Catagory) String
  99. # define ngettext(String1, String2, Count) \
  100. plural((String1), (String2), (Count))
  101. # define dngettext(Domain, String1, String2, Count) \
  102. plural((String1), (String2), (Count))
  103. # define dcngettext(Domain, String1, String2, Count, Catagory) \
  104. plural((String1), (String2), (Count))
  105. #endif
  106. #define T_(String) String
  107. #ifndef SWIG /* TODO: make this go away */
  108. #define _(String) dgettext("amanda", (String))
  109. #endif
  110. #ifdef HAVE_FCNTL_H
  111. # include <fcntl.h>
  112. #endif
  113. #ifdef HAVE_GRP_H
  114. # include <grp.h>
  115. #endif
  116. #if defined(USE_DB_H)
  117. # include <db.h>
  118. #else
  119. #if defined(USE_DBM_H)
  120. # include <dbm.h>
  121. #else
  122. #if defined(USE_GDBM_H)
  123. # include <gdbm.h>
  124. #else
  125. #if defined(USE_NDBM_H)
  126. # include <ndbm.h>
  127. #endif
  128. #endif
  129. #endif
  130. #endif
  131. #ifdef HAVE_NETDB_H
  132. # include <netdb.h>
  133. #endif
  134. #ifdef TIME_WITH_SYS_TIME
  135. # include <sys/time.h>
  136. # include <time.h>
  137. #else
  138. # ifdef HAVE_SYS_TIME_H
  139. # include <sys/time.h>
  140. # else
  141. # include <time.h>
  142. # endif
  143. #endif
  144. #ifdef HAVE_LIBC_H
  145. # include <libc.h>
  146. #endif
  147. #ifdef HAVE_STDLIB_H
  148. # include <stdlib.h>
  149. #endif
  150. #ifdef HAVE_LIBGEN_H
  151. # include <libgen.h>
  152. #endif
  153. #ifdef HAVE_STRING_H
  154. # include <string.h>
  155. #endif
  156. #ifdef HAVE_STRINGS_H
  157. # include <strings.h>
  158. #endif
  159. #ifdef HAVE_SYSLOG_H
  160. # include <syslog.h>
  161. #endif
  162. #ifdef HAVE_MATH_H
  163. # include <math.h>
  164. #endif
  165. #ifdef HAVE_SYS_FILE_H
  166. # include <sys/file.h>
  167. #endif
  168. #ifdef HAVE_SYS_IOCTL_H
  169. # include <sys/ioctl.h>
  170. #endif
  171. #ifdef HAVE_LIMITS_H
  172. #include <limits.h>
  173. #endif
  174. #ifdef HAVE_SYS_PARAM_H
  175. # include <sys/param.h>
  176. #endif
  177. #if defined(HAVE_SYS_IPC_H) && defined(HAVE_SYS_SHM_H)
  178. # include <sys/ipc.h>
  179. # include <sys/shm.h>
  180. #else
  181. # ifdef HAVE_SYS_MMAN_H
  182. # include <sys/mman.h>
  183. # endif
  184. #endif
  185. #ifdef HAVE_SYS_SELECT_H
  186. # include <sys/select.h>
  187. #endif
  188. #ifdef HAVE_SYS_STAT_H
  189. # include <sys/stat.h>
  190. #endif
  191. #ifdef HAVE_SYS_UIO_H
  192. # include <sys/uio.h>
  193. #else
  194. struct iovec {
  195. void *iov_base;
  196. int iov_len;
  197. };
  198. #endif
  199. #ifdef HAVE_WAIT_H
  200. # include <wait.h>
  201. #endif
  202. #ifdef HAVE_SYS_WAIT_H
  203. # include <sys/wait.h>
  204. #endif
  205. #ifdef HAVE_STDARG_H
  206. #include <stdarg.h>
  207. #endif
  208. #ifdef WAIT_USES_INT
  209. typedef int amwait_t;
  210. # ifndef WEXITSTATUS
  211. # define WEXITSTATUS(stat_val) (*(unsigned*)&(stat_val) >> 8)
  212. # endif
  213. # ifndef WTERMSIG
  214. # define WTERMSIG(stat_val) (*(unsigned*)&(stat_val) & 0x7F)
  215. # endif
  216. # ifndef WIFEXITED
  217. # define WIFEXITED(stat_val) ((*(unsigned*)&(stat_val) & 255) == 0)
  218. # endif
  219. #else
  220. # ifdef WAIT_USES_UNION
  221. typedef union wait amwait_t;
  222. # ifndef WEXITSTATUS
  223. # define WEXITSTATUS(stat_val) (((amwait_t*)&(stat_val))->w_retcode)
  224. # endif
  225. # ifndef WTERMSIG
  226. # define WTERMSIG(stat_val) (((amwait_t*)&(stat_val))->w_termsig)
  227. # endif
  228. # ifndef WIFEXITED
  229. # define WIFEXITED(stat_val) (WTERMSIG(stat_val) == 0)
  230. # endif
  231. # else
  232. typedef int amwait_t;
  233. # ifndef WEXITSTATUS
  234. # define WEXITSTATUS(stat_val) (*(unsigned*)&(stat_val) >> 8)
  235. # endif
  236. # ifndef WTERMSIG
  237. # define WTERMSIG(stat_val) (*(unsigned*)&(stat_val) & 0x7F)
  238. # endif
  239. # ifndef WIFEXITED
  240. # define WIFEXITED(stat_val) ((*(unsigned*)&(stat_val) & 255) == 0)
  241. # endif
  242. # endif
  243. #endif
  244. #ifndef WIFSIGNALED
  245. # define WIFSIGNALED(stat_val) (WTERMSIG(stat_val) != 0)
  246. #endif
  247. #ifdef HAVE_UNISTD_H
  248. # include <unistd.h>
  249. #endif
  250. #ifdef HAVE_NETINET_IN_H
  251. # include <netinet/in.h>
  252. #endif
  253. #include <ctype.h>
  254. #include <errno.h>
  255. #include <pwd.h>
  256. #include <signal.h>
  257. #include <setjmp.h>
  258. #include <stdio.h>
  259. #include <sys/resource.h>
  260. #include <sys/socket.h>
  261. #ifdef HAVE_ARPA_INET_H
  262. #include <arpa/inet.h>
  263. #endif
  264. /* Support for missing IPv6 components */
  265. #ifndef HAVE_SOCKADDR_STORAGE
  266. # define sockaddr_storage sockaddr_in
  267. # define ss_family sin_family
  268. #endif
  269. #ifdef WORKING_IPV6
  270. #define INET6
  271. #endif
  272. #ifndef INET_ADDRSTRLEN
  273. #define INET_ADDRSTRLEN 16
  274. #endif
  275. #if !defined(HAVE_SIGACTION) && defined(HAVE_SIGVEC)
  276. /* quick'n'dirty hack for NextStep31 */
  277. # define sa_flags sv_flags
  278. # define sa_handler sv_handler
  279. # define sa_mask sv_mask
  280. # define sigaction sigvec
  281. # define sigemptyset(mask) /* no way to clear pending signals */
  282. #endif
  283. /*
  284. * Most Unixen declare errno in <errno.h>, some don't. Some multithreaded
  285. * systems have errno as a per-thread macro. So, we have to be careful.
  286. */
  287. #ifndef errno
  288. extern int errno;
  289. #endif
  290. /*
  291. * Some compilers have int for type of sizeof() some use size_t.
  292. * size_t is the one we want...
  293. */
  294. #define SIZEOF(x) (size_t)sizeof(x)
  295. /*
  296. * Some older BSD systems don't have these FD_ macros, so if not, provide them.
  297. */
  298. #if !defined(FD_SET) || defined(LINT) || defined(__lint)
  299. # undef FD_SETSIZE
  300. # define FD_SETSIZE (int)(SIZEOF(fd_set) * CHAR_BIT)
  301. # undef FD_SET
  302. # define FD_SET(n, p) (((fd_set *)(p))->fds_bits[(n)/WORD_BIT] |= (int)((1 << ((n) % WORD_BIT))))
  303. # undef FD_CLR
  304. # define FD_CLR(n, p) (((fd_set *)(p))->fds_bits[(n)/WORD_BIT] &= (int)(~(1 << ((n) % WORD_BIT))))
  305. # undef FD_ISSET
  306. # define FD_ISSET(n, p) (((fd_set *)(p))->fds_bits[(n)/WORD_BIT] & (1 << ((n) % WORD_BIT)))
  307. # undef FD_ZERO
  308. # define FD_ZERO(p) memset((p), 0, SIZEOF(*(p)))
  309. #endif
  310. #ifndef FD_COPY
  311. # define FD_COPY(p, q) memcpy((q), (p), SIZEOF(*(p)))
  312. #endif
  313. /*
  314. * Define MAX_HOSTNAME_LENGTH as the size of arrays to hold hostname's.
  315. */
  316. #undef MAX_HOSTNAME_LENGTH
  317. #define MAX_HOSTNAME_LENGTH 1025
  318. /*
  319. * If void is broken, substitute char.
  320. */
  321. #ifdef BROKEN_VOID
  322. # define void char
  323. #endif
  324. #define stringize(x) #x
  325. #define stringconcat(x, y) x ## y
  326. /* amanda #days calculation, with roundoff */
  327. #define SECS_PER_DAY (24*60*60)
  328. #define days_diff(a, b) (int)(((b) - (a) + SECS_PER_DAY/2) / SECS_PER_DAY)
  329. /* Global constants. */
  330. #ifndef AMANDA_SERVICE_NAME
  331. #define AMANDA_SERVICE_NAME "amanda"
  332. #endif
  333. #ifndef KAMANDA_SERVICE_NAME
  334. #define KAMANDA_SERVICE_NAME "kamanda"
  335. #endif
  336. #ifndef SERVICE_SUFFIX
  337. #define SERVICE_SUFFIX ""
  338. #endif
  339. #ifndef AMANDA_SERVICE_DEFAULT
  340. #define AMANDA_SERVICE_DEFAULT ((in_port_t)10080)
  341. #endif
  342. #ifndef KAMANDA_SERVICE_DEFAULT
  343. #define KAMANDA_SERVICE_DEFAULT ((in_port_t)10081)
  344. #endif
  345. #define am_round(v,u) ((((v) + (u) - 1) / (u)) * (u))
  346. #define am_floor(v,u) (((v) / (u)) * (u))
  347. /* Holding disk block size. Do not even think about changint this! :-) */
  348. #define DISK_BLOCK_KB 32
  349. #define DISK_BLOCK_BYTES (DISK_BLOCK_KB * 1024)
  350. /* Maximum size of a tape block */
  351. /* MAX_TAPE_BLOCK_KB is defined in config.h */
  352. /* by configure --with-maxtapeblocksize */
  353. #define MAX_TAPE_BLOCK_BYTES (MAX_TAPE_BLOCK_KB*1024)
  354. /* Maximum length of tape label, plus one for null-terminator. */
  355. #define MAX_TAPE_LABEL_LEN (10240)
  356. #define MAX_TAPE_LABEL_BUF (MAX_TAPE_LABEL_LEN+1)
  357. #define MAX_TAPE_LABEL_FMT "%10240s"
  358. #include "debug.h"
  359. #include "file.h"
  360. void *debug_alloc(const char *file, int line, size_t size);
  361. void *debug_newalloc(const char *file, int line, void *old, size_t size);
  362. char *debug_stralloc(const char *file, int line, const char *str);
  363. char *debug_newstralloc(const char *file, int line,
  364. char *oldstr, const char *newstr);
  365. char *debug_vstralloc(const char *file, int line, const char *str, ...);
  366. char *debug_newvstralloc(const char *file, int line,
  367. char *oldstr, const char *str, ...);
  368. char *debug_vstrallocf(const char *file, int line, const char *fmt,
  369. ...) G_GNUC_PRINTF(3, 4);
  370. char *debug_newvstrallocf(const char *file, int line, char *oldstr,
  371. const char *fmt, ...) G_GNUC_PRINTF(4, 5);
  372. /* Usage: vstrextend(foo, "bar, "baz", NULL). Extends the existing
  373. * string, or allocates a brand new one. */
  374. char *debug_vstrextend(const char *file, int line, char **oldstr, ...);
  375. #define alloc(s) debug_alloc(__FILE__, __LINE__, (s))
  376. #define newalloc(p,s) debug_newalloc(__FILE__, __LINE__, (p), (s))
  377. #define stralloc(s) debug_stralloc(__FILE__, __LINE__, (s))
  378. #define newstralloc(p,s) debug_newstralloc(__FILE__, __LINE__, (p), (s))
  379. #define vstralloc(...) debug_vstralloc(__FILE__,__LINE__,__VA_ARGS__)
  380. #define newvstralloc(...) debug_newvstralloc(__FILE__,__LINE__,__VA_ARGS__)
  381. #define vstrallocf(...) debug_vstrallocf(__FILE__,__LINE__,__VA_ARGS__)
  382. #define newvstrallocf(...) debug_newvstrallocf(__FILE__,__LINE__,__VA_ARGS__)
  383. #define vstrextend(...) debug_vstrextend(__FILE__,__LINE__,__VA_ARGS__)
  384. #define stralloc2(s1,s2) vstralloc((s1),(s2),NULL)
  385. #define newstralloc2(p,s1,s2) newvstralloc((p),(s1),(s2),NULL)
  386. #define vstrallocf(...) debug_vstrallocf(__FILE__,__LINE__,__VA_ARGS__)
  387. /*@only@*/ /*@null@*/ char *debug_agets(const char *file, int line, FILE *f);
  388. /*@only@*/ /*@null@*/ char *debug_areads(const char *file, int line, int fd);
  389. #define agets(f) debug_agets(__FILE__,__LINE__,(f))
  390. #define areads(f) debug_areads(__FILE__,__LINE__,(f))
  391. extern int debug_amtable_alloc(const char *file,
  392. int line,
  393. void **table,
  394. size_t *current,
  395. size_t elsize,
  396. size_t count,
  397. int bump,
  398. void (*init_func)(void *));
  399. #define amtable_alloc(t,c,s,n,b,f) debug_amtable_alloc(__FILE__, \
  400. __LINE__, \
  401. (t), \
  402. (c), \
  403. (s), \
  404. (n), \
  405. (b), \
  406. (f))
  407. extern void amtable_free(void **, size_t *);
  408. char ** safe_env(void);
  409. char * validate_regexp(const char *regex);
  410. char * validate_glob(const char *glob);
  411. char * clean_regex(const char *regex);
  412. int match(const char *regex, const char *str);
  413. int match_glob(const char *glob, const char *str);
  414. char * glob_to_regex(const char *glob);
  415. int match_tar(const char *glob, const char *str);
  416. char * tar_to_regex(const char *glob);
  417. int match_host(const char *glob, const char *host);
  418. int match_disk(const char *glob, const char *disk);
  419. int match_datestamp(const char *dateexp, const char *datestamp);
  420. int match_level(const char *levelexp, const char *level);
  421. time_t unctime(char *timestr);
  422. /*
  423. * amfree(ptr) -- if allocated, release space and set ptr to NULL.
  424. *
  425. * In general, this should be called instead of just free(), unless
  426. * the very next source line sets the pointer to a new value.
  427. */
  428. #define amfree(ptr) do { \
  429. if((ptr) != NULL) { \
  430. int e__errno = errno; \
  431. free(ptr); \
  432. (ptr) = NULL; \
  433. errno = e__errno; \
  434. (void)(ptr); /* Fix value never used warning at end of routines */ \
  435. } \
  436. } while (0)
  437. #define strappend(s1,s2) do { \
  438. char *t_t_t = (s1) ? stralloc2((s1),(s2)) : stralloc((s2)); \
  439. amfree((s1)); \
  440. (s1) = t_t_t; \
  441. } while(0)
  442. /*
  443. * Return the number of elements in an array.
  444. */
  445. #define am_countof(a) (int)(SIZEOF(a) / SIZEOF((a)[0]))
  446. /*
  447. * min/max. Don't do something like
  448. *
  449. * x = min(y++, z);
  450. *
  451. * because the increment will be duplicated.
  452. */
  453. #undef min
  454. #undef max
  455. #define min(a, b) ((a) < (b) ? (a) : (b))
  456. #define max(a, b) ((a) > (b) ? (a) : (b))
  457. /*
  458. * Utility bitmask manipulation macros.
  459. */
  460. #define SET(t, f) ((t) |= (f))
  461. #define CLR(t, f) ((t) &= ~((unsigned)(f)))
  462. #define ISSET(t, f) ((t) & (f))
  463. /*
  464. * Utility string macros. All assume a variable holds the current
  465. * character and the string pointer points to the next character to
  466. * be processed. Typical setup is:
  467. *
  468. * s = buffer;
  469. * ch = *s++;
  470. * skip_whitespace(s, ch);
  471. * ...
  472. *
  473. * If you advance the pointer "by hand" to skip over something, do
  474. * it like this:
  475. *
  476. * s += some_amount;
  477. * ch = s[-1];
  478. *
  479. * Note that ch has the character at the end of the just skipped field.
  480. * It is often useful to terminate a string, make a copy, then restore
  481. * the input like this:
  482. *
  483. * skip_whitespace(s, ch);
  484. * fp = s-1; ## save the start
  485. * skip_nonwhitespace(s, ch); ## find the end
  486. * p[-1] = '\0'; ## temporary terminate
  487. * field = stralloc(fp); ## make a copy
  488. * p[-1] = ch; ## restore the input
  489. *
  490. * The scanning macros are:
  491. *
  492. * skip_whitespace (ptr, var)
  493. * -- skip whitespace, but stops at a newline
  494. * skip_non_whitespace (ptr, var)
  495. * -- skip non whitespace
  496. * skip_non_whitespace_cs (ptr, var)
  497. * -- skip non whitespace, stop at comment
  498. * skip_integer (ptr, var)
  499. * -- skip an integer field
  500. * skip_line (ptr, var)
  501. * -- skip just past the next newline
  502. * strncmp_const (str, const_str)
  503. * -- compare str to const_str, a string constant
  504. * strncmp_const_skip (str, const_var, ptr, var)
  505. * -- like strncmp_const, but skip the string if a match is
  506. * found; this macro only tests for equality, discarding
  507. * ordering information.
  508. *
  509. * where:
  510. *
  511. * ptr -- string pointer
  512. * var -- current character
  513. *
  514. * These macros copy a non-whitespace field to a new buffer, and should
  515. * only be used if dynamic allocation is impossible (fixed size buffers
  516. * are asking for trouble):
  517. *
  518. * copy_string (ptr, var, field, len, fldptr)
  519. * -- copy a non-whitespace field
  520. * copy_string_cs (ptr, var, field, len, fldptr)
  521. * -- copy a non-whitespace field, stop at comment
  522. *
  523. * where:
  524. *
  525. * ptr -- string pointer
  526. * var -- current character
  527. * field -- area to copy to
  528. * len -- length of area (needs room for null byte)
  529. * fldptr -- work pointer used in move
  530. * if NULL on exit, the field was too small for the input
  531. */
  532. #define STR_SIZE 4096 /* a generic string buffer size */
  533. #define NUM_STR_SIZE 128 /* a generic number buffer size */
  534. #define skip_whitespace(ptr,c) do { \
  535. while((c) != '\n' && isspace((int)c)) (c) = *(ptr)++; \
  536. } while(0)
  537. #define skip_non_whitespace(ptr,c) do { \
  538. while((c) != '\0' && !isspace((int)c)) (c) = *(ptr)++; \
  539. } while(0)
  540. #define skip_non_whitespace_cs(ptr,c) do { \
  541. while((c) != '\0' && (c) != '#' && !isspace((int)c)) (c) = *(ptr)++;\
  542. } while(0)
  543. #define skip_non_integer(ptr,c) do { \
  544. while((c) != '\0' && !isdigit(c)) (c) = *(ptr)++; \
  545. } while(0)
  546. #define skip_integer(ptr,c) do { \
  547. if((c) == '+' || (c) == '-') (c) = *(ptr)++; \
  548. while(isdigit(c)) (c) = *(ptr)++; \
  549. } while(0)
  550. #define skip_quoted_string(ptr, c) do { \
  551. int iq = 0; \
  552. while (((c) != '\0') && !((iq == 0) && isspace((int)c))) { \
  553. if ((c) == '"') { \
  554. iq = !iq; \
  555. } else if (((c) == '\\') && (*(ptr) == '"')) { \
  556. (ptr)++; \
  557. } \
  558. (c) = *(ptr)++; \
  559. } \
  560. } while (0)
  561. #define skip_quoted_line(ptr, c) do { \
  562. int iq = 0; \
  563. while((c) && !((iq == 0) && ((c) == '\n'))) { \
  564. if ((c) == '"') \
  565. iq = !iq; \
  566. (c) = *(ptr)++; \
  567. } \
  568. if(c) \
  569. (c) = *(ptr)++; \
  570. } while(0)
  571. #define skip_line(ptr,c) do { \
  572. while((c) && (c) != '\n') \
  573. (c) = *(ptr)++; \
  574. if(c) \
  575. (c) = *(ptr)++; \
  576. } while(0)
  577. #define copy_string(ptr,c,f,l,fp) do { \
  578. (fp) = (f); \
  579. while((c) != '\0' && !isspace((int)c)) { \
  580. if((fp) >= (f) + (l) - 1) { \
  581. *(fp) = '\0'; \
  582. (fp) = NULL; \
  583. (void)(fp); /* Fix value never used warning at end of routines */ \
  584. break; \
  585. } \
  586. *(fp)++ = (c); \
  587. (c) = *(ptr)++; \
  588. } \
  589. if(fp) \
  590. *fp = '\0'; \
  591. } while(0)
  592. #define copy_string_cs(ptr,c,f,l,fp) do { \
  593. (fp) = (f); \
  594. while((c) != '\0' && (c) != '#' && !isspace((int)c)) { \
  595. if((fp) >= (f) + (l) - 1) { \
  596. *(fp) = '\0'; \
  597. (fp) = NULL; \
  598. break; \
  599. } \
  600. *(fp)++ = (c); \
  601. (c) = *(ptr)++; \
  602. } \
  603. if(fp) *fp = '\0'; \
  604. } while(0)
  605. #define is_dot_or_dotdot(s) \
  606. ((s)[0] == '.' \
  607. && ((s)[1] == '\0' \
  608. || ((s)[1] == '.' && (s)[2] == '\0')))
  609. #define strncmp_const(str, cnst) \
  610. strncmp((str), (cnst), sizeof((cnst))-1)
  611. /* (have to roll this up in an expression, so it can be used in if()) */
  612. #define strncmp_const_skip(str, cnst, ptr, var) \
  613. ((strncmp((str), (cnst), sizeof((cnst))-1) == 0)? \
  614. ((ptr)+=sizeof((cnst))-1, (var)=(ptr)[-1], 0) \
  615. :1)
  616. /* from old bsd-security.c */
  617. extern int debug;
  618. extern int check_security(struct sockaddr_storage *, char *, unsigned long, char **);
  619. /*
  620. * Handle functions which are not always declared on all systems. This
  621. * stops gcc -Wall and lint from complaining.
  622. */
  623. /* AIX #defines accept, and provides a prototype for the alternate name */
  624. #if !defined(HAVE_ACCEPT_DECL) && !defined(accept)
  625. extern int accept(int s, struct sockaddr *addr, socklen_t *addrlen);
  626. #endif
  627. #ifndef HAVE_ATOF_DECL
  628. extern double atof(const char *ptr);
  629. #endif
  630. #ifndef HAVE_BCOPY
  631. # define bcopy(from,to,n) ((void)memmove((to), (from), (n)))
  632. #else
  633. # ifndef HAVE_BCOPY_DECL
  634. extern void bcopy(const void *s1, void *s2, size_t n);
  635. # endif
  636. #endif
  637. #ifndef HAVE_BIND_DECL
  638. extern int bind(int s, const struct sockaddr *name, socklen_t namelen);
  639. #endif
  640. #ifndef HAVE_BZERO
  641. #define bzero(s,n) ((void)memset((s),0,(n)))
  642. #else
  643. # ifndef HAVE_BZERO_DECL
  644. extern void bzero(void *s, size_t n);
  645. # endif
  646. #endif
  647. #ifndef HAVE_CLOSELOG_DECL
  648. extern void closelog(void);
  649. #endif
  650. #ifndef HAVE_CONNECT_DECL
  651. extern int connect(int s, struct sockaddr *name, socklen_t namelen);
  652. #endif
  653. #ifndef HAVE_FCLOSE_DECL
  654. extern int fclose(FILE *stream);
  655. #endif
  656. #ifndef HAVE_FFLUSH_DECL
  657. extern int fflush(FILE *stream);
  658. #endif
  659. #ifndef HAVE_FPRINTF_DECL
  660. extern int fprintf(FILE *stream, const char *format, ...);
  661. #endif
  662. #ifndef HAVE_FPUTC_DECL
  663. extern int fputc(int c, FILE *stream);
  664. #endif
  665. #ifndef HAVE_FPUTS_DECL
  666. extern int fputs(const char *s, FILE *stream);
  667. #endif
  668. #ifndef HAVE_FREAD_DECL
  669. extern size_t fread(void *ptr, size_t size, size_t nitems, FILE *stream);
  670. #endif
  671. #ifndef HAVE_FSEEK_DECL
  672. extern int fseek(FILE *stream, long offset, int ptrname);
  673. #endif
  674. #ifndef HAVE_FWRITE_DECL
  675. extern size_t fwrite(const void *ptr, size_t size, size_t nitems,
  676. FILE *stream);
  677. #endif
  678. #ifndef HAVE_GETHOSTNAME_DECL
  679. extern int gethostname(char *name, int namelen);
  680. #endif
  681. #ifndef HAVE_GETOPT_DECL
  682. extern char *optarg;
  683. extern int getopt(int argc, char * const *argv, const char *optstring);
  684. #endif
  685. /* AIX #defines getpeername, and provides a prototype for the alternate name */
  686. #if !defined(HAVE_GETPEERNAME_DECL) && !defined(getpeername)
  687. extern int getpeername(int s, struct sockaddr *name, socklen_t *namelen);
  688. #endif
  689. /* AIX #defines getsockname, and provides a prototype for the alternate name */
  690. #if !defined(HAVE_GETSOCKNAME_DECL) && !defined(getsockname)
  691. extern int getsockname(int s, struct sockaddr *name, socklen_t *namelen);
  692. #endif
  693. #ifndef HAVE_GETSOCKOPT_DECL
  694. extern int getsockopt(int s, int level, int optname, char *optval,
  695. socklen_t *optlen);
  696. #endif
  697. #ifndef HAVE_INITGROUPS
  698. # define initgroups(name,basegid) 0
  699. #else
  700. # ifndef HAVE_INITGROUPS_DECL
  701. extern int initgroups(const char *name, gid_t basegid);
  702. # endif
  703. #endif
  704. #ifndef HAVE_IOCTL_DECL
  705. extern int ioctl(int fildes, int request, ...);
  706. #endif
  707. #ifndef isnormal
  708. #ifndef HAVE_ISNORMAL
  709. #define isnormal(f) (((f) < 0.0) || ((f) > 0.0))
  710. #endif
  711. #endif
  712. #ifndef HAVE_LISTEN_DECL
  713. extern int listen(int s, int backlog);
  714. #endif
  715. #ifndef HAVE_LSTAT_DECL
  716. extern int lstat(const char *path, struct stat *buf);
  717. #endif
  718. #ifndef HAVE_MALLOC_DECL
  719. extern void *malloc (size_t size);
  720. #endif
  721. #ifndef HAVE_MEMMOVE_DECL
  722. #ifdef HAVE_MEMMOVE
  723. extern void *memmove(void *to, const void *from, size_t n);
  724. #else
  725. extern char *memmove(char *to, /*const*/ char *from, size_t n);
  726. #endif
  727. #endif
  728. #ifndef HAVE_MEMSET_DECL
  729. extern void *memset(void *s, int c, size_t n);
  730. #endif
  731. #ifndef HAVE_MKTEMP_DECL
  732. extern char *mktemp(char *template);
  733. #endif
  734. #ifndef HAVE_MKSTEMP_DECL
  735. extern int mkstemp(char *template);
  736. #endif
  737. #ifndef HAVE_MKTIME_DECL
  738. extern time_t mktime(struct tm *timeptr);
  739. #endif
  740. #ifndef HAVE_OPENLOG_DECL
  741. #ifdef LOG_AUTH
  742. extern void openlog(const char *ident, int logopt, int facility);
  743. #else
  744. extern void openlog(const char *ident, int logopt);
  745. #endif
  746. #endif
  747. #ifndef HAVE_PCLOSE_DECL
  748. extern int pclose(FILE *stream);
  749. #endif
  750. #ifndef HAVE_PERROR_DECL
  751. extern void perror(const char *s);
  752. #endif
  753. #ifndef HAVE_PRINTF_DECL
  754. extern int printf(const char *format, ...);
  755. #endif
  756. #ifndef HAVE_PUTS_DECL
  757. extern int puts(const char *s);
  758. #endif
  759. #ifndef HAVE_REALLOC_DECL
  760. extern void *realloc(void *ptr, size_t size);
  761. #endif
  762. /* AIX #defines recvfrom, and provides a prototype for the alternate name */
  763. #if !defined(HAVE_RECVFROM_DECL) && !defined(recvfrom)
  764. extern int recvfrom(int s, char *buf, int len, int flags,
  765. struct sockaddr *from, socklen_t *fromlen);
  766. #endif
  767. #ifndef HAVE_REMOVE_DECL
  768. extern int remove(const char *path);
  769. #endif
  770. #ifndef HAVE_RENAME_DECL
  771. extern int rename(const char *old, const char *new);
  772. #endif
  773. #ifndef HAVE_REWIND_DECL
  774. extern void rewind(FILE *stream);
  775. #endif
  776. #ifndef HAVE_RUSEROK_DECL
  777. extern int ruserok(const char *rhost, int suser,
  778. const char *ruser, const char *luser);
  779. #endif
  780. #ifndef HAVE_SELECT_DECL
  781. extern int select(int nfds,
  782. SELECT_ARG_TYPE *readfds,
  783. SELECT_ARG_TYPE *writefds,
  784. SELECT_ARG_TYPE *exceptfds,
  785. struct timeval *timeout);
  786. #endif
  787. #ifndef HAVE_SENDTO_DECL
  788. extern int sendto(int s, const char *msg, int len, int flags,
  789. const struct sockaddr *to, int tolen);
  790. #endif
  791. #ifdef HAVE_SETRESGID
  792. #define setegid(x) setresgid((gid_t)-1,(x),(gid_t)-1)
  793. #ifndef HAVE_SETRESGID_DECL
  794. extern int setresgid(gid_t rgid, gid_t egid, gid_t sgid);
  795. #endif
  796. #else
  797. #ifndef HAVE_SETEGID_DECL
  798. extern int setegid(gid_t egid);
  799. #endif
  800. #endif
  801. #ifdef HAVE_SETRESUID
  802. #define seteuid(x) setresuid((uid_t)-1,(x),(uid_t)-1)
  803. #ifndef HAVE_SETRESUID_DECL
  804. extern int setresuid(uid_t ruid, uid_t euid, uid_t suid);
  805. #endif
  806. #else
  807. #ifndef HAVE_SETEUID_DECL
  808. extern int seteuid(uid_t euid);
  809. #endif
  810. #endif
  811. #ifndef HAVE_SETPGID_DECL
  812. #ifdef HAVE_SETPGID
  813. extern int setpgid(pid_t pid, pid_t pgid);
  814. #endif
  815. #endif
  816. #ifndef HAVE_SETPGRP_DECL
  817. #ifdef SETPGRP_VOID
  818. extern pid_t setpgrp(void);
  819. #else
  820. extern pid_t setpgrp(pid_t pgrp, pid_t pid);
  821. #endif
  822. #endif
  823. #ifndef HAVE_SETSOCKOPT_DECL
  824. extern int setsockopt(int s, int level, int optname,
  825. const char *optval, int optlen);
  826. #endif
  827. #ifdef HAVE_SHMGET
  828. #ifndef HAVE_SHMAT_DECL
  829. extern void *shmat(int shmid, const SHM_ARG_TYPE *shmaddr, int shmflg);
  830. #endif
  831. #ifndef HAVE_SHMCTL_DECL
  832. extern int shmctl(int shmid, int cmd, struct shmid_ds *buf);
  833. #endif
  834. #ifndef HAVE_SHMDT_DECL
  835. extern int shmdt(SHM_ARG_TYPE *shaddr);
  836. #endif
  837. #ifndef HAVE_SHMGET_DECL
  838. extern int shmget(key_t key, size_t size, int shmflg);
  839. #endif
  840. #endif
  841. #ifndef HAVE_SNPRINTF_DECL
  842. #include "arglist.h"
  843. int snprintf(char *buf, size_t len, const char *format,...)
  844. G_GNUC_PRINTF(3,4);
  845. #endif
  846. #ifndef HAVE_VSNPRINTF_DECL
  847. #include "arglist.h"
  848. int vsnprintf(char *buf, size_t len, const char *format, va_list ap);
  849. #endif
  850. #ifndef HAVE_SOCKET_DECL
  851. extern int socket(int domain, int type, int protocol);
  852. #endif
  853. #ifndef HAVE_SOCKETPAIR_DECL
  854. extern int socketpair(int domain, int type, int protocol, int sv[2]);
  855. #endif
  856. #ifndef HAVE_SSCANF_DECL
  857. extern int sscanf(const char *s, const char *format, ...);
  858. #endif
  859. #ifndef HAVE_STRCASECMP_DECL
  860. extern int strcasecmp(const char *s1, const char *s2);
  861. #endif
  862. #ifndef HAVE_STRERROR_DECL
  863. extern char *strerror(int errnum);
  864. #endif
  865. #ifndef HAVE_STRFTIME_DECL
  866. extern size_t strftime(char *s, size_t maxsize, const char *format,
  867. const struct tm *timeptr);
  868. #endif
  869. #ifndef HAVE_STRNCASECMP_DECL
  870. extern int strncasecmp(const char *s1, const char *s2, int n);
  871. #endif
  872. #ifndef HAVE_SYSLOG_DECL
  873. extern void syslog(int priority, const char *logstring, ...)
  874. G_GNUC_PRINTF(2,3);
  875. #endif
  876. #ifndef HAVE_SYSTEM_DECL
  877. extern int system(const char *string);
  878. #endif
  879. #ifndef HAVE_TIME_DECL
  880. extern time_t time(time_t *tloc);
  881. #endif
  882. #ifndef HAVE_TOLOWER_DECL
  883. extern int tolower(int c);
  884. #endif
  885. #ifndef HAVE_TOUPPER_DECL
  886. extern int toupper(int c);
  887. #endif
  888. #ifndef HAVE_UNGETC_DECL
  889. extern int ungetc(int c, FILE *stream);
  890. #endif
  891. #ifndef HAVE_VFPRINTF_DECL
  892. #include "arglist.h"
  893. extern int vfprintf(FILE *stream, const char *format, va_list ap);
  894. #endif
  895. #ifndef HAVE_VPRINTF_DECL
  896. #include "arglist.h"
  897. extern int vprintf(const char *format, va_list ap);
  898. #endif
  899. /* gnulib-only includes (hence "" instead of <>) */
  900. #include "getaddrinfo.h"
  901. #include "inet_ntop.h"
  902. #if !defined(S_ISCHR) && defined(_S_IFCHR) && defined(_S_IFMT)
  903. #define S_ISCHR(mode) (((mode) & _S_IFMT) == _S_IFCHR)
  904. #endif
  905. #if !defined(S_ISREG) && defined(_S_IFREG) && defined(_S_IFMT)
  906. #define S_ISREG(mode) (((mode) & _S_IFMT) == _S_IFREG)
  907. #endif
  908. #ifndef HAVE_WAITPID
  909. #ifdef HAVE_WAIT4
  910. #define waitpid(pid,status,options) wait4(pid,status,options,0)
  911. #else
  912. extern pid_t waitpid(pid_t pid, amwait_t *stat_loc, int options);
  913. #endif
  914. #endif
  915. #ifndef HAVE_WRITEV_DECL
  916. extern ssize_t writev(int fd, const struct iovec *iov, int iovcnt);
  917. #endif
  918. #ifndef STDIN_FILENO
  919. #define STDIN_FILENO 0
  920. #endif
  921. #ifndef STDOUT_FILENO
  922. #define STDOUT_FILENO 1
  923. #endif
  924. #ifndef STDERR_FILENO
  925. #define STDERR_FILENO 2
  926. #endif
  927. /* S_ISDIR is not defined on Nextstep */
  928. #ifndef S_ISDIR
  929. #if defined(_S_IFMT) && defined(_S_IFDIR)
  930. #define S_ISDIR(mode) (((mode) & (_S_IFMT)) == (_S_IFDIR))
  931. #else
  932. #error Don t know how to define S_ISDIR
  933. #endif
  934. #endif
  935. #if SIZEOF_SIZE_T == SIZEOF_INT
  936. # define SIZE_T_ATOI (size_t)atoi
  937. # ifndef SIZE_MAX
  938. # define SIZE_MAX G_MAXUINT
  939. # endif
  940. #else
  941. # define SIZE_T_ATOI (size_t)atol
  942. # ifndef SIZE_MAX
  943. # define SIZE_MAX ULONG_MAX
  944. # endif
  945. #endif
  946. #if SIZEOF_SSIZE_T == SIZEOF_INT
  947. # define SSIZE_T_ATOI (ssize_t)atoi
  948. # ifndef SSIZE_MAX
  949. # define SSIZE_MAX INT_MAX
  950. # endif
  951. # ifndef SSIZE_MIN
  952. # define SSIZE_MIN INT_MIN
  953. # endif
  954. #else
  955. # define SSIZE_T_ATOI (ssize_t)atol
  956. # ifndef SSIZE_MAX
  957. # define SSIZE_MAX LONG_MAX
  958. # endif
  959. # ifndef SSIZE_MIN
  960. # define SSIZE_MIN LONG_MIN
  961. # endif
  962. #endif
  963. #if SIZEOF_TIME_T == SIZEOF_INT
  964. # define TIME_T_ATOI (time_t)atoi
  965. # ifndef TIME_MAX
  966. # define TIME_MAX G_MAXUINT
  967. # endif
  968. #else
  969. # define TIME_T_ATOI (time_t)atol
  970. # ifndef TIME_MAX
  971. # define TIME_MAX ULONG_MAX
  972. # endif
  973. #endif
  974. #if SIZEOF_OFF_T > SIZEOF_LONG
  975. # ifdef HAVE_ATOLL
  976. # define OFF_T_ATOI (off_t)atoll
  977. # else
  978. # define OFF_T_ATOI (off_t)atol
  979. # endif
  980. # ifdef HAVE_STRTOLL
  981. # define OFF_T_STRTOL (off_t)strtoll
  982. # else
  983. # define OFF_T_STRTOL (off_t)strtol
  984. # endif
  985. #else
  986. # if SIZEOF_OFF_T == SIZEOF_LONG
  987. # define OFF_T_ATOI (off_t)atol
  988. # define OFF_T_STRTOL (off_t)strtol
  989. # else
  990. # define OFF_T_ATOI (off_t)atoi
  991. # define OFF_T_STRTOL (off_t)strtol
  992. # endif
  993. #endif
  994. #if SIZEOF_OFF_T == 8
  995. # ifdef OFF_MAX
  996. # define AM64_MAX (off_t)(OFF_MAX)
  997. # else
  998. # define AM64_MAX (off_t)(9223372036854775807LL)
  999. # endif
  1000. # ifdef OFF_MIN
  1001. # define AM64_MIN (off_t)(OFF_MIN)
  1002. # else
  1003. # define AM64_MIN (off_t)(-9223372036854775807LL -1LL)
  1004. # endif
  1005. #else
  1006. #if SIZEOF_LONG == 8
  1007. # ifdef LONG_MAX
  1008. # define AM64_MAX (off_t)(LONG_MAX)
  1009. # else
  1010. # define AM64_MAX (off_t)9223372036854775807L
  1011. # endif
  1012. # ifdef LONG_MIN
  1013. # define AM64_MIN (off_t)(LONG_MIN)
  1014. # else
  1015. # define AM64_MIN (off_t)(-9223372036854775807L -1L)
  1016. # endif
  1017. #else
  1018. #if SIZEOF_LONG_LONG == 8
  1019. # ifdef LONG_LONG_MAX
  1020. # define AM64_MAX (off_t)(LONG_LONG_MAX)
  1021. # else
  1022. # define AM64_MAX (off_t)9223372036854775807LL
  1023. # endif
  1024. # ifdef LONG_LONG_MIN
  1025. # define AM64_MIN (off_t)(LONG_LONG_MIN)
  1026. # else
  1027. # define AM64_MIN (off_t)(-9223372036854775807LL -1LL)
  1028. # endif
  1029. #else
  1030. #if SIZEOF_INTMAX_T == 8
  1031. # ifdef INTMAX_MAX
  1032. # define AM64_MAX (off_t)(INTMAX_MAX)
  1033. # else
  1034. # define AM64_MAX (off_t)9223372036854775807LL
  1035. # endif
  1036. # ifdef INTMAX_MIN
  1037. # define AM64_MIN (off_t)(INTMAX_MIN)
  1038. # else
  1039. # define AM64_MIN (off_t)(-9223372036854775807LL -1LL)
  1040. # endif
  1041. #else /* no 64 bits type found, use long. */
  1042. # ifdef LONG_MAX
  1043. # define AM64_MAX (off_t)(LONG_MAX)
  1044. # else
  1045. # define AM64_MAX (off_t)2147483647
  1046. # endif
  1047. # ifdef LONG_MIN
  1048. # define AM64_MIN (off_t)(LONG_MIN)
  1049. # else
  1050. # define AM64_MIN (off_t)(-2147483647 -1)
  1051. # endif
  1052. #endif
  1053. #endif
  1054. #endif
  1055. #endif
  1056. #define BIND_CYCLE_RETRIES 120 /* Total of 30 minutes */
  1057. #define MAX_DUMPERS 63
  1058. #ifndef NI_MAXHOST
  1059. #define NI_MAXHOST 1025
  1060. #endif
  1061. typedef enum {
  1062. KENCRYPT_NONE, /* krb5 encryption not enabled */
  1063. KENCRYPT_WILL_DO, /* krb5 encryption will be enabled once amanda
  1064. protocol stream is closed */
  1065. KENCRYPT_YES /* krb5 encryption enabled on all stream */
  1066. } kencrypt_type;
  1067. #endif /* !AMANDA_H */