]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/filed/fd_plugins.h
Restore win32 dir from Branch-5.2 and update it
[bacula/bacula] / bacula / src / filed / fd_plugins.h
1 /*
2    Bacula(R) - The Network Backup Solution
3
4    Copyright (C) 2000-2017 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  * Application Programming Interface (API) definition for Bacula Plugins
21  *
22  * Kern Sibbald, October 2007
23  */
24
25 #ifndef __FD_PLUGINS_H
26 #define __FD_PLUGINS_H
27
28 #ifndef _BACULA_H
29 #ifdef __cplusplus
30 /* Workaround for SGI IRIX 6.5 */
31 #define _LANGUAGE_C_PLUS_PLUS 1
32 #endif
33 #define _REENTRANT    1
34 #define _THREAD_SAFE  1
35 #define _POSIX_PTHREAD_SEMANTICS 1
36 #define _FILE_OFFSET_BITS 64
37 #define _LARGEFILE_SOURCE 1
38 #define _LARGE_FILES 1
39 #endif  /* ! _BACULA_H */
40
41 #include <sys/types.h>
42
43 #if defined(HAVE_WIN32)
44 #if defined(HAVE_MINGW)
45 #include "mingwconfig.h"
46 #else
47 #include "winconfig.h"
48 #endif
49 #else  /* !HAVE_WIN32 */
50 #ifndef __CONFIG_H
51 #include "config.h"
52 #define __CONFIG_H
53 #endif
54 #endif
55
56 #include "../src/version.h"
57 #include "bc_types.h"
58 #include "lib/plugins.h"
59 #include <sys/stat.h>
60 #ifdef HAVE_WIN32
61 #include "../win32/filed/vss.h"
62 #endif
63
64 /*
65  * This packet is used for the restore objects
66  *  It is passed to the plugin when restoring
67  *  the object.
68  */
69 struct restore_object_pkt {
70    int32_t pkt_size;                  /* size of this packet */
71    char *object_name;                 /* Object name */
72    char *object;                      /* restore object data to save */
73    char *plugin_name;                 /* Plugin name */
74    int32_t object_type;               /* FT_xx for this file */
75    int32_t object_len;                /* restore object length */
76    int32_t object_full_len;           /* restore object uncompressed length */
77    int32_t object_index;              /* restore object index */
78    int32_t object_compression;        /* set to compression type */
79    int32_t stream;                    /* attribute stream id */
80    uint32_t JobId;                    /* JobId object came from */
81    int32_t pkt_end;                   /* end packet sentinel */
82 };
83
84 /*
85  * This packet is used for file save info transfer.
86 */
87 struct save_pkt {
88    int32_t pkt_size;                  /* size of this packet */
89    char *fname;                       /* Full path and filename */
90    char *link;                        /* Link name if any */
91    struct stat statp;                 /* System stat() packet for file */
92    int32_t type;                      /* FT_xx for this file */
93    uint64_t flags;                     /* Bacula internal flags */
94    bool no_read;                      /* During the save, the file should not be saved */
95    bool portable;                     /* set if data format is portable */
96    bool accurate_found;               /* Found in accurate list (valid after check_changes()) */
97    char *cmd;                         /* command */
98    uint32_t delta_seq;                /* Delta sequence number */
99    char *object_name;                 /* Object name to create */
100    char *object;                      /* restore object data to save */
101    int32_t object_len;                /* restore object length */
102    int32_t index;                     /* restore object index */
103    int32_t pkt_end;                   /* end packet sentinel */
104 };
105
106 /*
107  * This packet is used for file restore info transfer.
108 */
109 struct restore_pkt {
110    int32_t pkt_size;                  /* size of this packet */
111    int32_t stream;                    /* attribute stream id */
112    int32_t data_stream;               /* id of data stream to follow */
113    int32_t type;                      /* file type FT */
114    int32_t file_index;                /* file index */
115    int32_t LinkFI;                    /* file index to data if hard link */
116    uid_t uid;                         /* userid */
117    struct stat statp;                 /* decoded stat packet */
118    const char *attrEx;                /* extended attributes if any */
119    const char *ofname;                /* output filename */
120    const char *olname;                /* output link name */
121    const char *where;                 /* where */
122    const char *RegexWhere;            /* regex where */
123    int replace;                       /* replace flag */
124    int create_status;                 /* status from createFile() */
125    uint32_t delta_seq;                /* Delta sequence number */
126    int32_t pkt_end;                   /* end packet sentinel */
127 };
128
129 enum {
130    IO_OPEN = 1,
131    IO_READ = 2,
132    IO_WRITE = 3,
133    IO_CLOSE = 4,
134    IO_SEEK = 5
135 };
136
137 struct io_pkt {
138    int32_t pkt_size;                  /* Size of this packet */
139    int32_t func;                      /* Function code */
140    int32_t count;                     /* read/write count */
141    int32_t flags;                     /* Open flags */
142    mode_t mode;                       /* permissions for created files */
143    char *buf;                         /* read/write buffer */
144    const char *fname;                 /* open filename */
145    int32_t status;                    /* return status */
146    int32_t io_errno;                  /* errno code */
147    int32_t lerror;                    /* Win32 error code */
148    int32_t whence;                    /* lseek argument */
149    boffset_t offset;                  /* lseek argument or in bread current offset*/
150    bool win32;                        /* Win32 GetLastError returned */
151    int32_t pkt_end;                   /* end packet sentinel */
152 };
153
154 enum {
155     BACL_BACKUP = 1,
156     BACL_RESTORE = 2,
157     BXATTR_BACKUP = 3,
158     BXATTR_RESTORE = 4
159 };
160
161 struct xacl_pkt {
162     int32_t pkt_size;                  /* Size of this packet */
163     int32_t func;                      /* Function code */
164     int32_t count;                     /* read/write count */
165     char *content;                     /* read/write buffer */
166     int32_t pkt_end;                   /* end packet sentinel */
167 };
168
169 /****************************************************************************
170  *                                                                          *
171  *                Bacula definitions                                        *
172  *                                                                          *
173  ****************************************************************************/
174
175 /* Bacula Variable Ids */
176 typedef enum {
177   bVarJobId                 = 1,
178   bVarFDName                = 2,
179   bVarLevel                 = 3,
180   bVarType                  = 4,
181   bVarClient                = 5,
182   bVarJobName               = 6,
183   bVarJobStatus             = 7,
184   bVarSinceTime             = 8,
185   bVarAccurate              = 9,
186   bVarFileSeen              = 10,
187   bVarVssObject             = 11,
188   bVarVssDllHandle          = 12,
189   bVarWorkingDir            = 13,
190   bVarWhere                 = 14,
191   bVarRegexWhere            = 15,
192   bVarExePath               = 16,
193   bVarVersion               = 17,
194   bVarDistName              = 18,
195   bVarxxx                   = 19,
196   bVarPrevJobName           = 20,
197   bVarPrefixLinks           = 21,
198   bVarInteractiveSession    = 22,
199   bVarFileIndex             = 23,
200   bVarReplace               = 24
201 } bVariable;
202
203 /* Events that are passed to plugin */
204 typedef enum {
205   bEventJobStart                        = 1,
206   bEventJobEnd                          = 2,
207   bEventStartBackupJob                  = 3,
208   bEventEndBackupJob                    = 4,
209   bEventStartRestoreJob                 = 5,
210   bEventEndRestoreJob                   = 6,
211   bEventStartVerifyJob                  = 7,
212   bEventEndVerifyJob                    = 8,
213   bEventBackupCommand                   = 9,
214   bEventRestoreCommand                  = 10,
215   bEventEstimateCommand                 = 11,
216   bEventLevel                           = 12,
217   bEventSince                           = 13,
218   bEventCancelCommand                   = 14, /* Executed by another thread */
219   bEventVssBackupAddComponents          = 15, /* Just before bEventVssPrepareSnapshot */
220   bEventVssRestoreLoadComponentMetadata = 16,
221   bEventVssRestoreSetComponentsSelected = 17,
222   bEventRestoreObject                   = 18,
223   bEventEndFileSet                      = 19,
224   bEventPluginCommand                   = 20, /* Sent during FileSet creation */
225   bEventVssBeforeCloseRestore           = 21,
226   /* Add drives to VSS snapshot
227    *  argument: char[27] drivelist
228    * You need to add them without duplicates,
229    * see fd_common.h add_drive() copy_drives() to get help
230    */
231   bEventVssPrepareSnapshot              = 22,
232   bEventOptionPlugin                    = 23,
233   bEventHandleBackupFile                = 24, /* Used with Options Plugin */
234   bEventComponentInfo                   = 25  /* Plugin component */
235 } bEventType;
236
237 typedef struct s_bEvent {
238    uint32_t eventType;
239 } bEvent;
240
241 typedef struct s_baculaInfo {
242    uint32_t size;
243    uint32_t version;
244 } bInfo;
245
246 /* Bacula Core Routines -- not used within a plugin */
247 #ifdef FILE_DAEMON
248 struct BFILE;                   /* forward referenced */
249 struct FF_PKT;
250 void load_fd_plugins(const char *plugin_dir);
251 void new_plugins(JCR *jcr);
252 void free_plugins(JCR *jcr);
253 void generate_plugin_event(JCR *jcr, bEventType event, void *value=NULL);
254 bool send_plugin_name(JCR *jcr, BSOCK *sd, bool start);
255 bool plugin_name_stream(JCR *jcr, char *name);
256 int plugin_create_file(JCR *jcr, ATTR *attr, BFILE *bfd, int replace);
257 bool plugin_set_attributes(JCR *jcr, ATTR *attr, BFILE *ofd);
258 int plugin_save(JCR *jcr, FF_PKT *ff_pkt, bool top_level);
259 int plugin_estimate(JCR *jcr, FF_PKT *ff_pkt, bool top_level);
260 bool plugin_check_file(JCR *jcr, char *fname);
261 bRC plugin_option_handle_file(JCR *jcr, FF_PKT *ff_pkt, struct save_pkt *sp);
262 int plugin_backup_acl(JCR *jcr, FF_PKT *ff_pkt, char **data);
263 bool plugin_restore_acl(JCR *jcr, char *data, uint32_t length);
264 int plugin_backup_xattr(JCR *jcr, FF_PKT *ff_pkt, char **data);
265 bool plugin_restore_xattr(JCR *jcr, char *data, uint32_t length);
266 #endif
267
268 #ifdef __cplusplus
269 extern "C" {
270 #endif
271
272 /*
273  * Bacula interface version and function pointers --
274  *  i.e. callbacks from the plugin to Bacula
275  */
276 typedef struct s_baculaFuncs {
277    uint32_t size;
278    uint32_t version;
279    bRC (*registerBaculaEvents)(bpContext *ctx, ...);
280    bRC (*getBaculaValue)(bpContext *ctx, bVariable var, void *value);
281    bRC (*setBaculaValue)(bpContext *ctx, bVariable var, void *value);
282    bRC (*JobMessage)(bpContext *ctx, const char *file, int line,
283        int type, utime_t mtime, const char *fmt, ...);
284    bRC (*DebugMessage)(bpContext *ctx, const char *file, int line,
285        int level, const char *fmt, ...);
286    void *(*baculaMalloc)(bpContext *ctx, const char *file, int line,
287        size_t size);
288    void (*baculaFree)(bpContext *ctx, const char *file, int line, void *mem);
289    bRC (*AddExclude)(bpContext *ctx, const char *file);
290    bRC (*AddInclude)(bpContext *ctx, const char *file);
291    bRC (*AddOptions)(bpContext *ctx, const char *opts);
292    bRC (*AddRegex)(bpContext *ctx, const char *item, int type);
293    bRC (*AddWild)(bpContext *ctx, const char *item, int type);
294    bRC (*NewOptions)(bpContext *ctx);
295    bRC (*NewInclude)(bpContext *ctx);
296    bRC (*NewPreInclude)(bpContext *ctx);
297    bRC (*checkChanges)(bpContext *ctx, struct save_pkt *sp);
298    bRC (*AcceptFile)(bpContext *ctx, struct save_pkt *sp); /* Need fname and statp */
299 } bFuncs;
300
301
302
303
304 /****************************************************************************
305  *                                                                          *
306  *                Plugin definitions                                        *
307  *                                                                          *
308  ****************************************************************************/
309
310 typedef enum {
311   pVarName = 1,
312   pVarDescription = 2
313 } pVariable;
314
315 # define FD_PLUGIN_MAGIC  "*FDPluginData*"
316
317 #define FD_PLUGIN_INTERFACE_VERSION  ( 14 )
318
319 typedef struct s_pluginInfo {
320    uint32_t size;
321    uint32_t version;
322    const char *plugin_magic;
323    const char *plugin_license;
324    const char *plugin_author;
325    const char *plugin_date;
326    const char *plugin_version;
327    const char *plugin_description;
328 } pInfo;
329
330 /*
331  * This is a set of function pointers that Bacula can call
332  *  within the plugin.
333  */
334 typedef struct s_pluginFuncs {
335    uint32_t size;
336    uint32_t version;
337    bRC (*newPlugin)(bpContext *ctx);
338    bRC (*freePlugin)(bpContext *ctx);
339    bRC (*getPluginValue)(bpContext *ctx, pVariable var, void *value);
340    bRC (*setPluginValue)(bpContext *ctx, pVariable var, void *value);
341    bRC (*handlePluginEvent)(bpContext *ctx, bEvent *event, void *value);
342    bRC (*startBackupFile)(bpContext *ctx, struct save_pkt *sp);
343    bRC (*endBackupFile)(bpContext *ctx);
344    bRC (*startRestoreFile)(bpContext *ctx, const char *cmd);
345    bRC (*endRestoreFile)(bpContext *ctx);
346    bRC (*pluginIO)(bpContext *ctx, struct io_pkt *io);
347    bRC (*createFile)(bpContext *ctx, struct restore_pkt *rp);
348    bRC (*setFileAttributes)(bpContext *ctx, struct restore_pkt *rp);
349    bRC (*checkFile)(bpContext *ctx, char *fname);
350    bRC (*handleXACLdata)(bpContext *ctx, struct xacl_pkt *xacl);
351 } pFuncs;
352
353 #define plug_func(plugin) ((pFuncs *)(plugin->pfuncs))
354 #define plug_info(plugin) ((pInfo *)(plugin->pinfo))
355
356 #ifdef __cplusplus
357 }
358 #endif
359
360 #endif /* __FD_PLUGINS_H */