1 /*
2  * Amanda, The Advanced Maryland Automatic Network Disk Archiver
3  * Copyright (c) 1991-1998 University of Maryland at College Park
4  * Copyright (c) 2007-2013 Zmanda, Inc.  All Rights Reserved.
5  * All Rights Reserved.
6  *
7  * Permission to use, copy, modify, distribute, and sell this software and its
8  * documentation for any purpose is hereby granted without fee, provided that
9  * the above copyright notice appear in all copies and that both that
10  * copyright notice and this permission notice appear in supporting
11  * documentation, and that the name of U.M. not be used in advertising or
12  * publicity pertaining to distribution of the software without specific,
13  * written prior permission.  U.M. makes no representations about the
14  * suitability of this software for any purpose.  It is provided "as is"
15  * without express or implied warranty.
16  *
17  * U.M. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL U.M.
19  * BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
20  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
21  * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
22  * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
23  *
24  * Author: James da Silva, Systems Design and Analysis Group
25  *			   Computer Science Department
26  *			   University of Maryland at College Park
27  */
28 /*
29  * $Id: diskfile.h,v 1.38 2006/06/22 20:41:33 martinea Exp $
30  *
31  * interface for disklist file reading code
32  */
33 #ifndef DISKFILE_H
34 #define DISKFILE_H
35 
36 #include "amanda.h"
37 #include "conffile.h"
38 #include "fileheader.h"
39 #include "amfeatures.h"
40 
41 typedef struct netif_s {
42     struct netif_s *next;
43     interface_t *config;
44     unsigned long curusage;
45 } netif_t;
46 
47 typedef struct amhost_s {
48     struct amhost_s *next;		/* next host */
49     char *hostname;			/* name of host */
50     struct disk_s *disks;		/* linked list of disk records */
51     int inprogress;			/* # dumps in progress */
52     int maxdumps;			/* maximum dumps in parallel */
53     netif_t *netif;			/* network interface this host is on */
54     time_t start_t;			/* time last dump was started on this host */
55     char *up;				/* generic user pointer */
56     am_feature_t *features;		/* feature set */
57     int	 pre_script;
58     int  post_script;
59 } am_host_t;
60 
61 typedef struct disk_s {
62     int		line;			/* line number of last definition */
63     char       *filename;               /* the filename where it is read */
64     struct disk_s *prev, *next;		/* doubly linked disk list */
65 
66     am_host_t	*host;			/* host list */
67     struct disk_s *hostnext;
68 
69     char        *hostname;		/* hostname */
70     char	*name;			/* label name for disk */
71     char	*device;		/* device name for disk, eg "sd0g" */
72     char	*dtype_name;		/* name of dump type */
73     dumptype_t	*config;		/* pointer to the dumptype config */
74     char	*program;		/* dump program, eg DUMP, STAR, GNUTAR */
75     char	*srvcompprog;		/* custom compression server filter */
76     char	*clntcompprog;		/* custom compression client filter */
77     char	*srv_encrypt;		/* custom encryption server filter */
78     char	*clnt_encrypt;		/* custom encryption client filter */
79     char	*amandad_path;		/* amandad path on the client */
80     char	*client_username;	/* username to connect on the client */
81     char	*client_port;		/* port to connect on the client */
82     char	*ssh_keys;		/* ssh_key file to use */
83     am_sl_t	*exclude_file;		/* file exclude spec */
84     am_sl_t	*exclude_list;		/* exclude list */
85     am_sl_t	*include_file;		/* file include spec */
86     am_sl_t	*include_list;		/* include list */
87     int		exclude_optional;	/* exclude list are optional */
88     int		include_optional;	/* include list are optional */
89     int		priority;		/* priority of disk */
90     int		allow_split;
91     int         max_warnings;
92     off_t	splitsize;
93     off_t	tape_splitsize;         /* size of dumpfile chunks on tape */
94     char	*split_diskbuffer;      /* place where we can buffer PORT-WRITE dumps other than RAM */
95     off_t	fallback_splitsize;     /* size for in-RAM PORT-WRITE buffers */
96     int		dumpcycle;		/* days between fulls */
97     long	frequency;		/* XXX - not used */
98     char	*auth;			/* type of authentication (per disk) */
99     int		maxdumps;		/* max number of parallel dumps (per system) */
100     int		maxpromoteday;		/* maximum of promote day */
101     int		bumppercent;
102     off_t	bumpsize;
103     int		bumpdays;
104     double	bumpmult;
105     time_t	starttime;		/* start this dump after this time (integer: HHMM) */
106     time_t	start_t;		/* start this dump after this time (time_t) */
107     int		strategy;		/* what dump strategy to use */
108     int		ignore;			/* ignore */
109     estimatelist_t estimatelist;	/* what estimate strategy to use */
110     int		compress;		/* type of compression to use */
111     int		encrypt;		/* type of encryption to use */
112     char	*srv_decrypt_opt;	/* server-side decryption option parameter to use */
113     char	*clnt_decrypt_opt;	/* client-side decryption option parameter to use */
114     double	comprate[2];		/* default compression rates */
115     /* flag options */
116     int		record;			/* record dump in /etc/dumpdates ? */
117     int		skip_incr;		/* incs done externally ? */
118     int		skip_full;		/* fulls done externally ? */
119     int		orig_holdingdisk;	/* original holdingdisk setting */
120     int		to_holdingdisk;		/* holding disk setting */
121     int		kencrypt;
122     int		index;			/* produce an index ? */
123     data_path_t	data_path;		/* defined data-path */
124     char       *dataport_list;		/* list of address to send data */
125     int		spindle;		/* spindle # - for parallel dumps */
126     int		inprogress;		/* being dumped now? */
127     int		todo;
128     char       *application;
129     identlist_t pp_scriptlist;
130     host_limit_t *dump_limit;
131     void	*up;			/* generic user pointer */
132 } disk_t;
133 
134 typedef struct disklist_s {
135     disk_t *head, *tail;
136 } disklist_t;
137 
138 #define empty(dlist)	((dlist).head == NULL)
139 
140 /* This function is integrated with the conffile.c error-handling; handle its return
141  * value just as you would the return of config_init() */
142 cfgerr_level_t read_diskfile(const char *, disklist_t *);
143 
144 am_host_t *get_hostlist(void);
145 am_host_t *lookup_host(const char *hostname);
146 disk_t *lookup_disk(const char *hostname, const char *diskname);
147 
148 disk_t *add_disk(disklist_t *list, char *hostname, char *diskname);
149 
150 void enqueue_disk(disklist_t *list, disk_t *disk);
151 void headqueue_disk(disklist_t *list, disk_t *disk);
152 void insert_disk(disklist_t *list, disk_t *disk, int (*f)(disk_t *a, disk_t *b));
153 int  find_disk(disklist_t *list, disk_t *disk);
154 void sort_disk(disklist_t *in, disklist_t *out, int (*f)(disk_t *a, disk_t *b));
155 disk_t *dequeue_disk(disklist_t *list);
156 void remove_disk(disklist_t *list, disk_t *disk);
157 
158 void dump_queue(char *str, disklist_t q, int npr, FILE *f);
159 
160 char *optionstr(disk_t *dp);
161 
162 /* xml_optionstr()
163  * to_server must be set to 1 if the result is sent to another server
164  *           application, eg. driver to dumper.
165  *           It must be set to 0 if the result is sent to the client.
166  */
167 GPtrArray *validate_optionstr(disk_t *dp);
168 char *xml_optionstr(disk_t *dp, int to_server);
169 char *xml_estimate(estimatelist_t estimatelist, am_feature_t *their_features);
170 char *clean_dle_str_for_client(char *dle_str, am_feature_t *their_features);
171 char *xml_application(disk_t *dp, application_t *application,
172 		      am_feature_t *their_features);
173 char *xml_scripts(identlist_t pp_scriptlist, am_feature_t *their_features);
174 char *xml_dumptype_properties(disk_t *dp);
175 
176 /* disable_skip_disk() set the db->todo flag to 0 for each dle with 'ignore'
177  * 'strategy skip'. It is useful for all programs that want to skip them,i
178  * eg. all amdump process.
179  * Program use for listing dump or index should not use it.
180  */
181 void disable_skip_disk(disklist_t *origqp);
182 
183 char *match_disklist(disklist_t *origqp, gboolean exact_match, int sargc,
184 		     char **sargv);
185 gboolean match_dumpfile(dumpfile_t *file, gboolean exact_match, int sargc,
186 			char **sargv);
187 void unload_disklist(void);
188 
189 netif_t *disklist_netifs(void);
190 
191 #endif /* ! DISKFILE_H */
192