| 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-2012 Zmanda, Inc. All Rights Reserved. |
| 5 |
* Copyright (c) 2013-2016 Carbonite, Inc. All Rights Reserved. |
| 6 |
* All Rights Reserved. |
| 7 |
* |
| 8 |
* Permission to use, copy, modify, distribute, and sell this software and its |
| 9 |
* documentation for any purpose is hereby granted without fee, provided that |
| 10 |
* the above copyright notice appear in all copies and that both that |
| 11 |
* copyright notice and this permission notice appear in supporting |
| 12 |
* documentation, and that the name of U.M. not be used in advertising or |
| 13 |
* publicity pertaining to distribution of the software without specific, |
| 14 |
* written prior permission. U.M. makes no representations about the |
| 15 |
* suitability of this software for any purpose. It is provided "as is" |
| 16 |
* without express or implied warranty. |
| 17 |
* |
| 18 |
* U.M. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL |
| 19 |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL U.M. |
| 20 |
* BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 21 |
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION |
| 22 |
* OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN |
| 23 |
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 24 |
* |
| 25 |
* Authors: the Amanda Development Team. Its members are listed in a |
| 26 |
* file named AUTHORS, in the root directory of this distribution. |
| 27 |
*/ |
| 28 |
/* |
| 29 |
* $Id: amgtar.c 8888 2007-10-02 13:40:42Z martineau $ |
| 30 |
* |
| 31 |
* send estimated backup sizes using dump |
| 32 |
*/ |
| 33 |
|
| 34 |
/* PROPERTY: |
| 35 |
* |
| 36 |
* GNUTAR-PATH (default GNUTAR) |
| 37 |
* GNUTAR-LISTDIR (default CNF_GNUTAR_LIST_DIR) |
| 38 |
* TARGET (DIRECTORY) (no default, if set, the backup will be from that |
| 39 |
* directory instead of from the --device) |
| 40 |
* ONE-FILE-SYSTEM (default YES) |
| 41 |
* SPARSE (default YES) |
| 42 |
* ATIME-PRESERVE (default YES) |
| 43 |
* CHECK-DEVICE (default YES) |
| 44 |
* NO-UNQUOTE (default NO) |
| 45 |
* ACLS (default NO) |
| 46 |
* SELINUX (default NO) |
| 47 |
* XATTRS (default NO) |
| 48 |
* INCLUDE-FILE |
| 49 |
* INCLUDE-LIST |
| 50 |
* INCLUDE-LIST-GLOB |
| 51 |
* INCLUDE-OPTIONAL |
| 52 |
* EXCLUDE-FILE |
| 53 |
* EXCLUDE-LIST |
| 54 |
* EXCLUDE-LIST-GLOB |
| 55 |
* EXCLUDE-OPTIONAL |
| 56 |
* NORMAL |
| 57 |
* IGNORE |
| 58 |
* STRANGE |
| 59 |
* EXIT-HANDLING (1=GOOD 2=BAD) |
| 60 |
* TAR-BLOCKSIZE (default does not add --blocking-factor option, |
| 61 |
* using tar's default) |
| 62 |
* VERBOSE |
| 63 |
*/ |
| 64 |
|
| 65 |
#include "amanda.h" |
| 66 |
#include "match.h" |
| 67 |
#include "pipespawn.h" |
| 68 |
#include "amfeatures.h" |
| 69 |
#include "clock.h" |
| 70 |
#include "amutil.h" |
| 71 |
#include "getfsent.h" |
| 72 |
#include "client_util.h" |
| 73 |
#include "conffile.h" |
| 74 |
#include "getopt.h" |
| 75 |
#include "security-file.h" |
| 76 |
|
| 77 |
int debug_application = 1; |
| 78 |
#define application_debug(i, ...) do { \ |
| 79 |
if ((i) <= debug_application) { \ |
| 80 |
dbprintf(__VA_ARGS__); \ |
| 81 |
} \ |
| 82 |
} while (0) |
| 83 |
|
| 84 |
static amregex_t init_re_table[] = { |
| 85 |
/* tar prints the size in bytes */ |
| 86 |
AM_SIZE_RE("^ *Total bytes written: [0-9][0-9]*", 1, 1), |
| 87 |
AM_NORMAL_RE("^could not open conf file"), |
| 88 |
AM_NORMAL_RE("^Elapsed time:"), |
| 89 |
AM_NORMAL_RE("^Throughput"), |
| 90 |
AM_IGNORE_RE(": Directory is new$"), |
| 91 |
AM_IGNORE_RE(": Directory has been renamed"), |
| 92 |
|
| 93 |
/* GNU tar 1.27 */ |
| 94 |
AM_NORMAL_RE(": directory is on a different filesystem; not dumped"), |
| 95 |
|
| 96 |
/* GNU tar 1.13.17 will print this warning when (not) backing up a |
| 97 |
Unix named socket. */ |
| 98 |
AM_NORMAL_RE(": socket ignored$"), |
| 99 |
|
| 100 |
/* GNUTAR produces a few error messages when files are modified or |
| 101 |
removed while it is running. They may cause data to be lost, but |
| 102 |
then they may not. We shouldn't consider them NORMAL until |
| 103 |
further investigation. */ |
| 104 |
AM_NORMAL_RE(": File .* shrunk by [0-9][0-9]* bytes, padding with zeros"), |
| 105 |
AM_NORMAL_RE(": Cannot add file .*: No such file or directory$"), |
| 106 |
AM_NORMAL_RE(": Error exit delayed from previous errors"), |
| 107 |
|
| 108 |
AM_ERROR_RE("amgtar: error"), |
| 109 |
|
| 110 |
/* catch-all: DMP_STRANGE is returned for all other lines */ |
| 111 |
AM_STRANGE_RE(NULL) |
| 112 |
}; |
| 113 |
static amregex_t *re_table; |
| 114 |
|
| 115 |
/* local functions */ |
| 116 |
int main(int argc, char **argv); |
| 117 |
|
| 118 |
typedef struct application_argument_s { |
| 119 |
char *config; |
| 120 |
char *host; |
| 121 |
int message; |
| 122 |
int collection; |
| 123 |
int calcsize; |
| 124 |
char *tar_blocksize; |
| 125 |
GSList *level; |
| 126 |
GSList *command_options; |
| 127 |
char *include_list_glob; |
| 128 |
char *exclude_list_glob; |
| 129 |
dle_t dle; |
| 130 |
int argc; |
| 131 |
char **argv; |
| 132 |
int verbose; |
| 133 |
int ignore_zeros; |
| 134 |
am_feature_t *amfeatures; |
| 135 |
char *recover_dump_state_file; |
| 136 |
gboolean dar; |
| 137 |
int state_stream; |
| 138 |
char *timestamp; |
| 139 |
} application_argument_t; |
| 140 |
|
| 141 |
enum { CMD_ESTIMATE, CMD_BACKUP }; |
| 142 |
|
| 143 |
static void amgtar_support(application_argument_t *argument); |
| 144 |
static void amgtar_selfcheck(application_argument_t *argument); |
| 145 |
static void amgtar_discover(application_argument_t *argument); |
| 146 |
static void amgtar_estimate(application_argument_t *argument); |
| 147 |
static void amgtar_backup(application_argument_t *argument); |
| 148 |
static void amgtar_restore(application_argument_t *argument); |
| 149 |
static void amgtar_validate(application_argument_t *argument); |
| 150 |
static void amgtar_index(application_argument_t *argument); |
| 151 |
static void amgtar_build_exinclude(dle_t *dle, |
| 152 |
int *nb_exclude, char **file_exclude, |
| 153 |
int *nb_include, char **file_includei, |
| 154 |
char *dirname, messagelist_t *mlist); |
| 155 |
static char *amgtar_get_incrname(application_argument_t *argument, int level, |
| 156 |
FILE *mesgstream, int command); |
| 157 |
static void check_no_check_device(void); |
| 158 |
static GPtrArray *amgtar_build_argv(char *gnutar_realpath, |
| 159 |
application_argument_t *argument, |
| 160 |
char *incrname, char **file_exclude, |
| 161 |
char **file_include, int command, |
| 162 |
messagelist_t *mlist); |
| 163 |
static char *command = NULL; |
| 164 |
static char *gnutar_path; |
| 165 |
static char *gnutar_listdir; |
| 166 |
static char *gnutar_target; |
| 167 |
static int gnutar_onefilesystem; |
| 168 |
static int gnutar_atimepreserve; |
| 169 |
static int gnutar_acls; |
| 170 |
static int gnutar_selinux; |
| 171 |
static int gnutar_xattrs; |
| 172 |
static int gnutar_checkdevice; |
| 173 |
static int gnutar_no_unquote; |
| 174 |
static int gnutar_sparse; |
| 175 |
static int gnutar_sparse_set = 0; |
| 176 |
static GSList *normal_message = NULL; |
| 177 |
static GSList *ignore_message = NULL; |
| 178 |
static GSList *strange_message = NULL; |
| 179 |
static char *exit_handling; |
| 180 |
static int exit_value[256]; |
| 181 |
static FILE *mesgstream = NULL; |
| 182 |
static int amgtar_exit_value = 0; |
| 183 |
|
| 184 |
static struct option long_options[] = { |
| 185 |
{"config" , 1, NULL, 1}, |
| 186 |
{"host" , 1, NULL, 2}, |
| 187 |
{"disk" , 1, NULL, 3}, |
| 188 |
{"device" , 1, NULL, 4}, |
| 189 |
{"level" , 1, NULL, 5}, |
| 190 |
{"index" , 1, NULL, 6}, |
| 191 |
{"message" , 1, NULL, 7}, |
| 192 |
{"collection" , 0, NULL, 8}, |
| 193 |
{"record" , 0, NULL, 9}, |
| 194 |
{"gnutar-path" , 1, NULL, 10}, |
| 195 |
{"gnutar-listdir" , 1, NULL, 11}, |
| 196 |
{"one-file-system" , 1, NULL, 12}, |
| 197 |
{"sparse" , 1, NULL, 13}, |
| 198 |
{"atime-preserve" , 1, NULL, 14}, |
| 199 |
{"check-device" , 1, NULL, 15}, |
| 200 |
{"include-file" , 1, NULL, 16}, |
| 201 |
{"include-list" , 1, NULL, 17}, |
| 202 |
{"include-optional", 1, NULL, 18}, |
| 203 |
{"exclude-file" , 1, NULL, 19}, |
| 204 |
{"exclude-list" , 1, NULL, 20}, |
| 205 |
{"exclude-optional", 1, NULL, 21}, |
| 206 |
{"directory" , 1, NULL, 22}, |
| 207 |
{"normal" , 1, NULL, 23}, |
| 208 |
{"ignore" , 1, NULL, 24}, |
| 209 |
{"strange" , 1, NULL, 25}, |
| 210 |
{"exit-handling" , 1, NULL, 26}, |
| 211 |
{"calcsize" , 0, NULL, 27}, |
| 212 |
{"tar-blocksize" , 1, NULL, 28}, |
| 213 |
{"no-unquote" , 1, NULL, 29}, |
| 214 |
{"acls" , 1, NULL, 30}, |
| 215 |
{"selinux" , 1, NULL, 31}, |
| 216 |
{"xattrs" , 1, NULL, 32}, |
| 217 |
{"command-options" , 1, NULL, 33}, |
| 218 |
{"include-list-glob", 1, NULL, 34}, |
| 219 |
{"exclude-list-glob", 1, NULL, 35}, |
| 220 |
{"verbose" , 1, NULL, 36}, |
| 221 |
{"ignore-zeros" , 1, NULL, 37}, |
| 222 |
{"amfeatures" , 1, NULL, 38}, |
| 223 |
{"recover-dump-state-file", 1, NULL, 39}, |
| 224 |
{"dar" , 1, NULL, 40}, |
| 225 |
{"state-stream" , 1, NULL, 41}, |
| 226 |
{"target" , 1, NULL, 42}, |
| 227 |
{"timestamp" , 1, NULL, 43}, |
| 228 |
{NULL, 0, NULL, 0} |
| 229 |
}; |
| 230 |
|
| 231 |
static message_t * |
| 232 |
amgtar_print_message( |
| 233 |
message_t *message) |
| 234 |
{ |
| 235 |
if (strcasecmp(command, "selfcheck") == 0 || |
| 236 |
strcasecmp(command, "discover") == 0) { |
| 237 |
return print_message(message); |
| 238 |
} |
| 239 |
if (message_get_severity(message) <= MSG_INFO) { |
| 240 |
if (g_str_equal(command, "estimate")) { |
| 241 |
fprintf(stdout, "OK %s\n", get_message(message)); |
| 242 |
} else if (g_str_equal(command, "backup")) { |
| 243 |
fprintf(mesgstream, "| %s\n", get_message(message)); |
| 244 |
} else { |
| 245 |
fprintf(stdout, "%s\n", get_message(message)); |
| 246 |
} |
| 247 |
} else { |
| 248 |
amgtar_exit_value = 1; |
| 249 |
if (g_str_equal(command, "estimate")) { |
| 250 |
fprintf(stdout, "ERROR %s\n", get_message(message)); |
| 251 |
} else if (g_str_equal(command, "backup")) { |
| 252 |
fprintf(mesgstream, "sendbackup: error [%s]\n", get_message(message)); |
| 253 |
} else { |
| 254 |
fprintf(stdout, "%s\n", get_message(message)); |
| 255 |
} |
| 256 |
} |
| 257 |
return message; |
| 258 |
} |
| 259 |
|
| 260 |
static char * |
| 261 |
escape_tar_glob( |
| 262 |
char *str, |
| 263 |
int *in_argv) |
| 264 |
{ |
| 265 |
char *result = malloc(4*strlen(str)+1); |
| 266 |
char *r = result; |
| 267 |
char *s; |
| 268 |
|
| 269 |
*in_argv = 0; |
| 270 |
for (s = str; *s != '\0'; s++) { |
| 271 |
if (*s == '\\') { |
| 272 |
char c = *(s+1); |
| 273 |
if (c == '\\') { |
| 274 |
*r++ = '\\'; |
| 275 |
*r++ = '\\'; |
| 276 |
*r++ = '\\'; |
| 277 |
s++; |
| 278 |
} else if (c == '?') { |
| 279 |
*r++ = 127; |
| 280 |
s++; |
| 281 |
continue; |
| 282 |
} else if (c == 'a') { |
| 283 |
*r++ = 7; |
| 284 |
s++; |
| 285 |
continue; |
| 286 |
} else if (c == 'b') { |
| 287 |
*r++ = 8; |
| 288 |
s++; |
| 289 |
continue; |
| 290 |
} else if (c == 'f') { |
| 291 |
*r++ = 12; |
| 292 |
s++; |
| 293 |
continue; |
| 294 |
} else if (c == 'n') { |
| 295 |
*r++ = 10; |
| 296 |
s++; |
| 297 |
*in_argv = 1; |
| 298 |
continue; |
| 299 |
} else if (c == 'r') { |
| 300 |
*r++ = 13; |
| 301 |
s++; |
| 302 |
*in_argv = 1; |
| 303 |
continue; |
| 304 |
} else if (c == 't') { |
| 305 |
*r++ = 9; |
| 306 |
s++; |
| 307 |
continue; |
| 308 |
} else if (c == 'v') { |
| 309 |
*r++ = 11; |
| 310 |
s++; |
| 311 |
continue; |
| 312 |
} else if (c >= '0' && c <= '9') { |
| 313 |
char d = c-'0'; |
| 314 |
s++; |
| 315 |
c = *(s+1); |
| 316 |
if (c >= '0' && c <= '9') { |
| 317 |
d = (d*8)+(c-'0'); |
| 318 |
s++; |
| 319 |
c = *(s+1); |
| 320 |
if (c >= '0' && c <= '9') { |
| 321 |
d = (d*8)+(c-'0'); |
| 322 |
s++; |
| 323 |
} |
| 324 |
} |
| 325 |
*r++ = d; |
| 326 |
continue; |
| 327 |
} else { |
| 328 |
*r++ = '\\'; |
| 329 |
} |
| 330 |
} else if (*s == '?') { |
| 331 |
*r++ = '\\'; |
| 332 |
*r++ = '\\'; |
| 333 |
} else if (*s == '*' || *s == '[') { |
| 334 |
*r++ = '\\'; |
| 335 |
} |
| 336 |
*r++ = *s; |
| 337 |
} |
| 338 |
*r = '\0'; |
| 339 |
|
| 340 |
return result; |
| 341 |
} |
| 342 |
|
| 343 |
|
| 344 |
int |
| 345 |
main( |
| 346 |
int argc, |
| 347 |
char ** argv) |
| 348 |
{ |
| 349 |
int c; |
| 350 |
application_argument_t argument; |
| 351 |
int i; |
| 352 |
char *gnutar_onefilesystem_value = NULL; |
| 353 |
char *gnutar_sparse_value = NULL; |
| 354 |
char *gnutar_atimepreserve_value = NULL; |
| 355 |
char *gnutar_checkdevice_value = NULL; |
| 356 |
char *gnutar_no_unquote_value = NULL; |
| 357 |
char *gnutar_dar_value = NULL; |
| 358 |
|
| 359 |
#ifdef GNUTAR |
| 360 |
gnutar_path = g_strdup(GNUTAR); |
| 361 |
#else |
| 362 |
gnutar_path = NULL; |
| 363 |
#endif |
| 364 |
gnutar_listdir = NULL; |
| 365 |
gnutar_target = NULL; |
| 366 |
gnutar_onefilesystem = 1; |
| 367 |
gnutar_atimepreserve = 1; |
| 368 |
gnutar_acls = 0; |
| 369 |
gnutar_selinux = 0; |
| 370 |
gnutar_xattrs = 0; |
| 371 |
gnutar_checkdevice = 1; |
| 372 |
gnutar_sparse = 1; |
| 373 |
gnutar_no_unquote = 0; |
| 374 |
exit_handling = NULL; |
| 375 |
|
| 376 |
/* initialize */ |
| 377 |
|
| 378 |
glib_init(); |
| 379 |
|
| 380 |
/* |
| 381 |
* Configure program for internationalization: |
| 382 |
* 1) Only set the message locale for now. |
| 383 |
* 2) Set textdomain for all amanda related programs to "amanda" |
| 384 |
* We don't want to be forced to support dozens of message catalogs. |
| 385 |
*/ |
| 386 |
setlocale(LC_MESSAGES, "C"); |
| 387 |
textdomain("amanda"); |
| 388 |
|
| 389 |
if (argc < 2) { |
| 390 |
printf("ERROR no command given to amgtar\n"); |
| 391 |
error(_("No command given to amgtar")); |
| 392 |
} |
| 393 |
|
| 394 |
/* drop root privileges */ |
| 395 |
if (!set_root_privs(0)) { |
| 396 |
if (g_str_equal(argv[1], "selfcheck")) { |
| 397 |
printf("ERROR amgtar must be run setuid root\n"); |
| 398 |
} |
| 399 |
error(_("amgtar must be run setuid root")); |
| 400 |
} |
| 401 |
|
| 402 |
set_pname("amgtar"); |
| 403 |
set_pcomponent("application"); |
| 404 |
set_pmodule("amgtar"); |
| 405 |
|
| 406 |
/* Don't die when child closes pipe */ |
| 407 |
signal(SIGPIPE, SIG_IGN); |
| 408 |
|
| 409 |
#if defined(USE_DBMALLOC) |
| 410 |
malloc_size_1 = malloc_inuse(&malloc_hist_1); |
| 411 |
#endif |
| 412 |
|
| 413 |
add_amanda_log_handler(amanda_log_stderr); |
| 414 |
add_amanda_log_handler(amanda_log_syslog); |
| 415 |
dbopen(DBG_SUBDIR_CLIENT); |
| 416 |
startclock(); |
| 417 |
dbprintf(_("version %s\n"), VERSION); |
| 418 |
|
| 419 |
config_init(CONFIG_INIT_CLIENT|CONFIG_INIT_GLOBAL, NULL); |
| 420 |
|
| 421 |
//check_running_as(RUNNING_AS_DUMPUSER_PREFERRED); |
| 422 |
//root for amrecover |
| 423 |
//RUNNING_AS_CLIENT_LOGIN from selfcheck, sendsize, sendbackup |
| 424 |
|
| 425 |
/* parse argument */ |
| 426 |
command = argv[1]; |
| 427 |
|
| 428 |
if (strcasecmp(command,"selfcheck") == 0) { |
| 429 |
fprintf(stdout, "MESSAGE JSON\n"); |
| 430 |
} |
| 431 |
argument.config = NULL; |
| 432 |
argument.timestamp = NULL; |
| 433 |
argument.host = NULL; |
| 434 |
argument.message = 0; |
| 435 |
argument.collection = 0; |
| 436 |
argument.calcsize = 0; |
| 437 |
argument.tar_blocksize = NULL; |
| 438 |
argument.level = NULL; |
| 439 |
argument.command_options = NULL; |
| 440 |
argument.include_list_glob = NULL; |
| 441 |
argument.exclude_list_glob = NULL; |
| 442 |
argument.verbose = 0; |
| 443 |
argument.ignore_zeros = 1; |
| 444 |
argument.amfeatures = NULL; |
| 445 |
argument.recover_dump_state_file = NULL; |
| 446 |
argument.dar = FALSE; |
| 447 |
argument.state_stream = -1; |
| 448 |
init_dle(&argument.dle); |
| 449 |
argument.dle.record = 0; |
| 450 |
|
| 451 |
while (1) { |
| 452 |
int option_index = 0; |
| 453 |
c = getopt_long (argc, argv, "", long_options, &option_index); |
| 454 |
if (c == -1) { |
| 455 |
break; |
| 456 |
} |
| 457 |
switch (c) { |
| 458 |
case 1: amfree(argument.config); |
| 459 |
argument.config = g_strdup(optarg); |
| 460 |
break; |
| 461 |
case 2: amfree(argument.host); |
| 462 |
argument.host = g_strdup(optarg); |
| 463 |
break; |
| 464 |
case 3: amfree(argument.dle.disk); |
| 465 |
argument.dle.disk = g_strdup(optarg); |
| 466 |
break; |
| 467 |
case 4: amfree(argument.dle.device); |
| 468 |
argument.dle.device = g_strdup(optarg); |
| 469 |
break; |
| 470 |
case 5: argument.level = g_slist_append(argument.level, |
| 471 |
GINT_TO_POINTER(atoi(optarg))); |
| 472 |
break; |
| 473 |
case 6: argument.dle.create_index = 1; |
| 474 |
break; |
| 475 |
case 7: argument.message = 1; |
| 476 |
break; |
| 477 |
case 8: argument.collection = 1; |
| 478 |
break; |
| 479 |
case 9: argument.dle.record = 1; |
| 480 |
break; |
| 481 |
case 10: amfree(gnutar_path); |
| 482 |
gnutar_path = g_strdup(optarg); |
| 483 |
break; |
| 484 |
case 11: amfree(gnutar_listdir); |
| 485 |
gnutar_listdir = g_strdup(optarg); |
| 486 |
break; |
| 487 |
case 12: amfree(gnutar_onefilesystem_value); |
| 488 |
gnutar_onefilesystem_value = g_strdup(optarg); |
| 489 |
break; |
| 490 |
case 13: amfree(gnutar_sparse_value); |
| 491 |
gnutar_sparse_value = g_strdup(optarg); |
| 492 |
break; |
| 493 |
case 14: amfree(gnutar_atimepreserve_value); |
| 494 |
gnutar_atimepreserve_value = g_strdup(optarg); |
| 495 |
break; |
| 496 |
case 15: amfree(gnutar_checkdevice_value); |
| 497 |
gnutar_checkdevice_value = g_strdup(optarg); |
| 498 |
break; |
| 499 |
case 16: argument.dle.include_file = |
| 500 |
append_sl(argument.dle.include_file, optarg); |
| 501 |
break; |
| 502 |
case 17: argument.dle.include_list = |
| 503 |
append_sl(argument.dle.include_list, optarg); |
| 504 |
break; |
| 505 |
case 18: argument.dle.include_optional = 1; |
| 506 |
break; |
| 507 |
case 19: argument.dle.exclude_file = |
| 508 |
append_sl(argument.dle.exclude_file, optarg); |
| 509 |
break; |
| 510 |
case 20: argument.dle.exclude_list = |
| 511 |
append_sl(argument.dle.exclude_list, optarg); |
| 512 |
break; |
| 513 |
case 21: argument.dle.exclude_optional = 1; |
| 514 |
break; |
| 515 |
case 22: amfree(gnutar_target); |
| 516 |
gnutar_target = g_strdup(optarg); |
| 517 |
break; |
| 518 |
case 23: normal_message = |
| 519 |
g_slist_append(normal_message, optarg); |
| 520 |
break; |
| 521 |
case 24: ignore_message = |
| 522 |
g_slist_append(ignore_message, optarg); |
| 523 |
break; |
| 524 |
case 25: strange_message = |
| 525 |
g_slist_append(strange_message, optarg); |
| 526 |
break; |
| 527 |
case 26: amfree(exit_handling); |
| 528 |
exit_handling = g_strdup(optarg); |
| 529 |
break; |
| 530 |
case 27: argument.calcsize = 1; |
| 531 |
break; |
| 532 |
case 28: amfree(argument.tar_blocksize); |
| 533 |
argument.tar_blocksize = g_strdup(optarg); |
| 534 |
break; |
| 535 |
case 29: amfree(gnutar_no_unquote_value); |
| 536 |
gnutar_no_unquote_value = g_strdup(optarg); |
| 537 |
break; |
| 538 |
case 30: if (strcasecmp(optarg, "YES") == 0) |
| 539 |
gnutar_acls = 1; |
| 540 |
break; |
| 541 |
case 31: if (strcasecmp(optarg, "YES") == 0) |
| 542 |
gnutar_selinux = 1; |
| 543 |
break; |
| 544 |
case 32: if (strcasecmp(optarg, "YES") == 0) |
| 545 |
gnutar_xattrs = 1; |
| 546 |
break; |
| 547 |
case 33: argument.command_options = |
| 548 |
g_slist_append(argument.command_options, |
| 549 |
g_strdup(optarg)); |
| 550 |
break; |
| 551 |
case 34: amfree(argument.include_list_glob); |
| 552 |
argument.include_list_glob = g_strdup(optarg); |
| 553 |
break; |
| 554 |
case 35: amfree(argument.exclude_list_glob); |
| 555 |
argument.exclude_list_glob = g_strdup(optarg); |
| 556 |
break; |
| 557 |
case 36: if (strcasecmp(optarg, "YES") == 0) |
| 558 |
argument.verbose = 1; |
| 559 |
break; |
| 560 |
case 37: if (strcasecmp(optarg, "YES") != 0) |
| 561 |
argument.ignore_zeros = 0; |
| 562 |
break; |
| 563 |
case 38: amfree(argument.amfeatures); |
| 564 |
argument.amfeatures = am_string_to_feature(optarg); |
| 565 |
break; |
| 566 |
case 39: amfree(argument.recover_dump_state_file); |
| 567 |
argument.recover_dump_state_file = g_strdup(optarg); |
| 568 |
break; |
| 569 |
case 40: amfree(gnutar_dar_value); |
| 570 |
gnutar_dar_value = g_strdup(optarg); |
| 571 |
break; |
| 572 |
case 41: argument.state_stream = atoi(optarg); |
| 573 |
break; |
| 574 |
case 42: amfree(gnutar_target); |
| 575 |
gnutar_target = g_strdup(optarg); |
| 576 |
break; |
| 577 |
case 43: amfree(argument.timestamp); |
| 578 |
argument.timestamp = g_strdup(optarg); |
| 579 |
break; |
| 580 |
case ':': |
| 581 |
case '?': |
| 582 |
break; |
| 583 |
} |
| 584 |
} |
| 585 |
|
| 586 |
if ((g_str_equal(command, "backup") || |
| 587 |
g_str_equal(command, "restore")) && argument.state_stream >= 0) { |
| 588 |
g_debug("state_stream: %d", argument.state_stream); |
| 589 |
safe_fd3(3, 2, dbfd(), argument.state_stream); |
| 590 |
} else { |
| 591 |
safe_fd2(3, 2, dbfd()); |
| 592 |
} |
| 593 |
|
| 594 |
if (g_str_equal(command, "backup")) { |
| 595 |
mesgstream = fdopen(3, "w"); |
| 596 |
if (!mesgstream) { |
| 597 |
error(_("error mesgstream(%d): %s\n"), 3, strerror(errno)); |
| 598 |
} |
| 599 |
} |
| 600 |
|
| 601 |
if (!argument.dle.disk && argument.dle.device) |
| 602 |
argument.dle.disk = g_strdup(argument.dle.device); |
| 603 |
if (!argument.dle.device && argument.dle.disk) |
| 604 |
argument.dle.device = g_strdup(argument.dle.disk); |
| 605 |
if (!argument.dle.disk && !argument.dle.device) { |
| 606 |
argument.dle.disk = g_strdup("no disk"); |
| 607 |
argument.dle.device = g_strdup("no device"); |
| 608 |
} |
| 609 |
if (!argument.host) |
| 610 |
argument.host = g_strdup("no host"); |
| 611 |
|
| 612 |
if (gnutar_onefilesystem_value) { |
| 613 |
if (strcasecmp(gnutar_onefilesystem_value, "NO") == 0) { |
| 614 |
gnutar_onefilesystem = 0; |
| 615 |
} else if (strcasecmp(gnutar_onefilesystem_value, "YES") == 0) { |
| 616 |
gnutar_onefilesystem = 1; |
| 617 |
} else { |
| 618 |
delete_message(amgtar_print_message(build_message( |
| 619 |
AMANDA_FILE, __LINE__, 3700007, MSG_ERROR, 4, |
| 620 |
"value", gnutar_onefilesystem_value, |
| 621 |
"disk", argument.dle.disk, |
| 622 |
"device", argument.dle.device, |
| 623 |
"hostname", argument.host))); |
| 624 |
} |
| 625 |
} |
| 626 |
|
| 627 |
if (gnutar_sparse_value) { |
| 628 |
if (strcasecmp(gnutar_sparse_value, "NO") == 0) { |
| 629 |
gnutar_sparse = 0; |
| 630 |
} else if (strcasecmp(gnutar_sparse_value, "YES") == 0) { |
| 631 |
gnutar_sparse = 1; |
| 632 |
} else { |
| 633 |
delete_message(amgtar_print_message(build_message( |
| 634 |
AMANDA_FILE, __LINE__, 3700008, MSG_ERROR, 4, |
| 635 |
"value", gnutar_sparse_value, |
| 636 |
"disk", argument.dle.disk, |
| 637 |
"device", argument.dle.device, |
| 638 |
"hostname", argument.host))); |
| 639 |
} |
| 640 |
} |
| 641 |
|
| 642 |
if (gnutar_atimepreserve_value) { |
| 643 |
if (strcasecmp(gnutar_atimepreserve_value, "NO") == 0) { |
| 644 |
gnutar_atimepreserve = 0; |
| 645 |
} else if (strcasecmp(gnutar_atimepreserve_value, "YES") == 0) { |
| 646 |
gnutar_atimepreserve = 1; |
| 647 |
} else { |
| 648 |
delete_message(amgtar_print_message(build_message( |
| 649 |
AMANDA_FILE, __LINE__, 3700009, MSG_ERROR, 4, |
| 650 |
"value", gnutar_atimepreserve_value, |
| 651 |
"disk", argument.dle.disk, |
| 652 |
"device", argument.dle.device, |
| 653 |
"hostname", argument.host))); |
| 654 |
} |
| 655 |
} |
| 656 |
|
| 657 |
if (gnutar_checkdevice_value) { |
| 658 |
if (strcasecmp(gnutar_checkdevice_value, "NO") == 0) { |
| 659 |
gnutar_checkdevice = 0; |
| 660 |
} else if (strcasecmp(gnutar_checkdevice_value, "YES") == 0) { |
| 661 |
gnutar_checkdevice = 1; |
| 662 |
} else { |
| 663 |
delete_message(amgtar_print_message(build_message( |
| 664 |
AMANDA_FILE, __LINE__, 3700010, MSG_ERROR, 4, |
| 665 |
"value", gnutar_checkdevice_value, |
| 666 |
"disk", argument.dle.disk, |
| 667 |
"device", argument.dle.device, |
| 668 |
"hostname", argument.host))); |
| 669 |
} |
| 670 |
} |
| 671 |
|
| 672 |
if (gnutar_no_unquote_value) { |
| 673 |
if (strcasecmp(gnutar_no_unquote_value, "NO") == 0) { |
| 674 |
gnutar_no_unquote = 0; |
| 675 |
} else if (strcasecmp(gnutar_no_unquote_value, "YES") == 0) { |
| 676 |
gnutar_no_unquote = 1; |
| 677 |
} else { |
| 678 |
delete_message(amgtar_print_message(build_message( |
| 679 |
AMANDA_FILE, __LINE__, 3700011, MSG_ERROR, 4, |
| 680 |
"value", gnutar_no_unquote_value, |
| 681 |
"disk", argument.dle.disk, |
| 682 |
"device", argument.dle.device, |
| 683 |
"hostname", argument.host))); |
| 684 |
} |
| 685 |
} |
| 686 |
|
| 687 |
if (gnutar_dar_value) { |
| 688 |
if (strcasecmp(gnutar_dar_value, "NO") == 0) { |
| 689 |
argument.dar = FALSE; |
| 690 |
} else if (strcasecmp(gnutar_dar_value, "YES") == 0) { |
| 691 |
argument.dar = TRUE; |
| 692 |
} else { |
| 693 |
delete_message(amgtar_print_message(build_message( |
| 694 |
AMANDA_FILE, __LINE__, 3700015, MSG_ERROR, 4, |
| 695 |
"property_value", optarg, |
| 696 |
"disk", argument.dle.disk, |
| 697 |
"device", argument.dle.device, |
| 698 |
"hostname", argument.host))); |
| 699 |
} |
| 700 |
} |
| 701 |
|
| 702 |
argument.argc = argc - optind; |
| 703 |
argument.argv = argv + optind; |
| 704 |
|
| 705 |
if (argument.config) { |
| 706 |
config_init(CONFIG_INIT_CLIENT | CONFIG_INIT_EXPLICIT_NAME | CONFIG_INIT_OVERLAY, |
| 707 |
argument.config); |
| 708 |
dbrename(get_config_name(), DBG_SUBDIR_CLIENT); |
| 709 |
} |
| 710 |
|
| 711 |
if (config_errors(NULL) >= CFGERR_ERRORS) { |
| 712 |
g_critical(_("errors processing config file")); |
| 713 |
} |
| 714 |
|
| 715 |
if (!gnutar_listdir) { |
| 716 |
gnutar_listdir = g_strdup(getconf_str(CNF_GNUTAR_LIST_DIR)); |
| 717 |
} |
| 718 |
|
| 719 |
re_table = build_re_table(init_re_table, normal_message, ignore_message, |
| 720 |
strange_message); |
| 721 |
|
| 722 |
for(i=0;i<256;i++) |
| 723 |
exit_value[i] = 1; /* BAD */ |
| 724 |
exit_value[0] = 0; /* GOOD */ |
| 725 |
exit_value[1] = 0; /* GOOD */ |
| 726 |
if (exit_handling) { |
| 727 |
char *s = exit_handling; |
| 728 |
while (s) { |
| 729 |
char *r = strchr(s, '='); |
| 730 |
if (r) { |
| 731 |
int j = atoi(s); |
| 732 |
if (j >= 0 && j < 256) { |
| 733 |
r++; |
| 734 |
if (strncasecmp(r, "GOOD", 4) == 0) { |
| 735 |
exit_value[j] = 0; |
| 736 |
} |
| 737 |
} |
| 738 |
} |
| 739 |
s = strchr(s+1, ' '); |
| 740 |
} |
| 741 |
} |
| 742 |
|
| 743 |
if (strlen(gnutar_listdir) == 0) |
| 744 |
amfree(gnutar_listdir); |
| 745 |
|
| 746 |
if (gnutar_path) { |
| 747 |
dbprintf("GNUTAR-PATH %s\n", gnutar_path); |
| 748 |
} else { |
| 749 |
dbprintf("GNUTAR-PATH is not set\n"); |
| 750 |
} |
| 751 |
if (gnutar_listdir) { |
| 752 |
dbprintf("GNUTAR-LISTDIR %s\n", gnutar_listdir); |
| 753 |
} else { |
| 754 |
dbprintf("GNUTAR-LISTDIR is not set\n"); |
| 755 |
} |
| 756 |
if (gnutar_target) { |
| 757 |
dbprintf("TARGET %s\n", gnutar_target); |
| 758 |
} |
| 759 |
dbprintf("ONE-FILE-SYSTEM %s\n", gnutar_onefilesystem? "yes":"no"); |
| 760 |
dbprintf("SPARSE %s\n", gnutar_sparse? "yes":"no"); |
| 761 |
dbprintf("NO-UNQUOTE %s\n", gnutar_no_unquote? "yes":"no"); |
| 762 |
dbprintf("ATIME-PRESERVE %s\n", gnutar_atimepreserve? "yes":"no"); |
| 763 |
dbprintf("ACLS %s\n", gnutar_acls? "yes":"no"); |
| 764 |
dbprintf("SELINUX %s\n", gnutar_selinux? "yes":"no"); |
| 765 |
dbprintf("XATTRS %s\n", gnutar_xattrs? "yes":"no"); |
| 766 |
dbprintf("CHECK-DEVICE %s\n", gnutar_checkdevice? "yes":"no"); |
| 767 |
{ |
| 768 |
amregex_t *rp; |
| 769 |
for (rp = re_table; rp->regex != NULL; rp++) { |
| 770 |
switch (rp->typ) { |
| 771 |
case DMP_NORMAL : dbprintf("NORMAL %s\n", rp->regex); break; |
| 772 |
case DMP_IGNORE : dbprintf("IGNORE %s\n", rp->regex); break; |
| 773 |
case DMP_STRANGE: dbprintf("STRANGE %s\n", rp->regex); break; |
| 774 |
case DMP_SIZE : dbprintf("SIZE %s\n", rp->regex); break; |
| 775 |
case DMP_ERROR : dbprintf("ERROR %s\n", rp->regex); break; |
| 776 |
} |
| 777 |
} |
| 778 |
} |
| 779 |
|
| 780 |
if (g_str_equal(command, "support")) { |
| 781 |
amgtar_support(&argument); |
| 782 |
} else if (g_str_equal(command, "selfcheck")) { |
| 783 |
amgtar_selfcheck(&argument); |
| 784 |
} else if (g_str_equal(command, "estimate")) { |
| 785 |
amgtar_estimate(&argument); |
| 786 |
} else if (g_str_equal(command, "backup")) { |
| 787 |
amgtar_backup(&argument); |
| 788 |
} else if (g_str_equal(command, "restore")) { |
| 789 |
amgtar_restore(&argument); |
| 790 |
} else if (g_str_equal(command, "validate")) { |
| 791 |
amgtar_validate(&argument); |
| 792 |
} else if (g_str_equal(command, "index")) { |
| 793 |
amgtar_index(&argument); |
| 794 |
} else if (g_str_equal(command, "discover")) { |
| 795 |
amgtar_discover(&argument); |
| 796 |
} else { |
| 797 |
dbprintf("Unknown command `%s'.\n", command); |
| 798 |
fprintf(stderr, "Unknown command `%s'.\n", command); |
| 799 |
exit (1); |
| 800 |
} |
| 801 |
|
| 802 |
g_free(argument.config); |
| 803 |
g_free(argument.host); |
| 804 |
g_free(argument.dle.disk); |
| 805 |
g_free(argument.dle.device); |
| 806 |
g_free(argument.tar_blocksize); |
| 807 |
g_free(argument.timestamp); |
| 808 |
g_slist_free(argument.level); |
| 809 |
|
| 810 |
dbclose(); |
| 811 |
|
| 812 |
return amgtar_exit_value; |
| 813 |
} |
| 814 |
|
| 815 |
static char *validate_command_options( |
| 816 |
application_argument_t *argument) |
| 817 |
{ |
| 818 |
GSList *copt; |
| 819 |
|
| 820 |
for (copt = argument->command_options; copt != NULL; copt = copt->next) { |
| 821 |
char *opt = (char *)copt->data; |
| 822 |
|
| 823 |
if (g_str_has_prefix(opt,"--create") || |
| 824 |
g_str_has_prefix(opt,"--totals") || |
| 825 |
g_str_has_prefix(opt,"--dereference") || |
| 826 |
g_str_has_prefix(opt,"--no-recursion") || |
| 827 |
g_str_has_prefix(opt,"--one-file-system") || |
| 828 |
g_str_has_prefix(opt,"--incremental") || |
| 829 |
g_str_has_prefix(opt,"--atime-preserve") || |
| 830 |
g_str_has_prefix(opt,"--sparse") || |
| 831 |
g_str_has_prefix(opt,"--ignore-failed-read") || |
| 832 |
g_str_has_prefix(opt,"--numeric-owner") || |
| 833 |
g_str_has_prefix(opt,"--verbose") || |
| 834 |
g_str_has_prefix(opt,"--blocking-factor") || |
| 835 |
g_str_has_prefix(opt,"--file") || |
| 836 |
g_str_has_prefix(opt,"--directory") || |
| 837 |
g_str_has_prefix(opt,"--exclude") || |
| 838 |
g_str_has_prefix(opt,"--transform") || |
| 839 |
g_str_has_prefix(opt,"--listed-incremental") || |
| 840 |
g_str_has_prefix(opt,"--newer") || |
| 841 |
g_str_has_prefix(opt,"--exclude-from") || |
| 842 |
g_str_has_prefix(opt,"--files-from")) { |
| 843 |
// All the above mentioned options are allowed. |
| 844 |
continue; |
| 845 |
} |
| 846 |
else { |
| 847 |
// This function return non-null value if one of the not allowed option is given. |
| 848 |
return opt; |
| 849 |
} |
| 850 |
} |
| 851 |
|
| 852 |
return NULL; |
| 853 |
} |
| 854 |
|
| 855 |
static void |
| 856 |
amgtar_support( |
| 857 |
application_argument_t *argument) |
| 858 |
{ |
| 859 |
(void)argument; |
| 860 |
fprintf(stdout, "CONFIG YES\n"); |
| 861 |
fprintf(stdout, "HOST YES\n"); |
| 862 |
fprintf(stdout, "DISK YES\n"); |
| 863 |
fprintf(stdout, "MAX-LEVEL 399\n"); |
| 864 |
fprintf(stdout, "INDEX-LINE YES\n"); |
| 865 |
fprintf(stdout, "INDEX-XML NO\n"); |
| 866 |
fprintf(stdout, "MESSAGE-LINE YES\n"); |
| 867 |
fprintf(stdout, "MESSAGE-SELFCHECK-JSON YES\n"); |
| 868 |
fprintf(stdout, "MESSAGE-XML NO\n"); |
| 869 |
fprintf(stdout, "RECORD YES\n"); |
| 870 |
fprintf(stdout, "INCLUDE-FILE YES\n"); |
| 871 |
fprintf(stdout, "INCLUDE-LIST YES\n"); |
| 872 |
fprintf(stdout, "INCLUDE-LIST-GLOB YES\n"); |
| 873 |
fprintf(stdout, "INCLUDE-OPTIONAL YES\n"); |
| 874 |
fprintf(stdout, "EXCLUDE-FILE YES\n"); |
| 875 |
fprintf(stdout, "EXCLUDE-LIST YES\n"); |
| 876 |
fprintf(stdout, "EXCLUDE-LIST-GLOB YES\n"); |
| 877 |
fprintf(stdout, "EXCLUDE-OPTIONAL YES\n"); |
| 878 |
fprintf(stdout, "COLLECTION NO\n"); |
| 879 |
fprintf(stdout, "MULTI-ESTIMATE YES\n"); |
| 880 |
fprintf(stdout, "CALCSIZE YES\n"); |
| 881 |
fprintf(stdout, "CLIENT-ESTIMATE YES\n"); |
| 882 |
fprintf(stdout, "DISCOVER YES\n"); |
| 883 |
fprintf(stdout, "AMFEATURES YES\n"); |
| 884 |
fprintf(stdout, "RECOVER-DUMP-STATE-FILE YES\n"); |
| 885 |
fprintf(stdout, "DAR YES\n"); |
| 886 |
fprintf(stdout, "STATE-STREAM YES\n"); |
| 887 |
fprintf(stdout, "TIMESTAMP YES\n"); |
| 888 |
} |
| 889 |
|
| 890 |
static void |
| 891 |
amgtar_discover( |
| 892 |
application_argument_t *argument ) |
| 893 |
{ |
| 894 |
DIR *dir; |
| 895 |
struct dirent *dp; |
| 896 |
char *full_path; |
| 897 |
size_t path_len; |
| 898 |
size_t path_alloc; |
| 899 |
struct stat stat_buf; |
| 900 |
char *file_type; |
| 901 |
gboolean reported_entries = FALSE; |
| 902 |
|
| 903 |
if (argument->dle.disk) { |
| 904 |
if ((dir = opendir(argument->dle.disk)) == NULL) { |
| 905 |
delete_message(amgtar_print_message(build_message( |
| 906 |
AMANDA_FILE, __LINE__, 3700012, MSG_ERROR, 2, |
| 907 |
"diskname", argument->dle.disk, |
| 908 |
"errno", errno))); |
| 909 |
return; |
| 910 |
} |
| 911 |
|
| 912 |
path_len = strlen(argument->dle.disk); |
| 913 |
path_alloc = path_len + 258; |
| 914 |
full_path = g_malloc(path_alloc); |
| 915 |
strcpy(full_path, argument->dle.disk); |
| 916 |
if (full_path[path_len-1] != '/') { |
| 917 |
strcat(full_path, "/"); |
| 918 |
path_len++; |
| 919 |
} |
| 920 |
|
| 921 |
while ((dp = readdir (dir)) != NULL) { |
| 922 |
if (strcmp(dp->d_name, ".") == 0 || strcmp(dp->d_name, "..") == 0) |
| 923 |
continue; |
| 924 |
|
| 925 |
while (path_len + strlen(dp->d_name) + 1 > path_alloc) { |
| 926 |
path_alloc *= 2; |
| 927 |
full_path = g_realloc(full_path, path_alloc); |
| 928 |
} |
| 929 |
strcpy(full_path + path_len, dp->d_name); |
| 930 |
|
| 931 |
if (lstat(full_path, &stat_buf) != 0) { |
| 932 |
delete_message(amgtar_print_message(build_message( |
| 933 |
AMANDA_FILE, __LINE__, 3700013, MSG_ERROR, 2, |
| 934 |
"diskname", argument->dle.disk, |
| 935 |
"errno", errno))); |
| 936 |
continue; |
| 937 |
} |
| 938 |
file_type = "unknown"; |
| 939 |
if (S_ISDIR(stat_buf.st_mode)) { |
| 940 |
file_type = "dir"; |
| 941 |
} else if (S_ISCHR(stat_buf.st_mode)) { |
| 942 |
file_type = "char"; |
| 943 |
} else if (S_ISBLK(stat_buf.st_mode)) { |
| 944 |
file_type = "block"; |
| 945 |
} else if (S_ISREG(stat_buf.st_mode)) { |
| 946 |
file_type = "regular"; |
| 947 |
} else if (S_ISSOCK(stat_buf.st_mode)) { |
| 948 |
file_type = "socket"; |
| 949 |
} else if (S_ISLNK(stat_buf.st_mode)) { |
| 950 |
file_type = "link"; |
| 951 |
} else if (S_ISFIFO(stat_buf.st_mode)) { |
| 952 |
file_type = "fifo"; |
| 953 |
} |
| 954 |
delete_message(amgtar_print_message(build_message( |
| 955 |
AMANDA_FILE, __LINE__, 3100005, MSG_INFO, 4, |
| 956 |
"file_type", file_type, |
| 957 |
"full_path", full_path, |
| 958 |
"diskname", argument->dle.disk, |
| 959 |
"dle_name", dp->d_name))); |
| 960 |
reported_entries = TRUE; |
| 961 |
} |
| 962 |
closedir(dir); |
| 963 |
g_free(full_path); |
| 964 |
} |
| 965 |
|
| 966 |
if (!reported_entries) { |
| 967 |
delete_message(amgtar_print_message(build_message( |
| 968 |
AMANDA_FILE, __LINE__, 3100006, MSG_ERROR, 1, |
| 969 |
"diskname", argument->dle.disk))); |
| 970 |
} |
| 971 |
} |
| 972 |
|
| 973 |
static void |
| 974 |
amgtar_selfcheck( |
| 975 |
application_argument_t *argument) |
| 976 |
{ |
| 977 |
char *option; |
| 978 |
messagelist_t mlist = NULL; |
| 979 |
messagelist_t mesglist = NULL; |
| 980 |
char *dirname; |
| 981 |
|
| 982 |
if (argument->dle.disk) { |
| 983 |
delete_message(amgtar_print_message(build_message( |
| 984 |
AMANDA_FILE, __LINE__, 3700000, MSG_INFO, 3, |
| 985 |
"disk", argument->dle.disk, |
| 986 |
"device", argument->dle.device, |
| 987 |
"hostname", argument->host))); |
| 988 |
} |
| 989 |
|
| 990 |
delete_message(amgtar_print_message(build_message( |
| 991 |
AMANDA_FILE, __LINE__, 3700001, MSG_INFO, 4, |
| 992 |
"version", VERSION, |
| 993 |
"disk", argument->dle.disk, |
| 994 |
"device", argument->dle.device, |
| 995 |
"hostname", argument->host))); |
| 996 |
|
| 997 |
if (gnutar_target) { |
| 998 |
dirname = gnutar_target; |
| 999 |
} else { |
| 1000 |
dirname = argument->dle.device; |
| 1001 |
} |
| 1002 |
|
| 1003 |
amgtar_build_exinclude(&argument->dle, NULL, NULL, NULL, NULL, |
| 1004 |
dirname, &mlist); |
| 1005 |
for (mesglist = mlist; mesglist != NULL; mesglist = mesglist->next){ |
| 1006 |
message_t *message = mesglist->data; |
| 1007 |
if (message_get_severity(message) > MSG_INFO) |
| 1008 |
amgtar_print_message(message); |
| 1009 |
delete_message(message); |
| 1010 |
} |
| 1011 |
g_slist_free(mlist); |
| 1012 |
|
| 1013 |
delete_message(amgtar_print_message(build_message( |
| 1014 |
AMANDA_FILE, __LINE__, 3700004, MSG_INFO, 3, |
| 1015 |
"disk", argument->dle.disk, |
| 1016 |
"device", argument->dle.device, |
| 1017 |
"hostname", argument->host))); |
| 1018 |
|
| 1019 |
if ((option = validate_command_options(argument))) { |
| 1020 |
delete_message(amgtar_print_message(build_message( |
| 1021 |
AMANDA_FILE, __LINE__, 3700014, MSG_ERROR, 4, |
| 1022 |
"disk", argument->dle.disk, |
| 1023 |
"device", argument->dle.device, |
| 1024 |
"hostname", argument->host, |
| 1025 |
"command-options", option))); |
| 1026 |
} |
| 1027 |
|
| 1028 |
if (gnutar_path) { |
| 1029 |
char *gnutar_realpath = NULL; |
| 1030 |
message_t *message; |
| 1031 |
if ((message = check_exec_for_suid_message("GNUTAR_PATH", gnutar_path, &gnutar_realpath))) { |
| 1032 |
delete_message(amgtar_print_message(message)); |
| 1033 |
} else { |
| 1034 |
message = amgtar_print_message(check_file_message(gnutar_path, X_OK)); |
| 1035 |
if (message && message_get_severity(message) <= MSG_INFO) { |
| 1036 |
char *gtar_version; |
| 1037 |
GPtrArray *argv_ptr = g_ptr_array_new(); |
| 1038 |
|
| 1039 |
g_ptr_array_add(argv_ptr, gnutar_path); |
| 1040 |
g_ptr_array_add(argv_ptr, "--version"); |
| 1041 |
g_ptr_array_add(argv_ptr, NULL); |
| 1042 |
|
| 1043 |
gtar_version = get_first_line(argv_ptr); |
| 1044 |
if (gtar_version) { |
| 1045 |
char *gv; |
| 1046 |
for (gv = gtar_version; *gv && !g_ascii_isdigit(*gv); gv++); |
| 1047 |
delete_message(amgtar_print_message(build_message( |
| 1048 |
AMANDA_FILE, __LINE__, 3700002, MSG_INFO, 4, |
| 1049 |
"gtar-version", gv, |
| 1050 |
"disk", argument->dle.disk, |
| 1051 |
"device", argument->dle.device, |
| 1052 |
"hostname", argument->host))); |
| 1053 |
} else { |
| 1054 |
delete_message(amgtar_print_message(build_message( |
| 1055 |
AMANDA_FILE, __LINE__, 3700003, MSG_ERROR, 4, |
| 1056 |
"gtar-path", gnutar_path, |
| 1057 |
"disk", argument->dle.disk, |
| 1058 |
"device", argument->dle.device, |
| 1059 |
"hostname", argument->host))); |
| 1060 |
} |
| 1061 |
|
| 1062 |
g_ptr_array_free(argv_ptr, TRUE); |
| 1063 |
amfree(gtar_version); |
| 1064 |
} |
| 1065 |
if (message) |
| 1066 |
delete_message(message); |
| 1067 |
} |
| 1068 |
if (gnutar_realpath) g_free(gnutar_realpath); |
| 1069 |
} else { |
| 1070 |
delete_message(amgtar_print_message(build_message( |
| 1071 |
AMANDA_FILE, __LINE__, 3700005, MSG_ERROR, 3, |
| 1072 |
"disk", argument->dle.disk, |
| 1073 |
"device", argument->dle.device, |
| 1074 |
"hostname", argument->host))); |
| 1075 |
} |
| 1076 |
if (gnutar_listdir && strlen(gnutar_listdir) == 0) |
| 1077 |
gnutar_listdir = NULL; |
| 1078 |
if (gnutar_listdir) { |
| 1079 |
delete_message(amgtar_print_message(check_dir_message(gnutar_listdir, R_OK|W_OK))); |
| 1080 |
} else { |
| 1081 |
delete_message(amgtar_print_message(build_message( |
| 1082 |
AMANDA_FILE, __LINE__, 3700006, MSG_ERROR, 3, |
| 1083 |
"disk", argument->dle.disk, |
| 1084 |
"device", argument->dle.device, |
| 1085 |
"hostname", argument->host))); |
| 1086 |
} |
| 1087 |
|
| 1088 |
set_root_privs(1); |
| 1089 |
if (gnutar_target) { |
| 1090 |
delete_message(amgtar_print_message(check_dir_message(gnutar_target, R_OK))); |
| 1091 |
} else if (argument->dle.device) { |
| 1092 |
delete_message(amgtar_print_message(check_dir_message(argument->dle.device, R_OK))); |
| 1093 |
} |
| 1094 |
if (argument->calcsize) { |
| 1095 |
char *calcsize = g_strjoin(NULL, amlibexecdir, "/", "calcsize", NULL); |
| 1096 |
delete_message(amgtar_print_message(check_file_message(calcsize, X_OK))); |
| 1097 |
delete_message(amgtar_print_message(check_suid_message(calcsize))); |
| 1098 |
amfree(calcsize); |
| 1099 |
} |
| 1100 |
set_root_privs(0); |
| 1101 |
} |
| 1102 |
|
| 1103 |
static void |
| 1104 |
amgtar_estimate( |
| 1105 |
application_argument_t *argument) |
| 1106 |
{ |
| 1107 |
char *incrname = NULL; |
| 1108 |
GPtrArray *argv_ptr; |
| 1109 |
int nullfd = -1; |
| 1110 |
int pipefd = -1; |
| 1111 |
FILE *dumpout = NULL; |
| 1112 |
off_t size = -1; |
| 1113 |
char line[32768]; |
| 1114 |
char *errmsg = NULL; |
| 1115 |
char *qerrmsg = NULL; |
| 1116 |
char *qdisk = NULL; |
| 1117 |
amwait_t wait_status; |
| 1118 |
int tarpid; |
| 1119 |
amregex_t *rp; |
| 1120 |
times_t start_time; |
| 1121 |
int level; |
| 1122 |
GSList *levels; |
| 1123 |
char *file_exclude = NULL; |
| 1124 |
char *file_include = NULL; |
| 1125 |
GString *strbuf; |
| 1126 |
char *option; |
| 1127 |
char *gnutar_realpath = NULL; |
| 1128 |
message_t *message; |
| 1129 |
|
| 1130 |
if (!argument->level) { |
| 1131 |
fprintf(stderr, "ERROR No level argument\n"); |
| 1132 |
error(_("No level argument")); |
| 1133 |
} |
| 1134 |
if (!argument->dle.disk) { |
| 1135 |
fprintf(stderr, "ERROR No disk argument\n"); |
| 1136 |
error(_("No disk argument")); |
| 1137 |
} |
| 1138 |
if (!argument->dle.device) { |
| 1139 |
fprintf(stderr, "ERROR No device argument\n"); |
| 1140 |
error(_("No device argument")); |
| 1141 |
} |
| 1142 |
|
| 1143 |
if ((option = validate_command_options(argument))) { |
| 1144 |
fprintf(stderr, "ERROR Invalid '%s' COMMAND-OPTIONS\n", option); |
| 1145 |
error("Invalid '%s' COMMAND-OPTIONS", option); |
| 1146 |
} |
| 1147 |
|
| 1148 |
if (argument->calcsize) { |
| 1149 |
char *dirname; |
| 1150 |
int nb_exclude; |
| 1151 |
int nb_include; |
| 1152 |
messagelist_t mlist = NULL; |
| 1153 |
messagelist_t mesglist = NULL; |
| 1154 |
|
| 1155 |
if (gnutar_target) { |
| 1156 |
dirname = gnutar_target; |
| 1157 |
} else { |
| 1158 |
dirname = argument->dle.device; |
| 1159 |
} |
| 1160 |
|
| 1161 |
amgtar_build_exinclude(&argument->dle, |
| 1162 |
&nb_exclude, &file_exclude, |
| 1163 |
&nb_include, &file_include, dirname, &mlist); |
| 1164 |
for (mesglist = mlist; mesglist != NULL; mesglist = mesglist->next){ |
| 1165 |
message_t *message = mesglist->data; |
| 1166 |
if (message_get_severity(message) > MSG_INFO) |
| 1167 |
fprintf(stdout, "ERROR %s\n", get_message(message)); |
| 1168 |
delete_message(message); |
| 1169 |
} |
| 1170 |
g_slist_free(mlist); |
| 1171 |
mlist = NULL; |
| 1172 |
|
| 1173 |
run_calcsize(argument->config, "GNUTAR", argument->dle.disk, dirname, |
| 1174 |
argument->level, file_exclude, file_include); |
| 1175 |
|
| 1176 |
if (argument->verbose == 0) { |
| 1177 |
if (file_exclude) |
| 1178 |
unlink(file_exclude); |
| 1179 |
if (file_include) |
| 1180 |
unlink(file_include); |
| 1181 |
} |
| 1182 |
amfree(file_exclude); |
| 1183 |
amfree(file_include); |
| 1184 |
return; |
| 1185 |
} |
| 1186 |
|
| 1187 |
if (!gnutar_path) { |
| 1188 |
errmsg = g_strdup(_("GNUTAR-PATH not defined")); |
| 1189 |
goto common_error; |
| 1190 |
} |
| 1191 |
|
| 1192 |
if (!gnutar_listdir) { |
| 1193 |
errmsg = g_strdup(_("GNUTAR-LISTDIR not defined")); |
| 1194 |
goto common_error; |
| 1195 |
} |
| 1196 |
|
| 1197 |
if ((message = check_exec_for_suid_message("GNUTAR_PATH", gnutar_path, &gnutar_realpath))) { |
| 1198 |
errmsg = g_strdup(get_message(message)); |
| 1199 |
delete_message(message); |
| 1200 |
goto common_error; |
| 1201 |
} |
| 1202 |
|
| 1203 |
qdisk = quote_string(argument->dle.disk); |
| 1204 |
for (levels = argument->level; levels != NULL; levels = levels->next) { |
| 1205 |
messagelist_t mlist = NULL; |
| 1206 |
messagelist_t mesglist = NULL; |
| 1207 |
level = GPOINTER_TO_INT(levels->data); |
| 1208 |
incrname = amgtar_get_incrname(argument, level, stdout, CMD_ESTIMATE); |
| 1209 |
argv_ptr = amgtar_build_argv(gnutar_realpath, |
| 1210 |
argument, incrname, &file_exclude, |
| 1211 |
&file_include, CMD_ESTIMATE, &mlist); |
| 1212 |
for (mesglist = mlist; mesglist != NULL; mesglist = mesglist->next){ |
| 1213 |
message_t *message = mesglist->data; |
| 1214 |
if (message_get_severity(message) > MSG_INFO) |
| 1215 |
fprintf(stdout, "ERROR %s\n", get_message(message)); |
| 1216 |
delete_message(message); |
| 1217 |
} |
| 1218 |
g_slist_free(mlist); |
| 1219 |
mlist = NULL; |
| 1220 |
|
| 1221 |
start_time = curclock(); |
| 1222 |
|
| 1223 |
if ((nullfd = open("/dev/null", O_RDWR)) == -1) { |
| 1224 |
errmsg = g_strdup_printf(_("Cannot access /dev/null : %s"), |
| 1225 |
strerror(errno)); |
| 1226 |
goto common_exit; |
| 1227 |
} |
| 1228 |
|
| 1229 |
tarpid = pipespawnv(gnutar_realpath, STDERR_PIPE, 1, |
| 1230 |
&nullfd, &nullfd, &pipefd, |
| 1231 |
(char **)argv_ptr->pdata); |
| 1232 |
|
| 1233 |
dumpout = fdopen(pipefd,"r"); |
| 1234 |
if (!dumpout) { |
| 1235 |
error(_("Can't fdopen: %s"), strerror(errno)); |
| 1236 |
/*NOTREACHED*/ |
| 1237 |
} |
| 1238 |
|
| 1239 |
size = (off_t)-1; |
| 1240 |
while (size < 0 && (fgets(line, sizeof(line), dumpout) != NULL)) { |
| 1241 |
if (strlen(line) > 0 && line[strlen(line)-1] == '\n') { |
| 1242 |
/* remove trailling \n */ |
| 1243 |
line[strlen(line)-1] = '\0'; |
| 1244 |
} |
| 1245 |
if (line[0] == '\0') |
| 1246 |
continue; |
| 1247 |
dbprintf("%s\n", line); |
| 1248 |
/* check for size match */ |
| 1249 |
/*@ignore@*/ |
| 1250 |
for(rp = re_table; rp->regex != NULL; rp++) { |
| 1251 |
if(match(rp->regex, line)) { |
| 1252 |
if (rp->typ == DMP_SIZE) { |
| 1253 |
size = ((the_num(line, rp->field)*rp->scale+1023.0)/1024.0); |
| 1254 |
if(size < 0.0) |
| 1255 |
size = 1.0; /* found on NeXT -- sigh */ |
| 1256 |
} |
| 1257 |
break; |
| 1258 |
} |
| 1259 |
} |
| 1260 |
/*@end@*/ |
| 1261 |
} |
| 1262 |
|
| 1263 |
while (fgets(line, sizeof(line), dumpout) != NULL) { |
| 1264 |
dbprintf("%s", line); |
| 1265 |
} |
| 1266 |
|
| 1267 |
dbprintf(".....\n"); |
| 1268 |
dbprintf(_("estimate time for %s level %d: %s\n"), |
| 1269 |
qdisk, |
| 1270 |
level, |
| 1271 |
walltime_str(timessub(curclock(), start_time))); |
| 1272 |
if(size == (off_t)-1) { |
| 1273 |
errmsg = g_strdup_printf(_("no size line match in %s output"), gnutar_realpath); |
| 1274 |
dbprintf(_("%s for %s\n"), errmsg, qdisk); |
| 1275 |
dbprintf(".....\n"); |
| 1276 |
} else if(size == (off_t)0 && argument->level == 0) { |
| 1277 |
dbprintf(_("possible %s problem -- is \"%s\" really empty?\n"), |
| 1278 |
gnutar_realpath, argument->dle.disk); |
| 1279 |
dbprintf(".....\n"); |
| 1280 |
} |
| 1281 |
dbprintf(_("estimate size for %s level %d: %lld KB\n"), |
| 1282 |
qdisk, |
| 1283 |
level, |
| 1284 |
(long long)size); |
| 1285 |
|
| 1286 |
(void)kill(-tarpid, SIGTERM); |
| 1287 |
|
| 1288 |
dbprintf(_("waiting for %s \"%s\" child\n"), gnutar_realpath, qdisk); |
| 1289 |
waitpid(tarpid, &wait_status, 0); |
| 1290 |
if (WIFSIGNALED(wait_status)) { |
| 1291 |
strbuf = g_string_new(errmsg); |
| 1292 |
g_string_append_printf(strbuf, "%s terminated with signal %d: see %s", |
| 1293 |
gnutar_realpath, WTERMSIG(wait_status), dbfn()); |
| 1294 |
g_free(errmsg); |
| 1295 |
errmsg = g_string_free(strbuf, FALSE); |
| 1296 |
} else if (WIFEXITED(wait_status)) { |
| 1297 |
if (exit_value[WEXITSTATUS(wait_status)] == 1) { |
| 1298 |
strbuf = g_string_new(errmsg); |
| 1299 |
g_string_append_printf(strbuf, "%s exited with status %d: see %s", |
| 1300 |
gnutar_realpath, WEXITSTATUS(wait_status), dbfn()); |
| 1301 |
g_free(errmsg); |
| 1302 |
errmsg = g_string_free(strbuf, FALSE); |
| 1303 |
} else { |
| 1304 |
/* Normal exit */ |
| 1305 |
} |
| 1306 |
} else { |
| 1307 |
errmsg = g_strdup_printf(_("%s got bad exit: see %s"), |
| 1308 |
gnutar_realpath, dbfn()); |
| 1309 |
} |
| 1310 |
dbprintf(_("after %s %s wait\n"), gnutar_realpath, qdisk); |
| 1311 |
|
| 1312 |
common_exit: |
| 1313 |
if (errmsg) { |
| 1314 |
dbprintf("%s", errmsg); |
| 1315 |
fprintf(stdout, "ERROR %s\n", errmsg); |
| 1316 |
amfree(errmsg); |
| 1317 |
} |
| 1318 |
|
| 1319 |
unlink(incrname); |
| 1320 |
|
| 1321 |
if (argument->verbose == 0) { |
| 1322 |
if (file_exclude) |
| 1323 |
unlink(file_exclude); |
| 1324 |
if (file_include) |
| 1325 |
unlink(file_include); |
| 1326 |
} |
| 1327 |
|
| 1328 |
g_ptr_array_free_full(argv_ptr); |
| 1329 |
amfree(incrname); |
| 1330 |
|
| 1331 |
aclose(nullfd); |
| 1332 |
afclose(dumpout); |
| 1333 |
|
| 1334 |
fprintf(stdout, "%d %lld 1\n", level, (long long)size); |
| 1335 |
} |
| 1336 |
amfree(qdisk); |
| 1337 |
amfree(file_exclude); |
| 1338 |
amfree(file_include); |
| 1339 |
amfree(errmsg); |
| 1340 |
amfree(qerrmsg); |
| 1341 |
amfree(incrname); |
| 1342 |
amfree(gnutar_realpath); |
| 1343 |
return; |
| 1344 |
|
| 1345 |
common_error: |
| 1346 |
qerrmsg = quote_string(errmsg); |
| 1347 |
amfree(qdisk); |
| 1348 |
dbprintf("%s", errmsg); |
| 1349 |
fprintf(stdout, "ERROR %s\n", qerrmsg); |
| 1350 |
amfree(file_exclude); |
| 1351 |
amfree(file_include); |
| 1352 |
amfree(errmsg); |
| 1353 |
amfree(qerrmsg); |
| 1354 |
amfree(incrname); |
| 1355 |
amfree(gnutar_realpath); |
| 1356 |
return; |
| 1357 |
} |
| 1358 |
|
| 1359 |
static void |
| 1360 |
amgtar_backup( |
| 1361 |
application_argument_t *argument) |
| 1362 |
{ |
| 1363 |
int dumpin; |
| 1364 |
char *qdisk; |
| 1365 |
char *incrname; |
| 1366 |
char line[32768]; |
| 1367 |
amregex_t *rp; |
| 1368 |
off_t dump_size = -1; |
| 1369 |
char *type; |
| 1370 |
char startchr; |
| 1371 |
int dataf = 1; |
| 1372 |
int indexf = 4; |
| 1373 |
int outf; |
| 1374 |
FILE *indexstream = NULL; |
| 1375 |
FILE *outstream; |
| 1376 |
char *errmsg = NULL; |
| 1377 |
amwait_t wait_status; |
| 1378 |
GPtrArray *argv_ptr; |
| 1379 |
int tarpid; |
| 1380 |
char *file_exclude; |
| 1381 |
char *file_include; |
| 1382 |
char *option; |
| 1383 |
char *gnutar_realpath = NULL; |
| 1384 |
messagelist_t mlist = NULL; |
| 1385 |
messagelist_t mesglist = NULL; |
| 1386 |
message_t *message; |
| 1387 |
|
| 1388 |
if (!gnutar_path) { |
| 1389 |
fprintf(mesgstream, "sendbackup:: error [GNUTAR-PATH not defined]\n"); |
| 1390 |
exit(1); |
| 1391 |
} |
| 1392 |
if (!gnutar_listdir) { |
| 1393 |
fprintf(mesgstream, "sendbackup:: error [GNUTAR-LISTDIR not defined]\n"); |
| 1394 |
exit(1); |
| 1395 |
} |
| 1396 |
|
| 1397 |
if (!argument->level) { |
| 1398 |
fprintf(mesgstream, "sendbackup:: error [No level argument]\n"); |
| 1399 |
exit(1); |
| 1400 |
} |
| 1401 |
if (!argument->dle.disk) { |
| 1402 |
fprintf(mesgstream, "sendbackup:: error [No disk argument]\n"); |
| 1403 |
exit(1); |
| 1404 |
} |
| 1405 |
if (!argument->dle.device) { |
| 1406 |
fprintf(mesgstream, "sendbackup:: error [No device argument]\n"); |
| 1407 |
exit(1); |
| 1408 |
} |
| 1409 |
|
| 1410 |
if ((message = check_exec_for_suid_message("GNUTAR_PATH", gnutar_path, &gnutar_realpath))) { |
| 1411 |
fprintf(mesgstream, "sendbackup: error [%s]\n", get_message(message)); |
| 1412 |
delete_message(message); |
| 1413 |
exit(1); |
| 1414 |
} |
| 1415 |
|
| 1416 |
if ((option = validate_command_options(argument))) { |
| 1417 |
fprintf(mesgstream, "? Invalid '%s' COMMAND-OPTIONS\n", option); |
| 1418 |
error("Invalid '%s' COMMAND-OPTIONS", option); |
| 1419 |
} |
| 1420 |
|
| 1421 |
qdisk = quote_string(argument->dle.disk); |
| 1422 |
|
| 1423 |
incrname = amgtar_get_incrname(argument, |
| 1424 |
GPOINTER_TO_INT(argument->level->data), |
| 1425 |
mesgstream, CMD_BACKUP); |
| 1426 |
argv_ptr = amgtar_build_argv(gnutar_realpath, |
| 1427 |
argument, incrname, &file_exclude, |
| 1428 |
&file_include, CMD_BACKUP, &mlist); |
| 1429 |
for (mesglist = mlist; mesglist != NULL; mesglist = mesglist->next){ |
| 1430 |
message_t *message = mesglist->data; |
| 1431 |
if (message_get_severity(message) <= MSG_INFO) { |
| 1432 |
fprintf(mesgstream, "| %s\n", get_message(message)); |
| 1433 |
} else { |
| 1434 |
fprintf(mesgstream, "? %s\n", get_message(message)); |
| 1435 |
} |
| 1436 |
delete_message(message); |
| 1437 |
} |
| 1438 |
g_slist_free(mlist); |
| 1439 |
|
| 1440 |
tarpid = pipespawnv(gnutar_realpath, STDIN_PIPE|STDERR_PIPE, 1, |
| 1441 |
&dumpin, &dataf, &outf, (char **)argv_ptr->pdata); |
| 1442 |
/* close the write ends of the pipes */ |
| 1443 |
|
| 1444 |
aclose(dumpin); |
| 1445 |
aclose(dataf); |
| 1446 |
if (argument->dle.create_index) { |
| 1447 |
indexstream = fdopen(indexf, "w"); |
| 1448 |
if (!indexstream) { |
| 1449 |
error(_("error indexstream(%d): %s\n"), indexf, strerror(errno)); |
| 1450 |
} |
| 1451 |
} |
| 1452 |
outstream = fdopen(outf, "r"); |
| 1453 |
if (!outstream) { |
| 1454 |
error(_("error outstream(%d): %s\n"), outf, strerror(errno)); |
| 1455 |
} |
| 1456 |
|
| 1457 |
while (fgets(line, sizeof(line), outstream) != NULL) { |
| 1458 |
if (strlen(line) > 0 && line[strlen(line)-1] == '\n') { |
| 1459 |
/* remove trailling \n */ |
| 1460 |
line[strlen(line)-1] = '\0'; |
| 1461 |
} |
| 1462 |
if (strncmp(line, "block ", 6) == 0) { /* filename */ |
| 1463 |
off_t block_no = g_ascii_strtoull(line+6, NULL, 0); |
| 1464 |
char *filename = strchr(line, ':'); |
| 1465 |
if (filename) { |
| 1466 |
filename += 2; |
| 1467 |
if (*filename == '.' && *(filename+1) == '/') { |
| 1468 |
if (argument->dle.create_index) { |
| 1469 |
fprintf(indexstream, "%s\n", &filename[1]); /* remove . */ |
| 1470 |
} |
| 1471 |
if (argument->state_stream != -1) { |
| 1472 |
char *s = g_strdup_printf("%lld %s\n", |
| 1473 |
(long long)block_no, &filename[1]); |
| 1474 |
guint a = full_write(argument->state_stream, s, strlen(s)); |
| 1475 |
if (a < strlen(s)) { |
| 1476 |
g_debug("Failed to write to the state stream: %s", |
| 1477 |
strerror(errno)); |
| 1478 |
} |
| 1479 |
g_free(s); |
| 1480 |
} else if (argument->amfeatures && |
| 1481 |
am_has_feature(argument->amfeatures, |
| 1482 |
fe_sendbackup_state)) { |
| 1483 |
fprintf(mesgstream, "sendbackup: state %lld %s\n", |
| 1484 |
(long long)block_no, &filename[1]); |
| 1485 |
} |
| 1486 |
} |
| 1487 |
} |
| 1488 |
} else { /* message */ |
| 1489 |
for(rp = re_table; rp->regex != NULL; rp++) { |
| 1490 |
if(match(rp->regex, line)) { |
| 1491 |
break; |
| 1492 |
} |
| 1493 |
} |
| 1494 |
if(rp->typ == DMP_SIZE) { |
| 1495 |
dump_size = (off_t)((the_num(line, rp->field)* rp->scale+1023.0)/1024.0); |
| 1496 |
} |
| 1497 |
switch(rp->typ) { |
| 1498 |
case DMP_NORMAL: |
| 1499 |
type = "normal"; |
| 1500 |
startchr = '|'; |
| 1501 |
break; |
| 1502 |
case DMP_IGNORE: |
| 1503 |
continue; |
| 1504 |
case DMP_STRANGE: |
| 1505 |
type = "strange"; |
| 1506 |
startchr = '?'; |
| 1507 |
break; |
| 1508 |
case DMP_SIZE: |
| 1509 |
type = "size"; |
| 1510 |
startchr = '|'; |
| 1511 |
break; |
| 1512 |
case DMP_ERROR: |
| 1513 |
type = "error"; |
| 1514 |
startchr = '?'; |
| 1515 |
break; |
| 1516 |
default: |
| 1517 |
type = "unknown"; |
| 1518 |
startchr = '!'; |
| 1519 |
break; |
| 1520 |
} |
| 1521 |
dbprintf("%3d: %7s(%c): %s\n", rp->srcline, type, startchr, line); |
| 1522 |
fprintf(mesgstream,"%c %s\n", startchr, line); |
| 1523 |
} |
| 1524 |
} |
| 1525 |
fclose(outstream); |
| 1526 |
|
| 1527 |
waitpid(tarpid, &wait_status, 0); |
| 1528 |
if (WIFSIGNALED(wait_status)) { |
| 1529 |
errmsg = g_strdup_printf(_("%s terminated with signal %d: see %s"), |
| 1530 |
gnutar_realpath, WTERMSIG(wait_status), dbfn()); |
| 1531 |
} else if (WIFEXITED(wait_status)) { |
| 1532 |
if (exit_value[WEXITSTATUS(wait_status)] == 1) { |
| 1533 |
errmsg = g_strdup_printf(_("%s exited with status %d: see %s"), |
| 1534 |
gnutar_realpath, WEXITSTATUS(wait_status), dbfn()); |
| 1535 |
} else { |
| 1536 |
/* Normal exit */ |
| 1537 |
} |
| 1538 |
} else { |
| 1539 |
errmsg = g_strdup_printf(_("%s got bad exit: see %s"), |
| 1540 |
gnutar_realpath, dbfn()); |
| 1541 |
} |
| 1542 |
dbprintf(_("after %s %s wait\n"), gnutar_realpath, qdisk); |
| 1543 |
dbprintf(_("amgtar: %s: pid %ld\n"), gnutar_realpath, (long)tarpid); |
| 1544 |
if (errmsg) { |
| 1545 |
dbprintf("%s", errmsg); |
| 1546 |
g_fprintf(mesgstream, "sendbackup: error [%s]\n", errmsg); |
| 1547 |
} |
| 1548 |
|
| 1549 |
if (!errmsg && strlen(incrname) > 4) { |
| 1550 |
if (argument->dle.record) { |
| 1551 |
char *nodotnew; |
| 1552 |
nodotnew = g_strdup(incrname); |
| 1553 |
nodotnew[strlen(nodotnew)-4] = '\0'; |
| 1554 |
if (rename(incrname, nodotnew)) { |
| 1555 |
dbprintf(_("%s: warning [renaming %s to %s: %s]\n"), |
| 1556 |
get_pname(), incrname, nodotnew, strerror(errno)); |
| 1557 |
g_fprintf(mesgstream, _("? warning [renaming %s to %s: %s]\n"), |
| 1558 |
incrname, nodotnew, strerror(errno)); |
| 1559 |
} |
| 1560 |
amfree(nodotnew); |
| 1561 |
} else { |
| 1562 |
if (unlink(incrname) == -1) { |
| 1563 |
dbprintf(_("%s: warning [unlink %s: %s]\n"), |
| 1564 |
get_pname(), incrname, strerror(errno)); |
| 1565 |
g_fprintf(mesgstream, _("? warning [unlink %s: %s]\n"), |
| 1566 |
incrname, strerror(errno)); |
| 1567 |
} |
| 1568 |
} |
| 1569 |
} |
| 1570 |
|
| 1571 |
dbprintf("sendbackup: size %lld\n", (long long)dump_size); |
| 1572 |
fprintf(mesgstream, "sendbackup: size %lld\n", (long long)dump_size); |
| 1573 |
|
| 1574 |
if (argument->dle.create_index) |
| 1575 |
fclose(indexstream); |
| 1576 |
|
| 1577 |
fclose(mesgstream); |
| 1578 |
|
| 1579 |
if (argument->verbose == 0) { |
| 1580 |
if (file_exclude) |
| 1581 |
unlink(file_exclude); |
| 1582 |
if (file_include) |
| 1583 |
unlink(file_include); |
| 1584 |
} |
| 1585 |
|
| 1586 |
amfree(file_exclude); |
| 1587 |
amfree(file_include); |
| 1588 |
amfree(incrname); |
| 1589 |
amfree(qdisk); |
| 1590 |
amfree(errmsg); |
| 1591 |
amfree(gnutar_realpath); |
| 1592 |
g_ptr_array_free_full(argv_ptr); |
| 1593 |
} |
| 1594 |
|
| 1595 |
static void |
| 1596 |
amgtar_restore( |
| 1597 |
application_argument_t *argument) |
| 1598 |
{ |
| 1599 |
GPtrArray *argv_ptr = g_ptr_array_new(); |
| 1600 |
GPtrArray *include_array = g_ptr_array_new(); |
| 1601 |
char **env; |
| 1602 |
int j; |
| 1603 |
char *e; |
| 1604 |
char *include_filename = NULL; |
| 1605 |
char *exclude_filename = NULL; |
| 1606 |
int tarpid; |
| 1607 |
amwait_t wait_status; |
| 1608 |
int exit_status = 0; |
| 1609 |
char *errmsg = NULL; |
| 1610 |
FILE *dar_file; |
| 1611 |
char *gnutar_realpath = NULL; |
| 1612 |
|
| 1613 |
if (!gnutar_path) { |
| 1614 |
error(_("GNUTAR-PATH not defined")); |
| 1615 |
} |
| 1616 |
|
| 1617 |
if (!check_exec_for_suid("GNUTAR_PATH", gnutar_path, NULL, &gnutar_realpath)) { |
| 1618 |
error("'%s' binary is not secure", gnutar_path); |
| 1619 |
} |
| 1620 |
|
| 1621 |
if (!security_allow_to_restore()) { |
| 1622 |
error("The user is not allowed to restore files"); |
| 1623 |
} |
| 1624 |
|
| 1625 |
g_ptr_array_add(argv_ptr, g_strdup(gnutar_realpath)); |
| 1626 |
g_ptr_array_add(argv_ptr, g_strdup("--numeric-owner")); |
| 1627 |
if (gnutar_no_unquote) |
| 1628 |
g_ptr_array_add(argv_ptr, g_strdup("--no-unquote")); |
| 1629 |
if (gnutar_acls) |
| 1630 |
g_ptr_array_add(argv_ptr, g_strdup("--acls")); |
| 1631 |
if (gnutar_selinux) |
| 1632 |
g_ptr_array_add(argv_ptr, g_strdup("--selinux")); |
| 1633 |
if (gnutar_xattrs) |
| 1634 |
g_ptr_array_add(argv_ptr, g_strdup("--xattrs")); |
| 1635 |
/* ignore trailing zero blocks on input (this was the default until tar-1.21) */ |
| 1636 |
if (argument->ignore_zeros) { |
| 1637 |
g_ptr_array_add(argv_ptr, g_strdup("--ignore-zeros")); |
| 1638 |
} |
| 1639 |
if (argument->tar_blocksize) { |
| 1640 |
g_ptr_array_add(argv_ptr, g_strdup("--blocking-factor")); |
| 1641 |
g_ptr_array_add(argv_ptr, g_strdup(argument->tar_blocksize)); |
| 1642 |
} |
| 1643 |
g_ptr_array_add(argv_ptr, g_strdup("-xpGvf")); |
| 1644 |
g_ptr_array_add(argv_ptr, g_strdup("-")); |
| 1645 |
if (gnutar_target) { |
| 1646 |
struct stat stat_buf; |
| 1647 |
if(stat(gnutar_target, &stat_buf) != 0) { |
| 1648 |
fprintf(stderr, "can not stat directory %s: %s\n", |
| 1649 |
gnutar_target, strerror(errno)); |
| 1650 |
exit(1); |
| 1651 |
} |
| 1652 |
if (!S_ISDIR(stat_buf.st_mode)) { |
| 1653 |
fprintf(stderr,"%s is not a directory\n", gnutar_target); |
| 1654 |
exit(1); |
| 1655 |
} |
| 1656 |
if (access(gnutar_target, W_OK) != 0) { |
| 1657 |
fprintf(stderr, "Can't write to %s: %s\n", |
| 1658 |
gnutar_target, strerror(errno)); |
| 1659 |
exit(1); |
| 1660 |
} |
| 1661 |
g_ptr_array_add(argv_ptr, g_strdup("--directory")); |
| 1662 |
g_ptr_array_add(argv_ptr, g_strdup(gnutar_target)); |
| 1663 |
} |
| 1664 |
|
| 1665 |
g_ptr_array_add(argv_ptr, g_strdup("--wildcards")); |
| 1666 |
if (argument->dle.exclude_list && |
| 1667 |
argument->dle.exclude_list->nb_element == 1) { |
| 1668 |
FILE *exclude; |
| 1669 |
char *sdisk; |
| 1670 |
int in_argv; |
| 1671 |
int entry_in_exclude = 0; |
| 1672 |
char line[2*PATH_MAX]; |
| 1673 |
FILE *exclude_list; |
| 1674 |
|
| 1675 |
if (argument->dle.disk) { |
| 1676 |
sdisk = sanitise_filename(argument->dle.disk); |
| 1677 |
} else { |
| 1678 |
sdisk = g_strdup_printf("no_dle-%d", (int)getpid()); |
| 1679 |
} |
| 1680 |
exclude_filename= g_strjoin(NULL, AMANDA_TMPDIR, "/", "exclude-", |
| 1681 |
sdisk, NULL); |
| 1682 |
exclude_list = fopen(argument->dle.exclude_list->first->name, "r"); |
| 1683 |
if (!exclude_list) { |
| 1684 |
fprintf(stderr, "Cannot open exclude file '%s': %s\n", |
| 1685 |
argument->dle.exclude_list->first->name, strerror(errno)); |
| 1686 |
error("Cannot open exclude file '%s': %s\n", |
| 1687 |
argument->dle.exclude_list->first->name, strerror(errno)); |
| 1688 |
/*NOTREACHED*/ |
| 1689 |
} |
| 1690 |
exclude = fopen(exclude_filename, "w"); |
| 1691 |
if (!exclude) { |
| 1692 |
fprintf(stderr, "Cannot open exclude file '%s': %s\n", |
| 1693 |
exclude_filename, strerror(errno)); |
| 1694 |
fclose(exclude_list); |
| 1695 |
error("Cannot open exclude file '%s': %s\n", |
| 1696 |
exclude_filename, strerror(errno)); |
| 1697 |
/*NOTREACHED*/ |
| 1698 |
} |
| 1699 |
while (fgets(line, 2*PATH_MAX, exclude_list)) { |
| 1700 |
char *escaped; |
| 1701 |
line[strlen(line)-1] = '\0'; /* remove '\n' */ |
| 1702 |
escaped = escape_tar_glob(line, &in_argv); |
| 1703 |
if (in_argv) { |
| 1704 |
g_ptr_array_add(argv_ptr, "--exclude"); |
| 1705 |
g_ptr_array_add(argv_ptr, escaped); |
| 1706 |
} else { |
| 1707 |
fprintf(exclude,"%s\n", escaped); |
| 1708 |
entry_in_exclude++; |
| 1709 |
amfree(escaped); |
| 1710 |
} |
| 1711 |
} |
| 1712 |
fclose(exclude_list); |
| 1713 |
fclose(exclude); |
| 1714 |
g_ptr_array_add(argv_ptr, g_strdup("--exclude-from")); |
| 1715 |
g_ptr_array_add(argv_ptr, exclude_filename); |
| 1716 |
} |
| 1717 |
|
| 1718 |
if (argument->exclude_list_glob) { |
| 1719 |
g_ptr_array_add(argv_ptr, g_strdup("--exclude-from")); |
| 1720 |
g_ptr_array_add(argv_ptr, g_strdup(argument->exclude_list_glob)); |
| 1721 |
} |
| 1722 |
|
| 1723 |
{ |
| 1724 |
GPtrArray *argv_include = g_ptr_array_new(); |
| 1725 |
FILE *include; |
| 1726 |
char *sdisk; |
| 1727 |
int in_argv; |
| 1728 |
guint i; |
| 1729 |
int entry_in_include = 0; |
| 1730 |
|
| 1731 |
if (argument->dle.disk) { |
| 1732 |
sdisk = sanitise_filename(argument->dle.disk); |
| 1733 |
} else { |
| 1734 |
sdisk = g_strdup_printf("no_dle-%d", (int)getpid()); |
| 1735 |
} |
| 1736 |
include_filename = g_strjoin(NULL, AMANDA_TMPDIR, "/", "include-", sdisk, NULL); |
| 1737 |
include = fopen(include_filename, "w"); |
| 1738 |
if (!include) { |
| 1739 |
fprintf(stderr, "Cannot open include file '%s': %s\n", |
| 1740 |
include_filename, strerror(errno)); |
| 1741 |
error("Cannot open include file '%s': %s\n", |
| 1742 |
include_filename, strerror(errno)); |
| 1743 |
/*NOTREACHED*/ |
| 1744 |
} |
| 1745 |
if (argument->dle.include_list && |
| 1746 |
argument->dle.include_list->nb_element == 1) { |
| 1747 |
char line[2*PATH_MAX]; |
| 1748 |
FILE *include_list = fopen(argument->dle.include_list->first->name, "r"); |
| 1749 |
if (!include_list) { |
| 1750 |
fclose(include); |
| 1751 |
fprintf(stderr, "Cannot open include file '%s': %s\n", |
| 1752 |
argument->dle.include_list->first->name, |
| 1753 |
strerror(errno)); |
| 1754 |
error("Cannot open include file '%s': %s\n", |
| 1755 |
argument->dle.include_list->first->name, |
| 1756 |
strerror(errno)); |
| 1757 |
/*NOTREACHED*/ |
| 1758 |
} |
| 1759 |
while (fgets(line, 2*PATH_MAX, include_list)) { |
| 1760 |
char *escaped; |
| 1761 |
line[strlen(line)-1] = '\0'; /* remove '\n' */ |
| 1762 |
escaped = escape_tar_glob(line, &in_argv); |
| 1763 |
g_ptr_array_add(include_array, g_strdup(line)); |
| 1764 |
if (in_argv) { |
| 1765 |
g_ptr_array_add(argv_include, escaped); |
| 1766 |
} else { |
| 1767 |
fprintf(include,"%s\n", escaped); |
| 1768 |
entry_in_include++; |
| 1769 |
amfree(escaped); |
| 1770 |
} |
| 1771 |
} |
| 1772 |
fclose(include_list); |
| 1773 |
} |
| 1774 |
|
| 1775 |
if (argument->dle.include_file) { |
| 1776 |
sle_t *slif; |
| 1777 |
|
| 1778 |
for (slif = argument->dle.include_file->first; slif != NULL; slif = slif->next) { |
| 1779 |
char *escaped = escape_tar_glob(slif->name, &in_argv); |
| 1780 |
g_ptr_array_add(include_array, slif->name); |
| 1781 |
if (in_argv) { |
| 1782 |
g_ptr_array_add(argv_include, escaped); |
| 1783 |
} else { |
| 1784 |
fprintf(include,"%s\n", escaped); |
| 1785 |
entry_in_include++; |
| 1786 |
amfree(escaped); |
| 1787 |
} |
| 1788 |
} |
| 1789 |
} |
| 1790 |
|
| 1791 |
for (j=1; j< argument->argc; j++) { |
| 1792 |
char *escaped = escape_tar_glob(argument->argv[j], &in_argv); |
| 1793 |
g_ptr_array_add(include_array, argument->argv[j]); |
| 1794 |
if (in_argv) { |
| 1795 |
g_ptr_array_add(argv_include, escaped); |
| 1796 |
} else { |
| 1797 |
fprintf(include,"%s\n", escaped); |
| 1798 |
entry_in_include++; |
| 1799 |
amfree(escaped); |
| 1800 |
} |
| 1801 |
} |
| 1802 |
fclose(include); |
| 1803 |
|
| 1804 |
if (entry_in_include) { |
| 1805 |
g_ptr_array_add(argv_ptr, g_strdup("--files-from")); |
| 1806 |
g_ptr_array_add(argv_ptr, include_filename); |
| 1807 |
} |
| 1808 |
|
| 1809 |
if (argument->include_list_glob) { |
| 1810 |
g_ptr_array_add(argv_ptr, g_strdup("--files-from")); |
| 1811 |
g_ptr_array_add(argv_ptr, g_strdup(argument->include_list_glob)); |
| 1812 |
} |
| 1813 |
|
| 1814 |
for (i = 0; i < argv_include->len; i++) { |
| 1815 |
g_ptr_array_add(argv_ptr, (char *)g_ptr_array_index(argv_include,i)); |
| 1816 |
} |
| 1817 |
amfree(sdisk); |
| 1818 |
} |
| 1819 |
g_ptr_array_add(argv_ptr, NULL); |
| 1820 |
|
| 1821 |
if (argument->dar) { |
| 1822 |
int dar_fd = argument->state_stream; |
| 1823 |
if (dar_fd == -1) dar_fd = 3; |
| 1824 |
dar_file = fdopen(dar_fd, "w"); |
| 1825 |
if (!dar_file) { |
| 1826 |
int save_errno = errno; |
| 1827 |
fprintf(stderr, "Can't fdopen the DAR file (fd %d): %s\n", |
| 1828 |
dar_fd, strerror(save_errno)); |
| 1829 |
g_debug("Can't fdopen the DAR file (fd %d): %s", |
| 1830 |
dar_fd, strerror(save_errno)); |
| 1831 |
exit(1); |
| 1832 |
} |
| 1833 |
if (argument->recover_dump_state_file && |
| 1834 |
include_array->len > 0) { |
| 1835 |
char line[32768]; |
| 1836 |
FILE *recover_state_file = fopen(argument->recover_dump_state_file, |
| 1837 |
"r"); |
| 1838 |
if (!recover_state_file) { |
| 1839 |
fprintf(dar_file,"DAR 0:-1\n"); |
| 1840 |
g_debug("full dar: 0:-1"); |
| 1841 |
} else { |
| 1842 |
int previous_block = -1; |
| 1843 |
|
| 1844 |
while (fgets(line, 32768, recover_state_file) != NULL) { |
| 1845 |
off_t block_no = g_ascii_strtoull(line, NULL, 0); |
| 1846 |
gboolean match = FALSE; |
| 1847 |
char *filename = strchr(line, ' '); |
| 1848 |
char *ii; |
| 1849 |
guint i; |
| 1850 |
|
| 1851 |
if (!filename) |
| 1852 |
continue; |
| 1853 |
|
| 1854 |
filename++; |
| 1855 |
if (filename[strlen(filename)-1] == '\n') |
| 1856 |
filename[strlen(filename)-1] = '\0'; |
| 1857 |
|
| 1858 |
g_debug("recover_dump_state_file: %lld %s", |
| 1859 |
(long long)block_no, filename); |
| 1860 |
for (i = 0; i < include_array->len; i++) { |
| 1861 |
size_t strlenii; |
| 1862 |
|
| 1863 |
ii = g_ptr_array_index(include_array, i); |
| 1864 |
ii++; // remove leading '.' |
| 1865 |
//g_debug("check %s : %s :", filename, ii); |
| 1866 |
strlenii = strlen(ii); |
| 1867 |
if (g_str_equal(filename, ii) == 1 || |
| 1868 |
(strlenii < strlen(filename) && |
| 1869 |
strncmp(filename, ii, strlenii) == 0 && |
| 1870 |
filename[strlenii] == '/')) { |
| 1871 |
//g_debug("match %s", ii); |
| 1872 |
match = TRUE; |
| 1873 |
break; |
| 1874 |
} |
| 1875 |
} |
| 1876 |
|
| 1877 |
if (match) { |
| 1878 |
if (previous_block < 0) |
| 1879 |
previous_block = block_no; |
| 1880 |
} else if (previous_block >= 0) { |
| 1881 |
g_debug("restore block %lld (%lld) to %lld (%lld)", |
| 1882 |
(long long)previous_block * 512, |
| 1883 |
(long long)previous_block, |
| 1884 |
(long long)block_no * 512 - 1, |
| 1885 |
(long long)block_no); |
| 1886 |
fprintf(dar_file, "DAR %lld:%lld\n", |
| 1887 |
(long long)previous_block * 512, |
| 1888 |
(long long)block_no * 512- 1); |
| 1889 |
previous_block = -1; |
| 1890 |
} |
| 1891 |
} |
| 1892 |
fclose(recover_state_file); |
| 1893 |
if (previous_block >= 0) { |
| 1894 |
g_debug("restore block %lld (%lld) to END", |
| 1895 |
(long long)previous_block * 512, |
| 1896 |
(long long)previous_block); |
| 1897 |
fprintf(dar_file, "DAR %lld:-1\n", |
| 1898 |
(long long)previous_block * 512); |
| 1899 |
} |
| 1900 |
} |
| 1901 |
} else { |
| 1902 |
fprintf(dar_file,"DAR 0:-1\n"); |
| 1903 |
g_debug("full dar: 0:-1"); |
| 1904 |
} |
| 1905 |
fflush(dar_file); |
| 1906 |
fclose(dar_file); |
| 1907 |
} |
| 1908 |
|
| 1909 |
debug_executing(argv_ptr); |
| 1910 |
|
| 1911 |
tarpid = fork(); |
| 1912 |
switch (tarpid) { |
| 1913 |
case -1: error(_("%s: fork returned: %s"), get_pname(), strerror(errno)); |
| 1914 |
case 0: |
| 1915 |
env = safe_env(); |
| 1916 |
become_root(); |
| 1917 |
execve(gnutar_realpath, (char **)argv_ptr->pdata, env); |
| 1918 |
free_env(env); |
| 1919 |
e = strerror(errno); |
| 1920 |
error(_("error [exec %s: %s]"), gnutar_realpath, e); |
| 1921 |
break; |
| 1922 |
default: break; |
| 1923 |
} |
| 1924 |
|
| 1925 |
waitpid(tarpid, &wait_status, 0); |
| 1926 |
if (WIFSIGNALED(wait_status)) { |
| 1927 |
errmsg = g_strdup_printf(_("%s terminated with signal %d: see %s"), |
| 1928 |
gnutar_realpath, WTERMSIG(wait_status), dbfn()); |
| 1929 |
exit_status = 1; |
| 1930 |
} else if (WIFEXITED(wait_status)) { |
| 1931 |
if (WEXITSTATUS(wait_status) > 0) { |
| 1932 |
errmsg = g_strdup_printf(_("%s exited with status %d: see %s"), |
| 1933 |
gnutar_realpath, WEXITSTATUS(wait_status), dbfn()); |
| 1934 |
exit_status = 1; |
| 1935 |
} else { |
| 1936 |
/* Normal exit */ |
| 1937 |
exit_status = 0; |
| 1938 |
} |
| 1939 |
} else { |
| 1940 |
errmsg = g_strdup_printf(_("%s got bad exit: see %s"), |
| 1941 |
gnutar_realpath, dbfn()); |
| 1942 |
exit_status = 1; |
| 1943 |
} |
| 1944 |
if (errmsg) { |
| 1945 |
dbprintf("%s", errmsg); |
| 1946 |
fprintf(stderr, "ERROR %s\n", errmsg); |
| 1947 |
amfree(errmsg); |
| 1948 |
} |
| 1949 |
|
| 1950 |
if (argument->verbose == 0) { |
| 1951 |
if (exclude_filename) |
| 1952 |
unlink(exclude_filename); |
| 1953 |
unlink(include_filename); |
| 1954 |
} |
| 1955 |
amfree(include_filename); |
| 1956 |
amfree(exclude_filename); |
| 1957 |
amfree(gnutar_realpath); |
| 1958 |
exit(exit_status); |
| 1959 |
} |
| 1960 |
|
| 1961 |
static void |
| 1962 |
amgtar_validate( |
| 1963 |
application_argument_t *argument G_GNUC_UNUSED) |
| 1964 |
{ |
| 1965 |
char *cmd = NULL; |
| 1966 |
GPtrArray *argv_ptr = g_ptr_array_new(); |
| 1967 |
char **env; |
| 1968 |
char *e; |
| 1969 |
char buf[32768]; |
| 1970 |
|
| 1971 |
if (!gnutar_path) { |
| 1972 |
dbprintf("GNUTAR-PATH not set; Piping to /dev/null\n"); |
| 1973 |
fprintf(stderr,"GNUTAR-PATH not set; Piping to /dev/null\n"); |
| 1974 |
goto pipe_to_null; |
| 1975 |
} |
| 1976 |
|
| 1977 |
cmd = g_strdup(gnutar_path); |
| 1978 |
g_ptr_array_add(argv_ptr, g_strdup(gnutar_path)); |
| 1979 |
/* ignore trailing zero blocks on input (this was the default until tar-1.21) */ |
| 1980 |
g_ptr_array_add(argv_ptr, g_strdup("--ignore-zeros")); |
| 1981 |
g_ptr_array_add(argv_ptr, g_strdup("-tf")); |
| 1982 |
g_ptr_array_add(argv_ptr, g_strdup("-")); |
| 1983 |
g_ptr_array_add(argv_ptr, NULL); |
| 1984 |
|
| 1985 |
debug_executing(argv_ptr); |
| 1986 |
env = safe_env(); |
| 1987 |
execve(cmd, (char **)argv_ptr->pdata, env); |
| 1988 |
e = strerror(errno); |
| 1989 |
dbprintf("failed to execute %s: %s; Piping to /dev/null\n", cmd, e); |
| 1990 |
fprintf(stderr,"failed to execute %s: %s; Piping to /dev/null\n", cmd, e); |
| 1991 |
free_env(env); |
| 1992 |
pipe_to_null: |
| 1993 |
while (read(0, buf, 32768) > 0) { |
| 1994 |
} |
| 1995 |
amfree(cmd); |
| 1996 |
} |
| 1997 |
|
| 1998 |
static void |
| 1999 |
amgtar_index( |
| 2000 |
application_argument_t *argument G_GNUC_UNUSED) |
| 2001 |
{ |
| 2002 |
char *cmd = NULL; |
| 2003 |
GPtrArray *argv_ptr = g_ptr_array_new(); |
| 2004 |
int datain = 0; |
| 2005 |
int indexf; |
| 2006 |
int errf = 2; |
| 2007 |
pid_t tarpid; |
| 2008 |
FILE *indexstream; |
| 2009 |
char line[32768]; |
| 2010 |
amwait_t wait_status; |
| 2011 |
char *errmsg = NULL; |
| 2012 |
|
| 2013 |
if (!gnutar_path) { |
| 2014 |
dbprintf("GNUTAR-PATH not set\n"); |
| 2015 |
fprintf(stderr,"GNUTAR-PATH not set\n"); |
| 2016 |
while (read(0, line, 32768) > 0) { |
| 2017 |
} |
| 2018 |
exit(1); |
| 2019 |
} |
| 2020 |
|
| 2021 |
cmd = g_strdup(gnutar_path); |
| 2022 |
g_ptr_array_add(argv_ptr, g_strdup(gnutar_path)); |
| 2023 |
/* ignore trailing zero blocks on input (this was the default until tar-1.21) */ |
| 2024 |
g_ptr_array_add(argv_ptr, g_strdup("--ignore-zeros")); |
| 2025 |
g_ptr_array_add(argv_ptr, g_strdup("-tf")); |
| 2026 |
g_ptr_array_add(argv_ptr, g_strdup("-")); |
| 2027 |
g_ptr_array_add(argv_ptr, NULL); |
| 2028 |
|
| 2029 |
tarpid = pipespawnv(cmd, STDOUT_PIPE, 0, |
| 2030 |
&datain, &indexf, &errf, (char **)argv_ptr->pdata); |
| 2031 |
aclose(datain); |
| 2032 |
|
| 2033 |
indexstream = fdopen(indexf, "r"); |
| 2034 |
if (!indexstream) { |
| 2035 |
error(_("error indexstream(%d): %s\n"), indexf, strerror(errno)); |
| 2036 |
} |
| 2037 |
|
| 2038 |
while (fgets(line, sizeof(line), indexstream) != NULL) { |
| 2039 |
if (strlen(line) > 0 && line[strlen(line)-1] == '\n') { |
| 2040 |
/* remove trailling \n */ |
| 2041 |
line[strlen(line)-1] = '\0'; |
| 2042 |
} |
| 2043 |
if (*line == '.' && *(line+1) == '/') { /* filename */ |
| 2044 |
fprintf(stdout, "%s\n", &line[1]); /* remove . */ |
| 2045 |
} |
| 2046 |
} |
| 2047 |
fclose(indexstream); |
| 2048 |
waitpid(tarpid, &wait_status, 0); |
| 2049 |
if (WIFSIGNALED(wait_status)) { |
| 2050 |
errmsg = g_strdup_printf(_("%s terminated with signal %d: see %s"), |
| 2051 |
cmd, WTERMSIG(wait_status), dbfn()); |
| 2052 |
} else if (WIFEXITED(wait_status)) { |
| 2053 |
if (exit_value[WEXITSTATUS(wait_status)] == 1) { |
| 2054 |
errmsg = g_strdup_printf(_("%s exited with status %d: see %s"), |
| 2055 |
cmd, WEXITSTATUS(wait_status), dbfn()); |
| 2056 |
} else { |
| 2057 |
/* Normal exit */ |
| 2058 |
} |
| 2059 |
} else { |
| 2060 |
errmsg = g_strdup_printf(_("%s got bad exit: see %s"), |
| 2061 |
cmd, dbfn()); |
| 2062 |
} |
| 2063 |
dbprintf(_("amgtar: %s: pid %ld\n"), cmd, (long)tarpid); |
| 2064 |
if (errmsg) { |
| 2065 |
dbprintf("%s", errmsg); |
| 2066 |
fprintf(stderr, "error [%s]\n", errmsg); |
| 2067 |
} |
| 2068 |
|
| 2069 |
amfree(cmd); |
| 2070 |
} |
| 2071 |
|
| 2072 |
static void |
| 2073 |
amgtar_build_exinclude( |
| 2074 |
dle_t *dle, |
| 2075 |
int *nb_exclude, |
| 2076 |
char **file_exclude, |
| 2077 |
int *nb_include, |
| 2078 |
char **file_include, |
| 2079 |
char *dirname, |
| 2080 |
messagelist_t *mlist) |
| 2081 |
{ |
| 2082 |
int n_exclude = 0; |
| 2083 |
int n_include = 0; |
| 2084 |
char *exclude = NULL; |
| 2085 |
char *include = NULL; |
| 2086 |
|
| 2087 |
if (dle->exclude_file) n_exclude += dle->exclude_file->nb_element; |
| 2088 |
if (dle->exclude_list) n_exclude += dle->exclude_list->nb_element; |
| 2089 |
if (dle->include_file) n_include += dle->include_file->nb_element; |
| 2090 |
if (dle->include_list) n_include += dle->include_list->nb_element; |
| 2091 |
|
| 2092 |
if (n_exclude > 0) exclude = build_exclude(dle, mlist); |
| 2093 |
if (n_include > 0) include = build_include(dle, dirname, mlist); |
| 2094 |
|
| 2095 |
if (nb_exclude) |
| 2096 |
*nb_exclude = n_exclude; |
| 2097 |
if (file_exclude) |
| 2098 |
*file_exclude = exclude; |
| 2099 |
else |
| 2100 |
amfree(exclude); |
| 2101 |
|
| 2102 |
if (nb_include) |
| 2103 |
*nb_include = n_include; |
| 2104 |
if (file_include) |
| 2105 |
*file_include = include; |
| 2106 |
else |
| 2107 |
amfree(include); |
| 2108 |
} |
| 2109 |
|
| 2110 |
static char * |
| 2111 |
amgtar_get_incrname( |
| 2112 |
application_argument_t *argument, |
| 2113 |
int level, |
| 2114 |
FILE *mesgstream, |
| 2115 |
int command) |
| 2116 |
{ |
| 2117 |
char *basename = NULL; |
| 2118 |
char *incrname = NULL; |
| 2119 |
int infd, outfd; |
| 2120 |
ssize_t nb; |
| 2121 |
char *inputname = NULL; |
| 2122 |
char *errmsg = NULL; |
| 2123 |
char *buf; |
| 2124 |
|
| 2125 |
if (gnutar_listdir) { |
| 2126 |
char number[NUM_STR_SIZE]; |
| 2127 |
int baselevel; |
| 2128 |
char *sdisk = sanitise_filename(argument->dle.disk); |
| 2129 |
|
| 2130 |
basename = g_strjoin(NULL, gnutar_listdir, |
| 2131 |
"/", |
| 2132 |
argument->host, |
| 2133 |
sdisk, |
| 2134 |
NULL); |
| 2135 |
amfree(sdisk); |
| 2136 |
|
| 2137 |
snprintf(number, sizeof(number), "%d", level); |
| 2138 |
incrname = g_strjoin(NULL, basename, "_", number, ".new", NULL); |
| 2139 |
unlink(incrname); |
| 2140 |
|
| 2141 |
/* |
| 2142 |
* Open the listed incremental file from the previous level. Search |
| 2143 |
* backward until one is found. If none are found (which will also |
| 2144 |
* be true for a level 0), arrange to read from /dev/null. |
| 2145 |
*/ |
| 2146 |
baselevel = level; |
| 2147 |
infd = -1; |
| 2148 |
while (infd == -1) { |
| 2149 |
if (--baselevel >= 0) { |
| 2150 |
snprintf(number, sizeof(number), "%d", baselevel); |
| 2151 |
g_free(inputname); |
| 2152 |
inputname = g_strconcat(basename, "_", number, NULL); |
| 2153 |
} else { |
| 2154 |
g_free(inputname); |
| 2155 |
inputname = g_strdup("/dev/null"); |
| 2156 |
} |
| 2157 |
if ((infd = open(inputname, O_RDONLY)) == -1) { |
| 2158 |
|
| 2159 |
errmsg = g_strdup_printf(_("amgtar: error opening %s: %s"), |
| 2160 |
inputname, strerror(errno)); |
| 2161 |
dbprintf("%s\n", errmsg); |
| 2162 |
if (baselevel < 0) { |
| 2163 |
if (command == CMD_ESTIMATE) { |
| 2164 |
fprintf(mesgstream, "ERROR %s\n", errmsg); |
| 2165 |
} else { |
| 2166 |
fprintf(mesgstream, "sendbackup: error [%s]\n", errmsg); |
| 2167 |
} |
| 2168 |
exit(1); |
| 2169 |
} |
| 2170 |
amfree(errmsg); |
| 2171 |
} |
| 2172 |
} |
| 2173 |
|
| 2174 |
/* |
| 2175 |
* Copy the previous listed incremental file to the new one. |
| 2176 |
*/ |
| 2177 |
if ((outfd = open(incrname, O_WRONLY|O_CREAT, 0600)) == -1) { |
| 2178 |
errmsg = g_strdup_printf(_("error opening %s: %s"), |
| 2179 |
incrname, strerror(errno)); |
| 2180 |
dbprintf("%s\n", errmsg); |
| 2181 |
if (command == CMD_ESTIMATE) { |
| 2182 |
fprintf(mesgstream, "ERROR %s\n", errmsg); |
| 2183 |
} else { |
| 2184 |
fprintf(mesgstream, "sendbackup: error [%s]\n", errmsg); |
| 2185 |
} |
| 2186 |
exit(1); |
| 2187 |
} |
| 2188 |
|
| 2189 |
amfree(inputname); |
| 2190 |
amfree(basename); |
| 2191 |
|
| 2192 |
while ((nb = read(infd, &buf, sizeof(buf))) > 0) { |
| 2193 |
if (full_write(outfd, &buf, (size_t)nb) < (size_t)nb) { |
| 2194 |
errmsg = g_strdup_printf(_("writing to %s: %s"), |
| 2195 |
incrname, strerror(errno)); |
| 2196 |
dbprintf("%s\n", errmsg); |
| 2197 |
aclose(infd); |
| 2198 |
aclose(outfd); |
| 2199 |
amfree(incrname); |
| 2200 |
dbprintf("%s\n", errmsg); |
| 2201 |
if (command == CMD_ESTIMATE) { |
| 2202 |
fprintf(mesgstream, "ERROR %s\n", errmsg); |
| 2203 |
} else { |
| 2204 |
fprintf(mesgstream, "sendbackup: error [%s]\n", errmsg); |
| 2205 |
} |
| 2206 |
amfree(errmsg); |
| 2207 |
exit(1); |
| 2208 |
} |
| 2209 |
} |
| 2210 |
|
| 2211 |
if (nb < 0) { |
| 2212 |
errmsg = g_strdup_printf(_("reading from %s: %s"), |
| 2213 |
inputname, strerror(errno)); |
| 2214 |
dbprintf("%s\n", errmsg); |
| 2215 |
aclose(infd); |
| 2216 |
aclose(outfd); |
| 2217 |
amfree(incrname); |
| 2218 |
dbprintf("%s\n", errmsg); |
| 2219 |
if (command == CMD_ESTIMATE) { |
| 2220 |
fprintf(mesgstream, "ERROR %s\n", errmsg); |
| 2221 |
} else { |
| 2222 |
fprintf(mesgstream, "sendbackup: error [%s]\n", errmsg); |
| 2223 |
} |
| 2224 |
amfree(errmsg); |
| 2225 |
exit(1); |
| 2226 |
} |
| 2227 |
|
| 2228 |
if (close(infd) != 0) { |
| 2229 |
errmsg = g_strdup_printf(_("closing %s: %s"), |
| 2230 |
inputname, strerror(errno)); |
| 2231 |
dbprintf("%s\n", errmsg); |
| 2232 |
aclose(outfd); |
| 2233 |
amfree(incrname); |
| 2234 |
amfree(errmsg); |
| 2235 |
dbprintf("%s\n", errmsg); |
| 2236 |
if (command == CMD_ESTIMATE) { |
| 2237 |
fprintf(mesgstream, "ERROR %s\n", errmsg); |
| 2238 |
} else { |
| 2239 |
fprintf(mesgstream, "sendbackup: error [%s]\n", errmsg); |
| 2240 |
} |
| 2241 |
exit(1); |
| 2242 |
} |
| 2243 |
if (close(outfd) != 0) { |
| 2244 |
errmsg = g_strdup_printf(_("closing %s: %s"), |
| 2245 |
incrname, strerror(errno)); |
| 2246 |
dbprintf("%s\n", errmsg); |
| 2247 |
amfree(incrname); |
| 2248 |
amfree(errmsg); |
| 2249 |
dbprintf("%s\n", errmsg); |
| 2250 |
if (command == CMD_ESTIMATE) { |
| 2251 |
fprintf(mesgstream, "ERROR %s\n", errmsg); |
| 2252 |
} else { |
| 2253 |
fprintf(mesgstream, "sendbackup: error [%s]\n", errmsg); |
| 2254 |
} |
| 2255 |
exit(1); |
| 2256 |
} |
| 2257 |
|
| 2258 |
} else { |
| 2259 |
errmsg = _("GNUTAR-LISTDIR is not defined"); |
| 2260 |
dbprintf("%s\n", errmsg); |
| 2261 |
if (command == CMD_ESTIMATE) { |
| 2262 |
fprintf(mesgstream, "ERROR %s\n", errmsg); |
| 2263 |
} else { |
| 2264 |
fprintf(mesgstream, "sendbackup: error [%s]\n", errmsg); |
| 2265 |
} |
| 2266 |
exit(1); |
| 2267 |
} |
| 2268 |
return incrname; |
| 2269 |
} |
| 2270 |
|
| 2271 |
static void |
| 2272 |
check_no_check_device(void) |
| 2273 |
{ |
| 2274 |
if (gnutar_checkdevice == 0) { |
| 2275 |
GPtrArray *argv_ptr = g_ptr_array_new(); |
| 2276 |
int dumpin; |
| 2277 |
int dataf; |
| 2278 |
int outf; |
| 2279 |
int size; |
| 2280 |
char buf[32768]; |
| 2281 |
|
| 2282 |
g_ptr_array_add(argv_ptr, gnutar_path); |
| 2283 |
g_ptr_array_add(argv_ptr, "-x"); |
| 2284 |
g_ptr_array_add(argv_ptr, "--no-check-device"); |
| 2285 |
g_ptr_array_add(argv_ptr, "-f"); |
| 2286 |
g_ptr_array_add(argv_ptr, "-"); |
| 2287 |
g_ptr_array_add(argv_ptr, NULL); |
| 2288 |
|
| 2289 |
pipespawnv(gnutar_path, STDIN_PIPE|STDOUT_PIPE|STDERR_PIPE, 0, |
| 2290 |
&dumpin, &dataf, &outf, (char **)argv_ptr->pdata); |
| 2291 |
aclose(dumpin); |
| 2292 |
aclose(dataf); |
| 2293 |
size = read(outf, buf, 32767); |
| 2294 |
if (size > 0) { |
| 2295 |
buf[size] = '\0'; |
| 2296 |
if (strstr(buf, "--no-check-device")) { |
| 2297 |
g_debug("disabling --no-check-device since '%s' doesn't support it", gnutar_path); |
| 2298 |
gnutar_checkdevice = 1; |
| 2299 |
} |
| 2300 |
} |
| 2301 |
aclose(outf); |
| 2302 |
g_ptr_array_free(argv_ptr, TRUE); |
| 2303 |
} |
| 2304 |
} |
| 2305 |
|
| 2306 |
GPtrArray *amgtar_build_argv( |
| 2307 |
char *gnutar_realpath, |
| 2308 |
application_argument_t *argument, |
| 2309 |
char *incrname, |
| 2310 |
char **file_exclude, |
| 2311 |
char **file_include, |
| 2312 |
int command, |
| 2313 |
messagelist_t *mlist) |
| 2314 |
{ |
| 2315 |
int nb_exclude; |
| 2316 |
int nb_include; |
| 2317 |
char *dirname; |
| 2318 |
char tmppath[PATH_MAX]; |
| 2319 |
GPtrArray *argv_ptr = g_ptr_array_new(); |
| 2320 |
GSList *copt; |
| 2321 |
|
| 2322 |
check_no_check_device(); |
| 2323 |
|
| 2324 |
if (gnutar_target) { |
| 2325 |
dirname = gnutar_target; |
| 2326 |
} else { |
| 2327 |
dirname = argument->dle.device; |
| 2328 |
} |
| 2329 |
|
| 2330 |
amgtar_build_exinclude(&argument->dle, |
| 2331 |
&nb_exclude, file_exclude, |
| 2332 |
&nb_include, file_include, dirname, mlist); |
| 2333 |
|
| 2334 |
g_ptr_array_add(argv_ptr, g_strdup(gnutar_realpath)); |
| 2335 |
|
| 2336 |
g_ptr_array_add(argv_ptr, g_strdup("--create")); |
| 2337 |
if (command == CMD_BACKUP && argument->dle.create_index) { |
| 2338 |
g_ptr_array_add(argv_ptr, g_strdup("--verbose")); |
| 2339 |
g_ptr_array_add(argv_ptr, g_strdup("--block-number")); |
| 2340 |
} |
| 2341 |
g_ptr_array_add(argv_ptr, g_strdup("--file")); |
| 2342 |
if (command == CMD_ESTIMATE) { |
| 2343 |
g_ptr_array_add(argv_ptr, g_strdup("/dev/null")); |
| 2344 |
} else { |
| 2345 |
g_ptr_array_add(argv_ptr, g_strdup("-")); |
| 2346 |
} |
| 2347 |
if (gnutar_no_unquote) |
| 2348 |
g_ptr_array_add(argv_ptr, g_strdup("--no-unquote")); |
| 2349 |
g_ptr_array_add(argv_ptr, g_strdup("--directory")); |
| 2350 |
canonicalize_pathname(dirname, tmppath); |
| 2351 |
g_ptr_array_add(argv_ptr, g_strdup(tmppath)); |
| 2352 |
if (gnutar_onefilesystem) |
| 2353 |
g_ptr_array_add(argv_ptr, g_strdup("--one-file-system")); |
| 2354 |
if (gnutar_atimepreserve) |
| 2355 |
g_ptr_array_add(argv_ptr, g_strdup("--atime-preserve=system")); |
| 2356 |
if (!gnutar_checkdevice) |
| 2357 |
g_ptr_array_add(argv_ptr, g_strdup("--no-check-device")); |
| 2358 |
if (gnutar_acls) |
| 2359 |
g_ptr_array_add(argv_ptr, g_strdup("--acls")); |
| 2360 |
if (gnutar_selinux) |
| 2361 |
g_ptr_array_add(argv_ptr, g_strdup("--selinux")); |
| 2362 |
if (gnutar_xattrs) |
| 2363 |
g_ptr_array_add(argv_ptr, g_strdup("--xattrs")); |
| 2364 |
g_ptr_array_add(argv_ptr, g_strdup("--listed-incremental")); |
| 2365 |
g_ptr_array_add(argv_ptr, g_strdup(incrname)); |
| 2366 |
if (gnutar_sparse) { |
| 2367 |
if (!gnutar_sparse_set) { |
| 2368 |
char *gtar_version; |
| 2369 |
char *minor_version; |
| 2370 |
char *sminor_version; |
| 2371 |
char *gv; |
| 2372 |
int major; |
| 2373 |
int minor; |
| 2374 |
GPtrArray *version_ptr = g_ptr_array_new(); |
| 2375 |
|
| 2376 |
g_ptr_array_add(version_ptr, gnutar_path); |
| 2377 |
g_ptr_array_add(version_ptr, "--version"); |
| 2378 |
g_ptr_array_add(version_ptr, NULL); |
| 2379 |
gtar_version = get_first_line(version_ptr); |
| 2380 |
if (gtar_version) { |
| 2381 |
for (gv = gtar_version; *gv && !g_ascii_isdigit(*gv); gv++); |
| 2382 |
minor_version = index(gtar_version, '.'); |
| 2383 |
if (minor_version) { |
| 2384 |
*minor_version++ = '\0'; |
| 2385 |
sminor_version = index(minor_version, '.'); |
| 2386 |
if (sminor_version) { |
| 2387 |
*sminor_version = '\0'; |
| 2388 |
} |
| 2389 |
major = atoi(gv); |
| 2390 |
minor = atoi(minor_version); |
| 2391 |
if (major < 1 || |
| 2392 |
(major == 1 && minor < 28)) { |
| 2393 |
gnutar_sparse = 0; |
| 2394 |
} |
| 2395 |
} |
| 2396 |
} |
| 2397 |
g_ptr_array_free(version_ptr, TRUE); |
| 2398 |
amfree(gtar_version); |
| 2399 |
} |
| 2400 |
if (gnutar_sparse) { |
| 2401 |
g_ptr_array_add(argv_ptr, g_strdup("--sparse")); |
| 2402 |
} |
| 2403 |
} |
| 2404 |
if (argument->tar_blocksize) { |
| 2405 |
g_ptr_array_add(argv_ptr, g_strdup("--blocking-factor")); |
| 2406 |
g_ptr_array_add(argv_ptr, g_strdup(argument->tar_blocksize)); |
| 2407 |
} |
| 2408 |
g_ptr_array_add(argv_ptr, g_strdup("--ignore-failed-read")); |
| 2409 |
g_ptr_array_add(argv_ptr, g_strdup("--totals")); |
| 2410 |
|
| 2411 |
for (copt = argument->command_options; copt != NULL; copt = copt->next) { |
| 2412 |
g_ptr_array_add(argv_ptr, g_strdup((char *)copt->data)); |
| 2413 |
} |
| 2414 |
|
| 2415 |
if (*file_exclude) { |
| 2416 |
g_ptr_array_add(argv_ptr, g_strdup("--exclude-from")); |
| 2417 |
g_ptr_array_add(argv_ptr, g_strdup(*file_exclude)); |
| 2418 |
} |
| 2419 |
|
| 2420 |
if (*file_include) { |
| 2421 |
g_ptr_array_add(argv_ptr, g_strdup("--files-from")); |
| 2422 |
g_ptr_array_add(argv_ptr, g_strdup(*file_include)); |
| 2423 |
} |
| 2424 |
else { |
| 2425 |
g_ptr_array_add(argv_ptr, g_strdup(".")); |
| 2426 |
} |
| 2427 |
g_ptr_array_add(argv_ptr, NULL); |
| 2428 |
|
| 2429 |
return(argv_ptr); |
| 2430 |
} |
| 2431 |
|