1 /*
2 Bacula(R) - The Network Backup Solution
3
4 Copyright (C) 2000-2018 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 * Written by James Harper, July 2010
21 */
22
23 #ifndef _EXCHANGE_FD_H
24 #define _EXCHANGE_FD_H
25
26 #define BUILD_PLUGIN
27
28 #if defined(BUILDING_DLL)
29 # define DLL_IMP_EXP __declspec(dllexport)
30 #elif defined(USING_DLL)
31 # define DLL_IMP_EXP __declspec(dllimport)
32 #else
33 # define DLL_IMP_EXP
34 #endif
35
36 #if defined(HAVE_WIN32)
37 #if defined(HAVE_MINGW)
38 #include "winhdrs.h"
39 #else
40 #include "winconfig.h"
41 #endif
42 #else
43 #include "config.h"
44 #endif
45 #define __CONFIG_H
46
47 enum {
48 /* Keep M_ABORT=1 for dlist.h */
49 M_ABORT = 1, /* MUST abort immediately */
50 M_DEBUG, /* debug message */
51 M_FATAL, /* Fatal error, stopping job */
52 M_ERROR, /* Error, but recoverable */
53 M_WARNING, /* Warning message */
54 M_INFO, /* Informational message */
55 M_SAVED, /* Info on saved file */
56 M_NOTSAVED, /* Info on notsaved file */
57 M_SKIPPED, /* File skipped during backup by option setting */
58 M_MOUNT, /* Mount requests */
59 M_ERROR_TERM, /* Error termination request (no dump) */
60 M_TERM, /* Terminating daemon normally */
61 M_RESTORED, /* ls -l of restored files */
62 M_SECURITY, /* security violation */
63 M_ALERT, /* tape alert messages */
64 M_VOLMGMT /* Volume management messages */
65 };
66
67 #define FT_REG 3
68 #define FT_DIREND 5
69
70 #define _REENTRANT 1
71 #define _THREAD_SAFE 1
72 #define _POSIX_PTHREAD_SEMANTICS 1
73
74 #include <stdint.h>
75
76 #include <stdio.h>
77 #include <stdlib.h>
78 #include <time.h>
79 #include <sys/types.h>
80 #ifdef HAVE_SYS_BITYPES_H
81 #include <sys/bitypes.h>
82 #endif
83
84 //#include "bacula.h"
85 #include "compat.h"
86 #include "bc_types.h"
87
88 typedef int64_t boffset_t;
89 //#define bstrdup(str) strcpy((char *)bmalloc(strlen((str))+1),(str))
90 #define bstrdup(str) strdup(str)
91
92 #include "fd_plugins.h"
93 #include "exch_api.h"
94
95 #if defined(HAVE_WIN32)
96 #include "winapi.h"
97 #include "winhost.h"
98 #else
99 #include "host.h"
100 #endif
101
102 #define EXCHANGE_PLUGIN_VERSION 1
103
104 #define JOB_TYPE_BACKUP 1
105 #define JOB_TYPE_RESTORE 2
106
107 #define JOB_LEVEL_FULL ((int)'F')
108 #define JOB_LEVEL_INCREMENTAL ((int)'I')
109 #define JOB_LEVEL_DIFFERENTIAL ((int)'D')
110
111 struct exchange_fd_context_t;
112
113 #include "exch_node.h"
114
115 struct exchange_fd_context_t {
116 struct bpContext *bpContext;
117 WCHAR *computer_name;
118 char *path_bits[6];
119 root_node_t *root_node;
120 node_t *current_node;
121 int job_type;
122 int job_level;
123 time_t job_since;
124 bool notrunconfull_option;
125 bool truncate_logs;
126 bool accurate;
127 bool plugin_active;
128 };
129
tocharstring(WCHAR * src)130 static inline char *tocharstring(WCHAR *src)
131 {
132 char *tmp = new char[wcslen(src) + 1];
133 wcstombs(tmp, src, wcslen(src) + 1);
134 return tmp;
135 }
136
towcharstring(char * src)137 static inline WCHAR *towcharstring(char *src)
138 {
139 WCHAR *tmp = new WCHAR[strlen(src) + 1];
140 mbstowcs(tmp, src, strlen(src) + 1);
141 return tmp;
142 }
143
144 #define safe_delete(buf) if (buf) { delete buf; buf=NULL; }
145
146 extern bFuncs *bfuncs;
147 extern bInfo *binfo;
148
149 #define _DebugMessage(level, message, ...) bfuncs->DebugMessage(context->bpContext, __FILE__, __LINE__, level, message, ##__VA_ARGS__)
150 #define _JobMessage(type, message, ...) bfuncs->JobMessage(context->bpContext, __FILE__, __LINE__, type, 0, message, ##__VA_ARGS__)
151 #define _JobMessageNull(type, message, ...) bfuncs->JobMessage(NULL, __FILE__, __LINE__, type, 0, message, ##__VA_ARGS__)
152
153 #define PLUGIN_PATH_PREFIX_BASE "@EXCHANGE"
154 #define PLUGIN_PATH_PREFIX_SERVICE "Microsoft Information Store"
155 #define PLUGIN_PATH_PREFIX_SERVICE_W L"Microsoft Information Store"
156
157 #endif /* _EXCHANGE_FD_H */
158