Imported Upstream version 3.3.2
[debian/amanda] / client-src / client_util.h
1 /*
2  * Amanda, The Advanced Maryland Automatic Network Disk Archiver
3  * Copyright (c) 1991-1998 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  * Authors: the Amanda Development Team.  Its members are listed in a
24  * file named AUTHORS, in the root directory of this distribution.
25  */
26 /* 
27  * $Id: client_util.h,v 1.14 2006/05/25 01:47:11 johnfranks Exp $
28  *
29  */
30
31 #ifndef CLIENT_UTIL_H
32 #define CLIENT_UTIL_H
33
34 #include "amanda.h"
35 #include "conffile.h"
36 #include "amfeatures.h"
37 #include "am_sl.h"
38 #include "util.h"               /* for bstrncmp() */
39 #include "amandad.h"            /* for g_option_t */
40 #include "amxml.h"              /* for dle_t      */
41
42 typedef enum {
43     RECOVER_PATH_CWD    = 0,
44     RECOVER_PATH_REMOTE = 1,
45 } recover_path_t;
46
47 typedef struct backup_support_option_s {
48     int config;
49     int host;
50     int disk;
51     int max_level;
52     int index_line;
53     int index_xml;
54     int message_line;
55     int message_xml;
56     int record;
57     int include_file;
58     int include_list;
59     int include_list_glob;
60     int include_optional;
61     int exclude_file;
62     int exclude_list;
63     int exclude_list_glob;
64     int exclude_optional;
65     int collection;
66     int calcsize;
67     int client_estimate;
68     int multi_estimate;
69     int smb_recover_mode;
70     int features;
71     data_path_t data_path_set;  /* bitfield of all allowed data-path */
72     recover_path_t recover_path;
73 } backup_support_option_t;
74
75 typedef struct client_script_result_s {
76     int exit_code;
77     proplist_t proplist;
78     GPtrArray *output;
79     GPtrArray *err;
80 } client_script_result_t;
81
82 typedef enum {
83     DMP_NORMAL, DMP_IGNORE, DMP_STRANGE, DMP_SIZE, DMP_ERROR
84 } dmpline_t;
85
86 typedef struct regex_s {
87     char *regex;
88     int srcline;
89     int scale;                  /* only used for size lines */
90     int field;
91     dmpline_t typ;
92 } amregex_t;
93
94 #define AM_NORMAL_RE(re)        {(re), __LINE__, 0, 0, DMP_NORMAL}
95 #define AM_IGNORE_RE(re)        {(re), __LINE__, 0, 0, DMP_IGNORE}
96 #define AM_STRANGE_RE(re)       {(re), __LINE__, 0, 0, DMP_STRANGE}
97 #define AM_SIZE_RE(re,s,f)      {(re), __LINE__, (s), (f), DMP_SIZE}
98 #define AM_ERROR_RE(re)         {(re), __LINE__, 0, 0, DMP_ERROR}
99
100 char *build_exclude(dle_t *dle, int verbose);
101 char *build_include(dle_t *dle, int verbose);
102 void parse_options(char *str,
103                    dle_t *dle,
104                    am_feature_t *features,
105                    int verbose);
106
107 /* Add all properties of an application for a dle to an ARGV.
108  * include/exclude options are converted to properties.
109  *
110  * @param argv_ptr: the ARGV where to store properties.
111  * @param dle: the dle.
112  * @returns: Number of argument added to ARGV.
113  */
114 void application_property_add_to_argv(GPtrArray *argv_ptr,
115                                       dle_t *dle,
116                                       backup_support_option_t *bsu,
117                                       am_feature_t *amfeatures);
118
119 /* Merge properties from amanda-client.conf files to dles (application and scripts)
120  *
121  * @param dle: the dle list.
122  * @returns: Return 1 on success
123  *           Return 0 on failure
124  */
125 int merge_dles_properties(dle_t *dles, int verbose);
126
127 char *fixup_relative(char *name, char *device);
128 backup_support_option_t *backup_support_option(char *program,
129                                                g_option_t *g_options,
130                                                char *disk,
131                                                char *amdevice,
132                                                GPtrArray **errarray);
133
134 void run_client_script(script_t     *script,
135                        execute_on_t  execute_on,
136                        g_option_t   *g_options,
137                        dle_t        *dle);
138
139 void run_client_scripts(execute_on_t  execute_on,
140                         g_option_t   *g_options,
141                         dle_t        *dle,
142                         FILE         *streamout);
143
144 void run_calcsize(char *config, char *program, char *disk,
145                   char *dirname, GSList *levels,
146                   char *file_exclude, char *file_include);
147
148 gboolean check_access(char *filename, int mode);
149 gboolean check_file(char *filename, int mode);
150 gboolean check_dir(char *dirname, int mode);
151 gboolean check_suid(char *filename);
152 double the_num(char * str, int pos);
153
154 /* Convert a GSList returned from config_errors into an "ERROR "
155  * line suitable for inclusion in a NAK or REP packet.  Because we only
156  * get one ERROR line per packet, this includes only the first 
157  * error, with an indication that there are more to follow.
158  *
159  * @param errlist: the list of errors from config_errors
160  * @returns: newly allocated string containing the error messages
161  */
162 char *config_errors_to_error_string(GSList *errlist);
163
164 amregex_t *build_re_table(amregex_t *orig_re_table,
165                           GSList *normal_message,
166                           GSList *ignore_message,
167                           GSList *strange_message);
168 void add_type_table(dmpline_t typ,
169                     amregex_t **re_table, amregex_t *orig_re_table,
170                     GSList *normal_message, GSList *ignore_message,
171                     GSList *strange_message);
172 void add_list_table(dmpline_t typ, amregex_t **re_table,
173                     GSList *message);
174
175 /* Merge properties from conf_proplist to dle_proplist
176    If verbose is 1, then dle->disk and name are used in output.
177  * @returns: Return 1 on success
178  *           Return 0 on failure
179  */
180 int
181 merge_properties(dle_t *dle, char *name, proplist_t dle_proplist,
182                  proplist_t conf_proplist, int verbose);
183
184 #endif
185