]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/stored/stored_conf.c
Add maximum network buffer size directive
[bacula/bacula] / bacula / src / stored / stored_conf.c
1 /*
2  * Configuration file parser for Bacula Storage daemon
3  *
4  *     Kern Sibbald, March MM
5  *
6  *   Version $Id$
7  */
8
9 /*
10    Copyright (C) 2000-2004 Kern Sibbald and John Walker
11
12    This program is free software; you can redistribute it and/or
13    modify it under the terms of the GNU General Public License as
14    published by the Free Software Foundation; either version 2 of
15    the License, or (at your option) any later version.
16
17    This program is distributed in the hope that it will be useful,
18    but WITHOUT ANY WARRANTY; without even the implied warranty of
19    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20    General Public License for more details.
21
22    You should have received a copy of the GNU General Public
23    License along with this program; if not, write to the Free
24    Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
25    MA 02111-1307, USA.
26
27  */
28
29 #include "bacula.h"
30 #include "stored.h"
31
32 extern int debug_level;
33
34
35 /* First and last resource ids */
36 int r_first = R_FIRST;
37 int r_last  = R_LAST;
38 pthread_mutex_t res_mutex =  PTHREAD_MUTEX_INITIALIZER;
39
40
41 /* Forward referenced subroutines */
42
43 /* We build the current resource here statically,
44  * then move it to dynamic memory */
45 URES res_all;
46 int res_all_size = sizeof(res_all);
47
48 /* Definition of records permitted within each
49  * resource with the routine to process the record 
50  * information.
51  */ 
52
53 /* Globals for the Storage daemon. */
54 static struct res_items store_items[] = {
55    {"name",                  store_name, ITEM(res_store.hdr.name),   0, ITEM_REQUIRED, 0},
56    {"description",           store_str,  ITEM(res_dir.hdr.desc),     0, 0, 0},
57    {"address",               store_str,  ITEM(res_store.address),    0, 0, 0}, /* deprecated */
58    {"sdaddress",             store_str,  ITEM(res_store.SDaddr),     0, 0, 0},
59    {"messages",              store_res,  ITEM(res_store.messages),   0, R_MSGS, 0},
60    {"sdport",                store_int,  ITEM(res_store.SDport),     0, ITEM_DEFAULT, 9103},
61    {"sddport",               store_int,  ITEM(res_store.SDDport),    0, 0, 0}, /* deprecated */
62    {"workingdirectory",      store_dir,  ITEM(res_store.working_directory), 0, ITEM_REQUIRED, 0},
63    {"piddirectory",          store_dir,  ITEM(res_store.pid_directory), 0, ITEM_REQUIRED, 0},
64    {"subsysdirectory",       store_dir,  ITEM(res_store.subsys_directory), 0, 0, 0},
65    {"requiressl",            store_yesno,ITEM(res_store.require_ssl), 1, ITEM_DEFAULT, 0},
66    {"maximumconcurrentjobs", store_pint, ITEM(res_store.max_concurrent_jobs), 0, ITEM_DEFAULT, 10},
67    {"heartbeatinterval",     store_time, ITEM(res_store.heartbeat_interval), 0, ITEM_DEFAULT, 0},
68    {NULL, NULL, 0, 0, 0, 0} 
69 };
70
71
72 /* Directors that can speak to the Storage daemon */
73 static struct res_items dir_items[] = {
74    {"name",        store_name,     ITEM(res_dir.hdr.name),   0, ITEM_REQUIRED, 0},
75    {"description", store_str,      ITEM(res_dir.hdr.desc),   0, 0, 0},
76    {"password",    store_password, ITEM(res_dir.password),   0, ITEM_REQUIRED, 0},
77    {"address",     store_str,      ITEM(res_dir.address),    0, 0, 0},
78    {"enablessl",   store_yesno,    ITEM(res_dir.enable_ssl), 1, ITEM_DEFAULT, 0},
79    {NULL, NULL, 0, 0, 0, 0} 
80 };
81
82 /* Device definition */
83 static struct res_items dev_items[] = {
84    {"name",                  store_name,   ITEM(res_dev.hdr.name),        0, ITEM_REQUIRED, 0},
85    {"description",           store_str,    ITEM(res_dir.hdr.desc),        0, 0, 0},
86    {"mediatype",             store_strname,ITEM(res_dev.media_type),      0, ITEM_REQUIRED, 0},
87    {"archivedevice",         store_strname,ITEM(res_dev.device_name),     0, ITEM_REQUIRED, 0},
88    {"hardwareendoffile",     store_yesno,  ITEM(res_dev.cap_bits), CAP_EOF,  ITEM_DEFAULT, 1},
89    {"hardwareendofmedium",   store_yesno,  ITEM(res_dev.cap_bits), CAP_EOM,  ITEM_DEFAULT, 1},
90    {"backwardspacerecord",   store_yesno,  ITEM(res_dev.cap_bits), CAP_BSR,  ITEM_DEFAULT, 1},
91    {"backwardspacefile",     store_yesno,  ITEM(res_dev.cap_bits), CAP_BSF,  ITEM_DEFAULT, 1},
92    {"bsfateom",              store_yesno,  ITEM(res_dev.cap_bits), CAP_BSFATEOM, ITEM_DEFAULT, 0},
93    {"twoeof",                store_yesno,  ITEM(res_dev.cap_bits), CAP_TWOEOF, ITEM_DEFAULT, 0},
94    {"forwardspacerecord",    store_yesno,  ITEM(res_dev.cap_bits), CAP_FSR,  ITEM_DEFAULT, 1},
95    {"forwardspacefile",      store_yesno,  ITEM(res_dev.cap_bits), CAP_FSF,  ITEM_DEFAULT, 1},
96    {"fastforwardspacefile",  store_yesno,  ITEM(res_dev.cap_bits), CAP_FASTFSF, ITEM_DEFAULT, 1},
97    {"removablemedia",        store_yesno,  ITEM(res_dev.cap_bits), CAP_REM,  ITEM_DEFAULT, 1},
98    {"randomaccess",          store_yesno,  ITEM(res_dev.cap_bits), CAP_RACCESS, 0, 0},
99    {"automaticmount",        store_yesno,  ITEM(res_dev.cap_bits), CAP_AUTOMOUNT,  ITEM_DEFAULT, 0},
100    {"labelmedia",            store_yesno,  ITEM(res_dev.cap_bits), CAP_LABEL,      ITEM_DEFAULT, 0},
101    {"alwaysopen",            store_yesno,  ITEM(res_dev.cap_bits), CAP_ALWAYSOPEN, ITEM_DEFAULT, 1},
102    {"autochanger",           store_yesno,  ITEM(res_dev.cap_bits), CAP_AUTOCHANGER, ITEM_DEFAULT, 0},
103    {"changerdevice",         store_strname,ITEM(res_dev.changer_name), 0, 0, 0},
104    {"changercommand",        store_strname,ITEM(res_dev.changer_command), 0, 0, 0},
105    {"maximumchangerwait",    store_pint,   ITEM(res_dev.max_changer_wait), 0, ITEM_DEFAULT, 5 * 60},
106    {"maximumopenwait",       store_pint,   ITEM(res_dev.max_open_wait), 0, ITEM_DEFAULT, 5 * 60},
107    {"maximumopenvolumes",    store_pint,   ITEM(res_dev.max_open_vols), 0, ITEM_DEFAULT, 1},
108    {"maximumnetworkbuffersize", store_pint, ITEM(res_dev.max_network_buffer_size), 0, 0, 0},
109    {"volumepollinterval",    store_time,   ITEM(res_dev.vol_poll_interval), 0, 0, 0},
110    {"offlineonunmount",      store_yesno,  ITEM(res_dev.cap_bits), CAP_OFFLINEUNMOUNT, ITEM_DEFAULT, 0},
111    {"maximumrewindwait",     store_pint,   ITEM(res_dev.max_rewind_wait), 0, ITEM_DEFAULT, 5 * 60},
112    {"minimumblocksize",      store_pint,   ITEM(res_dev.min_block_size), 0, 0, 0},
113    {"maximumblocksize",      store_pint,   ITEM(res_dev.max_block_size), 0, 0, 0},
114    {"maximumvolumesize",     store_size,   ITEM(res_dev.max_volume_size), 0, 0, 0},
115    {"maximumfilesize",       store_size,   ITEM(res_dev.max_file_size), 0, ITEM_DEFAULT, 1000000000},
116    {"volumecapacity",        store_size,   ITEM(res_dev.volume_capacity), 0, 0, 0},
117    {NULL, NULL, 0, 0, 0, 0} 
118 };
119
120 // {"mountanonymousvolumes", store_yesno,  ITEM(res_dev.cap_bits), CAP_ANONVOLS,   ITEM_DEFAULT, 0},
121
122
123 /* Message resource */
124 extern struct res_items msgs_items[];
125
126
127 /* This is the master resource definition */
128 struct s_res resources[] = {
129    {"director",      dir_items,   R_DIRECTOR,  NULL},
130    {"storage",       store_items, R_STORAGE,   NULL},
131    {"device",        dev_items,   R_DEVICE,    NULL},
132    {"messages",      msgs_items,  R_MSGS,      NULL},
133    {NULL,            NULL,        0,           NULL}
134 };
135
136
137
138 /* Dump contents of resource */
139 void dump_resource(int type, RES *reshdr, void sendit(void *sock, char *fmt, ...), void *sock)
140 {
141    URES *res = (URES *)reshdr;
142    char buf[MAXSTRING];
143    int recurse = 1;
144    if (res == NULL) {
145       sendit(sock, _("Warning: no %s resource (%d) defined.\n"), res_to_str(type), type);
146       return;
147    }
148    sendit(sock, "dump_resource type=%d\n", type);
149    if (type < 0) {                    /* no recursion */
150       type = - type;
151       recurse = 0;
152    }
153    switch (type) {
154    case R_DIRECTOR:
155       sendit(sock, "Director: name=%s\n", res->res_dir.hdr.name);
156       break;
157    case R_STORAGE:
158       sendit(sock, "Storage: name=%s SDaddr=%s SDport=%d SDDport=%d HB=%s\n",
159          res->res_store.hdr.name, NPRT(res->res_store.SDaddr),
160          res->res_store.SDport, res->res_store.SDDport,
161          edit_utime(res->res_store.heartbeat_interval, buf));
162       break;
163    case R_DEVICE:
164       sendit(sock, "Device: name=%s MediaType=%s Device=%s\n",
165          res->res_dev.hdr.name,
166          res->res_dev.media_type, res->res_dev.device_name);
167       sendit(sock, "        rew_wait=%d min_bs=%d max_bs=%d\n",
168          res->res_dev.max_rewind_wait, res->res_dev.min_block_size, 
169          res->res_dev.max_block_size);
170       sendit(sock, "        max_jobs=%d max_files=%" lld " max_size=%" lld "\n",
171          res->res_dev.max_volume_jobs, res->res_dev.max_volume_files,
172          res->res_dev.max_volume_size);
173       sendit(sock, "        max_file_size=%" lld " capacity=%" lld "\n",
174          res->res_dev.max_file_size, res->res_dev.volume_capacity);
175       strcpy(buf, "        ");
176       if (res->res_dev.cap_bits & CAP_EOF) {
177          bstrncat(buf, "CAP_EOF ", sizeof(buf));
178       }
179       if (res->res_dev.cap_bits & CAP_BSR) {
180          bstrncat(buf, "CAP_BSR ", sizeof(buf));
181       }
182       if (res->res_dev.cap_bits & CAP_BSF) {
183          bstrncat(buf, "CAP_BSF ", sizeof(buf));
184       }
185       if (res->res_dev.cap_bits & CAP_FSR) {
186          bstrncat(buf, "CAP_FSR ", sizeof(buf));
187       }
188       if (res->res_dev.cap_bits & CAP_FSF) {
189          bstrncat(buf, "CAP_FSF ", sizeof(buf));
190       }
191       if (res->res_dev.cap_bits & CAP_EOM) {
192          bstrncat(buf, "CAP_EOM ", sizeof(buf));
193       }
194       if (res->res_dev.cap_bits & CAP_REM) {
195          bstrncat(buf, "CAP_REM ", sizeof(buf));
196       }
197       if (res->res_dev.cap_bits & CAP_RACCESS) {
198          bstrncat(buf, "CAP_RACCESS ", sizeof(buf));
199       }
200       if (res->res_dev.cap_bits & CAP_AUTOMOUNT) {
201          bstrncat(buf, "CAP_AUTOMOUNT ", sizeof(buf));
202       }
203       if (res->res_dev.cap_bits & CAP_LABEL) {
204          bstrncat(buf, "CAP_LABEL ", sizeof(buf));
205       }
206       if (res->res_dev.cap_bits & CAP_ANONVOLS) {
207          bstrncat(buf, "CAP_ANONVOLS ", sizeof(buf));
208       }
209       if (res->res_dev.cap_bits & CAP_ALWAYSOPEN) {
210          bstrncat(buf, "CAP_ALWAYSOPEN ", sizeof(buf));
211       }
212       bstrncat(buf, "\n", sizeof(buf));
213       sendit(sock, buf);
214       break;
215    case R_MSGS:
216       sendit(sock, "Messages: name=%s\n", res->res_msgs.hdr.name);
217       if (res->res_msgs.mail_cmd) 
218          sendit(sock, "      mailcmd=%s\n", res->res_msgs.mail_cmd);
219       if (res->res_msgs.operator_cmd) 
220          sendit(sock, "      opcmd=%s\n", res->res_msgs.operator_cmd);
221       break;
222    default:
223       sendit(sock, _("Warning: unknown resource type %d\n"), type);
224       break;
225    }
226    if (recurse && res->res_dir.hdr.next)
227       dump_resource(type, (RES *)res->res_dir.hdr.next, sendit, sock);
228 }
229
230 /* 
231  * Free memory of resource.  
232  * NB, we don't need to worry about freeing any references
233  * to other resources as they will be freed when that 
234  * resource chain is traversed.  Mainly we worry about freeing
235  * allocated strings (names).
236  */
237 void free_resource(int type)
238 {
239    URES *nres;
240    URES *res;
241    int rindex = type - r_first;
242    res = (URES *)resources[rindex].res_head;
243
244    if (res == NULL)
245       return;
246
247    /* common stuff -- free the resource name */
248    nres = (URES *)res->res_dir.hdr.next;
249    if (res->res_dir.hdr.name) {
250       free(res->res_dir.hdr.name);
251    }
252    if (res->res_dir.hdr.desc) {
253       free(res->res_dir.hdr.desc);
254    }
255
256
257    switch (type) {
258       case R_DIRECTOR:
259          if (res->res_dir.password) {
260             free(res->res_dir.password);
261          }
262          if (res->res_dir.address) {
263             free(res->res_dir.address);
264          }
265          break;
266       case R_STORAGE:
267          if (res->res_store.address) {  /* ***FIXME*** deprecated */
268             free(res->res_store.address);
269          }
270          if (res->res_store.SDaddr) {
271             free(res->res_store.SDaddr);
272          }
273          if (res->res_store.working_directory) {
274             free(res->res_store.working_directory);
275          }
276          if (res->res_store.pid_directory) {
277             free(res->res_store.pid_directory);
278          }
279          if (res->res_store.subsys_directory) {
280             free(res->res_store.subsys_directory);
281          }
282          break;
283       case R_DEVICE:
284          if (res->res_dev.media_type) {
285             free(res->res_dev.media_type);
286          }
287          if (res->res_dev.device_name) {
288             free(res->res_dev.device_name);
289          }
290          if (res->res_dev.changer_name) {
291             free(res->res_dev.changer_name);
292          }
293          if (res->res_dev.changer_command) {
294             free(res->res_dev.changer_command);
295          }
296          break;
297       case R_MSGS:
298          if (res->res_msgs.mail_cmd) {
299             free(res->res_msgs.mail_cmd);
300          }
301          if (res->res_msgs.operator_cmd) {
302             free(res->res_msgs.operator_cmd);
303          }
304          free_msgs_res((MSGS *)res);  /* free message resource */
305          res = NULL;
306          break;
307       default:
308          Dmsg1(0, "Unknown resource type %d\n", type);
309          break;
310    }
311    /* Common stuff again -- free the resource, recurse to next one */
312    if (res) {
313       free(res);
314    }
315    resources[rindex].res_head = (RES *)nres;
316    if (nres) {
317       free_resource(type);
318    }
319 }
320
321 /* Save the new resource by chaining it into the head list for
322  * the resource. If this is pass 2, we update any resource
323  * pointers (currently only in the Job resource).
324  */
325 void save_resource(int type, struct res_items *items, int pass)
326 {
327    URES *res;
328    int rindex = type - r_first;
329    int i, size;
330    int error = 0;
331
332    /* 
333     * Ensure that all required items are present
334     */
335    for (i=0; items[i].name; i++) {
336       if (items[i].flags & ITEM_REQUIRED) {
337          if (!bit_is_set(i, res_all.res_dir.hdr.item_present)) {  
338             Emsg2(M_ABORT, 0, _("%s item is required in %s resource, but not found.\n"),
339               items[i].name, resources[rindex]);
340           }
341       }
342       /* If this triggers, take a look at lib/parse_conf.h */
343       if (i >= MAX_RES_ITEMS) {
344          Emsg1(M_ABORT, 0, _("Too many items in %s resource\n"), resources[rindex]);
345       }
346    }
347
348    /* During pass 2, we looked up pointers to all the resources
349     * referrenced in the current resource, , now we
350     * must copy their address from the static record to the allocated
351     * record.
352     */
353    if (pass == 2) {
354       switch (type) {
355          /* Resources not containing a resource */
356          case R_DIRECTOR:
357          case R_DEVICE:
358          case R_MSGS:
359             break;
360
361          /* Resources containing a resource */
362          case R_STORAGE:
363             if ((res = (URES *)GetResWithName(R_STORAGE, res_all.res_dir.hdr.name)) == NULL) {
364                Emsg1(M_ABORT, 0, "Cannot find Storage resource %s\n", res_all.res_dir.hdr.name);
365             }
366             res->res_store.messages = res_all.res_store.messages;
367             break;
368          default:
369             printf("Unknown resource type %d\n", type);
370             error = 1;
371             break;
372       }
373
374
375       if (res_all.res_dir.hdr.name) {
376          free(res_all.res_dir.hdr.name);
377          res_all.res_dir.hdr.name = NULL;
378       }
379       if (res_all.res_dir.hdr.desc) {
380          free(res_all.res_dir.hdr.desc);
381          res_all.res_dir.hdr.desc = NULL;
382       }
383       return;
384    }
385
386    /* The following code is only executed on pass 1 */
387    switch (type) {
388       case R_DIRECTOR:
389          size = sizeof(DIRRES);
390          break;
391       case R_STORAGE:
392          size = sizeof(STORES);
393          break;
394       case R_DEVICE:
395          size = sizeof(DEVRES);
396          break;
397       case R_MSGS:
398          size = sizeof(MSGS);   
399          break;
400       default:
401          printf("Unknown resource type %d\n", type);
402          error = 1;
403          size = 1;
404          break;
405    }
406    /* Common */
407    if (!error) {
408       res = (URES *)malloc(size);
409       memcpy(res, &res_all, size);
410       if (!resources[rindex].res_head) {
411          resources[rindex].res_head = (RES *)res; /* store first entry */
412       } else {
413          RES *next;
414          /* Add new res to end of chain */
415          for (next=resources[rindex].res_head; next->next; next=next->next) {
416             if (strcmp(next->name, res->res_dir.hdr.name) == 0) {
417                Emsg2(M_ERROR_TERM, 0,
418                   _("Attempt to define second %s resource named \"%s\" is not permitted.\n"),
419                   resources[rindex].name, res->res_dir.hdr.name);
420             }
421          }
422          next->next = (RES *)res;
423          Dmsg2(90, "Inserting %s res: %s\n", res_to_str(type),
424                res->res_dir.hdr.name);
425       }
426    }
427 }