1 /*
2    BAREOS® - Backup Archiving REcovery Open Sourced
3 
4    Copyright (C) 2000-2010 Free Software Foundation Europe e.V.
5    Copyright (C) 2011-2012 Planets Communications B.V.
6    Copyright (C) 2013-2019 Bareos GmbH & Co. KG
7 
8    This program is Free Software; you can redistribute it and/or
9    modify it under the terms of version three of the GNU Affero General Public
10    License as published by the Free Software Foundation and included
11    in the file LICENSE.
12 
13    This program is distributed in the hope that it will be useful, but
14    WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16    Affero General Public License for more details.
17 
18    You should have received a copy of the GNU Affero General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21    02110-1301, USA.
22 */
23 /**
24  * @file
25  * General header file configurations that apply to
26  * all daemons.  System dependent stuff goes here.
27  *
28  */
29 
30 
31 #ifndef BAREOS_INCLUDE_BACONFIG_H_
32 #define BAREOS_INCLUDE_BACONFIG_H_ 1
33 
34 
35 /* Bareos common configuration defines */
36 
37 #undef  TRUE
38 #undef  FALSE
39 #define TRUE  1
40 #define FALSE 0
41 
42 #ifdef HAVE_TLS
43 #define have_tls 1
44 #else
45 #define have_tls 0
46 #endif
47 
48 #ifndef ETIME
49 #define ETIME ETIMEDOUT
50 #endif
51 
52 #ifdef HAVE_IOCTL_ULINT_REQUEST
53 #define ioctl_req_t unsigned long int
54 #else
55 #define ioctl_req_t int
56 #endif
57 
58 
59 #ifdef PROTOTYPES
60 # define __PROTO(p)     p
61 #else
62 # define __PROTO(p)     ()
63 #endif
64 
65 #ifdef DEBUG
66 /**
67  * In DEBUG mode an assert that is triggered generates a segmentation
68  * fault so we can capture the debug info using btraceback.
69  */
70 #define ASSERT(x) if (!(x)) { \
71    char *fatal = NULL; \
72    Emsg1(M_ERROR, 0, _("Failed ASSERT: %s\n"), #x); \
73    Pmsg1(000, _("Failed ASSERT: %s\n"), #x); \
74    fatal[0] = 0; }
75 #define ASSERT2(x,y) if (!(x)) { \
76    assert_msg =  y; \
77    Emsg1(M_ERROR, 0, _("Failed ASSERT: %s\n"), #x); \
78    Pmsg1(000, _("Failed ASSERT: %s\n"), #x); \
79    char *fatal = NULL; \
80    fatal[0] = 0; }
81 #else
82 #define ASSERT(x)
83 #define ASSERT2(x, y)
84 #endif
85 
86 /**
87  * Allow printing of NULL pointers
88  */
89 #define NPRT(x) (x)?(x):_("*None*")
90 #define NPRTB(x) (x)?(x):""
91 
92 #if defined(HAVE_WIN32)
93 /**
94  * Reduce compiler warnings from Windows vss code
95  */
96 #define uuid(x)
97 
98 void InitWinAPIWrapper();
99 
100 #define  OSDependentInit()    InitWinAPIWrapper()
101 
102 #define sbrk(x)  0
103 
104 #define ClearThreadId(x) memset(&(x), 0, sizeof(x))
105 
106 #else  /* HAVE_WIN32 */
107 
108 #define ClearThreadId(x) x = 0
109 #define  OSDependentInit()
110 
111 #endif /* HAVE_WIN32 */
112 
113 #ifdef ENABLE_NLS
114    #include <libintl.h>
115    #include <locale.h>
116    #ifndef _
117       #define _(s) gettext((s))
118    #endif /* _ */
119    #ifndef N_
120       #define N_(s) (s)
121    #endif /* N_ */
122 #else /* !ENABLE_NLS */
123    #include <locale.h>
124    #undef _
125    #undef N_
126    #undef textdomain
127    #undef bindtextdomain
128 
129    #ifndef _
130       #define _(s) (s)
131    #endif
132    #ifndef N_
133       #define N_(s) (s)
134    #endif
135    #ifndef textdomain
136       #define textdomain(d)
137    #endif
138    #ifndef bindtextdomain
139       #define bindtextdomain(p, d)
140    #endif
141 #endif /* ENABLE_NLS */
142 
143 
144 /* Use the following for strings not to be translated */
145 #define NT_(s) (s)
146 
147 /* Maximum length to edit time/date */
148 #define MAX_TIME_LENGTH 50
149 
150 /* Maximum Name length including EOS */
151 #define MAX_NAME_LENGTH 128
152 
153 /* Maximum escaped Name length including EOS 2*MAX_NAME_LENGTH+1 */
154 #define MAX_ESCAPE_NAME_LENGTH 257
155 
156 /* Maximum number of user entered command args */
157 #define MAX_CMD_ARGS 30
158 
159 /* All tape operations MUST be a multiple of this */
160 #define TAPE_BSIZE 1024
161 
162 /* Maximum length of a hostname */
163 #ifndef MAXHOSTNAMELEN
164 #define MAXHOSTNAMELEN 256
165 #endif
166 
167 /* Default length of passphrases used */
168 #define DEFAULT_PASSPHRASE_LENGTH 32
169 
170 #ifdef DEV_BSIZE
171 #define B_DEV_BSIZE DEV_BSIZE
172 #endif
173 
174 #if !defined(B_DEV_BSIZE) & defined(BSIZE)
175 #define B_DEV_BSIZE BSIZE
176 #endif
177 
178 #ifndef B_DEV_BSIZE
179 #define B_DEV_BSIZE 512
180 #endif
181 
182 /**
183  * Set to time limit for other end to respond to
184  *  authentication.  Normally 10 minutes is *way*
185  *  more than enough. The idea is to keep the Director
186  *  from hanging because there is a dead connection on
187  *  the other end.
188  */
189 #define AUTH_TIMEOUT 60 * 10
190 
191 /**
192  * Default network buffer size
193  */
194 #define DEFAULT_NETWORK_BUFFER_SIZE (64 * 1024)
195 
196 /**
197  * Tape label types -- stored in catalog
198  */
199 #define B_BAREOS_LABEL 0
200 #define B_ANSI_LABEL   1
201 #define B_IBM_LABEL    2
202 
203 /**
204  * Actions on purge (bit mask)
205  */
206 #define ON_PURGE_NONE 0
207 #define ON_PURGE_TRUNCATE 1
208 
209 /* Size of File Address stored in STREAM_SPARSE_DATA. Do NOT change! */
210 #define OFFSET_FADDR_SIZE (sizeof(uint64_t))
211 
212 /* Size of crypto length stored at head of crypto buffer. Do NOT change! */
213 #define CRYPTO_LEN_SIZE ((int)sizeof(uint32_t))
214 
215 
216 /**
217  * This is for dumb compilers/libraries like Solaris. Linux GCC
218  * does it correctly, so it might be worthwhile
219  * to remove the isascii(c) with ifdefs on such
220  * "smart" systems.
221  */
222 #define B_ISSPACE(c) (isascii((int)(c)) && isspace((int)(c)))
223 #define B_ISALPHA(c) (isascii((int)(c)) && isalpha((int)(c)))
224 #define B_ISUPPER(c) (isascii((int)(c)) && isupper((int)(c)))
225 #define B_ISDIGIT(c) (isascii((int)(c)) && isdigit((int)(c)))
226 
227 /** For multiplying by 10 with shift and addition */
228 #define B_TIMES10(d) ((d<<3)+(d<<1))
229 
230 
231 typedef void (HANDLER)();
232 typedef int (INTHANDLER)();
233 
234 #ifdef SETPGRP_VOID
235 # define SETPGRP_ARGS(x, y) /* No arguments */
236 #else
237 # define SETPGRP_ARGS(x, y) (x, y)
238 #endif
239 
240 #ifndef S_ISLNK
241 #define S_ISLNK(m) (((m) & S_IFM) == S_IFLNK)
242 #endif
243 
244 /** Added by KES to deal with Win32 systems */
245 #ifndef S_ISWIN32
246 #define S_ISWIN32 020000
247 #endif
248 
249 #ifndef INADDR_NONE
250 #define INADDR_NONE ((unsigned long) -1)
251 #endif
252 
253 #ifdef TIME_WITH_SYS_TIME
254 #include <sys/time.h>
255 #include <time.h>
256 #else
257 #ifdef HAVE_SYS_TIME_H
258 #include <sys/time.h>
259 #else
260 #include <time.h>
261 #endif
262 #endif
263 
264 #ifndef O_BINARY
265 #define O_BINARY 0
266 #endif
267 
268 #ifndef O_NOFOLLOW
269 #define O_NOFOLLOW 0
270 #endif
271 
272 #ifndef MODE_RW
273 #define MODE_RW 0666
274 #endif
275 
276 
277 enum {
278 API_MODE_OFF = 0,
279 API_MODE_ON = 1,
280 API_MODE_JSON = 2
281 };
282 
283 #if defined(HAVE_WIN32)
284 typedef int64_t   boffset_t;
285 #define caddr_t  char *
286 #else
287 typedef off_t     boffset_t;
288 #endif
289 
290 /**
291 * Create some simple types for now int16_t e.g. 65 K should be enough.
292 */
293 typedef int16_t slot_number_t;
294 typedef int16_t drive_number_t;
295 typedef int16_t slot_flags_t;
296 
297 /* These probably should be subroutines */
298 #define Pw(x) \
299 do { int errstat; if ((errstat=RwlWritelock(&(x)))) \
300    e_msg(__FILE__, __LINE__, M_ABORT, 0, "Write lock lock failure. ERR=%s\n",\
301         strerror(errstat)); \
302 } while(0)
303 
304 #define Vw(x) \
305 do { int errstat; if ((errstat=RwlWriteunlock(&(x)))) \
306       e_msg(__FILE__, __LINE__, M_ABORT, 0, "Write lock unlock failure. ERR=%s\n",\
307         strerror(errstat)); \
308 } while(0)
309 
310 #define LockRes(x)   (x)->b_LockRes(__FILE__, __LINE__)
311 #define UnlockRes(x) (x)->b_UnlockRes(__FILE__, __LINE__)
312 
313 #ifdef DEBUG_MEMSET
314 #define memset(a, v, n) b_memset(__FILE__, __LINE__, a, v, n)
315 void b_memset(const char *file, int line, void *mem, int val, size_t num);
316 #endif
317 
318 /**
319 * The digit following Dmsg and Emsg indicates the number of substitutions in
320 * the message string. We need to do this kludge because non-GNU compilers
321 * do not handle varargs #defines.
322 */
323 /** Debug Messages that are printed */
324 #ifdef DEBUG
325 #define Dmsg0(lvl, msg) \
326 if ((lvl)<=debug_level) d_msg(__FILE__, __LINE__, lvl, msg)
327 #define Dmsg1(lvl, msg, a1) \
328 if ((lvl)<=debug_level) d_msg(__FILE__, __LINE__, lvl, msg, a1)
329 #define Dmsg2(lvl, msg, a1, a2) \
330 if ((lvl)<=debug_level) d_msg(__FILE__, __LINE__, lvl, msg, a1, a2)
331 #define Dmsg3(lvl, msg, a1, a2, a3) \
332 if ((lvl)<=debug_level) d_msg(__FILE__, __LINE__, lvl, msg, a1, a2, a3)
333 #define Dmsg4(lvl, msg, a1, a2, a3, a4) \
334 if ((lvl)<=debug_level) d_msg(__FILE__, __LINE__, lvl, msg, a1, a2, a3, a4)
335 #define Dmsg5(lvl, msg, a1, a2, a3, a4, a5) \
336 if ((lvl)<=debug_level) d_msg(__FILE__, __LINE__, lvl, msg, a1, a2, a3, a4, a5)
337 #define Dmsg6(lvl, msg, a1, a2, a3, a4, a5, a6) \
338 if ((lvl)<=debug_level) d_msg(__FILE__, __LINE__, lvl, msg, a1, a2, a3, a4, a5, a6)
339 #define Dmsg7(lvl, msg, a1, a2, a3, a4, a5, a6, a7) \
340 if ((lvl)<=debug_level) d_msg(__FILE__, __LINE__, lvl, msg, a1, a2, a3, a4, a5, a6, a7)
341 #define Dmsg8(lvl, msg, a1, a2, a3, a4, a5, a6, a7, a8) \
342 if ((lvl)<=debug_level) d_msg(__FILE__, __LINE__, lvl, msg, a1, a2, a3, a4, a5, a6, a7, a8)
343 #define Dmsg9(lvl, msg, a1, a2, a3, a4, a5, a6, a7, a8, a9) \
344 if ((lvl)<=debug_level) d_msg(__FILE__,__LINE__, lvl, msg, a1, a2, a3, a4, a5, a6, a7, a8, a9)
345 #define Dmsg10(lvl, msg, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) \
346 if ((lvl)<=debug_level) d_msg(__FILE__,__LINE__, lvl, msg, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10)
347 #define Dmsg11(lvl, msg, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11) \
348 if ((lvl)<=debug_level) d_msg(__FILE__,__LINE__, lvl, msg, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11)
349 #define Dmsg12(lvl, msg, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12) \
350 if ((lvl)<=debug_level) d_msg(__FILE__,__LINE__, lvl, msg, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12)
351 #define Dmsg13(lvl, msg, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13) \
352 if ((lvl)<=debug_level) d_msg(__FILE__,__LINE__, lvl, msg, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13)
353 #else
354 #define Dmsg0(lvl, msg)
355 #define Dmsg1(lvl, msg, a1)
356 #define Dmsg2(lvl, msg, a1, a2)
357 #define Dmsg3(lvl, msg, a1, a2, a3)
358 #define Dmsg4(lvl, msg, a1, a2, a3, a4)
359 #define Dmsg5(lvl, msg, a1, a2, a3, a4, a5)
360 #define Dmsg6(lvl, msg, a1, a2, a3, a4, a5, a6)
361 #define Dmsg7(lvl, msg, a1, a2, a3, a4, a5, a6, a7)
362 #define Dmsg8(lvl, msg, a1, a2, a3, a4, a5, a6, a7, a8)
363 #define Dmsg11(lvl, msg, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11)
364 #define Dmsg12(lvl, msg, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12)
365 #define Dmsg13(lvl, msg, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13)
366 #endif /* DEBUG */
367 
368 #ifdef TRACE_FILE
369 #define Tmsg0(lvl, msg) \
370 t_msg(__FILE__, __LINE__, lvl, msg)
371 #define Tmsg1(lvl, msg, a1) \
372 t_msg(__FILE__, __LINE__, lvl, msg, a1)
373 #define Tmsg2(lvl, msg, a1, a2) \
374 t_msg(__FILE__, __LINE__, lvl, msg, a1, a2)
375 #define Tmsg3(lvl, msg, a1, a2, a3) \
376 t_msg(__FILE__, __LINE__, lvl, msg, a1, a2, a3)
377 #define Tmsg4(lvl, msg, a1, a2, a3, a4) \
378 t_msg(__FILE__, __LINE__, lvl, msg, a1, a2, a3, a4)
379 #define Tmsg5(lvl, msg, a1, a2, a3, a4, a5) \
380 t_msg(__FILE__, __LINE__, lvl, msg, a1, a2, a3, a4, a5)
381 #define Tmsg6(lvl, msg, a1, a2, a3, a4, a5, a6) \
382 t_msg(__FILE__, __LINE__, lvl, msg, a1, a2, a3, a4, a5, a6)
383 #define Tmsg7(lvl, msg, a1, a2, a3, a4, a5, a6, a7) \
384 t_msg(__FILE__, __LINE__, lvl, msg, a1, a2, a3, a4, a5, a6, a7)
385 #define Tmsg8(lvl, msg, a1, a2, a3, a4, a5, a6, a7, a8) \
386 t_msg(__FILE__, __LINE__, lvl, msg, a1, a2, a3, a4, a5, a6, a7, a8)
387 #define Tmsg9(lvl, msg, a1, a2, a3, a4, a5, a6, a7, a8, a9) \
388 t_msg(__FILE__, __LINE__, lvl, msg, a1, a2, a3, a4, a5, a6, a7, a8, a9)
389 #define Tmsg10(lvl, msg, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) \
390 t_msg(__FILE__, __LINE__, lvl, msg, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10)
391 #define Tmsg11(lvl, msg, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11) \
392 t_msg(__FILE__, __LINE__, lvl, msg, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11)
393 #define Tmsg12(lvl, msg, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12) \
394 t_msg(__FILE__, __LINE__, lvl, msg, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12)
395 #define Tmsg13(lvl, msg, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13) \
396 t_msg(__FILE__, __LINE__, lvl, msg, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13)
397 #else
398 #define Tmsg0(lvl, msg)
399 #define Tmsg1(lvl, msg, a1)
400 #define Tmsg2(lvl, msg, a1, a2)
401 #define Tmsg3(lvl, msg, a1, a2, a3)
402 #define Tmsg4(lvl, msg, a1, a2, a3, a4)
403 #define Tmsg5(lvl, msg, a1, a2, a3, a4, a5)
404 #define Tmsg6(lvl, msg, a1, a2, a3, a4, a5, a6)
405 #define Tmsg7(lvl, msg, a1, a2, a3, a4, a5, a6, a7)
406 #define Tmsg8(lvl, msg, a1, a2, a3, a4, a5, a6, a7, a8)
407 #define Tmsg9(lvl, msg, a1, a2, a3, a4, a5, a6, a7, a8, a9)
408 #define Tmsg10(lvl, msg, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10)
409 #define Tmsg11(lvl, msg, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11)
410 #define Tmsg12(lvl, msg, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12)
411 #define Tmsg13(lvl, msg, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13)
412 #endif /* TRACE_FILE */
413 
414 /** Messages that are printed (uses p_msg) */
415 #define Pmsg0(lvl, msg) \
416 p_msg(__FILE__, __LINE__, lvl, msg)
417 #define Pmsg1(lvl, msg, a1) \
418 p_msg(__FILE__, __LINE__, lvl, msg, a1)
419 #define Pmsg2(lvl, msg, a1, a2) \
420 p_msg(__FILE__, __LINE__, lvl, msg, a1, a2)
421 #define Pmsg3(lvl, msg, a1, a2, a3) \
422 p_msg(__FILE__, __LINE__, lvl, msg, a1, a2, a3)
423 #define Pmsg4(lvl, msg, a1, a2, a3, a4) \
424 p_msg(__FILE__, __LINE__, lvl, msg, a1, a2, a3, a4)
425 #define Pmsg5(lvl, msg, a1, a2, a3, a4, a5) \
426 p_msg(__FILE__, __LINE__, lvl, msg, a1, a2, a3, a4, a5)
427 #define Pmsg6(lvl, msg, a1, a2, a3, a4, a5, a6) \
428 p_msg(__FILE__, __LINE__, lvl, msg, a1, a2, a3, a4, a5, a6)
429 #define Pmsg7(lvl, msg, a1, a2, a3, a4, a5, a6, a7) \
430 p_msg(__FILE__, __LINE__, lvl, msg, a1, a2, a3, a4, a5, a6, a7)
431 #define Pmsg8(lvl, msg, a1, a2, a3, a4, a5, a6, a7, a8) \
432 p_msg(__FILE__, __LINE__, lvl, msg, a1, a2, a3, a4, a5, a6, a7, a8)
433 #define Pmsg9(lvl, msg, a1, a2, a3, a4, a5, a6, a7, a8, a9) \
434 p_msg(__FILE__, __LINE__, lvl, msg, a1, a2, a3, a4, a5, a6, a7, a8, a9)
435 #define Pmsg10(lvl, msg, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10) \
436 p_msg(__FILE__, __LINE__, lvl, msg, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10)
437 #define Pmsg11(lvl, msg, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11) \
438 p_msg(__FILE__, __LINE__, lvl, msg, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11)
439 #define Pmsg12(lvl, msg, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12) \
440 p_msg(__FILE__, __LINE__, lvl, msg, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12)
441 #define Pmsg13(lvl, msg, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13) \
442 p_msg(__FILE__, __LINE__, lvl, msg, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13)
443 #define Pmsg14(lvl, msg, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14) \
444 p_msg(__FILE__, __LINE__, lvl, msg, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14)
445 #define Pmsg15(lvl, msg, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15) \
446 p_msg(__FILE__, __LINE__, lvl, msg, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15)
447 
448 /** Messages that are printed using fixed size buffers (uses p_msg_fb) */
449 #define FPmsg0(lvl, msg) \
450 p_msg_fb(__FILE__, __LINE__, lvl, msg)
451 #define FPmsg1(lvl, msg, a1) \
452 p_msg_fb(__FILE__, __LINE__, lvl, msg, a1)
453 #define FPmsg2(lvl, msg, a1, a2) \
454 p_msg_fb(__FILE__, __LINE__, lvl, msg, a1, a2)
455 #define FPmsg3(lvl, msg, a1, a2, a3) \
456 p_msg_fb(__FILE__, __LINE__, lvl, msg, a1, a2, a3)
457 #define FPmsg4(lvl, msg, a1, a2, a3, a4) \
458 p_msg_fb(__FILE__, __LINE__, lvl, msg, a1, a2, a3, a4)
459 #define FPmsg5(lvl, msg, a1, a2, a3, a4, a5) \
460 p_msg_fb(__FILE__, __LINE__, lvl, msg, a1, a2, a3, a4, a5)
461 #define FPmsg6(lvl, msg, a1, a2, a3, a4, a5, a6) \
462 p_msg_fb(__FILE__, __LINE__, lvl, msg, a1, a2, a3, a4, a5, a6)
463 
464 /** Daemon Error Messages that are delivered according to the message resource */
465 #define Emsg0(typ, lvl, msg) \
466 e_msg(__FILE__, __LINE__, typ, lvl, msg)
467 #define Emsg1(typ, lvl, msg, a1) \
468 e_msg(__FILE__, __LINE__, typ, lvl, msg, a1)
469 #define Emsg2(typ, lvl, msg, a1, a2) \
470 e_msg(__FILE__, __LINE__, typ, lvl, msg, a1, a2)
471 #define Emsg3(typ, lvl, msg, a1, a2, a3) \
472 e_msg(__FILE__, __LINE__, typ, lvl, msg, a1, a2, a3)
473 #define Emsg4(typ, lvl, msg, a1, a2, a3, a4) \
474 e_msg(__FILE__, __LINE__, typ, lvl, msg, a1, a2, a3, a4)
475 #define Emsg5(typ, lvl, msg, a1, a2, a3, a4, a5) \
476 e_msg(__FILE__, __LINE__, typ, lvl, msg, a1, a2, a3, a4, a5)
477 #define Emsg6(typ, lvl, msg, a1, a2, a3, a4, a5, a6) \
478 e_msg(__FILE__, __LINE__, typ, lvl, msg, a1, a2, a3, a4, a5, a6)
479 
480 /** Job Error Messages that are delivered according to the message resource */
481 #define Jmsg0(jcr, typ, lvl, msg) \
482 j_msg(__FILE__, __LINE__, jcr, typ, lvl, msg)
483 #define Jmsg1(jcr, typ, lvl, msg, a1) \
484 j_msg(__FILE__, __LINE__, jcr, typ, lvl, msg, a1)
485 #define Jmsg2(jcr, typ, lvl, msg, a1, a2) \
486 j_msg(__FILE__, __LINE__, jcr, typ, lvl, msg, a1, a2)
487 #define Jmsg3(jcr, typ, lvl, msg, a1, a2, a3) \
488 j_msg(__FILE__, __LINE__, jcr, typ, lvl, msg, a1, a2, a3)
489 #define Jmsg4(jcr, typ, lvl, msg, a1, a2, a3, a4) \
490 j_msg(__FILE__, __LINE__, jcr, typ, lvl, msg, a1, a2, a3, a4)
491 #define Jmsg5(jcr, typ, lvl, msg, a1, a2, a3, a4, a5) \
492 j_msg(__FILE__, __LINE__, jcr, typ, lvl, msg, a1, a2, a3, a4, a5)
493 #define Jmsg6(jcr, typ, lvl, msg, a1, a2, a3, a4, a5, a6) \
494 j_msg(__FILE__, __LINE__, jcr, typ, lvl, msg, a1, a2, a3, a4, a5, a6)
495 #define Jmsg7(jcr, typ, lvl, msg, a1, a2, a3, a4, a5, a6, a7) \
496 j_msg(__FILE__, __LINE__, jcr, typ, lvl, msg, a1, a2, a3, a4, a5, a6, a7)
497 #define Jmsg8(jcr, typ, lvl, msg, a1, a2, a3, a4, a5, a6, a7, a8) \
498 j_msg(__FILE__, __LINE__, jcr, typ, lvl, msg, a1, a2, a3, a4, a5, a6, a7, a8)
499 
500 /** Queued Job Error Messages that are delivered according to the message resource */
501 #define Qmsg0(jcr, typ, lvl, msg) \
502 q_msg(__FILE__, __LINE__, jcr, typ, lvl, msg)
503 #define Qmsg1(jcr, typ, lvl, msg, a1) \
504 q_msg(__FILE__, __LINE__, jcr, typ, lvl, msg, a1)
505 #define Qmsg2(jcr, typ, lvl, msg, a1, a2) \
506 q_msg(__FILE__, __LINE__, jcr, typ, lvl, msg, a1, a2)
507 #define Qmsg3(jcr, typ, lvl, msg, a1, a2, a3) \
508 q_msg(__FILE__, __LINE__, jcr, typ, lvl, msg, a1, a2, a3)
509 #define Qmsg4(jcr, typ, lvl, msg, a1, a2, a3, a4) \
510 q_msg(__FILE__, __LINE__, jcr, typ, lvl, msg, a1, a2, a3, a4)
511 #define Qmsg5(jcr, typ, lvl, msg, a1, a2, a3, a4, a5) \
512 q_msg(__FILE__, __LINE__, jcr, typ, lvl, msg, a1, a2, a3, a4, a5)
513 #define Qmsg6(jcr, typ, lvl, msg, a1, a2, a3, a4, a5, a6) \
514 q_msg(__FILE__, __LINE__, jcr, typ, lvl, msg, a1, a2, a3, a4, a5, a6)
515 
516 /** Memory Messages that are edited into a Pool Memory buffer */
517 #define Mmsg0(buf, msg) \
518 msg_(__FILE__, __LINE__, buf, msg)
519 #define Mmsg1(buf, msg, a1) \
520 msg_(__FILE__, __LINE__, buf, msg, a1)
521 #define Mmsg2(buf, msg, a1, a2) \
522 msg_(__FILE__, __LINE__, buf, msg, a1, a2)
523 #define Mmsg3(buf, msg, a1, a2, a3) \
524 msg_(__FILE__, __LINE__, buf, msg, a1, a2, a3)
525 #define Mmsg4(buf, msg, a1, a2, a3, a4) \
526 msg_(__FILE__, __LINE__, buf, msg, a1, a2, a3, a4)
527 #define Mmsg5(buf, msg, a1, a2, a3, a4, a5) \
528 msg_(__FILE__, __LINE__, buf, msg, a1, a2, a3, a4, a5)
529 #define Mmsg6(buf, msg, a1, a2, a3, a4, a5, a6) \
530 msg_(__FILE__, __LINE__, buf, msg, a1, a2, a3, a4, a5, a6)
531 #define Mmsg7(buf, msg, a1, a2, a3, a4, a5, a6, a7) \
532 msg_(__FILE__, __LINE__, buf, msg, a1, a2, a3, a4, a5, a6)
533 #define Mmsg8(buf, msg, a1, a2, a3, a4, a5, a6, a7, a8) \
534 msg_(__FILE__, __LINE__, buf, msg, a1, a2, a3, a4, a5, a6)
535 #define Mmsg11(buf, msg, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11) \
536 msg_(__FILE__, __LINE__, buf, msg, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11)
537 #define Mmsg15(buf, msg, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15) \
538 msg_(__FILE__, __LINE__, buf, msg, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15)
539 
540 class PoolMem;
541 
542 /* Edit message into Pool Memory buffer -- no __FILE__ and __LINE__ */
543 int Mmsg(POOLMEM *&msgbuf, const char *fmt, ...);
544 int Mmsg(PoolMem &msgbuf, const char *fmt, ...);
545 int Mmsg(PoolMem *&msgbuf, const char *fmt, ...);
546 
547 class JobControlRecord;
548 void d_msg(const char *file, int line, int level, const char *fmt, ...);
549 void p_msg(const char *file, int line, int level, const char *fmt, ...);
550 void p_msg_fb(const char *file, int line, int level, const char *fmt,...);
551 void e_msg(const char *file, int line, int type, int level, const char *fmt, ...);
552 void j_msg(const char *file, int line, JobControlRecord *jcr, int type, utime_t mtime, const char *fmt, ...);
553 void q_msg(const char *file, int line, JobControlRecord *jcr, int type, utime_t mtime, const char *fmt, ...);
554 int msg_(const char *file, int line, POOLMEM *&pool_buf, const char *fmt, ...);
555 
556 #include "lib/bsys.h"
557 #include "lib/scan.h"
558 
559 /** Use our strdup with smartalloc */
560 #undef strdup
561 #define strdup(buf) BadCallOnStrdupUseBstrdup(buf)
562 
563 /** Use our fgets which handles interrupts */
564 #undef fgets
565 #define fgets(x, y, z) bfgets((x), (y), (z))
566 
567 /** Use our sscanf, which is safer and works with known sizes */
568 #define sscanf bsscanf
569 
570 #ifdef DEBUG
571 #define bstrdup(str) strcpy((char *)b_malloc(__FILE__,__LINE__, strlen((str))+1), (str))
572 #else
573 #define bstrdup(str) strcpy((char *)bmalloc(strlen((str))+1),(str))
574 #endif
575 
576 #define actuallystrdup(str) strcpy((char *)actuallymalloc(strlen((str))+1), (str))
577 
578 #ifdef DEBUG
579 #define bmalloc(size) b_malloc(__FILE__, __LINE__, (size))
580 #endif
581 
582 /** Macro to simplify free/reset pointers */
583 #define BfreeAndNull(a) do{if(a){free(a); (a)=NULL;}} while(0)
584 
585 /**
586 * Replace codes needed in both file routines and non-file routines
587 * Job replace codes -- in "replace"
588 */
589 #define REPLACE_ALWAYS   'a'
590 #define REPLACE_IFNEWER  'w'
591 #define REPLACE_NEVER    'n'
592 #define REPLACE_IFOLDER  'o'
593 
594 /** This probably should be done on a machine by machine basis, but it works */
595 /** This is critical for the smartalloc routines to properly align memory */
596 #define ALIGN_SIZE (sizeof(double))
597 #define BALIGN(x) (((x) + ALIGN_SIZE - 1) & ~(ALIGN_SIZE -1))
598 
599 
600 /* =============================================================
601 *               OS Dependent defines
602 * =============================================================
603 */
604 #ifndef HAVE_WIN32
605 #if defined (__digital__) && defined (__unix__)
606 /* Tru64 - it does have fseeko and ftello , but since ftell/fseek are also 64 bit */
607 /* take this 'shortcut' */
608 #define fseeko fseek
609 #define ftello ftell
610 #else
611 #ifndef HAVE_FSEEKO
612 /* Bad news. This OS cannot handle 64 bit fseeks and ftells */
613 #define fseeko fseek
614 #define ftello ftell
615 #endif
616 #endif /* __digital__ && __unix__ */
617 #endif /* HAVE_WIN32 */
618 
619 #ifdef HAVE_SUN_OS
620 /**
621 * On Solaris 2.5/2.6/7 and 8, threads are not timesliced by default,
622 * so we need to explictly increase the concurrency level.
623 */
624 #ifdef USE_THR_SETCONCURRENCY
625 #include <thread.h>
626 #define SetThreadConcurrency(x)  ThrSetconcurrency(x)
627 extern int ThrSetconcurrency(int);
628 #define SunOS 1
629 #else
630 #define SetThreadConcurrency(x)
631 #endif
632 
633 #else
634 /**
635  * Not needed on most systems
636  */
637 #define SetThreadConcurrency(x)
638 
639 #endif
640 
641 #ifdef HAVE_DARWIN_OS
642 /* Apparently someone forgot to wrap Getdomainname as a C function */
643 #ifdef  __cplusplus
644 extern "C" {
645 #endif /* __cplusplus */
646 int Getdomainname(char *name, int len);
647 #ifdef  __cplusplus
648 }
649 #endif /* __cplusplus */
650 #endif /* HAVE_DARWIN_OS */
651 
652 #define TRACEFILEDIRECTORY working_directory ? working_directory : "c:"
653 
654 #if defined(HAVE_WIN32)
655 /**
656  *   Windows
657  */
658 #define DEFAULT_CONFIGDIR "C:\\Documents and Settings\\All Users\\Application Data\\Bareos"
659 #define PathSeparator '\\'
660 
IsPathSeparator(int ch)661 inline bool IsPathSeparator(int ch) { return ch == '/' || ch == '\\'; }
first_path_separator(char * path)662 inline char *first_path_separator(char *path) { return strpbrk(path, "/\\"); }
first_path_separator(const char * path)663 inline const char *first_path_separator(const char *path) { return strpbrk(path, "/\\"); }
664 
665 extern void PauseMsg(const char *file, const char *func, int line, const char *msg);
666 #define pause(msg) if (debug_level) PauseMsg(__FILE__, __func__, __LINE__, (msg))
667 
668 #else
669 /**
670  *   Unix/Linux
671  */
672 #define PathSeparator '/'
673 
674 /* Define Winsock functions if we aren't on Windows */
WSA_Init()675 inline int WSA_Init() { return (0); } /* 0 = success */
WSACleanup()676 inline int WSACleanup() { return (0); } /* 0 = success */
677 
IsPathSeparator(int ch)678 inline bool IsPathSeparator(int ch) { return ch == '/'; }
first_path_separator(char * path)679 inline char *first_path_separator(char *path) { return strchr(path, '/'); }
first_path_separator(const char * path)680 inline const char *first_path_separator(const char *path) { return strchr(path, '/'); }
681 #define pause(msg)
682 #endif
683 
684 
685 /** HP-UX 11 specific workarounds */
686 
687 #ifdef HAVE_HPUX_OS
688 # undef h_errno
689 extern int h_errno;
690 /** the {get,set}domainname() functions exist in HPUX's libc.
691  * the configure script detects that correctly.
692  * the problem is no system headers declares the prototypes for these functions
693  * this is done below
694  */
695 #ifdef  __cplusplus
696 extern "C" {
697 #endif /* __cplusplus */
698 int Getdomainname(char *name, int namelen);
699 int Setdomainname(char *name, int namelen);
700 #ifdef  __cplusplus
701 }
702 #endif /* __cplusplus */
703 #endif /* HAVE_HPUX_OS */
704 
705 
706 #ifdef HAVE_OSF1_OS
707 #ifdef  __cplusplus
708 extern "C" {
709 #endif /* __cplusplus */
710 int fchdir(int filedes);
711 long gethostid(void);
712 int Getdomainname(char *name, int len);
713 #ifdef  __cplusplus
714 }
715 #endif /* __cplusplus */
716 #endif /* HAVE_OSF1_OS */
717 
718 
719 /** Disabled because it breaks internationalisation...
720 #undef HAVE_SETLOCALE
721 #ifdef HAVE_SETLOCALE
722 #include <locale.h>
723 #else
724 #define setlocale(x, y) ("ANSI_X3.4-1968")
725 #endif
726 #ifdef HAVE_NL_LANGINFO
727 #include <langinfo.h>
728 #else
729 #define nl_langinfo(x) ("ANSI_X3.4-1968")
730 #endif
731 */
732 
733 /** Determine endianes */
bigendian()734 static inline bool bigendian() { return htonl(1) == 1L; }
735 
736 #ifndef __GNUC__
737 #define __PRETTY_FUNCTION__ __func__
738 #endif
739 #ifdef ENTER_LEAVE
740 #define Enter(lvl) Dmsg1(lvl, "Enter: %s\n", __PRETTY_FUNCTION__)
741 #define Leave(lvl) Dmsg1(lvl, "Leave: %s\n", __PRETTY_FUNCTION__)
742 #else
743 #define Enter(lvl)
744 #define Leave(lvl)
745 #endif
746 
747 #endif /* BAREOS_INCLUDE_BACONFIG_H_ */
748