1 /* 2 BAREOS® - Backup Archiving REcovery Open Sourced 3 4 Copyright (C) 2007-2012 Free Software Foundation Europe e.V. 5 Copyright (C) 2011-2012 Planets Communications B.V. 6 Copyright (C) 2013-2016 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, which is 11 listed 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 * Application Programming Interface (API) definition for Bareos Plugins 25 * 26 * Kern Sibbald, October 2007 27 */ 28 29 #ifndef BAREOS_FILED_FD_PLUGINS_H_ 30 #define BAREOS_FILED_FD_PLUGINS_H_ 31 32 #ifndef BAREOS_INCLUDE_BAREOS_H_ 33 #ifdef __cplusplus 34 /* Workaround for SGI IRIX 6.5 */ 35 #define _LANGUAGE_C_PLUS_PLUS 1 36 #endif 37 #define _REENTRANT 1 38 #define _THREAD_SAFE 1 39 #define _POSIX_PTHREAD_SEMANTICS 1 40 #define _FILE_OFFSET_BITS 64 41 #define _LARGEFILE_SOURCE 1 42 #define _LARGE_FILES 1 43 #endif /* ! BAREOS_INCLUDE_BAREOS_H_ */ 44 45 #include <sys/types.h> 46 47 #include "include/hostconfig.h" 48 49 #include "include/version.h" 50 #include "include/bc_types.h" 51 #include "include/fileopts.h" 52 #include "lib/plugins.h" 53 #include <sys/stat.h> 54 55 #ifdef HAVE_WIN32 56 #include "vss.h" 57 #endif 58 59 #ifdef FILE_DAEMON 60 struct BareosWinFilePacket; 61 struct FindFilesPacket; 62 #endif /* FILE_DAEMON */ 63 64 namespace filedaemon { 65 66 /* 67 * This packet is used for the restore objects 68 * It is passed to the plugin when restoring 69 * the object. 70 */ 71 struct restore_object_pkt { 72 int32_t pkt_size; /* Size of this packet */ 73 char *object_name; /* Object name */ 74 char *object; /* Restore object data to save */ 75 char *plugin_name; /* Plugin name */ 76 int32_t object_type; /* FT_xx for this file */ 77 int32_t object_len; /* Restore object length */ 78 int32_t object_full_len; /* Restore object uncompressed length */ 79 int32_t object_index; /* Restore object index */ 80 int32_t object_compression; /* Set to compression type */ 81 int32_t stream; /* Attribute stream id */ 82 uint32_t JobId; /* JobId object came from */ 83 int32_t pkt_end; /* End packet sentinel */ 84 }; 85 86 /* 87 * This packet is used for file save info transfer. 88 */ 89 struct save_pkt { 90 int32_t pkt_size; /* Size of this packet */ 91 char *fname; /* Full path and filename */ 92 char *link; /* Link name if any */ 93 struct stat statp; /* System stat() packet for file */ 94 int32_t type; /* FT_xx for this file */ 95 char flags[FOPTS_BYTES]; /* Bareos internal flags */ 96 bool no_read; /* During the save, the file should not be saved */ 97 bool portable; /* Set if data format is portable */ 98 bool accurate_found; /* Found in accurate list (valid after CheckChanges()) */ 99 char *cmd; /* Command */ 100 time_t save_time; /* Start of incremental time */ 101 uint32_t delta_seq; /* Delta sequence number */ 102 char *object_name; /* Object name to create */ 103 char *object; /* Restore object data to save */ 104 int32_t object_len; /* Restore object length */ 105 int32_t index; /* Restore object index */ 106 int32_t pkt_end; /* End packet sentinel */ 107 }; 108 109 /* 110 * This packet is used for file restore info transfer. 111 */ 112 struct restore_pkt { 113 int32_t pkt_size; /* Size of this packet */ 114 int32_t stream; /* Attribute stream id */ 115 int32_t data_stream; /* Id of data stream to follow */ 116 int32_t type; /* File type FT */ 117 int32_t file_index; /* File index */ 118 int32_t LinkFI; /* File index to data if hard link */ 119 uid_t uid; /* Userid */ 120 struct stat statp; /* Decoded stat packet */ 121 const char *attrEx; /* Extended attributes if any */ 122 const char *ofname; /* Output filename */ 123 const char *olname; /* Output link name */ 124 const char *where; /* Where */ 125 const char *RegexWhere; /* Regex where */ 126 int replace; /* Replace flag */ 127 int create_status; /* Status from createFile() */ 128 uint32_t delta_seq; /* Delta sequence number */ 129 int32_t pkt_end; /* End packet sentinel */ 130 }; 131 132 enum { 133 IO_OPEN = 1, 134 IO_READ = 2, 135 IO_WRITE = 3, 136 IO_CLOSE = 4, 137 IO_SEEK = 5 138 }; 139 140 struct io_pkt { 141 int32_t pkt_size; /* Size of this packet */ 142 int32_t func; /* Function code */ 143 int32_t count; /* Read/write count */ 144 int32_t flags; /* Open flags */ 145 mode_t mode; /* Permissions for created files */ 146 char *buf; /* Read/write buffer */ 147 const char *fname; /* Open filename */ 148 int32_t status; /* Return status */ 149 int32_t io_errno; /* Errno code */ 150 int32_t lerror; /* Win32 error code */ 151 int32_t whence; /* Lseek argument */ 152 boffset_t offset; /* Lseek argument */ 153 bool win32; /* Win32 GetLastError returned */ 154 int32_t pkt_end; /* End packet sentinel */ 155 }; 156 157 struct acl_pkt { 158 int32_t pkt_size; /* Size of this packet */ 159 const char *fname; /* Full path and filename */ 160 uint32_t content_length; /* ACL content length */ 161 char *content; /* ACL content */ 162 int32_t pkt_end; /* End packet sentinel */ 163 }; 164 165 struct xattr_pkt { 166 int32_t pkt_size; /* Size of this packet */ 167 const char *fname; /* Full path and filename */ 168 uint32_t name_length; /* XATTR name length */ 169 char *name; /* XATTR name */ 170 uint32_t value_length; /* XATTR value length */ 171 char *value; /* XATTR value */ 172 int32_t pkt_end; /* End packet sentinel */ 173 }; 174 175 /**************************************************************************** 176 * * 177 * Bareos definitions * 178 * * 179 ****************************************************************************/ 180 181 /* 182 * Bareos Variable Ids 183 */ 184 typedef enum { 185 bVarJobId = 1, 186 bVarFDName = 2, 187 bVarLevel = 3, 188 bVarType = 4, 189 bVarClient = 5, 190 bVarJobName = 6, 191 bVarJobStatus = 7, 192 bVarSinceTime = 8, 193 bVarAccurate = 9, 194 bVarFileSeen = 10, 195 bVarVssClient = 11, 196 bVarWorkingDir = 12, 197 bVarWhere = 13, 198 bVarRegexWhere = 14, 199 bVarExePath = 15, 200 bVarVersion = 16, 201 bVarDistName = 17, 202 bVarPrevJobName = 18, 203 bVarPrefixLinks = 19 204 } bVariable; 205 206 /* 207 * Events that are passed to plugin 208 */ 209 typedef enum { 210 bEventJobStart = 1, 211 bEventJobEnd = 2, 212 bEventStartBackupJob = 3, 213 bEventEndBackupJob = 4, 214 bEventStartRestoreJob = 5, 215 bEventEndRestoreJob = 6, 216 bEventStartVerifyJob = 7, 217 bEventEndVerifyJob = 8, 218 bEventBackupCommand = 9, 219 bEventRestoreCommand = 10, 220 bEventEstimateCommand = 11, 221 bEventLevel = 12, 222 bEventSince = 13, 223 bEventCancelCommand = 14, 224 bEventRestoreObject = 15, 225 bEventEndFileSet = 16, 226 bEventPluginCommand = 17, 227 bEventOptionPlugin = 18, 228 bEventHandleBackupFile = 19, 229 bEventNewPluginOptions = 20, 230 bEventVssInitializeForBackup = 21, 231 bEventVssInitializeForRestore = 22, 232 bEventVssSetBackupState = 23, 233 bEventVssPrepareForBackup = 24, 234 bEventVssBackupAddComponents = 25, 235 bEventVssPrepareSnapshot = 26, 236 bEventVssCreateSnapshots = 27, 237 bEventVssRestoreLoadComponentMetadata = 28, 238 bEventVssRestoreSetComponentsSelected = 29, 239 bEventVssCloseRestore = 30, 240 bEventVssBackupComplete = 31 241 } bEventType; 242 243 #define FD_NR_EVENTS bEventVssBackupComplete /* keep this updated ! */ 244 245 typedef struct s_bEvent { 246 uint32_t eventType; 247 } bEvent; 248 249 typedef struct s_bareosInfo { 250 uint32_t size; 251 uint32_t version; 252 } bInfo; 253 254 /* 255 * Bareos Core Routines -- not used within a plugin 256 */ 257 #ifdef FILE_DAEMON 258 void LoadFdPlugins(const char *plugin_dir, alist *plugin_names); 259 void UnloadFdPlugins(void); 260 int ListFdPlugins(PoolMem &msg); 261 void NewPlugins(JobControlRecord *jcr); 262 void FreePlugins(JobControlRecord *jcr); 263 bRC GeneratePluginEvent(JobControlRecord *jcr, bEventType event, 264 void *value = NULL, bool reverse = false); 265 bool SendPluginName(JobControlRecord *jcr, BareosSocket *sd, bool start); 266 bool PluginNameStream(JobControlRecord *jcr, char *name); 267 int PluginCreateFile(JobControlRecord *jcr, Attributes *attr, BareosWinFilePacket *bfd, int replace); 268 bool PluginSetAttributes(JobControlRecord *jcr, Attributes *attr, BareosWinFilePacket *ofd); 269 bacl_exit_code PluginBuildAclStreams(JobControlRecord *jcr, acl_data_t *acl_data, FindFilesPacket *ff_pkt); 270 bacl_exit_code plugin_parse_acl_streams(JobControlRecord *jcr, acl_data_t *acl_data, int stream, 271 char *content, uint32_t content_length); 272 BxattrExitCode PluginBuildXattrStreams(JobControlRecord *jcr, struct xattr_data_t *xattr_data, 273 FindFilesPacket *ff_pkt); 274 BxattrExitCode PluginParseXattrStreams(JobControlRecord *jcr, struct xattr_data_t *xattr_data, 275 int stream, char *content, uint32_t content_length); 276 int PluginSave(JobControlRecord *jcr, FindFilesPacket *ff_pkt, bool top_level); 277 int PluginEstimate(JobControlRecord *jcr, FindFilesPacket *ff_pkt, bool top_level); 278 bool PluginCheckFile(JobControlRecord *jcr, char *fname); 279 void PluginUpdateFfPkt(FindFilesPacket *ff_pkt, struct save_pkt *sp); 280 bRC PluginOptionHandleFile(JobControlRecord *jcr, FindFilesPacket *ff_pkt, struct save_pkt *sp); 281 #endif 282 283 #ifdef __cplusplus 284 extern "C" { 285 #endif 286 287 /* 288 * Bareos interface version and function pointers -- 289 * i.e. callbacks from the plugin to Bareos 290 */ 291 typedef struct s_bareosFuncs { 292 uint32_t size; 293 uint32_t version; 294 bRC (*registerBareosEvents)(bpContext *ctx, int nr_events, ...); 295 bRC (*unregisterBareosEvents)(bpContext *ctx, int nr_events, ...); 296 bRC (*getInstanceCount)(bpContext *ctx, int *ret); 297 bRC (*getBareosValue)(bpContext *ctx, bVariable var, void *value); 298 bRC (*setBareosValue)(bpContext *ctx, bVariable var, void *value); 299 bRC (*JobMessage)(bpContext *ctx, const char *file, int line, int type, 300 utime_t mtime, const char *fmt, ...); 301 bRC (*DebugMessage)(bpContext *ctx, const char *file, int line, int level, 302 const char *fmt, ...); 303 void *(*bareosMalloc)(bpContext *ctx, const char *file, int line, size_t size); 304 void (*bareosFree)(bpContext *ctx, const char *file, int line, void *mem); 305 bRC (*AddExclude)(bpContext *ctx, const char *file); 306 bRC (*AddInclude)(bpContext *ctx, const char *file); 307 bRC (*AddOptions)(bpContext *ctx, const char *opts); 308 bRC (*AddRegex)(bpContext *ctx, const char *item, int type); 309 bRC (*AddWild)(bpContext *ctx, const char *item, int type); 310 bRC (*NewOptions)(bpContext *ctx); 311 bRC (*NewInclude)(bpContext *ctx); 312 bRC (*NewPreInclude)(bpContext *ctx); 313 bRC (*checkChanges)(bpContext *ctx, struct save_pkt *sp); 314 bRC (*AcceptFile)(bpContext *ctx, struct save_pkt *sp); /* Need fname and statp */ 315 bRC (*SetSeenBitmap)(bpContext *ctx, bool all, char *fname); 316 bRC (*ClearSeenBitmap)(bpContext *ctx, bool all, char *fname); 317 } bFuncs; 318 319 /**************************************************************************** 320 * * 321 * Plugin definitions * 322 * * 323 ****************************************************************************/ 324 325 typedef enum { 326 pVarName = 1, 327 pVarDescription = 2 328 } pVariable; 329 330 #define FD_PLUGIN_MAGIC "*FDPluginData*" 331 #define FD_PLUGIN_INTERFACE_VERSION 10 332 333 /* 334 * This is a set of function pointers that Bareos can call within the plugin. 335 */ 336 typedef struct s_pluginFuncs { 337 uint32_t size; 338 uint32_t version; 339 bRC (*newPlugin)(bpContext *ctx); 340 bRC (*freePlugin)(bpContext *ctx); 341 bRC (*getPluginValue)(bpContext *ctx, pVariable var, void *value); 342 bRC (*setPluginValue)(bpContext *ctx, pVariable var, void *value); 343 bRC (*handlePluginEvent)(bpContext *ctx, bEvent *event, void *value); 344 bRC (*startBackupFile)(bpContext *ctx, struct save_pkt *sp); 345 bRC (*endBackupFile)(bpContext *ctx); 346 bRC (*startRestoreFile)(bpContext *ctx, const char *cmd); 347 bRC (*endRestoreFile)(bpContext *ctx); 348 bRC (*pluginIO)(bpContext *ctx, struct io_pkt *io); 349 bRC (*createFile)(bpContext *ctx, struct restore_pkt *rp); 350 bRC (*setFileAttributes)(bpContext *ctx, struct restore_pkt *rp); 351 bRC (*checkFile)(bpContext *ctx, char *fname); 352 bRC (*getAcl)(bpContext *ctx, struct acl_pkt *ap); 353 bRC (*setAcl)(bpContext *ctx, struct acl_pkt *ap); 354 bRC (*getXattr)(bpContext *ctx, struct xattr_pkt *xp); 355 bRC (*setXattr)(bpContext *ctx, struct xattr_pkt *xp); 356 } pFuncs; 357 358 #define PlugFunc(plugin) ((pFuncs *)(plugin->pfuncs)) 359 #define plug_info(plugin) ((genpInfo *)(plugin->pinfo)) 360 361 #ifdef __cplusplus 362 } 363 #endif 364 365 } /* namespace filedaemon */ 366 #endif /* BAREOS_FILED_FD_PLUGINS_H_ */ 367