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, July 2010
22 * Used only in "old Exchange plugin" now deprecated.
25 #include "exchange-fd.h"
27 service_node_t::service_node_t(char *name, node_t *parent_node) : node_t(name, NODE_TYPE_SERVICE, parent_node)
33 first_storage_group_node = NULL;
36 service_node_t::~service_node_t()
41 service_node_t::startBackupFile(exchange_fd_context_t *context, struct save_pkt *sp)
46 _DebugMessage(100, "startBackupNode_SERVICE state = %d\n", state);
50 if (strcmp(PLUGIN_PATH_PREFIX_SERVICE, name) != 0)
52 _JobMessage(M_FATAL, "Invalid restore path specified, must start with /" PLUGIN_PATH_PREFIX_BASE "/" PLUGIN_PATH_PREFIX_SERVICE "/\n");
55 // convert name to a wide string
57 _DebugMessage(100, "Calling HrESEBackupPrepare\n");
58 wcstombs(aname, context->computer_name, 256);
59 _JobMessage(M_INFO, "Preparing Exchange Backup for %s\n", aname);
60 result = HrESEBackupPrepare(context->computer_name,
61 (WCHAR *)PLUGIN_PATH_PREFIX_SERVICE_W, &ibi_count, &ibi, &hccx);
64 _JobMessage(M_FATAL, "HrESEBackupPrepare failed with error 0x%08x - %s\n", result, ESEErrorMessage(result));
70 if (context->path_bits[level + 1] == NULL)
72 _DebugMessage(100, "No specific storage group specified - backing them all up\n");
73 char *tmp = new char[wcslen(ibi[current_ibi].wszInstanceName) + 1];
74 wcstombs(tmp, ibi[current_ibi].wszInstanceName, wcslen(ibi[current_ibi].wszInstanceName) + 1);
75 first_storage_group_node = new storage_group_node_t(tmp, this);
77 _DebugMessage(100, "storage group name = %s\n", first_storage_group_node->name);
78 first_storage_group_node->ibi = &ibi[current_ibi];
79 first_storage_group_node->hccx = hccx;
80 context->current_node = first_storage_group_node;
85 for (current_ibi = 0; current_ibi < ibi_count; current_ibi++)
87 tmp = new char[wcslen(ibi[current_ibi].wszInstanceName) + 1];
88 wcstombs(tmp, ibi[current_ibi].wszInstanceName, wcslen(ibi[current_ibi].wszInstanceName) + 1);
89 if (stricmp(tmp, context->path_bits[level + 1]) == 0)
92 first_storage_group_node = new storage_group_node_t(tmp, this);
94 if (current_ibi == ibi_count)
96 _JobMessage(M_FATAL, "Invalid Storage Group '%s'\n", context->path_bits[level + 1]);
99 _DebugMessage(100, "storage group name = %s\n", first_storage_group_node->name);
100 first_storage_group_node->ibi = &ibi[current_ibi];
101 first_storage_group_node->hccx = hccx;
102 context->current_node = first_storage_group_node;
106 time_t now = time(NULL);
107 sp->fname = full_path;
108 sp->link = full_path;
109 sp->statp.st_mode = 0700 | S_IFDIR;
110 sp->statp.st_ctime = now;
111 sp->statp.st_mtime = now;
112 sp->statp.st_atime = now;
113 sp->statp.st_size = 0;
114 sp->statp.st_nlink = 1;
115 //sp->statp.st_blocks = 0;
116 sp->type = FT_DIREND;
119 _DebugMessage(100, "ending startBackupNode_SERVICE state = %d\n", state);
124 service_node_t::endBackupFile(exchange_fd_context_t *context)
129 _DebugMessage(100, "endBackupNode_SERVICE state = %d\n", state);
133 // should never happen
136 // free node->storage_group_node
137 if (context->path_bits[level + 1] == NULL)
140 if (current_ibi == ibi_count)
148 _DebugMessage(100, "calling HrESEBackupEnd\n");
149 result = HrESEBackupEnd(hccx);
152 _JobMessage(M_FATAL, "HrESEBackupEnd failed with error 0x%08x - %s\n", result, ESEErrorMessage(result));
156 context->current_node = parent;
164 service_node_t::createFile(exchange_fd_context_t *context, struct restore_pkt *rp)
166 storage_group_node_t *curr_sg, *prev_sg;
168 _DebugMessage(0, "createFile_SERVICE state = %d\n", state);
169 if (strcmp(name, "Microsoft Information Store") != 0)
171 _JobMessage(M_FATAL, "Invalid restore path specified, must start with '/" PLUGIN_PATH_PREFIX_BASE "/" PLUGIN_PATH_PREFIX_SERVICE "/'\n", state);
179 if (context->path_bits[level + 1] == NULL)
184 for (prev_sg = NULL, curr_sg = first_storage_group_node; curr_sg != NULL; prev_sg = curr_sg, curr_sg = curr_sg->next)
186 if (strcmp(curr_sg->name, context->path_bits[level + 1]) == 0)
193 curr_sg = new storage_group_node_t(bstrdup(context->path_bits[level + 1]), this);
195 first_storage_group_node = curr_sg;
197 prev_sg->next = curr_sg;
199 context->current_node = curr_sg;
202 rp->create_status = CF_CREATED;
210 service_node_t::endRestoreFile(exchange_fd_context_t *context)
212 _DebugMessage(0, "endRestoreFile_SERVICE state = %d\n", state);
218 context->current_node = parent;