2 * Amanda, The Advanced Maryland Automatic Network Disk Archiver
3 * Copyright (c) 1991-2000 University of Maryland at College Park
6 * Permission to use, copy, modify, distribute, and sell this software and its
7 * documentation for any purpose is hereby granted without fee, provided that
8 * the above copyright notice appear in all copies and that both that
9 * copyright notice and this permission notice appear in supporting
10 * documentation, and that the name of U.M. not be used in advertising or
11 * publicity pertaining to distribution of the software without specific,
12 * written prior permission. U.M. makes no representations about the
13 * suitability of this software for any purpose. It is provided "as is"
14 * without express or implied warranty.
16 * U.M. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL U.M.
18 * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
20 * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
21 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23 * Author: James da Silva, Systems Design and Analysis Group
24 * Computer Science Department
25 * University of Maryland at College Park
28 * $Id: conffile.h,v 1.72 2006/07/26 15:17:37 martinea Exp $
30 * interface for config file reading code
38 /* Getting Configuration Values
39 * ============================
41 * Amanda configurations consist of a number of "global" parameters, as well as named
42 * subsections of four types: dumptypes, interfaces, holdingdisks, and tapetypes. The
43 * global parameters are fetched with the getconf_CONFTYPE functions, keyed by a
44 * confparam_t constant (with prefix CNF_). The subsection parameters are fetched with
45 * SUBSEC_get_PARAM() macros, e.g., tapetype_get_blocksize(ttyp), where the argument
46 * comes from lookup_SUBSEC(), in this case lookup_tapetype(name).
51 * This module juggles two kinds of types: C types and conftypes. Conftypes include
52 * everything from integers through property lists, and are specific to the needs of
53 * the configuration system. Each conftype has a corresponding C type, which is of course
54 * necessary to actually use the data.
56 * The val_t__CONFTYPE macros represent the canonical correspondance of conftypes to C
57 * types, but in general the relationship is obvious: ints, strings, reals, and so forth
58 * are represented directly. Enumerated conftypes are represented by the corresponding
59 * C enum type. The 'rate' conftype is represented as a 2-element array of doubles, and
60 * the 'intrange' conftype is represented as a 2-element array of ints. exincludes are
61 * a exinclude_t *, and a proplist is represented as a GHashTable *.
65 * Note that, unless specified, all memory in this module is managed by the module
66 * itself; return strings should not be freed by the caller.
72 * This module uses a generic val_t type to hold values of various types -- it's basically
73 * a union with type information and a 'seen' flag. In a way, it's a very simple equivalent
74 * to Glib's GValue. It's worth considering rewriting this with GValue, but for the moment,
75 * this works and it's here.
78 /* holdingdisk types */
80 HOLD_NEVER, /* Always direct to tape */
81 HOLD_AUTO, /* If possible */
82 HOLD_REQUIRED /* Always to holding disk */
85 /* Compression types */
87 COMP_NONE, /* No compression */
88 COMP_FAST, /* Fast compression on client */
89 COMP_BEST, /* Best compression on client */
90 COMP_CUST, /* Custom compression on client */
91 COMP_SERVER_FAST, /* Fast compression on server */
92 COMP_SERVER_BEST, /* Best compression on server */
93 COMP_SERVER_CUST /* Custom compression on server */
96 /* Encryption types */
98 ENCRYPT_NONE, /* No encryption */
99 ENCRYPT_CUST, /* Custom encryption on client */
100 ENCRYPT_SERV_CUST /* Custom encryption on server */
103 /* Estimate strategies */
105 ES_CLIENT, /* client estimate */
106 ES_SERVER, /* server estimate */
107 ES_CALCSIZE, /* calcsize estimate */
111 /* Dump strategies */
113 DS_SKIP, /* Don't do any dumps at all */
114 DS_STANDARD, /* Standard (0 1 1 1 1 2 2 2 ...) */
115 DS_NOFULL, /* No full's (1 1 1 ...) */
116 DS_NOINC, /* No inc's (0 0 0 ...) */
117 DS_4, /* ? (0 1 2 3 4 5 6 7 8 9 10 11 ...) */
118 DS_5, /* ? (0 1 1 1 1 1 1 1 1 1 1 1 ...) */
119 DS_HANOI, /* Tower of Hanoi (? ? ? ? ? ...) */
120 DS_INCRONLY, /* Forced fulls (0 1 1 2 2 FORCE0 1 1 ...) */
131 ALGO_ALGO /* sentinel */
134 typedef struct exinclude_s {
140 typedef GHashTable* proplist_t;
142 /* Names for the type of value in a val_t. Mostly for internal use, but useful
143 * for wrapping val_t's, too. */
166 /* This should be considered an opaque type for any other modules. The complete
167 * struct is included here to allow quick access via macros. Access it *only* through
169 typedef struct val_s {
178 exinclude_t exinclude;
186 /* Functions to typecheck and extract a particular type of
187 * value from a val_t. All call error() if the type is incorrect,
188 * as this is a programming error. */
189 int val_t_to_int (val_t *);
190 off_t val_t_to_am64 (val_t *);
191 float val_t_to_real (val_t *);
192 char *val_t_to_str (val_t *); /* (also converts CONFTYPE_IDENT) */
193 char *val_t_to_ident (val_t *); /* (also converts CONFTYPE_STR) */
194 time_t val_t_to_time (val_t *);
195 ssize_t val_t_to_size (val_t *);
196 int val_t_to_boolean (val_t *);
197 comp_t val_t_to_compress (val_t *);
198 encrypt_t val_t_to_encrypt (val_t *);
199 dump_holdingdisk_t val_t_to_holding (val_t *);
200 estimate_t val_t_to_estimate (val_t *);
201 strategy_t val_t_to_strategy (val_t *);
202 taperalgo_t val_t_to_taperalgo(val_t *);
203 int val_t_to_priority (val_t *);
204 float *val_t_to_rate (val_t *); /* array of two floats */
205 exinclude_t val_t_to_exinclude(val_t *);
206 int *val_t_to_intrange (val_t *); /* array of two ints */
207 proplist_t val_t_to_proplist (val_t *);
209 /* Has the given val_t been seen in a configuration file or config overwrite?
211 * @param val: val_t* to examine
214 #define val_t_seen(val) ((val)->seen)
216 /* What is the underlying type of this val_t?
218 * @param val: val_t* to examine
219 * @returns: conftype_t
221 #define val_t_type(val) ((val)->type)
223 /* Macros to convert val_t's to a particular type without the benefit of
224 * a typecheck. Use these only if you really know what you're doing!
226 * Implementation note: these macros encode the relationship of conftypes
227 * (in the macro name) to the corresponding union field. The macros work
230 #define val_t__seen(val) ((val)->seen)
231 #define val_t__int(val) ((val)->v.i)
232 #define val_t__am64(val) ((val)->v.am64)
233 #define val_t__real(val) ((val)->v.r)
234 #define val_t__str(val) ((val)->v.s)
235 #define val_t__ident(val) ((val)->v.s)
236 #define val_t__time(val) ((val)->v.t)
237 #define val_t__size(val) ((val)->v.size)
238 #define val_t__boolean(val) ((val)->v.i)
239 #define val_t__compress(val) ((val)->v.i)
240 #define val_t__encrypt(val) ((val)->v.i)
241 #define val_t__holding(val) ((val)->v.i)
242 #define val_t__estimate(val) ((val)->v.i)
243 #define val_t__strategy(val) ((val)->v.i)
244 #define val_t__taperalgo(val) ((val)->v.i)
245 #define val_t__priority(val) ((val)->v.i)
246 #define val_t__rate(val) ((val)->v.rate)
247 #define val_t__exinclude(val) ((val)->v.exinclude)
248 #define val_t__intrange(val) ((val)->v.intrange)
249 #define val_t__proplist(val) ((val)->v.proplist)
253 * Programs get val_t's by giving the index of the parameters they're interested in.
254 * For global parameters, these start with CNF; for subsections, they start with the
255 * name of the subsection.
259 * Global parameter access
302 CNF_DEVICE_OUTPUT_BUFFER_SIZE,
308 CNF_AMRECOVER_DO_FSF,
309 CNF_AMRECOVER_CHECK_LABEL,
310 CNF_AMRECOVER_CHANGER,
312 CNF_FLUSH_THRESHOLD_DUMPED,
313 CNF_FLUSH_THRESHOLD_SCHEDULED,
324 CNF_DEBUG_AMIDXTAPED,
338 CNF_DEBUG_SENDBACKUP,
339 CNF_RESERVED_UDP_PORT,
340 CNF_RESERVED_TCP_PORT,
341 CNF_UNRESERVED_TCP_PORT,
342 CNF_CNF /* sentinel */
345 /* Given a confparm_key, return a pointer to the corresponding val_t.
347 * @param key: confparm_key
348 * @returns: pointer to value
350 val_t *getconf(confparm_key key);
352 /* (convenience macro) has this global parameter been seen?
354 * @param key: confparm_key
357 #define getconf_seen(key) (val_t_seen(getconf((key))))
359 /* (convenience macros)
360 * Fetch a gloabl parameter of a specific type. Note that these
361 * convenience macros have a different form from those for the
362 * subsections: here you specify a type and a key, while for the
363 * subsections you specify only a key. The difference is historical.
365 * @param key: confparm_key
368 #define getconf_int(key) (val_t_to_int(getconf((key))))
369 #define getconf_am64(key) (val_t_to_am64(getconf((key))))
370 #define getconf_real(key) (val_t_to_real(getconf((key))))
371 #define getconf_str(key) (val_t_to_str(getconf((key))))
372 #define getconf_ident(key) (val_t_to_ident(getconf((key))))
373 #define getconf_time(key) (val_t_to_time(getconf((key))))
374 #define getconf_size(key) (val_t_to_size(getconf((key))))
375 #define getconf_boolean(key) (val_t_to_boolean(getconf((key))))
376 #define getconf_compress(key) (val_t_to_compress(getconf((key))))
377 #define getconf_encrypt(key) (val_t_to_encrypt(getconf((key))))
378 #define getconf_holding(key) (val_t_to_holding(getconf((key))))
379 #define getconf_estimate(key) (val_t_to_estimate(getconf((key))))
380 #define getconf_strategy(key) (val_t_to_strategy(getconf((key))))
381 #define getconf_taperalgo(key) (val_t_to_taperalgo(getconf((key))))
382 #define getconf_priority(key) (val_t_to_priority(getconf((key))))
383 #define getconf_rate(key) (val_t_to_rate(getconf((key))))
384 #define getconf_exinclude(key) (val_t_to_exinclude(getconf((key))))
385 #define getconf_intrange(key) (val_t_to_intrange(getconf((key))))
386 #define getconf_proplist(key) (val_t_to_proplist(getconf((key))))
388 /* Get a list of names for subsections of the given type
390 * @param listname: the desired type of subsection
391 * @returns: list of subsection names; caller is responsible for freeing
392 * this list, but not the strings it points to, using g_slist_free().
394 GSList *getconf_list(char *listname);
396 /* Get a configuration value by name, supporting the TYPE:SUBSEC:KEYWORD.
397 * Returns NULL if the configuration value doesnt exist.
399 val_t *getconf_byname(char *key);
404 * Values which aren't directly specified by the configuration, but which
405 * are derived from it.
408 /* Return a divisor which will convert a value in units of kilo-whatevers
409 * to the user's selected display unit.
411 * @returns: long integer divisor
413 long int getconf_unit_divisor(void);
415 /* If any of these globals are true, the corresponding component will
416 * send verbose debugging output to the debug file. The options are
417 * set during config_init, but can be modified at will after that if
420 extern int debug_amandad;
421 extern int debug_amidxtaped;
422 extern int debug_amindexd;
423 extern int debug_amrecover;
424 extern int debug_auth;
425 extern int debug_event;
426 extern int debug_holding;
427 extern int debug_protocol;
428 extern int debug_planner;
429 extern int debug_driver;
430 extern int debug_dumper;
431 extern int debug_chunker;
432 extern int debug_taper;
433 extern int debug_selfcheck;
434 extern int debug_sendsize;
435 extern int debug_sendbackup;
438 * Tapetype parameter access
445 TAPETYPE_READBLOCKSIZE,
450 TAPETYPE_TAPETYPE /* sentinel */
454 typedef struct tapetype_s tapetype_t;
456 /* Given the name of the tapetype, return a tapetype object. Returns NULL
457 * if no matching tapetype exists. Note that the match is case-insensitive.
459 * @param identifier: name of the desired tapetype
460 * @returns: object or NULL
462 tapetype_t *lookup_tapetype(char *identifier);
464 /* Given a tapetype and a key, return a pointer to the corresponding val_t.
466 * @param ttyp: the tapetype to examine
467 * @param key: tapetype_key (one of the TAPETYPE_* constants)
468 * @returns: pointer to value
470 val_t *tapetype_getconf(tapetype_t *ttyp, tapetype_key key);
472 /* Get the name of this tapetype.
474 * @param ttyp: the tapetype to examine
475 * @returns: name of the tapetype
477 char *tapetype_name(tapetype_t *ttyp);
479 /* (convenience macro) has this parameter been seen in this tapetype? This
480 * applies to the specific parameter *within* the tapetype.
482 * @param key: tapetype_key
485 #define tapetype_seen(ttyp, key) (val_t_seen(tapetype_getconf((ttyp), (key))))
487 /* (convenience macros)
488 * fetch a particular parameter; caller must know the correct type.
490 * @param ttyp: the tapetype to examine
493 #define tapetype_get_comment(ttyp) (val_t_to_str(tapetype_getconf((ttyp), TAPETYPE_COMMENT)))
494 #define tapetype_get_lbl_templ(ttyp) (val_t_to_str(tapetype_getconf((ttyp), TAPETYPE_LBL_TEMPL)))
495 #define tapetype_get_blocksize(ttyp) (val_t_to_size(tapetype_getconf((ttyp), TAPETYPE_BLOCKSIZE)))
496 #define tapetype_get_readblocksize(ttyp) (val_t_to_size(tapetype_getconf((ttyp), TAPETYPE_READBLOCKSIZE)))
497 #define tapetype_get_length(ttyp) (val_t_to_am64(tapetype_getconf((ttyp), TAPETYPE_LENGTH)))
498 #define tapetype_get_filemark(ttyp) (val_t_to_am64(tapetype_getconf((ttyp), TAPETYPE_FILEMARK)))
499 #define tapetype_get_speed(ttyp) (val_t_to_int(tapetype_getconf((ttyp), TAPETYPE_SPEED)))
500 #define tapetype_get_file_pad(ttyp) (val_t_to_boolean(tapetype_getconf((ttyp), TAPETYPE_FILE_PAD)))
503 * Dumptype parameter access
509 DUMPTYPE_SRVCOMPPROG,
510 DUMPTYPE_CLNTCOMPPROG,
511 DUMPTYPE_SRV_ENCRYPT,
512 DUMPTYPE_CLNT_ENCRYPT,
513 DUMPTYPE_AMANDAD_PATH,
514 DUMPTYPE_CLIENT_USERNAME,
516 DUMPTYPE_SECURITY_DRIVER,
522 DUMPTYPE_MAXPROMOTEDAY,
523 DUMPTYPE_BUMPPERCENT,
532 DUMPTYPE_SRV_DECRYPT_OPT,
533 DUMPTYPE_CLNT_DECRYPT_OPT,
535 DUMPTYPE_TAPE_SPLITSIZE,
536 DUMPTYPE_FALLBACK_SPLITSIZE,
537 DUMPTYPE_SPLIT_DISKBUFFER,
541 DUMPTYPE_HOLDINGDISK,
545 DUMPTYPE_DUMPTYPE /* sentinel */
549 typedef struct dumptype_s dumptype_t;
551 /* Given the name of the dumptype, return a dumptype object. Returns NULL
552 * if no matching dumptype exists. Note that the match is case-insensitive.
554 * @param identifier: name of the desired dumptype
555 * @returns: object or NULL
557 dumptype_t *lookup_dumptype(char *identifier);
559 /* Given a dumptype and a key, return a pointer to the corresponding val_t.
561 * @param dtyp: the dumptype to examine
562 * @param key: dumptype_key (one of the TAPETYPE_* constants)
563 * @returns: pointer to value
565 val_t *dumptype_getconf(dumptype_t *dtyp, dumptype_key key);
567 /* Get the name of this dumptype.
569 * @param dtyp: the dumptype to examine
570 * @returns: name of the dumptype
572 char *dumptype_name(dumptype_t *dtyp);
574 /* (convenience macro) has this parameter been seen in this dumptype? This
575 * applies to the specific parameter *within* the dumptype.
577 * @param key: dumptype_key
580 #define dumptype_seen(dtyp, key) (val_t_seen(dumptype_getconf((dtyp), (key))))
582 /* (convenience macros)
583 * fetch a particular parameter; caller must know the correct type.
585 * @param dtyp: the dumptype to examine
588 #define dumptype_get_comment(dtyp) (val_t_to_str(dumptype_getconf((dtyp), DUMPTYPE_COMMENT)))
589 #define dumptype_get_program(dtyp) (val_t_to_str(dumptype_getconf((dtyp), DUMPTYPE_PROGRAM)))
590 #define dumptype_get_srvcompprog(dtyp) (val_t_to_str(dumptype_getconf((dtyp), DUMPTYPE_SRVCOMPPROG)))
591 #define dumptype_get_clntcompprog(dtyp) (val_t_to_str(dumptype_getconf((dtyp), DUMPTYPE_CLNTCOMPPROG)))
592 #define dumptype_get_srv_encrypt(dtyp) (val_t_to_str(dumptype_getconf((dtyp), DUMPTYPE_SRV_ENCRYPT)))
593 #define dumptype_get_clnt_encrypt(dtyp) (val_t_to_str(dumptype_getconf((dtyp), DUMPTYPE_CLNT_ENCRYPT)))
594 #define dumptype_get_amandad_path(dtyp) (val_t_to_str(dumptype_getconf((dtyp), DUMPTYPE_AMANDAD_PATH)))
595 #define dumptype_get_client_username(dtyp) (val_t_to_str(dumptype_getconf((dtyp), DUMPTYPE_CLIENT_USERNAME)))
596 #define dumptype_get_ssh_keys(dtyp) (val_t_to_str(dumptype_getconf((dtyp), DUMPTYPE_SSH_KEYS)))
597 #define dumptype_get_security_driver(dtyp) (val_t_to_str(dumptype_getconf((dtyp), DUMPTYPE_SECURITY_DRIVER)))
598 #define dumptype_get_exclude(dtyp) (val_t_to_exinclude(dumptype_getconf((dtyp), DUMPTYPE_EXCLUDE)))
599 #define dumptype_get_include(dtyp) (val_t_to_exinclude(dumptype_getconf((dtyp), DUMPTYPE_INCLUDE)))
600 #define dumptype_get_priority(dtyp) (val_t_to_priority(dumptype_getconf((dtyp), DUMPTYPE_PRIORITY)))
601 #define dumptype_get_dumpcycle(dtyp) (val_t_to_int(dumptype_getconf((dtyp), DUMPTYPE_DUMPCYCLE)))
602 #define dumptype_get_maxcycle(dtyp) (val_t_to_int(dumptype_getconf((dtyp), DUMPTYPE_MAXCYCLE)))
603 #define dumptype_get_frequency(dtyp) (val_t_to_int(dumptype_getconf((dtyp), DUMPTYPE_FREQUENCY)))
604 #define dumptype_get_maxdumps(dtyp) (val_t_to_int(dumptype_getconf((dtyp), DUMPTYPE_MAXDUMPS)))
605 #define dumptype_get_maxpromoteday(dtyp) (val_t_to_int(dumptype_getconf((dtyp), DUMPTYPE_MAXPROMOTEDAY)))
606 #define dumptype_get_bumppercent(dtyp) (val_t_to_int(dumptype_getconf((dtyp), DUMPTYPE_BUMPPERCENT)))
607 #define dumptype_get_bumpsize(dtyp) (val_t_to_am64(dumptype_getconf((dtyp), DUMPTYPE_BUMPSIZE)))
608 #define dumptype_get_bumpdays(dtyp) (val_t_to_int(dumptype_getconf((dtyp), DUMPTYPE_BUMPDAYS)))
609 #define dumptype_get_bumpmult(dtyp) (val_t_to_real(dumptype_getconf((dtyp), DUMPTYPE_BUMPMULT)))
610 #define dumptype_get_starttime(dtyp) (val_t_to_time(dumptype_getconf((dtyp), DUMPTYPE_STARTTIME)))
611 #define dumptype_get_strategy(dtyp) (val_t_to_strategy(dumptype_getconf((dtyp), DUMPTYPE_STRATEGY)))
612 #define dumptype_get_estimate(dtyp) (val_t_to_estimate(dumptype_getconf((dtyp), DUMPTYPE_ESTIMATE)))
613 #define dumptype_get_compress(dtyp) (val_t_to_compress(dumptype_getconf((dtyp), DUMPTYPE_COMPRESS)))
614 #define dumptype_get_encrypt(dtyp) (val_t_to_encrypt(dumptype_getconf((dtyp), DUMPTYPE_ENCRYPT)))
615 #define dumptype_get_srv_decrypt_opt(dtyp) (val_t_to_str(dumptype_getconf((dtyp), DUMPTYPE_SRV_DECRYPT_OPT)))
616 #define dumptype_get_clnt_decrypt_opt(dtyp) (val_t_to_str(dumptype_getconf((dtyp), DUMPTYPE_CLNT_DECRYPT_OPT)))
617 #define dumptype_get_comprate(dtyp) (val_t_to_rate(dumptype_getconf((dtyp), DUMPTYPE_COMPRATE)))
618 #define dumptype_get_tape_splitsize(dtyp) (val_t_to_am64(dumptype_getconf((dtyp), DUMPTYPE_TAPE_SPLITSIZE)))
619 #define dumptype_get_fallback_splitsize(dtyp) (val_t_to_am64(dumptype_getconf((dtyp), DUMPTYPE_FALLBACK_SPLITSIZE)))
620 #define dumptype_get_split_diskbuffer(dtyp) (val_t_to_str(dumptype_getconf((dtyp), DUMPTYPE_SPLIT_DISKBUFFER)))
621 #define dumptype_get_record(dtyp) (val_t_to_boolean(dumptype_getconf((dtyp), DUMPTYPE_RECORD)))
622 #define dumptype_get_skip_incr(dtyp) (val_t_to_boolean(dumptype_getconf((dtyp), DUMPTYPE_SKIP_INCR)))
623 #define dumptype_get_skip_full(dtyp) (val_t_to_boolean(dumptype_getconf((dtyp), DUMPTYPE_SKIP_FULL)))
624 #define dumptype_get_to_holdingdisk(dtyp) (val_t_to_holding(dumptype_getconf((dtyp), DUMPTYPE_HOLDINGDISK)))
625 #define dumptype_get_kencrypt(dtyp) (val_t_to_boolean(dumptype_getconf((dtyp), DUMPTYPE_KENCRYPT)))
626 #define dumptype_get_ignore(dtyp) (val_t_to_boolean(dumptype_getconf((dtyp), DUMPTYPE_IGNORE)))
627 #define dumptype_get_index(dtyp) (val_t_to_boolean(dumptype_getconf((dtyp), DUMPTYPE_INDEX)))
630 * Interface parameter access
636 INTER_INTER /* sentinel */
640 typedef struct interface_s interface_t;
642 /* Given the name of the interface, return a interface object. Returns NULL
643 * if no matching interface exists. Note that the match is case-insensitive.
645 * @param identifier: name of the desired interface
646 * @returns: object or NULL
648 interface_t *lookup_interface(char *identifier);
650 /* Given a interface and a key, return a pointer to the corresponding val_t.
652 * @param iface: the interface to examine
653 * @param key: interface_key (one of the TAPETYPE_* constants)
654 * @returns: pointer to value
656 val_t *interface_getconf(interface_t *iface, interface_key key);
658 /* Get the name of this interface.
660 * @param iface: the interface to examine
661 * @returns: name of the interface
663 char *interface_name(interface_t *iface);
665 /* (convenience macro) has this parameter been seen in this interface? This
666 * applies to the specific parameter *within* the interface.
668 * @param key: interface_key
671 #define interface_seen(iface, key) (val_t_seen(interface_getconf((iface), (key))))
673 /* (convenience macros)
674 * fetch a particular parameter; caller must know the correct type.
676 * @param iface: the interface to examine
679 #define interface_get_comment(iface) (val_t_to_str(interface_getconf((iface), INTER_COMMENT)))
680 #define interface_get_maxusage(iface) (val_t_to_int(interface_getconf((iface), INTER_MAXUSAGE)))
683 * Holdingdisk parameter access
691 HOLDING_HOLDING /* sentinel */
695 typedef struct holdingdisk_s holdingdisk_t;
697 /* Given the name of the holdingdisk, return a holdingdisk object. Returns NULL
698 * if no matching holdingdisk exists. Note that the match is case-insensitive.
700 * @param identifier: name of the desired holdingdisk
701 * @returns: object or NULL
703 holdingdisk_t *lookup_holdingdisk(char *identifier);
705 /* Return the whole linked list of holdingdisks. Use holdingdisk_next
706 * to traverse the list.
708 * @returns: first holding disk
710 holdingdisk_t *getconf_holdingdisks(void);
712 /* Return the next holdingdisk in the list.
714 * @param hdisk: holding disk
715 * @returns: NULL if hdisk is the last disk, otherwise the next holding
718 holdingdisk_t *holdingdisk_next(holdingdisk_t *hdisk);
720 /* Given a holdingdisk and a key, return a pointer to the corresponding val_t.
722 * @param hdisk: the holdingdisk to examine
723 * @param key: holdingdisk_key (one of the TAPETYPE_* constants)
724 * @returns: pointer to value
726 val_t *holdingdisk_getconf(holdingdisk_t *hdisk, holdingdisk_key key);
728 /* Get the name of this holdingdisk.
730 * @param hdisk: the holdingdisk to examine
731 * @returns: name of the holdingdisk
733 char *holdingdisk_name(holdingdisk_t *hdisk);
735 /* (convenience macro) has this parameter been seen in this holdingdisk? This
736 * applies to the specific parameter *within* the holdingdisk.
738 * @param key: holdingdisk_key
741 #define holdingdisk_seen(hdisk, key) (val_t_seen(holdingdisk_getconf((hdisk), (key))))
743 /* (convenience macros)
744 * fetch a particular parameter; caller must know the correct type.
746 * @param hdisk: the holdingdisk to examine
749 #define holdingdisk_get_comment(hdisk) (val_t_to_str(holdingdisk_getconf((hdisk), HOLDING_COMMENT)))
750 #define holdingdisk_get_diskdir(hdisk) (val_t_to_str(holdingdisk_getconf((hdisk), HOLDING_DISKDIR)))
751 #define holdingdisk_get_disksize(hdisk) (val_t_to_am64(holdingdisk_getconf((hdisk), HOLDING_DISKSIZE)))
752 #define holdingdisk_get_chunksize(hdisk) (val_t_to_am64(holdingdisk_getconf((hdisk), HOLDING_CHUNKSIZE)))
755 * Command-line handling
759 typedef struct config_overwrites_s config_overwrites_t;
761 /* Create a new, empty config_overwrites object.
763 * @param size_estimate: a guess at the number of overwrites; argc/2 is a
765 * @returns: new object
767 config_overwrites_t *new_config_overwrites(int size_estimate);
769 /* Free a config_overwrites object. This usually won't be needed, as
770 * apply_config_overwrites takes ownership of the overwrites for you.
772 * @param co: config_overwrites object
774 void free_config_overwrites(config_overwrites_t *co);
776 /* Add an overwrite to a config_overwrites object.
778 * @param co: the config_overwrites object
779 * @param key: the configuration parameter's key, possibly with the format
780 * SUBTYPE:NAME:KEYWORD
781 * @param value: the value for the parameter, as would be seen in amanda.conf
783 void add_config_overwrite(config_overwrites_t *co,
787 /* Add an overwrite option from the command line to a config_overwrites
788 * object. Calls error() with any errors
790 * @param co: the config_overwrites object
791 * @param optarg: the value of the command-line option
793 void add_config_overwrite_opt(config_overwrites_t *co,
796 /* Given a command line, represented as argc/argv, extract any -o options
797 * as config overwrites. This function modifies argc and argv in place.
799 * This is the deprecated way to extract config overwrites, for applications
800 * which do not use getopt. The preferred method is to use getopt and
801 * call add_config_overwrite_opt for any -o options.
803 * @param argc: (in/out) command-line length
804 * @param argv: (in/out) command-line strings
805 * @returns: newly allocated config_overwrites object
807 config_overwrites_t *
808 extract_commandline_config_overwrites(int *argc,
811 /* Apply configuration overwrites to the current configuration and take
812 * ownership of the config_overwrites object.
814 * If any parameters are not matched in the current symbol table, or
815 * correspond to named subsections which do not exist, this function calls
816 * error() and does not return.
818 * @param co: the config_overwrites object
820 void apply_config_overwrites(config_overwrites_t *co);
826 /* Constants for config_init */
828 /* Use arg_config_name, if not NULL */
829 CONFIG_INIT_EXPLICIT_NAME = 1 << 0,
831 /* Use the current working directory if an explicit name is not available */
832 CONFIG_INIT_USE_CWD = 1 << 1,
834 /* This is a client application (server is default) */
835 CONFIG_INIT_CLIENT = 1 << 2,
837 /* New configuration should "overlay" existing configuration; this
838 * is used by clients to load multiple amanda-client.conf files. */
839 CONFIG_INIT_OVERLAY = 1 << 3,
841 /* If the file doesn't exist, halt with an error. */
842 CONFIG_INIT_FATAL = 1 << 4,
845 /* Initialize this application's configuration, with the specific actions
847 * - if CONFIG_INIT_OVERLAY is not set, configuration values are reset
849 * - if CONFIG_INIT_EXPLICIT_NAME and arg_config_name is not NULL,
850 * use CONFIG_DIR/arg_config_name as config_dir arg_config_name as
852 * - otherwise, if CONFIG_USE_CWD is set, use the directory in which
853 * the application was started as config_dir, and its filename as
855 * - otherwise, for the client only, se config_dir to CONFIG_DIR and
856 * config_name to NULL.
857 * - depending on CONFIG_INIT_CLIENT, read amanda.conf or amanda-client.conf
858 * - in the event of an error, call error() if CONFIG_INIT_FATAL, otherwise
859 * record a message in the debug log and return false.
861 * @param flags: flags indicating desired behavior, as above
862 * @param arg_config_name: config name to use (from e.g., argv[1])
863 * @returns: true on success, false on failure, unless CONFIG_INIT_FATAL
865 gboolean config_init(config_init_flags flags,
866 char *arg_config_name);
868 /* Free all memory allocated for the configuration. This effectively
869 * reverses the effects of config_init().
871 void config_uninit(void);
873 /* Encode any applied config_overwrites into a strv format suitale for
874 * executing another Amanda tool.
876 * The * result is dynamically allocated and NULL terminated. There is no
877 * provision to free the result, as this function is always called just
880 * First gives the number of array elements to leave for the caller to
881 * fill in. The usual calling pattern is this:
882 * command_line = get_config_options(3);
883 * command_line[0] = "appname";
884 * command_line[1] = config_name;
885 * command_line[2] = "--foo";
886 * execve(command_line[0], command_line, safe_env());
888 * @param first: number of unused elements to leave at the beginning of
890 * @returns: NULL-terminated string array suitable for execve
892 char **get_config_options(int first);
894 /* The name of the configuration under which this application is running.
895 * This variable is initialized by config_init, and should be treated as
898 extern char *config_name;
900 /* The directory containing the configuration for this application. This
901 * variable is initialized by config_init, and should be treated as read-only.
903 extern char *config_dir;
905 /* The most recently read top-level configuration file. This variable is
906 * initialized by config_init, and should be treated as read-only.
908 extern char *config_filename;
914 /* Security plugins get their configuration information through a callback
915 * with the signature:
916 * char *callback(char *key, void *userpointer);
917 * where key is the name of the desired parameter, which may not match the
918 * name used in this module. See the implementations of these functions
919 * to learn which keys they support, or to add new keys.
921 char *generic_client_get_security_conf(char *, void *);
922 char *generic_get_security_conf(char *, void *);
924 /* Dump the current configuration information to stdout, in a format
925 * that can be re-read by this module. The results will include any
926 * command-line overwrites.
928 * This function only dumps the server configuration, and will fail on
931 void dump_configuration(void);
933 /* Return a sequence of strings giving the printable representation
934 * of the given val_t. If str_needs_quotes is true and each string is
935 * prefixed by the relevant configuration keyword, these strings will
936 * be parseable by this module, and will reproduce exactly the same
937 * configuration value. See the implementation of dump_configuration
940 * If str_needs_quotes is provided, a CONFTYPE_STR value will be returned with
943 * The result is a NULL-terminated strv, which can be freed with g_strfreev or
944 * joined with g_strjoinv. Caller is responsible for freeing the memory.
946 * @param val: the value to analyze
947 * @param str_needs_quotes: add quotes to CONFTYPE_STR values?
948 * @returns: NULL-terminated string vector
950 char **val_t_display_strs(val_t *val, int str_needs_quotes);
952 /* Read a dumptype; this is used by this module as well as by diskfile.c to
953 * read the disklist. The two are carefully balanced in their parsing process.
955 * Nobody else should use this function. Seriously.
957 dumptype_t *read_dumptype(char *name, FILE *from, char *fname, int *linenum);
959 /* Extend a relative filename with the current config_dir; if filename is already
960 * absolute, this is equivalent to stralloc.
962 * @param filename: filename to extend
963 * @returns: newly allocated filename
965 char *config_dir_relative(char *filename);
967 /* Convert from a symbol back to a name for logging and for dumping
970 * @param taperalgo: the constant value
971 * @returns: statically allocated string
973 char *taperalgo2str(taperalgo_t taperalgo);
975 /* Looks for a unit value like b, byte, bytes, bps, etc. Technically
976 * the return value should never be < 1, but we return a signed value
977 * to help mitigate bad C promotion semantics. Returns 0 on error.
979 * This is here in this module because it uses the numb_keytable.
981 * @param casestr: the unit string
982 * @returns: the corresponding multiplier (e.g., 'M' => 1024*1024)
984 gint64 find_multiplier(char * casestr);
986 #endif /* ! CONFFILE_H */