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 namespace storagedaemon {
52 
53 /*
54  * Bareos definitions
55  */
56 
57 /**
58  * Bareos Variable Ids (Read)
59  */
60 typedef enum {
61    bsdVarJob = 1,
62    bsdVarLevel = 2,
63    bsdVarType = 3,
64    bsdVarJobId = 4,
65    bsdVarClient = 5,
66    bsdVarPool = 6,
67    bsdVarPoolType = 7,
68    bsdVarStorage = 8,
69    bsdVarMediaType = 9,
70    bsdVarJobName = 10,
71    bsdVarJobStatus = 11,
72    bsdVarVolumeName = 12,
73    bsdVarJobErrors = 13,
74    bsdVarJobFiles = 14,
75    bsdVarJobBytes = 15,
76    bsdVarCompatible = 16,
77    bsdVarPluginDir = 17
78 } bsdrVariable;
79 
80 /**
81  * Bareos Variable Ids (Write)
82  */
83 typedef enum {
84    bsdwVarJobReport = 1,
85    bsdwVarVolumeName = 2,
86    bsdwVarPriority = 3,
87    bsdwVarJobLevel = 4
88 } bsdwVariable;
89 
90 /**
91  * Events that are passed to plugin
92  */
93 typedef enum {
94    bsdEventJobStart = 1,
95    bsdEventJobEnd = 2,
96    bsdEventDeviceInit = 3,
97    bsdEventDeviceMount = 4,
98    bsdEventVolumeLoad = 5,
99    bsdEventDeviceReserve = 6,
100    bsdEventDeviceOpen = 7,
101    bsdEventLabelRead = 8,
102    bsdEventLabelVerified = 9,
103    bsdEventLabelWrite = 10,
104    bsdEventDeviceClose = 11,
105    bsdEventVolumeUnload = 12,
106    bsdEventDeviceUnmount = 13,
107    bsdEventReadError = 14,
108    bsdEventWriteError = 15,
109    bsdEventDriveStatus = 16,
110    bsdEventVolumeStatus = 17,
111    bsdEventSetupRecordTranslation = 18,
112    bsdEventReadRecordTranslation = 19,
113    bsdEventWriteRecordTranslation = 20,
114    bsdEventDeviceRelease = 21,
115    bsdEventNewPluginOptions = 22,
116    bsdEventChangerLock = 23,
117    bsdEventChangerUnlock = 24
118 } bsdEventType;
119 
120 #define SD_NR_EVENTS bsdEventChangerUnlock /**< keep this updated ! */
121 
122 typedef struct s_bsdEvent {
123    uint32_t eventType;
124 } bsdEvent;
125 
126 typedef struct s_sdbareosInfo {
127    uint32_t size;
128    uint32_t version;
129 } bsdInfo;
130 
131 #ifdef __cplusplus
132 extern "C" {
133 #endif
134 
135 /**
136  * Bareos interface version and function pointers
137  */
138 class DeviceControlRecord;
139 struct DeviceRecord;
140 
141 typedef struct s_sdbareosFuncs {
142    uint32_t size;
143    uint32_t version;
144    bRC (*registerBareosEvents)(bpContext *ctx, int nr_events, ...);
145    bRC (*unregisterBareosEvents)(bpContext *ctx, int nr_events, ...);
146    bRC (*getInstanceCount)(bpContext *ctx, int *ret);
147    bRC (*getBareosValue)(bpContext *ctx, bsdrVariable var, void *value);
148    bRC (*setBareosValue)(bpContext *ctx, bsdwVariable var, void *value);
149    bRC (*JobMessage)(bpContext *ctx, const char *file, int line,
150                      int type, utime_t mtime, const char *fmt, ...);
151    bRC (*DebugMessage)(bpContext *ctx, const char *file, int line,
152                        int level, const char *fmt, ...);
153    char *(*EditDeviceCodes)(DeviceControlRecord *dcr, POOLMEM *&omsg,
154                             const char *imsg, const char *cmd);
155    char *(*LookupCryptoKey)(const char *VolumeName);
156    bool (*UpdateVolumeInfo)(DeviceControlRecord *dcr);
157    void (*UpdateTapeAlert)(DeviceControlRecord *dcr, uint64_t flags);
158    DeviceRecord *(*new_record)(bool with_data);
159    void (*CopyRecordState)(DeviceRecord *dst, DeviceRecord *src);
160    void (*FreeRecord)(DeviceRecord *rec);
161 } bsdFuncs;
162 
163 /*
164  * Bareos Core Routines -- not used within a plugin
165  */
166 #ifdef STORAGE_DAEMON
167 void LoadSdPlugins(const char *plugin_dir, alist *plugin_names);
168 void UnloadSdPlugins(void);
169 int ListSdPlugins(PoolMem &msg);
170 void DispatchNewPluginOptions(JobControlRecord *jcr);
171 void NewPlugins(JobControlRecord *jcr);
172 void FreePlugins(JobControlRecord *jcr);
173 bRC GeneratePluginEvent(JobControlRecord *jcr, bsdEventType event,
174                           void *value = NULL, bool reverse = false);
175 #endif
176 
177 /*
178  * Plugin definitions
179  */
180 
181 typedef enum {
182   psdVarName = 1,
183   psdVarDescription = 2
184 } psdVariable;
185 
186 #define SD_PLUGIN_MAGIC     "*SDPluginData*"
187 #define SD_PLUGIN_INTERFACE_VERSION  4
188 
189 /*
190  * Functions that must be defined in every plugin
191  */
192 typedef struct s_sdpluginFuncs {
193    uint32_t size;
194    uint32_t version;
195    bRC (*newPlugin)(bpContext *ctx);
196    bRC (*freePlugin)(bpContext *ctx);
197    bRC (*getPluginValue)(bpContext *ctx, psdVariable var, void *value);
198    bRC (*setPluginValue)(bpContext *ctx, psdVariable var, void *value);
199    bRC (*handlePluginEvent)(bpContext *ctx, bsdEvent *event, void *value);
200 } psdFuncs;
201 
202 #define SdplugFunc(plugin) ((psdFuncs *)(plugin->pfuncs))
203 #define sdplug_info(plugin) ((genpInfo *)(plugin->pinfo))
204 
205 #ifdef __cplusplus
206 }
207 #endif
208 
209 char *edit_device_codes(DeviceControlRecord *dcr, POOLMEM *&omsg, const char *imsg, const char *cmd);
210 
211 } /* namespace storagedaemon */
212 
213 #endif /* BAREOS_STORED_SD_PLUGINS_H_ */
214