]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/filed/filed_conf.c
Use Bacula in place of Libz variables so we can build with/without libz and lzo
[bacula/bacula] / bacula / src / filed / filed_conf.c
1 /*
2    Bacula(R) - The Network Backup Solution
3
4    Copyright (C) 2000-2017 Kern Sibbald
5
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.
8
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.
13
14    This notice must be preserved when any source code is
15    conveyed and/or propagated.
16
17    Bacula(R) is a registered trademark of Kern Sibbald.
18 */
19 /*
20  *   Main configuration file parser for Bacula File Daemon (Client)
21  *    some parts may be split into separate files such as
22  *    the schedule configuration (sch_config.c).
23  *
24  *   Note, the configuration file parser consists of three parts
25  *
26  *   1. The generic lexical scanner in lib/lex.c and lib/lex.h
27  *
28  *   2. The generic config  scanner in lib/parse_config.c and
29  *      lib/parse_config.h.
30  *      These files contain the parser code, some utility
31  *      routines, and the common store routines (name, int,
32  *      string).
33  *
34  *   3. The daemon specific file, which contains the Resource
35  *      definitions as well as any specific store routines
36  *      for the resource records.
37  *
38  *     Kern Sibbald, September MM
39  */
40
41 #include "bacula.h"
42 #include "filed.h"
43
44 /* Define the first and last resource ID record
45  * types. Note, these should be unique for each
46  * daemon though not a requirement.
47  */
48 int32_t r_first = R_FIRST;
49 int32_t r_last  = R_LAST;
50 RES_HEAD **res_head;
51
52
53 /* Forward referenced subroutines */
54
55
56 /* We build the current resource here as we are
57  * scanning the resource configuration definition,
58  * then move it to allocated memory when the resource
59  * scan is complete.
60  */
61 #if defined(_MSC_VER)
62 extern "C" { // work around visual compiler mangling variables
63    URES res_all;
64 }
65 #else
66 URES res_all;
67 #endif
68 int32_t res_all_size = sizeof(res_all);
69
70 /* Forward definition for encyption cipher/digest type  */
71 static void store_cipher_type(LEX *lc, RES_ITEM *item, int index, int pass);
72 static void store_digest_type(LEX *lc, RES_ITEM *item, int index, int pass);
73
74 /* Definition of records permitted within each
75  * resource with the routine to process the record
76  * information.
77  */
78
79 /* Client or File daemon "Global" resources */
80 static RES_ITEM cli_items[] = {
81    {"Name",        store_name,  ITEM(res_client.hdr.name), 0, ITEM_REQUIRED, 0},
82    {"Description", store_str,   ITEM(res_client.hdr.desc), 0, 0, 0},
83    {"FdPort",      store_addresses_port,    ITEM(res_client.FDaddrs),  0, ITEM_DEFAULT, 9102},
84    {"FdAddress",   store_addresses_address, ITEM(res_client.FDaddrs),  0, ITEM_DEFAULT, 9102},
85    {"FdAddresses", store_addresses,         ITEM(res_client.FDaddrs),  0, ITEM_DEFAULT, 9102},
86    {"FdSourceAddress", store_addresses_address, ITEM(res_client.FDsrc_addr),  0, ITEM_DEFAULT, 0},
87
88    {"WorkingDirectory",  store_dir, ITEM(res_client.working_directory), 0, ITEM_REQUIRED, 0},
89    {"PidDirectory",  store_dir,     ITEM(res_client.pid_directory),     0, ITEM_REQUIRED, 0},
90    {"SubsysDirectory",  store_dir,  ITEM(res_client.subsys_directory),  0, 0, 0},
91    {"PluginDirectory",  store_dir,  ITEM(res_client.plugin_directory),  0, 0, 0},
92    {"SnapshotCommand",  store_str,  ITEM(res_client.snapshot_command), 0, 0, 0},
93    {"ScriptsDirectory", store_dir,  ITEM(res_client.scripts_directory),  0, 0, 0},
94    {"MaximumConcurrentJobs", store_pint32,  ITEM(res_client.MaxConcurrentJobs), 0, ITEM_DEFAULT, 20},
95    {"Messages",      store_res, ITEM(res_client.messages), R_MSGS, 0, 0},
96    {"SdConnectTimeout", store_time,ITEM(res_client.SDConnectTimeout), 0, ITEM_DEFAULT, 60 * 30},
97    {"HeartbeatInterval", store_time, ITEM(res_client.heartbeat_interval), 0, ITEM_DEFAULT, 5 * 60},
98    {"MaximumNetworkBufferSize", store_pint32, ITEM(res_client.max_network_buffer_size), 0, 0, 0},
99 #ifdef DATA_ENCRYPTION
100    {"PkiSignatures",         store_bool,    ITEM(res_client.pki_sign), 0, ITEM_DEFAULT, 0},
101    {"PkiEncryption",         store_bool,    ITEM(res_client.pki_encrypt), 0, ITEM_DEFAULT, 0},
102    {"PkiKeyPair",            store_dir,         ITEM(res_client.pki_keypair_file), 0, 0, 0},
103    {"PkiSigner",             store_alist_str,   ITEM(res_client.pki_signing_key_files), 0, 0, 0},
104    {"PkiMasterKey",          store_alist_str,   ITEM(res_client.pki_master_key_files), 0, 0, 0},
105    {"PkiCipher",             store_cipher_type, ITEM(res_client.pki_cipher), 0, 0, 0},
106    {"PkiDigest",             store_digest_type, ITEM(res_client.pki_digest), 0, 0, 0},
107 #endif
108    {"TlsAuthenticate",       store_bool,    ITEM(res_client.tls_authenticate),  0, 0, 0},
109    {"TlsEnable",             store_bool,    ITEM(res_client.tls_enable),  0, 0, 0},
110    {"TlsRequire",            store_bool,    ITEM(res_client.tls_require), 0, 0, 0},
111    {"TlsCaCertificateFile",  store_dir,     ITEM(res_client.tls_ca_certfile), 0, 0, 0},
112    {"TlsCaCertificateDir",   store_dir,     ITEM(res_client.tls_ca_certdir), 0, 0, 0},
113    {"TlsCertificate",        store_dir,     ITEM(res_client.tls_certfile), 0, 0, 0},
114    {"TlsKey",                store_dir,     ITEM(res_client.tls_keyfile), 0, 0, 0},
115    {"VerId",                 store_str,     ITEM(res_client.verid), 0, 0, 0},
116    {"MaximumBandwidthPerJob",store_speed,   ITEM(res_client.max_bandwidth_per_job), 0, 0, 0},
117    {"CommCompression",       store_bool,    ITEM(res_client.comm_compression), 0, ITEM_DEFAULT, true},
118    {"DisableCommand",        store_alist_str, ITEM(res_client.disable_cmds), 0, 0, 0},
119    {NULL, NULL, {0}, 0, 0, 0}
120 };
121
122 /* Directors that can use our services */
123 static RES_ITEM dir_items[] = {
124    {"Name",        store_name,     ITEM(res_dir.hdr.name),  0, ITEM_REQUIRED, 0},
125    {"Description", store_str,      ITEM(res_dir.hdr.desc),  0, 0, 0},
126    {"Password",    store_password, ITEM(res_dir.password),  0, ITEM_REQUIRED, 0},
127    {"Address",     store_str,      ITEM(res_dir.address),   0, 0, 0},
128    {"Monitor",     store_bool,   ITEM(res_dir.monitor),   0, ITEM_DEFAULT, 0},
129    {"Remote",      store_bool,   ITEM(res_dir.remote),   0, ITEM_DEFAULT, 0},
130    {"TlsAuthenticate",      store_bool,    ITEM(res_dir.tls_authenticate), 0, 0, 0},
131    {"TlsEnable",            store_bool,    ITEM(res_dir.tls_enable), 0, 0, 0},
132    {"TlsRequire",           store_bool,    ITEM(res_dir.tls_require), 0, 0, 0},
133    {"TlsVerifyPeer",        store_bool,    ITEM(res_dir.tls_verify_peer), 0, ITEM_DEFAULT, 1},
134    {"TlsCaCertificateFile", store_dir,       ITEM(res_dir.tls_ca_certfile), 0, 0, 0},
135    {"TlsCaCertificateDir",  store_dir,       ITEM(res_dir.tls_ca_certdir), 0, 0, 0},
136    {"TlsCertificate",       store_dir,       ITEM(res_dir.tls_certfile), 0, 0, 0},
137    {"TlsKey",               store_dir,       ITEM(res_dir.tls_keyfile), 0, 0, 0},
138    {"TlsDhFile",            store_dir,       ITEM(res_dir.tls_dhfile), 0, 0, 0},
139    {"TlsAllowedCn",         store_alist_str, ITEM(res_dir.tls_allowed_cns), 0, 0, 0},
140    {"MaximumBandwidthPerJob", store_speed,     ITEM(res_dir.max_bandwidth_per_job), 0, 0, 0},
141    {"DisableCommand",        store_alist_str, ITEM(res_dir.disable_cmds), 0, 0, 0},
142    {"Console",              store_res, ITEM(res_dir.console),  R_CONSOLE, 0, 0},
143    {NULL, NULL, {0}, 0, 0, 0}
144 };
145
146 /* Consoles that we can use to connect a Director */
147 static RES_ITEM cons_items[] = {
148    {"Name",        store_name,     ITEM(res_cons.hdr.name),  0, ITEM_REQUIRED, 0},
149    {"Description", store_str,      ITEM(res_cons.hdr.desc),  0, 0, 0},
150    {"Password",    store_password, ITEM(res_cons.password),  0, ITEM_REQUIRED, 0},
151    {"Address",     store_str,      ITEM(res_cons.address),   0, 0, 0},
152    {"DirPort",        store_pint32,    ITEM(res_cons.DIRport),  0, ITEM_DEFAULT, 9101},
153    {"TlsAuthenticate",      store_bool,    ITEM(res_cons.tls_authenticate), 0, 0, 0},
154    {"TlsEnable",            store_bool,    ITEM(res_cons.tls_enable), 0, 0, 0},
155    {"TlsRequire",           store_bool,    ITEM(res_cons.tls_require), 0, 0, 0},
156    {"TlsVerifyPeer",        store_bool,    ITEM(res_cons.tls_verify_peer), 0, ITEM_DEFAULT, 1},
157    {"TlsCaCertificateFile", store_dir,       ITEM(res_cons.tls_ca_certfile), 0, 0, 0},
158    {"TlsCaCertificateDir",  store_dir,       ITEM(res_cons.tls_ca_certdir), 0, 0, 0},
159    {"TlsCertificate",       store_dir,       ITEM(res_cons.tls_certfile), 0, 0, 0},
160    {"TlsKey",               store_dir,       ITEM(res_cons.tls_keyfile), 0, 0, 0},
161    {"TlsDhFile",            store_dir,       ITEM(res_cons.tls_dhfile), 0, 0, 0},
162    {"TlsAllowedCn",         store_alist_str, ITEM(res_cons.tls_allowed_cns), 0, 0, 0},
163    {NULL, NULL, {0}, 0, 0, 0}
164 };
165
166 /* Message resource */
167 extern RES_ITEM msgs_items[];
168
169 /*
170  * This is the master resource definition.
171  * It must have one item for each of the resources.
172  */
173 RES_TABLE resources[] = {
174    {"Director",      dir_items,   R_DIRECTOR},
175    {"FileDaemon",    cli_items,   R_CLIENT},
176    {"Messages",      msgs_items,  R_MSGS},
177    {"Console",       cons_items,  R_CONSOLE},
178    {"Client",        cli_items,   R_CLIENT},     /* alias for filedaemon */
179    {NULL,            NULL,        0}
180 };
181
182 /* Cipher/Digest keyword structure */
183 struct s_ct {
184    const char *type_name;
185    int32_t type_value;
186 };
187
188 struct s_ct ciphertypes[] = {
189    {"aes128",        CRYPTO_CIPHER_AES_128_CBC},
190    {"aes192",        CRYPTO_CIPHER_AES_192_CBC},
191    {"aes256",        CRYPTO_CIPHER_AES_256_CBC},
192    {"blowfish",      CRYPTO_CIPHER_BLOWFISH_CBC},
193    {NULL,            0}
194 };
195
196 struct s_ct digesttypes[] = {
197    {"md5",         CRYPTO_DIGEST_MD5},
198    {"sha1",        CRYPTO_DIGEST_SHA1},
199    {"sha256",      CRYPTO_DIGEST_SHA256},
200 //   {"sha512",      CRYPTO_DIGEST_SHA512}, /* Not working yet */
201    {NULL,                             0}
202 };
203
204 /*
205  * Store cipher type
206  *
207  */
208 static void store_cipher_type(LEX *lc, RES_ITEM *item, int index, int pass)
209 {
210    int i;
211
212    lex_get_token(lc, T_NAME);
213    /* Store the type both pass 1 and pass 2 */
214    for (i=0; ciphertypes[i].type_name; i++) {
215       if (strcasecmp(lc->str, ciphertypes[i].type_name) == 0) {
216          *(uint32_t *)(item->value) = ciphertypes[i].type_value;
217          i = 0;
218          break;
219       }
220    }
221    if (i != 0) {
222       scan_err1(lc, _("Expected a Cipher Type keyword, got: %s"), lc->str);
223    }
224    scan_to_eol(lc);
225    set_bit(index, res_all.hdr.item_present);
226 }
227
228 /*
229  * Store digest type
230  *
231  */
232 static void store_digest_type(LEX *lc, RES_ITEM *item, int index, int pass)
233 {
234    int i;
235
236    lex_get_token(lc, T_NAME);
237    /* Store the type both pass 1 and pass 2 */
238    for (i=0; digesttypes[i].type_name; i++) {
239       if (strcasecmp(lc->str, digesttypes[i].type_name) == 0) {
240          *(uint32_t *)(item->value) = digesttypes[i].type_value;
241          i = 0;
242          break;
243       }
244    }
245    if (i != 0) {
246       scan_err1(lc, _("Expected a Cipher Type keyword, got: %s"), lc->str);
247    }
248    scan_to_eol(lc);
249    set_bit(index, res_all.hdr.item_present);
250 }
251
252 /* Dump contents of resource */
253 void dump_resource(int type, RES *ares, void sendit(void *sock, const char *fmt, ...), void *sock)
254 {
255    URES *res = (URES *)ares;
256    int recurse = 1;
257
258    if (res == NULL) {
259       sendit(sock, "No record for %d %s\n", type, res_to_str(type));
260       return;
261    }
262    if (type < 0) {                    /* no recursion */
263       type = - type;
264       recurse = 0;
265    }
266    switch (type) {
267    case R_CONSOLE:
268       sendit(sock, "Console: name=%s password=%s\n", ares->name,
269              res->res_cons.password);
270       break;
271    case R_DIRECTOR:
272       sendit(sock, "Director: name=%s password=%s\n", ares->name,
273               res->res_dir.password);
274       break;
275    case R_CLIENT:
276       sendit(sock, "Client: name=%s FDport=%d\n", ares->name,
277               get_first_port_host_order(res->res_client.FDaddrs));
278       break;
279    case R_MSGS:
280       sendit(sock, "Messages: name=%s\n", res->res_msgs.hdr.name);
281       if (res->res_msgs.mail_cmd)
282          sendit(sock, "      mailcmd=%s\n", res->res_msgs.mail_cmd);
283       if (res->res_msgs.operator_cmd)
284          sendit(sock, "      opcmd=%s\n", res->res_msgs.operator_cmd);
285       break;
286    default:
287       sendit(sock, "Unknown resource type %d\n", type);
288    }
289    ares = GetNextRes(type, ares);
290    if (recurse && ares) {
291       dump_resource(type, ares, sendit, sock);
292    }
293 }
294
295
296 /*
297  * Free memory of resource.
298  * NB, we don't need to worry about freeing any references
299  * to other resources as they will be freed when that
300  * resource chain is traversed.  Mainly we worry about freeing
301  * allocated strings (names).
302  */
303 void free_resource(RES *sres, int type)
304 {
305    URES *res = (URES *)sres;
306
307    if (res == NULL) {
308       return;
309    }
310
311    /* common stuff -- free the resource name */
312    if (res->res_dir.hdr.name) {
313       free(res->res_dir.hdr.name);
314    }
315    if (res->res_dir.hdr.desc) {
316       free(res->res_dir.hdr.desc);
317    }
318    switch (type) {
319    case R_DIRECTOR:
320       if (res->res_dir.password) {
321          free(res->res_dir.password);
322       }
323       if (res->res_dir.address) {
324          free(res->res_dir.address);
325       }
326       if (res->res_dir.tls_ctx) {
327          free_tls_context(res->res_dir.tls_ctx);
328       }
329       if (res->res_dir.tls_ca_certfile) {
330          free(res->res_dir.tls_ca_certfile);
331       }
332       if (res->res_dir.tls_ca_certdir) {
333          free(res->res_dir.tls_ca_certdir);
334       }
335       if (res->res_dir.tls_certfile) {
336          free(res->res_dir.tls_certfile);
337       }
338       if (res->res_dir.tls_keyfile) {
339          free(res->res_dir.tls_keyfile);
340       }
341       if (res->res_dir.tls_dhfile) {
342          free(res->res_dir.tls_dhfile);
343       }
344       if (res->res_dir.tls_allowed_cns) {
345          delete res->res_dir.tls_allowed_cns;
346       }
347       if (res->res_dir.disable_cmds) {
348          delete res->res_dir.disable_cmds;
349       }
350       if (res->res_dir.disabled_cmds_array) {
351          free(res->res_dir.disabled_cmds_array);
352       }
353       break;
354    case R_CONSOLE:
355       if (res->res_cons.password) {
356          free(res->res_cons.password);
357       }
358       if (res->res_cons.address) {
359          free(res->res_cons.address);
360       }
361       if (res->res_cons.tls_ctx) {
362          free_tls_context(res->res_cons.tls_ctx);
363       }
364       if (res->res_cons.tls_ca_certfile) {
365          free(res->res_cons.tls_ca_certfile);
366       }
367       if (res->res_cons.tls_ca_certdir) {
368          free(res->res_cons.tls_ca_certdir);
369       }
370       if (res->res_cons.tls_certfile) {
371          free(res->res_cons.tls_certfile);
372       }
373       if (res->res_cons.tls_keyfile) {
374          free(res->res_cons.tls_keyfile);
375       }
376       if (res->res_cons.tls_dhfile) {
377          free(res->res_cons.tls_dhfile);
378       }
379       if (res->res_cons.tls_allowed_cns) {
380          delete res->res_cons.tls_allowed_cns;
381       }
382       break;
383     case R_CLIENT:
384       if (res->res_client.working_directory) {
385          free(res->res_client.working_directory);
386       }
387       if (res->res_client.pid_directory) {
388          free(res->res_client.pid_directory);
389       }
390       if (res->res_client.subsys_directory) {
391          free(res->res_client.subsys_directory);
392       }
393       if (res->res_client.scripts_directory) {
394          free(res->res_client.scripts_directory);
395       }
396       if (res->res_client.plugin_directory) {
397          free(res->res_client.plugin_directory);
398       }
399       if (res->res_client.FDaddrs) {
400          free_addresses(res->res_client.FDaddrs);
401       }
402       if (res->res_client.FDsrc_addr) {
403          free_addresses(res->res_client.FDsrc_addr);
404       }
405       if (res->res_client.snapshot_command) {
406          free(res->res_client.snapshot_command);
407       }
408       if (res->res_client.pki_keypair_file) {
409          free(res->res_client.pki_keypair_file);
410       }
411       if (res->res_client.pki_keypair) {
412          crypto_keypair_free(res->res_client.pki_keypair);
413       }
414
415       if (res->res_client.pki_signing_key_files) {
416          delete res->res_client.pki_signing_key_files;
417       }
418       if (res->res_client.pki_signers) {
419          X509_KEYPAIR *keypair;
420          foreach_alist(keypair, res->res_client.pki_signers) {
421             crypto_keypair_free(keypair);
422          }
423          delete res->res_client.pki_signers;
424       }
425
426       if (res->res_client.pki_master_key_files) {
427          delete res->res_client.pki_master_key_files;
428       }
429
430       if (res->res_client.pki_recipients) {
431          X509_KEYPAIR *keypair;
432          foreach_alist(keypair, res->res_client.pki_recipients) {
433             crypto_keypair_free(keypair);
434          }
435          delete res->res_client.pki_recipients;
436       }
437
438       if (res->res_client.tls_ctx) {
439          free_tls_context(res->res_client.tls_ctx);
440       }
441       if (res->res_client.tls_ca_certfile) {
442          free(res->res_client.tls_ca_certfile);
443       }
444       if (res->res_client.tls_ca_certdir) {
445          free(res->res_client.tls_ca_certdir);
446       }
447       if (res->res_client.tls_certfile) {
448          free(res->res_client.tls_certfile);
449       }
450       if (res->res_client.tls_keyfile) {
451          free(res->res_client.tls_keyfile);
452       }
453       if (res->res_client.disable_cmds) {
454          delete res->res_client.disable_cmds;
455       }
456       if (res->res_client.disabled_cmds_array) {
457          free(res->res_client.disabled_cmds_array);
458       }
459       if (res->res_client.verid) {
460          free(res->res_client.verid);
461       }
462       break;
463    case R_MSGS:
464       if (res->res_msgs.mail_cmd) {
465          free(res->res_msgs.mail_cmd);
466       }
467       if (res->res_msgs.operator_cmd) {
468          free(res->res_msgs.operator_cmd);
469       }
470       free_msgs_res((MSGS *)res);  /* free message resource */
471       res = NULL;
472       break;
473    default:
474       printf(_("Unknown resource type %d\n"), type);
475    }
476    /* Common stuff again -- free the resource, recurse to next one */
477    if (res) {
478       free(res);
479    }
480 }
481
482 /* Save the new resource by chaining it into the head list for
483  * the resource. If this is pass 2, we update any resource
484  * pointers (currently only in the Job resource).
485  */
486 bool save_resource(CONFIG *config, int type, RES_ITEM *items, int pass)
487 {
488    URES *res;
489    CONSRES *cons;
490    int rindex = type - r_first;
491    int i, size;
492    int error = 0;
493
494    /*
495     * Ensure that all required items are present
496     */
497    for (i=0; items[i].name; i++) {
498       if (items[i].flags & ITEM_REQUIRED) {
499          if (!bit_is_set(i, res_all.res_dir.hdr.item_present)) {
500             Mmsg(config->m_errmsg, _("\"%s\" directive is required in \"%s\" resource, but not found.\n"),
501                  items[i].name, resources[rindex].name);
502             return false;
503          }
504       }
505    }
506
507    /* During pass 2, we looked up pointers to all the resources
508     * referrenced in the current resource, , now we
509     * must copy their address from the static record to the allocated
510     * record.
511     */
512    if (pass == 2) {
513       switch (type) {
514          /* Resources not containing a resource */
515          case R_MSGS:
516             break;
517
518          /* Resources containing another resource */
519          case R_DIRECTOR:
520             if ((res = (URES *)GetResWithName(R_DIRECTOR, res_all.res_dir.hdr.name)) == NULL) {
521                Mmsg(config->m_errmsg, _("Cannot find Director resource %s\n"), res_all.res_dir.hdr.name);
522                return false;
523             }
524             res->res_dir.tls_allowed_cns = res_all.res_dir.tls_allowed_cns;
525             res->res_dir.disable_cmds = res_all.res_dir.disable_cmds;
526             res->res_dir.console = res_all.res_dir.console;
527             if (res_all.res_dir.remote && !res_all.res_dir.console) {
528                if ((cons = (CONSRES *)GetNextRes(R_CONSOLE, NULL)) == NULL) {
529                   Mmsg(config->m_errmsg, _("Cannot find any Console resource for remote access\n"));
530                   return false;
531                }
532                res->res_dir.console = cons;
533             }
534             break;
535          /* Resources containing another resource */
536          case R_CONSOLE:
537             break;
538          case R_CLIENT:
539             if ((res = (URES *)GetResWithName(R_CLIENT, res_all.res_dir.hdr.name)) == NULL) {
540                Mmsg(config->m_errmsg, _("Cannot find Client resource %s\n"), res_all.res_dir.hdr.name);
541                return false;
542             }
543             res->res_client.pki_signing_key_files = res_all.res_client.pki_signing_key_files;
544             res->res_client.pki_master_key_files = res_all.res_client.pki_master_key_files;
545
546             res->res_client.pki_signers = res_all.res_client.pki_signers;
547             res->res_client.pki_recipients = res_all.res_client.pki_recipients;
548
549             res->res_client.messages = res_all.res_client.messages;
550             res->res_client.disable_cmds = res_all.res_client.disable_cmds;
551             break;
552          default:
553             Emsg1(M_ERROR, 0, _("Unknown resource type %d\n"), type);
554             error = 1;
555             break;
556       }
557       /* Note, the resoure name was already saved during pass 1,
558        * so here, we can just release it.
559        */
560       if (res_all.res_dir.hdr.name) {
561          free(res_all.res_dir.hdr.name);
562          res_all.res_dir.hdr.name = NULL;
563       }
564       if (res_all.res_dir.hdr.desc) {
565          free(res_all.res_dir.hdr.desc);
566          res_all.res_dir.hdr.desc = NULL;
567       }
568       return true;
569    }
570
571    /* The following code is only executed on pass 1 */
572    switch (type) {
573       case R_DIRECTOR:
574          size = sizeof(DIRRES);
575          break;
576       case R_CONSOLE:
577          size = sizeof(CONSRES);
578          break;
579       case R_CLIENT:
580          size = sizeof(CLIENT);
581          break;
582       case R_MSGS:
583          size = sizeof(MSGS);
584          break;
585       default:
586          printf(_("Unknown resource type %d\n"), type);
587          error = 1;
588          size = 1;
589          break;
590    }
591    /* Common */
592    if (!error) {
593       if (!config->insert_res(rindex, size)) {
594          return false;
595       }
596    }
597    return true;
598 }
599
600 bool parse_fd_config(CONFIG *config, const char *configfile, int exit_code)
601 {
602    config->init(configfile, NULL, exit_code, (void *)&res_all, res_all_size,
603       r_first, r_last, resources, &res_head);
604    return config->parse_config();
605 }