1 /*
2 Bacula(R) - The Network Backup Solution
3
4 Copyright (C) 2000-2018 Kern Sibbald
5
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.
8
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.
13
14 This notice must be preserved when any source code is
15 conveyed and/or propagated.
16
17 Bacula(R) is a registered trademark of Kern Sibbald.
18 */
19 /*
20 * Written by James Harper, October 2008
21 */
22
23 #include "exchange-fd.h"
24
root_node_t(char * name)25 root_node_t::root_node_t(char *name) : node_t(name, NODE_TYPE_ROOT)
26 {
27 service_node = NULL;
28 }
29
~root_node_t()30 root_node_t::~root_node_t()
31 {
32 }
33
34 bRC
startBackupFile(exchange_fd_context_t * context,struct save_pkt * sp)35 root_node_t::startBackupFile(exchange_fd_context_t *context, struct save_pkt *sp)
36 {
37 bRC retval = bRC_OK;
38 time_t now;
39
40 _DebugMessage(100, "startBackupNode_ROOT state = %d\n", state);
41 switch(state)
42 {
43 case 0:
44 if (strcmp(PLUGIN_PATH_PREFIX_BASE, name) != 0)
45 {
46 _JobMessage(M_FATAL, "Invalid backup path specified, must start with '/" PLUGIN_PATH_PREFIX_BASE "/'\n");
47 state = 999;
48 return bRC_Error;
49 }
50 // check that service_node == NULL
51 service_node = new service_node_t(bstrdup(context->path_bits[level + 1]), this);
52 state = 1;
53 // fall through
54 case 1:
55 context->current_node = service_node;
56 break;
57 case 2:
58 now = time(NULL);
59 sp->fname = full_path;
60 sp->link = full_path;
61 sp->statp.st_mode = 0700 | S_IFDIR;
62 sp->statp.st_ctime = now;
63 sp->statp.st_mtime = now;
64 sp->statp.st_atime = now;
65 sp->statp.st_size = 0;
66 sp->type = FT_DIREND;
67 break;
68 case 999:
69 return bRC_Error;
70 default:
71 _JobMessage(M_FATAL, "startBackupFile: invalid internal state %d", state);
72 state = 999;
73 }
74 return retval;
75 }
76
77 bRC
endBackupFile(exchange_fd_context_t * context)78 root_node_t::endBackupFile(exchange_fd_context_t *context)
79 {
80 bRC retval = bRC_OK;
81
82 _DebugMessage(100, "endBackupNode_ROOT state = %d\n", state);
83 switch(state)
84 {
85 case 1:
86 state = 2;
87 retval = bRC_More;
88 // free service_node here?
89 break;
90 case 2:
91 retval = bRC_OK;
92 break;
93 case 999:
94 retval = bRC_Error;
95 default:
96 _JobMessage(M_FATAL, "endBackupFile: invalid internal state %d", state);
97 state = 999;
98 return bRC_Error;
99 }
100 return retval;
101 }
102
103 bRC
createFile(exchange_fd_context_t * context,struct restore_pkt * rp)104 root_node_t::createFile(exchange_fd_context_t *context, struct restore_pkt *rp)
105 {
106 _DebugMessage(100, "createFile_ROOT state = %d\n", state);
107 switch (state) {
108 case 0:
109 if (strcmp(name, PLUGIN_PATH_PREFIX_BASE) != 0) {
110 _JobMessage(M_FATAL, "Invalid restore path specified, must start with '/" PLUGIN_PATH_PREFIX_BASE "/'\n");
111 state = 999;
112 return bRC_Error;
113 }
114 service_node = new service_node_t(bstrdup(context->path_bits[level + 1]), this);
115 context->current_node = service_node;
116 return bRC_OK;
117 case 1:
118 rp->create_status = CF_CREATED;
119 return bRC_OK;
120
121 /* Skip this file */
122 case 900:
123 rp->create_status = CF_SKIP;
124 return bRC_OK;
125 /* Error */
126 case 999:
127 return bRC_Error;
128 default:
129 _JobMessage(M_FATAL, "createFile: invalid internal state %d", state);
130 state = 999;
131 }
132 return bRC_Error;
133 }
134
135 bRC
endRestoreFile(exchange_fd_context_t * context)136 root_node_t::endRestoreFile(exchange_fd_context_t *context)
137 {
138 _DebugMessage(100, "endRestoreFile_ROOT state = %d\n", state);
139 switch (state) {
140 case 0:
141 delete service_node;
142 state = 1;
143 return bRC_OK;
144 case 1:
145 return bRC_OK;
146 case 900:
147 return bRC_OK;
148 default:
149 _JobMessage(M_FATAL, "endRestore: invalid internal state %d", state);
150 state = 999;
151 }
152 return bRC_Error;
153 }
154