1 /*
2    Bacula(R) - The Network Backup Solution
3 
4    Copyright (C) 2000-2020 Kern Sibbald
5 
6    The original author of Bacula is Kern Sibbald, with contributions
7    from many others, a complete list can be found in the file AUTHORS.
8 
9    You may use this file and others of this release according to the
10    license defined in the LICENSE file, which includes the Affero General
11    Public License, v3.0 ("AGPLv3") and some additional permissions and
12    terms pursuant to its AGPLv3 Section 7.
13 
14    This notice must be preserved when any source code is
15    conveyed and/or propagated.
16 
17    Bacula(R) is a registered trademark of Kern Sibbald.
18 */
19 /**
20  * General header file configurations that apply to
21  * all daemons.  System dependent stuff goes here.
22  *
23  */
24 
25 
26 #ifndef _BACONFIG_H
27 #define _BACONFIG_H 1
28 
29 /* Bacula common configuration defines */
30 
31 #undef  TRUE
32 #undef  FALSE
33 #define TRUE  1
34 #define FALSE 0
35 
36 #ifdef HAVE_TLS
37  #define have_tls 1
38  #ifdef HAVE_TLS_PSK
39    #define tls_psk_default 1
40  #else
41   #define tls_psk_default 0
42  #endif
43 #else
44  #define have_tls 0
45  #define tls_psk_default 0
46 #endif
47 
48 #ifndef ENODATA
49 #define ENODATA EPIPE
50 #endif
51 
52 #ifndef ETIME
53 #define ETIME ETIMEDOUT
54 #endif
55 
56 #ifdef HAVE_IOCTL_ULINT_REQUEST
57 #define ioctl_req_t unsigned long int
58 #else
59 #define ioctl_req_t int
60 #endif
61 
62 #define MANUAL_AUTH_URL "http://www.bacula.org/rel-manual/en/problems/Bacula_Frequently_Asked_Que.html"
63 
64 #ifdef PROTOTYPES
65 # define __PROTO(p)     p
66 #else
67 # define __PROTO(p)     ()
68 #endif
69 
70 #ifdef DEBUG
71 #define ASSERT(x) if (!(x)) { \
72    char *tjcr = NULL; \
73    Emsg1(M_ERROR, 0, _("Failed ASSERT: %s\n"), #x); \
74    Pmsg1(000, _("Failed ASSERT: %s\n"), #x); \
75    tjcr[0] = 0; }
76 
77 #define ASSERT2(x,y) if (!(x)) { \
78    set_assert_msg(__FILE__, __LINE__, y); \
79    Emsg1(M_ERROR, 0, _("Failed ASSERT: %s\n"), #x); \
80    Pmsg1(000, _("Failed ASSERT: %s\n"), #x); \
81    char *tjcr = NULL; \
82    tjcr[0] = 0; }
83 #else
84 #define ASSERT(x)
85 #define ASSERT2(x, y)
86 #endif
87 
88 #ifdef DEVELOPER
89 #define ASSERTD(x, y) if (!(x)) { \
90    set_assert_msg(__FILE__, __LINE__, y); \
91    Emsg1(M_ERROR, 0, _("Failed ASSERT: %s\n"), #x); \
92    Pmsg1(000, _("Failed ASSERT: %s\n"), #x); \
93    char *jcr = NULL; \
94    jcr[0] = 0; }
95 #else
96 #define ASSERTD(x, y)
97 #endif
98 
99 /* Until DDE has its own logging, use Tmsg, with following debug levels */
100 #define DDE_MSG 0
101 #define VACUUM_MSG 0
102 #define DDEERR_MSG 0
103 #define VACERR_MSG 0
104 #define SCRUB_MSG 0
105 #define SCRUBERR_MSG 0
106 
107 /* Allow printing of NULL pointers */
108 #define NPRT(x) (x)?(x):_("*None*")
109 #define NPRTB(x) (x)?(x):""
110 
111 /* stored in statp.st_rdev */
112 #define WIN32_REPARSE_NONE   0   /* Not a reparse point */
113 #define WIN32_REPARSE_POINT  1   /* Can be any reparse point except one of the following */
114 #define WIN32_MOUNT_POINT    2   /* Directory link to Volume */
115 #define WIN32_JUNCTION_POINT 3   /* Directory link to a directory */
116 #define WIN32_SYMLINK_POINT  4   /* A Symlink to a file OR a directory */
117 #define WIN32_ROOT_POINT     5   /* Root of a volume, like C: */
118 
119 #if defined(HAVE_WIN32)
120 
121 /* Reduce compiler warnings from Windows vss code */
122 #define uuid(x)
123 
124 void InitWinAPIWrapper();
125 
126 #define  OSDependentInit()    InitWinAPIWrapper()
127 
128 #define clear_thread_id(x) memset(&(x), 0, sizeof(x))
129 
130 #if defined(BUILDING_DLL)
131 #  define DLL_IMP_EXP   _declspec(dllexport)
132 #elif defined(USING_DLL)
133 #  define DLL_IMP_EXP   _declspec(dllimport)
134 #else
135 #  define DLL_IMP_EXP
136 #endif
137 
138 #if defined(USING_CATS)
139 #  define CATS_IMP_EXP   _declspec(dllimport)
140 #else
141 #  define CATS_IMP_EXP
142 #endif
143 
144 #else  /* HAVE_WIN32 */
145 
146 #define clear_thread_id(x) x = 0
147 
148 #define DLL_IMP_EXP
149 #define CATS_IMP_EXP
150 
151 #define  OSDependentInit()
152 
153 #endif /* HAVE_WIN32 */
154 
155 
156 #ifdef ENABLE_NLS
157    #include <libintl.h>
158    #include <locale.h>
159    #ifndef _
160       #define _(s) gettext((s))
161    #endif /* _ */
162    #ifndef N_
163       #define N_(s) (s)
164    #endif /* N_ */
165 #else /* !ENABLE_NLS */
166    #undef _
167    #undef N_
168    #undef textdomain
169    #undef bindtextdomain
170    #undef setlocale
171 
172    #ifndef _
173       #define _(s) (s)
174    #endif
175    #ifndef N_
176       #define N_(s) (s)
177    #endif
178    #ifndef textdomain
179       #define textdomain(d)
180    #endif
181    #ifndef bindtextdomain
182       #define bindtextdomain(p, d)
183    #endif
184 #ifdef __DragonFly__
185 /* <regex.h> include <xlocale.h> including <locale.h> */
186 #include <locale.h>
187 #endif
188    #ifndef setlocale
189       #define setlocale(p, d)
190    #endif
191 #endif /* ENABLE_NLS */
192 
193 
194 /* Use the following for strings not to be translated */
195 #define NT_(s) (s)
196 
197 /* This should go away! ****FIXME***** */
198 #define MAXSTRING 500
199 
200 /* Maximum length to edit time/date */
201 #define MAX_TIME_LENGTH 50
202 
203 /* Maximum Name length including EOS */
204 #define MAX_NAME_LENGTH 128
205 
206 /* Maximum escaped Name lenght including EOS 2*MAX_NAME_LENGTH+1 */
207 #define MAX_ESCAPE_NAME_LENGTH 257
208 
209 /* Maximume number of user entered command args */
210 #define MAX_CMD_ARGS 30
211 
212 /* All tape operations MUST be a multiple of this */
213 #define TAPE_BSIZE 1024
214 
215 #ifdef DEV_BSIZE
216 #define B_DEV_BSIZE DEV_BSIZE
217 #endif
218 
219 #if !defined(B_DEV_BSIZE) & defined(BSIZE)
220 #define B_DEV_BSIZE BSIZE
221 #endif
222 
223 #ifndef B_DEV_BSIZE
224 #define B_DEV_BSIZE 512
225 #endif
226 
227 /**
228  * Set to time limit for other end to respond to
229  *  authentication.  Normally 10 minutes is *way*
230  *  more than enough. The idea is to keep the Director
231  *  from hanging because there is a dead connection on
232  *  the other end.
233  */
234 #define AUTH_TIMEOUT 60 * 10
235 
236 /*
237  * Default network buffer size
238  */
239 #define DEFAULT_NETWORK_BUFFER_SIZE (64 * 1024)
240 
241 /**
242  * Tape label types -- stored in catalog
243  */
244 #define B_BACULA_LABEL 0
245 #define B_ANSI_LABEL   1
246 #define B_IBM_LABEL    2
247 
248 /*
249  * Device types
250  * If you update this table, be sure to add an
251  *  entry in prt_dev_types[] in stored/dev.c
252  *  This number is stored in the Catalog as VolType or VolParts, do not change.
253  */
254 enum {
255    B_FILE_DEV = 1,
256    B_TAPE_DEV = 2,
257    B_DVD_DEV  = 3,
258    B_FIFO_DEV = 4,
259    B_VTAPE_DEV= 5,                    /* change to B_TAPE_DEV after init */
260    B_FTP_DEV =  6,
261    B_VTL_DEV =  7,                    /* Virtual tape library device */
262    B_ADATA_DEV = 8,                   /* Aligned data Data file */
263    B_ALIGNED_DEV = 9,                 /* Aligned data Meta file */
264    B_DEDUP_OLD_DEV = 10,              /* Old Deduplication device */
265    B_NULL_DEV  = 11,                  /* /dev/null for testing */
266    B_VALIGNED_DEV = 12,               /* Virtual for Aligned device (not stored) */
267    B_VDEDUP_DEV = 13,                 /* Virtual for Dedup device (not stored) */
268    B_CLOUD_DEV  = 14,                 /* New Cloud device type (available in 8.8) */
269    B_DEDUP_DEV  = 15                  /* New Deduplication Device (do not split ref records) */
270 };
271 
272 /**
273  * Actions on purge (bit mask)
274  */
275 #define ON_PURGE_TRUNCATE 1
276 
277 /* Size of File Address stored in STREAM_SPARSE_DATA. Do NOT change! */
278 #define OFFSET_FADDR_SIZE (sizeof(uint64_t))
279 
280 /* Size of crypto length stored at head of crypto buffer. Do NOT change! */
281 #define CRYPTO_LEN_SIZE ((int)sizeof(uint32_t))
282 
283 
284 /* Plugin Features */
285 #define PLUGIN_FEATURE_RESTORELISTFILES "RestoreListFiles"
286 
287 /**
288  * This is for dumb compilers/libraries like Solaris. Linux GCC
289  * does it correctly, so it might be worthwhile
290  * to remove the isascii(c) with ifdefs on such
291  * "smart" systems.
292  */
293 #define B_ISSPACE(c) (isascii((int)(c)) && isspace((int)(c)))
294 #define B_ISALPHA(c) (isascii((int)(c)) && isalpha((int)(c)))
295 #define B_ISUPPER(c) (isascii((int)(c)) && isupper((int)(c)))
296 #define B_ISDIGIT(c) (isascii((int)(c)) && isdigit((int)(c)))
297 #define B_ISXDIGIT(c) (isascii((int)(c)) && isxdigit((int)(c)))
298 
299 /** For multiplying by 10 with shift and addition */
300 #define B_TIMES10(d) ((d<<3)+(d<<1))
301 
302 
303 typedef void (HANDLER)();
304 typedef int (INTHANDLER)();
305 
306 #ifdef SETPGRP_VOID
307 # define SETPGRP_ARGS(x, y) /* No arguments */
308 #else
309 # define SETPGRP_ARGS(x, y) (x, y)
310 #endif
311 
312 #ifndef S_ISLNK
313 #define S_ISLNK(m) (((m) & S_IFM) == S_IFLNK)
314 #endif
315 
316 /** Added by KES to deal with Win32 systems */
317 #ifndef S_ISWIN32
318 #define S_ISWIN32 020000
319 #endif
320 
321 #ifndef INADDR_NONE
322 #define INADDR_NONE ((unsigned long) -1)
323 #endif
324 
325 #ifdef TIME_WITH_SYS_TIME
326 # include <sys/time.h>
327 # include <time.h>
328 #else
329 # ifdef HAVE_SYS_TIME_H
330 #  include <sys/time.h>
331 # else
332 #  include <time.h>
333 # endif
334 #endif
335 
336 #ifndef O_BINARY
337 #define O_BINARY 0
338 #endif
339 
340 #ifndef O_NOFOLLOW
341 #define O_NOFOLLOW 0
342 #endif
343 
344 #ifndef MODE_RW
345 #define MODE_RW 0666
346 #endif
347 
348 #if defined(HAVE_WIN32)
349 typedef int64_t   boffset_t;
350 #define caddr_t  char *
351 #else
352 typedef off_t     boffset_t;
353 #endif
354 
355 /* These probably should be subroutines */
356 #define Pw(x) \
357    do { int errstat; if ((errstat=rwl_writelock(&(x)))) \
358       e_msg(__FILE__, __LINE__, M_ABORT, 0, "Write lock lock failure. ERR=%s\n",\
359            strerror(errstat)); \
360    } while(0)
361 
362 #define Vw(x) \
363    do { int errstat; if ((errstat=rwl_writeunlock(&(x)))) \
364          e_msg(__FILE__, __LINE__, M_ABORT, 0, "Write lock unlock failure. ERR=%s\n",\
365            strerror(errstat)); \
366    } while(0)
367 
368 #define LockRes()   b_LockRes(__FILE__, __LINE__)
369 #define UnlockRes() b_UnlockRes(__FILE__, __LINE__)
370 
371 #ifdef DEBUG_MEMSET
372 #define memset(a, v, n) b_memset(__FILE__, __LINE__, a, v, n)
373 void b_memset(const char *file, int line, void *mem, int val, size_t num);
374 #endif
375 
376 /* we look for simple debug level
377  * then finally we check if tags are set on debug_level and lvl
378  */
379 
380 /*
381   lvl   |   debug_level  | tags  | result
382  -------+----------------+-------+-------
383   0     |   0            |       |  OK
384   T1|0  |   0            |       |  NOK
385   T1|0  |   0            |  T1   |  OK
386   10    |   0            |       |  NOK
387   10    |   10           |       |  OK
388   T1|10 |   10           |       |  NOK
389   T1|10 |   10           |  T1   |  OK
390   T1|10 |   10           |  T2   |  NOK
391  */
392 
393 /* The basic test is working because tags are on high bits */
394 #if 1
395 #define chk_dbglvl(lvl) ((lvl) <= debug_level ||                     \
396     (((lvl) & debug_level_tags) && (((lvl) & ~DT_ALL) <= debug_level)))
397 #else
398 /* Alain's macro for debug */
399 #define chk_dbglvl(lvl) (((lvl) & debug_level_tags) || (((lvl) & ~DT_ALL) <= debug_level))
400 #endif
401 /**
402  * The digit following Dmsg and Emsg indicates the number of substitutions in
403  * the message string. We need to do this kludge because non-GNU compilers
404  * do not handle varargs #defines.
405  */
406 /** Debug Messages that are printed */
407 #ifdef DEBUG
408 #define Dmsg0(lvl, msg)             if (chk_dbglvl(lvl)) d_msg(__FILE__, __LINE__, lvl, msg)
409 #define Dmsg1(lvl, msg, a1)         if (chk_dbglvl(lvl)) d_msg(__FILE__, __LINE__, lvl, msg, a1)
410 #define Dmsg2(lvl, msg, a1, a2)     if (chk_dbglvl(lvl)) d_msg(__FILE__, __LINE__, lvl, msg, a1, a2)
411 #define Dmsg3(lvl, msg, a1, a2, a3) if (chk_dbglvl(lvl)) d_msg(__FILE__, __LINE__, lvl, msg, a1, a2, a3)
412 #define Dmsg4(lvl, msg, arg1, arg2, arg3, arg4) if (chk_dbglvl(lvl)) d_msg(__FILE__, __LINE__, lvl, msg, arg1, arg2, arg3, arg4)
413 #define Dmsg5(lvl, msg, a1, a2, a3, a4, a5) if (chk_dbglvl(lvl)) d_msg(__FILE__, __LINE__, lvl, msg, a1, a2, a3, a4, a5)
414 #define Dmsg6(lvl, msg, a1, a2, a3, a4, a5, a6) if (chk_dbglvl(lvl)) d_msg(__FILE__, __LINE__, lvl, msg, a1, a2, a3, a4, a5, a6)
415 #define Dmsg7(lvl, msg, a1, a2, a3, a4, a5, a6, a7) if (chk_dbglvl(lvl)) d_msg(__FILE__, __LINE__, lvl, msg, a1, a2, a3, a4, a5, a6, a7)
416 #define Dmsg8(lvl, msg, a1, a2, a3, a4, a5, a6, a7, a8) if (chk_dbglvl(lvl)) d_msg(__FILE__, __LINE__, lvl, msg, a1, a2, a3, a4, a5, a6, a7, a8)
417 #define Dmsg9(lvl,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9) if (chk_dbglvl(lvl)) d_msg(__FILE__,__LINE__,lvl,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9)
418 #define Dmsg10(lvl,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10) if (chk_dbglvl(lvl)) d_msg(__FILE__,__LINE__,lvl,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10)
419 #define Dmsg11(lvl,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11) if (chk_dbglvl(lvl)) d_msg(__FILE__,__LINE__,lvl,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11)
420 #define Dmsg12(lvl,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12) if (chk_dbglvl(lvl)) d_msg(__FILE__,__LINE__,lvl,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12)
421 #define Dmsg13(lvl,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13) if (chk_dbglvl(lvl)) d_msg(__FILE__,__LINE__,lvl,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13)
422 #else
423 #define Dmsg0(lvl, msg)
424 #define Dmsg1(lvl, msg, a1)
425 #define Dmsg2(lvl, msg, a1, a2)
426 #define Dmsg3(lvl, msg, a1, a2, a3)
427 #define Dmsg4(lvl, msg, arg1, arg2, arg3, arg4)
428 #define Dmsg5(lvl, msg, a1, a2, a3, a4, a5)
429 #define Dmsg6(lvl, msg, a1, a2, a3, a4, a5, a6)
430 #define Dmsg7(lvl, msg, a1, a2, a3, a4, a5, a6, a7)
431 #define Dmsg8(lvl, msg, a1, a2, a3, a4, a5, a6, a7, a8)
432 #define Dmsg11(lvl,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11)
433 #define Dmsg12(lvl,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12)
434 #define Dmsg13(lvl,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13)
435 #endif /* DEBUG */
436 
437 #ifdef TRACE_FILE
438 #define Tmsg0(lvl, msg)             t_msg(__FILE__, __LINE__, lvl, msg)
439 #define Tmsg1(lvl, msg, a1)         t_msg(__FILE__, __LINE__, lvl, msg, a1)
440 #define Tmsg2(lvl, msg, a1, a2)     t_msg(__FILE__, __LINE__, lvl, msg, a1, a2)
441 #define Tmsg3(lvl, msg, a1, a2, a3) t_msg(__FILE__, __LINE__, lvl, msg, a1, a2, a3)
442 #define Tmsg4(lvl, msg, arg1, arg2, arg3, arg4) t_msg(__FILE__, __LINE__, lvl, msg, arg1, arg2, arg3, arg4)
443 #define Tmsg5(lvl, msg, a1, a2, a3, a4, a5) t_msg(__FILE__, __LINE__, lvl, msg, a1, a2, a3, a4, a5)
444 #define Tmsg6(lvl, msg, a1, a2, a3, a4, a5, a6) t_msg(__FILE__, __LINE__, lvl, msg, a1, a2, a3, a4, a5, a6)
445 #define Tmsg7(lvl, msg, a1, a2, a3, a4, a5, a6, a7) t_msg(__FILE__, __LINE__, lvl, msg, a1, a2, a3, a4, a5, a6, a7)
446 #define Tmsg8(lvl, msg, a1, a2, a3, a4, a5, a6, a7, a8) t_msg(__FILE__, __LINE__, lvl, msg, a1, a2, a3, a4, a5, a6, a7, a8)
447 #define Tmsg9(lvl,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9) t_msg(__FILE__,__LINE__,lvl,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9)
448 #define Tmsg10(lvl,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10) t_msg(__FILE__,__LINE__,lvl,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10)
449 #define Tmsg11(lvl,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11) t_msg(__FILE__,__LINE__,lvl,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11)
450 #define Tmsg12(lvl,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12) t_msg(__FILE__,__LINE__,lvl,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12)
451 #define Tmsg13(lvl,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13) t_msg(__FILE__,__LINE__,lvl,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13)
452 #else
453 #define Tmsg0(lvl, msg)
454 #define Tmsg1(lvl, msg, a1)
455 #define Tmsg2(lvl, msg, a1, a2)
456 #define Tmsg3(lvl, msg, a1, a2, a3)
457 #define Tmsg4(lvl, msg, arg1, arg2, arg3, arg4)
458 #define Tmsg5(lvl, msg, a1, a2, a3, a4, a5)
459 #define Tmsg6(lvl, msg, a1, a2, a3, a4, a5, a6)
460 #define Tmsg7(lvl, msg, a1, a2, a3, a4, a5, a6, a7)
461 #define Tmsg8(lvl, msg, a1, a2, a3, a4, a5, a6, a7, a8)
462 #define Tmsg11(lvl,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11)
463 #define Tmsg12(lvl,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12)
464 #define Tmsg13(lvl,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13)
465 #endif /* TRACE_FILE */
466 
467 
468 
469 /** Messages that are printed (uses d_msg) */
470 #define Pmsg0(lvl, msg)             p_msg(__FILE__, __LINE__, lvl, msg)
471 #define Pmsg1(lvl, msg, a1)         p_msg(__FILE__, __LINE__, lvl, msg, a1)
472 #define Pmsg2(lvl, msg, a1, a2)     p_msg(__FILE__, __LINE__, lvl, msg, a1, a2)
473 #define Pmsg3(lvl, msg, a1, a2, a3) p_msg(__FILE__, __LINE__, lvl, msg, a1, a2, a3)
474 #define Pmsg4(lvl, msg, arg1, arg2, arg3, arg4) p_msg(__FILE__, __LINE__, lvl, msg, arg1, arg2, arg3, arg4)
475 #define Pmsg5(lvl, msg, a1, a2, a3, a4, a5) p_msg(__FILE__, __LINE__, lvl, msg, a1, a2, a3, a4, a5)
476 #define Pmsg6(lvl, msg, a1, a2, a3, a4, a5, a6) p_msg(__FILE__, __LINE__, lvl, msg, a1, a2, a3, a4, a5, a6)
477 #define Pmsg7(lvl, msg, a1, a2, a3, a4, a5, a6, a7) p_msg(__FILE__, __LINE__, lvl, msg, a1, a2, a3, a4, a5, a6, a7)
478 #define Pmsg8(lvl, msg, a1, a2, a3, a4, a5, a6, a7, a8) p_msg(__FILE__, __LINE__, lvl, msg, a1, a2, a3, a4, a5, a6, a7, a8)
479 #define Pmsg9(lvl,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9) p_msg(__FILE__,__LINE__,lvl,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9)
480 #define Pmsg10(lvl,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10) p_msg(__FILE__,__LINE__,lvl,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10)
481 #define Pmsg11(lvl,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11) p_msg(__FILE__,__LINE__,lvl,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11)
482 #define Pmsg12(lvl,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12) p_msg(__FILE__,__LINE__,lvl,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12)
483 #define Pmsg13(lvl,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13) p_msg(__FILE__,__LINE__,lvl,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13)
484 #define Pmsg14(lvl,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14) p_msg(__FILE__,__LINE__,lvl,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14)
485 
486 
487 /** Daemon Error Messages that are delivered according to the message resource */
488 #define Emsg0(typ, lvl, msg)             e_msg(__FILE__, __LINE__, typ, lvl, msg)
489 #define Emsg1(typ, lvl, msg, a1)         e_msg(__FILE__, __LINE__, typ, lvl, msg, a1)
490 #define Emsg2(typ, lvl, msg, a1, a2)     e_msg(__FILE__, __LINE__, typ, lvl, msg, a1, a2)
491 #define Emsg3(typ, lvl, msg, a1, a2, a3) e_msg(__FILE__, __LINE__, typ, lvl, msg, a1, a2, a3)
492 #define Emsg4(typ, lvl, msg, a1, a2, a3, a4) e_msg(__FILE__, __LINE__, typ, lvl, msg, a1, a2, a3, a4)
493 #define Emsg5(typ, lvl, msg, a1, a2, a3, a4, a5) e_msg(__FILE__, __LINE__, typ, lvl, msg, a1, a2, a3, a4, a5)
494 #define Emsg6(typ, lvl, msg, a1, a2, a3, a4, a5, a6) e_msg(__FILE__, __LINE__, typ, lvl, msg, a1, a2, a3, a4, a5, a6)
495 
496 /** Job Error Messages that are delivered according to the message resource */
497 #define Jmsg0(jcr, typ, lvl, msg)             j_msg(__FILE__, __LINE__, jcr, typ, lvl, msg)
498 #define Jmsg1(jcr, typ, lvl, msg, a1)         j_msg(__FILE__, __LINE__, jcr, typ, lvl, msg, a1)
499 #define Jmsg2(jcr, typ, lvl, msg, a1, a2)     j_msg(__FILE__, __LINE__, jcr, typ, lvl, msg, a1, a2)
500 #define Jmsg3(jcr, typ, lvl, msg, a1, a2, a3) j_msg(__FILE__, __LINE__, jcr, typ, lvl, msg, a1, a2, a3)
501 #define Jmsg4(jcr, typ, lvl, msg, a1, a2, a3, a4) j_msg(__FILE__, __LINE__, jcr, typ, lvl, msg, a1, a2, a3, a4)
502 #define Jmsg5(jcr, typ, lvl, msg, a1, a2, a3, a4, a5) j_msg(__FILE__, __LINE__, jcr, typ, lvl, msg, a1, a2, a3, a4, a5)
503 #define Jmsg6(jcr, typ, lvl, msg, a1, a2, a3, a4, a5, a6) j_msg(__FILE__, __LINE__, jcr, typ, lvl, msg, a1, a2, a3, a4, a5, a6)
504 #define Jmsg7(jcr, typ, lvl, msg, a1, a2, a3, a4, a5, a6, a7) j_msg(__FILE__, __LINE__, jcr, typ, lvl, msg, a1, a2, a3, a4, a5, a6, a7)
505 #define Jmsg8(jcr, typ, lvl, msg, a1, a2, a3, a4, a5, a6, a7, a8) j_msg(__FILE__, __LINE__, jcr, typ, lvl, msg, a1, a2, a3, a4, a5, a6, a7, a8)
506 
507 /** Queued Job Error Messages that are delivered according to the message resource */
508 #define Qmsg0(jcr, typ, mtime, msg)             q_msg(__FILE__, __LINE__, jcr, typ, mtime, msg)
509 #define Qmsg1(jcr, typ, mtime, msg, a1)         q_msg(__FILE__, __LINE__, jcr, typ, mtime, msg, a1)
510 #define Qmsg2(jcr, typ, mtime, msg, a1, a2)     q_msg(__FILE__, __LINE__, jcr, typ, mtime, msg, a1, a2)
511 #define Qmsg3(jcr, typ, mtime, msg, a1, a2, a3) q_msg(__FILE__, __LINE__, jcr, typ, mtime, msg, a1, a2, a3)
512 #define Qmsg4(jcr, typ, mtime, msg, a1, a2, a3, a4) q_msg(__FILE__, __LINE__, jcr, typ, mtime, msg, a1, a2, a3, a4)
513 #define Qmsg5(jcr, typ, mtime, msg, a1, a2, a3, a4, a5) q_msg(__FILE__, __LINE__, jcr, typ, mtime, msg, a1, a2, a3, a4, a5)
514 #define Qmsg6(jcr, typ, mtime, msg, a1, a2, a3, a4, a5, a6) q_msg(__FILE__, __LINE__, jcr, typ, mtime, msg, a1, a2, a3, a4, a5, a6)
515 
516 
517 /** Memory Messages that are edited into a Pool Memory buffer */
518 #define Mmsg0(buf, msg)             m_msg(__FILE__, __LINE__, buf, msg)
519 #define Mmsg1(buf, msg, a1)         m_msg(__FILE__, __LINE__, buf, msg, a1)
520 #define Mmsg2(buf, msg, a1, a2)     m_msg(__FILE__, __LINE__, buf, msg, a1, a2)
521 #define Mmsg3(buf, msg, a1, a2, a3) m_msg(__FILE__, __LINE__, buf, msg, a1, a2, a3)
522 #define Mmsg4(buf, msg, a1, a2, a3, a4) m_msg(__FILE__, __LINE__, buf, msg, a1, a2, a3, a4)
523 #define Mmsg5(buf, msg, a1, a2, a3, a4, a5) m_msg(__FILE__, __LINE__, buf, msg, a1, a2, a3, a4, a5)
524 #define Mmsg6(buf, msg, a1, a2, a3, a4, a5, a6) m_msg(__FILE__, __LINE__, buf, msg, a1, a2, a3, a4, a5, a6)
525 #define Mmsg7(buf, msg, a1, a2, a3, a4, a5, a6, a7) m_msg(__FILE__, __LINE__, buf, msg, a1, a2, a3, a4, a5, a6)
526 #define Mmsg8(buf,msg,a1,a2,a3,a4,a5,a6,a7,a8) m_msg(__FILE__,__LINE__,buf,msg,a1,a2,a3,a4,a5,a6)
527 #define Mmsg11(buf,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11) m_msg(__FILE__,__LINE__,buf,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11)
528 #define Mmsg15(buf,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15) m_msg(__FILE__,__LINE__,buf,msg,a1,a2,a3,a4,a5,a6,a7,a8,a9,a10,a11,a12,a13,a14,a15)
529 
530 class POOL_MEM;
531 /* Edit message into Pool Memory buffer -- no __FILE__ and __LINE__ */
532 int  Mmsg(POOLMEM **msgbuf, const char *fmt,...);
533 int  Mmsg(POOLMEM *&msgbuf, const char *fmt,...);
534 int  Mmsg(POOL_MEM &msgbuf, const char *fmt,...);
535 
536 #define MmsgD0(level, msgbuf, fmt) \
537    { Mmsg(msgbuf, fmt); Dmsg1(level, "%s", msgbuf); }
538 #define MmsgD1(level, msgbuf, fmt, a1) \
539    { Mmsg(msgbuf, fmt, a1); Dmsg1(level, "%s", msgbuf); }
540 #define MmsgD2(level, msgbuf, fmt, a1, a2) \
541    { Mmsg(msgbuf, fmt, a1, a2); Dmsg1(level, "%s", msgbuf); }
542 #define MmsgD3(level, msgbuf, fmt, a1, a2, a3) \
543    { Mmsg(msgbuf, fmt, a1, a2, a3); Dmsg1(level, "%s", msgbuf); }
544 #define MmsgD4(level, msgbuf, fmt, a1, a2, a3, a4) \
545    { Mmsg(msgbuf, fmt, a1, a2, a3, a4); Dmsg1(level, "%s", msgbuf); }
546 #define MmsgD5(level, msgbuf, fmt, a1, a2, a3, a4, a5) \
547    { Mmsg(msgbuf, fmt, a1, a2, a3, a4, a5); Dmsg1(level, "%s", msgbuf); }
548 #define MmsgD6(level, msgbuf, fmt, a1, a2, a3, a4, a5, a6) \
549    { Mmsg(msgbuf, fmt, a1, a2, a3, a4, a5, a6); Dmsg1(level, "%s", msgbuf); }
550 
551 #define MmsgT0(level, msgbuf, fmt) \
552    { Mmsg(msgbuf, fmt); Tmsg1(level, "%s", msgbuf); }
553 #define MmsgT1(level, msgbuf, fmt, a1) \
554    { Mmsg(msgbuf, fmt, a1); Tmsg1(level, "%s", msgbuf); }
555 #define MmsgT2(level, msgbuf, fmt, a1, a2) \
556    { Mmsg(msgbuf, fmt, a1, a2); Tmsg1(level, "%s", msgbuf); }
557 #define MmsgT3(level, msgbuf, fmt, a1, a2, a3) \
558    { Mmsg(msgbuf, fmt, a1, a2, a3); Tmsg1(level, "%s", msgbuf); }
559 #define MmsgT4(level, msgbuf, fmt, a1, a2, a3, a4) \
560    { Mmsg(msgbuf, fmt, a1, a2, a3, a4); Tmsg1(level, "%s", msgbuf); }
561 #define MmsgT5(level, msgbuf, fmt, a1, a2, a3, a4, a5) \
562    { Mmsg(msgbuf, fmt, a1, a2, a3, a4, a5); Tmsg1(level, "%s", msgbuf); }
563 #define MmsgT6(level, msgbuf, fmt, a1, a2, a3, a4, a5, a6) \
564    { Mmsg(msgbuf, fmt, a1, a2, a3, a4, a5, a6); Tmsg1(level, "%s", msgbuf); }
565 
566 class JCR;
567 void d_msg(const char *file, int line, int64_t level, const char *fmt,...);
568 void p_msg(const char *file, int line, int level, const char *fmt,...);
569 void e_msg(const char *file, int line, int type, int level, const char *fmt,...);
570 void j_msg(const char *file, int line, JCR *jcr, int type, utime_t mtime, const char *fmt,...);
571 void q_msg(const char *file, int line, JCR *jcr, int type, utime_t mtime, const char *fmt,...);
572 int  m_msg(const char *file, int line, POOLMEM **msgbuf, const char *fmt,...);
573 int  m_msg(const char *file, int line, POOLMEM *&pool_buf, const char *fmt, ...);
574 void t_msg(const char *file, int line, int64_t level, const char *fmt,...);
575 
576 /* Use bstrncpy instead of strncpy because it ensures last char is a 0 */
577 #define strncpy bad_call_on_strncpy_use_bstrncpy
578 
579 /** Use our strdup with smartalloc */
580 #ifndef HAVE_WXCONSOLE
581 #undef strdup
582 #define strdup(buf) bad_call_on_strdup_use_bstrdup(buf)
583 #else
584 /* Groan, WxWidgets has its own way of doing NLS so cleanup */
585 #ifndef ENABLE_NLS
586 #undef _
587 #undef setlocale
588 #undef textdomain
589 #undef bindtextdomain
590 #endif
591 #endif
592 
593 /** Use our fgets which handles interrupts */
594 #undef fgets
595 #define fgets(x,y,z) bfgets((x), (y), (z))
596 
597 /** Use our sscanf, which is safer and works with known sizes */
598 #define sscanf bsscanf
599 
600 /* Use our fopen, which uses the CLOEXEC flag */
601 #define fopen bfopen
602 
603 #ifdef DEBUG
604 #define bstrdup(str) strcpy((char *)b_malloc(__FILE__,__LINE__,strlen((str))+1),(str))
605 #else
606 #define bstrdup(str) strcpy((char *)bmalloc(strlen((str))+1),(str))
607 #endif
608 
609 #ifdef DEBUG
610 #define bmalloc(size) b_malloc(__FILE__, __LINE__, (size))
611 #endif
612 
613 /** Macro to simplify free/reset pointers */
614 #define bfree_and_null(a) do{if(a){void *b__=(void*)a; (a)=NULL; bfree(b__);}} while(0)
615 
616 /* If changed, please run the tests in tools/test-cpp.c */
617 #if __cplusplus >= 201103L
618 # define bdelete_and_null(a) do{if(a){auto b__ = a; (a)=NULL; delete b__;}} while(0)
619 #else
620 # ifdef HAVE_TYPEOF
621 #  define bdelete_and_null(a) do{if(a){typeof(a) b__ = a; (a)=NULL; delete b__;}} while(0)
622 # else
623 #  define bdelete_and_null(a) do{if(a){delete a; (a)=NULL;}} while(0)
624 # endif
625 #endif
626 
627 /**
628  * Replace codes needed in both file routines and non-file routines
629  * Job replace codes -- in "replace"
630  */
631 #define REPLACE_ALWAYS   'a'
632 #define REPLACE_IFNEWER  'w'
633 #define REPLACE_NEVER    'n'
634 #define REPLACE_IFOLDER  'o'
635 
636 /** This probably should be done on a machine by machine basis, but it works */
637 /** This is critical for the smartalloc routines to properly align memory */
638 #define ALIGN_SIZE (sizeof(double))
639 #define BALIGN(x) (((x) + ALIGN_SIZE - 1) & ~(ALIGN_SIZE -1))
640 
641 
642 /* =============================================================
643  *               OS Dependent defines
644  * =============================================================
645  */
646 #if defined (__digital__) && defined (__unix__)
647 /* Tru64 - has 64 bit fseeko and ftello */
648 #define  fseeko fseek
649 #define  ftello ftell
650 #endif /* digital stuff */
651 
652 #ifndef HAVE_FSEEKO
653 /* This OS does not handle 64 bit fseeks and ftells */
654 #define  fseeko fseek
655 #define  ftello ftell
656 #endif
657 
658 
659 #ifdef HAVE_WIN32
660 /*
661  *   Windows
662  */
663 #define PathSeparator '\\'
664 #define PathSeparatorUp "..\\"
665 #define PathSeparatorCur ".\\"
666 
IsPathSeparator(int ch)667 inline bool IsPathSeparator(int ch) { return ch == '/' || ch == '\\'; }
IsWPathSeparator(wchar_t ch)668 inline bool IsWPathSeparator(wchar_t ch) { return ch == L'/' || ch == L'\\'; }
first_path_separator(char * path)669 inline char *first_path_separator(char *path) { return strpbrk(path, "/\\"); }
first_path_separator(const char * path)670 inline const char *first_path_separator(const char *path) { return strpbrk(path, "/\\"); }
671 
672 extern void pause_msg(const char *file, const char *func, int line, const char *msg);
673 #define pause(msg) if (debug_level) pause_msg(__FILE__, __func__, __LINE__, (msg))
674 
675 #else /* Unix/Linux */
676 #define PathSeparator '/'
677 #define PathSeparatorUp "../"
678 #define PathSeparatorCur "./"
679 
680 /* Define Winsock functions if we aren't on Windows */
681 
682 #define WSA_Init() 0 /* 0 = success */
683 #define WSACleanup() 0 /* 0 = success */
684 
IsPathSeparator(int ch)685 inline bool IsPathSeparator(int ch) { return ch == '/'; }
first_path_separator(char * path)686 inline char *first_path_separator(char *path) { return strchr(path, '/'); }
first_path_separator(const char * path)687 inline const char *first_path_separator(const char *path) { return strchr(path, '/'); }
688 #define pause(msg)
689 #endif /* HAVE_WIN32 */
690 
691 #ifdef HAVE_DARWIN_OS
692 /* Apparently someone forgot to wrap getdomainname as a C function */
693 #ifdef __cplusplus
694 extern "C" {
695 #endif
696 int getdomainname(char *name, int namelen);
697 #ifdef __cplusplus
698 }
699 #endif
700 #endif /* HAVE_DARWIN_OS */
701 
702 
703 /* **** Unix Systems **** */
704 #ifdef HAVE_SUN_OS
705 /*
706  * On Solaris 2.5/2.6/7 and 8, threads are not timesliced by default,
707  * so we need to explictly increase the conncurrency level.
708  */
709 #ifdef USE_THR_SETCONCURRENCY
710 #include <thread.h>
711 #define set_thread_concurrency(x)  thr_setconcurrency(x)
712 extern int thr_setconcurrency(int);
713 #define SunOS 1
714 #else
715 #define set_thread_concurrency(x)
716 #define thr_setconcurrency(x)
717 #endif
718 
719 #else
720 #define set_thread_concurrency(x)
721 #endif /* HAVE_SUN_OS */
722 
723 
724 #ifdef HAVE_OSF1_OS
725 #ifdef __cplusplus
726 extern "C" {
727 #endif
728 int fchdir(int filedes);
729 long gethostid(void);
730 int getdomainname(char *name, int namelen);
731 #ifdef __cplusplus
732 }
733 #endif
734 #endif /* HAVE_OSF1_OS */
735 
736 
737 #ifdef HAVE_HPUX_OS
738 # undef h_errno
739 extern int h_errno;
740 /** the {get,set}domainname() functions exist in HPUX's libc.
741  * the configure script detects that correctly.
742  * the problem is no system headers declares the prototypes for these functions
743  * this is done below
744  */
745 #ifdef __cplusplus
746 extern  "C" {
747 #endif
748 int getdomainname(char *name, int namlen);
749 int setdomainname(char *name, int namlen);
750 #ifdef __cplusplus
751 }
752 #endif
753 #endif /* HAVE_HPUX_OS */
754 
755 
756 /** Disabled because it breaks internationalisation...
757 #undef HAVE_SETLOCALE
758 #ifdef HAVE_SETLOCALE
759 #include <locale.h>
760 #else
761 #define setlocale(x, y) ("ANSI_X3.4-1968")
762 #endif
763 #ifdef HAVE_NL_LANGINFO
764 #include <langinfo.h>
765 #else
766 #define nl_langinfo(x) ("ANSI_X3.4-1968")
767 #endif
768 */
769 
770 /** Determine endianes */
bigendian()771 static inline bool bigendian() { return htonl(1) == 1L; }
772 
773 #ifndef __GNUC__
774 #define __PRETTY_FUNCTION__ __func__
775 #endif
776 #ifdef HAVE_SUN_OS
777 #undef ENTER_LEAVE
778 #endif
779 #ifdef ENTER_LEAVE
780 #define Enter(lvl) Dmsg1(lvl, "Enter: %s\n", __PRETTY_FUNCTION__)
781 #define Leave(lvl) Dmsg1(lvl, "Leave: %s\n", __PRETTY_FUNCTION__)
782 #else
783 #define Enter(lvl)
784 #define Leave(lvl)
785 #endif
786 
787 #ifdef __GNUC__x
788 # define CHECK_FORMAT(fun, f, a) __attribute__ ((format (fun, f, a)))
789 #else
790 # define CHECK_FORMAT(fun, f, a)
791 #endif
792 
793 /* error_t is a type that can be used for the return value of functions to tell
794  * the developer how to handle the result
795  * value == 0 : means no error
796  * value > 0 : are for expected or controlled conditions, like to notify that
797  *             the end of file is reached or that the last element has been processed
798  * value < 0 : are for exceptional or unexpected errors like memory allocation
799  *             failures or failing open("/dev/null"), ....
800  */
801 typedef int error_t;
802 
803 #endif /* _BACONFIG_H */
804