]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/filed/fd_plugins.h
19e69cb9bbe0649050c054c00635abaf6834f877
[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   bVarReplace               = 23,
200 } bVariable;
201
202 /* Events that are passed to plugin */
203 typedef enum {
204   bEventJobStart                        = 1,
205   bEventJobEnd                          = 2,
206   bEventStartBackupJob                  = 3,
207   bEventEndBackupJob                    = 4,
208   bEventStartRestoreJob                 = 5,
209   bEventEndRestoreJob                   = 6,
210   bEventStartVerifyJob                  = 7,
211   bEventEndVerifyJob                    = 8,
212   bEventBackupCommand                   = 9,
213   bEventRestoreCommand                  = 10,
214   bEventEstimateCommand                 = 11,
215   bEventLevel                           = 12,
216   bEventSince                           = 13,
217   bEventCancelCommand                   = 14, /* Executed by another thread */
218   bEventVssBackupAddComponents          = 15, /* Just before bEventVssPrepareSnapshot */
219   bEventVssRestoreLoadComponentMetadata = 16,
220   bEventVssRestoreSetComponentsSelected = 17,
221   bEventRestoreObject                   = 18,
222   bEventEndFileSet                      = 19,
223   bEventPluginCommand                   = 20, /* Sent during FileSet creation */
224   bEventVssBeforeCloseRestore           = 21,
225   /* Add drives to VSS snapshot
226    *  argument: char[27] drivelist
227    * You need to add them without duplicates,
228    * see fd_common.h add_drive() copy_drives() to get help
229    */
230   bEventVssPrepareSnapshot              = 22,
231   bEventOptionPlugin                    = 23,
232   bEventHandleBackupFile                = 24, /* Used with Options Plugin */
233   bEventComponentInfo                   = 25  /* Plugin component */
234 } bEventType;
235
236 typedef struct s_bEvent {
237    uint32_t eventType;
238 } bEvent;
239
240 typedef struct s_baculaInfo {
241    uint32_t size;
242    uint32_t version;
243 } bInfo;
244
245 /* Bacula Core Routines -- not used within a plugin */
246 #ifdef FILE_DAEMON
247 struct BFILE;                   /* forward referenced */
248 struct FF_PKT;
249 void load_fd_plugins(const char *plugin_dir);
250 void new_plugins(JCR *jcr);
251 void free_plugins(JCR *jcr);
252 void generate_plugin_event(JCR *jcr, bEventType event, void *value=NULL);
253 bool send_plugin_name(JCR *jcr, BSOCK *sd, bool start);
254 bool plugin_name_stream(JCR *jcr, char *name);
255 int plugin_create_file(JCR *jcr, ATTR *attr, BFILE *bfd, int replace);
256 bool plugin_set_attributes(JCR *jcr, ATTR *attr, BFILE *ofd);
257 int plugin_save(JCR *jcr, FF_PKT *ff_pkt, bool top_level);
258 int plugin_estimate(JCR *jcr, FF_PKT *ff_pkt, bool top_level);
259 bool plugin_check_file(JCR *jcr, char *fname);
260 bRC plugin_option_handle_file(JCR *jcr, FF_PKT *ff_pkt, struct save_pkt *sp);
261 int plugin_backup_acl(JCR *jcr, FF_PKT *ff_pkt, char **data);
262 bool plugin_restore_acl(JCR *jcr, char *data, uint32_t length);
263 int plugin_backup_xattr(JCR *jcr, FF_PKT *ff_pkt, char **data);
264 bool plugin_restore_xattr(JCR *jcr, char *data, uint32_t length);
265 #endif
266
267 #ifdef __cplusplus
268 extern "C" {
269 #endif
270
271 /*
272  * Bacula interface version and function pointers --
273  *  i.e. callbacks from the plugin to Bacula
274  */
275 typedef struct s_baculaFuncs {
276    uint32_t size;
277    uint32_t version;
278    bRC (*registerBaculaEvents)(bpContext *ctx, ...);
279    bRC (*getBaculaValue)(bpContext *ctx, bVariable var, void *value);
280    bRC (*setBaculaValue)(bpContext *ctx, bVariable var, void *value);
281    bRC (*JobMessage)(bpContext *ctx, const char *file, int line,
282        int type, utime_t mtime, const char *fmt, ...);
283    bRC (*DebugMessage)(bpContext *ctx, const char *file, int line,
284        int level, const char *fmt, ...);
285    void *(*baculaMalloc)(bpContext *ctx, const char *file, int line,
286        size_t size);
287    void (*baculaFree)(bpContext *ctx, const char *file, int line, void *mem);
288    bRC (*AddExclude)(bpContext *ctx, const char *file);
289    bRC (*AddInclude)(bpContext *ctx, const char *file);
290    bRC (*AddOptions)(bpContext *ctx, const char *opts);
291    bRC (*AddRegex)(bpContext *ctx, const char *item, int type);
292    bRC (*AddWild)(bpContext *ctx, const char *item, int type);
293    bRC (*NewOptions)(bpContext *ctx);
294    bRC (*NewInclude)(bpContext *ctx);
295    bRC (*NewPreInclude)(bpContext *ctx);
296    bRC (*checkChanges)(bpContext *ctx, struct save_pkt *sp);
297    bRC (*AcceptFile)(bpContext *ctx, struct save_pkt *sp); /* Need fname and statp */
298 } bFuncs;
299
300
301
302
303 /****************************************************************************
304  *                                                                          *
305  *                Plugin definitions                                        *
306  *                                                                          *
307  ****************************************************************************/
308
309 typedef enum {
310   pVarName = 1,
311   pVarDescription = 2
312 } pVariable;
313
314 # define FD_PLUGIN_MAGIC  "*FDPluginData*"
315
316 #define FD_PLUGIN_INTERFACE_VERSION  ( 14 )
317
318 typedef struct s_pluginInfo {
319    uint32_t size;
320    uint32_t version;
321    const char *plugin_magic;
322    const char *plugin_license;
323    const char *plugin_author;
324    const char *plugin_date;
325    const char *plugin_version;
326    const char *plugin_description;
327 } pInfo;
328
329 /*
330  * This is a set of function pointers that Bacula can call
331  *  within the plugin.
332  */
333 typedef struct s_pluginFuncs {
334    uint32_t size;
335    uint32_t version;
336    bRC (*newPlugin)(bpContext *ctx);
337    bRC (*freePlugin)(bpContext *ctx);
338    bRC (*getPluginValue)(bpContext *ctx, pVariable var, void *value);
339    bRC (*setPluginValue)(bpContext *ctx, pVariable var, void *value);
340    bRC (*handlePluginEvent)(bpContext *ctx, bEvent *event, void *value);
341    bRC (*startBackupFile)(bpContext *ctx, struct save_pkt *sp);
342    bRC (*endBackupFile)(bpContext *ctx);
343    bRC (*startRestoreFile)(bpContext *ctx, const char *cmd);
344    bRC (*endRestoreFile)(bpContext *ctx);
345    bRC (*pluginIO)(bpContext *ctx, struct io_pkt *io);
346    bRC (*createFile)(bpContext *ctx, struct restore_pkt *rp);
347    bRC (*setFileAttributes)(bpContext *ctx, struct restore_pkt *rp);
348    bRC (*checkFile)(bpContext *ctx, char *fname);
349    bRC (*handleXACLdata)(bpContext *ctx, struct xacl_pkt *xacl);
350 } pFuncs;
351
352 #define plug_func(plugin) ((pFuncs *)(plugin->pfuncs))
353 #define plug_info(plugin) ((pInfo *)(plugin->pinfo))
354
355 #ifdef __cplusplus
356 }
357 #endif
358
359 #endif /* __FD_PLUGINS_H */