2 * Amanda, The Advanced Maryland Automatic Network Disk Archiver
3 * Copyright (c) 1991-1999 University of Maryland at College Park
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.
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.
23 * Authors: the Amanda Development Team. Its members are listed in a
24 * file named AUTHORS, in the root directory of this distribution.
27 * $Id: amanda.h,v 1.131.2.5 2006/12/12 14:56:38 martinea Exp $
29 * the central header file included by all amanda sources
39 * Force large file source even if configure guesses wrong.
41 #ifndef _LARGE_FILE_SOURCE
42 #define _LARGE_FILES 1
45 #ifndef _LARGEFILE64_SOURCE
46 #define _LARGEFILE64_SOURCE 1
49 #ifndef _FILE_OFFSET_BITS
50 #define _FILE_OFFSET_BITS 64
53 #ifdef HAVE_SYS_TYPES_H
54 # include <sys/types.h>
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.
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.
69 /* from the autoconf documentation */
72 # define NAMLEN(dirent) strlen((dirent)->d_name)
74 # define dirent direct
75 # define NAMLEN(dirent) (dirent)->d_namlen
77 # include <sys/ndir.h>
98 #if defined(USE_DBM_H)
101 #if defined(USE_GDBM_H)
104 #if defined(USE_NDBM_H)
115 #ifdef TIME_WITH_SYS_TIME
116 # include <sys/time.h>
119 # ifdef HAVE_SYS_TIME_H
120 # include <sys/time.h>
142 #ifdef HAVE_STRINGS_H
143 # include <strings.h>
154 #ifdef HAVE_SYS_FILE_H
155 # include <sys/file.h>
158 #ifdef HAVE_SYS_IOCTL_H
159 # include <sys/ioctl.h>
166 #ifdef HAVE_SYS_PARAM_H
167 # include <sys/param.h>
170 #if defined(HAVE_SYS_IPC_H) && defined(HAVE_SYS_SHM_H)
171 # include <sys/ipc.h>
172 # include <sys/shm.h>
174 # ifdef HAVE_SYS_MMAN_H
175 # include <sys/mman.h>
179 #ifdef HAVE_SYS_SELECT_H
180 # include <sys/select.h>
183 #ifdef HAVE_SYS_STAT_H
184 # include <sys/stat.h>
187 #ifdef HAVE_SYS_UIO_H
188 # include <sys/uio.h>
200 #ifdef HAVE_SYS_WAIT_H
201 # include <sys/wait.h>
209 typedef int amwait_t;
211 # define WEXITSTATUS(stat_val) (*(unsigned*)&(stat_val) >> 8)
214 # define WTERMSIG(stat_val) (*(unsigned*)&(stat_val) & 0x7F)
217 # define WIFEXITED(stat_val) ((*(unsigned*)&(stat_val) & 255) == 0)
220 # ifdef WAIT_USES_UNION
221 typedef union wait amwait_t;
223 # define WEXITSTATUS(stat_val) (((amwait_t*)&(stat_val))->w_retcode)
226 # define WTERMSIG(stat_val) (((amwait_t*)&(stat_val))->w_termsig)
229 # define WIFEXITED(stat_val) (WTERMSIG(stat_val) == 0)
232 typedef int amwait_t;
234 # define WEXITSTATUS(stat_val) (*(unsigned*)&(stat_val) >> 8)
237 # define WTERMSIG(stat_val) (*(unsigned*)&(stat_val) & 0x7F)
240 # define WIFEXITED(stat_val) ((*(unsigned*)&(stat_val) & 255) == 0)
246 # define WIFSIGNALED(stat_val) (WTERMSIG(stat_val) != 0)
255 #include <netinet/in.h>
260 #include <sys/resource.h>
261 #include <sys/socket.h>
263 #if !defined(CONFIGURE_TEST)
264 # include "amanda-int.h"
267 #ifdef HAVE_ARPA_INET_H
268 #include <arpa/inet.h>
272 * The dbmalloc package comes from:
274 * http://www.clark.net/pub/dickey/dbmalloc/dbmalloc.tar.gz
278 * ftp://gatekeeper.dec.com/pub/usenet/comp.sources.misc/volume32/dbmalloc/
280 * The following functions are sprinkled through the code, but are
281 * disabled unless USE_DBMALLOC is defined:
283 * malloc_enter(char *) -- stack trace for malloc reports
284 * malloc_leave(char *) -- stack trace for malloc reports
285 * malloc_mark(void *) -- mark an area as never to be free-d
286 * malloc_chain_check(void) -- check the malloc area now
287 * malloc_dump(int fd) -- report the malloc contents to a file descriptor
288 * malloc_list(int fd, ulong a, ulong b) -- report memory activated since
289 * history stamp a that is still active as of stamp b (leak check)
290 * malloc_inuse(ulong *h) -- create history stamp h and return the amount
291 * of memory currently in use.
295 #include "dbmalloc.h"
297 #define malloc_enter(func) ((void)0)
298 #define malloc_leave(func) ((void)0)
299 #define malloc_mark(ptr) ((void)0)
300 #define malloc_chain_check() ((void)0)
301 #define malloc_dump(fd) ((void)0)
302 #define malloc_list(a,b,c) ((void)0)
303 #define malloc_inuse(hist) (*(hist) = 0, 0)
304 #define dbmalloc_caller_loc(x,y) (x)
307 #if !defined(HAVE_SIGACTION) && defined(HAVE_SIGVEC)
308 /* quick'n'dirty hack for NextStep31 */
309 # define sa_flags sv_flags
310 # define sa_handler sv_handler
311 # define sa_mask sv_mask
312 # define sigaction sigvec
313 # define sigemptyset(mask) /* no way to clear pending signals */
317 * Most Unixen declare errno in <errno.h>, some don't. Some multithreaded
318 * systems have errno as a per-thread macro. So, we have to be careful.
325 * Some compilers have int for type of sizeof() some use size_t.
326 * size_t is the one we want...
328 #define SIZEOF(x) (size_t)sizeof(x)
332 * Some older BSD systems don't have these FD_ macros, so if not, provide them.
334 #if !defined(FD_SET) || defined(LINT) || defined(__lint)
336 # define FD_SETSIZE (int)(SIZEOF(fd_set) * CHAR_BIT)
339 # define FD_SET(n, p) (((fd_set *)(p))->fds_bits[(n)/WORD_BIT] |= (int)((1 << ((n) % WORD_BIT))))
342 # define FD_CLR(n, p) (((fd_set *)(p))->fds_bits[(n)/WORD_BIT] &= (int)(~(1 << ((n) % WORD_BIT))))
345 # define FD_ISSET(n, p) (((fd_set *)(p))->fds_bits[(n)/WORD_BIT] & (1 << ((n) % WORD_BIT)))
348 # define FD_ZERO(p) memset((p), 0, SIZEOF(*(p)))
352 # define FD_COPY(p, q) memcpy((q), (p), SIZEOF(*(p)))
357 * Define MAX_HOSTNAME_LENGTH as the size of arrays to hold hostname's.
359 #undef MAX_HOSTNAME_LENGTH
360 #define MAX_HOSTNAME_LENGTH 1025
363 * If void is broken, substitute char.
369 #define stringize(x) #x
370 #define stringconcat(x, y) x ## y
373 * So that we can use GNUC attributes (such as to get -Wall warnings
374 * for printf-like functions). Only do this in gcc 2.7 or later ...
375 * it may work on earlier stuff, but why chance it.
377 #if !defined(__GNUC__) || __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7) || defined(S_SPLINT_S) || defined(LINT) || defined(__lint)
379 #define __attribute__(__x)
383 * assertions, but call error() instead of abort
387 #define assert(exp) ((void)0)
389 #else /* ASSERTIONS */
391 #define assert(exp) do { \
394 error("assert: %s false, file %s, line %d", \
395 stringize(exp), __FILE__, __LINE__); \
400 #endif /* ASSERTIONS */
403 * print debug output, else compile to nothing.
406 #ifdef DEBUG_CODE /* { */
407 # define dbopen(a) debug_open(a)
408 # define dbreopen(a,b) debug_reopen(a,b)
409 # define dbrename(a,b) debug_rename(a,b)
410 # define dbclose() debug_close()
411 # define dbprintf(p) (debug_printf p)
412 # define dbfd() debug_fd()
413 # define dbfp() debug_fp()
414 # define dbfn() debug_fn()
416 extern void debug_open(char *subdir);
417 extern void debug_reopen(char *file, char *notation);
418 extern void debug_rename(char *config, char *subdir);
419 extern void debug_close(void);
420 extern void debug_printf(const char *format, ...)
421 __attribute__ ((format (printf, 1, 2)));
422 extern int debug_fd(void);
423 extern FILE * debug_fp(void);
424 extern char * debug_fn(void);
425 extern void set_debug_prefix_pid(pid_t);
426 extern char *debug_prefix(char *);
427 extern char *debug_prefix_time(char *);
430 # define dbreopen(a,b)
431 # define dbrename(a,b)
437 # define set_debug_prefix_pid(x)
438 # define debug_prefix(x) get_pname()
439 # define debug_prefix_time(x) get_pname()
442 /* amanda #days calculation, with roundoff */
444 #define SECS_PER_DAY (24*60*60)
445 #define days_diff(a, b) (int)(((b) - (a) + SECS_PER_DAY/2) / SECS_PER_DAY)
447 /* Global constants. */
448 #ifndef AMANDA_SERVICE_NAME
449 #define AMANDA_SERVICE_NAME "amanda"
451 #ifndef KAMANDA_SERVICE_NAME
452 #define KAMANDA_SERVICE_NAME "kamanda"
454 #ifndef SERVICE_SUFFIX
455 #define SERVICE_SUFFIX ""
457 #ifndef AMANDA_SERVICE_DEFAULT
458 #define AMANDA_SERVICE_DEFAULT ((in_port_t)10080)
460 #ifndef KAMANDA_SERVICE_DEFAULT
461 #define KAMANDA_SERVICE_DEFAULT ((in_port_t)10081)
464 #define am_round(v,u) ((((v) + (u) - 1) / (u)) * (u))
465 #define am_floor(v,u) (((v) / (u)) * (u))
467 /* Holding disk block size. Do not even think about changint this! :-) */
468 #define DISK_BLOCK_KB 32
469 #define DISK_BLOCK_BYTES (DISK_BLOCK_KB * 1024)
471 /* Maximum size of a tape block */
472 /* MAX_TAPE_BLOCK_KB is defined in config.h */
473 /* by configure --with-maxtapeblocksize */
474 #define MAX_TAPE_BLOCK_BYTES (MAX_TAPE_BLOCK_KB*1024)
476 /* Maximum length of tape label, plus one for null-terminator. */
477 #define MAX_TAPE_LABEL_LEN (10240)
478 #define MAX_TAPE_LABEL_BUF (MAX_TAPE_LABEL_LEN+1)
479 #define MAX_TAPE_LABEL_FMT "%10240s"
481 /* Define miscellaneous amanda functions. */
482 #define ERR_INTERACTIVE 1
484 #define ERR_AMANDALOG 4
486 extern void set_logerror(void (*f)(char *));
487 extern void set_pname(char *pname);
488 extern char *get_pname(void);
489 extern int erroutput_type;
490 extern void error(const char *format, ...)
491 __attribute__ ((format (printf, 1, 2), noreturn));
492 extern void errordump(const char *format, ...)
493 __attribute__ ((format (printf, 1, 2), noreturn));
494 extern int onerror(void (*errf)(void));
496 extern void *debug_alloc (const char *c, int l, size_t size);
497 extern void *debug_newalloc (const char *c, int l, void *old, size_t size);
498 extern char *debug_stralloc (const char *c, int l, const char *str);
499 extern char *debug_newstralloc(const char *c, int l, char *oldstr,
501 extern const char *debug_caller_loc (const char *file, int line);
502 extern int debug_alloc_push (char *file, int line);
503 extern void debug_alloc_pop (void);
505 #define alloc(s) debug_alloc(__FILE__, __LINE__, (s))
506 #define newalloc(p,s) debug_newalloc(__FILE__, __LINE__, (p), (s))
507 #define stralloc(s) debug_stralloc(__FILE__, __LINE__, (s))
508 #define newstralloc(p,s) debug_newstralloc(__FILE__, __LINE__, (p), (s))
511 * Voodoo time. We want to be able to mark these calls with the source
512 * line, but CPP does not handle variable argument lists so we cannot
513 * do what we did above (e.g. for alloc()).
515 * What we do is call a function to save the file and line number
516 * and have it return "false". That triggers the "?" operator to
517 * the right side of the ":" which is a call to the debug version of
518 * vstralloc/newvstralloc but without parameters. The compiler gets
519 * those from the next input tokens:
521 * xx = vstralloc(a,b,NULL);
525 * xx = debug_alloc_push(__FILE__,__LINE__)?0:debug_vstralloc(a,b,NULL);
527 * This works as long as vstralloc/newvstralloc are not part of anything
528 * very complicated. Assignment is fine, as is an argument to another
529 * function (but you should not do that because it creates a memory leak).
530 * This will not work in arithmetic or comparison, but it is unlikely
531 * they are used like that.
533 * xx = vstralloc(a,b,NULL); OK
534 * return vstralloc(j,k,NULL); OK
535 * sub(a, vstralloc(g,h,NULL), z); OK, but a leak
536 * if(vstralloc(s,t,NULL) == NULL) { ... NO, but unneeded
537 * xx = vstralloc(x,y,NULL) + 13; NO, but why do it?
540 #define vstralloc debug_alloc_push(__FILE__,__LINE__)?0:debug_vstralloc
541 #define newvstralloc debug_alloc_push(__FILE__,__LINE__)?0:debug_newvstralloc
543 extern char *debug_vstralloc(const char *str, ...);
544 extern char *debug_newvstralloc(char *oldstr, const char *newstr, ...);
546 #define stralloc2(s1,s2) vstralloc((s1),(s2),NULL)
547 #define newstralloc2(p,s1,s2) newvstralloc((p),(s1),(s2),NULL)
549 /* Usage: vstrextend(foo, "bar, "baz", NULL). Extends the existing
550 * string, or allocates a brand new one. */
551 extern char *vstrextend(char **oldstr, ...);
553 extern /*@only@*/ /*@null@*/ char *debug_agets(const char *c, int l, FILE *file);
554 extern /*@only@*/ /*@null@*/ char *debug_areads(const char *c, int l, int fd);
555 #define agets(f) debug_agets(__FILE__,__LINE__,(f))
556 #define areads(f) debug_areads(__FILE__,__LINE__,(f))
558 extern int debug_amtable_alloc(const char *file,
565 void (*init_func)(void *));
567 #define amtable_alloc(t,c,s,n,b,f) debug_amtable_alloc(__FILE__, \
576 extern void amtable_free(void **table, size_t *current);
578 extern uid_t client_uid;
579 extern gid_t client_gid;
581 void safe_fd(int fd_start, int fd_count);
583 void save_core(void);
584 char ** safe_env(void);
585 char * validate_regexp(const char *regex);
586 char * validate_glob(const char *glob);
587 char * clean_regex(const char *regex);
588 int match(const char *regex, const char *str);
589 int match_glob(const char *glob, const char *str);
590 char * glob_to_regex(const char *glob);
591 int match_tar(const char *glob, const char *str);
592 char * tar_to_regex(const char *glob);
593 int match_host(const char *glob, const char *host);
594 int match_disk(const char *glob, const char *disk);
595 int match_datestamp(const char *dateexp, const char *datestamp);
596 int match_level(const char *levelexp, const char *level);
597 time_t unctime(char *timestr);
598 ssize_t areads_dataready(int fd);
599 void areads_relbuf(int fd);
602 * amfree(ptr) -- if allocated, release space and set ptr to NULL.
604 * In general, this should be called instead of just free(), unless
605 * the very next source line sets the pointer to a new value.
608 #define amfree(ptr) do { \
609 if((ptr) != NULL) { \
610 int e__errno = errno; \
614 (void)(ptr); /* Fix value never used warning at end of routines */ \
618 #define strappend(s1,s2) do { \
619 char *t_t_t = (s1) ? stralloc2((s1),(s2)) : stralloc((s2)); \
625 * "Safe" close macros. Close the object then set it to a value that
626 * will cause an error if referenced.
628 * aclose(fd) -- close a file descriptor and set it to -1.
629 * afclose(f) -- close a stdio file and set it to NULL.
630 * apclose(p) -- close a stdio pipe file and set it to NULL.
632 * Note: be careful not to do the following:
634 * for(fd = low; fd < high; fd++) {
638 * Since aclose() sets the argument to -1, this will loop forever.
639 * Just copy fd to a temp variable and use that with aclose().
641 * Aclose() interacts with areads() to inform it to release any buffer
642 * it has outstanding on the file descriptor.
645 #define aclose(fd) do { \
651 (void)(fd); /* Fix value never used warning at end of routines */ \
654 #define afclose(f) do { \
658 (void)(f); /* Fix value never used warning at end of routines */ \
662 #define apclose(p) do { \
666 (void)(p); /* Fix value never used warning at end of routines */ \
671 * Return the number of elements in an array.
673 #define am_countof(a) (int)(SIZEOF(a) / SIZEOF((a)[0]))
676 * min/max. Don't do something like
680 * because the increment will be duplicated.
684 #define min(a, b) ((a) < (b) ? (a) : (b))
685 #define max(a, b) ((a) > (b) ? (a) : (b))
688 * Utility bitmask manipulation macros.
690 #define SET(t, f) ((t) |= (f))
691 #define CLR(t, f) ((t) &= ~((unsigned)(f)))
692 #define ISSET(t, f) ((t) & (f))
695 * Utility string macros. All assume a variable holds the current
696 * character and the string pointer points to the next character to
697 * be processed. Typical setup is:
701 * skip_whitespace(s, ch);
704 * If you advance the pointer "by hand" to skip over something, do
710 * Note that ch has the character at the end of the just skipped field.
711 * It is often useful to terminate a string, make a copy, then restore
712 * the input like this:
714 * skip_whitespace(s, ch);
715 * fp = s-1; ## save the start
716 * skip_nonwhitespace(s, ch); ## find the end
717 * p[-1] = '\0'; ## temporary terminate
718 * field = stralloc(fp); ## make a copy
719 * p[-1] = ch; ## restore the input
721 * The scanning macros are:
723 * skip_whitespace (ptr, var)
724 * -- skip whitespace, but stops at a newline
725 * skip_non_whitespace (ptr, var)
726 * -- skip non whitespace
727 * skip_non_whitespace_cs (ptr, var)
728 * -- skip non whitespace, stop at comment
729 * skip_integer (ptr, var)
730 * -- skip an integer field
731 * skip_line (ptr, var)
732 * -- skip just past the next newline
736 * ptr -- string pointer
737 * var -- current character
739 * These macros copy a non-whitespace field to a new buffer, and should
740 * only be used if dynamic allocation is impossible (fixed size buffers
741 * are asking for trouble):
743 * copy_string (ptr, var, field, len, fldptr)
744 * -- copy a non-whitespace field
745 * copy_string_cs (ptr, var, field, len, fldptr)
746 * -- copy a non-whitespace field, stop at comment
750 * ptr -- string pointer
751 * var -- current character
752 * field -- area to copy to
753 * len -- length of area (needs room for null byte)
754 * fldptr -- work pointer used in move
755 * if NULL on exit, the field was too small for the input
758 #define STR_SIZE 4096 /* a generic string buffer size */
759 #define NUM_STR_SIZE 128 /* a generic number buffer size */
761 #define skip_whitespace(ptr,c) do { \
762 while((c) != '\n' && isspace(c)) (c) = *(ptr)++; \
765 #define skip_non_whitespace(ptr,c) do { \
766 while((c) != '\0' && !isspace(c)) (c) = *(ptr)++; \
769 #define skip_non_whitespace_cs(ptr,c) do { \
770 while((c) != '\0' && (c) != '#' && !isspace(c)) (c) = *(ptr)++; \
773 #define skip_non_integer(ptr,c) do { \
774 while((c) != '\0' && !isdigit(c)) (c) = *(ptr)++; \
777 #define skip_integer(ptr,c) do { \
778 if((c) == '+' || (c) == '-') (c) = *(ptr)++; \
779 while(isdigit(c)) (c) = *(ptr)++; \
782 #define skip_quoted_string(ptr, c) do { \
784 while (((c) != '\0') && !((iq == 0) && isspace(c))) { \
787 } else if (((c) == '\\') && (*(ptr) == '"')) { \
794 #define skip_quoted_line(ptr, c) do { \
796 while((c) && !((iq == 0) && ((c) == '\n'))) { \
805 #define skip_line(ptr,c) do { \
806 while((c) && (c) != '\n') \
812 #define copy_string(ptr,c,f,l,fp) do { \
814 while((c) != '\0' && !isspace(c)) { \
815 if((fp) >= (f) + (l) - 1) { \
818 (void)(fp); /* Fix value never used warning at end of routines */ \
828 #define copy_string_cs(ptr,c,f,l,fp) do { \
830 while((c) != '\0' && (c) != '#' && !isspace(c)) { \
831 if((fp) >= (f) + (l) - 1) { \
842 #define is_dot_or_dotdot(s) \
845 || ((s)[1] == '.' && (s)[2] == '\0')))
848 extern int amflock(int fd, char *resource);
849 extern int amroflock(int fd, char *resource);
850 extern int amfunlock(int fd, char *resource);
853 extern int mkpdir(char *file, mode_t mode, uid_t uid, gid_t gid);
854 extern int rmpdir(char *file, char *topdir);
855 extern char *sanitise_filename(char *inp);
856 extern char *old_sanitise_filename(char *inp);
858 /* from old bsd-security.c */
860 extern int check_security(struct sockaddr_in *, char *, unsigned long, char **);
863 * Handle functions which are not always declared on all systems. This
864 * stops gcc -Wall and lint from complaining.
867 /* AIX #defines accept, and provides a prototype for the alternate name */
868 #if !defined(HAVE_ACCEPT_DECL) && !defined(accept)
869 extern int accept(int s, struct sockaddr *addr, socklen_t *addrlen);
872 #ifndef HAVE_ATOF_DECL
873 extern double atof(const char *ptr);
877 # define bcopy(from,to,n) ((void)memmove((to), (from), (n)))
879 # ifndef HAVE_BCOPY_DECL
880 extern void bcopy(const void *s1, void *s2, size_t n);
884 #ifndef HAVE_BIND_DECL
885 extern int bind(int s, const struct sockaddr *name, socklen_t namelen);
889 #define bzero(s,n) ((void)memset((s),0,(n)))
891 # ifndef HAVE_BZERO_DECL
892 extern void bzero(void *s, size_t n);
896 #ifndef HAVE_CLOSELOG_DECL
897 extern void closelog(void);
900 #ifndef HAVE_CONNECT_DECL
901 extern int connect(int s, struct sockaddr *name, socklen_t namelen);
904 #if !defined(TEXTDB) && !defined(HAVE_DBM_OPEN_DECL)
909 #define DBM_REPLACE 1
915 #ifndef HAVE_STRUCT_DATUM
922 extern DBM *dbm_open(char *file, int flags, int mode);
923 extern void dbm_close(DBM *db);
924 extern datum dbm_fetch(DBM *db, datum key);
925 extern datum dbm_firstkey(DBM *db);
926 extern datum dbm_nextkey(DBM *db);
927 extern int dbm_delete(DBM *db, datum key);
928 extern int dbm_store(DBM *db, datum key, datum content, int flg);
931 #ifndef HAVE_FCLOSE_DECL
932 extern int fclose(FILE *stream);
935 #ifndef HAVE_FFLUSH_DECL
936 extern int fflush(FILE *stream);
939 #ifndef HAVE_FPRINTF_DECL
940 extern int fprintf(FILE *stream, const char *format, ...);
943 #ifndef HAVE_FPUTC_DECL
944 extern int fputc(int c, FILE *stream);
947 #ifndef HAVE_FPUTS_DECL
948 extern int fputs(const char *s, FILE *stream);
951 #ifndef HAVE_FREAD_DECL
952 extern size_t fread(void *ptr, size_t size, size_t nitems, FILE *stream);
955 #ifndef HAVE_FSEEK_DECL
956 extern int fseek(FILE *stream, long offset, int ptrname);
959 #ifndef HAVE_FWRITE_DECL
960 extern size_t fwrite(const void *ptr, size_t size, size_t nitems,
964 #ifndef HAVE_GETHOSTNAME_DECL
965 extern int gethostname(char *name, int namelen);
968 #ifndef HAVE_GETOPT_DECL
970 extern int getopt(int argc, char * const *argv, const char *optstring);
973 /* AIX #defines getpeername, and provides a prototype for the alternate name */
974 #if !defined(HAVE_GETPEERNAME_DECL) && !defined(getpeername)
975 extern int getpeername(int s, struct sockaddr *name, socklen_t *namelen);
978 /* AIX #defines getsockname, and provides a prototype for the alternate name */
979 #if !defined(HAVE_GETSOCKNAME_DECL) && !defined(getsockname)
980 extern int getsockname(int s, struct sockaddr *name, socklen_t *namelen);
983 #ifndef HAVE_GETSOCKOPT_DECL
984 extern int getsockopt(int s, int level, int optname, char *optval,
988 #ifndef HAVE_GETTIMEOFDAY_DECL
989 # ifdef HAVE_TWO_ARG_GETTIMEOFDAY
990 extern int gettimeofday(struct timeval *tp, struct timezone *tzp);
992 extern int gettimeofday(struct timeval *tp);
996 #ifndef HAVE_INITGROUPS
997 # define initgroups(name,basegid) 0
999 # ifndef HAVE_INITGROUPS_DECL
1000 extern int initgroups(const char *name, gid_t basegid);
1004 #ifndef HAVE_IOCTL_DECL
1005 extern int ioctl(int fildes, int request, ...);
1009 #ifndef HAVE_ISNORMAL
1010 #define isnormal(f) (((f) < 0.0) || ((f) > 0.0))
1014 #ifndef HAVE_LISTEN_DECL
1015 extern int listen(int s, int backlog);
1018 #ifndef HAVE_LSTAT_DECL
1019 extern int lstat(const char *path, struct stat *buf);
1022 #ifndef HAVE_MALLOC_DECL
1023 extern void *malloc (size_t size);
1026 #ifndef HAVE_MEMMOVE_DECL
1028 extern void *memmove(void *to, const void *from, size_t n);
1030 extern char *memmove(char *to, /*const*/ char *from, size_t n);
1034 #ifndef HAVE_MEMSET_DECL
1035 extern void *memset(void *s, int c, size_t n);
1038 #ifndef HAVE_MKTEMP_DECL
1039 extern char *mktemp(char *template);
1042 #ifndef HAVE_MKSTEMP_DECL
1043 extern int mkstemp(char *template);
1046 #ifndef HAVE_MKTIME_DECL
1047 extern time_t mktime(struct tm *timeptr);
1050 #ifndef HAVE_OPENLOG_DECL
1052 extern void openlog(const char *ident, int logopt, int facility);
1054 extern void openlog(const char *ident, int logopt);
1058 #ifndef HAVE_PCLOSE_DECL
1059 extern int pclose(FILE *stream);
1062 #ifndef HAVE_PERROR_DECL
1063 extern void perror(const char *s);
1066 #ifndef HAVE_PRINTF_DECL
1067 extern int printf(const char *format, ...);
1070 #ifndef HAVE_PUTS_DECL
1071 extern int puts(const char *s);
1074 #ifndef HAVE_REALLOC_DECL
1075 extern void *realloc(void *ptr, size_t size);
1078 /* AIX #defines recvfrom, and provides a prototype for the alternate name */
1079 #if !defined(HAVE_RECVFROM_DECL) && !defined(recvfrom)
1080 extern int recvfrom(int s, char *buf, int len, int flags,
1081 struct sockaddr *from, socklen_t *fromlen);
1084 #ifndef HAVE_REMOVE_DECL
1085 extern int remove(const char *path);
1088 #ifndef HAVE_RENAME_DECL
1089 extern int rename(const char *old, const char *new);
1092 #ifndef HAVE_REWIND_DECL
1093 extern void rewind(FILE *stream);
1096 #ifndef HAVE_RUSEROK_DECL
1097 extern int ruserok(const char *rhost, int suser,
1098 const char *ruser, const char *luser);
1101 #ifndef HAVE_SELECT_DECL
1102 extern int select(int nfds,
1103 SELECT_ARG_TYPE *readfds,
1104 SELECT_ARG_TYPE *writefds,
1105 SELECT_ARG_TYPE *exceptfds,
1106 struct timeval *timeout);
1109 #ifndef HAVE_SENDTO_DECL
1110 extern int sendto(int s, const char *msg, int len, int flags,
1111 const struct sockaddr *to, int tolen);
1114 #ifdef HAVE_SETRESGID
1115 #define setegid(x) setresgid((gid_t)-1,(x),(gid_t)-1)
1116 #ifndef HAVE_SETRESGID_DECL
1117 extern int setresgid(gid_t rgid, gid_t egid, gid_t sgid);
1120 #ifndef HAVE_SETEGID_DECL
1121 extern int setegid(gid_t egid);
1125 #ifdef HAVE_SETRESUID
1126 #define seteuid(x) setresuid((uid_t)-1,(x),(uid_t)-1)
1127 #ifndef HAVE_SETRESUID_DECL
1128 extern int setresuid(uid_t ruid, uid_t euid, uid_t suid);
1131 #ifndef HAVE_SETEUID_DECL
1132 extern int seteuid(uid_t euid);
1136 #ifndef HAVE_SETPGID_DECL
1138 extern int setpgid(pid_t pid, pid_t pgid);
1142 #ifndef HAVE_SETPGRP_DECL
1144 extern pid_t setpgrp(void);
1146 extern pid_t setpgrp(pid_t pgrp, pid_t pid);
1150 #ifndef HAVE_SETSOCKOPT_DECL
1151 extern int setsockopt(int s, int level, int optname,
1152 const char *optval, int optlen);
1156 #ifndef HAVE_SHMAT_DECL
1157 extern void *shmat(int shmid, const SHM_ARG_TYPE *shmaddr, int shmflg);
1160 #ifndef HAVE_SHMCTL_DECL
1161 extern int shmctl(int shmid, int cmd, struct shmid_ds *buf);
1164 #ifndef HAVE_SHMDT_DECL
1165 extern int shmdt(SHM_ARG_TYPE *shaddr);
1168 #ifndef HAVE_SHMGET_DECL
1169 extern int shmget(key_t key, size_t size, int shmflg);
1173 #ifndef HAVE_SNPRINTF_DECL
1174 #include "arglist.h"
1175 int snprintf(char *buf, size_t len, const char *format,...)
1176 __attribute__((format(printf,3,4)));
1178 #ifndef HAVE_VSNPRINTF_DECL
1179 #include "arglist.h"
1180 int vsnprintf(char *buf, size_t len, const char *format, va_list ap);
1183 #ifndef HAVE_SOCKET_DECL
1184 extern int socket(int domain, int type, int protocol);
1187 #ifndef HAVE_SOCKETPAIR_DECL
1188 extern int socketpair(int domain, int type, int protocol, int sv[2]);
1191 #ifndef HAVE_SSCANF_DECL
1192 extern int sscanf(const char *s, const char *format, ...);
1195 #ifndef HAVE_STRCASECMP_DECL
1196 extern int strcasecmp(const char *s1, const char *s2);
1199 #ifndef HAVE_STRERROR_DECL
1200 extern char *strerror(int errnum);
1203 #ifndef HAVE_STRFTIME_DECL
1204 extern size_t strftime(char *s, size_t maxsize, const char *format,
1205 const struct tm *timeptr);
1208 #ifndef HAVE_STRNCASECMP_DECL
1209 extern int strncasecmp(const char *s1, const char *s2, int n);
1212 #ifndef HAVE_SYSLOG_DECL
1213 extern void syslog(int priority, const char *logstring, ...)
1214 __attribute__ ((format (printf, 2, 3)));
1217 #ifndef HAVE_SYSTEM_DECL
1218 extern int system(const char *string);
1221 #ifndef HAVE_TIME_DECL
1222 extern time_t time(time_t *tloc);
1225 #ifndef HAVE_TOLOWER_DECL
1226 extern int tolower(int c);
1229 #ifndef HAVE_TOUPPER_DECL
1230 extern int toupper(int c);
1233 #ifndef HAVE_UNGETC_DECL
1234 extern int ungetc(int c, FILE *stream);
1237 #ifndef HAVE_VFPRINTF_DECL
1238 #include "arglist.h"
1239 extern int vfprintf(FILE *stream, const char *format, va_list ap);
1242 #ifndef HAVE_VPRINTF_DECL
1243 #include "arglist.h"
1244 extern int vprintf(const char *format, va_list ap);
1247 #if !defined(S_ISCHR) && defined(_S_IFCHR) && defined(_S_IFMT)
1248 #define S_ISCHR(mode) (((mode) & _S_IFMT) == _S_IFCHR)
1251 #if !defined(S_ISREG) && defined(_S_IFREG) && defined(_S_IFMT)
1252 #define S_ISREG(mode) (((mode) & _S_IFMT) == _S_IFREG)
1255 #ifndef HAVE_WAITPID
1257 #define waitpid(pid,status,options) wait4(pid,status,options,0)
1259 extern pid_t waitpid(pid_t pid, amwait_t *stat_loc, int options);
1263 #ifndef HAVE_WRITEV_DECL
1264 extern ssize_t writev(int fd, const struct iovec *iov, int iovcnt);
1267 #ifndef STDIN_FILENO
1268 #define STDIN_FILENO 0
1271 #ifndef STDOUT_FILENO
1272 #define STDOUT_FILENO 1
1275 #ifndef STDERR_FILENO
1276 #define STDERR_FILENO 2
1279 /* S_ISDIR is not defined on Nextstep */
1281 #if defined(_S_IFMT) && defined(_S_IFDIR)
1282 #define S_ISDIR(mode) (((mode) & (_S_IFMT)) == (_S_IFDIR))
1284 #error Don t know how to define S_ISDIR
1288 #if SIZEOF_SIZE_T == SIZEOF_INT
1289 # define SIZE_T_FMT "%u"
1290 # define SIZE_T_FMT_TYPE unsigned
1291 # define SIZE_T_ATOI (size_t)atoi
1293 # define SIZE_MAX UINT_MAX
1296 # define SIZE_T_FMT "%lu"
1297 # define SIZE_T_FMT_TYPE unsigned long
1298 # define SIZE_T_ATOI (size_t)atol
1300 # define SIZE_MAX ULONG_MAX
1304 #if SIZEOF_SSIZE_T == SIZEOF_INT
1305 # define SSIZE_T_FMT "%d"
1306 # define SSIZE_T_FMT_TYPE int
1307 # define SSIZE_T_ATOI (ssize_t)atoi
1309 # define SSIZE_MAX INT_MAX
1312 # define SSIZE_MIN INT_MIN
1315 # define SSIZE_T_FMT "%ld"
1316 # define SSIZE_T_FMT_TYPE long
1317 # define SSIZE_T_ATOI (ssize_t)atol
1319 # define SSIZE_MAX LONG_MAX
1322 # define SSIZE_MIN LONG_MIN
1326 #if SIZEOF_TIME_T == SIZEOF_INT
1327 # define TIME_T_FMT "%u"
1328 # define TIME_T_FMT_TYPE unsigned
1329 # define TIME_T_ATOI (time_t)atoi
1331 # define TIME_MAX UINT_MAX
1334 # define TIME_T_FMT "%lu"
1335 # define TIME_T_FMT_TYPE unsigned long
1336 # define TIME_T_ATOI (time_t)atol
1338 # define TIME_MAX ULONG_MAX
1342 #if SIZEOF_OFF_T > SIZEOF_LONG
1343 # define OFF_T_FMT LL_FMT
1344 # define OFF_T_RFMT LL_RFMT
1345 # define OFF_T_FMT_TYPE long long
1347 # define OFF_T_ATOI (off_t)atoll
1349 # define OFF_T_ATOI (off_t)atol
1351 # ifdef HAVE_STRTOLL
1352 # define OFF_T_STRTOL (off_t)strtoll
1354 # define OFF_T_STRTOL (off_t)strtol
1357 # if SIZEOF_OFF_T == SIZEOF_LONG
1358 # define OFF_T_FMT "%ld"
1359 # define OFF_T_RFMT "ld"
1360 # define OFF_T_FMT_TYPE long
1361 # define OFF_T_ATOI (off_t)atol
1362 # define OFF_T_STRTOL (off_t)strtol
1364 # define OFF_T_FMT "%d"
1365 # define OFF_T_RFMT "d"
1366 # define OFF_T_FMT_TYPE int
1367 # define OFF_T_ATOI (off_t)atoi
1368 # define OFF_T_STRTOL (off_t)strtol
1372 #if SIZEOF_OFF_T == 8
1374 # define AM64_MAX (off_t)(OFF_MAX)
1376 # define AM64_MAX (off_t)(9223372036854775807LL)
1379 # define AM64_MIN (off_t)(OFF_MIN)
1381 # define AM64_MIN (off_t)(-9223372036854775807LL -1LL)
1383 # define AM64_FMT OFF_T_FMT
1385 #if SIZEOF_LONG == 8
1387 # define AM64_MAX (off_t)(LONG_MAX)
1389 # define AM64_MAX (off_t)9223372036854775807L
1392 # define AM64_MIN (off_t)(LONG_MIN)
1394 # define AM64_MIN (off_t)(-9223372036854775807L -1L)
1396 # define AM64_FMT "%ld"
1398 #if SIZEOF_LONG_LONG == 8
1399 # ifdef LONG_LONG_MAX
1400 # define AM64_MAX (off_t)(LONG_LONG_MAX)
1402 # define AM64_MAX (off_t)9223372036854775807LL
1404 # ifdef LONG_LONG_MIN
1405 # define AM64_MIN (off_t)(LONG_LONG_MIN)
1407 # define AM64_MIN (off_t)(-9223372036854775807LL -1LL)
1409 # define AM64_FMT LL_FMT
1411 #if SIZEOF_INTMAX_T == 8
1413 # define AM64_MAX (off_t)(INTMAX_MAX)
1415 # define AM64_MAX (off_t)9223372036854775807LL
1418 # define AM64_MIN (off_t)(INTMAX_MIN)
1420 # define AM64_MIN (off_t)(-9223372036854775807LL -1LL)
1422 # define AM64_FMT LL_FMT
1423 #else /* no 64 bits type found, use long. */
1425 # define AM64_MAX (off_t)(LONG_MAX)
1427 # define AM64_MAX (off_t)2147483647
1430 # define AM64_MIN (off_t)(LONG_MIN)
1432 # define AM64_MIN (off_t)(-2147483647 -1)
1434 # define AM64_FMT "%ld"
1440 #ifdef HAVE_LIBREADLINE
1441 # ifdef HAVE_READLINE_READLINE_H
1442 # include <readline/readline.h>
1443 # ifdef HAVE_READLINE_HISTORY_H
1444 # include <readline/history.h>
1447 # ifdef HAVE_READLINE_H
1448 # include <readline.h>
1449 # ifdef HAVE_HISTORY_H
1450 # include <history.h>
1453 # undef HAVE_LIBREADLINE
1458 char * readline(const char *prompt);
1459 void add_history(const char *line);
1463 #define BIND_CYCLE_RETRIES 120 /* Total of 30 minutes */
1465 #define DBG_SUBDIR_SERVER "server"
1466 #define DBG_SUBDIR_CLIENT "client"
1467 #define DBG_SUBDIR_AMANDAD "amandad"
1469 #endif /* !AMANDA_H */