]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/lib/parse_conf.c
Fix over-zellous restriction of chars in Names
[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 int res_locked = 0;             /* 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                strcat(dest, " ");  /* separate multiple destinations with space */
218                dest_len++;
219             }
220             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    *(item->value) = bstrdup(lc->str);
333    scan_to_eol(lc);
334    set_bit(index, res_all.hdr.item_present);
335 }
336
337
338 /*
339  * Store a name string at specified address
340  * A name string is limited to MAX_RES_NAME_LENGTH
341  */
342 void store_strname(LEX *lc, struct res_items *item, int index, int pass)
343 {
344    lex_get_token(lc, T_NAME);
345    /* Store the name */
346    if (pass == 1) {
347       *(item->value) = bstrdup(lc->str);
348    }
349    scan_to_eol(lc);
350    set_bit(index, res_all.hdr.item_present);
351 }
352
353 /* Store a string at specified address */
354 void store_str(LEX *lc, struct res_items *item, int index, int pass)
355 {
356    lex_get_token(lc, T_STRING);
357    if (pass == 1) {
358       *(item->value) = bstrdup(lc->str);
359    }
360    scan_to_eol(lc);
361    set_bit(index, res_all.hdr.item_present);
362 }
363
364 /*
365  * Store a directory name at specified address. Note, we do
366  *   shell expansion except if the string begins with a vertical
367  *   bar (i.e. it will likely be passed to the shell later).
368  */
369 void store_dir(LEX *lc, struct res_items *item, int index, int pass)
370 {
371    lex_get_token(lc, T_STRING);
372    if (pass == 1) {
373       if (lc->str[0] != '|') {
374          do_shell_expansion(lc->str, sizeof(lc->str));
375       }
376       *(item->value) = bstrdup(lc->str);
377    }
378    scan_to_eol(lc);
379    set_bit(index, res_all.hdr.item_present);
380 }
381
382
383 /* Store a password specified address in MD5 coding */
384 void store_password(LEX *lc, struct res_items *item, int index, int pass)
385 {
386    unsigned int i, j;
387    struct MD5Context md5c;
388    unsigned char signature[16];
389    char sig[100];
390
391
392    lex_get_token(lc, T_STRING);
393    if (pass == 1) {
394       MD5Init(&md5c);
395       MD5Update(&md5c, (unsigned char *) (lc->str), lc->str_len);
396       MD5Final(signature, &md5c);
397       for (i = j = 0; i < sizeof(signature); i++) {
398          sprintf(&sig[j], "%02x", signature[i]); 
399          j += 2;
400       }
401       *(item->value) = bstrdup(sig);
402    }
403    scan_to_eol(lc);
404    set_bit(index, res_all.hdr.item_present);
405 }
406
407
408 /* Store a resource at specified address.
409  * If we are in pass 2, do a lookup of the 
410  * resource.
411  */
412 void store_res(LEX *lc, struct res_items *item, int index, int pass)
413 {
414    RES *res;
415
416    lex_get_token(lc, T_NAME);
417    if (pass == 2) {
418      res = GetResWithName(item->code, lc->str);
419      if (res == NULL) {
420         scan_err3(lc, _("Could not find config Resource %s referenced on line %d : %s\n"), 
421            lc->str, lc->line_no, lc->line);
422      }
423      *(item->value) = (char *)res;
424    }
425    scan_to_eol(lc);
426    set_bit(index, res_all.hdr.item_present);
427 }
428
429 /* Store default values for Resource from xxxDefs
430  * If we are in pass 2, do a lookup of the 
431  * resource and store everything not explicitly set
432  * in main resource.
433  *
434  * Note, here item points to the main resource (e.g. Job, not
435  *  the jobdefs, which we look up).
436  */
437 void store_defs(LEX *lc, struct res_items *item, int index, int pass)
438 {
439    RES *res;
440
441    lex_get_token(lc, T_NAME);
442    if (pass == 2) {
443      res = GetResWithName(item->code, lc->str);
444      if (res == NULL) {
445         scan_err3(lc, _("Could not find config Resource %s referenced on line %d : %s\n"), 
446            lc->str, lc->line_no, lc->line);
447      }
448      /* for each item not set, we copy the field from item */
449      /* ***FIXME **** add code */
450    }
451    scan_to_eol(lc);
452 }
453
454
455
456 /* Store an integer at specified address */
457 void store_int(LEX *lc, struct res_items *item, int index, int pass)
458 {
459    lex_get_token(lc, T_INT32);
460    *(int *)(item->value) = lc->int32_val;
461    scan_to_eol(lc);
462    set_bit(index, res_all.hdr.item_present);
463 }
464
465 /* Store a positive integer at specified address */
466 void store_pint(LEX *lc, struct res_items *item, int index, int pass)
467 {
468    lex_get_token(lc, T_PINT32);
469    *(int *)(item->value) = lc->pint32_val;
470    scan_to_eol(lc);
471    set_bit(index, res_all.hdr.item_present);
472 }
473
474
475 /* Store an 64 bit integer at specified address */
476 void store_int64(LEX *lc, struct res_items *item, int index, int pass)
477 {
478    lex_get_token(lc, T_INT64);
479    *(int64_t *)(item->value) = lc->int64_val;
480    scan_to_eol(lc);
481    set_bit(index, res_all.hdr.item_present);
482 }
483
484 /* Store a size in bytes */
485 void store_size(LEX *lc, struct res_items *item, int index, int pass)
486 {
487    int token;
488    uint64_t uvalue;
489
490    Dmsg0(400, "Enter store_size\n");
491    token = lex_get_token(lc, T_ALL);
492    errno = 0;
493    switch (token) {
494    case T_NUMBER:
495    case T_IDENTIFIER:
496    case T_UNQUOTED_STRING:
497       if (!size_to_uint64(lc->str, lc->str_len, &uvalue)) {
498          scan_err1(lc, "expected a size number, got: %s", lc->str);
499       }
500       *(uint64_t *)(item->value) = uvalue;
501       break;
502    default:
503       scan_err1(lc, "expected a size, got: %s", lc->str);
504       break;
505    }
506    scan_to_eol(lc);
507    set_bit(index, res_all.hdr.item_present);
508    Dmsg0(400, "Leave store_size\n");
509 }
510
511
512 /* Store a time period in seconds */
513 void store_time(LEX *lc, struct res_items *item, int index, int pass)
514 {
515    int token; 
516    utime_t utime;
517    char period[500];
518
519    token = lex_get_token(lc, T_ALL);
520    errno = 0;
521    switch (token) {
522    case T_NUMBER:
523    case T_IDENTIFIER:
524    case T_UNQUOTED_STRING:
525       bstrncpy(period, lc->str, sizeof(period));
526       if (lc->ch == ' ') {
527          token = lex_get_token(lc, T_ALL);
528          switch (token) {
529          case T_IDENTIFIER:
530          case T_UNQUOTED_STRING:
531             bstrncat(period, lc->str, sizeof(period));
532             break;
533          }
534       }
535       if (!duration_to_utime(period, &utime)) {
536          scan_err1(lc, "expected a time period, got: %s", period);
537       }
538       *(utime_t *)(item->value) = utime;
539       break;
540    default:
541       scan_err1(lc, "expected a time period, got: %s", lc->str);
542       break;
543    }
544    if (token != T_EOL) {
545       scan_to_eol(lc);
546    }
547    set_bit(index, res_all.hdr.item_present);
548 }
549
550
551 /* Store a yes/no in a bit field */
552 void store_yesno(LEX *lc, struct res_items *item, int index, int pass)
553 {
554    lex_get_token(lc, T_NAME);
555    if (strcasecmp(lc->str, "yes") == 0) {
556       *(int *)(item->value) |= item->code;
557    } else if (strcasecmp(lc->str, "no") == 0) {
558       *(int *)(item->value) &= ~(item->code);
559    } else {
560       scan_err1(lc, "Expect a YES or NO, got: %s", lc->str);
561    }
562    scan_to_eol(lc);
563    set_bit(index, res_all.hdr.item_present);
564 }
565
566
567
568 void LockRes()
569 {
570    P(res_mutex);
571    res_locked = 1;
572 }
573
574 void UnlockRes()
575 {
576    res_locked = 0;
577    V(res_mutex);
578 }
579
580 /*
581  * Return resource of type rcode that matches name
582  */
583 RES *
584 GetResWithName(int rcode, char *name)
585 {
586    RES *res;
587    int rindex = rcode - r_first;
588
589    LockRes();
590    res = resources[rindex].res_head;
591    while (res) {
592       if (strcmp(res->name, name) == 0) {
593          break;
594       }
595       res = res->next;
596    }
597    UnlockRes();
598    return res;
599    
600 }
601
602 /*
603  * Return next resource of type rcode. On first
604  * call second arg (res) is NULL, on subsequent
605  * calls, it is called with previous value.
606  */
607 RES *
608 GetNextRes(int rcode, RES *res)
609 {
610    RES *nres;
611    int rindex = rcode - r_first;
612        
613
614    if (!res_locked) {
615       Emsg0(M_ABORT, 0, "Resource chain not locked.\n");
616    }
617    if (res == NULL) {
618       nres = resources[rindex].res_head;
619    } else {
620       nres = res->next;
621    }
622    return nres;
623 }
624
625
626 /* Parser state */
627 enum parse_state {
628    p_none,
629    p_resource
630 };
631
632 /*********************************************************************
633  *
634  *      Parse configuration file
635  *
636  */
637 void 
638 parse_config(char *cf)
639 {
640    LEX *lc = NULL;
641    int token, i, pass;
642    int res_type = 0;
643    enum parse_state state = p_none;
644    struct res_items *items = NULL;
645    int level = 0;
646
647    /* Make two passes. The first builds the name symbol table,
648     * and the second picks up the items. 
649     */
650    Dmsg0(200, "Enter parse_config()\n");
651    for (pass=1; pass <= 2; pass++) {
652       Dmsg1(200, "parse_config pass %d\n", pass);
653       lc = lex_open_file(lc, cf, NULL);
654       while ((token=lex_get_token(lc, T_ALL)) != T_EOF) {
655          Dmsg1(150, "parse got token=%s\n", lex_tok_to_str(token));
656          switch (state) {
657             case p_none:
658                if (token == T_EOL) {
659                   break;
660                }
661                if (token != T_IDENTIFIER) {
662                   scan_err1(lc, "Expected a Resource name identifier, got: %s", lc->str);
663                   /* NOT REACHED */
664                }
665                for (i=0; resources[i].name; i++)
666                   if (strcasecmp(resources[i].name, lc->str) == 0) {
667                      state = p_resource;
668                      items = resources[i].items;
669                      res_type = resources[i].rcode;
670                      init_resource(res_type, items);
671                      break;
672                   }
673                if (state == p_none) {
674                   scan_err1(lc, "expected resource name, got: %s", lc->str);
675                   /* NOT REACHED */
676                }
677                break;
678             case p_resource:
679                switch (token) {
680                   case T_BOB:
681                      level++;
682                      break;
683                   case T_IDENTIFIER:
684                      if (level != 1) {
685                         scan_err1(lc, "not in resource definition: %s", lc->str);
686                         /* NOT REACHED */
687                      }
688                      for (i=0; items[i].name; i++) {
689                         if (strcasecmp(items[i].name, lc->str) == 0) {
690                            /* If the ITEM_NO_EQUALS flag is set we do NOT              
691                             *   scan for = after the keyword  */
692                            if (!(items[i].flags & ITEM_NO_EQUALS)) {
693                               token = lex_get_token(lc, T_ALL);
694                               Dmsg1 (150, "in T_IDENT got token=%s\n", lex_tok_to_str(token));
695                               if (token != T_EQUALS) {
696                                  scan_err1(lc, "expected an equals, got: %s", lc->str);
697                                  /* NOT REACHED */
698                               }
699                            }
700                            Dmsg1(150, "calling handler for %s\n", items[i].name);
701                            /* Call item handler */
702                            items[i].handler(lc, &items[i], i, pass);
703                            i = -1;
704                            break;
705                         }
706                      }
707                      if (i >= 0) {
708                         Dmsg2(150, "level=%d id=%s\n", level, lc->str);
709                         Dmsg1(150, "Keyword = %s\n", lc->str);
710                         scan_err1(lc, "Keyword \"%s\" not permitted in this resource.\n"
711                            "Perhaps you left the trailing brace off of the previous resource.", lc->str);
712                         /* NOT REACHED */
713                      }
714                      break;
715
716                   case T_EOB:
717                      level--;
718                      state = p_none;
719                      Dmsg0(150, "T_EOB => define new resource\n");
720                      save_resource(res_type, items, pass);  /* save resource */
721                      break;
722
723                   case T_EOL:
724                      break;
725
726                   default:
727                      scan_err2(lc, "unexpected token %d %s in resource definition",    
728                         token, lex_tok_to_str(token));
729                      /* NOT REACHED */
730                }
731                break;
732             default:
733                scan_err1(lc, "Unknown parser state %d\n", state);
734                /* NOT REACHED */
735          }
736       }
737       if (state != p_none) {
738          scan_err0(lc, "End of conf file reached with unclosed resource.");
739       }
740       if (debug_level > 50 && pass == 2) {
741          int i;
742          for (i=r_first; i<=r_last; i++) {
743             dump_resource(i, resources[i-r_first].res_head, prtmsg, NULL);
744          }
745       }
746       lc = lex_close_file(lc);
747    }
748    Dmsg0(200, "Leave parse_config()\n");
749 }
750
751 /*********************************************************************
752  *
753  *      Free configuration resources
754  *
755  */
756 void 
757 free_config_resources()
758 {
759    int i;
760    for (i=r_first; i<=r_last; i++) {
761       free_resource(i);
762    }
763 }