]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/dird/dird_conf.c
Tweak gnome2 console + documentation
[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 (run_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-2003 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
54 pthread_mutex_t res_mutex =  PTHREAD_MUTEX_INITIALIZER;
55
56 /* Imported subroutines */
57 extern void store_run(LEX *lc, struct res_items *item, int index, int pass);
58 extern void store_finc(LEX *lc, struct res_items *item, int index, int pass);
59 extern void store_inc(LEX *lc, struct res_items *item, int index, int pass);
60
61
62 /* Forward referenced subroutines */
63
64 static void store_backup(LEX *lc, struct res_items *item, int index, int pass);
65 static void store_restore(LEX *lc, struct res_items *item, int index, int pass);
66 static void store_jobtype(LEX *lc, struct res_items *item, int index, int pass);
67 static void store_level(LEX *lc, struct res_items *item, int index, int pass);
68 static void store_replace(LEX *lc, struct res_items *item, int index, int pass);
69
70
71 /* We build the current resource here as we are
72  * scanning the resource configuration definition,
73  * then move it to allocated memory when the resource
74  * scan is complete.
75  */
76 URES res_all;
77 int  res_all_size = sizeof(res_all);
78
79
80 /* Definition of records permitted within each
81  * resource with the routine to process the record 
82  * information.  NOTE! quoted names must be in lower case.
83  */ 
84 /* 
85  *    Director Resource
86  *
87  *   name          handler     value                 code flags    default_value
88  */
89 static struct res_items dir_items[] = {
90    {"name",        store_name,     ITEM(res_dir.hdr.name), 0, ITEM_REQUIRED, 0},
91    {"description", store_str,      ITEM(res_dir.hdr.desc), 0, 0, 0},
92    {"messages",    store_res,      ITEM(res_dir.messages), R_MSGS, 0, 0},
93    {"dirport",     store_pint,     ITEM(res_dir.DIRport),  0, ITEM_DEFAULT, 9101},
94    {"diraddress",  store_str,      ITEM(res_dir.DIRaddr),  0, 0, 0},
95    {"queryfile",   store_dir,      ITEM(res_dir.query_file), 0, ITEM_REQUIRED, 0},
96    {"workingdirectory", store_dir, ITEM(res_dir.working_directory), 0, ITEM_REQUIRED, 0},
97    {"piddirectory",store_dir,     ITEM(res_dir.pid_directory), 0, ITEM_REQUIRED, 0},
98    {"subsysdirectory", store_dir,  ITEM(res_dir.subsys_directory), 0, 0, 0},
99    {"requiressl",  store_yesno,    ITEM(res_dir.require_ssl), 1, ITEM_DEFAULT, 0},
100    {"enablessl",   store_yesno,    ITEM(res_dir.enable_ssl), 1, ITEM_DEFAULT, 0},
101    {"maximumconcurrentjobs", store_pint, ITEM(res_dir.MaxConcurrentJobs), 0, ITEM_DEFAULT, 1},
102    {"password",    store_password, ITEM(res_dir.password), 0, ITEM_REQUIRED, 0},
103    {"fdconnecttimeout", store_time,ITEM(res_dir.FDConnectTimeout), 0, ITEM_DEFAULT, 60 * 30},
104    {"sdconnecttimeout", store_time,ITEM(res_dir.SDConnectTimeout), 0, ITEM_DEFAULT, 60 * 30},
105    {NULL, NULL, NULL, 0, 0, 0}
106 };
107
108 /* 
109  *    Console Resource
110  *
111  *   name          handler     value                 code flags    default_value
112  */
113 static struct res_items con_items[] = {
114    {"name",        store_name,     ITEM(res_con.hdr.name), 0, ITEM_REQUIRED, 0},
115    {"description", store_str,      ITEM(res_con.hdr.desc), 0, 0, 0},
116    {"enablessl",   store_yesno,    ITEM(res_con.enable_ssl), 1, ITEM_DEFAULT, 0},
117    {"password",    store_password, ITEM(res_con.password), 0, ITEM_REQUIRED, 0},
118    {NULL, NULL, NULL, 0, 0, 0}
119 };
120
121
122 /* 
123  *    Client or File daemon resource
124  *
125  *   name          handler     value                 code flags    default_value
126  */
127
128 static struct res_items cli_items[] = {
129    {"name",     store_name,       ITEM(res_client.hdr.name), 0, ITEM_REQUIRED, 0},
130    {"description", store_str,     ITEM(res_client.hdr.desc), 0, 0, 0},
131    {"address",  store_str,        ITEM(res_client.address),  0, ITEM_REQUIRED, 0},
132    {"fdaddress",  store_str,      ITEM(res_client.address),  0, 0, 0},
133    {"fdport",   store_pint,       ITEM(res_client.FDport),   0, ITEM_DEFAULT, 9102},
134    {"password", store_password,   ITEM(res_client.password), 0, ITEM_REQUIRED, 0},
135    {"fdpassword", store_password,   ITEM(res_client.password), 0, 0, 0},
136    {"catalog",  store_res,        ITEM(res_client.catalog),  R_CATALOG, 0, 0},
137    {"fileretention", store_time,  ITEM(res_client.FileRetention), 0, ITEM_DEFAULT, 60*60*24*60},
138    {"jobretention",  store_time,  ITEM(res_client.JobRetention),  0, ITEM_DEFAULT, 60*60*24*180},
139    {"autoprune", store_yesno,     ITEM(res_client.AutoPrune), 1, ITEM_DEFAULT, 1},
140    {"enablessl", store_yesno,     ITEM(res_client.enable_ssl), 1, ITEM_DEFAULT, 0},
141    {"maximumconcurrentjobs", store_pint, ITEM(res_client.MaxConcurrentJobs), 0, ITEM_DEFAULT, 1},
142    {NULL, NULL, NULL, 0, 0, 0} 
143 };
144
145 /* Storage daemon resource
146  *
147  *   name          handler     value                 code flags    default_value
148  */
149 static struct res_items store_items[] = {
150    {"name",        store_name,     ITEM(res_store.hdr.name),   0, ITEM_REQUIRED, 0},
151    {"description", store_str,      ITEM(res_store.hdr.desc),   0, 0, 0},
152    {"sdport",      store_pint,     ITEM(res_store.SDport),     0, ITEM_DEFAULT, 9103},
153    {"address",     store_str,      ITEM(res_store.address),    0, ITEM_REQUIRED, 0},
154    {"sdaddress",   store_str,      ITEM(res_store.address),    0, 0, 0},
155    {"password",    store_password, ITEM(res_store.password),   0, ITEM_REQUIRED, 0},
156    {"sdpassword",  store_password, ITEM(res_store.password),   0, 0, 0},
157    {"device",      store_strname,  ITEM(res_store.dev_name),   0, ITEM_REQUIRED, 0},
158    {"sddevicename", store_strname, ITEM(res_store.dev_name),   0, 0, 0},
159    {"mediatype",   store_strname,  ITEM(res_store.media_type), 0, ITEM_REQUIRED, 0},
160    {"autochanger", store_yesno,    ITEM(res_store.autochanger), 1, ITEM_DEFAULT, 0},
161    {"enablessl",   store_yesno,    ITEM(res_store.enable_ssl),  1, ITEM_DEFAULT, 0},
162    {"maximumconcurrentjobs", store_pint, ITEM(res_store.MaxConcurrentJobs), 0, ITEM_DEFAULT, 1},
163    {"sddport", store_pint, ITEM(res_store.SDDport), 0, 0, 0}, /* deprecated */
164    {NULL, NULL, NULL, 0, 0, 0} 
165 };
166
167 /* 
168  *    Catalog Resource Directives
169  *
170  *   name          handler     value                 code flags    default_value
171  */
172 static struct res_items cat_items[] = {
173    {"name",     store_name,     ITEM(res_cat.hdr.name),    0, ITEM_REQUIRED, 0},
174    {"description", store_str,   ITEM(res_cat.hdr.desc),    0, 0, 0},
175    {"address",  store_str,      ITEM(res_cat.db_address),  0, 0, 0},
176    {"dbaddress", store_str,     ITEM(res_cat.db_address),  0, 0, 0},
177    {"dbport",   store_pint,     ITEM(res_cat.db_port),      0, 0, 0},
178    /* keep this password as store_str for the moment */
179    {"password", store_str,      ITEM(res_cat.db_password), 0, 0, 0},
180    {"dbpassword", store_str,    ITEM(res_cat.db_password), 0, 0, 0},
181    {"user",     store_str,      ITEM(res_cat.db_user),     0, 0, 0},
182    {"dbname",   store_str,      ITEM(res_cat.db_name),     0, ITEM_REQUIRED, 0},
183    {"dbsocket", store_str,      ITEM(res_cat.db_socket),   0, 0, 0}, 
184    {NULL, NULL, NULL, 0, 0, 0} 
185 };
186
187 /* 
188  *    Job Resource Directives
189  *
190  *   name          handler     value                 code flags    default_value
191  */
192 static struct res_items job_items[] = {
193    {"name",     store_name,    ITEM(res_job.hdr.name), 0, ITEM_REQUIRED, 0},
194    {"description", store_str,  ITEM(res_job.hdr.desc), 0, 0, 0},
195    {"backup",   store_backup,  ITEM(res_job),          JT_BACKUP, 0, 0},
196    {"verify",   store_backup,  ITEM(res_job),          JT_VERIFY, 0, 0},
197    {"restore",  store_restore, ITEM(res_job),          JT_RESTORE, 0, 0},
198    {"schedule", store_res,     ITEM(res_job.schedule), R_SCHEDULE, 0, 0},
199    {"type",     store_jobtype, ITEM(res_job),          0, 0, 0},
200    {"level",    store_level,   ITEM(res_job),          0, 0, 0},
201    {"messages", store_res,     ITEM(res_job.messages), R_MSGS, 0, 0},
202    {"storage",  store_res,     ITEM(res_job.storage),  R_STORAGE, 0, 0},
203    {"pool",     store_res,     ITEM(res_job.pool),     R_POOL, 0, 0},
204    {"client",   store_res,     ITEM(res_job.client),   R_CLIENT, 0, 0},
205    {"fileset",  store_res,     ITEM(res_job.fileset),  R_FILESET, 0, 0},
206    {"verifyjob",  store_res,   ITEM(res_job.verify_job), R_JOB, 0, 0},
207    {"where",    store_dir,     ITEM(res_job.RestoreWhere), 0, 0, 0},
208    {"replace",  store_replace, ITEM(res_job.replace), 0, ITEM_DEFAULT, REPLACE_ALWAYS},
209    {"bootstrap",store_dir,     ITEM(res_job.RestoreBootstrap), 0, 0, 0},
210    {"maxruntime", store_time,  ITEM(res_job.MaxRunTime), 0, 0, 0},
211    {"maxstartdelay", store_time,ITEM(res_job.MaxStartDelay), 0, 0, 0},
212    {"prefixlinks", store_yesno, ITEM(res_job.PrefixLinks), 1, ITEM_DEFAULT, 0},
213    {"prunejobs",   store_yesno, ITEM(res_job.PruneJobs), 1, ITEM_DEFAULT, 0},
214    {"prunefiles",  store_yesno, ITEM(res_job.PruneFiles), 1, ITEM_DEFAULT, 0},
215    {"prunevolumes", store_yesno, ITEM(res_job.PruneVolumes), 1, ITEM_DEFAULT, 0},
216    {"runbeforejob", store_str,  ITEM(res_job.RunBeforeJob), 0, 0, 0},
217    {"runafterjob",  store_str,  ITEM(res_job.RunAfterJob),  0, 0, 0},
218    {"clientrunbeforejob", store_str,  ITEM(res_job.ClientRunBeforeJob), 0, 0, 0},
219    {"clientrunafterjob",  store_str,  ITEM(res_job.ClientRunAfterJob),  0, 0, 0},
220    {"spoolattributes", store_yesno, ITEM(res_job.SpoolAttributes), 1, ITEM_DEFAULT, 0},
221    {"writebootstrap", store_dir, ITEM(res_job.WriteBootstrap), 0, 0, 0},
222    {"maximumconcurrentjobs", store_pint, ITEM(res_job.MaxConcurrentJobs), 0, ITEM_DEFAULT, 1},
223    {"rescheduleonerror", store_yesno, ITEM(res_job.RescheduleOnError), 1, ITEM_DEFAULT, 0},
224    {"rescheduleinterval", store_time, ITEM(res_job.RescheduleInterval), 0, ITEM_DEFAULT, 60 * 30},
225    {"rescheduletimes", store_pint, ITEM(res_job.RescheduleTimes), 0, 0, 0},
226    {"priority",   store_pint, ITEM(res_job.Priority), 0, ITEM_DEFAULT, 10},
227    {NULL, NULL, NULL, 0, 0, 0} 
228 };
229
230 /* FileSet resource
231  *
232  *   name          handler     value                 code flags    default_value
233  */
234 static struct res_items fs_items[] = {
235    {"name",        store_name, ITEM(res_fs.hdr.name), 0, ITEM_REQUIRED, 0},
236    {"description", store_str,  ITEM(res_fs.hdr.desc), 0, 0, 0},
237    {"include",     store_inc,  NULL,                  0, ITEM_NO_EQUALS, 0},
238    {"exclude",     store_inc,  NULL,                  1, ITEM_NO_EQUALS, 0},
239    {NULL,          NULL,       NULL,                  0, 0, 0} 
240 };
241
242 /* Schedule -- see run_conf.c */
243 /* Schedule
244  *
245  *   name          handler     value                 code flags    default_value
246  */
247 static struct res_items sch_items[] = {
248    {"name",     store_name,  ITEM(res_sch.hdr.name), 0, ITEM_REQUIRED, 0},
249    {"description", store_str, ITEM(res_sch.hdr.desc), 0, 0, 0},
250    {"run",      store_run,   ITEM(res_sch.run),      0, 0, 0},
251    {NULL, NULL, NULL, 0, 0, 0} 
252 };
253
254 /* Group resource -- not implemented
255  *
256  *   name          handler     value                 code flags    default_value
257  */
258 static struct res_items group_items[] = {
259    {"name",        store_name, ITEM(res_group.hdr.name), 0, ITEM_REQUIRED, 0},
260    {"description", store_str,  ITEM(res_group.hdr.desc), 0, 0, 0},
261    {NULL, NULL, NULL, 0, 0, 0} 
262 };
263
264 /* Pool resource
265  *
266  *   name             handler     value                        code flags default_value
267  */
268 static struct res_items pool_items[] = {
269    {"name",            store_name,    ITEM(res_pool.hdr.name),      0, ITEM_REQUIRED, 0},
270    {"description",     store_str,     ITEM(res_pool.hdr.desc),      0, 0,     0},
271    {"pooltype",        store_strname, ITEM(res_pool.pool_type),     0, ITEM_REQUIRED, 0},
272    {"labelformat",     store_strname, ITEM(res_pool.label_format),  0, 0,     0},
273    {"cleaningprefix",  store_strname, ITEM(res_pool.cleaning_prefix),  0, 0,     0},
274    {"usecatalog",      store_yesno, ITEM(res_pool.use_catalog),     1, ITEM_DEFAULT,  1},
275    {"usevolumeonce",   store_yesno, ITEM(res_pool.use_volume_once), 1, 0,        0},
276    {"purgeoldestvolume", store_yesno, ITEM(res_pool.purge_oldest_volume), 1, 0, 0},
277    {"recycleoldestvolume", store_yesno, ITEM(res_pool.recycle_oldest_volume), 1, 0, 0},
278    {"recyclecurrentvolume", store_yesno, ITEM(res_pool.recycle_current_volume), 1, 0, 0},
279    {"maximumvolumes",  store_pint,  ITEM(res_pool.max_volumes),     0, 0,        0},
280    {"maximumvolumejobs", store_pint,  ITEM(res_pool.MaxVolJobs),    0, 0,       0},
281    {"maximumvolumefiles", store_pint, ITEM(res_pool.MaxVolFiles),   0, 0,       0},
282    {"maximumvolumebytes", store_size, ITEM(res_pool.MaxVolBytes),   0, 0,       0},
283    {"acceptanyvolume", store_yesno, ITEM(res_pool.accept_any_volume), 1, ITEM_DEFAULT,     1},
284    {"catalogfiles",    store_yesno, ITEM(res_pool.catalog_files),   1, ITEM_DEFAULT,  1},
285    {"volumeretention", store_time,  ITEM(res_pool.VolRetention),    0, ITEM_DEFAULT, 60*60*24*365},
286    {"volumeuseduration", store_time,  ITEM(res_pool.VolUseDuration),0, 0, 0},
287    {"autoprune",       store_yesno, ITEM(res_pool.AutoPrune), 1, ITEM_DEFAULT, 1},
288    {"recycle",         store_yesno, ITEM(res_pool.Recycle),     1, ITEM_DEFAULT, 1},
289    {NULL, NULL, NULL, 0, 0, 0} 
290 };
291
292 /* 
293  * Counter Resource
294  *   name             handler     value                        code flags default_value
295  */
296 static struct res_items counter_items[] = {
297    {"name",            store_name,    ITEM(res_counter.hdr.name),        0, ITEM_REQUIRED, 0},
298    {"description",     store_str,     ITEM(res_counter.hdr.desc),        0, 0,     0},
299    {"minimum",         store_int,     ITEM(res_counter.MinValue),        0, ITEM_DEFAULT, 0},
300    {"maximum",         store_pint,    ITEM(res_counter.MaxValue),        0, ITEM_DEFAULT, INT32_MAX},
301    {"wrapcounter",     store_res,     ITEM(res_counter.WrapCounter),     R_COUNTER, 0, 0},
302    {"catalog",         store_res,     ITEM(res_counter.Catalog),         R_CATALOG, 0, 0},
303    {NULL, NULL, NULL, 0, 0, 0} 
304 };
305
306
307 /* Message resource */
308 extern struct res_items msgs_items[];
309
310 /* 
311  * This is the master resource definition.  
312  * It must have one item for each of the resources.
313  *
314  *  NOTE!!! keep it in the same order as the R_codes
315  *    or eliminate all resources[rindex].name
316  *
317  *  name             items        rcode        res_head
318  */
319 struct s_res resources[] = {
320    {"director",      dir_items,   R_DIRECTOR,  NULL},
321    {"client",        cli_items,   R_CLIENT,    NULL},
322    {"job",           job_items,   R_JOB,       NULL},
323    {"storage",       store_items, R_STORAGE,   NULL},
324    {"catalog",       cat_items,   R_CATALOG,   NULL},
325    {"schedule",      sch_items,   R_SCHEDULE,  NULL},
326    {"fileset",       fs_items,    R_FILESET,   NULL},
327    {"group",         group_items, R_GROUP,     NULL},
328    {"pool",          pool_items,  R_POOL,      NULL},
329    {"messages",      msgs_items,  R_MSGS,      NULL},
330    {"counter",       counter_items, R_COUNTER, NULL},
331    {"console",       con_items,   R_CONSOLE,   NULL},
332    {NULL,            NULL,        0,           NULL}
333 };
334
335
336 /* Keywords (RHS) permitted in Job Level records   
337  *
338  *   level_name      level              job_type
339  */
340 struct s_jl joblevels[] = {
341    {"Full",          L_FULL,            JT_BACKUP},
342    {"Base",          L_BASE,            JT_BACKUP},
343    {"Incremental",   L_INCREMENTAL,     JT_BACKUP},
344    {"Differential",  L_DIFFERENTIAL,    JT_BACKUP},
345    {"Since",         L_SINCE,           JT_BACKUP},
346    {"Catalog",       L_VERIFY_CATALOG,  JT_VERIFY},
347    {"InitCatalog",   L_VERIFY_INIT,     JT_VERIFY},
348    {"VolumeToCatalog", L_VERIFY_VOLUME_TO_CATALOG,   JT_VERIFY},
349    {"DiskToCatalog", L_VERIFY_DISK_TO_CATALOG,   JT_VERIFY},
350    {"Data",          L_VERIFY_DATA,     JT_VERIFY},
351    {NULL,            0}
352 };
353
354 /* Keywords (RHS) permitted in Job type records   
355  *
356  *   type_name       job_type
357  */
358 struct s_jt jobtypes[] = {
359    {"backup",        JT_BACKUP},
360    {"admin",         JT_ADMIN},
361    {"verify",        JT_VERIFY},
362    {"restore",       JT_RESTORE},
363    {NULL,            0}
364 };
365
366
367 /* Keywords (RHS) permitted in Backup and Verify records */
368 static struct s_kw BakVerFields[] = {
369    {"client",        'C'},
370    {"fileset",       'F'},
371    {"level",         'L'}, 
372    {NULL,            0}
373 };
374
375 /* Keywords (RHS) permitted in Restore records */
376 static struct s_kw RestoreFields[] = {
377    {"client",        'C'},
378    {"fileset",       'F'},
379    {"jobid",         'J'},            /* JobId to restore */
380    {"where",         'W'},            /* root of restore */
381    {"replace",       'R'},            /* replacement options */
382    {"bootstrap",     'B'},            /* bootstrap file */
383    {NULL,              0}
384 };
385
386 /* Options permitted in Restore replace= */
387 struct s_kw ReplaceOptions[] = {
388    {"always",         REPLACE_ALWAYS},
389    {"ifnewer",        REPLACE_IFNEWER},
390    {"ifolder",        REPLACE_IFOLDER},
391    {"never",          REPLACE_NEVER},
392    {NULL,               0}
393 };
394
395 char *level_to_str(int level)
396 {
397    int i;
398    static char level_no[30];
399    char *str = level_no;
400
401    sprintf(level_no, "%d", level);    /* default if not found */
402    for (i=0; joblevels[i].level_name; i++) {
403       if (level == joblevels[i].level) {
404          str = joblevels[i].level_name;
405          break;
406       }
407    }
408    return str;
409 }
410
411 /* Dump contents of resource */
412 void dump_resource(int type, RES *reshdr, void sendit(void *sock, char *fmt, ...), void *sock)
413 {
414    URES *res = (URES *)reshdr;
415    bool recurse = true;
416    char ed1[100], ed2[100];
417
418    if (res == NULL) {
419       sendit(sock, "No %s resource defined\n", res_to_str(type));
420       return;
421    }
422    if (type < 0) {                    /* no recursion */
423       type = - type;
424       recurse = false;
425    }
426    switch (type) {
427    case R_DIRECTOR:
428       sendit(sock, "Director: name=%s MaxJobs=%d FDtimeout=%s SDtimeout=%s\n", 
429          reshdr->name, res->res_dir.MaxConcurrentJobs, 
430          edit_uint64(res->res_dir.FDConnectTimeout, ed1),
431          edit_uint64(res->res_dir.SDConnectTimeout, ed2));
432       if (res->res_dir.query_file) {
433          sendit(sock, "   query_file=%s\n", res->res_dir.query_file);
434       }
435       if (res->res_dir.messages) {
436          sendit(sock, "  --> ");
437          dump_resource(-R_MSGS, (RES *)res->res_dir.messages, sendit, sock);
438       }
439       break;
440    case R_CONSOLE:
441       sendit(sock, "Console: name=%s SSL=%d\n", 
442          res->res_con.hdr.name, res->res_con.enable_ssl);
443       break;
444    case R_COUNTER:
445       if (res->res_counter.WrapCounter) {
446          sendit(sock, "Counter: name=%s min=%d max=%d cur=%d wrapcntr=%s\n",
447             res->res_counter.hdr.name, res->res_counter.MinValue, 
448             res->res_counter.MaxValue, res->res_counter.CurrentValue,
449             res->res_counter.WrapCounter->hdr.name);
450       } else {
451          sendit(sock, "Counter: name=%s min=%d max=%d\n",
452             res->res_counter.hdr.name, res->res_counter.MinValue, 
453             res->res_counter.MaxValue);
454       }
455       if (res->res_counter.Catalog) {
456          sendit(sock, "  --> ");
457          dump_resource(-R_CATALOG, (RES *)res->res_counter.Catalog, sendit, sock);
458       }
459       break;
460
461    case R_CLIENT:
462       sendit(sock, "Client: name=%s address=%s FDport=%d MaxJobs=%u\n",
463          res->res_client.hdr.name, res->res_client.address, res->res_client.FDport,
464          res->res_client.MaxConcurrentJobs);
465       sendit(sock, "      JobRetention=%s FileRetention=%s AutoPrune=%d\n",
466          edit_utime(res->res_client.JobRetention, ed1), 
467          edit_utime(res->res_client.FileRetention, ed2),
468          res->res_client.AutoPrune);
469       if (res->res_client.catalog) {
470          sendit(sock, "  --> ");
471          dump_resource(-R_CATALOG, (RES *)res->res_client.catalog, sendit, sock);
472       }
473       break;
474    case R_STORAGE:
475       sendit(sock, "Storage: name=%s address=%s SDport=%d MaxJobs=%u\n\
476       DeviceName=%s MediaType=%s\n",
477          res->res_store.hdr.name, res->res_store.address, res->res_store.SDport,
478          res->res_store.MaxConcurrentJobs,
479          res->res_store.dev_name, res->res_store.media_type);
480       break;
481    case R_CATALOG:
482       sendit(sock, "Catalog: name=%s address=%s DBport=%d db_name=%s\n\
483       db_user=%s\n",
484          res->res_cat.hdr.name, NPRT(res->res_cat.db_address),
485          res->res_cat.db_port, res->res_cat.db_name, NPRT(res->res_cat.db_user));
486       break;
487    case R_JOB:
488       sendit(sock, "Job: name=%s JobType=%d level=%s Priority=%d MaxJobs=%u\n", 
489          res->res_job.hdr.name, res->res_job.JobType, 
490          level_to_str(res->res_job.level), res->res_job.Priority,
491          res->res_job.MaxConcurrentJobs);
492       sendit(sock, "     Resched=%d Times=%d Interval=%s\n",
493           res->res_job.RescheduleOnError, res->res_job.RescheduleTimes,
494           edit_uint64_with_commas(res->res_job.RescheduleInterval, ed1));
495       if (res->res_job.client) {
496          sendit(sock, "  --> ");
497          dump_resource(-R_CLIENT, (RES *)res->res_job.client, sendit, sock);
498       }
499       if (res->res_job.fileset) {
500          sendit(sock, "  --> ");
501          dump_resource(-R_FILESET, (RES *)res->res_job.fileset, sendit, sock);
502       }
503       if (res->res_job.schedule) {
504          sendit(sock, "  --> ");
505          dump_resource(-R_SCHEDULE, (RES *)res->res_job.schedule, sendit, sock);
506       }
507       if (res->res_job.RestoreWhere) {
508          sendit(sock, "  --> Where=%s\n", NPRT(res->res_job.RestoreWhere));
509       }
510       if (res->res_job.RestoreBootstrap) {
511          sendit(sock, "  --> Bootstrap=%s\n", NPRT(res->res_job.RestoreBootstrap));
512       }
513       if (res->res_job.RunBeforeJob) {
514          sendit(sock, "  --> RunBefore=%s\n", NPRT(res->res_job.RunBeforeJob));
515       }
516       if (res->res_job.RunAfterJob) {
517          sendit(sock, "  --> RunAfter=%s\n", NPRT(res->res_job.RunAfterJob));
518       }
519       if (res->res_job.WriteBootstrap) {
520          sendit(sock, "  --> WriteBootstrap=%s\n", NPRT(res->res_job.WriteBootstrap));
521       }
522       if (res->res_job.storage) {
523          sendit(sock, "  --> ");
524          dump_resource(-R_STORAGE, (RES *)res->res_job.storage, sendit, sock);
525       }
526       if (res->res_job.pool) {
527          sendit(sock, "  --> ");
528          dump_resource(-R_POOL, (RES *)res->res_job.pool, sendit, sock);
529       } else {
530          sendit(sock, "!!! No Pool resource\n");
531       }
532       if (res->res_job.verify_job) {
533          sendit(sock, "  --> ");
534          dump_resource(-R_JOB, (RES *)res->res_job.verify_job, sendit, sock);
535       }
536       break;
537       if (res->res_job.messages) {
538          sendit(sock, "  --> ");
539          dump_resource(-R_MSGS, (RES *)res->res_job.messages, sendit, sock);
540       }
541       break;
542    case R_FILESET:
543       sendit(sock, "FileSet: name=%s\n", res->res_fs.hdr.name);
544       for (int i=0; i<res->res_fs.num_includes; i++) {
545          INCEXE *incexe = res->res_fs.include_items[i];
546          for (int j=0; j<incexe->name_list.size(); j++) {
547             sendit(sock, "      Inc: %s\n", incexe->name_list.get(j));
548          }
549       }
550       for (int i=0; i<res->res_fs.num_excludes; i++) {
551          INCEXE *incexe = res->res_fs.exclude_items[i];
552          for (int j=0; j<incexe->name_list.size(); j++) {
553             sendit(sock, "      Exc: %s\n", incexe->name_list.get(j));
554          }
555       }
556       break;
557    case R_SCHEDULE:
558       if (res->res_sch.run) {
559          int i;
560          RUN *run = res->res_sch.run;
561          char buf[1000], num[10];
562          sendit(sock, "Schedule: name=%s\n", res->res_sch.hdr.name);
563          if (!run) {
564             break;
565          }
566 next_run:
567          sendit(sock, "  --> Run Level=%s\n", level_to_str(run->level));
568          bstrncpy(buf, "      hour=", sizeof(buf));
569          for (i=0; i<24; i++) {
570             if (bit_is_set(i, run->hour)) {
571                sprintf(num, "%d ", i);
572                bstrncat(buf, num, sizeof(buf));
573             }
574          }
575          strcat(buf, "\n");
576          sendit(sock, buf);
577          strcpy(buf, "      mday=");
578          for (i=0; i<31; i++) {
579             if (bit_is_set(i, run->mday)) {
580                sprintf(num, "%d ", i+1);
581                strcat(buf, num);
582             }
583          }
584          strcat(buf, "\n");
585          sendit(sock, buf);
586          strcpy(buf, "      month=");
587          for (i=0; i<12; i++) {
588             if (bit_is_set(i, run->month)) {
589                sprintf(num, "%d ", i+1);
590                strcat(buf, num);
591             }
592          }
593          strcat(buf, "\n");
594          sendit(sock, buf);
595          strcpy(buf, "      wday=");
596          for (i=0; i<7; i++) {
597             if (bit_is_set(i, run->wday)) {
598                sprintf(num, "%d ", i+1);
599                strcat(buf, num);
600             }
601          }
602          strcat(buf, "\n");
603          sendit(sock, buf);
604          strcpy(buf, "      wpos=");
605          for (i=0; i<5; i++) {
606             if (bit_is_set(i, run->wpos)) {
607                sprintf(num, "%d ", i+1);
608                strcat(buf, num);
609             }
610          }
611          strcat(buf, "\n");
612          sendit(sock, buf);
613          sendit(sock, "      mins=%d\n", run->minute);
614          if (run->pool) {
615             sendit(sock, "     --> ");
616             dump_resource(-R_POOL, (RES *)run->pool, sendit, sock);
617          }
618          if (run->storage) {
619             sendit(sock, "     --> ");
620             dump_resource(-R_STORAGE, (RES *)run->storage, sendit, sock);
621          }
622          if (run->msgs) {
623             sendit(sock, "     --> ");
624             dump_resource(-R_MSGS, (RES *)run->msgs, sendit, sock);
625          }
626          /* If another Run record is chained in, go print it */
627          if (run->next) {
628             run = run->next;
629             goto next_run;
630          }
631       } else {
632          sendit(sock, "Schedule: name=%s\n", res->res_sch.hdr.name);
633       }
634       break;
635    case R_GROUP:
636       sendit(sock, "Group: name=%s\n", res->res_group.hdr.name);
637       break;
638    case R_POOL:
639       sendit(sock, "Pool: name=%s PoolType=%s\n", res->res_pool.hdr.name,
640               res->res_pool.pool_type);
641       sendit(sock, "      use_cat=%d use_once=%d acpt_any=%d cat_files=%d\n",
642               res->res_pool.use_catalog, res->res_pool.use_volume_once,
643               res->res_pool.accept_any_volume, res->res_pool.catalog_files);
644       sendit(sock, "      max_vols=%d auto_prune=%d VolRetention=%s\n",
645               res->res_pool.max_volumes, res->res_pool.AutoPrune,
646               edit_utime(res->res_pool.VolRetention, ed1));
647       sendit(sock, "      VolUse=%s recycle=%d LabelFormat=%s\n", 
648               edit_utime(res->res_pool.VolUseDuration, ed1),
649               res->res_pool.Recycle,
650               NPRT(res->res_pool.label_format));
651       sendit(sock, "      CleaningPrefix=%s\n",
652               NPRT(res->res_pool.cleaning_prefix));
653       sendit(sock, "      recyleOldest=%d MaxVolJobs=%d MaxVolFiles=%d\n",
654               res->res_pool.purge_oldest_volume, 
655               res->res_pool.MaxVolJobs, res->res_pool.MaxVolFiles);
656       break;
657    case R_MSGS:
658       sendit(sock, "Messages: name=%s\n", res->res_msgs.hdr.name);
659       if (res->res_msgs.mail_cmd) 
660          sendit(sock, "      mailcmd=%s\n", res->res_msgs.mail_cmd);
661       if (res->res_msgs.operator_cmd) 
662          sendit(sock, "      opcmd=%s\n", res->res_msgs.operator_cmd);
663       break;
664    default:
665       sendit(sock, "Unknown resource type %d in dump_resource.\n", type);
666       break;
667    }
668    if (recurse && res->res_dir.hdr.next) {
669       dump_resource(type, res->res_dir.hdr.next, sendit, sock);
670    }
671 }
672
673 /*
674  * Free all the members of an INCEXE structure
675  */
676 static void free_incexe(INCEXE *incexe)
677 {
678    incexe->name_list.destroy();
679    for (int i=0; i<incexe->num_opts; i++) {
680       FOPTS *fopt = incexe->opts_list[i];
681       fopt->match.destroy();
682       fopt->base_list.destroy();
683       free(fopt);
684    }
685    if (incexe->opts_list) {
686       free(incexe->opts_list);
687    }
688    free(incexe);
689 }
690
691 /* 
692  * Free memory of resource.  
693  * NB, we don't need to worry about freeing any references
694  * to other resources as they will be freed when that 
695  * resource chain is traversed.  Mainly we worry about freeing
696  * allocated strings (names).
697  */
698 void free_resource(int type)
699 {
700    int num;
701    URES *res;
702    RES *nres;
703    int rindex = type - r_first;
704
705    res = (URES *)resources[rindex].res_head;
706
707    if (res == NULL)
708       return;
709
710    /* common stuff -- free the resource name and description */
711    nres = (RES *)res->res_dir.hdr.next;
712    if (res->res_dir.hdr.name) {
713       free(res->res_dir.hdr.name);
714    }
715    if (res->res_dir.hdr.desc) {
716       free(res->res_dir.hdr.desc);
717    }
718
719    switch (type) {
720    case R_DIRECTOR:
721       if (res->res_dir.working_directory) {
722          free(res->res_dir.working_directory);
723       }
724       if (res->res_dir.pid_directory) {
725          free(res->res_dir.pid_directory);
726       }
727       if (res->res_dir.subsys_directory) {
728          free(res->res_dir.subsys_directory);
729       }
730       if (res->res_dir.password) {
731          free(res->res_dir.password);
732       }
733       if (res->res_dir.query_file) {
734          free(res->res_dir.query_file);
735       }
736       if (res->res_dir.DIRaddr) {
737          free(res->res_dir.DIRaddr);
738       }
739       break;
740    case R_COUNTER:
741        break;
742    case R_CONSOLE:
743       if (res->res_con.password) {
744          free(res->res_con.password);
745       }
746       break;
747    case R_CLIENT:
748       if (res->res_client.address) {
749          free(res->res_client.address);
750       }
751       if (res->res_client.password) {
752          free(res->res_client.password);
753       }
754       break;
755    case R_STORAGE:
756       if (res->res_store.address) {
757          free(res->res_store.address);
758       }
759       if (res->res_store.password) {
760          free(res->res_store.password);
761       }
762       if (res->res_store.media_type) {
763          free(res->res_store.media_type);
764       }
765       if (res->res_store.dev_name) {
766          free(res->res_store.dev_name);
767       }
768       break;
769    case R_CATALOG:
770       if (res->res_cat.db_address) {
771          free(res->res_cat.db_address);
772       }
773       if (res->res_cat.db_socket) {
774          free(res->res_cat.db_socket);
775       }
776       if (res->res_cat.db_user) {
777          free(res->res_cat.db_user);
778       }
779       if (res->res_cat.db_name) {
780          free(res->res_cat.db_name);
781       }
782       if (res->res_cat.db_password) {
783          free(res->res_cat.db_password);
784       }
785       break;
786    case R_FILESET:
787       if ((num=res->res_fs.num_includes)) {
788          while (--num >= 0) {   
789             free_incexe(res->res_fs.include_items[num]);
790          }
791          free(res->res_fs.include_items);
792       }
793       res->res_fs.num_includes = 0;
794       if ((num=res->res_fs.num_excludes)) {
795          while (--num >= 0) {   
796             free_incexe(res->res_fs.exclude_items[num]);
797          }
798          free(res->res_fs.exclude_items);
799       }
800       res->res_fs.num_excludes = 0;
801       break;
802    case R_POOL:
803       if (res->res_pool.pool_type) {
804          free(res->res_pool.pool_type);
805       }
806       if (res->res_pool.label_format) {
807          free(res->res_pool.label_format);
808       }
809       if (res->res_pool.cleaning_prefix) {
810          free(res->res_pool.cleaning_prefix);
811       }
812       break;
813    case R_SCHEDULE:
814       if (res->res_sch.run) {
815          RUN *nrun, *next;
816          nrun = res->res_sch.run;
817          while (nrun) {
818             next = nrun->next;
819             free(nrun);
820             nrun = next;
821          }
822       }
823       break;
824    case R_JOB:
825       if (res->res_job.RestoreWhere) {
826          free(res->res_job.RestoreWhere);
827       }
828       if (res->res_job.RestoreBootstrap) {
829          free(res->res_job.RestoreBootstrap);
830       }
831       if (res->res_job.WriteBootstrap) {
832          free(res->res_job.WriteBootstrap);
833       }
834       if (res->res_job.RunBeforeJob) {
835          free(res->res_job.RunBeforeJob);
836       }
837       if (res->res_job.RunAfterJob) {
838          free(res->res_job.RunAfterJob);
839       }
840       if (res->res_job.ClientRunBeforeJob) {
841          free(res->res_job.ClientRunBeforeJob);
842       }
843       if (res->res_job.ClientRunAfterJob) {
844          free(res->res_job.ClientRunAfterJob);
845       }
846       break;
847    case R_MSGS:
848       if (res->res_msgs.mail_cmd) {
849          free(res->res_msgs.mail_cmd);
850       }
851       if (res->res_msgs.operator_cmd) {
852          free(res->res_msgs.operator_cmd);
853       }
854       free_msgs_res((MSGS *)res);  /* free message resource */
855       res = NULL;
856       break;
857    case R_GROUP:
858       break;
859    default:
860       printf("Unknown resource type %d in free_resource.\n", type);
861    }
862    /* Common stuff again -- free the resource, recurse to next one */
863    if (res) {
864       free(res);
865    }
866    resources[rindex].res_head = nres;
867    if (nres) {
868       free_resource(type);
869    }
870 }
871
872 /*
873  * Save the new resource by chaining it into the head list for
874  * the resource. If this is pass 2, we update any resource
875  * pointers because they may not have been defined until 
876  * later in pass 1.
877  */
878 void save_resource(int type, struct res_items *items, int pass)
879 {
880    URES *res;
881    int rindex = type - r_first;
882    int i, size;
883    int error = 0;
884    
885    /* 
886     * Ensure that all required items are present
887     */
888    for (i=0; items[i].name; i++) {
889       if (items[i].flags & ITEM_REQUIRED) {
890             if (!bit_is_set(i, res_all.res_dir.hdr.item_present)) {  
891                Emsg2(M_ERROR_TERM, 0, "%s item is required in %s resource, but not found.\n",
892                  items[i].name, resources[rindex]);
893              }
894       }
895       /* If this triggers, take a look at lib/parse_conf.h */
896       if (i >= MAX_RES_ITEMS) {
897          Emsg1(M_ERROR_TERM, 0, "Too many items in %s resource\n", resources[rindex]);
898       }
899    }
900
901    /* During pass 2 in each "store" routine, we looked up pointers 
902     * to all the resources referrenced in the current resource, now we
903     * must copy their addresses from the static record to the allocated
904     * record.
905     */
906    if (pass == 2) {
907       switch (type) {
908       /* Resources not containing a resource */
909       case R_CONSOLE:
910       case R_CATALOG:
911       case R_STORAGE:
912       case R_GROUP:
913       case R_POOL:
914       case R_MSGS:
915       case R_FILESET:
916          break;
917
918       /* Resources containing another resource */
919       case R_DIRECTOR:
920          if ((res = (URES *)GetResWithName(R_DIRECTOR, res_all.res_dir.hdr.name)) == NULL) {
921             Emsg1(M_ERROR_TERM, 0, "Cannot find Director resource %s\n", res_all.res_dir.hdr.name);
922          }
923          res->res_dir.messages = res_all.res_dir.messages;
924          break;
925       case R_JOB:
926          if ((res = (URES *)GetResWithName(R_JOB, res_all.res_dir.hdr.name)) == NULL) {
927             Emsg1(M_ERROR_TERM, 0, "Cannot find Job resource %s\n", res_all.res_dir.hdr.name);
928          }
929          res->res_job.messages   = res_all.res_job.messages;
930          res->res_job.schedule   = res_all.res_job.schedule;
931          res->res_job.client     = res_all.res_job.client;
932          res->res_job.fileset    = res_all.res_job.fileset;
933          res->res_job.storage    = res_all.res_job.storage;
934          res->res_job.pool       = res_all.res_job.pool;
935          res->res_job.verify_job = res_all.res_job.verify_job;
936          if (res->res_job.JobType == 0) {
937             Emsg1(M_ERROR_TERM, 0, "Job Type not defined for Job resource %s\n", res_all.res_dir.hdr.name);
938          }
939          if (res->res_job.level != 0) {
940             int i;
941             for (i=0; joblevels[i].level_name; i++) {
942                if (joblevels[i].level == res->res_job.level &&
943                    joblevels[i].job_type == res->res_job.JobType) {
944                   i = 0;
945                   break;
946                }
947             }
948             if (i != 0) {
949                Emsg1(M_ERROR_TERM, 0, "Inappropriate level specified in Job resource %s\n", 
950                   res_all.res_dir.hdr.name);
951             }
952          }
953          break;
954       case R_COUNTER:
955          if ((res = (URES *)GetResWithName(R_COUNTER, res_all.res_counter.hdr.name)) == NULL) {
956             Emsg1(M_ERROR_TERM, 0, "Cannot find Counter resource %s\n", res_all.res_counter.hdr.name);
957          }
958          res->res_counter.Catalog = res_all.res_counter.Catalog;
959          res->res_counter.WrapCounter = res_all.res_counter.WrapCounter;
960          break;
961
962       case R_CLIENT:
963          if ((res = (URES *)GetResWithName(R_CLIENT, res_all.res_client.hdr.name)) == NULL) {
964             Emsg1(M_ERROR_TERM, 0, "Cannot find Client resource %s\n", res_all.res_client.hdr.name);
965          }
966          res->res_client.catalog = res_all.res_client.catalog;
967          break;
968       case R_SCHEDULE:
969          /* Schedule is a bit different in that it contains a RUN record
970           * chain which isn't a "named" resource. This chain was linked
971           * in by run_conf.c during pass 2, so here we jam the pointer 
972           * into the Schedule resource.                         
973           */
974          if ((res = (URES *)GetResWithName(R_SCHEDULE, res_all.res_client.hdr.name)) == NULL) {
975             Emsg1(M_ERROR_TERM, 0, "Cannot find Schedule resource %s\n", res_all.res_client.hdr.name);
976          }
977          res->res_sch.run = res_all.res_sch.run;
978          break;
979       default:
980          Emsg1(M_ERROR, 0, "Unknown resource type %d in save_resource.\n", type);
981          error = 1;
982          break;
983       }
984       /* Note, the resource name was already saved during pass 1,
985        * so here, we can just release it.
986        */
987       if (res_all.res_dir.hdr.name) {
988          free(res_all.res_dir.hdr.name);
989          res_all.res_dir.hdr.name = NULL;
990       }
991       if (res_all.res_dir.hdr.desc) {
992          free(res_all.res_dir.hdr.desc);
993          res_all.res_dir.hdr.desc = NULL;
994       }
995       return;
996    }
997
998    /*
999     * The following code is only executed during pass 1   
1000     */
1001    switch (type) {
1002    case R_DIRECTOR:
1003       size = sizeof(DIRRES);
1004       break;
1005    case R_CONSOLE:
1006       size = sizeof(CONRES);
1007       break;
1008    case R_CLIENT:
1009       size =sizeof(CLIENT);
1010       break;
1011    case R_STORAGE:
1012       size = sizeof(STORE); 
1013       break;
1014    case R_CATALOG:
1015       size = sizeof(CAT);
1016       break;
1017    case R_JOB:
1018       size = sizeof(JOB);
1019       break;
1020    case R_FILESET:
1021       size = sizeof(FILESET);
1022       break;
1023    case R_SCHEDULE:
1024       size = sizeof(SCHED);
1025       break;
1026    case R_GROUP:
1027       size = sizeof(GROUP);
1028       break;
1029    case R_POOL:
1030       size = sizeof(POOL);
1031       break;
1032    case R_MSGS:
1033       size = sizeof(MSGS);
1034       break;
1035    case R_COUNTER:
1036       size = sizeof(COUNTER);
1037       break;
1038    default:
1039       printf("Unknown resource type %d in save_resrouce.\n", type);
1040       error = 1;
1041       size = 1;
1042       break;
1043    }
1044    /* Common */
1045    if (!error) {
1046       res = (URES *)malloc(size);
1047       memcpy(res, &res_all, size);
1048       if (!resources[rindex].res_head) {
1049          resources[rindex].res_head = (RES *)res; /* store first entry */
1050          Dmsg3(200, "Inserting first %s res: %s index=%d\n", res_to_str(type),
1051                res->res_dir.hdr.name, rindex);
1052       } else {
1053          RES *next;
1054          /* Add new res to end of chain */
1055          for (next=resources[rindex].res_head; next->next; next=next->next) {
1056             if (strcmp(next->name, res->res_dir.hdr.name) == 0) {
1057                Emsg2(M_ERROR_TERM, 0,
1058                   _("Attempt to define second %s resource named \"%s\" is not permitted.\n"),
1059                   resources[rindex].name, res->res_dir.hdr.name);
1060             }
1061          }
1062          next->next = (RES *)res;
1063          Dmsg4(200, "Inserting %s res: %s index=%d pass=%d\n", res_to_str(type),
1064                res->res_dir.hdr.name, rindex, pass);
1065       }
1066    }
1067 }
1068
1069 /* 
1070  * Store JobType (backup, verify, restore)
1071  *
1072  */
1073 static void store_jobtype(LEX *lc, struct res_items *item, int index, int pass)
1074 {
1075    int token, i;   
1076
1077    token = lex_get_token(lc, T_NAME);
1078    /* Store the type both pass 1 and pass 2 */
1079    for (i=0; jobtypes[i].type_name; i++) {
1080       if (strcasecmp(lc->str, jobtypes[i].type_name) == 0) {
1081          ((JOB *)(item->value))->JobType = jobtypes[i].job_type;
1082          i = 0;
1083          break;
1084       }
1085    }
1086    if (i != 0) {
1087       scan_err1(lc, "Expected a Job Type keyword, got: %s", lc->str);
1088    }
1089    scan_to_eol(lc);
1090    set_bit(index, res_all.hdr.item_present);
1091 }
1092
1093 /* 
1094  * Store Job Level (Full, Incremental, ...)
1095  *
1096  */
1097 static void store_level(LEX *lc, struct res_items *item, int index, int pass)
1098 {
1099    int token, i;
1100
1101    token = lex_get_token(lc, T_NAME);
1102    /* Store the level pass 2 so that type is defined */
1103    for (i=0; joblevels[i].level_name; i++) {
1104       if (strcasecmp(lc->str, joblevels[i].level_name) == 0) {
1105          ((JOB *)(item->value))->level = joblevels[i].level;
1106          i = 0;
1107          break;
1108       }
1109    }
1110    if (i != 0) {
1111       scan_err1(lc, "Expected a Job Level keyword, got: %s", lc->str);
1112    }
1113    scan_to_eol(lc);
1114    set_bit(index, res_all.hdr.item_present);
1115 }
1116
1117 static void store_replace(LEX *lc, struct res_items *item, int index, int pass)
1118 {
1119    int token, i;
1120    token = lex_get_token(lc, T_NAME);
1121    /* Scan Replacement options */
1122    for (i=0; ReplaceOptions[i].name; i++) {
1123       if (strcasecmp(lc->str, ReplaceOptions[i].name) == 0) {
1124          *(int *)(item->value) = ReplaceOptions[i].token;
1125          i = 0;
1126          break;
1127       }
1128    }
1129    if (i != 0) {
1130       scan_err1(lc, "Expected a Restore replacement option, got: %s", lc->str);
1131    }
1132    scan_to_eol(lc);
1133    set_bit(index, res_all.hdr.item_present);
1134 }
1135
1136 /* 
1137  * Store backup/verify info for Job record 
1138  *
1139  * Note, this code is used for both BACKUP and VERIFY jobs
1140  *
1141  *    Backup = Client=<client-name> FileSet=<FileSet-name> Level=<level>
1142  */
1143 static void store_backup(LEX *lc, struct res_items *item, int index, int pass)
1144 {
1145    int token, i;
1146    RES *res;
1147    int options = lc->options;
1148
1149    lc->options |= LOPT_NO_IDENT;      /* make spaces significant */
1150
1151    
1152    ((JOB *)(item->value))->JobType = item->code;
1153    while ((token = lex_get_token(lc, T_ALL)) != T_EOL) {
1154       bool found = false;
1155
1156       Dmsg1(150, "store_backup got token=%s\n", lex_tok_to_str(token));
1157       
1158       if (token != T_IDENTIFIER && token != T_UNQUOTED_STRING && token != T_QUOTED_STRING) {
1159          scan_err1(lc, "Expected a backup/verify keyword, got: %s", lc->str);
1160       }
1161       Dmsg1(190, "Got keyword: %s\n", lc->str);
1162       for (i=0; BakVerFields[i].name; i++) {
1163          if (strcasecmp(lc->str, BakVerFields[i].name) == 0) {
1164             found = true;
1165             if (lex_get_token(lc, T_ALL) != T_EQUALS) {
1166                scan_err1(lc, "Expected an equals, got: %s", lc->str);
1167             }
1168             token = lex_get_token(lc, T_NAME);
1169             Dmsg1(190, "Got value: %s\n", lc->str);
1170             switch (BakVerFields[i].token) {
1171             case 'C':
1172                /* Find Client Resource */
1173                if (pass == 2) {
1174                   res = GetResWithName(R_CLIENT, lc->str);
1175                   if (res == NULL) {
1176                      scan_err1(lc, "Could not find specified Client Resource: %s",
1177                                 lc->str);
1178                   }
1179                   res_all.res_job.client = (CLIENT *)res;
1180                }
1181                break;
1182             case 'F':
1183                /* Find FileSet Resource */
1184                if (pass == 2) {
1185                   res = GetResWithName(R_FILESET, lc->str);
1186                   if (res == NULL) {
1187                      scan_err1(lc, "Could not find specified FileSet Resource: %s\n",
1188                                  lc->str);
1189                   }
1190                   res_all.res_job.fileset = (FILESET *)res;
1191                }
1192                break;
1193             case 'L':
1194                /* Get level */
1195                for (i=0; joblevels[i].level_name; i++) {
1196                   if (joblevels[i].job_type == item->code && 
1197                        strcasecmp(lc->str, joblevels[i].level_name) == 0) {
1198                      ((JOB *)(item->value))->level = joblevels[i].level;
1199                      i = 0;
1200                      break;
1201                   }
1202                }
1203                if (i != 0) {
1204                   scan_err1(lc, "Expected a Job Level keyword, got: %s", lc->str);
1205                }
1206                break;
1207             } /* end switch */
1208             break;
1209          } /* end if strcmp() */
1210       } /* end for */
1211       if (!found) {
1212          scan_err1(lc, "%s not a valid Backup/verify keyword", lc->str);
1213       }
1214    } /* end while */
1215    lc->options = options;             /* reset original options */
1216    set_bit(index, res_all.hdr.item_present);
1217 }
1218
1219 /* 
1220  * Store restore info for Job record 
1221  *
1222  *    Restore = JobId=<job-id> Where=<root-directory> Replace=<options> Bootstrap=<file>
1223  *
1224  */
1225 static void store_restore(LEX *lc, struct res_items *item, int index, int pass)
1226 {
1227    int token, i;
1228    RES *res;
1229    int options = lc->options;
1230
1231    lc->options |= LOPT_NO_IDENT;      /* make spaces significant */
1232
1233    Dmsg0(190, "Enter store_restore()\n");
1234    
1235    ((JOB *)(item->value))->JobType = item->code;
1236    while ((token = lex_get_token(lc, T_ALL)) != T_EOL) {
1237       bool found = false;
1238
1239       if (token != T_IDENTIFIER && token != T_UNQUOTED_STRING && token != T_QUOTED_STRING) {
1240          scan_err1(lc, "expected a name, got: %s", lc->str);
1241       }
1242       for (i=0; RestoreFields[i].name; i++) {
1243          Dmsg1(190, "Restore kw=%s\n", lc->str);
1244          if (strcasecmp(lc->str, RestoreFields[i].name) == 0) {
1245             found = true;
1246             if (lex_get_token(lc, T_ALL) != T_EQUALS) {
1247                scan_err1(lc, "Expected an equals, got: %s", lc->str);
1248             }
1249             token = lex_get_token(lc, T_ALL);
1250             Dmsg1(190, "Restore value=%s\n", lc->str);
1251             switch (RestoreFields[i].token) {
1252             case 'B':
1253                /* Bootstrap */
1254                if (token != T_IDENTIFIER && token != T_UNQUOTED_STRING && token != T_QUOTED_STRING) {
1255                   scan_err1(lc, "Expected a Restore bootstrap file, got: %s", lc->str);
1256                }
1257                if (pass == 1) {
1258                   res_all.res_job.RestoreBootstrap = bstrdup(lc->str);
1259                }
1260                break;
1261             case 'C':
1262                /* Find Client Resource */
1263                if (pass == 2) {
1264                   res = GetResWithName(R_CLIENT, lc->str);
1265                   if (res == NULL) {
1266                      scan_err1(lc, "Could not find specified Client Resource: %s",
1267                                 lc->str);
1268                   }
1269                   res_all.res_job.client = (CLIENT *)res;
1270                }
1271                break;
1272             case 'F':
1273                /* Find FileSet Resource */
1274                if (pass == 2) {
1275                   res = GetResWithName(R_FILESET, lc->str);
1276                   if (res == NULL) {
1277                      scan_err1(lc, "Could not find specified FileSet Resource: %s\n",
1278                                  lc->str);
1279                   }
1280                   res_all.res_job.fileset = (FILESET *)res;
1281                }
1282                break;
1283             case 'J':
1284                /* JobId */
1285                if (token != T_NUMBER) {
1286                   scan_err1(lc, "expected an integer number, got: %s", lc->str);
1287                }
1288                errno = 0;
1289                res_all.res_job.RestoreJobId = strtol(lc->str, NULL, 0);
1290                Dmsg1(190, "RestorJobId=%d\n", res_all.res_job.RestoreJobId);
1291                if (errno != 0) {
1292                   scan_err1(lc, "expected an integer number, got: %s", lc->str);
1293                }
1294                break;
1295             case 'W':
1296                /* Where */
1297                if (token != T_IDENTIFIER && token != T_UNQUOTED_STRING && token != T_QUOTED_STRING) {
1298                   scan_err1(lc, "Expected a Restore root directory, got: %s", lc->str);
1299                }
1300                if (pass == 1) {
1301                   res_all.res_job.RestoreWhere = bstrdup(lc->str);
1302                }
1303                break;
1304             case 'R':
1305                /* Replacement options */
1306                if (token != T_IDENTIFIER && token != T_UNQUOTED_STRING && token != T_QUOTED_STRING) {
1307                   scan_err1(lc, "Expected a keyword name, got: %s", lc->str);
1308                }
1309                /* Fix to scan Replacement options */
1310                for (i=0; ReplaceOptions[i].name; i++) {
1311                   if (strcasecmp(lc->str, ReplaceOptions[i].name) == 0) {
1312                       ((JOB *)(item->value))->replace = ReplaceOptions[i].token;
1313                      i = 0;
1314                      break;
1315                   }
1316                }
1317                if (i != 0) {
1318                   scan_err1(lc, "Expected a Restore replacement option, got: %s", lc->str);
1319                }
1320                break;
1321             } /* end switch */
1322             break;
1323          } /* end if strcmp() */
1324       } /* end for */
1325       if (!found) {
1326          scan_err1(lc, "%s not a valid Restore keyword", lc->str);
1327       }
1328    } /* end while */
1329    lc->options = options;             /* reset original options */
1330    set_bit(index, res_all.hdr.item_present);
1331 }