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