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