]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/dird/dird_conf.h
ebl fix nasty runscript configuration parsing bug
[bacula/bacula] / bacula / src / dird / dird_conf.h
1 /*
2  * Director specific configuration and defines
3  *
4  *     Kern Sibbald, Feb MM
5  *
6  *    Version $Id$
7  */
8 /*
9    Bacula® - The Network Backup Solution
10
11    Copyright (C) 2000-2006 Free Software Foundation Europe e.V.
12
13    The main author of Bacula is Kern Sibbald, with contributions from
14    many others, a complete list can be found in the file AUTHORS.
15    This program is Free Software; you can redistribute it and/or
16    modify it under the terms of version two of the GNU General Public
17    License as published by the Free Software Foundation plus additions
18    that are listed in the file LICENSE.
19
20    This program is distributed in the hope that it will be useful, but
21    WITHOUT ANY WARRANTY; without even the implied warranty of
22    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23    General Public License for more details.
24
25    You should have received a copy of the GNU General Public License
26    along with this program; if not, write to the Free Software
27    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
28    02110-1301, USA.
29
30    Bacula® is a registered trademark of John Walker.
31    The licensor of Bacula is the Free Software Foundation Europe
32    (FSFE), Fiduciary Program, Sumatrastrasse 25, 8006 Zürich,
33    Switzerland, email:ftf@fsfeurope.org.
34 */
35
36 /* NOTE:  #includes at the end of this file */
37
38 /*
39  * Resource codes -- they must be sequential for indexing
40  */
41 enum {
42    R_DIRECTOR = 1001,
43    R_CLIENT,
44    R_JOB,
45    R_STORAGE,
46    R_CATALOG,
47    R_SCHEDULE,
48    R_FILESET,
49    R_POOL,
50    R_MSGS,
51    R_COUNTER,
52    R_CONSOLE,
53    R_JOBDEFS,
54    R_DEVICE,
55    R_FIRST = R_DIRECTOR,
56    R_LAST  = R_DEVICE                 /* keep this updated */
57 };
58
59
60 /*
61  * Some resource attributes
62  */
63 enum {
64    R_NAME = 1020,
65    R_ADDRESS,
66    R_PASSWORD,
67    R_TYPE,
68    R_BACKUP
69 };
70
71
72 /* Used for certain KeyWord tables */
73 struct s_kw {
74    const char *name;
75    int token;
76 };
77
78 /* Job Level keyword structure */
79 struct s_jl {
80    const char *level_name;                  /* level keyword */
81    int  level;                        /* level */
82    int  job_type;                     /* JobType permitting this level */
83 };
84
85 /* Job Type keyword structure */
86 struct s_jt {
87    const char *type_name;
88    int job_type;
89 };
90
91 /* Definition of the contents of each Resource */
92 /* Needed for forward references */
93 class SCHED;
94 class CLIENT;
95 class FILESET;
96 class POOL;
97 class RUN;
98 class DEVICE;
99 class RUNSCRIPT;
100
101 /*
102  *   Director Resource
103  *
104  */
105 class DIRRES {
106 public:
107    RES   hdr;
108    dlist *DIRaddrs;
109    char *password;                    /* Password for UA access */
110    char *query_file;                  /* SQL query file */
111    char *working_directory;           /* WorkingDirectory */
112    const char *scripts_directory;     /* ScriptsDirectory */
113    char *pid_directory;               /* PidDirectory */
114    char *subsys_directory;            /* SubsysDirectory */
115    MSGS *messages;                    /* Daemon message handler */
116    uint32_t MaxConcurrentJobs;        /* Max concurrent jobs for whole director */
117    utime_t FDConnectTimeout;          /* timeout for connect in seconds */
118    utime_t SDConnectTimeout;          /* timeout in seconds */
119    char *tls_ca_certfile;             /* TLS CA Certificate File */
120    char *tls_ca_certdir;              /* TLS CA Certificate Directory */
121    char *tls_certfile;                /* TLS Server Certificate File */
122    char *tls_keyfile;                 /* TLS Server Key File */
123    char *tls_dhfile;                  /* TLS Diffie-Hellman Parameters */
124    alist *tls_allowed_cns;            /* TLS Allowed Clients */
125    TLS_CONTEXT *tls_ctx;              /* Shared TLS Context */
126    bool tls_enable;                   /* Enable TLS */
127    bool tls_require;                  /* Require TLS */
128    bool tls_verify_peer;              /* TLS Verify Client Certificate */
129
130    /* Methods */
131    char *name() const;
132 };
133
134 inline char *DIRRES::name() const { return hdr.name; }
135
136 /*
137  * Device Resource
138  *  This resource is a bit different from the other resources
139  *  because it is not defined in the Director 
140  *  by DEVICE { ... }, but rather by a "reference" such as
141  *  DEVICE = xxx; Then when the Director connects to the
142  *  SD, it requests the information about the device.
143  */
144 class DEVICE {
145 public:
146    RES hdr;
147
148    bool found;                        /* found with SD */
149    int num_writers;                   /* number of writers */
150    int max_writers;                   /* = 1 for files */
151    int reserved;                      /* number of reserves */
152    int num_drives;                    /* for autochanger */
153    bool autochanger;                  /* set if device is autochanger */
154    bool open;                         /* drive open */
155    bool append;                       /* in append mode */
156    bool read;                         /* in read mode */
157    bool labeled;                      /* Volume name valid */
158    bool offline;                      /* not available */
159    bool autoselect;                   /* can be selected via autochanger */
160    uint32_t PoolId;
161    char ChangerName[MAX_NAME_LENGTH];
162    char VolumeName[MAX_NAME_LENGTH];
163    char MediaType[MAX_NAME_LENGTH];
164
165    /* Methods */
166    char *name() const;
167 };
168
169 inline char *DEVICE::name() const { return hdr.name; }
170
171 /*
172  * Console ACL positions
173  */
174 enum {
175    Job_ACL = 0,
176    Client_ACL,
177    Storage_ACL,
178    Schedule_ACL,
179    Run_ACL,
180    Pool_ACL,
181    Command_ACL,
182    FileSet_ACL,
183    Catalog_ACL,
184    Where_ACL,
185    Num_ACL                            /* keep last */
186 };
187
188 /*
189  *    Console Resource
190  */
191 class CONRES {
192 public:
193    RES   hdr;
194    char *password;                    /* UA server password */
195    alist *ACL_lists[Num_ACL];         /* pointers to ACLs */
196    char *tls_ca_certfile;             /* TLS CA Certificate File */
197    char *tls_ca_certdir;              /* TLS CA Certificate Directory */
198    char *tls_certfile;                /* TLS Server Certificate File */
199    char *tls_keyfile;                 /* TLS Server Key File */
200    char *tls_dhfile;                  /* TLS Diffie-Hellman Parameters */
201    alist *tls_allowed_cns;            /* TLS Allowed Clients */
202    TLS_CONTEXT *tls_ctx;              /* Shared TLS Context */
203    bool tls_enable;                   /* Enable TLS */
204    bool tls_require;                  /* Require TLS */
205    bool tls_verify_peer;              /* TLS Verify Client Certificate */
206
207    /* Methods */
208    char *name() const;
209 };
210
211 inline char *CONRES::name() const { return hdr.name; }
212
213
214 /*
215  *   Catalog Resource
216  *
217  */
218 class CAT {
219 public:
220    RES   hdr;
221
222    int   db_port;                     /* Port */
223    char *db_address;                  /* host name for remote access */
224    char *db_socket;                   /* Socket for local access */
225    char *db_password;
226    char *db_user;
227    char *db_name;
228    int   mult_db_connections;         /* set if multiple connections wanted */
229
230    /* Methods */
231    char *name() const;
232 };
233
234 inline char *CAT::name() const { return hdr.name; }
235
236
237 /*
238  *   Client Resource
239  *
240  */
241 class CLIENT {
242 public:
243    RES   hdr;
244
245    int   FDport;                      /* Where File daemon listens */
246    utime_t FileRetention;             /* file retention period in seconds */
247    utime_t JobRetention;              /* job retention period in seconds */
248    char *address;
249    char *password;
250    CAT *catalog;                      /* Catalog resource */
251    uint32_t MaxConcurrentJobs;        /* Maximume concurrent jobs */
252    uint32_t NumConcurrentJobs;        /* number of concurrent jobs running */
253    char *tls_ca_certfile;             /* TLS CA Certificate File */
254    char *tls_ca_certdir;              /* TLS CA Certificate Directory */
255    char *tls_certfile;                /* TLS Client Certificate File */
256    char *tls_keyfile;                 /* TLS Client Key File */
257    TLS_CONTEXT *tls_ctx;              /* Shared TLS Context */
258    bool tls_enable;                   /* Enable TLS */
259    bool tls_require;                  /* Require TLS */
260    bool AutoPrune;                    /* Do automatic pruning? */
261
262    /* Methods */
263    char *name() const;
264 };
265
266 inline char *CLIENT::name() const { return hdr.name; }
267
268
269 /*
270  *   Store Resource
271  *
272  */
273 class STORE {
274 public:
275    RES   hdr;
276
277    int   SDport;                      /* port where Directors connect */
278    int   SDDport;                     /* data port for File daemon */
279    char *address;
280    char *password;
281    char *media_type;
282    alist *device;                     /* Alternate devices for this Storage */
283    uint32_t MaxConcurrentJobs;        /* Maximume concurrent jobs */
284    uint32_t NumConcurrentJobs;        /* number of concurrent jobs running */
285    char *tls_ca_certfile;             /* TLS CA Certificate File */
286    char *tls_ca_certdir;              /* TLS CA Certificate Directory */
287    char *tls_certfile;                /* TLS Client Certificate File */
288    char *tls_keyfile;                 /* TLS Client Key File */
289    TLS_CONTEXT *tls_ctx;              /* Shared TLS Context */
290    bool tls_enable;                   /* Enable TLS */
291    bool tls_require;                  /* Require TLS */
292    bool enabled;                      /* Set if device is enabled */
293    bool  autochanger;                 /* set if autochanger */
294    int64_t StorageId;                 /* Set from Storage DB record */
295    int  drives;                       /* number of drives in autochanger */
296
297    /* Methods */
298    char *dev_name() const;
299    char *name() const;
300 };
301
302 inline char *STORE::dev_name() const
303
304    DEVICE *dev = (DEVICE *)device->first();
305    return dev->hdr.name;
306 }
307
308 inline char *STORE::name() const { return hdr.name; }
309
310 /*
311  * This is a sort of "unified" store that has both the
312  *  storage pointer and the text of where the pointer was
313  *  found.
314  */
315 class USTORE {
316 public:
317    STORE *store;
318    POOLMEM *store_source;
319
320    /* Methods */
321    USTORE() { store = NULL; store_source = get_pool_memory(PM_MESSAGE); }
322    ~USTORE() { destroy(); }   
323    void set_source(const char *where);
324    void destroy();
325 };
326
327 inline void USTORE::destroy()
328 {
329    if (store_source) {
330       free_pool_memory(store_source);
331       store_source = NULL;
332    }
333 }
334
335
336 inline void USTORE::set_source(const char *where)
337 {
338    if (!store_source) {
339       store_source = get_pool_memory(PM_MESSAGE);
340    }
341    pm_strcpy(store_source, where);
342 }
343
344
345 /*
346  *   Job Resource
347  */
348 class JOB {
349 public:
350    RES   hdr;
351
352    int   JobType;                     /* job type (backup, verify, restore */
353    int   JobLevel;                    /* default backup/verify level */
354    int   Priority;                    /* Job priority */
355    int   RestoreJobId;                /* What -- JobId to restore */
356    char *RestoreWhere;                /* Where on disk to restore -- directory */
357    char *RestoreBootstrap;            /* Bootstrap file */
358    alist *RunScripts;                 /* Run {client} program {after|before} Job */
359    union {
360       char *WriteBootstrap;           /* Where to write bootstrap Job updates */
361       char *WriteVerifyList;          /* List of changed files */
362    };
363    int   replace;                     /* How (overwrite, ..) */
364    utime_t MaxRunTime;                /* max run time in seconds */
365    utime_t MaxWaitTime;               /* max blocking time in seconds */
366    utime_t FullMaxWaitTime;           /* Max Full job wait time */
367    utime_t DiffMaxWaitTime;           /* Max Differential job wait time */
368    utime_t IncMaxWaitTime;            /* Max Incremental job wait time */
369    utime_t MaxStartDelay;             /* max start delay in seconds */
370    utime_t RescheduleInterval;        /* Reschedule interval */
371    utime_t JobRetention;              /* job retention period in seconds */
372    uint32_t MaxConcurrentJobs;        /* Maximum concurrent jobs */
373    int RescheduleTimes;               /* Number of times to reschedule job */
374    bool RescheduleOnError;            /* Set to reschedule on error */
375    bool PrefixLinks;                  /* prefix soft links with Where path */
376    bool PruneJobs;                    /* Force pruning of Jobs */
377    bool PruneFiles;                   /* Force pruning of Files */
378    bool PruneVolumes;                 /* Force pruning of Volumes */
379    bool SpoolAttributes;              /* Set to spool attributes in SD */
380    bool spool_data;                   /* Set to spool data in SD */
381    bool rerun_failed_levels;          /* Upgrade to rerun failed levels */
382    bool PreferMountedVolumes;         /* Prefer vols mounted rather than new one */
383    bool write_part_after_job;         /* Set to write part after job in SD */
384    bool enabled;                      /* Set if job enabled */
385    
386    MSGS      *messages;               /* How and where to send messages */
387    SCHED     *schedule;               /* When -- Automatic schedule */
388    CLIENT    *client;                 /* Who to backup */
389    FILESET   *fileset;                /* What to backup -- Fileset */
390    alist     *storage;                /* Where is device -- list of Storage to be used */
391    POOL      *pool;                   /* Where is media -- Media Pool */
392    POOL      *full_pool;              /* Pool for Full backups */
393    POOL      *inc_pool;               /* Pool for Incremental backups */
394    POOL      *diff_pool;              /* Pool for Differental backups */
395    char      *selection_pattern;
396    int        selection_type;
397    union {
398       JOB       *verify_job;          /* Job name to verify */
399    };
400    JOB       *jobdefs;                /* Job defaults */
401    alist     *run_cmds;               /* Run commands */
402    uint32_t NumConcurrentJobs;        /* number of concurrent jobs running */
403
404    /* Methods */
405    char *name() const;
406 };
407
408 inline char *JOB::name() const { return hdr.name; }
409
410 #undef  MAX_FOPTS
411 #define MAX_FOPTS 34
412
413 /* File options structure */
414 struct FOPTS {
415    char opts[MAX_FOPTS];              /* options string */
416    alist regex;                       /* regex string(s) */
417    alist regexdir;                    /* regex string(s) for directories */
418    alist regexfile;                   /* regex string(s) for files */
419    alist wild;                        /* wild card strings */
420    alist wilddir;                     /* wild card strings for directories */
421    alist wildfile;                    /* wild card strings for files */
422    alist wildbase;                    /* wild card strings for files without '/' */
423    alist base;                        /* list of base names */
424    alist fstype;                      /* file system type limitation */
425    alist drivetype;                   /* drive type limitation */
426    char *reader;                      /* reader program */
427    char *writer;                      /* writer program */
428 };
429
430
431 /* This is either an include item or an exclude item */
432 struct INCEXE {
433    FOPTS *current_opts;               /* points to current options structure */
434    FOPTS **opts_list;                 /* options list */
435    int num_opts;                      /* number of options items */
436    alist name_list;                   /* filename list -- holds char * */
437 };
438
439 /*
440  *   FileSet Resource
441  *
442  */
443 class FILESET {
444 public:
445    RES   hdr;
446
447    bool new_include;                  /* Set if new include used */
448    INCEXE **include_items;            /* array of incexe structures */
449    int num_includes;                  /* number in array */
450    INCEXE **exclude_items;
451    int num_excludes;
452    bool have_MD5;                     /* set if MD5 initialized */
453    struct MD5Context md5c;            /* MD5 of include/exclude */
454    char MD5[30];                      /* base 64 representation of MD5 */
455    bool ignore_fs_changes;            /* Don't force Full if FS changed */
456    bool enable_vss;                   /* Enable Volume Shadow Copy */
457
458    /* Methods */
459    char *name() const;
460 };
461
462 inline char *FILESET::name() const { return hdr.name; }
463
464 /*
465  *   Schedule Resource
466  *
467  */
468 class SCHED {
469 public:
470    RES   hdr;
471
472    RUN *run;
473 };
474
475 /*
476  *   Counter Resource
477  */
478 class COUNTER {
479 public:
480    RES   hdr;
481
482    int32_t  MinValue;                 /* Minimum value */
483    int32_t  MaxValue;                 /* Maximum value */
484    int32_t  CurrentValue;             /* Current value */
485    COUNTER *WrapCounter;              /* Wrap counter name */
486    CAT     *Catalog;                  /* Where to store */
487    bool     created;                  /* Created in DB */
488    /* Methods */
489    char *name() const;
490 };
491
492 inline char *COUNTER::name() const { return hdr.name; }
493
494 /*
495  *   Pool Resource
496  *
497  */
498 class POOL {
499 public:
500    RES   hdr;
501
502    char *pool_type;                   /* Pool type */
503    char *label_format;                /* Label format string */
504    char *cleaning_prefix;             /* Cleaning label prefix */
505    int32_t LabelType;                 /* Bacula/ANSI/IBM label type */
506    uint32_t max_volumes;              /* max number of volumes */
507    utime_t VolRetention;              /* volume retention period in seconds */
508    utime_t VolUseDuration;            /* duration volume can be used */
509    uint32_t MaxVolJobs;               /* Maximum jobs on the Volume */
510    uint32_t MaxVolFiles;              /* Maximum files on the Volume */
511    uint64_t MaxVolBytes;              /* Maximum bytes on the Volume */
512    utime_t MigrationTime;             /* Time to migrate to next pool */
513    uint64_t MigrationHighBytes;       /* When migration starts */
514    uint64_t MigrationLowBytes;        /* When migration stops */
515    POOL  *NextPool;                   /* Next pool for migration */
516    alist *storage;                    /* Where is device -- list of Storage to be used */
517    bool  use_catalog;                 /* maintain catalog for media */
518    bool  catalog_files;               /* maintain file entries in catalog */
519    bool  use_volume_once;             /* write on volume only once */
520    bool  purge_oldest_volume;         /* purge oldest volume */
521    bool  recycle_oldest_volume;       /* attempt to recycle oldest volume */
522    bool  recycle_current_volume;      /* attempt recycle of current volume */
523    bool  AutoPrune;                   /* default for pool auto prune */
524    bool  Recycle;                     /* default for media recycle yes/no */
525
526    /* Methods */
527    char *name() const;
528 };
529
530 inline char *POOL::name() const { return hdr.name; }
531
532
533
534
535 /* Define the Union of all the above
536  * resource structure definitions.
537  */
538 union URES {
539    DIRRES     res_dir;
540    CONRES     res_con;
541    CLIENT     res_client;
542    STORE      res_store;
543    CAT        res_cat;
544    JOB        res_job;
545    FILESET    res_fs;
546    SCHED      res_sch;
547    POOL       res_pool;
548    MSGS       res_msgs;
549    COUNTER    res_counter;
550    DEVICE     res_dev;
551    RES        hdr;
552    RUNSCRIPT  res_runscript;
553 };
554
555
556
557 /* Run structure contained in Schedule Resource */
558 class RUN {
559 public:
560    RUN *next;                         /* points to next run record */
561    int level;                         /* level override */
562    int Priority;                      /* priority override */
563    int job_type;
564    bool spool_data;                   /* Data spooling override */
565    bool spool_data_set;               /* Data spooling override given */
566    bool write_part_after_job;         /* Write part after job override */
567    bool write_part_after_job_set;     /* Write part after job override given */
568    
569    POOL *pool;                        /* Pool override */
570    POOL *full_pool;                   /* Pool override */
571    POOL *inc_pool;                    /* Pool override */
572    POOL *diff_pool;                   /* Pool override */
573    STORE *storage;                    /* Storage override */
574    MSGS *msgs;                        /* Messages override */
575    char *since;
576    int level_no;
577    int minute;                        /* minute to run job */
578    time_t last_run;                   /* last time run */
579    time_t next_run;                   /* next time to run */
580    char hour[nbytes_for_bits(24)];    /* bit set for each hour */
581    char mday[nbytes_for_bits(31)];    /* bit set for each day of month */
582    char month[nbytes_for_bits(12)];   /* bit set for each month */
583    char wday[nbytes_for_bits(7)];     /* bit set for each day of the week */
584    char wom[nbytes_for_bits(5)];      /* week of month */
585    char woy[nbytes_for_bits(54)];     /* week of year */
586 };