]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/dird/dird_conf.c
Solaris fixes -- kes21Jun02
[bacula/bacula] / bacula / src / dird / dird_conf.c
1 /*
2  *   Main configuration file parser for Bacula Directors,
3  *    some parts may be split into separate files such as
4  *    the schedule configuration (sch_config.c).
5  *
6  *   Note, the configuration file parser consists of three parts
7  *
8  *   1. The generic lexical scanner in lib/lex.c and lib/lex.h
9  *
10  *   2. The generic config  scanner in lib/parse_config.c and 
11  *      lib/parse_config.h.
12  *      These files contain the parser code, some utility
13  *      routines, and the common store routines (name, int,
14  *      string).
15  *
16  *   3. The daemon specific file, which contains the Resource
17  *      definitions as well as any specific store routines
18  *      for the resource records.
19  *
20  *     Kern Sibbald, January MM
21  *
22  *     Version $Id$
23  */
24 /*
25    Copyright (C) 2000, 2001, 2002 Kern Sibbald and John Walker
26
27    This program is free software; you can redistribute it and/or
28    modify it under the terms of the GNU General Public License as
29    published by the Free Software Foundation; either version 2 of
30    the License, or (at your option) any later version.
31
32    This program is distributed in the hope that it will be useful,
33    but WITHOUT ANY WARRANTY; without even the implied warranty of
34    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
35    General Public License for more details.
36
37    You should have received a copy of the GNU General Public
38    License along with this program; if not, write to the Free
39    Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
40    MA 02111-1307, USA.
41
42  */
43
44 #include "bacula.h"
45 #include "dird.h"
46
47 /* Define the first and last resource ID record
48  * types. Note, these should be unique for each
49  * daemon though not a requirement.
50  */
51 int r_first = R_FIRST;
52 int r_last  = R_LAST;
53 pthread_mutex_t res_mutex =  PTHREAD_MUTEX_INITIALIZER;
54
55 /* Imported subroutines */
56 extern void store_run(LEX *lc, struct res_items *item, int index, int pass);
57
58
59 /* Forward referenced subroutines */
60
61 static void store_inc(LEX *lc, struct res_items *item, int index, int pass);
62 static void store_backup(LEX *lc, struct res_items *item, int index, int pass);
63 static void store_restore(LEX *lc, struct res_items *item, int index, int pass);
64 static void store_jobtype(LEX *lc, struct res_items *item, int index, int pass);
65 static void store_level(LEX *lc, struct res_items *item, int index, int pass);
66
67
68 /* We build the current resource here as we are
69  * scanning the resource configuration definition,
70  * then move it to allocated memory when the resource
71  * scan is complete.
72  */
73 URES res_all;
74 int  res_all_size = sizeof(res_all);
75
76
77 /* Definition of records permitted within each
78  * resource with the routine to process the record 
79  * information.  NOTE! quoted names must be in lower case.
80  */ 
81 /* 
82  *    Director Resource
83  *
84  *   name          handler     value                 code flags    default_value
85  */
86 static struct res_items dir_items[] = {
87    {"name",        store_name,     ITEM(res_dir.hdr.name), 0, ITEM_REQUIRED, 0},
88    {"description", store_str,      ITEM(res_dir.hdr.desc), 0, 0, 0},
89    {"messages",    store_res,      ITEM(res_dir.messages), R_MSGS, 0, 0},
90    {"dirport",     store_pint,     ITEM(res_dir.DIRport),  0, ITEM_REQUIRED, 0},
91    {"queryfile",   store_dir,      ITEM(res_dir.query_file), 0, 0, 0},
92    {"workingdirectory", store_dir, ITEM(res_dir.working_directory), 0, ITEM_REQUIRED, 0},
93    {"piddirectory", store_dir,     ITEM(res_dir.pid_directory), 0, ITEM_REQUIRED, 0},
94    {"subsysdirectory", store_dir,  ITEM(res_dir.subsys_directory), 0, ITEM_REQUIRED, 0},
95    {"maximumconcurrentjobs", store_pint, ITEM(res_dir.MaxConcurrentJobs), 0, ITEM_DEFAULT, 1},
96    {"password",    store_password, ITEM(res_dir.password), 0, ITEM_REQUIRED, 0},
97    {"fdconnecttimeout", store_time,ITEM(res_dir.FDConnectTimeout), 0, ITEM_DEFAULT, 60 * 30},
98    {"sdconnecttimeout", store_time,ITEM(res_dir.SDConnectTimeout), 0, ITEM_DEFAULT, 60 * 30},
99    {NULL, NULL, NULL, 0, 0, 0}
100 };
101
102 /* 
103  *    Client or File daemon resource
104  *
105  *   name          handler     value                 code flags    default_value
106  */
107
108 static struct res_items cli_items[] = {
109    {"name",     store_name,       ITEM(res_client.hdr.name), 0, ITEM_REQUIRED, 0},
110    {"description", store_str,     ITEM(res_client.hdr.desc), 0, 0, 0},
111    {"address",  store_str,        ITEM(res_client.address),  0, ITEM_REQUIRED, 0},
112    {"fdport",   store_pint,       ITEM(res_client.FDport),   0, ITEM_REQUIRED, 0},
113    {"password", store_password,   ITEM(res_client.password), 0, ITEM_REQUIRED, 0},
114    {"catalog",  store_res,        ITEM(res_client.catalog),  R_CATALOG, 0, 0},
115    {"fileretention", store_time,  ITEM(res_client.FileRetention), 0, ITEM_DEFAULT, 60*60*24*60},
116    {"jobretention",  store_time,  ITEM(res_client.JobRetention),  0, ITEM_DEFAULT, 60*60*24*180},
117    {"autoprune", store_yesno,     ITEM(res_client.AutoPrune), 1, ITEM_DEFAULT, 1},
118    {NULL, NULL, NULL, 0, 0, 0} 
119 };
120
121 /* Storage daemon resource
122  *
123  *   name          handler     value                 code flags    default_value
124  */
125 static struct res_items store_items[] = {
126    {"name",      store_name,     ITEM(res_store.hdr.name),   0, ITEM_REQUIRED, 0},
127    {"description", store_str,    ITEM(res_store.hdr.desc),   0, 0, 0},
128    {"sdport",    store_pint,     ITEM(res_store.SDport),     0, ITEM_REQUIRED, 0},
129    {"sddport",   store_pint,     ITEM(res_store.SDDport),    0, 0, 0}, /* deprecated */
130    {"address",   store_str,      ITEM(res_store.address),    0, ITEM_REQUIRED, 0},
131    {"password",  store_password, ITEM(res_store.password),   0, ITEM_REQUIRED, 0},
132    {"device",    store_strname,  ITEM(res_store.dev_name),   0, ITEM_REQUIRED, 0},
133    {"mediatype", store_strname,  ITEM(res_store.media_type), 0, ITEM_REQUIRED, 0},
134    {NULL, NULL, NULL, 0, 0, 0} 
135 };
136
137 /* 
138  *    Catalog Resource Directives
139  *
140  *   name          handler     value                 code flags    default_value
141  */
142 static struct res_items cat_items[] = {
143    {"name",     store_name,     ITEM(res_cat.hdr.name),    0, ITEM_REQUIRED, 0},
144    {"description", store_str,   ITEM(res_cat.hdr.desc),    0, 0, 0},
145    {"address",  store_str,      ITEM(res_cat.address),     0, 0, 0},
146    {"dbport",   store_pint,     ITEM(res_cat.DBport),      0, 0, 0},
147    /* keep this password as store_str for the moment */
148    {"password", store_str,      ITEM(res_cat.db_password), 0, 0, 0},
149    {"user",     store_str,      ITEM(res_cat.db_user),     0, 0, 0},
150    {"dbname",   store_str,      ITEM(res_cat.db_name),     0, ITEM_REQUIRED, 0},
151    {NULL, NULL, NULL, 0, 0, 0} 
152 };
153
154 /* 
155  *    Job Resource Directives
156  *
157  *   name          handler     value                 code flags    default_value
158  */
159 static struct res_items job_items[] = {
160    {"name",     store_name,    ITEM(res_job.hdr.name), 0, ITEM_REQUIRED, 0},
161    {"description", store_str,  ITEM(res_job.hdr.desc), 0, 0, 0},
162    {"backup",   store_backup,  ITEM(res_job),          JT_BACKUP, 0, 0},
163    {"verify",   store_backup,  ITEM(res_job),          JT_VERIFY, 0, 0},
164    {"restore",  store_restore, ITEM(res_job),          JT_RESTORE, 0, 0},
165    {"schedule", store_res,     ITEM(res_job.schedule), R_SCHEDULE, 0, 0},
166    {"type",     store_jobtype, ITEM(res_job),          0, 0, 0},
167    {"level",    store_level,   ITEM(res_job),          0, 0, 0},
168    {"messages", store_res,     ITEM(res_job.messages), R_MSGS, 0, 0},
169    {"storage",  store_res,     ITEM(res_job.storage),  R_STORAGE, 0, 0},
170    {"pool",     store_res,     ITEM(res_job.pool),     R_POOL, 0, 0},
171    {"client",   store_res,     ITEM(res_job.client),   R_CLIENT, 0, 0},
172    {"fileset",  store_res,     ITEM(res_job.fs),       R_FILESET, 0, 0},
173    {"maxruntime", store_time,  ITEM(res_job.MaxRunTime), 0, 0, 0},
174    {"maxstartdelay", store_time,ITEM(res_job.MaxStartDelay), 0, 0, 0},
175    {"prunejobs",   store_yesno, ITEM(res_job.PruneJobs), 1, ITEM_DEFAULT, 0},
176    {"prunefiles",  store_yesno, ITEM(res_job.PruneFiles), 1, ITEM_DEFAULT, 0},
177    {"prunevolumes", store_yesno, ITEM(res_job.PruneVolumes), 1, ITEM_DEFAULT, 0},
178    {NULL, NULL, NULL, 0, 0, 0} 
179 };
180
181 /* FileSet resource
182  *
183  *   name          handler     value                 code flags    default_value
184  */
185 static struct res_items fs_items[] = {
186    {"name",        store_name, ITEM(res_fs.hdr.name), 0, ITEM_REQUIRED, 0},
187    {"description", store_str,  ITEM(res_fs.hdr.desc), 0, 0, 0},
188    {"include",     store_inc,  NULL,                  0, 0, 0},
189    {"exclude",     store_inc,  NULL,                  1, 0, 0},
190    {NULL,          NULL,       NULL,                  0, 0, 0} 
191 };
192
193 /* Schedule -- see run_conf.c */
194 /* Schedule
195  *
196  *   name          handler     value                 code flags    default_value
197  */
198 static struct res_items sch_items[] = {
199    {"name",     store_name,  ITEM(res_sch.hdr.name), 0, ITEM_REQUIRED, 0},
200    {"description", store_str, ITEM(res_sch.hdr.desc), 0, 0, 0},
201    {"run",      store_run,   ITEM(res_sch.run),      0, 0, 0},
202    {NULL, NULL, NULL, 0, 0, 0} 
203 };
204
205 /* Group resource -- not implemented
206  *
207  *   name          handler     value                 code flags    default_value
208  */
209 static struct res_items group_items[] = {
210    {"name",        store_name, ITEM(res_group.hdr.name), 0, ITEM_REQUIRED, 0},
211    {"description", store_str,  ITEM(res_group.hdr.desc), 0, 0, 0},
212    {NULL, NULL, NULL, 0, 0, 0} 
213 };
214
215 /* Pool resource
216  *
217  *   name             handler     value                        code flags default_value
218  */
219 static struct res_items pool_items[] = {
220    {"name",            store_name,    ITEM(res_pool.hdr.name),        0, ITEM_REQUIRED, 0},
221    {"description",     store_str,     ITEM(res_pool.hdr.desc),        0, 0,     0},
222    {"pooltype",        store_strname, ITEM(res_pool.pool_type),       0, ITEM_REQUIRED, 0},
223    {"labelformat",     store_strname, ITEM(res_pool.label_format),    0, 0,     0},
224    {"usecatalog",      store_yesno, ITEM(res_pool.use_catalog),     1, ITEM_DEFAULT,  1},
225    {"usevolumeonce",   store_yesno, ITEM(res_pool.use_volume_once), 1, 0,       0},
226    {"maximumvolumes",  store_pint,  ITEM(res_pool.max_volumes),     0, 0,             0},
227    {"acceptanyvolume", store_yesno, ITEM(res_pool.accept_any_volume), 1, 0,     0},
228    {"catalogfiles",    store_yesno, ITEM(res_pool.catalog_files),   1, ITEM_DEFAULT,  1},
229    {"volumeretention", store_time,  ITEM(res_pool.VolRetention), 0, ITEM_DEFAULT, 60*60*24*365},
230    {"autoprune",       store_yesno, ITEM(res_pool.AutoPrune), 1, ITEM_DEFAULT, 1},
231    {"recycle",         store_yesno, ITEM(res_pool.Recycle),     1, ITEM_DEFAULT, 1},
232    {NULL, NULL, NULL, 0, 0, 0} 
233 };
234
235 /* Message resource */
236 extern struct res_items msgs_items[];
237
238 /* 
239  * This is the master resource definition.  
240  * It must have one item for each of the resources.
241  *
242  *  name             items        rcode        res_head
243  */
244 struct s_res resources[] = {
245    {"director",      dir_items,   R_DIRECTOR,  NULL},
246    {"client",        cli_items,   R_CLIENT,    NULL},
247    {"job",           job_items,   R_JOB,       NULL},
248    {"storage",       store_items, R_STORAGE,   NULL},
249    {"catalog",       cat_items,   R_CATALOG,   NULL},
250    {"schedule",      sch_items,   R_SCHEDULE,  NULL},
251    {"fileset",       fs_items,    R_FILESET,   NULL},
252    {"group",         group_items, R_GROUP,     NULL},
253    {"pool",          pool_items,  R_POOL,      NULL},
254    {"messages",      msgs_items,  R_MSGS,      NULL},
255    {NULL,            NULL,        0,           NULL}
256 };
257
258
259 /* Keywords (RHS) permitted in Job Level records   
260  *
261  *   level_name      level              job_type
262  */
263 struct s_jl joblevels[] = {
264    {"Full",          L_FULL,            JT_BACKUP},
265    {"Incremental",   L_INCREMENTAL,     JT_BACKUP},
266    {"Differential",  L_DIFFERENTIAL,    JT_BACKUP},
267    {"Level",         L_LEVEL,           JT_BACKUP},
268    {"Since",         L_SINCE,           JT_BACKUP},
269    {"Catalog",       L_VERIFY_CATALOG,  JT_VERIFY},
270    {"Initcatalog",   L_VERIFY_INIT,     JT_VERIFY},
271    {"Volume",        L_VERIFY_VOLUME,   JT_VERIFY},
272    {"Data",          L_VERIFY_DATA,     JT_VERIFY},
273    {NULL,            0}
274 };
275
276 /* Keywords (RHS) permitted in Job type records   
277  *
278  *   type_name       job_type
279  */
280 struct s_jt jobtypes[] = {
281    {"backup",        JT_BACKUP},
282    {"admin",         JT_ADMIN},
283    {"verify",        JT_VERIFY},
284    {"restore",       JT_RESTORE},
285    {NULL,            0}
286 };
287
288
289 /* Keywords (RHS) permitted in Backup and Verify records */
290 static struct s_kw BakVerFields[] = {
291    {"client",        'C'},
292    {"fileset",       'F'},
293    {"level",         'L'}, 
294    {NULL,            0}
295 };
296
297 /* Keywords (RHS) permitted in Restore records */
298 static struct s_kw RestoreFields[] = {
299    {"client",        'C'},
300    {"fileset",       'F'},
301    {"jobid",         'J'},            /* JobId to restore */
302    {"where",         'W'},            /* root of restore */
303    {"replace",       'R'},            /* replacement options */
304    {NULL,              0}
305 };
306
307 /* Options permitted in Restore replace= */
308 static struct s_kw ReplaceOptions[] = {
309    {"always",         'A'},           /* always */
310    {"ifnewer",        'W'},
311    {"never",          'N'},
312    {NULL,               0}
313 };
314
315
316
317 /* Define FileSet KeyWord values */
318
319 #define FS_KW_NONE         0
320 #define FS_KW_COMPRESSION  1
321 #define FS_KW_SIGNATURE    2
322 #define FS_KW_ENCRYPTION   3
323 #define FS_KW_VERIFY       4
324
325 /* FileSet keywords */
326 static struct s_kw FS_option_kw[] = {
327    {"compression", FS_KW_COMPRESSION},
328    {"signature",   FS_KW_SIGNATURE},
329    {"encryption",  FS_KW_ENCRYPTION},
330    {"verify",      FS_KW_VERIFY},
331    {NULL,          0}
332 };
333
334 /* Options for FileSet keywords */
335
336 struct s_fs_opt {
337    char *name;
338    int keyword;
339    char *option;
340 };
341
342 /* Options permitted for each keyword and resulting value */
343 static struct s_fs_opt FS_options[] = {
344    {"md5",      FS_KW_SIGNATURE,    "M"},
345    {"gzip",     FS_KW_COMPRESSION,  "Z6"},
346    {"gzip1",    FS_KW_COMPRESSION,  "Z1"},
347    {"gzip2",    FS_KW_COMPRESSION,  "Z2"},
348    {"gzip3",    FS_KW_COMPRESSION,  "Z3"},
349    {"gzip4",    FS_KW_COMPRESSION,  "Z4"},
350    {"gzip5",    FS_KW_COMPRESSION,  "Z5"},
351    {"gzip6",    FS_KW_COMPRESSION,  "Z6"},
352    {"gzip7",    FS_KW_COMPRESSION,  "Z7"},
353    {"gzip8",    FS_KW_COMPRESSION,  "Z8"},
354    {"gzip9",    FS_KW_COMPRESSION,  "Z9"},
355    {"blowfish", FS_KW_ENCRYPTION,   "B"},   /* ***FIXME*** not implemented */
356    {"3des",     FS_KW_ENCRYPTION,   "3"},   /* ***FIXME*** not implemented */
357    {NULL,       0,                   0}
358 };
359
360 char *level_to_str(int level)
361 {
362    int i;
363    static char level_no[30];
364    char *str = level_no;
365
366    sprintf(level_no, "%d", level);    /* default if not found */
367    for (i=0; joblevels[i].level_name; i++) {
368       if (level == joblevels[i].level) {
369          str = joblevels[i].level_name;
370          break;
371       }
372    }
373    return str;
374 }
375
376
377
378 /* Dump contents of resource */
379 void dump_resource(int type, RES *reshdr, void sendit(void *sock, char *fmt, ...), void *sock)
380 {
381    int i;
382    URES *res = (URES *)reshdr;
383    int recurse = 1;
384
385    if (res == NULL) {
386       sendit(sock, "No %s resource defined\n", res_to_str(type));
387       return;
388    }
389    if (type < 0) {                    /* no recursion */
390       type = - type;
391       recurse = 0;
392    }
393    switch (type) {
394       case R_DIRECTOR:
395          char ed1[30], ed2[30];
396          sendit(sock, "Director: name=%s maxjobs=%d FDtimeout=%s SDtimeout=%s\n", 
397             reshdr->name, res->res_dir.MaxConcurrentJobs, 
398             edit_uint64(res->res_dir.FDConnectTimeout, ed1),
399             edit_uint64(res->res_dir.SDConnectTimeout, ed2));
400          if (res->res_dir.query_file) {
401             sendit(sock, "   query_file=%s\n", res->res_dir.query_file);
402          }
403          if (res->res_dir.messages) {
404             sendit(sock, "  --> ");
405             dump_resource(-R_MSGS, (RES *)res->res_dir.messages, sendit, sock);
406          }
407          break;
408       case R_CLIENT:
409          sendit(sock, "Client: name=%s address=%s FDport=%d\n",
410             res->res_client.hdr.name, res->res_client.address, res->res_client.FDport);
411          sendit(sock, "JobRetention=%" lld " FileRetention=%" lld " AutoPrune=%d\n",
412             res->res_client.JobRetention, res->res_client.FileRetention,
413             res->res_client.AutoPrune);
414          if (res->res_client.catalog) {
415             sendit(sock, "  --> ");
416             dump_resource(-R_CATALOG, (RES *)res->res_client.catalog, sendit, sock);
417          }
418          break;
419       case R_STORAGE:
420          sendit(sock, "Storage: name=%s address=%s SDport=%d\n\
421          DeviceName=%s MediaType=%s\n",
422             res->res_store.hdr.name, res->res_store.address, res->res_store.SDport,
423             res->res_store.dev_name, res->res_store.media_type);
424          break;
425       case R_CATALOG:
426          sendit(sock, "Catalog: name=%s address=%s DBport=%d db_name=%s\n\
427          db_user=%s\n",
428             res->res_cat.hdr.name, NPRT(res->res_cat.address),
429             res->res_cat.DBport, res->res_cat.db_name, NPRT(res->res_cat.db_user));
430          break;
431       case R_JOB:
432          sendit(sock, "Job: name=%s JobType=%d level=%s\n", res->res_job.hdr.name, 
433             res->res_job.JobType, level_to_str(res->res_job.level));
434          if (res->res_job.client) {
435             sendit(sock, "  --> ");
436             dump_resource(-R_CLIENT, (RES *)res->res_job.client, sendit, sock);
437          }
438          if (res->res_job.fs) {
439             sendit(sock, "  --> ");
440             dump_resource(-R_FILESET, (RES *)res->res_job.fs, sendit, sock);
441          }
442          if (res->res_job.schedule) {
443             sendit(sock, "  --> ");
444             dump_resource(-R_SCHEDULE, (RES *)res->res_job.schedule, sendit, sock);
445          }
446          if (res->res_job.RestoreWhere) {
447             sendit(sock, "  --> Where=%s\n", res->res_job.RestoreWhere);
448          }
449          if (res->res_job.storage) {
450             sendit(sock, "  --> ");
451             dump_resource(-R_STORAGE, (RES *)res->res_job.storage, sendit, sock);
452          }
453          if (res->res_job.pool) {
454             sendit(sock, "  --> ");
455             dump_resource(-R_POOL, (RES *)res->res_job.pool, sendit, sock);
456          } else {
457             sendit(sock, "!!! No Pool resource\n");
458          }
459          if (res->res_job.messages) {
460             sendit(sock, "  --> ");
461             dump_resource(-R_MSGS, (RES *)res->res_job.messages, sendit, sock);
462          }
463          break;
464       case R_FILESET:
465          sendit(sock, "FileSet: name=%s\n", res->res_fs.hdr.name);
466          for (i=0; i<res->res_fs.num_includes; i++)
467             sendit(sock, "      Inc: %s\n", res->res_fs.include_array[i]);
468          for (i=0; i<res->res_fs.num_excludes; i++)
469             sendit(sock, "      Exc: %s\n", res->res_fs.exclude_array[i]);
470          break;
471       case R_SCHEDULE:
472          if (res->res_sch.run) {
473             int i;
474             RUN *run = res->res_sch.run;
475             char buf[1000], num[10];
476             sendit(sock, "Schedule: name=%s\n", res->res_sch.hdr.name);
477             if (!run) {
478                break;
479             }
480 next_run:
481             sendit(sock, "  --> Run Level=%s\n", level_to_str(run->level));
482             strcpy(buf, "      hour=");
483             for (i=0; i<24; i++) {
484                if (bit_is_set(i, run->hour)) {
485                   sprintf(num, "%d ", i+1);
486                   strcat(buf, num);
487                }
488             }
489             strcat(buf, "\n");
490             sendit(sock, buf);
491             strcpy(buf, "      mday=");
492             for (i=0; i<31; i++) {
493                if (bit_is_set(i, run->mday)) {
494                   sprintf(num, "%d ", i+1);
495                   strcat(buf, num);
496                }
497             }
498             strcat(buf, "\n");
499             sendit(sock, buf);
500             strcpy(buf, "      month=");
501             for (i=0; i<12; i++) {
502                if (bit_is_set(i, run->month)) {
503                   sprintf(num, "%d ", i+1);
504                   strcat(buf, num);
505                }
506             }
507             strcat(buf, "\n");
508             sendit(sock, buf);
509             strcpy(buf, "      wday=");
510             for (i=0; i<7; i++) {
511                if (bit_is_set(i, run->wday)) {
512                   sprintf(num, "%d ", i+1);
513                   strcat(buf, num);
514                }
515             }
516             strcat(buf, "\n");
517             sendit(sock, buf);
518             sendit(sock, "      mins=%d\n", run->minute);
519             if (run->pool) {
520                sendit(sock, "     --> ");
521                dump_resource(-R_POOL, (RES *)run->pool, sendit, sock);
522             }
523             if (run->storage) {
524                sendit(sock, "     --> ");
525                dump_resource(-R_STORAGE, (RES *)run->storage, sendit, sock);
526             }
527             if (run->msgs) {
528                sendit(sock, "     --> ");
529                dump_resource(-R_MSGS, (RES *)run->msgs, sendit, sock);
530             }
531             /* If another Run record is chained in, go print it */
532             if (run->next) {
533                run = run->next;
534                goto next_run;
535             }
536          } else {
537             sendit(sock, "Schedule: name=%s\n", res->res_sch.hdr.name);
538          }
539          break;
540       case R_GROUP:
541          sendit(sock, "Group: name=%s\n", res->res_group.hdr.name);
542          break;
543       case R_POOL:
544          sendit(sock, "Pool: name=%s PoolType=%s\n", res->res_pool.hdr.name,
545                  res->res_pool.pool_type);
546          sendit(sock, "      use_cat=%d use_once=%d acpt_any=%d cat_files=%d\n",
547                  res->res_pool.use_catalog, res->res_pool.use_volume_once,
548                  res->res_pool.accept_any_volume, res->res_pool.catalog_files);
549          sendit(sock, "      max_vols=%d auto_prune=%d VolRetention=%" lld "\n",
550                  res->res_pool.max_volumes, res->res_pool.AutoPrune,
551                  res->res_pool.VolRetention);
552          sendit(sock, "      recycle=%d LabelFormat=%s\n", res->res_pool.Recycle,
553                  NPRT(res->res_pool.label_format));
554          break;
555       case R_MSGS:
556          sendit(sock, "Messages: name=%s\n", res->res_msgs.hdr.name);
557          if (res->res_msgs.mail_cmd) 
558             sendit(sock, "      mailcmd=%s\n", res->res_msgs.mail_cmd);
559          if (res->res_msgs.operator_cmd) 
560             sendit(sock, "      opcmd=%s\n", res->res_msgs.operator_cmd);
561          break;
562       default:
563          sendit(sock, "Unknown resource type %d\n", type);
564          break;
565    }
566    if (recurse && res->res_dir.hdr.next) {
567       dump_resource(type, res->res_dir.hdr.next, sendit, sock);
568    }
569 }
570
571 /* 
572  * Free memory of resource.  
573  * NB, we don't need to worry about freeing any references
574  * to other resources as they will be freed when that 
575  * resource chain is traversed.  Mainly we worry about freeing
576  * allocated strings (names).
577  */
578 void free_resource(int type)
579 {
580    int num;
581    URES *res;
582    RES *nres;
583    int rindex = type - r_first;
584
585    res = (URES *)resources[rindex].res_head;
586
587    if (res == NULL)
588       return;
589
590    /* common stuff -- free the resource name and description */
591    nres = (RES *)res->res_dir.hdr.next;
592    if (res->res_dir.hdr.name) {
593       free(res->res_dir.hdr.name);
594    }
595    if (res->res_dir.hdr.desc) {
596       free(res->res_dir.hdr.desc);
597    }
598
599    switch (type) {
600       case R_DIRECTOR:
601          if (res->res_dir.working_directory)
602             free(res->res_dir.working_directory);
603          if (res->res_dir.pid_directory)
604             free(res->res_dir.pid_directory);
605          if (res->res_dir.subsys_directory)
606             free(res->res_dir.subsys_directory);
607          if (res->res_dir.password)
608             free(res->res_dir.password);
609          if (res->res_dir.query_file)
610             free(res->res_dir.query_file);
611          break;
612       case R_CLIENT:
613          if (res->res_client.address)
614             free(res->res_client.address);
615          if (res->res_client.password)
616             free(res->res_client.password);
617          break;
618       case R_STORAGE:
619          if (res->res_store.address)
620             free(res->res_store.address);
621          if (res->res_store.password)
622             free(res->res_store.password);
623          if (res->res_store.media_type)
624             free(res->res_store.media_type);
625          if (res->res_store.dev_name)
626             free(res->res_store.dev_name);
627          break;
628       case R_CATALOG:
629          if (res->res_cat.address)
630             free(res->res_cat.address);
631          if (res->res_cat.db_user)
632             free(res->res_cat.db_user);
633          if (res->res_cat.db_name)
634             free(res->res_cat.db_name);
635          if (res->res_cat.db_password)
636             free(res->res_cat.db_password);
637          break;
638       case R_FILESET:
639          if ((num=res->res_fs.num_includes)) {
640             while (--num >= 0)    
641                free(res->res_fs.include_array[num]);
642             free(res->res_fs.include_array);
643          }
644          if ((num=res->res_fs.num_excludes)) {
645             while (--num >= 0)    
646                free(res->res_fs.exclude_array[num]);
647             free(res->res_fs.exclude_array);
648          }
649          break;
650       case R_POOL:
651          if (res->res_pool.pool_type) {
652             free(res->res_pool.pool_type);
653          }
654          if (res->res_pool.label_format) {
655             free(res->res_pool.label_format);
656          }
657          break;
658       case R_SCHEDULE:
659          if (res->res_sch.run) {
660             RUN *nrun, *next;
661             nrun = res->res_sch.run;
662             while (nrun) {
663                next = nrun->next;
664                free(nrun);
665                nrun = next;
666             }
667          }
668          break;
669       case R_JOB:
670          if (res->res_job.RestoreWhere) {
671             free(res->res_job.RestoreWhere);
672          }
673          break;
674       case R_MSGS:
675          if (res->res_msgs.mail_cmd)
676             free(res->res_msgs.mail_cmd);
677          if (res->res_msgs.operator_cmd)
678             free(res->res_msgs.operator_cmd);
679          free_msgs_res((MSGS *)res);  /* free message resource */
680          res = NULL;
681          break;
682       case R_GROUP:
683          break;
684       default:
685          printf("Unknown resource type %d\n", type);
686    }
687    /* Common stuff again -- free the resource, recurse to next one */
688    if (res) {
689       free(res);
690    }
691    resources[rindex].res_head = nres;
692    if (nres) {
693       free_resource(type);
694    }
695 }
696
697 /*
698  * Save the new resource by chaining it into the head list for
699  * the resource. If this is pass 2, we update any resource
700  * pointers because they may not have been defined until 
701  * later in pass 1.
702  */
703 void save_resource(int type, struct res_items *items, int pass)
704 {
705    URES *res;
706    int rindex = type - r_first;
707    int i, size;
708    int error = 0;
709    
710    /* 
711     * Ensure that all required items are present
712     */
713    for (i=0; items[i].name; i++) {
714       if (items[i].flags & ITEM_REQUIRED) {
715             if (!bit_is_set(i, res_all.res_dir.hdr.item_present)) {  
716                Emsg2(M_ABORT, 0, "%s item is required in %s resource, but not found.\n",
717                  items[i].name, resources[rindex]);
718              }
719       }
720       /* If this triggers, take a look at lib/parse_conf.h */
721       if (i >= MAX_RES_ITEMS) {
722          Emsg1(M_ABORT, 0, "Too many items in %s resource\n", resources[rindex]);
723       }
724    }
725
726    /* During pass 2 in each "store" routine, we looked up pointers 
727     * to all the resources referrenced in the current resource, now we
728     * must copy their addresses from the static record to the allocated
729     * record.
730     */
731    if (pass == 2) {
732       switch (type) {
733          /* Resources not containing a resource */
734          case R_CATALOG:
735          case R_STORAGE:
736          case R_FILESET:
737          case R_GROUP:
738          case R_POOL:
739          case R_MSGS:
740             break;
741
742          /* Resources containing another resource */
743          case R_DIRECTOR:
744             if ((res = (URES *)GetResWithName(R_DIRECTOR, res_all.res_dir.hdr.name)) == NULL) {
745                Emsg1(M_ABORT, 0, "Cannot find Director resource %s\n", res_all.res_dir.hdr.name);
746             }
747             res->res_dir.messages = res_all.res_dir.messages;
748             break;
749          case R_JOB:
750             if ((res = (URES *)GetResWithName(R_JOB, res_all.res_dir.hdr.name)) == NULL) {
751                Emsg1(M_ABORT, 0, "Cannot find Job resource %s\n", res_all.res_dir.hdr.name);
752             }
753             res->res_job.messages = res_all.res_job.messages;
754             res->res_job.schedule = res_all.res_job.schedule;
755             res->res_job.client   = res_all.res_job.client;
756             res->res_job.fs       = res_all.res_job.fs;
757             res->res_job.storage  = res_all.res_job.storage;
758             res->res_job.pool     = res_all.res_job.pool;
759             if (res->res_job.JobType == 0) {
760                Emsg1(M_ABORT, 0, "Job Type not defined for Job resource %s\n", res_all.res_dir.hdr.name);
761             }
762             if (res->res_job.level != 0) {
763                int i;
764                for (i=0; joblevels[i].level_name; i++) {
765                   if (joblevels[i].level == res->res_job.level &&
766                       joblevels[i].job_type == res->res_job.JobType) {
767                      i = 0;
768                      break;
769                   }
770                }
771                if (i != 0) {
772                   Emsg1(M_ABORT, 0, "Inappropriate level specified in Job resource %s\n", 
773                      res_all.res_dir.hdr.name);
774                }
775             }
776             break;
777          case R_CLIENT:
778             if ((res = (URES *)GetResWithName(R_CLIENT, res_all.res_client.hdr.name)) == NULL) {
779                Emsg1(M_ABORT, 0, "Cannot find Client resource %s\n", res_all.res_client.hdr.name);
780             }
781             res->res_client.catalog = res_all.res_client.catalog;
782             break;
783          case R_SCHEDULE:
784             /* Schedule is a bit different in that it contains a RUN record
785              * chain which isn't a "named" resource. This chain was linked
786              * in by run_conf.c during pass 2, so here we jam the pointer 
787              * into the Schedule resource.                         
788              */
789             if ((res = (URES *)GetResWithName(R_SCHEDULE, res_all.res_client.hdr.name)) == NULL) {
790                Emsg1(M_ABORT, 0, "Cannot find Schedule resource %s\n", res_all.res_client.hdr.name);
791             }
792             res->res_sch.run = res_all.res_sch.run;
793             break;
794          default:
795             Emsg1(M_ERROR, 0, "Unknown resource type %d\n", type);
796             error = 1;
797             break;
798       }
799       /* Note, the resource name was already saved during pass 1,
800        * so here, we can just release it.
801        */
802       if (res_all.res_dir.hdr.name) {
803          free(res_all.res_dir.hdr.name);
804          res_all.res_dir.hdr.name = NULL;
805       }
806       if (res_all.res_dir.hdr.desc) {
807          free(res_all.res_dir.hdr.desc);
808          res_all.res_dir.hdr.desc = NULL;
809       }
810       return;
811    }
812
813    /* The following code is only executed for pass 1 */
814    switch (type) {
815       case R_DIRECTOR:
816          size = sizeof(DIRRES);
817          break;
818       case R_CLIENT:
819          size =sizeof(CLIENT);
820          break;
821       case R_STORAGE:
822          size = sizeof(STORE); 
823          break;
824       case R_CATALOG:
825          size = sizeof(CAT);
826          break;
827       case R_JOB:
828          size = sizeof(JOB);
829          break;
830       case R_FILESET:
831          size = sizeof(FILESET);
832          break;
833       case R_SCHEDULE:
834          size = sizeof(SCHED);
835          break;
836       case R_GROUP:
837          size = sizeof(GROUP);
838          break;
839       case R_POOL:
840          size = sizeof(POOL);
841          break;
842       case R_MSGS:
843          size = sizeof(MSGS);
844          break;
845       default:
846          printf("Unknown resource type %d\n", type);
847          error = 1;
848          break;
849    }
850    /* Common */
851    if (!error) {
852       res = (URES *)malloc(size);
853       memcpy(res, &res_all, size);
854       res->res_dir.hdr.next = resources[rindex].res_head;
855       resources[rindex].res_head = (RES *)res;
856       Dmsg2(90, "dir_conf: inserting %s res: %s\n", res_to_str(type),
857          res->res_dir.hdr.name);
858    }
859
860 }
861
862 /* 
863  * Store JobType (backup, verify, restore)
864  *
865  */
866 static void store_jobtype(LEX *lc, struct res_items *item, int index, int pass)
867 {
868    int token, i;   
869
870    token = lex_get_token(lc, T_NAME);
871    /* Store the type both pass 1 and pass 2 */
872    for (i=0; jobtypes[i].type_name; i++) {
873       if (strcasecmp(lc->str, jobtypes[i].type_name) == 0) {
874          ((JOB *)(item->value))->JobType = jobtypes[i].job_type;
875          i = 0;
876          break;
877       }
878    }
879    if (i != 0) {
880       scan_err1(lc, "Expected a Job Type keyword, got: %s", lc->str);
881    }
882    scan_to_eol(lc);
883    set_bit(index, res_all.hdr.item_present);
884 }
885
886 /* 
887  * Store Job Level (Full, Incremental, ...)
888  *
889  */
890 static void store_level(LEX *lc, struct res_items *item, int index, int pass)
891 {
892    int token, i;
893
894    token = lex_get_token(lc, T_NAME);
895    /* Store the level pass 2 so that type is defined */
896    for (i=0; joblevels[i].level_name; i++) {
897       if (strcasecmp(lc->str, joblevels[i].level_name) == 0) {
898          ((JOB *)(item->value))->level = joblevels[i].level;
899          i = 0;
900          break;
901       }
902    }
903    if (i != 0) {
904       scan_err1(lc, "Expected a Job Level keyword, got: %s", lc->str);
905    }
906    scan_to_eol(lc);
907    set_bit(index, res_all.hdr.item_present);
908 }
909
910
911
912 /* 
913  * Store backup/verify info for Job record 
914  *
915  * Note, this code is used for both BACKUP and VERIFY jobs
916  *
917  *    Backup = Client=<client-name> FileSet=<FileSet-name> Level=<level>
918  */
919 static void store_backup(LEX *lc, struct res_items *item, int index, int pass)
920 {
921    int token, i;
922    RES *res;
923    int options = lc->options;
924
925    lc->options |= LOPT_NO_IDENT;      /* make spaces significant */
926
927    
928    ((JOB *)(item->value))->JobType = item->code;
929    while ((token = lex_get_token(lc, T_ALL)) != T_EOL) {
930       int found;
931
932       Dmsg1(150, "store_backup got token=%s\n", lex_tok_to_str(token));
933       
934       if (token != T_IDENTIFIER && token != T_UNQUOTED_STRING && token != T_QUOTED_STRING) {
935          scan_err1(lc, "Expected a backup/verify keyword, got: %s", lc->str);
936       }
937       Dmsg1(190, "Got keyword: %s\n", lc->str);
938       found = FALSE;
939       for (i=0; BakVerFields[i].name; i++) {
940          if (strcasecmp(lc->str, BakVerFields[i].name) == 0) {
941             found = TRUE;
942             if (lex_get_token(lc, T_ALL) != T_EQUALS) {
943                scan_err1(lc, "Expected an equals, got: %s", lc->str);
944             }
945             token = lex_get_token(lc, T_NAME);
946             Dmsg1(190, "Got value: %s\n", lc->str);
947             switch (BakVerFields[i].token) {
948                case 'C':
949                   /* Find Client Resource */
950                   if (pass == 2) {
951                      res = GetResWithName(R_CLIENT, lc->str);
952                      if (res == NULL) {
953                         scan_err1(lc, "Could not find specified Client Resource: %s",
954                                    lc->str);
955                      }
956                      res_all.res_job.client = (CLIENT *)res;
957                   }
958                   break;
959                case 'F':
960                   /* Find FileSet Resource */
961                   if (pass == 2) {
962                      res = GetResWithName(R_FILESET, lc->str);
963                      if (res == NULL) {
964                         scan_err1(lc, "Could not find specified FileSet Resource: %s\n",
965                                     lc->str);
966                      }
967                      res_all.res_job.fs = (FILESET *)res;
968                   }
969                   break;
970                case 'L':
971                   /* Get level */
972                   for (i=0; joblevels[i].level_name; i++) {
973                      if (joblevels[i].job_type == item->code && 
974                           strcasecmp(lc->str, joblevels[i].level_name) == 0) {
975                         ((JOB *)(item->value))->level = joblevels[i].level;
976                         i = 0;
977                         break;
978                      }
979                   }
980                   if (i != 0) {
981                      scan_err1(lc, "Expected a Job Level keyword, got: %s", lc->str);
982                   }
983                   break;
984             } /* end switch */
985             break;
986          } /* end if strcmp() */
987       } /* end for */
988       if (!found) {
989          scan_err1(lc, "%s not a valid Backup/verify keyword", lc->str);
990       }
991    } /* end while */
992    lc->options = options;             /* reset original options */
993    set_bit(index, res_all.hdr.item_present);
994 }
995
996 /* 
997  * Store restore info for Job record 
998  *
999  *    Restore = JobId=<job-id> Where=<root-directory> Replace=<options>
1000  *
1001  */
1002 static void store_restore(LEX *lc, struct res_items *item, int index, int pass)
1003 {
1004    int token, i;
1005    RES *res;
1006    int options = lc->options;
1007
1008    lc->options |= LOPT_NO_IDENT;      /* make spaces significant */
1009
1010    Dmsg0(190, "Enter store_restore()\n");
1011    
1012    ((JOB *)(item->value))->JobType = item->code;
1013    while ((token = lex_get_token(lc, T_ALL)) != T_EOL) {
1014       int found; 
1015
1016       if (token != T_IDENTIFIER && token != T_UNQUOTED_STRING && token != T_QUOTED_STRING) {
1017          scan_err1(lc, "expected a name, got: %s", lc->str);
1018       }
1019       found = FALSE;
1020       for (i=0; RestoreFields[i].name; i++) {
1021          Dmsg1(190, "Restore kw=%s\n", lc->str);
1022          if (strcasecmp(lc->str, RestoreFields[i].name) == 0) {
1023             found = TRUE;
1024             if (lex_get_token(lc, T_ALL) != T_EQUALS) {
1025                scan_err1(lc, "Expected an equals, got: %s", lc->str);
1026             }
1027             token = lex_get_token(lc, T_ALL);
1028             Dmsg1(190, "Restore value=%s\n", lc->str);
1029             switch (RestoreFields[i].token) {
1030                case 'C':
1031                   /* Find Client Resource */
1032                   if (pass == 2) {
1033                      res = GetResWithName(R_CLIENT, lc->str);
1034                      if (res == NULL) {
1035                         scan_err1(lc, "Could not find specified Client Resource: %s",
1036                                    lc->str);
1037                      }
1038                      res_all.res_job.client = (CLIENT *)res;
1039                   }
1040                   break;
1041                case 'F':
1042                   /* Find FileSet Resource */
1043                   if (pass == 2) {
1044                      res = GetResWithName(R_FILESET, lc->str);
1045                      if (res == NULL) {
1046                         scan_err1(lc, "Could not find specified FileSet Resource: %s\n",
1047                                     lc->str);
1048                      }
1049                      res_all.res_job.fs = (FILESET *)res;
1050                   }
1051                   break;
1052                case 'J':
1053                   /* JobId */
1054                   if (token != T_NUMBER) {
1055                      scan_err1(lc, "expected an integer number, got: %s", lc->str);
1056                   }
1057                   errno = 0;
1058                   res_all.res_job.RestoreJobId = strtol(lc->str, NULL, 0);
1059                   Dmsg1(190, "RestorJobId=%d\n", res_all.res_job.RestoreJobId);
1060                   if (errno != 0) {
1061                      scan_err1(lc, "expected an integer number, got: %s", lc->str);
1062                   }
1063                   break;
1064                case 'W':
1065                   /* Where */
1066                   if (token != T_IDENTIFIER && token != T_UNQUOTED_STRING && token != T_QUOTED_STRING) {
1067                      scan_err1(lc, "Expected a Restore root directory, got: %s", lc->str);
1068                   }
1069                   if (pass == 1) {
1070                      res_all.res_job.RestoreWhere = bstrdup(lc->str);
1071                   }
1072                   break;
1073                case 'R':
1074                   /* Replacement options */
1075                   if (token != T_IDENTIFIER && token != T_UNQUOTED_STRING && token != T_QUOTED_STRING) {
1076                      scan_err1(lc, "Expected a keyword name, got: %s", lc->str);
1077                   }
1078                   /* Fix to scan Replacement options */
1079                   for (i=0; ReplaceOptions[i].name; i++) {
1080                      if (strcasecmp(lc->str, ReplaceOptions[i].name) == 0) {
1081                          ((JOB *)(item->value))->RestoreOptions = ReplaceOptions[i].token;
1082                         i = 0;
1083                         break;
1084                      }
1085                   }
1086                   if (i != 0) {
1087                      scan_err1(lc, "Expected a Restore replacement option, got: %s", lc->str);
1088                   }
1089                   break;
1090             } /* end switch */
1091             break;
1092          } /* end if strcmp() */
1093       } /* end for */
1094       if (!found) {
1095          scan_err1(lc, "%s not a valid Restore keyword", lc->str);
1096       }
1097    } /* end while */
1098    lc->options = options;             /* reset original options */
1099    set_bit(index, res_all.hdr.item_present);
1100 }
1101
1102
1103
1104 /* 
1105  * Scan for FileSet options (keyword=option) is converted into one or
1106  *  two characters. Verifyopts=xxxx is Vxxxx:
1107  */
1108 static char *scan_fs_options(LEX *lc, int keyword)
1109 {
1110    int token, i;
1111    static char opts[100];
1112    char option[3];
1113
1114    option[0] = 0;                     /* default option = none */
1115    opts[0] = option[2] = 0;           /* terminate options */
1116    for (;;) {
1117       token = lex_get_token(lc, T_NAME);             /* expect at least one option */       
1118       if (keyword == FS_KW_VERIFY) { /* special case */
1119          /* ***FIXME**** ensure these are in permitted set */
1120          strcpy(option, "V");         /* indicate Verify */
1121          strcat(option, lc->str);
1122          strcat(option, ":");         /* terminate it */
1123       } else {
1124          for (i=0; FS_options[i].name; i++) {
1125             if (strcasecmp(lc->str, FS_options[i].name) == 0 && FS_options[i].keyword == keyword) {
1126                option[0] = FS_options[i].option[0];
1127                option[1] = FS_options[i].option[1];
1128                i = 0;
1129                break;
1130             }
1131          }
1132          if (i != 0) {
1133             scan_err1(lc, "Expected a FileSet option keyword, got: %s", lc->str);
1134          }
1135       }
1136       strcat(opts, option);
1137
1138       /* check if more options are specified */
1139       if (lc->ch != ',') {
1140          break;                       /* no, get out */
1141       }
1142       token = lex_get_token(lc, T_ALL);      /* yes, eat comma */
1143    }
1144
1145    return opts;
1146 }
1147
1148
1149 /* Store FileSet Include/Exclude info */
1150 static void store_inc(LEX *lc, struct res_items *item, int index, int pass)
1151 {
1152    int token, i;
1153    int options = lc->options;
1154    int keyword;
1155    char *fname;
1156    char inc_opts[100];
1157    int inc_opts_len;
1158
1159    lc->options |= LOPT_NO_IDENT;      /* make spaces significant */
1160
1161    /* Get include options */
1162    strcpy(inc_opts, "0");             /* set no options */
1163    while ((token=lex_get_token(lc, T_ALL)) != T_BOB) {
1164       keyword = FS_KW_NONE;
1165       for (i=0; FS_option_kw[i].name; i++) {
1166          if (strcasecmp(lc->str, FS_option_kw[i].name) == 0) {
1167             keyword = FS_option_kw[i].token;
1168             break;
1169          }
1170       }
1171       if (keyword == FS_KW_NONE) {
1172          scan_err1(lc, "Expected a FileSet keyword, got: %s", lc->str);
1173       }
1174       /* Option keyword should be following by = <option> */
1175       if ((token=lex_get_token(lc, T_ALL)) != T_EQUALS) {
1176          scan_err1(lc, "expected an = following keyword, got: %s", lc->str);
1177       }
1178       strcat(inc_opts, scan_fs_options(lc, keyword));
1179       if (token == T_BOB) {
1180          break;
1181       }
1182    }
1183    strcat(inc_opts, " ");             /* add field separator */
1184    inc_opts_len = strlen(inc_opts);
1185
1186
1187    if (pass == 1) {
1188       if (!res_all.res_fs.have_MD5) {
1189          MD5Init(&res_all.res_fs.md5c);
1190          res_all.res_fs.have_MD5 = TRUE;
1191       }
1192       /* Pickup include/exclude names. Note, they are stored as
1193        * XYZ fname
1194        * where XYZ are the include/exclude options for the FileSet
1195        *     a "0 " (zero) indicates no options,
1196        * and fname is the file/directory name given
1197        */
1198       while ((token = lex_get_token(lc, T_ALL)) != T_EOB) {
1199          switch (token) {
1200             case T_COMMA:
1201             case T_EOL:
1202                continue;
1203
1204             case T_IDENTIFIER:
1205             case T_UNQUOTED_STRING:
1206             case T_QUOTED_STRING:
1207                fname = (char *) malloc(lc->str_len + inc_opts_len + 1);
1208                strcpy(fname, inc_opts);
1209                strcat(fname, lc->str);
1210                if (res_all.res_fs.have_MD5) {
1211                   MD5Update(&res_all.res_fs.md5c, (unsigned char *) fname, inc_opts_len + lc->str_len);
1212                }
1213                if (item->code == 0) { /* include */
1214                   if (res_all.res_fs.num_includes == res_all.res_fs.include_size) {
1215                      res_all.res_fs.include_size += 10;
1216                      if (res_all.res_fs.include_array == NULL) {
1217                         res_all.res_fs.include_array = (char **) malloc(sizeof(char *) * res_all.res_fs.include_size);
1218                      } else {
1219                         res_all.res_fs.include_array = (char **) realloc(res_all.res_fs.include_array,
1220                            sizeof(char *) * res_all.res_fs.include_size);
1221                      }
1222                   }
1223                   res_all.res_fs.include_array[res_all.res_fs.num_includes++] =    
1224                      fname;
1225                } else {                /* exclude */
1226                   if (res_all.res_fs.num_excludes == res_all.res_fs.exclude_size) {
1227                      res_all.res_fs.exclude_size += 10;
1228                      if (res_all.res_fs.exclude_array == NULL) {
1229                         res_all.res_fs.exclude_array = (char **) malloc(sizeof(char *) * res_all.res_fs.exclude_size);
1230                      } else {
1231                         res_all.res_fs.exclude_array = (char **) realloc(res_all.res_fs.exclude_array,
1232                            sizeof(char *) * res_all.res_fs.exclude_size);
1233                      }
1234                   }
1235                   res_all.res_fs.exclude_array[res_all.res_fs.num_excludes++] =    
1236                      fname;
1237                }
1238                break;
1239             default:
1240                scan_err1(lc, "Expected a filename, got: %s", lc->str);
1241          }                                 
1242       }
1243    } else { /* pass 2 */
1244       while (lex_get_token(lc, T_ALL) != T_EOB) 
1245          {}
1246    }
1247    scan_to_eol(lc);
1248    lc->options = options;
1249    set_bit(index, res_all.hdr.item_present);
1250 }