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