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-2020 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 #include "lib/message.h"
35 
36 /* Bareos common configuration defines */
37 
38 #undef TRUE
39 #undef FALSE
40 #define TRUE 1
41 #define FALSE 0
42 
43 #ifdef HAVE_TLS
44 #  define have_tls 1
45 #else
46 #  define have_tls 0
47 #endif
48 
49 #ifndef ETIME
50 #  define ETIME ETIMEDOUT
51 #endif
52 
53 #ifdef HAVE_IOCTL_ULINT_REQUEST
54 #  define ioctl_req_t unsigned long int
55 #else
56 #  define ioctl_req_t int
57 #endif
58 
59 /**
60  * In DEBUG mode an assert that is triggered generates a segmentation
61  * fault so we can capture the debug info using btraceback.
62  */
63 #define ASSERT(x)                                    \
64   if (!(x)) {                                        \
65     Emsg1(M_ERROR, 0, _("Failed ASSERT: %s\n"), #x); \
66     Pmsg1(000, _("Failed ASSERT: %s\n"), #x);        \
67     abort();                                         \
68   }
69 
70 /**
71  * Allow printing of NULL pointers
72  */
73 #define NPRT(x) (x) ? (x) : _("*None*")
74 #define NSTDPRNT(x) x.empty() ? "*None*" : x.c_str()
75 #define NPRTB(x) (x) ? (x) : ""
76 
77 #if defined(HAVE_WIN32)
78 /**
79  * Reduce compiler warnings from Windows vss code
80  */
81 #  define uuid(x)
82 
83 void InitWinAPIWrapper();
84 
85 #  define OSDependentInit() InitWinAPIWrapper()
86 
87 #  define ClearThreadId(x) memset(&(x), 0, sizeof(x))
88 
89 #else /* HAVE_WIN32 */
90 
91 #  define ClearThreadId(x) x = 0
92 #  define OSDependentInit()
93 
94 #endif /* HAVE_WIN32 */
95 
96 #ifdef ENABLE_NLS
97 #  include <libintl.h>
98 #  include <locale.h>
99 #  ifndef _
100 #    define _(s) gettext((s))
101 #  endif /* _ */
102 #  ifndef N_
103 #    define N_(s) (s)
104 #  endif /* N_ */
105 #else    /* !ENABLE_NLS */
106 #  include <locale.h>
107 #  undef _
108 #  undef N_
109 #  undef textdomain
110 #  undef bindtextdomain
111 
112 #  ifndef _
113 #    define _(s) (s)
114 #  endif
115 #  ifndef N_
116 #    define N_(s) (s)
117 #  endif
118 #  ifndef textdomain
119 #    define textdomain(d)
120 #  endif
121 #  ifndef bindtextdomain
122 #    define bindtextdomain(p, d)
123 #  endif
124 #endif /* ENABLE_NLS */
125 
126 
127 /* Use the following for strings not to be translated */
128 #define NT_(s) (s)
129 
130 /* Maximum length to edit time/date */
131 #define MAX_TIME_LENGTH 50
132 
133 /* Maximum Name length including EOS */
134 #define MAX_NAME_LENGTH 128
135 
136 /* Maximum escaped Name length including EOS 2*MAX_NAME_LENGTH+1 */
137 #define MAX_ESCAPE_NAME_LENGTH 257
138 
139 /* Maximum number of user entered command args */
140 #define MAX_CMD_ARGS 30
141 
142 /* All tape operations MUST be a multiple of this */
143 #define TAPE_BSIZE 1024
144 
145 /* Maximum length of a hostname */
146 #ifndef MAXHOSTNAMELEN
147 #  define MAXHOSTNAMELEN 256
148 #endif
149 
150 /* Default length of passphrases used */
151 #define DEFAULT_PASSPHRASE_LENGTH 32
152 
153 #ifdef DEV_BSIZE
154 #  define B_DEV_BSIZE DEV_BSIZE
155 #endif
156 
157 #if !defined(B_DEV_BSIZE) & defined(BSIZE)
158 #  define B_DEV_BSIZE BSIZE
159 #endif
160 
161 #ifndef B_DEV_BSIZE
162 #  define B_DEV_BSIZE 512
163 #endif
164 
165 /**
166  * Set to time limit for other end to respond to
167  *  authentication.  Normally 10 minutes is *way*
168  *  more than enough. The idea is to keep the Director
169  *  from hanging because there is a dead connection on
170  *  the other end.
171  */
172 #define AUTH_TIMEOUT 60 * 10
173 
174 /**
175  * Default network buffer size
176  */
177 #define DEFAULT_NETWORK_BUFFER_SIZE (64 * 1024)
178 
179 /**
180  * Tape label types -- stored in catalog
181  */
182 #define B_BAREOS_LABEL 0
183 #define B_ANSI_LABEL 1
184 #define B_IBM_LABEL 2
185 
186 /**
187  * Actions on purge (bit mask)
188  */
189 #define ON_PURGE_NONE 0
190 #define ON_PURGE_TRUNCATE 1
191 
192 /* Size of File Address stored in STREAM_SPARSE_DATA. Do NOT change! */
193 #define OFFSET_FADDR_SIZE (sizeof(uint64_t))
194 
195 /* Size of crypto length stored at head of crypto buffer. Do NOT change! */
196 #define CRYPTO_LEN_SIZE ((int)sizeof(uint32_t))
197 
198 
199 /**
200  * This is for dumb compilers/libraries like Solaris. Linux GCC
201  * does it correctly, so it might be worthwhile
202  * to remove the isascii(c) with ifdefs on such
203  * "smart" systems.
204  */
205 #define B_ISSPACE(c) (isascii((int)(c)) && isspace((int)(c)))
206 #define B_ISALPHA(c) (isascii((int)(c)) && isalpha((int)(c)))
207 #define B_ISUPPER(c) (isascii((int)(c)) && isupper((int)(c)))
208 #define B_ISDIGIT(c) (isascii((int)(c)) && isdigit((int)(c)))
209 
210 /** For multiplying by 10 with shift and addition */
211 #define B_TIMES10(d) ((d << 3) + (d << 1))
212 
213 
214 typedef void(HANDLER)();
215 typedef int(INTHANDLER)();
216 
217 #ifndef S_ISLNK
218 #  define S_ISLNK(m) (((m)&S_IFM) == S_IFLNK)
219 #endif
220 
221 /** Added by KES to deal with Win32 systems */
222 #ifndef S_ISWIN32
223 #  define S_ISWIN32 020000
224 #endif
225 
226 #ifndef INADDR_NONE
227 #  define INADDR_NONE ((unsigned long)-1)
228 #endif
229 
230 #ifdef TIME_WITH_SYS_TIME
231 #  include <sys/time.h>
232 #  include <time.h>
233 #else
234 #  ifdef HAVE_SYS_TIME_H
235 #    include <sys/time.h>
236 #  else
237 #    include <time.h>
238 #  endif
239 #endif
240 
241 #ifndef O_BINARY
242 #  define O_BINARY 0
243 #endif
244 
245 #ifndef O_NOFOLLOW
246 #  define O_NOFOLLOW 0
247 #endif
248 
249 #ifndef MODE_RW
250 #  define MODE_RW 0666
251 #endif
252 
253 #if defined(HAVE_WIN32)
254 typedef int64_t boffset_t;
255 #  define caddr_t char*
256 #else
257 typedef off_t boffset_t;
258 #endif
259 
260 typedef uint16_t slot_number_t;
261 typedef uint16_t drive_number_t;
262 typedef uint16_t slot_flags_t;
263 
264 #include <limits>
265 
266 constexpr slot_number_t kInvalidSlotNumber
267     = std::numeric_limits<slot_number_t>::max();
268 constexpr slot_number_t kInvalidDriveNumber
269     = std::numeric_limits<drive_number_t>::max();
270 
IsSlotNumberValid(slot_number_t slot)271 inline bool IsSlotNumberValid(slot_number_t slot)
272 {
273   return slot && slot != kInvalidSlotNumber;
274 }
275 
276 /* These probably should be subroutines */
277 #define Pw(x)                                                        \
278   do {                                                               \
279     int errstat;                                                     \
280     if ((errstat = RwlWritelock(&(x))))                              \
281       e_msg(__FILE__, __LINE__, M_ABORT, 0,                          \
282             "Write lock lock failure. ERR=%s\n", strerror(errstat)); \
283   } while (0)
284 
285 #define Vw(x)                                                          \
286   do {                                                                 \
287     int errstat;                                                       \
288     if ((errstat = RwlWriteunlock(&(x))))                              \
289       e_msg(__FILE__, __LINE__, M_ABORT, 0,                            \
290             "Write lock unlock failure. ERR=%s\n", strerror(errstat)); \
291   } while (0)
292 
293 
294 /**
295  * In modern versions of C/C++ we can use attributes to express intentions
296  * as not all compilers are modern enough for the attribute we want to use
297  * we add macros for the attributes that will be automatically disabled on
298  * older compilers that don't understand the attribute yet
299  */
300 #if !defined(FALLTHROUGH_INTENDED)
301 #  if defined(__clang__)
302 #    define FALLTHROUGH_INTENDED [[clang::fallthrough]]
303 #  elif defined(__GNUC__) && __GNUC__ >= 7
304 #    define FALLTHROUGH_INTENDED [[gnu::fallthrough]]
305 #  else
306 #    define FALLTHROUGH_INTENDED \
307       do {                       \
308       } while (0)
309 #  endif
310 #endif
311 
312 /**
313  * As of C++11 varargs macros are part of the standard.
314  * We keep the kludgy versions for backwards compatability for now
315  * but they're going to go away soon.
316  */
317 /** Debug Messages that are printed */
318 #define Dmsg0(lvl, ...) \
319   if ((lvl) <= debug_level) d_msg(__FILE__, __LINE__, lvl, __VA_ARGS__)
320 #define Dmsg1(lvl, ...) \
321   if ((lvl) <= debug_level) d_msg(__FILE__, __LINE__, lvl, __VA_ARGS__)
322 #define Dmsg2(lvl, ...) \
323   if ((lvl) <= debug_level) d_msg(__FILE__, __LINE__, lvl, __VA_ARGS__)
324 #define Dmsg3(lvl, ...) \
325   if ((lvl) <= debug_level) d_msg(__FILE__, __LINE__, lvl, __VA_ARGS__)
326 #define Dmsg4(lvl, ...) \
327   if ((lvl) <= debug_level) d_msg(__FILE__, __LINE__, lvl, __VA_ARGS__)
328 #define Dmsg5(lvl, ...) \
329   if ((lvl) <= debug_level) d_msg(__FILE__, __LINE__, lvl, __VA_ARGS__)
330 #define Dmsg6(lvl, ...) \
331   if ((lvl) <= debug_level) d_msg(__FILE__, __LINE__, lvl, __VA_ARGS__)
332 #define Dmsg7(lvl, ...) \
333   if ((lvl) <= debug_level) d_msg(__FILE__, __LINE__, lvl, __VA_ARGS__)
334 #define Dmsg8(lvl, ...) \
335   if ((lvl) <= debug_level) d_msg(__FILE__, __LINE__, lvl, __VA_ARGS__)
336 #define Dmsg9(lvl, ...) \
337   if ((lvl) <= debug_level) d_msg(__FILE__, __LINE__, lvl, __VA_ARGS__)
338 #define Dmsg10(lvl, ...) \
339   if ((lvl) <= debug_level) d_msg(__FILE__, __LINE__, lvl, __VA_ARGS__)
340 #define Dmsg11(lvl, ...) \
341   if ((lvl) <= debug_level) d_msg(__FILE__, __LINE__, lvl, __VA_ARGS__)
342 #define Dmsg12(lvl, ...) \
343   if ((lvl) <= debug_level) d_msg(__FILE__, __LINE__, lvl, __VA_ARGS__)
344 #define Dmsg13(lvl, ...) \
345   if ((lvl) <= debug_level) d_msg(__FILE__, __LINE__, lvl, __VA_ARGS__)
346 
347 /** Messages that are printed (uses p_msg) */
348 #define Pmsg0(lvl, ...) p_msg(__FILE__, __LINE__, lvl, __VA_ARGS__)
349 #define Pmsg1(lvl, ...) p_msg(__FILE__, __LINE__, lvl, __VA_ARGS__)
350 #define Pmsg2(lvl, ...) p_msg(__FILE__, __LINE__, lvl, __VA_ARGS__)
351 #define Pmsg3(lvl, ...) p_msg(__FILE__, __LINE__, lvl, __VA_ARGS__)
352 #define Pmsg4(lvl, ...) p_msg(__FILE__, __LINE__, lvl, __VA_ARGS__)
353 #define Pmsg5(lvl, ...) p_msg(__FILE__, __LINE__, lvl, __VA_ARGS__)
354 #define Pmsg6(lvl, ...) p_msg(__FILE__, __LINE__, lvl, __VA_ARGS__)
355 #define Pmsg7(lvl, ...) p_msg(__FILE__, __LINE__, lvl, __VA_ARGS__)
356 #define Pmsg8(lvl, ...) p_msg(__FILE__, __LINE__, lvl, __VA_ARGS__)
357 #define Pmsg9(lvl, ...) p_msg(__FILE__, __LINE__, lvl, __VA_ARGS__)
358 #define Pmsg10(lvl, ...) p_msg(__FILE__, __LINE__, lvl, __VA_ARGS__)
359 #define Pmsg11(lvl, ...) p_msg(__FILE__, __LINE__, lvl, __VA_ARGS__)
360 #define Pmsg12(lvl, ...) p_msg(__FILE__, __LINE__, lvl, __VA_ARGS__)
361 #define Pmsg13(lvl, ...) p_msg(__FILE__, __LINE__, lvl, __VA_ARGS__)
362 #define Pmsg14(lvl, ...) p_msg(__FILE__, __LINE__, lvl, __VA_ARGS__)
363 #define Pmsg15(lvl, ...) p_msg(__FILE__, __LINE__, lvl, __VA_ARGS__)
364 
365 /** Messages that are printed using fixed size buffers (uses p_msg_fb) */
366 #define FPmsg0(lvl, ...) p_msg_fb(__FILE__, __LINE__, lvl, __VA_ARGS__)
367 #define FPmsg1(lvl, ...) p_msg_fb(__FILE__, __LINE__, lvl, __VA_ARGS__)
368 #define FPmsg2(lvl, ...) p_msg_fb(__FILE__, __LINE__, lvl, __VA_ARGS__)
369 #define FPmsg3(lvl, ...) p_msg_fb(__FILE__, __LINE__, lvl, __VA_ARGS__)
370 #define FPmsg4(lvl, ...) p_msg_fb(__FILE__, __LINE__, lvl, __VA_ARGS__)
371 #define FPmsg5(lvl, ...) p_msg_fb(__FILE__, __LINE__, lvl, __VA_ARGS__)
372 #define FPmsg6(lvl, ...) p_msg_fb(__FILE__, __LINE__, lvl, __VA_ARGS__)
373 
374 /** Daemon Error Messages that are delivered according to the message resource
375  */
376 #define Emsg0(typ, lvl, ...) e_msg(__FILE__, __LINE__, typ, lvl, __VA_ARGS__)
377 #define Emsg1(typ, lvl, ...) e_msg(__FILE__, __LINE__, typ, lvl, __VA_ARGS__)
378 #define Emsg2(typ, lvl, ...) e_msg(__FILE__, __LINE__, typ, lvl, __VA_ARGS__)
379 #define Emsg3(typ, lvl, ...) e_msg(__FILE__, __LINE__, typ, lvl, __VA_ARGS__)
380 #define Emsg4(typ, lvl, ...) e_msg(__FILE__, __LINE__, typ, lvl, __VA_ARGS__)
381 #define Emsg5(typ, lvl, ...) e_msg(__FILE__, __LINE__, typ, lvl, __VA_ARGS__)
382 #define Emsg6(typ, lvl, ...) e_msg(__FILE__, __LINE__, typ, lvl, __VA_ARGS__)
383 
384 /** Job Error Messages that are delivered according to the message resource */
385 #define Jmsg0(jcr, typ, lvl, ...) \
386   j_msg(__FILE__, __LINE__, jcr, typ, lvl, __VA_ARGS__)
387 #define Jmsg1(jcr, typ, lvl, ...) \
388   j_msg(__FILE__, __LINE__, jcr, typ, lvl, __VA_ARGS__)
389 #define Jmsg2(jcr, typ, lvl, ...) \
390   j_msg(__FILE__, __LINE__, jcr, typ, lvl, __VA_ARGS__)
391 #define Jmsg3(jcr, typ, lvl, ...) \
392   j_msg(__FILE__, __LINE__, jcr, typ, lvl, __VA_ARGS__)
393 #define Jmsg4(jcr, typ, lvl, ...) \
394   j_msg(__FILE__, __LINE__, jcr, typ, lvl, __VA_ARGS__)
395 #define Jmsg5(jcr, typ, lvl, ...) \
396   j_msg(__FILE__, __LINE__, jcr, typ, lvl, __VA_ARGS__)
397 #define Jmsg6(jcr, typ, lvl, ...) \
398   j_msg(__FILE__, __LINE__, jcr, typ, lvl, __VA_ARGS__)
399 #define Jmsg7(jcr, typ, lvl, ...) \
400   j_msg(__FILE__, __LINE__, jcr, typ, lvl, __VA_ARGS__)
401 #define Jmsg8(jcr, typ, lvl, ...) \
402   j_msg(__FILE__, __LINE__, jcr, typ, lvl, __VA_ARGS__)
403 
404 /** Queued Job Error Messages that are delivered according to the message
405  * resource */
406 #define Qmsg0(jcr, typ, lvl, ...) \
407   q_msg(__FILE__, __LINE__, jcr, typ, lvl, __VA_ARGS__)
408 #define Qmsg1(jcr, typ, lvl, ...) \
409   q_msg(__FILE__, __LINE__, jcr, typ, lvl, __VA_ARGS__)
410 #define Qmsg2(jcr, typ, lvl, ...) \
411   q_msg(__FILE__, __LINE__, jcr, typ, lvl, __VA_ARGS__)
412 #define Qmsg3(jcr, typ, lvl, ...) \
413   q_msg(__FILE__, __LINE__, jcr, typ, lvl, __VA_ARGS__)
414 #define Qmsg4(jcr, typ, lvl, ...) \
415   q_msg(__FILE__, __LINE__, jcr, typ, lvl, __VA_ARGS__)
416 #define Qmsg5(jcr, typ, lvl, ...) \
417   q_msg(__FILE__, __LINE__, jcr, typ, lvl, __VA_ARGS__)
418 #define Qmsg6(jcr, typ, lvl, ...) \
419   q_msg(__FILE__, __LINE__, jcr, typ, lvl, __VA_ARGS__)
420 
421 /** Memory Messages that are edited into a Pool Memory buffer */
422 #define Mmsg0(buf, ...) msg_(__FILE__, __LINE__, buf, __VA_ARGS__)
423 #define Mmsg1(buf, ...) msg_(__FILE__, __LINE__, buf, __VA_ARGS__)
424 #define Mmsg2(buf, ...) msg_(__FILE__, __LINE__, buf, __VA_ARGS__)
425 #define Mmsg3(buf, ...) msg_(__FILE__, __LINE__, buf, __VA_ARGS__)
426 #define Mmsg4(buf, ...) msg_(__FILE__, __LINE__, buf, __VA_ARGS__)
427 #define Mmsg5(buf, ...) msg_(__FILE__, __LINE__, buf, __VA_ARGS__)
428 #define Mmsg6(buf, ...) msg_(__FILE__, __LINE__, buf, __VA_ARGS__)
429 #define Mmsg7(buf, ...) msg_(__FILE__, __LINE__, buf, __VA_ARGS__)
430 #define Mmsg8(buf, ...) msg_(__FILE__, __LINE__, buf, __VA_ARGS__)
431 #define Mmsg9(buf, ...) msg_(__FILE__, __LINE__, buf, __VA_ARGS__)
432 #define Mmsg10(buf, ...) msg_(__FILE__, __LINE__, buf, __VA_ARGS__)
433 #define Mmsg11(buf, ...) msg_(__FILE__, __LINE__, buf, __VA_ARGS__)
434 #define Mmsg12(buf, ...) msg_(__FILE__, __LINE__, buf, __VA_ARGS__)
435 #define Mmsg13(buf, ...) msg_(__FILE__, __LINE__, buf, __VA_ARGS__)
436 #define Mmsg14(buf, ...) msg_(__FILE__, __LINE__, buf, __VA_ARGS__)
437 #define Mmsg15(buf, ...) msg_(__FILE__, __LINE__, buf, __VA_ARGS__)
438 
439 class PoolMem;
440 
441 /* Edit message into Pool Memory buffer -- no __FILE__ and __LINE__ */
442 int Mmsg(POOLMEM*& msgbuf, const char* fmt, ...);
443 int Mmsg(PoolMem& msgbuf, const char* fmt, ...);
444 int Mmsg(PoolMem*& msgbuf, const char* fmt, ...);
445 int Mmsg(std::vector<char>& msgbuf, const char* fmt, ...);
446 
447 class JobControlRecord;
448 void d_msg(const char* file, int line, int level, const char* fmt, ...);
449 void p_msg(const char* file, int line, int level, const char* fmt, ...);
450 void p_msg_fb(const char* file, int line, int level, const char* fmt, ...);
451 void e_msg(const char* file,
452            int line,
453            int type,
454            int level,
455            const char* fmt,
456            ...);
457 void j_msg(const char* file,
458            int line,
459            JobControlRecord* jcr,
460            int type,
461            utime_t mtime,
462            const char* fmt,
463            ...);
464 void q_msg(const char* file,
465            int line,
466            JobControlRecord* jcr,
467            int type,
468            utime_t mtime,
469            const char* fmt,
470            ...);
471 int msg_(const char* file, int line, POOLMEM*& pool_buf, const char* fmt, ...);
472 
473 #include "lib/bsys.h"
474 #include "lib/scan.h"
475 
476 /** Use our fgets which handles interrupts */
477 #undef fgets
478 #define fgets(x, y, z) bfgets((x), (y), (z))
479 
480 /** Use our sscanf, which is safer and works with known sizes */
481 #define sscanf bsscanf
482 
483 /** Macro to simplify free/reset pointers */
484 #define BfreeAndNull(a) \
485   do {                  \
486     if (a) {            \
487       free(a);          \
488       (a) = NULL;       \
489     }                   \
490   } while (0)
491 
492 /**
493  * Replace codes needed in both file routines and non-file routines
494  * Job replace codes -- in "replace"
495  */
496 #define REPLACE_ALWAYS 'a'
497 #define REPLACE_IFNEWER 'w'
498 #define REPLACE_NEVER 'n'
499 #define REPLACE_IFOLDER 'o'
500 
501 /** This probably should be done on a machine by machine basis, but it works */
502 /** This is critical for the memory allocation routines to properly align memory
503  */
504 #define ALIGN_SIZE (sizeof(double))
505 #define BALIGN(x) (((x) + ALIGN_SIZE - 1) & ~(ALIGN_SIZE - 1))
506 
507 
508 /* =============================================================
509  *               OS Dependent defines
510  * =============================================================
511  */
512 #ifndef HAVE_WIN32
513 #  if defined(__digital__) && defined(__unix__)
514 /* Tru64 - it does have fseeko and ftello , but since ftell/fseek are also 64
515  * bit */
516 /* take this 'shortcut' */
517 #    define fseeko fseek
518 #    define ftello ftell
519 #  else
520 #    ifndef HAVE_FSEEKO
521 /* Bad news. This OS cannot handle 64 bit fseeks and ftells */
522 #      define fseeko fseek
523 #      define ftello ftell
524 #    endif
525 #  endif /* __digital__ && __unix__ */
526 #endif   /* HAVE_WIN32 */
527 
528 #ifdef HAVE_DARWIN_OS
529 /* Apparently someone forgot to wrap Getdomainname as a C function */
530 #  ifdef __cplusplus
531 extern "C" {
532 #  endif /* __cplusplus */
533 int Getdomainname(char* name, int len);
534 #  ifdef __cplusplus
535 }
536 #  endif /* __cplusplus */
537 #endif   /* HAVE_DARWIN_OS */
538 
539 #define TRACEFILEDIRECTORY working_directory ? working_directory : "c:"
540 
541 #if defined(HAVE_WIN32)
542 /**
543  *   Windows
544  */
545 #  define DEFAULT_CONFIGDIR \
546     "C:\\Documents and Settings\\All Users\\Application Data\\Bareos"
547 #  define PathSeparator '\\'
548 
IsPathSeparator(int ch)549 inline bool IsPathSeparator(int ch) { return ch == '/' || ch == '\\'; }
first_path_separator(char * path)550 inline char* first_path_separator(char* path) { return strpbrk(path, "/\\"); }
first_path_separator(const char * path)551 inline const char* first_path_separator(const char* path)
552 {
553   return strpbrk(path, "/\\");
554 }
555 
556 extern void PauseMsg(const char* file,
557                      const char* func,
558                      int line,
559                      const char* msg);
560 #  define pause(msg) \
561     if (debug_level) PauseMsg(__FILE__, __func__, __LINE__, (msg))
562 
563 #else
564 /**
565  *   Unix/Linux
566  */
567 #  define PathSeparator '/'
568 
569 /* Define Winsock functions if we aren't on Windows */
WSA_Init()570 inline int WSA_Init() { return (0); }   /* 0 = success */
WSACleanup()571 inline int WSACleanup() { return (0); } /* 0 = success */
572 
IsPathSeparator(int ch)573 inline bool IsPathSeparator(int ch) { return ch == '/'; }
first_path_separator(char * path)574 inline char* first_path_separator(char* path) { return strchr(path, '/'); }
first_path_separator(const char * path)575 inline const char* first_path_separator(const char* path)
576 {
577   return strchr(path, '/');
578 }
579 #  define pause(msg)
580 #endif
581 
582 
583 /** HP-UX 11 specific workarounds */
584 
585 #ifdef HAVE_HPUX_OS
586 #  undef h_errno
587 extern int h_errno;
588 /** the {get,set}domainname() functions exist in HPUX's libc.
589  * the configure script detects that correctly.
590  * the problem is no system headers declares the prototypes for these functions
591  * this is done below
592  */
593 #  ifdef __cplusplus
594 extern "C" {
595 #  endif /* __cplusplus */
596 int Getdomainname(char* name, int namelen);
597 int Setdomainname(char* name, int namelen);
598 #  ifdef __cplusplus
599 }
600 #  endif /* __cplusplus */
601 #endif   /* HAVE_HPUX_OS */
602 
603 
604 #ifdef HAVE_OSF1_OS
605 #  ifdef __cplusplus
606 extern "C" {
607 #  endif /* __cplusplus */
608 int fchdir(int filedes);
609 long gethostid(void);
610 int Getdomainname(char* name, int len);
611 #  ifdef __cplusplus
612 }
613 #  endif /* __cplusplus */
614 #endif   /* HAVE_OSF1_OS */
615 
616 /** Determine endianes */
bigendian()617 static inline bool bigendian() { return htonl(1) == 1L; }
618 
619 #ifndef __GNUC__
620 #  define __PRETTY_FUNCTION__ __func__
621 #endif
622 #ifdef ENTER_LEAVE
623 #  define Enter(lvl) Dmsg1(lvl, "Enter: %s\n", __PRETTY_FUNCTION__)
624 #  define Leave(lvl) Dmsg1(lvl, "Leave: %s\n", __PRETTY_FUNCTION__)
625 #else
626 #  define Enter(lvl)
627 #  define Leave(lvl)
628 #endif
629 
630 #endif /* BAREOS_INCLUDE_BACONFIG_H_ */
631