2 Bacula(R) - The Network Backup Solution
4 Copyright (C) 2000-2017 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.
21 * Kern Sibbald, January MM
25 /* Used for certain keyword tables */
31 struct RES_ITEM; /* Declare forward referenced structure */
33 struct RES_ITEM2; /* Declare forward referenced structure */
34 class RES; /* Declare forward referenced structure */
35 struct HPKT; /* Declare forward referenced structure */
36 typedef void (RES_HANDLER)(HPKT &hpkt);
37 typedef void (MSG_RES_HANDLER)(LEX *lc, RES_ITEM *item, int index, int pass);
38 /* The INC_RES handler has an extra argument */
39 typedef void (INC_RES_HANDLER)(LEX *lc, RES_ITEM2 *item, int index, int pass, bool exclude);
41 /* This is the structure that defines
42 * the record types (items) permitted within each
43 * resource. It is used to define the configuration
47 const char *name; /* Resource name i.e. Director, ... */
48 MSG_RES_HANDLER *handler; /* Routine storing the resource item */
50 char **value; /* Where to store the item */
61 int32_t code; /* item code/additional info */
62 uint32_t flags; /* flags: default, required, ... */
63 int32_t default_value; /* default value */
67 * This handler takes only the RPKT as an argument
70 const char *name; /* Resource name i.e. Director, ... */
71 RES_HANDLER *handler; /* Routine storing/displaying the resource */
73 char **value; /* Where to store the item */
84 int32_t code; /* item code/additional info */
85 uint32_t flags; /* flags: default, required, ... */
86 int32_t default_value; /* default value */
89 /* INC_RES_HANDLER has exclude argument */
91 const char *name; /* Resource name i.e. Director, ... */
92 INC_RES_HANDLER *handler; /* Routine storing the resource item */
94 char **value; /* Where to store the item */
105 int32_t code; /* item code/additional info */
106 uint32_t flags; /* flags: default, required, ... */
107 int32_t default_value; /* default value */
111 /* For storing name_addr items in res_items table */
112 #define ITEM(x) {(char **)&res_all.x}
114 #define MAX_RES_ITEMS 100 /* maximum resource items per RES */
118 rblist *res_list; /* Resource list */
119 RES *first; /* First RES item in list */
120 RES *last; /* Last RES item inserted */
124 * This is the universal header that is
125 * at the beginning of every resource
130 rblink link; /* red-black link */
131 RES *res_next; /* pointer to next resource of this type */
132 char *name; /* resource name */
133 char *desc; /* resource description */
134 uint32_t rcode; /* resource id or type */
135 int32_t refcnt; /* reference count for releasing */
136 char item_present[MAX_RES_ITEMS]; /* set if item is present in conf file */
141 * Master Resource configuration structure definition
142 * This is the structure that defines the
143 * resources that are available to this daemon.
146 const char *name; /* resource name */
147 RES_ITEM *items; /* list of resource keywords */
148 uint32_t rcode; /* code if needed */
151 /* Common Resource definitions */
153 #define MAX_RES_NAME_LENGTH MAX_NAME_LENGTH-1 /* maximum resource name length */
155 /* Permitted bits in Flags field */
156 #define ITEM_REQUIRED (1<<0) /* item required */
157 #define ITEM_DEFAULT (1<<1) /* default supplied */
158 #define ITEM_NO_EQUALS (1<<2) /* Don't scan = after name */
159 #define ITEM_LAST (1<<3) /* Last item in list */
160 #define ITEM_ALLOW_DUPS (1<<4) /* Allow duplicate directives */
162 /* Message Resource */
166 char *mail_cmd; /* mail command */
167 char *operator_cmd; /* Operator command */
168 DEST *dest_chain; /* chain of destinations */
169 char send_msg[nbytes_for_bits(M_MAX+1)]; /* bit array of types */
172 bool m_in_use; /* set when using to send a message */
173 bool m_closing; /* set when closing message resource */
178 void clear_in_use() { lock(); m_in_use=false; unlock(); }
179 void set_in_use() { wait_not_in_use(); m_in_use=true; unlock(); }
180 void set_closing() { m_closing=true; }
181 bool get_closing() { return m_closing; }
182 void clear_closing() { lock(); m_closing=false; unlock(); }
183 bool is_closing() { lock(); bool rtn=m_closing; unlock(); return rtn; }
185 void wait_not_in_use(); /* in message.c */
186 void lock(); /* in message.c */
187 void unlock(); /* in message.c */
190 inline char *MSGS::name() const { return hdr.name; }
193 * New C++ configuration routines
196 class CONFIG: public SMARTALLOC {
198 const char *m_cf; /* config file */
199 LEX_ERROR_HANDLER *m_scan_error; /* error handler if non-null */
200 int32_t m_err_type; /* the way to terminate on failure */
201 void *m_res_all; /* pointer to res_all buffer */
202 int32_t m_res_all_size; /* length of buffer */
203 bool m_encode_pass; /* Encode passwords with MD5 or not */
205 /* The below are not yet implemented */
206 int32_t m_r_first; /* first daemon resource type */
207 int32_t m_r_last; /* last daemon resource type */
208 RES_TABLE *m_resources; /* pointer to table of permitted resources */
209 RES_HEAD **m_res_head; /* pointer to list of resources this type */
210 brwlock_t m_res_lock; /* resource lock */
216 LEX_ERROR_HANDLER *scan_error,
219 int32_t res_all_size,
222 RES_TABLE *resources,
223 RES_HEAD ***res_head);
227 void encode_password(bool encode);
229 void free_all_resources();
230 bool insert_res(int rindex, int size);
231 RES_HEAD **save_resources();
232 RES_HEAD **new_res_head();
233 void init_res_head(RES_HEAD ***rhead, int32_t first, int32_t last);
236 /* Resource routines */
237 int res_compare(void *item1, void *item2);
238 RES *GetResWithName(int rcode, const char *name);
239 RES *GetNextRes(int rcode, RES *res);
240 RES *GetNextRes(RES_HEAD **rhead, int rcode, RES *res);
241 void b_LockRes(const char *file, int line);
242 void b_UnlockRes(const char *file, int line);
243 void dump_resource(int type, RES *res, void sendmsg(void *sock, const char *fmt, ...), void *sock);
244 void dump_each_resource(int type, void sendmsg(void *sock, const char *fmt, ...), void *sock);
245 void free_resource(RES *res, int type);
246 bool init_resource(CONFIG *config, uint32_t type, void *res);
247 bool save_resource(CONFIG *config, int type, RES_ITEM *item, int pass);
248 void unstrip_password(RES_TABLE *resources); /* Used for json stuff */
249 void strip_password(RES_TABLE *resources); /* Used for tray monitor */
250 const char *res_to_str(int rcode);
251 bool find_config_file(const char *config_file, char *full_path, int max_path);
253 /* Loop through each resource of type, returning in var */
255 #define foreach_res(var, type) \
256 for((var)=NULL; ((var)=(typeof(var))GetNextRes((type), (RES *)var));)
258 #define foreach_res(var, type) \
259 for(var=NULL; (*((void **)&(var))=(void *)GetNextRes((type), (RES *)var));)
264 * Standard global parsers defined in parse_config.c
266 void store_str(LEX *lc, RES_ITEM *item, int index, int pass);
267 void store_dir(LEX *lc, RES_ITEM *item, int index, int pass);
268 void store_clear_password(LEX *lc, RES_ITEM *item, int index, int pass);
269 void store_password(LEX *lc, RES_ITEM *item, int index, int pass);
270 void store_name(LEX *lc, RES_ITEM *item, int index, int pass);
271 void store_strname(LEX *lc, RES_ITEM *item, int index, int pass);
272 void store_res(LEX *lc, RES_ITEM *item, int index, int pass);
273 void store_alist_res(LEX *lc, RES_ITEM *item, int index, int pass);
274 void store_alist_str(LEX *lc, RES_ITEM *item, int index, int pass);
275 void store_int32(LEX *lc, RES_ITEM *item, int index, int pass);
276 void store_pint32(LEX *lc, RES_ITEM *item, int index, int pass);
277 void store_msgs(LEX *lc, RES_ITEM *item, int index, int pass);
278 void store_int64(LEX *lc, RES_ITEM *item, int index, int pass);
279 void store_bit(LEX *lc, RES_ITEM *item, int index, int pass);
280 void store_bool(LEX *lc, RES_ITEM *item, int index, int pass);
281 void store_time(LEX *lc, RES_ITEM *item, int index, int pass);
282 void store_size64(LEX *lc, RES_ITEM *item, int index, int pass);
283 void store_size32(LEX *lc, RES_ITEM *item, int index, int pass);
284 void store_speed(LEX *lc, RES_ITEM *item, int index, int pass);
285 void store_defs(LEX *lc, RES_ITEM *item, int index, int pass);
286 void store_label(LEX *lc, RES_ITEM *item, int index, int pass);
288 /* ***FIXME*** eliminate these globals */
289 extern int32_t r_first;
290 extern int32_t r_last;
291 extern RES_TABLE resources[];
292 extern RES_HEAD **res_head;
293 extern int32_t res_all_size;