/*
Bacula® - The Network Backup Solution
- Copyright (C) 2000-2007 Free Software Foundation Europe e.V.
+ Copyright (C) 2000-20087 Free Software Foundation Europe e.V.
The main author of Bacula is Kern Sibbald, with contributions from
many others, a complete list can be found in the file AUTHORS.
restore_cleanup(jcr, JS_ErrorTerminated);
return false;
}
- if (!bnet_fsend(jcr->store_bsock, "run")) {
+ if (!jcr->store_bsock->fsend("run")) {
return false;
}
/*
if (jcr->rstore->SDDport == 0) {
jcr->rstore->SDDport = jcr->rstore->SDport;
}
- bnet_fsend(fd, storaddr, jcr->rstore->address, jcr->rstore->SDDport);
+ fd->fsend(storaddr, jcr->rstore->address, jcr->rstore->SDDport);
Dmsg1(6, "dird>filed: %s\n", fd->msg);
if (!response(jcr, fd, OKstore, "Storage", DISPLAY_ERROR)) {
restore_cleanup(jcr, JS_ErrorTerminated);
where = jcr->job->RestoreWhere; /* no override take from job */
cmd = restorecmd;
- } else { /* nothing was specified */
- where = ∅ /* use default */
- cmd = restorecmd;
+ } else { /* nothing was specified */
+ where = ∅ /* use default */
+ cmd = restorecmd;
}
jcr->prefix_links = jcr->job->PrefixLinks;
bash_spaces(where);
- bnet_fsend(fd, cmd, replace, jcr->prefix_links, where);
+ fd->fsend(cmd, replace, jcr->prefix_links, where);
unbash_spaces(where);
if (!response(jcr, fd, OKrestore, "Restore", DISPLAY_ERROR)) {
term_msg = _("*** Restore Error ***");
msg_type = M_ERROR; /* Generate error message */
if (jcr->store_bsock) {
- bnet_sig(jcr->store_bsock, BNET_TERMINATE);
+ jcr->store_bsock->signal(BNET_TERMINATE);
if (jcr->SD_msg_chan) {
pthread_cancel(jcr->SD_msg_chan);
}
case JS_Canceled:
term_msg = _("Restore Canceled");
if (jcr->store_bsock) {
- bnet_sig(jcr->store_bsock, BNET_TERMINATE);
+ jcr->store_bsock->signal(BNET_TERMINATE);
if (jcr->SD_msg_chan) {
pthread_cancel(jcr->SD_msg_chan);
}
return;
}
+/*
+ * Tell the plugin to create the file. Return values are
+ *
+ * CF_ERROR -- error
+ * CF_SKIP -- skip processing this file
+ * CF_EXTRACT -- extract the file (i.e.call i/o routines)
+ * CF_CREATED -- created, but no content to extract (typically directories)
+ *
+ */
+int plugin_create_file(JCR *jcr, ATTR *attr, BFILE *bfd, int replace)
+{
+// bpContext *plugin_ctx = (bpContext *)jcr->plugin_ctx;
+// Plugin *plugin = (Plugin *)jcr->plugin;
+ if (!set_cmd_plugin(bfd, jcr)) {
+ return CF_ERROR;
+ }
+ return CF_EXTRACT;
+}
+
+/*
+ * Reset the file attributes after all file I/O is done -- this allows
+ * the previous access time/dates to be set properly, and it also allows
+ * us to properly set directory permissions.
+ */
+bool plugin_set_attributes(JCR *jcr, ATTR *attr, BFILE *ofd)
+{
+ return true;
+}
void load_fd_plugins(const char *plugin_dir)
{
ssize_t (*plugin_bwrite)(JCR *jcr, void *buf, size_t count) = NULL;
boffset_t (*plugin_blseek)(JCR *jcr, boffset_t offset, int whence) = NULL;
-int save_file(FF_PKT *ff_pkt, void *vjcr, bool top_level)
+int save_file(JCR *jcr, FF_PKT *ff_pkt, bool top_level)
{
return 0;
}
+bool set_cmd_plugin(BFILE *bfd, JCR *jcr)
+{
+ return true;
+}
+
int main(int argc, char *argv[])
{
char plugin_dir[1000];
Switzerland, email:ftf@fsfeurope.org.
*/
/*
- * Interface definition for Bacula Plugins
+ * Application Programming Interface (API) definition for Bacula Plugins
*
* Kern Sibbald, October 2007
*
struct restore_pkt {
};
-#define IO_OPEN 1
-#define IO_READ 2
-#define IO_WRITE 3
-#define IO_CLOSE 4
-#define IO_SEEK 5
+enum {
+ IO_OPEN = 1,
+ IO_READ = 2,
+ IO_WRITE = 3,
+ IO_CLOSE = 4,
+ IO_SEEK = 5
+};
struct io_pkt {
int32_t func; /* Function code */
} bInfo;
/* Bacula Core Routines -- not used by plugins */
+struct BFILE; /* forward referenced */
void load_fd_plugins(const char *plugin_dir);
void new_plugins(JCR *jcr);
void free_plugins(JCR *jcr);
void generate_plugin_event(JCR *jcr, bEventType event, void *value=NULL);
bool send_plugin_name(JCR *jcr, BSOCK *sd, bool start);
void plugin_name_stream(JCR *jcr, char *name);
+int plugin_create_file(JCR *jcr, ATTR *attr, BFILE *bfd, int replace);
+bool plugin_set_attributes(JCR *jcr, ATTR *attr, BFILE *ofd);
#ifdef __cplusplus
extern "C" {
#endif
-/* Bacula interface version and function pointers */
+/*
+ * Bacula interface version and function pointers --
+ * i.e. callbacks from the plugin to Bacula
+ */
typedef struct s_baculaFuncs {
uint32_t size;
uint32_t version;
char *plugin_description;
} pInfo;
+/*
+ * This is a set of function pointers that Bacula can call
+ * within the plugin.
+ */
typedef struct s_pluginFuncs {
uint32_t size;
uint32_t version;
bRC (*handlePluginEvent)(bpContext *ctx, bEvent *event, void *value);
bRC (*startPluginBackup)(bpContext *ctx, struct save_pkt *sp);
bRC (*endPluginBackup)(bpContext *ctx);
+ bRC (*startRestoreFile)(bpContext *ctx, const char *cmd);
+ bRC (*endRestoreFile)(bpContext *ctx);
bRC (*pluginIO)(bpContext *ctx, struct io_pkt *io);
- bRC (*createPluginFile)(bpContext *ctx, struct restore_pkt *rp);
+ bRC (*createFile)(bpContext *ctx, struct restore_pkt *rp);
+ bRC (*setFileAttributes)(bpContext *ctx, struct restore_pkt *rp);
} pFuncs;
#define plug_func(plugin) ((pFuncs *)(plugin->pfuncs))
/*
* Close a bfd check that we are at the expected file offset.
- * Makes some code in set_attributes().
+ * Makes use of some code from set_attributes().
*/
static int bclose_chksize(JCR *jcr, BFILE *bfd, boffset_t osize)
{
deallocate_fork_cipher(rctx);
}
- set_attributes(jcr, attr, &rctx.bfd);
+ if (jcr->plugin) {
+ plugin_set_attributes(jcr, attr, &rctx.bfd);
+ } else {
+ set_attributes(jcr, attr, &rctx.bfd);
+ }
extract = false;
/* Verify the cryptographic signature, if any */
build_attr_output_fnames(jcr, attr);
/*
- * Now determine if we are extracting or not.
+ * Try to actually create the file, which returns a status telling
+ * us if we need to extract or not.
*/
jcr->num_files_examined++;
extract = false;
- stat = create_file(jcr, attr, &rctx.bfd, jcr->replace);
+ if (jcr->plugin) {
+ stat = plugin_create_file(jcr, attr, &rctx.bfd, jcr->replace);
+ } else {
+ stat = create_file(jcr, attr, &rctx.bfd, jcr->replace);
+ }
Dmsg2(30, "Outfile=%s create_file stat=%d\n", attr->ofname, stat);
switch (stat) {
case CF_ERROR:
}
if (!extract) {
/* set attributes now because file will not be extracted */
- set_attributes(jcr, attr, &rctx.bfd);
+ if (jcr->plugin) {
+ plugin_set_attributes(jcr, attr, &rctx.bfd);
+ } else {
+ set_attributes(jcr, attr, &rctx.bfd);
+ }
}
break;
}
deallocate_cipher(rctx);
deallocate_fork_cipher(rctx);
- set_attributes(jcr, attr, &rctx.bfd);
+ if (jcr->plugin) {
+ plugin_set_attributes(jcr, attr, &rctx.bfd);
+ } else {
+ set_attributes(jcr, attr, &rctx.bfd);
+ }
/* Verify the cryptographic signature if any */
rctx.type = attr->type;
deallocate_cipher(rctx);
deallocate_fork_cipher(rctx);
- set_attributes(jcr, attr, &rctx.bfd);
+ if (jcr->plugin) {
+ plugin_set_attributes(jcr, attr, &rctx.bfd);
+ } else {
+ set_attributes(jcr, attr, &rctx.bfd);
+ }
/* Verify the cryptographic signature on the last file, if any */
rctx.type = attr->type;
return true;
}
-bool set_prog(BFILE *bfd, char *prog, JCR *jcr)
-{
- return false;
-}
-
bool set_cmd_plugin(BFILE *bfd, JCR *jcr)
{
bfd->cmd_plugin = true;
struct FF_PKT;
struct B_DB;
struct ATTR_DBR;
+struct Plugin;
+struct save_pkt;
#ifdef FILE_DAEMON
struct CRYPTO_CTX {
void *plugin_ctx_list; /* list of contexts for plugins */
void *plugin_ctx; /* current plugin context */
- void *plugin; /* plugin instance */
- void *plugin_sp; /* plugin save packet */
+ Plugin *plugin; /* plugin instance */
+ save_pkt *plugin_sp; /* plugin save packet */
/* Daemon specific part of JCR */
/* This should be empty in the library */
static bRC setPluginValue(bpContext *ctx, pVariable var, void *value);
static bRC handlePluginEvent(bpContext *ctx, bEvent *event, void *value);
static bRC startPluginBackup(bpContext *ctx, struct save_pkt *sp);
+static bRC endPluginBackup(bpContext *ctx);
static bRC pluginIO(bpContext *ctx, struct io_pkt *io);
+static bRC startRestoreFile(bpContext *ctx, const char *cmd);
+static bRC endRestoreFile(bpContext *ctx);
+static bRC createFile(bpContext *ctx, struct restore_pkt *rp);
+static bRC setFileAttributes(bpContext *ctx, struct restore_pkt *rp);
/* Pointers to Bacula functions */
setPluginValue,
handlePluginEvent,
startPluginBackup,
- pluginIO
+ endPluginBackup,
+ startRestoreFile,
+ endRestoreFile,
+ pluginIO,
+ createFile,
+ setFileAttributes
};
struct plugin_ctx {
return bRC_OK;
}
+static bRC endPluginBackup(bpContext *ctx)
+{
+ return bRC_OK;
+}
+
/*
* Do actual I/O
*/
return bRC_OK;
}
+static bRC startRestoreFile(bpContext *ctx, const char *cmd)
+{
+ return bRC_OK;
+}
+
+static bRC endRestoreFile(bpContext *ctx)
+{
+ return bRC_OK;
+}
+
+static bRC createFile(bpContext *ctx, struct restore_pkt *rp)
+{
+ return bRC_OK;
+}
+
+static bRC setFileAttributes(bpContext *ctx, struct restore_pkt *rp)
+{
+ return bRC_OK;
+}
+
+
#ifdef __cplusplus
}
#endif
static bRC setPluginValue(bpContext *ctx, pVariable var, void *value);
static bRC handlePluginEvent(bpContext *ctx, bEvent *event, void *value);
static bRC startPluginBackup(bpContext *ctx, struct save_pkt *sp);
+static bRC endPluginBackup(bpContext *ctx);
static bRC pluginIO(bpContext *ctx, struct io_pkt *io);
+static bRC startRestoreFile(bpContext *ctx, const char *cmd);
+static bRC endRestoreFile(bpContext *ctx);
+static bRC createFile(bpContext *ctx, struct restore_pkt *rp);
+static bRC setFileAttributes(bpContext *ctx, struct restore_pkt *rp);
/* Pointers to Bacula functions */
setPluginValue,
handlePluginEvent,
startPluginBackup,
- pluginIO
+ endPluginBackup,
+ startRestoreFile,
+ endRestoreFile,
+ pluginIO,
+ createFile,
+ setFileAttributes
};
bRC loadPlugin(bInfo *lbinfo, bFuncs *lbfuncs, pInfo **pinfo, pFuncs **pfuncs)
return bRC_OK;
}
+static bRC endPluginBackup(bpContext *ctx)
+{
+ return bRC_OK;
+}
+
/*
* Do actual I/O
*/
return bRC_OK;
}
+static bRC startRestoreFile(bpContext *ctx, const char *cmd)
+{
+ return bRC_OK;
+}
+
+static bRC endRestoreFile(bpContext *ctx)
+{
+ return bRC_OK;
+}
+
+static bRC createFile(bpContext *ctx, struct restore_pkt *rp)
+{
+ return bRC_OK;
+}
+
+static bRC setFileAttributes(bpContext *ctx, struct restore_pkt *rp)
+{
+ return bRC_OK;
+}
+
+
#ifdef __cplusplus
}
#endif