2 Bacula® - The Network Backup Solution
4 Copyright (C) 2008-2008 Free Software Foundation Europe e.V.
6 The main author of Bacula is Kern Sibbald, with contributions from
7 many others, a complete list can be found in the file AUTHORS.
8 This program is Free Software; you can redistribute it and/or
9 modify it under the terms of version two of the GNU General Public
10 License as published by the Free Software Foundation, which is
11 listed in the file LICENSE.
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 General Public License for more details.
18 You should have received a copy of the GNU 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
23 Bacula® is a registered trademark of Kern Sibbald.
24 The licensor of Bacula is the Free Software Foundation Europe
25 (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
26 Switzerland, email:ftf@fsfeurope.org.
29 * Written by James Harper, October 2008
32 #include "exchange-fd.h"
34 service_node_t::service_node_t(char *name, node_t *parent_node) : node_t(name, NODE_TYPE_SERVICE, parent_node)
40 first_storage_group_node = NULL;
43 service_node_t::~service_node_t()
48 service_node_t::startBackupFile(exchange_fd_context_t *context, struct save_pkt *sp)
52 _DebugMessage(100, "startBackupNode_SERVICE state = %d\n", state);
56 if (strcmp(PLUGIN_PATH_PREFIX_SERVICE, name) != 0)
58 _JobMessage(M_ERROR, "Invalid restore path specified, must start with /" PLUGIN_PATH_PREFIX_BASE "/" PLUGIN_PATH_PREFIX_SERVICE "/\n");
61 // convert name to a wide string
63 _DebugMessage(100, "Calling HrESEBackupPrepare\n");
64 result = HrESEBackupPrepare(context->computer_name, PLUGIN_PATH_PREFIX_SERVICE_W, &ibi_count, &ibi, &hccx);
67 _JobMessage(M_ERROR, "HrESEBackupPrepare failed with error 0x%08x - %s\n", result, ESEErrorMessage(result));
73 if (context->path_bits[level + 1] == NULL)
75 _DebugMessage(100, "No specific storage group specified - backing them all up\n");
76 char *tmp = new char[wcslen(ibi[current_ibi].wszInstanceName) + 1];
77 wcstombs(tmp, ibi[current_ibi].wszInstanceName, wcslen(ibi[current_ibi].wszInstanceName) + 1);
78 first_storage_group_node = new storage_group_node_t(tmp, this);
80 _DebugMessage(100, "storage group name = %s\n", first_storage_group_node->name);
81 first_storage_group_node->ibi = &ibi[current_ibi];
82 first_storage_group_node->hccx = hccx;
83 context->current_node = first_storage_group_node;
88 for (current_ibi = 0; current_ibi < ibi_count; current_ibi++)
90 tmp = new char[wcslen(ibi[current_ibi].wszInstanceName) + 1];
91 wcstombs(tmp, ibi[current_ibi].wszInstanceName, wcslen(ibi[current_ibi].wszInstanceName) + 1);
92 if (stricmp(tmp, context->path_bits[level + 1]) == 0)
95 first_storage_group_node = new storage_group_node_t(tmp, this);
97 if (current_ibi == ibi_count)
99 _JobMessage(M_ERROR, "Invalid Storage Group '%s'\n", context->path_bits[level + 1]);
102 _DebugMessage(100, "storage group name = %s\n", first_storage_group_node->name);
103 first_storage_group_node->ibi = &ibi[current_ibi];
104 first_storage_group_node->hccx = hccx;
105 context->current_node = first_storage_group_node;
109 time_t now = time(NULL);
110 sp->fname = full_path;
111 sp->link = full_path;
112 sp->statp.st_mode = 0700 | S_IFDIR;
113 sp->statp.st_ctime = now;
114 sp->statp.st_mtime = now;
115 sp->statp.st_atime = now;
116 sp->statp.st_size = 0;
117 sp->statp.st_nlink = 1;
118 //sp->statp.st_blocks = 0;
119 sp->type = FT_DIREND;
122 _DebugMessage(100, "ending startBackupNode_SERVICE state = %d\n", state);
127 service_node_t::endBackupFile(exchange_fd_context_t *context)
132 _DebugMessage(100, "endBackupNode_SERVICE state = %d\n", state);
136 // should never happen
139 // free node->storage_group_node
140 if (context->path_bits[level + 1] == NULL)
143 if (current_ibi == ibi_count)
151 _DebugMessage(100, "calling HrESEBackupEnd\n");
152 result = HrESEBackupEnd(hccx);
155 _JobMessage(M_ERROR, "HrESEBackupEnd failed with error 0x%08x - %s\n", result, ESEErrorMessage(result));
159 context->current_node = parent;
167 service_node_t::createFile(exchange_fd_context_t *context, struct restore_pkt *rp)
169 storage_group_node_t *curr_sg, *prev_sg;
171 _DebugMessage(0, "createFile_SERVICE state = %d\n", state);
172 if (strcmp(name, "Microsoft Information Store") != 0)
174 _JobMessage(M_ERROR, "Invalid restore path specified, must start with '/" PLUGIN_PATH_PREFIX_BASE "/" PLUGIN_PATH_PREFIX_SERVICE "/'\n", state);
182 if (context->path_bits[level + 1] == NULL)
187 for (prev_sg = NULL, curr_sg = first_storage_group_node; curr_sg != NULL; prev_sg = curr_sg, curr_sg = curr_sg->next)
189 if (strcmp(curr_sg->name, context->path_bits[level + 1]) == 0)
196 curr_sg = new storage_group_node_t(bstrdup(context->path_bits[level + 1]), this);
198 first_storage_group_node = curr_sg;
200 prev_sg->next = curr_sg;
202 context->current_node = curr_sg;
205 rp->create_status = CF_CREATED;
213 service_node_t::endRestoreFile(exchange_fd_context_t *context)
215 _DebugMessage(0, "endRestoreFile_SERVICE state = %d\n", state);
221 context->current_node = parent;