]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/lib/parse_conf.c
Add const for Solaris' C++ compiler
[bacula/bacula] / bacula / src / lib / parse_conf.c
1 /*
2  *   Master Configuration routines.
3  *  
4  *   This file contains the common parts of the Bacula
5  *   configuration routines.
6  *
7  *   Note, the configuration file parser consists of three parts
8  *
9  *   1. The generic lexical scanner in lib/lex.c and lib/lex.h
10  *
11  *   2. The generic config  scanner in lib/parse_conf.c and 
12  *      lib/parse_conf.h.
13  *      These files contain the parser code, some utility
14  *      routines, and the common store routines (name, int,
15  *      string).
16  *
17  *   3. The daemon specific file, which contains the Resource
18  *      definitions as well as any specific store routines
19  *      for the resource records.
20  *
21  *    N.B. This is a two pass parser, so if you malloc() a string
22  *         in a "store" routine, you must ensure to do it during
23  *         only one of the two passes, or to free it between.
24  *         Also, note that the resource record is malloced and
25  *         saved in save_resource() during pass 1.  Anything that
26  *         you want saved after pass two (e.g. resource pointers)
27  *         must explicitly be done in save_resource. Take a look
28  *         at the Job resource in src/dird/dird_conf.c to see how
29  *         it is done.
30  *
31  *     Kern Sibbald, January MM
32  *
33  *   Version $Id$
34  */
35
36 /*
37    Copyright (C) 2000-2003 Kern Sibbald and John Walker
38
39    This program is free software; you can redistribute it and/or
40    modify it under the terms of the GNU General Public License as
41    published by the Free Software Foundation; either version 2 of
42    the License, or (at your option) any later version.
43
44    This program is distributed in the hope that it will be useful,
45    but WITHOUT ANY WARRANTY; without even the implied warranty of
46    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
47    General Public License for more details.
48
49    You should have received a copy of the GNU General Public
50    License along with this program; if not, write to the Free
51    Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
52    MA 02111-1307, USA.
53
54  */
55
56
57 #include "bacula.h"
58
59 extern int debug_level;
60
61 /* Each daemon has a slightly different set of 
62  * resources, so it will define the following
63  * global values.
64  */
65 extern int r_first;
66 extern int r_last;
67 extern pthread_mutex_t res_mutex;
68 extern struct s_res resources[];
69 #ifdef HAVE_WIN32
70 // work around visual studio name manling preventing external linkage since res_all
71 // is declared as a different type when instantiated.
72 extern "C" CURES res_all;
73 extern "C" int res_all_size;
74 #else
75 extern  CURES res_all;
76 extern int res_all_size;
77 #endif
78
79
80 static bool res_locked = false;        /* set when resource chains locked */
81
82 /* Forward referenced subroutines */
83 static void scan_types(LEX *lc, MSGS *msg, int dest, char *where, char *cmd);
84
85
86 /* Common Resource definitions */
87
88 /* Message resource directives
89  *  name         handler      value       code   flags  default_value
90  */
91 struct res_items msgs_items[] = {
92    {"name",        store_name,    ITEM(res_msgs.hdr.name),  0, 0, 0},
93    {"description", store_str,     ITEM(res_msgs.hdr.desc),  0, 0, 0},
94    {"mailcommand", store_str,     ITEM(res_msgs.mail_cmd),  0, 0, 0},
95    {"operatorcommand", store_str, ITEM(res_msgs.operator_cmd), 0, 0, 0},
96    {"syslog",      store_msgs, ITEM(res_msgs), MD_SYSLOG,   0, 0}, 
97    {"mail",        store_msgs, ITEM(res_msgs), MD_MAIL,     0, 0},
98    {"mailonerror", store_msgs, ITEM(res_msgs), MD_MAIL_ON_ERROR, 0, 0},
99    {"file",        store_msgs, ITEM(res_msgs), MD_FILE,     0, 0},
100    {"append",      store_msgs, ITEM(res_msgs), MD_APPEND,   0, 0},
101    {"stdout",      store_msgs, ITEM(res_msgs), MD_STDOUT,   0, 0},
102    {"stderr",      store_msgs, ITEM(res_msgs), MD_STDERR,   0, 0},
103    {"director",    store_msgs, ITEM(res_msgs), MD_DIRECTOR, 0, 0},
104    {"console",     store_msgs, ITEM(res_msgs), MD_CONSOLE,  0, 0},   
105    {"operator",    store_msgs, ITEM(res_msgs), MD_OPERATOR, 0, 0},
106    {NULL, NULL,    NULL, 0}
107 };
108
109 struct s_mtypes {       
110    const char *name;
111    int token;   
112 };
113 /* Various message types */
114 static struct s_mtypes msg_types[] = {
115    {"debug",         M_DEBUG},
116    {"abort",         M_ABORT},
117    {"fatal",         M_FATAL},
118    {"error",         M_ERROR},
119    {"warning",       M_WARNING},
120    {"info",          M_INFO},
121    {"saved",         M_SAVED},
122    {"notsaved",      M_NOTSAVED},
123    {"skipped",       M_SKIPPED},
124    {"mount",         M_MOUNT},
125    {"terminate",     M_TERM},
126    {"restored",      M_RESTORED},
127    {"all",           M_MAX+1},
128    {NULL,            0}
129 };
130
131
132 /* Simply print a message */
133 static void prtmsg(void *sock, char *fmt, ...)
134 {
135    va_list arg_ptr;
136
137    va_start(arg_ptr, fmt);
138    vfprintf(stdout, fmt, arg_ptr);
139    va_end(arg_ptr);
140 }
141
142 const char *res_to_str(int rcode)
143 {
144    if (rcode < r_first || rcode > r_last) {
145       return _("***UNKNOWN***");
146    } else {
147       return resources[rcode-r_first].name;
148    }
149 }
150
151
152 /* 
153  * Initialize the static structure to zeros, then
154  *  apply all the default values.
155  */
156 void init_resource(int type, struct res_items *items)
157 {
158    int i;
159    int rindex = type - r_first;
160
161    memset(&res_all, 0, res_all_size);
162    res_all.hdr.rcode = type;
163    res_all.hdr.refcnt = 1;
164
165    for (i=0; items[i].name; i++) {
166       Dmsg3(300, "Item=%s def=%s defval=%d\n", items[i].name,
167             (items[i].flags & ITEM_DEFAULT) ? "yes" : "no",      
168             items[i].default_value);
169       if (items[i].flags & ITEM_DEFAULT && items[i].default_value != 0) {
170          if (items[i].handler == store_yesno) {
171             *(int *)(items[i].value) |= items[i].code;
172          } else if (items[i].handler == store_pint || 
173                     items[i].handler == store_int) {
174             *(int *)(items[i].value) = items[i].default_value;
175          } else if (items[i].handler == store_int64) {
176             *(int64_t *)(items[i].value) = items[i].default_value;
177          } else if (items[i].handler == store_size) {
178             *(uint64_t *)(items[i].value) = (uint64_t)items[i].default_value;
179          } else if (items[i].handler == store_time) {
180             *(utime_t *)(items[i].value) = (utime_t)items[i].default_value;
181          }
182       }
183       /* If this triggers, take a look at lib/parse_conf.h */
184       if (i >= MAX_RES_ITEMS) {
185          Emsg1(M_ERROR_TERM, 0, _("Too many items in %s resource\n"), resources[rindex]);
186       }
187    }
188 }
189
190
191 /* Store Messages Destination information */
192 void store_msgs(LEX *lc, struct res_items *item, int index, int pass)
193 {
194    int token;
195    char *cmd;
196    POOLMEM *dest;
197    int dest_len;    
198
199    Dmsg2(200, "store_msgs pass=%d code=%d\n", pass, item->code);
200    if (pass == 1) {
201       switch (item->code) {
202       case MD_STDOUT:
203       case MD_STDERR:
204       case MD_SYSLOG:              /* syslog */
205       case MD_CONSOLE:
206          scan_types(lc, (MSGS *)(item->value), item->code, NULL, NULL);
207          break;
208       case MD_OPERATOR:            /* send to operator */
209       case MD_DIRECTOR:            /* send to Director */
210       case MD_MAIL:                /* mail */
211       case MD_MAIL_ON_ERROR:       /* mail if Job errors */
212          if (item->code == MD_OPERATOR) {
213             cmd = res_all.res_msgs.operator_cmd;
214          } else {
215             cmd = res_all.res_msgs.mail_cmd;
216          }
217          dest = get_pool_memory(PM_MESSAGE);
218          dest[0] = 0;
219          dest_len = 0;
220          /* Pick up comma separated list of destinations */
221          for ( ;; ) {
222             token = lex_get_token(lc, T_NAME);   /* scan destination */
223             dest = check_pool_memory_size(dest, dest_len + lc->str_len + 2);
224             if (dest[0] != 0) {
225                pm_strcat(&dest, " ");  /* separate multiple destinations with space */
226                dest_len++;
227             }
228             pm_strcat(&dest, lc->str);
229             dest_len += lc->str_len;
230             Dmsg2(100, "store_msgs newdest=%s: dest=%s:\n", lc->str, NPRT(dest));
231             token = lex_get_token(lc, T_ALL);
232             if (token == T_COMMA) { 
233                continue;           /* get another destination */
234             }
235             if (token != T_EQUALS) {
236                scan_err1(lc, _("expected an =, got: %s"), lc->str); 
237             }
238             break;
239          }
240          Dmsg1(200, "mail_cmd=%s\n", NPRT(cmd));
241          scan_types(lc, (MSGS *)(item->value), item->code, dest, cmd);
242          free_pool_memory(dest);
243          Dmsg0(200, "done with dest codes\n");
244          break;
245       case MD_FILE:                /* file */
246       case MD_APPEND:              /* append */
247          dest = get_pool_memory(PM_MESSAGE);
248          /* Pick up a single destination */
249          token = lex_get_token(lc, T_NAME);   /* scan destination */
250          pm_strcpy(&dest, lc->str);
251          dest_len = lc->str_len;
252          token = lex_get_token(lc, T_ALL);
253          Dmsg1(200, "store_msgs dest=%s:\n", NPRT(dest));
254          if (token != T_EQUALS) {
255             scan_err1(lc, _("expected an =, got: %s"), lc->str); 
256          }
257          scan_types(lc, (MSGS *)(item->value), item->code, dest, NULL);
258          free_pool_memory(dest);
259          Dmsg0(200, "done with dest codes\n");
260          break;
261
262       default:
263          scan_err1(lc, _("Unknown item code: %d\n"), item->code);
264          break;
265       }
266    }
267    scan_to_eol(lc);
268    set_bit(index, res_all.hdr.item_present);
269    Dmsg0(200, "Done store_msgs\n");
270 }
271
272 /* 
273  * Scan for message types and add them to the message
274  * destination. The basic job here is to connect message types
275  *  (WARNING, ERROR, FATAL, INFO, ...) with an appropriate
276  *  destination (MAIL, FILE, OPERATOR, ...)
277  */
278 static void scan_types(LEX *lc, MSGS *msg, int dest_code, char *where, char *cmd)
279 {
280    int i, found, quit, is_not;
281    int msg_type = 0;
282    char *str;
283
284    for (quit=0; !quit;) {
285       lex_get_token(lc, T_NAME);            /* expect at least one type */       
286       found = FALSE;
287       if (lc->str[0] == '!') {
288          is_not = TRUE;
289          str = &lc->str[1];
290       } else {
291          is_not = FALSE;
292          str = &lc->str[0];
293       }
294       for (i=0; msg_types[i].name; i++) {
295          if (strcasecmp(str, msg_types[i].name) == 0) {
296             msg_type = msg_types[i].token;
297             found = TRUE;
298             break;
299          }
300       }
301       if (!found) {
302          scan_err1(lc, _("message type: %s not found"), str);
303          /* NOT REACHED */
304       }
305
306       if (msg_type == M_MAX+1) {         /* all? */
307          for (i=1; i<=M_MAX; i++) {      /* yes set all types */
308             add_msg_dest(msg, dest_code, i, where, cmd);
309          }
310       } else {
311          if (is_not) {
312             rem_msg_dest(msg, dest_code, msg_type, where);
313          } else {
314             add_msg_dest(msg, dest_code, msg_type, where, cmd);
315          }
316       }
317       if (lc->ch != ',') {
318          break;
319       }
320       Dmsg0(200, "call lex_get_token() to eat comma\n");
321       lex_get_token(lc, T_ALL);          /* eat comma */
322    }
323    Dmsg0(200, "Done scan_types()\n");
324 }
325
326
327 /* 
328  * This routine is ONLY for resource names
329  *  Store a name at specified address.
330  */
331 void store_name(LEX *lc, struct res_items *item, int index, int pass)
332 {
333    POOLMEM *msg = get_pool_memory(PM_EMSG);
334    lex_get_token(lc, T_NAME);
335    if (!is_name_valid(lc->str, &msg)) {
336       scan_err1(lc, "%s\n", msg);
337    }
338    free_pool_memory(msg);
339    /* Store the name both pass 1 and pass 2 */
340    if (*(item->value)) {
341       scan_err2(lc, _("Attempt to redefine name \"%s\" to \"%s\"."), 
342          *(item->value), lc->str);
343    }
344    *(item->value) = bstrdup(lc->str);
345    scan_to_eol(lc);
346    set_bit(index, res_all.hdr.item_present);
347 }
348
349
350 /*
351  * Store a name string at specified address
352  * A name string is limited to MAX_RES_NAME_LENGTH
353  */
354 void store_strname(LEX *lc, struct res_items *item, int index, int pass)
355 {
356    lex_get_token(lc, T_NAME);
357    /* Store the name */
358    if (pass == 1) {
359       *(item->value) = bstrdup(lc->str);
360    }
361    scan_to_eol(lc);
362    set_bit(index, res_all.hdr.item_present);
363 }
364
365 /* Store a string at specified address */
366 void store_str(LEX *lc, struct res_items *item, int index, int pass)
367 {
368    lex_get_token(lc, T_STRING);
369    if (pass == 1) {
370       *(item->value) = bstrdup(lc->str);
371    }
372    scan_to_eol(lc);
373    set_bit(index, res_all.hdr.item_present);
374 }
375
376 /*
377  * Store a directory name at specified address. Note, we do
378  *   shell expansion except if the string begins with a vertical
379  *   bar (i.e. it will likely be passed to the shell later).
380  */
381 void store_dir(LEX *lc, struct res_items *item, int index, int pass)
382 {
383    lex_get_token(lc, T_STRING);
384    if (pass == 1) {
385       if (lc->str[0] != '|') {
386          do_shell_expansion(lc->str, sizeof(lc->str));
387       }
388       *(item->value) = bstrdup(lc->str);
389    }
390    scan_to_eol(lc);
391    set_bit(index, res_all.hdr.item_present);
392 }
393
394
395 /* Store a password specified address in MD5 coding */
396 void store_password(LEX *lc, struct res_items *item, int index, int pass)
397 {
398    unsigned int i, j;
399    struct MD5Context md5c;
400    unsigned char signature[16];
401    char sig[100];
402
403
404    lex_get_token(lc, T_STRING);
405    if (pass == 1) {
406       MD5Init(&md5c);
407       MD5Update(&md5c, (unsigned char *) (lc->str), lc->str_len);
408       MD5Final(signature, &md5c);
409       for (i = j = 0; i < sizeof(signature); i++) {
410          sprintf(&sig[j], "%02x", signature[i]); 
411          j += 2;
412       }
413       *(item->value) = bstrdup(sig);
414    }
415    scan_to_eol(lc);
416    set_bit(index, res_all.hdr.item_present);
417 }
418
419
420 /* Store a resource at specified address.
421  * If we are in pass 2, do a lookup of the 
422  * resource.
423  */
424 void store_res(LEX *lc, struct res_items *item, int index, int pass)
425 {
426    RES *res;
427
428    lex_get_token(lc, T_NAME);
429    if (pass == 2) {
430      res = GetResWithName(item->code, lc->str);
431      if (res == NULL) {
432         scan_err3(lc, _("Could not find config Resource %s referenced on line %d : %s\n"), 
433            lc->str, lc->line_no, lc->line);
434      }
435      *(item->value) = (char *)res;
436    }
437    scan_to_eol(lc);
438    set_bit(index, res_all.hdr.item_present);
439 }
440
441 /*
442  * Store default values for Resource from xxxDefs
443  * If we are in pass 2, do a lookup of the 
444  * resource and store everything not explicitly set
445  * in main resource.
446  *
447  * Note, here item points to the main resource (e.g. Job, not
448  *  the jobdefs, which we look up).
449  */
450 void store_defs(LEX *lc, struct res_items *item, int index, int pass)
451 {
452    RES *res;
453
454    lex_get_token(lc, T_NAME);
455    if (pass == 2) {
456      Dmsg2(200, "Code=%d name=%s\n", item->code, lc->str);
457      res = GetResWithName(item->code, lc->str);
458      if (res == NULL) {
459         scan_err3(lc, _("Missing config Resource \"%s\" referenced on line %d : %s\n"), 
460            lc->str, lc->line_no, lc->line);
461      }
462      /* for each item not set, we copy the field from res */
463 #ifdef xxx
464      for (int i=0; item->name;; i++, item++) {
465         if (bit_is_set(i, res->item_present)) {
466            Dmsg2(000, "Item %d is present in %s\n", i, res->name);
467         } else {
468            Dmsg2(000, "Item %d is not present in %s\n", i, res->name);
469         }
470      }
471      /* ***FIXME **** add code */
472 #endif
473    }
474    scan_to_eol(lc);
475 }
476
477
478
479 /* Store an integer at specified address */
480 void store_int(LEX *lc, struct res_items *item, int index, int pass)
481 {
482    lex_get_token(lc, T_INT32);
483    *(int *)(item->value) = lc->int32_val;
484    scan_to_eol(lc);
485    set_bit(index, res_all.hdr.item_present);
486 }
487
488 /* Store a positive integer at specified address */
489 void store_pint(LEX *lc, struct res_items *item, int index, int pass)
490 {
491    lex_get_token(lc, T_PINT32);
492    *(int *)(item->value) = lc->pint32_val;
493    scan_to_eol(lc);
494    set_bit(index, res_all.hdr.item_present);
495 }
496
497
498 /* Store an 64 bit integer at specified address */
499 void store_int64(LEX *lc, struct res_items *item, int index, int pass)
500 {
501    lex_get_token(lc, T_INT64);
502    *(int64_t *)(item->value) = lc->int64_val;
503    scan_to_eol(lc);
504    set_bit(index, res_all.hdr.item_present);
505 }
506
507 /* Store a size in bytes */
508 void store_size(LEX *lc, struct res_items *item, int index, int pass)
509 {
510    int token;
511    uint64_t uvalue;
512
513    Dmsg0(400, "Enter store_size\n");
514    token = lex_get_token(lc, T_ALL);
515    errno = 0;
516    switch (token) {
517    case T_NUMBER:
518    case T_IDENTIFIER:
519    case T_UNQUOTED_STRING:
520       if (!size_to_uint64(lc->str, lc->str_len, &uvalue)) {
521          scan_err1(lc, _("expected a size number, got: %s"), lc->str);
522       }
523       *(uint64_t *)(item->value) = uvalue;
524       break;
525    default:
526       scan_err1(lc, _("expected a size, got: %s"), lc->str);
527       break;
528    }
529    scan_to_eol(lc);
530    set_bit(index, res_all.hdr.item_present);
531    Dmsg0(400, "Leave store_size\n");
532 }
533
534
535 /* Store a time period in seconds */
536 void store_time(LEX *lc, struct res_items *item, int index, int pass)
537 {
538    int token; 
539    utime_t utime;
540    char period[500];
541
542    token = lex_get_token(lc, T_ALL);
543    errno = 0;
544    switch (token) {
545    case T_NUMBER:
546    case T_IDENTIFIER:
547    case T_UNQUOTED_STRING:
548       bstrncpy(period, lc->str, sizeof(period));
549       if (lc->ch == ' ') {
550          token = lex_get_token(lc, T_ALL);
551          switch (token) {
552          case T_IDENTIFIER:
553          case T_UNQUOTED_STRING:
554             bstrncat(period, lc->str, sizeof(period));
555             break;
556          }
557       }
558       if (!duration_to_utime(period, &utime)) {
559          scan_err1(lc, _("expected a time period, got: %s"), period);
560       }
561       *(utime_t *)(item->value) = utime;
562       break;
563    default:
564       scan_err1(lc, _("expected a time period, got: %s"), lc->str);
565       break;
566    }
567    if (token != T_EOL) {
568       scan_to_eol(lc);
569    }
570    set_bit(index, res_all.hdr.item_present);
571 }
572
573
574 /* Store a yes/no in a bit field */
575 void store_yesno(LEX *lc, struct res_items *item, int index, int pass)
576 {
577    lex_get_token(lc, T_NAME);
578    if (strcasecmp(lc->str, "yes") == 0) {
579       *(int *)(item->value) |= item->code;
580    } else if (strcasecmp(lc->str, "no") == 0) {
581       *(int *)(item->value) &= ~(item->code);
582    } else {
583       scan_err1(lc, _("Expect a YES or NO, got: %s"), lc->str);
584    }
585    scan_to_eol(lc);
586    set_bit(index, res_all.hdr.item_present);
587 }
588
589
590
591 void LockRes()
592 {
593    P(res_mutex);
594    res_locked = true;
595 }
596
597 void UnlockRes()
598 {
599    res_locked = false;
600    V(res_mutex);
601 }
602
603 /*
604  * Return resource of type rcode that matches name
605  */
606 RES *
607 GetResWithName(int rcode, char *name)
608 {
609    RES *res;
610    int rindex = rcode - r_first;
611
612    LockRes();
613    res = resources[rindex].res_head;
614    while (res) {
615       if (strcmp(res->name, name) == 0) {
616          break;
617       }
618       res = res->next;
619    }
620    UnlockRes();
621    return res;
622    
623 }
624
625 /*
626  * Return next resource of type rcode. On first
627  * call second arg (res) is NULL, on subsequent
628  * calls, it is called with previous value.
629  */
630 RES *
631 GetNextRes(int rcode, RES *res)
632 {
633    RES *nres;
634    int rindex = rcode - r_first;
635        
636
637    if (!res_locked) {
638       Emsg0(M_ABORT, 0, "Resource chain not locked.\n");
639    }
640    if (res == NULL) {
641       nres = resources[rindex].res_head;
642    } else {
643       nres = res->next;
644    }
645    return nres;
646 }
647
648
649 /* Parser state */
650 enum parse_state {
651    p_none,
652    p_resource
653 };
654
655 /*********************************************************************
656  *
657  *      Parse configuration file
658  *
659  */
660 void 
661 parse_config(char *cf)
662 {
663    LEX *lc = NULL;
664    int token, i, pass;
665    int res_type = 0;
666    enum parse_state state = p_none;
667    struct res_items *items = NULL;
668    int level = 0;
669
670    /* Make two passes. The first builds the name symbol table,
671     * and the second picks up the items. 
672     */
673    Dmsg0(200, "Enter parse_config()\n");
674    for (pass=1; pass <= 2; pass++) {
675       Dmsg1(200, "parse_config pass %d\n", pass);
676       lc = lex_open_file(lc, cf, NULL);
677       while ((token=lex_get_token(lc, T_ALL)) != T_EOF) {
678          Dmsg1(150, "parse got token=%s\n", lex_tok_to_str(token));
679          switch (state) {
680             case p_none:
681                if (token == T_EOL) {
682                   break;
683                }
684                if (token != T_IDENTIFIER) {
685                   scan_err1(lc, _("Expected a Resource name identifier, got: %s"), lc->str);
686                   /* NOT REACHED */
687                }
688                for (i=0; resources[i].name; i++)
689                   if (strcasecmp(resources[i].name, lc->str) == 0) {
690                      state = p_resource;
691                      items = resources[i].items;
692                      res_type = resources[i].rcode;
693                      init_resource(res_type, items);
694                      break;
695                   }
696                if (state == p_none) {
697                   scan_err1(lc, _("expected resource name, got: %s"), lc->str);
698                   /* NOT REACHED */
699                }
700                break;
701             case p_resource:
702                switch (token) {
703                   case T_BOB:
704                      level++;
705                      break;
706                   case T_IDENTIFIER:
707                      if (level != 1) {
708                         scan_err1(lc, _("not in resource definition: %s"), lc->str);
709                         /* NOT REACHED */
710                      }
711                      for (i=0; items[i].name; i++) {
712                         if (strcasecmp(items[i].name, lc->str) == 0) {
713                            /* If the ITEM_NO_EQUALS flag is set we do NOT              
714                             *   scan for = after the keyword  */
715                            if (!(items[i].flags & ITEM_NO_EQUALS)) {
716                               token = lex_get_token(lc, T_ALL);
717                               Dmsg1 (150, "in T_IDENT got token=%s\n", lex_tok_to_str(token));
718                               if (token != T_EQUALS) {
719                                  scan_err1(lc, _("expected an equals, got: %s"), lc->str);
720                                  /* NOT REACHED */
721                               }
722                            }
723                            Dmsg1(150, "calling handler for %s\n", items[i].name);
724                            /* Call item handler */
725                            items[i].handler(lc, &items[i], i, pass);
726                            i = -1;
727                            break;
728                         }
729                      }
730                      if (i >= 0) {
731                         Dmsg2(150, "level=%d id=%s\n", level, lc->str);
732                         Dmsg1(150, "Keyword = %s\n", lc->str);
733                         scan_err1(lc, _("Keyword \"%s\" not permitted in this resource.\n"
734                            "Perhaps you left the trailing brace off of the previous resource."), lc->str);
735                         /* NOT REACHED */
736                      }
737                      break;
738
739                   case T_EOB:
740                      level--;
741                      state = p_none;
742                      Dmsg0(150, "T_EOB => define new resource\n");
743                      save_resource(res_type, items, pass);  /* save resource */
744                      break;
745
746                   case T_EOL:
747                      break;
748
749                   default:
750                      scan_err2(lc, _("unexpected token %d %s in resource definition"),    
751                         token, lex_tok_to_str(token));
752                      /* NOT REACHED */
753                }
754                break;
755             default:
756                scan_err1(lc, _("Unknown parser state %d\n"), state);
757                /* NOT REACHED */
758          }
759       }
760       if (state != p_none) {
761          scan_err0(lc, _("End of conf file reached with unclosed resource."));
762       }
763       if (debug_level > 50 && pass == 2) {
764          int i;
765          for (i=r_first; i<=r_last; i++) {
766             dump_resource(i, resources[i-r_first].res_head, prtmsg, NULL);
767          }
768       }
769       lc = lex_close_file(lc);
770    }
771    Dmsg0(200, "Leave parse_config()\n");
772 }
773
774 /*********************************************************************
775  *
776  *      Free configuration resources
777  *
778  */
779 void 
780 free_config_resources()
781 {
782    int i;
783    for (i=r_first; i<=r_last; i++) {
784       free_resource(i);
785    }
786 }