8873cec75292b3d659bae70148c72d098d6319c0
[debian/amanda] / common-src / conffile.h
1 /*
2  * Amanda, The Advanced Maryland Automatic Network Disk Archiver
3  * Copyright (c) 1991-2000 University of Maryland at College Park
4  * All Rights Reserved.
5  *
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.
15  *
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.
22  *
23  * Author: James da Silva, Systems Design and Analysis Group
24  *                         Computer Science Department
25  *                         University of Maryland at College Park
26  */
27 /*
28  * $Id: conffile.h,v 1.72 2006/07/26 15:17:37 martinea Exp $
29  *
30  * interface for config file reading code
31  */
32 #ifndef CONFFILE_H
33 #define CONFFILE_H
34
35 #include "amanda.h"
36 #include "util.h"
37
38 /* Getting Configuration Values
39  * ============================
40  *
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).
47  *
48  * Types
49  * =====
50  *
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.
55  *
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 *.
62  *
63  * Memory
64  * ======
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.
67  */
68
69 /*
70  * Generic values
71  *
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.
76  */
77
78 /* holdingdisk types */
79 typedef enum {
80     HOLD_NEVER,                 /* Always direct to tape  */
81     HOLD_AUTO,                  /* If possible            */
82     HOLD_REQUIRED               /* Always to holding disk */
83 } dump_holdingdisk_t;
84
85 /* Compression types */
86 typedef enum {
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 */
94 } comp_t;
95
96 /* Encryption types */
97 typedef enum {
98     ENCRYPT_NONE,               /* No encryption */
99     ENCRYPT_CUST,               /* Custom encryption on client */
100     ENCRYPT_SERV_CUST           /* Custom encryption on server */
101 } encrypt_t;
102
103 /* Estimate strategies */
104 typedef enum {
105     ES_CLIENT,          /* client estimate */
106     ES_SERVER,          /* server estimate */
107     ES_CALCSIZE,        /* calcsize estimate */
108     ES_ES /* sentinel */
109 } estimate_t;
110
111 /* Dump strategies */
112 typedef enum {
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 ...) */
121     DS_DS /* sentinel */
122 } strategy_t;
123
124 typedef enum {
125     ALGO_FIRST,
126     ALGO_FIRSTFIT,
127     ALGO_LARGEST,
128     ALGO_LARGESTFIT,
129     ALGO_SMALLEST,
130     ALGO_LAST,
131     ALGO_ALGO /* sentinel */
132 } taperalgo_t;
133
134 typedef struct exinclude_s {
135     sl_t *sl_list;
136     sl_t *sl_file;
137     int  optional;
138 } exinclude_t;
139
140 typedef GHashTable* proplist_t;
141
142 /* Names for the type of value in a val_t.  Mostly for internal use, but useful
143  * for wrapping val_t's, too. */
144 typedef enum {
145     CONFTYPE_INT,
146     CONFTYPE_AM64,
147     CONFTYPE_REAL,
148     CONFTYPE_STR,
149     CONFTYPE_IDENT,
150     CONFTYPE_TIME,
151     CONFTYPE_SIZE,
152     CONFTYPE_BOOLEAN,
153     CONFTYPE_COMPRESS,
154     CONFTYPE_ENCRYPT,
155     CONFTYPE_HOLDING,
156     CONFTYPE_ESTIMATE,
157     CONFTYPE_STRATEGY,
158     CONFTYPE_TAPERALGO,
159     CONFTYPE_PRIORITY,
160     CONFTYPE_RATE,
161     CONFTYPE_INTRANGE,
162     CONFTYPE_EXINCLUDE,
163     CONFTYPE_PROPLIST
164 } conftype_t;
165
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
168  * those macros. */
169 typedef struct val_s {
170     union {
171         int             i;
172         off_t           am64;
173         double          r;
174         char            *s;
175         ssize_t         size;
176         time_t          t;
177         float           rate[2];
178         exinclude_t     exinclude;
179         int             intrange[2];
180         proplist_t      proplist;
181     } v;
182     int seen;
183     conftype_t type;
184 } val_t;
185
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 *);
208
209 /* Has the given val_t been seen in a configuration file or config overwrite?
210  *
211  * @param val: val_t* to examine
212  * @returns: boolean
213  */
214 #define val_t_seen(val) ((val)->seen)
215
216 /* What is the underlying type of this val_t?
217  *
218  * @param val: val_t* to examine
219  * @returns: conftype_t
220  */
221 #define val_t_type(val) ((val)->type)
222
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!
225  *
226  * Implementation note: these macros encode the relationship of conftypes
227  * (in the macro name) to the corresponding union field.  The macros work
228  * as lvalues, too.
229  */
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)
250 /*
251  * Parameters
252  *
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.
256  */
257
258 /*
259  * Global parameter access
260  */
261 typedef enum {
262     CNF_ORG,
263     CNF_CONF,
264     CNF_INDEX_SERVER,
265     CNF_TAPE_SERVER,
266     CNF_AUTH,
267     CNF_SSH_KEYS,
268     CNF_AMANDAD_PATH,
269     CNF_CLIENT_USERNAME,
270     CNF_GNUTAR_LIST_DIR,
271     CNF_AMANDATES,
272     CNF_MAILTO,
273     CNF_DUMPUSER,
274     CNF_TAPEDEV,
275     CNF_DEVICE_PROPERTY,
276     CNF_CHANGERDEV,
277     CNF_CHANGERFILE,
278     CNF_LABELSTR,
279     CNF_TAPELIST,
280     CNF_DISKFILE,
281     CNF_INFOFILE,
282     CNF_LOGDIR,
283     CNF_INDEXDIR,
284     CNF_TAPETYPE,
285     CNF_DUMPCYCLE,
286     CNF_RUNSPERCYCLE,
287     CNF_TAPECYCLE,
288     CNF_NETUSAGE,
289     CNF_INPARALLEL,
290     CNF_DUMPORDER,
291     CNF_BUMPPERCENT,
292     CNF_BUMPSIZE,
293     CNF_BUMPMULT,
294     CNF_BUMPDAYS,
295     CNF_TPCHANGER,
296     CNF_RUNTAPES,
297     CNF_MAXDUMPS,
298     CNF_ETIMEOUT,
299     CNF_DTIMEOUT,
300     CNF_CTIMEOUT,
301     CNF_TAPEBUFS,
302     CNF_DEVICE_OUTPUT_BUFFER_SIZE,
303     CNF_PRINTER,
304     CNF_AUTOFLUSH,
305     CNF_RESERVE,
306     CNF_MAXDUMPSIZE,
307     CNF_COLUMNSPEC,
308     CNF_AMRECOVER_DO_FSF,
309     CNF_AMRECOVER_CHECK_LABEL,
310     CNF_AMRECOVER_CHANGER,
311     CNF_TAPERALGO,
312     CNF_FLUSH_THRESHOLD_DUMPED,
313     CNF_FLUSH_THRESHOLD_SCHEDULED,
314     CNF_TAPERFLUSH,
315     CNF_DISPLAYUNIT,
316     CNF_KRB5KEYTAB,
317     CNF_KRB5PRINCIPAL,
318     CNF_LABEL_NEW_TAPES,
319     CNF_USETIMESTAMPS,
320     CNF_REP_TRIES,
321     CNF_CONNECT_TRIES,
322     CNF_REQ_TRIES,
323     CNF_DEBUG_AMANDAD,
324     CNF_DEBUG_AMIDXTAPED,
325     CNF_DEBUG_AMINDEXD,
326     CNF_DEBUG_AMRECOVER,
327     CNF_DEBUG_AUTH,
328     CNF_DEBUG_EVENT,
329     CNF_DEBUG_HOLDING,
330     CNF_DEBUG_PROTOCOL,
331     CNF_DEBUG_PLANNER,
332     CNF_DEBUG_DRIVER,
333     CNF_DEBUG_DUMPER,
334     CNF_DEBUG_CHUNKER,
335     CNF_DEBUG_TAPER,
336     CNF_DEBUG_SELFCHECK,
337     CNF_DEBUG_SENDSIZE,
338     CNF_DEBUG_SENDBACKUP,
339     CNF_RESERVED_UDP_PORT,
340     CNF_RESERVED_TCP_PORT,
341     CNF_UNRESERVED_TCP_PORT,
342     CNF_CNF /* sentinel */
343 } confparm_key;
344
345 /* Given a confparm_key, return a pointer to the corresponding val_t.
346  *
347  * @param key: confparm_key
348  * @returns: pointer to value
349  */
350 val_t *getconf(confparm_key key);
351
352 /* (convenience macro) has this global parameter been seen?
353  *
354  * @param key: confparm_key
355  * @returns: boolean
356  */
357 #define getconf_seen(key)       (val_t_seen(getconf((key))))
358
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.
364  *
365  * @param key: confparm_key
366  * @returns: various
367  */
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))))
387
388 /* Get a list of names for subsections of the given type
389  *
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().
393  */
394 GSList *getconf_list(char *listname);
395
396 /* Get a configuration value by name, supporting the TYPE:SUBSEC:KEYWORD.
397  * Returns NULL if the configuration value doesnt exist.
398  */
399 val_t *getconf_byname(char *key);
400
401 /*
402  * Derived values
403  *
404  * Values which aren't directly specified by the configuration, but which
405  * are derived from it.
406  */
407
408 /* Return a divisor which will convert a value in units of kilo-whatevers
409  * to the user's selected display unit.
410  *
411  * @returns: long integer divisor
412  */
413 long int getconf_unit_divisor(void);
414
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 
418  * desired.  */
419
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;
436
437 /*
438  * Tapetype parameter access
439  */
440
441 typedef enum {
442     TAPETYPE_COMMENT,
443     TAPETYPE_LBL_TEMPL,
444     TAPETYPE_BLOCKSIZE,
445     TAPETYPE_READBLOCKSIZE,
446     TAPETYPE_LENGTH,
447     TAPETYPE_FILEMARK,
448     TAPETYPE_SPEED,
449     TAPETYPE_FILE_PAD,
450     TAPETYPE_TAPETYPE /* sentinel */
451 } tapetype_key;
452
453 /* opaque object */
454 typedef struct tapetype_s tapetype_t;
455
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.
458  *
459  * @param identifier: name of the desired tapetype
460  * @returns: object or NULL
461  */
462 tapetype_t *lookup_tapetype(char *identifier);
463
464 /* Given a tapetype and a key, return a pointer to the corresponding val_t.
465  *
466  * @param ttyp: the tapetype to examine
467  * @param key: tapetype_key (one of the TAPETYPE_* constants)
468  * @returns: pointer to value
469  */
470 val_t *tapetype_getconf(tapetype_t *ttyp, tapetype_key key);
471
472 /* Get the name of this tapetype.
473  *
474  * @param ttyp: the tapetype to examine
475  * @returns: name of the tapetype
476  */
477 char *tapetype_name(tapetype_t *ttyp);
478
479 /* (convenience macro) has this parameter been seen in this tapetype?  This
480  * applies to the specific parameter *within* the tapetype.
481  *
482  * @param key: tapetype_key
483  * @returns: boolean
484  */
485 #define tapetype_seen(ttyp, key)       (val_t_seen(tapetype_getconf((ttyp), (key))))
486
487 /* (convenience macros)
488  * fetch a particular parameter; caller must know the correct type.
489  *
490  * @param ttyp: the tapetype to examine
491  * @returns: various
492  */
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)))
501
502 /*
503  * Dumptype parameter access
504  */
505
506 typedef enum {
507     DUMPTYPE_COMMENT,
508     DUMPTYPE_PROGRAM,
509     DUMPTYPE_SRVCOMPPROG,
510     DUMPTYPE_CLNTCOMPPROG,
511     DUMPTYPE_SRV_ENCRYPT,
512     DUMPTYPE_CLNT_ENCRYPT,
513     DUMPTYPE_AMANDAD_PATH,
514     DUMPTYPE_CLIENT_USERNAME,
515     DUMPTYPE_SSH_KEYS,
516     DUMPTYPE_SECURITY_DRIVER,
517     DUMPTYPE_EXCLUDE,
518     DUMPTYPE_INCLUDE,
519     DUMPTYPE_PRIORITY,
520     DUMPTYPE_DUMPCYCLE,
521     DUMPTYPE_MAXDUMPS,
522     DUMPTYPE_MAXPROMOTEDAY,
523     DUMPTYPE_BUMPPERCENT,
524     DUMPTYPE_BUMPSIZE,
525     DUMPTYPE_BUMPDAYS,
526     DUMPTYPE_BUMPMULT,
527     DUMPTYPE_STARTTIME,
528     DUMPTYPE_STRATEGY,
529     DUMPTYPE_ESTIMATE,
530     DUMPTYPE_COMPRESS,
531     DUMPTYPE_ENCRYPT,
532     DUMPTYPE_SRV_DECRYPT_OPT,
533     DUMPTYPE_CLNT_DECRYPT_OPT,
534     DUMPTYPE_COMPRATE,
535     DUMPTYPE_TAPE_SPLITSIZE,
536     DUMPTYPE_FALLBACK_SPLITSIZE,
537     DUMPTYPE_SPLIT_DISKBUFFER,
538     DUMPTYPE_RECORD,
539     DUMPTYPE_SKIP_INCR,
540     DUMPTYPE_SKIP_FULL,
541     DUMPTYPE_HOLDINGDISK,
542     DUMPTYPE_KENCRYPT,
543     DUMPTYPE_IGNORE,
544     DUMPTYPE_INDEX,
545     DUMPTYPE_DUMPTYPE /* sentinel */
546 } dumptype_key;
547
548 /* opaque object */
549 typedef struct dumptype_s dumptype_t;
550
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.
553  *
554  * @param identifier: name of the desired dumptype
555  * @returns: object or NULL
556  */
557 dumptype_t *lookup_dumptype(char *identifier);
558
559 /* Given a dumptype and a key, return a pointer to the corresponding val_t.
560  *
561  * @param dtyp: the dumptype to examine
562  * @param key: dumptype_key (one of the TAPETYPE_* constants)
563  * @returns: pointer to value
564  */
565 val_t *dumptype_getconf(dumptype_t *dtyp, dumptype_key key);
566
567 /* Get the name of this dumptype.
568  *
569  * @param dtyp: the dumptype to examine
570  * @returns: name of the dumptype
571  */
572 char *dumptype_name(dumptype_t *dtyp);
573
574 /* (convenience macro) has this parameter been seen in this dumptype?  This
575  * applies to the specific parameter *within* the dumptype.
576  *
577  * @param key: dumptype_key
578  * @returns: boolean
579  */
580 #define dumptype_seen(dtyp, key)       (val_t_seen(dumptype_getconf((dtyp), (key))))
581
582 /* (convenience macros)
583  * fetch a particular parameter; caller must know the correct type.
584  *
585  * @param dtyp: the dumptype to examine
586  * @returns: various
587  */
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)))
628
629 /*
630  * Interface parameter access
631  */
632
633 typedef enum {
634     INTER_COMMENT,
635     INTER_MAXUSAGE,
636     INTER_INTER /* sentinel */
637 } interface_key;
638
639 /* opaque object */
640 typedef struct interface_s interface_t;
641
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.
644  *
645  * @param identifier: name of the desired interface
646  * @returns: object or NULL
647  */
648 interface_t *lookup_interface(char *identifier);
649
650 /* Given a interface and a key, return a pointer to the corresponding val_t.
651  *
652  * @param iface: the interface to examine
653  * @param key: interface_key (one of the TAPETYPE_* constants)
654  * @returns: pointer to value
655  */
656 val_t *interface_getconf(interface_t *iface, interface_key key);
657
658 /* Get the name of this interface.
659  *
660  * @param iface: the interface to examine
661  * @returns: name of the interface
662  */
663 char *interface_name(interface_t *iface);
664
665 /* (convenience macro) has this parameter been seen in this interface?  This
666  * applies to the specific parameter *within* the interface.
667  *
668  * @param key: interface_key
669  * @returns: boolean
670  */
671 #define interface_seen(iface, key)       (val_t_seen(interface_getconf((iface), (key))))
672
673 /* (convenience macros)
674  * fetch a particular parameter; caller must know the correct type.
675  *
676  * @param iface: the interface to examine
677  * @returns: various
678  */
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)))
681
682 /*
683  * Holdingdisk parameter access
684  */
685
686 typedef enum {
687     HOLDING_COMMENT,
688     HOLDING_DISKDIR,
689     HOLDING_DISKSIZE,
690     HOLDING_CHUNKSIZE,
691     HOLDING_HOLDING /* sentinel */
692 } holdingdisk_key;
693
694 /* opaque object */
695 typedef struct holdingdisk_s holdingdisk_t;
696
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.
699  *
700  * @param identifier: name of the desired holdingdisk
701  * @returns: object or NULL
702  */
703 holdingdisk_t *lookup_holdingdisk(char *identifier);
704
705 /* Return the whole linked list of holdingdisks.  Use holdingdisk_next
706  * to traverse the list.
707  *
708  * @returns: first holding disk
709  */
710 holdingdisk_t *getconf_holdingdisks(void);
711
712 /* Return the next holdingdisk in the list.
713  *
714  * @param hdisk: holding disk
715  * @returns: NULL if hdisk is the last disk, otherwise the next holding
716  * disk
717  */
718 holdingdisk_t *holdingdisk_next(holdingdisk_t *hdisk);
719
720 /* Given a holdingdisk and a key, return a pointer to the corresponding val_t.
721  *
722  * @param hdisk: the holdingdisk to examine
723  * @param key: holdingdisk_key (one of the TAPETYPE_* constants)
724  * @returns: pointer to value
725  */
726 val_t *holdingdisk_getconf(holdingdisk_t *hdisk, holdingdisk_key key);
727
728 /* Get the name of this holdingdisk.
729  *
730  * @param hdisk: the holdingdisk to examine
731  * @returns: name of the holdingdisk
732  */
733 char *holdingdisk_name(holdingdisk_t *hdisk);
734
735 /* (convenience macro) has this parameter been seen in this holdingdisk?  This
736  * applies to the specific parameter *within* the holdingdisk.
737  *
738  * @param key: holdingdisk_key
739  * @returns: boolean
740  */
741 #define holdingdisk_seen(hdisk, key)       (val_t_seen(holdingdisk_getconf((hdisk), (key))))
742
743 /* (convenience macros)
744  * fetch a particular parameter; caller must know the correct type.
745  *
746  * @param hdisk: the holdingdisk to examine
747  * @returns: various
748  */
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)))
753
754 /*
755  * Command-line handling
756  */
757
758 /* opaque type */
759 typedef struct config_overwrites_s config_overwrites_t;
760
761 /* Create a new, empty config_overwrites object.
762  *
763  * @param size_estimate: a guess at the number of overwrites; argc/2 is a 
764  *  good estimate.
765  * @returns: new object
766  */
767 config_overwrites_t *new_config_overwrites(int size_estimate);
768
769 /* Free a config_overwrites object.  This usually won't be needed, as
770  * apply_config_overwrites takes ownership of the overwrites for you.
771  *
772  * @param co: config_overwrites object
773  */
774 void free_config_overwrites(config_overwrites_t *co);
775
776 /* Add an overwrite to a config_overwrites object.
777  *
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
782  */
783 void add_config_overwrite(config_overwrites_t *co,
784                          char *key,
785                          char *value);
786
787 /* Add an overwrite option from the command line to a config_overwrites
788  * object.  Calls error() with any errors
789  *
790  * @param co: the config_overwrites object
791  * @param optarg: the value of the command-line option
792  */
793 void add_config_overwrite_opt(config_overwrites_t *co,
794                               char *optarg);
795
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.
798  *
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.
802  *
803  * @param argc: (in/out) command-line length
804  * @param argv: (in/out) command-line strings
805  * @returns: newly allocated config_overwrites object
806  */
807 config_overwrites_t *
808 extract_commandline_config_overwrites(int *argc,
809                                       char ***argv);
810
811 /* Apply configuration overwrites to the current configuration and take
812  * ownership of the config_overwrites object.
813  *
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.
817  *
818  * @param co: the config_overwrites object
819  */
820 void apply_config_overwrites(config_overwrites_t *co);
821
822 /*
823  * Initialization
824  */
825
826 /* Constants for config_init */
827 typedef enum {
828     /* Use arg_config_name, if not NULL */
829     CONFIG_INIT_EXPLICIT_NAME = 1 << 0,
830
831     /* Use the current working directory if an explicit name is not available */
832     CONFIG_INIT_USE_CWD = 1 << 1,
833
834     /* This is a client application (server is default) */
835     CONFIG_INIT_CLIENT = 1 << 2,
836
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,
840
841     /* If the file doesn't exist, halt with an error. */
842     CONFIG_INIT_FATAL = 1 << 4,
843 } config_init_flags;
844
845 /* Initialize this application's configuration, with the specific actions
846  * based on 'flags':
847  *  - if CONFIG_INIT_OVERLAY is not set, configuration values are reset
848  *    to their defaults
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 
851  *    config_name.
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 
854  *    config_name.
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.
860  *
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
864  */
865 gboolean config_init(config_init_flags flags,
866                      char *arg_config_name);
867
868 /* Free all memory allocated for the configuration.  This effectively
869  * reverses the effects of config_init().
870  */
871 void config_uninit(void);
872
873 /* Encode any applied config_overwrites into a strv format suitale for
874  * executing another Amanda tool.
875  *
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
878  * before execve(..).
879  *
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());
887  *
888  * @param first: number of unused elements to leave at the beginning of
889  * the array.
890  * @returns: NULL-terminated string array suitable for execve
891  */
892 char **get_config_options(int first);
893
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
896  * read-only.
897  */
898 extern char *config_name;
899
900 /* The directory containing the configuration for this application.  This
901  * variable is initialized by config_init, and should be treated as read-only.
902  */
903 extern char *config_dir;
904
905 /* The most recently read top-level configuration file.  This variable is
906  * initialized by config_init, and should be treated as read-only.
907  */
908 extern char *config_filename;
909
910 /*
911  * Utilities
912  */
913
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.
920  */
921 char *generic_client_get_security_conf(char *, void *);
922 char *generic_get_security_conf(char *, void *);
923
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.
927  *
928  * This function only dumps the server configuration, and will fail on
929  * clients.
930  */
931 void dump_configuration(void);
932
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
938  * for details.
939  *
940  * If str_needs_quotes is provided, a CONFTYPE_STR value will be returned with 
941  * quotes.
942  *
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.
945  *
946  * @param val: the value to analyze
947  * @param str_needs_quotes: add quotes to CONFTYPE_STR values?
948  * @returns: NULL-terminated string vector
949  */
950 char **val_t_display_strs(val_t *val, int str_needs_quotes);
951
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.
954  *
955  * Nobody else should use this function.  Seriously.
956  */
957 dumptype_t *read_dumptype(char *name, FILE *from, char *fname, int *linenum);
958
959 /* Extend a relative filename with the current config_dir; if filename is already
960  * absolute, this is equivalent to stralloc.
961  *
962  * @param filename: filename to extend
963  * @returns: newly allocated filename
964  */
965 char *config_dir_relative(char *filename);
966
967 /* Convert from a symbol back to a name for logging and for dumping
968  * config values
969  *
970  * @param taperalgo: the constant value
971  * @returns: statically allocated string
972  */
973 char *taperalgo2str(taperalgo_t taperalgo);
974
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.
978  *
979  * This is here in this module because it uses the numb_keytable.
980  *
981  * @param casestr: the unit string
982  * @returns: the corresponding multiplier (e.g., 'M' => 1024*1024)
983  */
984 gint64 find_multiplier(char * casestr);
985
986 #endif /* ! CONFFILE_H */