2 Bacula(R) - The Network Backup Solution
4 Copyright (C) 2000-2018 Kern Sibbald
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.
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.
14 This notice must be preserved when any source code is
15 conveyed and/or propagated.
17 Bacula(R) is a registered trademark of Kern Sibbald.
20 * Written by James Harper, October 2008
23 #include "exchange-fd.h"
25 service_node_t::service_node_t(char *name, node_t *parent_node) : node_t(name, NODE_TYPE_SERVICE, parent_node)
31 first_storage_group_node = NULL;
34 service_node_t::~service_node_t()
39 service_node_t::startBackupFile(exchange_fd_context_t *context, struct save_pkt *sp)
44 _DebugMessage(100, "startBackupNode_SERVICE state = %d\n", state);
48 if (strcmp(PLUGIN_PATH_PREFIX_SERVICE, name) != 0)
50 _JobMessage(M_FATAL, "Invalid restore path specified, must start with /" PLUGIN_PATH_PREFIX_BASE "/" PLUGIN_PATH_PREFIX_SERVICE "/\n");
53 // convert name to a wide string
55 _DebugMessage(100, "Calling HrESEBackupPrepare\n");
56 wcstombs(aname, context->computer_name, 256);
57 _JobMessage(M_INFO, "Preparing Exchange Backup for %s\n", aname);
58 result = HrESEBackupPrepare(context->computer_name, PLUGIN_PATH_PREFIX_SERVICE_W, &ibi_count, &ibi, &hccx);
61 _JobMessage(M_FATAL, "HrESEBackupPrepare failed with error 0x%08x - %s\n", result, ESEErrorMessage(result));
67 if (context->path_bits[level + 1] == NULL)
69 _DebugMessage(100, "No specific storage group specified - backing them all up\n");
70 char *tmp = new char[wcslen(ibi[current_ibi].wszInstanceName) + 1];
71 wcstombs(tmp, ibi[current_ibi].wszInstanceName, wcslen(ibi[current_ibi].wszInstanceName) + 1);
72 first_storage_group_node = new storage_group_node_t(tmp, this);
74 _DebugMessage(100, "storage group name = %s\n", first_storage_group_node->name);
75 first_storage_group_node->ibi = &ibi[current_ibi];
76 first_storage_group_node->hccx = hccx;
77 context->current_node = first_storage_group_node;
82 for (current_ibi = 0; current_ibi < ibi_count; current_ibi++)
84 tmp = new char[wcslen(ibi[current_ibi].wszInstanceName) + 1];
85 wcstombs(tmp, ibi[current_ibi].wszInstanceName, wcslen(ibi[current_ibi].wszInstanceName) + 1);
86 if (stricmp(tmp, context->path_bits[level + 1]) == 0)
89 first_storage_group_node = new storage_group_node_t(tmp, this);
91 if (current_ibi == ibi_count)
93 _JobMessage(M_FATAL, "Invalid Storage Group '%s'\n", context->path_bits[level + 1]);
96 _DebugMessage(100, "storage group name = %s\n", first_storage_group_node->name);
97 first_storage_group_node->ibi = &ibi[current_ibi];
98 first_storage_group_node->hccx = hccx;
99 context->current_node = first_storage_group_node;
103 time_t now = time(NULL);
104 sp->fname = full_path;
105 sp->link = full_path;
106 sp->statp.st_mode = 0700 | S_IFDIR;
107 sp->statp.st_ctime = now;
108 sp->statp.st_mtime = now;
109 sp->statp.st_atime = now;
110 sp->statp.st_size = 0;
111 sp->statp.st_nlink = 1;
112 //sp->statp.st_blocks = 0;
113 sp->type = FT_DIREND;
116 _DebugMessage(100, "ending startBackupNode_SERVICE state = %d\n", state);
121 service_node_t::endBackupFile(exchange_fd_context_t *context)
126 _DebugMessage(100, "endBackupNode_SERVICE state = %d\n", state);
130 // should never happen
133 // free node->storage_group_node
134 if (context->path_bits[level + 1] == NULL)
137 if (current_ibi == ibi_count)
145 _DebugMessage(100, "calling HrESEBackupEnd\n");
146 result = HrESEBackupEnd(hccx);
149 _JobMessage(M_FATAL, "HrESEBackupEnd failed with error 0x%08x - %s\n", result, ESEErrorMessage(result));
153 context->current_node = parent;
161 service_node_t::createFile(exchange_fd_context_t *context, struct restore_pkt *rp)
163 storage_group_node_t *curr_sg, *prev_sg;
165 _DebugMessage(100, "createFile_SERVICE state = %d\n", state);
166 if (strcmp(name, "Microsoft Information Store") != 0)
168 _JobMessage(M_FATAL, "Invalid restore path specified, must start with '/" PLUGIN_PATH_PREFIX_BASE "/" PLUGIN_PATH_PREFIX_SERVICE "/'\n", state);
176 if (context->path_bits[level + 1] == NULL)
181 for (prev_sg = NULL, curr_sg = first_storage_group_node; curr_sg != NULL; prev_sg = curr_sg, curr_sg = curr_sg->next)
183 if (strcmp(curr_sg->name, context->path_bits[level + 1]) == 0)
190 curr_sg = new storage_group_node_t(bstrdup(context->path_bits[level + 1]), this);
192 first_storage_group_node = curr_sg;
194 prev_sg->next = curr_sg;
196 context->current_node = curr_sg;
199 rp->create_status = CF_CREATED;
207 service_node_t::endRestoreFile(exchange_fd_context_t *context)
209 _DebugMessage(100, "endRestoreFile_SERVICE state = %d\n", state);
215 context->current_node = parent;