Imported Upstream version 3.2.0
[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 "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 char *fixup_relative(char *name, char *device);
120 backup_support_option_t *backup_support_option(char *program,
121                                                g_option_t *g_options,
122                                                char *disk,
123                                                char *amdevice,
124                                                GPtrArray **errarray);
125
126 void run_client_script(script_t     *script,
127                        execute_on_t  execute_on,
128                        g_option_t   *g_options,
129                        dle_t        *dle);
130
131 void run_client_scripts(execute_on_t  execute_on,
132                         g_option_t   *g_options,
133                         dle_t        *dle,
134                         FILE         *streamout);
135
136 void run_calcsize(char *config, char *program, char *disk,
137                   char *dirname, GSList *levels,
138                   char *file_exclude, char *file_include);
139
140 void check_access(char *filename, int mode);
141 void check_file(char *filename, int mode);
142 void check_dir(char *dirname, int mode);
143 void check_suid(char *filename);
144 double the_num(char * str, int pos);
145
146 /* Convert a GSList returned from config_errors into an "ERROR "
147  * line suitable for inclusion in a NAK or REP packet.  Because we only
148  * get one ERROR line per packet, this includes only the first 
149  * error, with an indication that there are more to follow.
150  *
151  * @param errlist: the list of errors from config_errors
152  * @returns: newly allocated string containing the error messages
153  */
154 char *config_errors_to_error_string(GSList *errlist);
155
156 amregex_t *build_re_table(amregex_t *orig_re_table,
157                           GSList *normal_message,
158                           GSList *ignore_message,
159                           GSList *strange_message);
160 void add_type_table(dmpline_t typ,
161                     amregex_t **re_table, amregex_t *orig_re_table,
162                     GSList *normal_message, GSList *ignore_message,
163                     GSList *strange_message);
164 void add_list_table(dmpline_t typ, amregex_t **re_table,
165                     GSList *message);
166
167 /* Merge properties from proplist2 to proplist1)
168  */
169 void merge_properties(proplist_t proplist1, proplist_t proplist2);
170
171 #endif
172