1 /*
2    BAREOS® - Backup Archiving REcovery Open Sourced
3 
4    Copyright (C) 2007-2011 Free Software Foundation Europe e.V.
5    Copyright (C) 2011-2012 Planets Communications B.V.
6    Copyright (C) 2013-2016 Bareos GmbH & Co. KG
7 
8    This program is Free Software; you can redistribute it and/or
9    modify it under the terms of version three of the GNU Affero General Public
10    License as published by the Free Software Foundation, which is
11    listed in the file LICENSE.
12 
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    Affero General Public License for more details.
17 
18    You should have received a copy of the GNU Affero 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
21    02110-1301, USA.
22 */
23 /*
24  * Kern Sibbald, October 2007
25  */
26 /**
27  * Interface definition for Bareos SD Plugins
28  */
29 
30 #ifndef BAREOS_STORED_SD_PLUGINS_H_
31 #define BAREOS_STORED_SD_PLUGINS_H_
32 
33 #ifndef BAREOS_INCLUDE_BAREOS_H_
34 #ifdef __cplusplus
35 /* Workaround for SGI IRIX 6.5 */
36 #define _LANGUAGE_C_PLUS_PLUS 1
37 #endif
38 #define _REENTRANT 1
39 #define _THREAD_SAFE 1
40 #define _POSIX_PTHREAD_SEMANTICS 1
41 #define _FILE_OFFSET_BITS 64
42 #define _LARGEFILE_SOURCE 1
43 #define _LARGE_FILES 1
44 #endif
45 
46 #include <sys/types.h>
47 #include "include/hostconfig.h"
48 #include "include/bc_types.h"
49 #include "lib/plugins.h"
50 
51 class alist;
52 
53 namespace storagedaemon {
54 
55 /*
56  * Bareos definitions
57  */
58 
59 /**
60  * Bareos Variable Ids (Read)
61  */
62 typedef enum
63 {
64   bsdVarJob = 1,
65   bsdVarLevel = 2,
66   bsdVarType = 3,
67   bsdVarJobId = 4,
68   bsdVarClient = 5,
69   bsdVarPool = 6,
70   bsdVarPoolType = 7,
71   bsdVarStorage = 8,
72   bsdVarMediaType = 9,
73   bsdVarJobName = 10,
74   bsdVarJobStatus = 11,
75   bsdVarVolumeName = 12,
76   bsdVarJobErrors = 13,
77   bsdVarJobFiles = 14,
78   bsdVarJobBytes = 15,
79   bsdVarCompatible = 16,
80   bsdVarPluginDir = 17
81 } bsdrVariable;
82 
83 /**
84  * Bareos Variable Ids (Write)
85  */
86 typedef enum
87 {
88   bsdwVarJobReport = 1,
89   bsdwVarVolumeName = 2,
90   bsdwVarPriority = 3,
91   bsdwVarJobLevel = 4
92 } bsdwVariable;
93 
94 /**
95  * Events that are passed to plugin
96  */
97 typedef enum
98 {
99   bsdEventJobStart = 1,
100   bsdEventJobEnd = 2,
101   bsdEventDeviceInit = 3,
102   bsdEventDeviceMount = 4,
103   bsdEventVolumeLoad = 5,
104   bsdEventDeviceReserve = 6,
105   bsdEventDeviceOpen = 7,
106   bsdEventLabelRead = 8,
107   bsdEventLabelVerified = 9,
108   bsdEventLabelWrite = 10,
109   bsdEventDeviceClose = 11,
110   bsdEventVolumeUnload = 12,
111   bsdEventDeviceUnmount = 13,
112   bsdEventReadError = 14,
113   bsdEventWriteError = 15,
114   bsdEventDriveStatus = 16,
115   bsdEventVolumeStatus = 17,
116   bsdEventSetupRecordTranslation = 18,
117   bsdEventReadRecordTranslation = 19,
118   bsdEventWriteRecordTranslation = 20,
119   bsdEventDeviceRelease = 21,
120   bsdEventNewPluginOptions = 22,
121   bsdEventChangerLock = 23,
122   bsdEventChangerUnlock = 24
123 } bsdEventType;
124 
125 #define SD_NR_EVENTS bsdEventChangerUnlock /**< keep this updated ! */
126 
127 typedef struct s_bsdEvent {
128   uint32_t eventType;
129 } bsdEvent;
130 
131 typedef struct s_sdbareosInfo {
132   uint32_t size;
133   uint32_t version;
134 } bsdInfo;
135 
136 #ifdef __cplusplus
137 extern "C" {
138 #endif
139 
140 /**
141  * Bareos interface version and function pointers
142  */
143 class DeviceControlRecord;
144 struct DeviceRecord;
145 
146 typedef struct s_sdbareosFuncs {
147   uint32_t size;
148   uint32_t version;
149   bRC (*registerBareosEvents)(bpContext* ctx, int nr_events, ...);
150   bRC (*unregisterBareosEvents)(bpContext* ctx, int nr_events, ...);
151   bRC (*getInstanceCount)(bpContext* ctx, int* ret);
152   bRC (*getBareosValue)(bpContext* ctx, bsdrVariable var, void* value);
153   bRC (*setBareosValue)(bpContext* ctx, bsdwVariable var, void* value);
154   bRC (*JobMessage)(bpContext* ctx,
155                     const char* file,
156                     int line,
157                     int type,
158                     utime_t mtime,
159                     const char* fmt,
160                     ...);
161   bRC (*DebugMessage)(bpContext* ctx,
162                       const char* file,
163                       int line,
164                       int level,
165                       const char* fmt,
166                       ...);
167   char* (*EditDeviceCodes)(DeviceControlRecord* dcr,
168                            POOLMEM*& omsg,
169                            const char* imsg,
170                            const char* cmd);
171   char* (*LookupCryptoKey)(const char* VolumeName);
172   bool (*UpdateVolumeInfo)(DeviceControlRecord* dcr);
173   void (*UpdateTapeAlert)(DeviceControlRecord* dcr, uint64_t flags);
174   DeviceRecord* (*new_record)(bool with_data);
175   void (*CopyRecordState)(DeviceRecord* dst, DeviceRecord* src);
176   void (*FreeRecord)(DeviceRecord* rec);
177 } bsdFuncs;
178 
179 /*
180  * Bareos Core Routines -- not used within a plugin
181  */
182 #ifdef STORAGE_DAEMON
183 void LoadSdPlugins(const char* plugin_dir, alist* plugin_names);
184 void UnloadSdPlugins(void);
185 int ListSdPlugins(PoolMem& msg);
186 void DispatchNewPluginOptions(JobControlRecord* jcr);
187 void NewPlugins(JobControlRecord* jcr);
188 void FreePlugins(JobControlRecord* jcr);
189 bRC GeneratePluginEvent(JobControlRecord* jcr,
190                         bsdEventType event,
191                         void* value = NULL,
192                         bool reverse = false);
193 #endif
194 
195 /*
196  * Plugin definitions
197  */
198 
199 typedef enum
200 {
201   psdVarName = 1,
202   psdVarDescription = 2
203 } psdVariable;
204 
205 #define SD_PLUGIN_MAGIC "*SDPluginData*"
206 #define SD_PLUGIN_INTERFACE_VERSION 4
207 
208 /*
209  * Functions that must be defined in every plugin
210  */
211 typedef struct s_sdpluginFuncs {
212   uint32_t size;
213   uint32_t version;
214   bRC (*newPlugin)(bpContext* ctx);
215   bRC (*freePlugin)(bpContext* ctx);
216   bRC (*getPluginValue)(bpContext* ctx, psdVariable var, void* value);
217   bRC (*setPluginValue)(bpContext* ctx, psdVariable var, void* value);
218   bRC (*handlePluginEvent)(bpContext* ctx, bsdEvent* event, void* value);
219 } psdFuncs;
220 
221 #define SdplugFunc(plugin) ((psdFuncs*)(plugin->pfuncs))
222 #define sdplug_info(plugin) ((genpInfo*)(plugin->pinfo))
223 
224 #ifdef __cplusplus
225 }
226 #endif
227 
228 char* edit_device_codes(DeviceControlRecord* dcr,
229                         POOLMEM*& omsg,
230                         const char* imsg,
231                         const char* cmd);
232 
233 } /* namespace storagedaemon */
234 
235 #endif /* BAREOS_STORED_SD_PLUGINS_H_ */
236