1 /*
2    BAREOS® - Backup Archiving REcovery Open Sourced
3 
4    Copyright (C) 2000-2011 Free Software Foundation Europe e.V.
5    Copyright (C) 2011-2012 Planets Communications B.V.
6    Copyright (C) 2013-2020 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 and included
11    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, Feb MM
25  */
26 /**
27  * @file
28  * Director specific configuration and defines
29  */
30 #ifndef BAREOS_DIRD_DIRD_CONF_H_
31 #define BAREOS_DIRD_DIRD_CONF_H_
32 
33 #include "dird/client_connection_handshake_mode.h"
34 #include "dird/date_time_bitfield.h"
35 #include "lib/alist.h"
36 #include "lib/messages_resource.h"
37 #include "lib/resource_item.h"
38 #include "lib/tls_conf.h"
39 
40 class dlist;
41 struct json_t;
42 
43 namespace directordaemon {
44 
45 static std::string default_config_filename("bareos-dir.conf");
46 
47 /**
48  * Resource codes -- they must be sequential for indexing
49  */
50 enum
51 {
52   R_DIRECTOR = 1001,
53   R_CLIENT,
54   R_JOBDEFS,
55   R_JOB,
56   R_STORAGE,
57   R_CATALOG,
58   R_SCHEDULE,
59   R_FILESET,
60   R_POOL,
61   R_MSGS,
62   R_COUNTER,
63   R_PROFILE,
64   R_CONSOLE,
65   R_DEVICE,
66   R_USER,
67   R_FIRST = R_DIRECTOR,
68   R_LAST = R_USER /* keep this updated */
69 };
70 
71 /**
72  * Some resource attributes
73  */
74 enum
75 {
76   R_NAME = 1020,
77   R_ADDRESS,
78   R_PASSWORD,
79   R_TYPE,
80   R_BACKUP
81 };
82 
83 /**
84  * Job Level keyword structure
85  */
86 struct s_jl {
87   const char* level_name; /* level keyword */
88   uint32_t level;         /* level */
89   int32_t job_type;       /* JobType permitting this level */
90 };
91 
92 /**
93  * Job Type keyword structure
94  */
95 struct s_jt {
96   const char* type_name;
97   uint32_t job_type;
98 };
99 
100 /**
101  * Definition of the contents of each Resource
102  * Needed for forward references
103  */
104 class ScheduleResource;
105 class ClientResource;
106 class FilesetResource;
107 class PoolResource;
108 class RunResource;
109 class DeviceResource;
110 
111 /*
112  * Print configuration file schema in json format
113  */
114 bool PrintConfigSchemaJson(PoolMem& buff);
115 
116 /*
117  *   Director Resource
118  */
119 class DirectorResource
120     : public BareosResource
121     , public TlsResource {
122  public:
123   DirectorResource() = default;
124   virtual ~DirectorResource() = default;
125 
126   dlist* DIRaddrs = nullptr;
127   dlist* DIRsrc_addr = nullptr;      /* Address to source connections from */
128   char* query_file = nullptr;        /* SQL query file */
129   char* working_directory = nullptr; /* WorkingDirectory */
130   char* scripts_directory = nullptr; /* ScriptsDirectory */
131   char* plugin_directory = nullptr;  /* Plugin Directory */
132   alist* plugin_names = nullptr;     /* Plugin names to load */
133   char* pid_directory = nullptr;     /* PidDirectory */
134   char* subsys_directory = nullptr;  /* SubsysDirectory */
135   std::vector<std::string> backend_directories;
136   MessagesResource* messages = nullptr; /* Daemon message handler */
137   uint32_t MaxConcurrentJobs = 0; /* Max concurrent jobs for whole director */
138   uint32_t MaxConnections = 0;    /* Max concurrent connections */
139   uint32_t MaxConsoleConnections = 0; /* Max concurrent console connections */
140   utime_t FDConnectTimeout = {0};     /* Timeout for connect in seconds */
141   utime_t SDConnectTimeout = {0};     /* Timeout for connect in seconds */
142   utime_t heartbeat_interval = {0};   /* Interval to send heartbeats */
143   utime_t stats_retention = {0};   /* Statistics retention period in seconds */
144   bool optimize_for_size = false;  /* Optimize daemon for minimum memory size */
145   bool optimize_for_speed = false; /* Optimize daemon for speed which may need
146                               more memory */
147   bool omit_defaults = false; /* Omit config variables with default values when
148                          dumping the config */
149   bool ndmp_snooping = false; /* NDMP Protocol specific snooping enabled */
150   bool auditing = false;      /* Auditing enabled */
151   alist* audit_events = nullptr;   /* Specific audit events to enable */
152   uint32_t ndmp_loglevel = 0;      /* NDMP Protocol specific loglevel to use */
153   uint32_t subscriptions = 0;      /* Number of subscribtions available */
154   uint32_t subscriptions_used = 0; /* Number of subscribtions used */
155   uint32_t jcr_watchdog_time = 0;  /* Absolute time after which a Job gets
156                                   terminated  regardless of its progress */
157   uint32_t stats_collect_interval
158       = 0;               /* Statistics collect interval in seconds */
159   char* verid = nullptr; /* Custom Id to print in version command */
160   char* secure_erase_cmdline = nullptr; /* Cmdline to execute to perform secure
161                                  erase of file */
162   char* log_timestamp_format = nullptr; /* Timestamp format to use in generic
163                                  logging messages */
164   s_password keyencrkey;                /* Key Encryption Key */
165 };
166 
167 /*
168  * Device Resource
169  *
170  * This resource is a bit different from the other resources
171  * because it is not defined in the Director
172  * by Device { ... }, but rather by a "reference" such as
173  * Device = xxx; Then when the Director connects to the
174  * SD, it requests the information about the device.
175  */
176 class DeviceResource : public BareosResource {
177  public:
178   DeviceResource() = default;
179   virtual ~DeviceResource() = default;
180 
181   bool found = false;       /**< found with SD */
182   int32_t num_writers = 0;  /**< number of writers */
183   int32_t max_writers = 0;  /**< = 1 for files */
184   int32_t reserved = 0;     /**< number of reserves */
185   int32_t num_drives = 0;   /**< for autochanger */
186   bool autochanger = false; /**< set if device is autochanger */
187   bool open = false;        /**< drive open */
188   bool append = false;      /**< in append mode */
189   bool read = false;        /**< in read mode */
190   bool labeled = false;     /**< Volume name valid */
191   bool offline = false;     /**< not available */
192   bool autoselect = false;  /**< can be selected via autochanger */
193   uint32_t PoolId = 0;
194   char ChangerName[MAX_NAME_LENGTH] = {0};
195   char VolumeName[MAX_NAME_LENGTH] = {0};
196   char MediaType[MAX_NAME_LENGTH] = {0};
197 };
198 
199 /**
200  * Console ACL positions
201  */
202 enum
203 {
204   Job_ACL = 0,
205   Client_ACL,
206   Storage_ACL,
207   Schedule_ACL,
208   Pool_ACL,
209   Command_ACL,
210   FileSet_ACL,
211   Catalog_ACL,
212   Where_ACL,
213   PluginOptions_ACL,
214   Num_ACL /**< keep last */
215 };
216 
217 /**
218  * Profile Resource
219  */
220 class ProfileResource : public BareosResource {
221  public:
222   ProfileResource() = default;
223   virtual ~ProfileResource() = default;
224 
225   alist* ACL_lists[Num_ACL] = {0}; /**< Pointers to ACLs */
226 };
227 
228 struct UserAcl {
229   BareosResource* corresponding_resource = nullptr;
230   alist* ACL_lists[Num_ACL] = {0}; /**< Pointers to ACLs */
231   alist* profiles = nullptr;       /**< Pointers to profile resources */
232 };
233 
234 /**
235  * Console Resource
236  */
237 class ConsoleResource
238     : public BareosResource
239     , public TlsResource {
240  public:
241   ConsoleResource() = default;
242   virtual ~ConsoleResource() = default;
243   UserAcl user_acl;
244   bool use_pam_authentication_ = false; /**< PAM Console */
245 };
246 
247 class UserResource : public BareosResource {
248  public:
249   UserResource() = default;
250   virtual ~UserResource() = default;
251   UserAcl user_acl;
252 };
253 
254 /**
255  * Catalog Resource
256  */
257 class CatalogResource : public BareosResource {
258  public:
259   CatalogResource() = default;
260   virtual ~CatalogResource() = default;
261   virtual bool Validate() override;
262 
263   uint32_t db_port = 0;       /**< Port */
264   char* db_address = nullptr; /**< Hostname for remote access */
265   char* db_socket = nullptr;  /**< Socket for local access */
266   s_password db_password;
267   char* db_user = nullptr;
268   char* db_name = nullptr;
269   char* db_driver = nullptr;        /**< Select appropriate driver */
270   uint32_t mult_db_connections = 0; /**< Set if multiple connections wanted */
271   bool disable_batch_insert
272       = false;                /**< Set if batch inserts should be disabled */
273   bool try_reconnect = false; /**< Try to reconnect a database connection when
274                          its dropped */
275   bool exit_on_fatal = false; /**< Make any fatal error in the connection to the
276                          database exit the program */
277   uint32_t pooling_min_connections
278       = 0; /**< When using sql pooling start with this
279           number of connections to the database */
280   uint32_t pooling_max_connections = 0; /**< When using sql pooling maximum
281                                        number of connections to the database */
282   uint32_t pooling_increment_connections = 0; /**< When using sql pooling
283                                              increment the pool with this amount
284                                              when its to small */
285   uint32_t pooling_idle_timeout
286       = 0; /**< When using sql pooling set this to the number
287           of seconds to keep an idle connection */
288   uint32_t pooling_validate_timeout = 0; /**< When using sql pooling set this to
289                                         the number of seconds after a idle
290                                         connection should be validated */
291 
292   /**< Methods */
293   char* display(POOLMEM* dst); /**< Get catalog information */
294 };
295 
296 /**
297  * Forward referenced structures
298  */
299 struct runtime_client_status_t;
300 struct RuntimeStorageStatus;
301 struct runtime_job_status_t;
302 
303 /**
304  * Client Resource
305  */
306 class ClientResource
307     : public BareosResource
308     , public TlsResource {
309  public:
310   ClientResource() = default;
311   virtual ~ClientResource() = default;
312 
313   uint32_t Protocol = 0;       /* Protocol to use to connect */
314   uint32_t AuthType = 0;       /* Authentication Type to use for protocol */
315   uint32_t ndmp_loglevel = 0;  /* NDMP Protocol specific loglevel to use */
316   uint32_t ndmp_blocksize = 0; /* NDMP Protocol specific blocksize to use */
317   uint32_t FDport = 0;         /* Where File daemon listens */
318   uint64_t SoftQuota = 0;      /* Soft Quota permitted in bytes */
319   uint64_t HardQuota = 0;      /* Maximum permitted quota in bytes */
320   uint64_t GraceTime = 0;      /* Time remaining on gracetime */
321   uint64_t QuotaLimit = 0;     /* The total softquota supplied if over grace */
322   utime_t SoftQuotaGracePeriod = {0}; /* Grace time for softquota */
323   utime_t FileRetention = {0};        /* File retention period in seconds */
324   utime_t JobRetention = {0};         /* Job retention period in seconds */
325   utime_t heartbeat_interval = {0};   /* Interval to send heartbeats */
326   char* address = nullptr;            /* Hostname for remote access to Client */
327   char* lanaddress
328       = nullptr; /* Hostname for remote access to Client if behind NAT in LAN
329                   */
330   char* username = nullptr; /* Username to use for authentication if protocol
331                                supports it */
332   CatalogResource* catalog = nullptr; /* Catalog resource */
333   int32_t MaxConcurrentJobs = 0;      /* Maximum concurrent jobs */
334   bool passive = false;               /* Passive Client */
335   bool conn_from_dir_to_fd = false;   /* Connect to Client */
336   bool conn_from_fd_to_dir = false;   /* Allow incoming connections */
337   bool enabled = false;               /* Set if client is enabled */
338   bool AutoPrune = false;             /* Do automatic pruning? */
339   bool StrictQuotas = false;          /* Enable strict quotas? */
340   bool QuotaIncludeFailedJobs
341       = false; /* Ignore failed jobs when calculating quota */
342   bool ndmp_use_lmdb
343       = false; /* NDMP Protocol specific use LMDB for the FHDB or not */
344   int64_t max_bandwidth = 0;              /* Limit speed on this client */
345   runtime_client_status_t* rcs = nullptr; /* Runtime Client Status */
346   ClientConnectionHandshakeMode connection_successful_handshake_
347       = ClientConnectionHandshakeMode::kUndefined;
348 };
349 
350 /**
351  * Store Resource
352  */
353 class StorageResource
354     : public BareosResource
355     , public TlsResource {
356  public:
357   StorageResource() = default;
358   virtual ~StorageResource() = default;
359 
360   uint32_t Protocol = 0;      /* Protocol to use to connect */
361   uint32_t AuthType = 0;      /* Authentication Type to use for protocol */
362   uint32_t SDport = 0;        /* Port where Directors connect */
363   uint32_t SDDport = 0;       /* Data port for File daemon */
364   char* address = nullptr;    /* Hostname for remote access to Storage */
365   char* lanaddress = nullptr; /* Hostname for remote access to Storage if behind
366                        NAT in LAN */
367   char* username = nullptr;   /* Username to use for authentication if protocol
368                                  supports it */
369   char* media_type = nullptr; /**< Media Type provided by this Storage */
370   char* ndmp_changer_device = nullptr; /**< If DIR controls storage directly
371                                 (NDMP_NATIVE) changer device used */
372   alist* device = nullptr;           /**< Alternate devices for this Storage */
373   int32_t MaxConcurrentJobs = 0;     /**< Maximum concurrent jobs */
374   int32_t MaxConcurrentReadJobs = 0; /**< Maximum concurrent jobs reading */
375   bool enabled = false;              /**< Set if device is enabled */
376   bool autochanger = false;          /**< Set if autochanger */
377   bool collectstats
378       = false; /**< Set if statistics should be collected of this SD */
379   bool AllowCompress = false; /**< Set if this Storage should allow jobs to
380                          enable compression */
381   int64_t StorageId = 0;      /**< Set from Storage DB record */
382   int64_t max_bandwidth
383       = 0; /**< Limit speed on this storage daemon for replication */
384   utime_t heartbeat_interval = {0}; /**< Interval to send heartbeats */
385   utime_t cache_status_interval = {
386       0}; /**< Interval to cache the vol_list in the runtime_storage_status */
387   RuntimeStorageStatus* runtime_storage_status = nullptr;
388   StorageResource* paired_storage = nullptr; /**< Paired storage configuration
389                                       item for protocols like NDMP */
390 
391   /* Methods */
392   char* dev_name() const;
393 };
394 
dev_name()395 inline char* StorageResource::dev_name() const
396 {
397   DeviceResource* dev = (DeviceResource*)device->first();
398   return dev->resource_name_;
399 }
400 
401 /**
402  * This is a sort of "unified" store that has both the
403  * storage pointer and the text of where the pointer was
404  * found.
405  */
406 class UnifiedStorageResource : public BareosResource {
407  public:
408   StorageResource* store = nullptr;
409   POOLMEM* store_source = nullptr;
410 
UnifiedStorageResource()411   UnifiedStorageResource()
412   {
413     store = nullptr;
414     store_source = GetPoolMemory(PM_MESSAGE);
415     *store_source = 0;
416   }
~UnifiedStorageResource()417   ~UnifiedStorageResource() { destroy(); }
418 
419   void SetSource(const char* where);
420   void destroy();
421 };
422 
destroy()423 inline void UnifiedStorageResource::destroy()
424 {
425   if (store_source) {
426     FreePoolMemory(store_source);
427     store_source = nullptr;
428   }
429 }
430 
SetSource(const char * where)431 inline void UnifiedStorageResource::SetSource(const char* where)
432 {
433   if (!store_source) { store_source = GetPoolMemory(PM_MESSAGE); }
434   PmStrcpy(store_source, where);
435 }
436 
437 /**
438  * Job Resource
439  */
440 /* clang-format off */
441 class JobResource : public BareosResource {
442  public:
443   JobResource() = default;
444   virtual ~JobResource() = default;
445 
446   uint32_t Protocol = 0;       /**< Protocol to use to connect */
447   uint32_t JobType = 0;        /**< Job type (backup, verify, restore) */
448   uint32_t JobLevel = 0;       /**< default backup/verify level */
449   int32_t Priority = 0;        /**< Job priority */
450   uint32_t RestoreJobId = 0;   /**< What -- JobId to restore */
451   int32_t RescheduleTimes = 0; /**< Number of times to reschedule job */
452   uint32_t replace = 0;        /**< How (overwrite, ..) */
453   uint32_t selection_type = 0;
454 
455   char* RestoreWhere = nullptr;  /**< Where on disk to restore -- directory */
456   char* RegexWhere = nullptr;    /**< RegexWhere option */
457   char* strip_prefix = nullptr;  /**< Remove prefix from filename  */
458   char* add_prefix = nullptr;    /**< add prefix to filename  */
459   char* add_suffix = nullptr;    /**< add suffix to filename -- .old */
460   char* backup_format = nullptr; /**< Format of backup to use for protocols supporting multiple backup formats */
461   char* RestoreBootstrap = nullptr; /**< Bootstrap file */
462   char* WriteBootstrap = nullptr;   /**< Where to write bootstrap Job updates */
463   char* WriteVerifyList = nullptr;  /**< List of changed files */
464   utime_t MaxRunTime = {0};         /**< Max run time in seconds */
465   utime_t MaxWaitTime = {0};        /**< Max blocking time in seconds */
466   utime_t FullMaxRunTime = {0};     /**< Max Full job run time */
467   utime_t DiffMaxRunTime = {0};     /**< Max Differential job run time */
468   utime_t IncMaxRunTime = {0};      /**< Max Incremental job run time */
469   utime_t MaxStartDelay = {0};      /**< Max start delay in seconds */
470   utime_t MaxRunSchedTime = {0}; /**< Max run time in seconds from Scheduled time*/
471   utime_t RescheduleInterval = {0}; /**< Reschedule interval */
472   utime_t MaxFullInterval = {0};    /**< Maximum time interval between Fulls */
473   utime_t MaxVFullInterval = {0}; /**< Maximum time interval between Virtual Fulls */
474   utime_t MaxDiffInterval = {0}; /**< Maximum time interval between Diffs */
475   utime_t DuplicateJobProximity = {0}; /**< Permitted time between duplicicates */
476   utime_t AlwaysIncrementalJobRetention = {0}; /**< Timeinterval where incrementals are not consolidated */
477   utime_t AlwaysIncrementalMaxFullAge = {0};   /**< If Full Backup is older than this age
478                                                 *   the consolidation job will include also the full */
479   utime_t RunOnIncomingConnectInterval = {0};
480   int64_t spool_size = 0;    /**< Size of spool file for this job */
481   int64_t max_bandwidth = 0; /**< Speed limit on this job */
482   int64_t FileHistSize = 0; /**< Hint about the size of the expected File history */
483   int32_t MaxConcurrentJobs = 0;   /**< Maximum concurrent jobs */
484   int32_t MaxConcurrentCopies = 0; /**< Limit number of concurrent jobs one Copy Job spawns */
485   int32_t AlwaysIncrementalKeepNumber = 0; /**< Number of incrementals that are always left and not consolidated */
486   int32_t MaxFullConsolidations = 0;       /**< Number of consolidate jobs to be started that will include a full */
487 
488   MessagesResource* messages = nullptr; /**< How and where to send messages */
489   ScheduleResource* schedule = nullptr; /**< When -- Automatic schedule */
490   ClientResource* client = nullptr;     /**< Who to backup */
491   FilesetResource* fileset = nullptr;   /**< What to backup -- Fileset */
492   CatalogResource* catalog = nullptr;   /**< Which Catalog to use */
493   alist* storage = nullptr; /**< Where is device -- list of Storage to be used */
494   PoolResource* pool = nullptr;       /**< Where is media -- Media Pool */
495   PoolResource* full_pool = nullptr;  /**< Pool for Full backups */
496   PoolResource* vfull_pool = nullptr; /**< Pool for Virtual Full backups */
497   PoolResource* inc_pool = nullptr;   /**< Pool for Incremental backups */
498   PoolResource* diff_pool = nullptr;  /**< Pool for Differental backups */
499   PoolResource* next_pool = nullptr; /**< Next Pool for Copy/Migration Jobs and Virtual backups */
500   char* selection_pattern = nullptr;
501   JobResource* verify_job = nullptr; /**< Job name to verify */
502   JobResource* jobdefs = nullptr;    /**< Job defaults */
503   alist* run_cmds = nullptr;         /**< Run commands */
504   alist* RunScripts = nullptr; /**< Run {client} program {after|before} Job */
505   alist* FdPluginOptions = nullptr; /**< Generic FD plugin options used by this Job */
506   alist* SdPluginOptions = nullptr; /**< Generic SD plugin options used by this Job */
507   alist* DirPluginOptions = nullptr;           /**< Generic DIR plugin options used by this Job */
508   alist* base = nullptr; /**< Base jobs */
509 
510   bool allow_mixed_priority = false; /**< Allow jobs with higher priority concurrently with this */
511   bool where_use_regexp = false;  /**< true if RestoreWhere is a BareosRegex */
512   bool RescheduleOnError = false; /**< Set to reschedule on error */
513   bool RescheduleIncompleteJobs = false; /**< Set to reschedule incomplete Jobs */
514   bool PrefixLinks = false;         /**< Prefix soft links with Where path */
515   bool PruneJobs = false;           /**< Force pruning of Jobs */
516   bool PruneFiles = false;          /**< Force pruning of Files */
517   bool PruneVolumes = false;        /**< Force pruning of Volumes */
518   bool SpoolAttributes = false;     /**< Set to spool attributes in SD */
519   bool spool_data = false;          /**< Set to spool data in SD */
520   bool rerun_failed_levels = false; /**< Upgrade to rerun failed levels */
521   bool PreferMountedVolumes = false; /**< Prefer vols mounted rather than new one */
522   bool write_part_after_job = false; /**< Set to write part after job in SD */
523   bool enabled = false;              /**< Set if job enabled */
524   bool accurate = false;             /**< Set if it is an accurate backup job */
525   bool AllowDuplicateJobs = false;   /**< Allow duplicate jobs */
526   bool AllowHigherDuplicates = false; /**< Permit Higher Level */
527   bool CancelLowerLevelDuplicates = false; /**< Cancel lower level backup jobs */
528   bool CancelQueuedDuplicates = false;  /**< Cancel queued jobs */
529   bool CancelRunningDuplicates = false; /**< Cancel Running jobs */
530   bool PurgeMigrateJob = false;         /**< Purges source job on completion */
531   bool IgnoreDuplicateJobChecking = false; /**< Ignore Duplicate Job Checking */
532   bool SaveFileHist = false; /**< Ability to disable File history saving for certain protocols */
533   bool AlwaysIncremental = false; /**< Always incremental with regular consolidation */
534 
535   runtime_job_status_t* rjs = nullptr; /**< Runtime Job Status */
536 
537   /* Methods */
538   virtual bool Validate() override;
539 };
540 /* clang-format on */
541 
542 #undef MAX_FOPTS
543 #define MAX_FOPTS 40
544 
545 /**
546  * File options structure
547  */
548 struct FileOptions {
549   FileOptions() = default;
550   virtual ~FileOptions() = default;
551 
552   char opts[MAX_FOPTS] = {0}; /**< Options string */
553   alist regex;                /**< Regex string(s) */
554   alist regexdir;             /**< Regex string(s) for directories */
555   alist regexfile;            /**< Regex string(s) for files */
556   alist wild;                 /**< Wild card strings */
557   alist wilddir;              /**< Wild card strings for directories */
558   alist wildfile;             /**< Wild card strings for files */
559   alist wildbase;             /**< Wild card strings for files without '/' */
560   alist base;                 /**< List of base names */
561   alist fstype;               /**< File system type limitation */
562   alist Drivetype;            /**< Drive type limitation */
563   alist meta;                 /**< Backup meta information */
564   char* reader = nullptr;     /**< Reader program */
565   char* writer = nullptr;     /**< Writer program */
566   char* plugin = nullptr;     /**< Plugin program */
567 };
568 
569 /**
570  * This is either an include item or an exclude item
571  */
572 class IncludeExcludeItem {
573  public:
574   IncludeExcludeItem() = default;
575   virtual ~IncludeExcludeItem() = default;
576 
577   FileOptions* current_opts = nullptr;
578   std::vector<FileOptions*> file_options_list;
579   alist name_list;   /**< Filename list -- holds char * */
580   alist plugin_list; /**< Filename list for plugins */
581   alist ignoredir;   /**< Ignoredir string */
582 };
583 
584 /**
585  * FileSet Resource
586  */
587 class FilesetResource : public BareosResource {
588  public:
589   FilesetResource() = default;
590   virtual ~FilesetResource() = default;
591 
592   bool new_include = false; /**< Set if new include used */
593   std::vector<IncludeExcludeItem*> include_items;
594   std::vector<IncludeExcludeItem*> exclude_items;
595   bool have_MD5 = false;          /**< Set if MD5 initialized */
596   MD5_CTX md5c = {0};             /**< MD5 of include/exclude */
597   char MD5[30]{0};                /**< Base 64 representation of MD5 */
598   bool ignore_fs_changes = false; /**< Don't force Full if FS changed */
599   bool enable_vss = false;        /**< Enable Volume Shadow Copy */
600 
601   /* Methods */
602   bool PrintConfig(OutputFormatterResource& send,
603                    const ConfigurationParser& my_config /* unused */,
604                    bool hide_sensitive_data = false,
605                    bool verbose = false) override;
606   void PrintConfigIncludeExcludeOptions(OutputFormatterResource& send,
607                                         FileOptions* fo,
608                                         bool verbose);
609   std::string GetOptionValue(const char** option);
610 };
611 
612 /**
613  * Schedule Resource
614  */
615 class ScheduleResource : public BareosResource {
616  public:
617   ScheduleResource() = default;
618   virtual ~ScheduleResource() = default;
619 
620   RunResource* run = nullptr;
621   bool enabled = false; /* Set if schedule is enabled */
622 };
623 
624 /**
625  * Counter Resource
626  */
627 class CounterResource : public BareosResource {
628  public:
629   CounterResource() = default;
630   virtual ~CounterResource() = default;
631 
632   int32_t MinValue = 0;                   /* Minimum value */
633   int32_t MaxValue = 0;                   /* Maximum value */
634   int32_t CurrentValue = 0;               /* Current value */
635   CounterResource* WrapCounter = nullptr; /* Wrap counter name */
636   CatalogResource* Catalog = nullptr;     /* Where to store */
637   bool created;                           /* Created in DB */
638 };
639 
640 /**
641  * Pool Resource
642  */
643 class PoolResource : public BareosResource {
644  public:
645   PoolResource() = default;
646   virtual ~PoolResource() = default;
647 
648   char* pool_type = nullptr;        /* Pool type */
649   char* label_format = nullptr;     /* Label format string */
650   char* cleaning_prefix = nullptr;  /* Cleaning label prefix */
651   int32_t LabelType = 0;            /* Bareos/ANSI/IBM label type */
652   uint32_t max_volumes = 0;         /* Max number of volumes */
653   utime_t VolRetention = {0};       /* Volume retention period in seconds */
654   utime_t VolUseDuration = {0};     /* Duration volume can be used */
655   uint32_t MaxVolJobs = 0;          /* Maximum jobs on the Volume */
656   uint32_t MaxVolFiles = 0;         /* Maximum files on the Volume */
657   uint64_t MaxVolBytes = 0;         /* Maximum bytes on the Volume */
658   utime_t MigrationTime = {0};      /* Time to migrate to next pool */
659   uint64_t MigrationHighBytes = 0;  /* When migration starts */
660   uint64_t MigrationLowBytes = 0;   /* When migration stops */
661   PoolResource* NextPool = nullptr; /* Next pool for migration */
662   alist* storage = nullptr; /* Where is device -- list of Storage to be used */
663   bool use_catalog = false; /* Maintain catalog for media */
664   bool catalog_files = false;          /* Maintain file entries in catalog */
665   bool use_volume_once = false;        /* Write on volume only once */
666   bool purge_oldest_volume = false;    /* Purge oldest volume */
667   bool recycle_oldest_volume = false;  /* Attempt to recycle oldest volume */
668   bool recycle_current_volume = false; /* Attempt recycle of current volume */
669   bool AutoPrune = false;              /* Default for pool auto prune */
670   bool Recycle = false;                /* Default for media recycle yes/no */
671   uint32_t action_on_purge
672       = 0; /* Action on purge, e.g. truncate the disk volume */
673   PoolResource* RecyclePool
674       = nullptr; /* RecyclePool destination when media is purged */
675   PoolResource* ScratchPool
676       = nullptr; /* ScratchPool source when requesting media */
677   CatalogResource* catalog = nullptr; /* Catalog to be used */
678   utime_t FileRetention = {0};        /* File retention period in seconds */
679   utime_t JobRetention = {0};         /* Job retention period in seconds */
680   uint32_t MinBlocksize = 0;          /* Minimum Blocksize */
681   uint32_t MaxBlocksize = 0;          /* Maximum Blocksize */
682 };
683 
684 /**
685  * Run structure contained in Schedule Resource
686  */
687 class RunResource : public BareosResource {
688  public:
689   RunResource() = default;
690   virtual ~RunResource() = default;
691 
692   RunResource* next = nullptr; /**< points to next run record */
693   uint32_t level = 0;          /**< level override */
694   int32_t Priority = 0;        /**< priority override */
695   uint32_t job_type = 0;
696   utime_t MaxRunSchedTime = {0};    /**< max run time in sec from Sched time */
697   bool MaxRunSchedTime_set = false; /**< MaxRunSchedTime given */
698   bool spool_data = false;          /**< Data spooling override */
699   bool spool_data_set = false;      /**< Data spooling override given */
700   bool accurate = false;            /**< accurate */
701   bool accurate_set = false;        /**< accurate given */
702 
703   PoolResource* pool = nullptr;       /**< Pool override */
704   PoolResource* full_pool = nullptr;  /**< Full Pool override */
705   PoolResource* vfull_pool = nullptr; /**< Virtual Full Pool override */
706   PoolResource* inc_pool = nullptr;   /**< Incr Pool override */
707   PoolResource* diff_pool = nullptr;  /**< Diff Pool override */
708   PoolResource* next_pool = nullptr;  /**< Next Pool override */
709   StorageResource* storage = nullptr; /**< Storage override */
710   MessagesResource* msgs = nullptr;   /**< Messages override */
711   uint32_t minute = 0;                /* minute to run job */
712   time_t scheduled_last = {0};
713   DateTimeBitfield date_time_bitfield;
714 };
715 
716 ConfigurationParser* InitDirConfig(const char* configfile, int exit_code);
717 bool PropagateJobdefs(int res_type, JobResource* res);
718 bool ValidateResource(int type, ResourceItem* items, BareosResource* res);
719 
720 bool print_datatype_schema_json(PoolMem& buffer,
721                                 int level,
722                                 const int type,
723                                 ResourceItem items[],
724                                 const bool last = false);
725 #ifdef HAVE_JANSSON
726 json_t* json_datatype(const int type, ResourceItem items[]);
727 #endif
728 const char* AuthenticationProtocolTypeToString(uint32_t auth_protocol);
729 const char* JobLevelToString(int level);
730 extern "C" char* job_code_callback_director(JobControlRecord* jcr, const char*);
731 const char* GetUsageStringForConsoleConfigureCommand();
732 void DestroyConfigureUsageString();
733 bool PopulateDefs();
734 std::vector<JobResource*> GetAllJobResourcesByClientName(std::string name);
735 
736 } /* namespace directordaemon */
737 #endif  // BAREOS_DIRD_DIRD_CONF_H_
738