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