| 1 |
/* POSIX extended headers for tar. |
| 2 |
|
| 3 |
Copyright (C) 2003-2023 Free Software Foundation, Inc. |
| 4 |
|
| 5 |
This file is part of GNU tar. |
| 6 |
|
| 7 |
GNU tar is free software; you can redistribute it and/or modify |
| 8 |
it under the terms of the GNU General Public License as published by |
| 9 |
the Free Software Foundation; either version 3 of the License, or |
| 10 |
(at your option) any later version. |
| 11 |
|
| 12 |
GNU tar is distributed in the hope that it will be useful, |
| 13 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 |
GNU General Public License for more details. |
| 16 |
|
| 17 |
You should have received a copy of the GNU General Public License |
| 18 |
along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
| 19 |
|
| 20 |
#include <system.h> |
| 21 |
|
| 22 |
#include <fnmatch.h> |
| 23 |
#include <hash.h> |
| 24 |
#include <inttostr.h> |
| 25 |
#include <quotearg.h> |
| 26 |
|
| 27 |
#include "common.h" |
| 28 |
|
| 29 |
static void xheader_init (struct xheader *xhdr); |
| 30 |
static bool xheader_protected_pattern_p (char const *pattern); |
| 31 |
static bool xheader_protected_keyword_p (char const *keyword); |
| 32 |
|
| 33 |
/* Used by xheader_finish() */ |
| 34 |
static void code_string (char const *string, char const *keyword, |
| 35 |
struct xheader *xhdr); |
| 36 |
|
| 37 |
/* Number of global headers written so far. */ |
| 38 |
static size_t global_header_count; |
| 39 |
/* FIXME: Possibly it should be reset after changing the volume. |
| 40 |
POSIX %n specification says that it is expanded to the sequence |
| 41 |
number of current global header in *the* archive. However, for |
| 42 |
multi-volume archives this will yield duplicate header names |
| 43 |
in different volumes, which I'd like to avoid. The best way |
| 44 |
to solve this would be to use per-archive header count as required |
| 45 |
by POSIX *and* set globexthdr.name to, say, |
| 46 |
$TMPDIR/GlobalHead.%p.$NUMVOLUME.%n. |
| 47 |
|
| 48 |
However it should wait until buffer.c is finally rewritten */ |
| 49 |
|
| 50 |
|
| 51 |
/* Interface functions to obstacks */ |
| 52 |
|
| 53 |
static void |
| 54 |
x_obstack_grow (struct xheader *xhdr, const char *ptr, size_t length) |
| 55 |
{ |
| 56 |
obstack_grow (xhdr->stk, ptr, length); |
| 57 |
xhdr->size += length; |
| 58 |
} |
| 59 |
|
| 60 |
static void |
| 61 |
x_obstack_1grow (struct xheader *xhdr, char c) |
| 62 |
{ |
| 63 |
obstack_1grow (xhdr->stk, c); |
| 64 |
xhdr->size++; |
| 65 |
} |
| 66 |
|
| 67 |
static void |
| 68 |
x_obstack_blank (struct xheader *xhdr, size_t length) |
| 69 |
{ |
| 70 |
obstack_blank (xhdr->stk, length); |
| 71 |
xhdr->size += length; |
| 72 |
} |
| 73 |
|
| 74 |
|
| 75 |
/* Keyword options */ |
| 76 |
|
| 77 |
struct keyword_list |
| 78 |
{ |
| 79 |
struct keyword_list *next; |
| 80 |
char *pattern; |
| 81 |
char *value; |
| 82 |
}; |
| 83 |
|
| 84 |
|
| 85 |
/* List of keyword patterns set by delete= option */ |
| 86 |
static struct keyword_list *keyword_pattern_list; |
| 87 |
|
| 88 |
/* List of keyword/value pairs set by 'keyword=value' option */ |
| 89 |
static struct keyword_list *keyword_global_override_list; |
| 90 |
|
| 91 |
/* List of keyword/value pairs set by 'keyword:=value' option */ |
| 92 |
static struct keyword_list *keyword_override_list; |
| 93 |
|
| 94 |
/* List of keyword/value pairs decoded from the last 'g' type header */ |
| 95 |
static struct keyword_list *global_header_override_list; |
| 96 |
|
| 97 |
/* Template for the name field of an 'x' type header */ |
| 98 |
static char *exthdr_name; |
| 99 |
|
| 100 |
static char *exthdr_mtime_option; |
| 101 |
static time_t exthdr_mtime; |
| 102 |
|
| 103 |
/* Template for the name field of a 'g' type header */ |
| 104 |
static char *globexthdr_name; |
| 105 |
|
| 106 |
static char *globexthdr_mtime_option; |
| 107 |
static time_t globexthdr_mtime; |
| 108 |
|
| 109 |
bool |
| 110 |
xheader_keyword_deleted_p (const char *kw) |
| 111 |
{ |
| 112 |
struct keyword_list *kp; |
| 113 |
|
| 114 |
for (kp = keyword_pattern_list; kp; kp = kp->next) |
| 115 |
if (fnmatch (kp->pattern, kw, 0) == 0) |
| 116 |
return true; |
| 117 |
return false; |
| 118 |
} |
| 119 |
|
| 120 |
static bool |
| 121 |
xheader_keyword_override_p (const char *keyword) |
| 122 |
{ |
| 123 |
struct keyword_list *kp; |
| 124 |
|
| 125 |
for (kp = keyword_override_list; kp; kp = kp->next) |
| 126 |
if (strcmp (kp->pattern, keyword) == 0) |
| 127 |
return true; |
| 128 |
return false; |
| 129 |
} |
| 130 |
|
| 131 |
static void |
| 132 |
xheader_list_append (struct keyword_list **root, char const *kw, |
| 133 |
char const *value) |
| 134 |
{ |
| 135 |
struct keyword_list *kp = xmalloc (sizeof *kp); |
| 136 |
kp->pattern = xstrdup (kw); |
| 137 |
kp->value = value ? xstrdup (value) : NULL; |
| 138 |
kp->next = *root; |
| 139 |
*root = kp; |
| 140 |
} |
| 141 |
|
| 142 |
static void |
| 143 |
xheader_list_destroy (struct keyword_list **root) |
| 144 |
{ |
| 145 |
if (root) |
| 146 |
{ |
| 147 |
struct keyword_list *kw = *root; |
| 148 |
while (kw) |
| 149 |
{ |
| 150 |
struct keyword_list *next = kw->next; |
| 151 |
free (kw->pattern); |
| 152 |
free (kw->value); |
| 153 |
free (kw); |
| 154 |
kw = next; |
| 155 |
} |
| 156 |
*root = NULL; |
| 157 |
} |
| 158 |
} |
| 159 |
|
| 160 |
static _Noreturn void |
| 161 |
xheader_set_single_keyword (char *kw) |
| 162 |
{ |
| 163 |
USAGE_ERROR ((0, 0, _("Keyword %s is unknown or not yet implemented"), kw)); |
| 164 |
} |
| 165 |
|
| 166 |
static void |
| 167 |
assign_time_option (char **sval, time_t *tval, const char *input) |
| 168 |
{ |
| 169 |
char *p; |
| 170 |
struct timespec t = decode_timespec (input, &p, false); |
| 171 |
if (! valid_timespec (t) || *p) |
| 172 |
ERROR ((0, 0, _("Time stamp is out of allowed range"))); |
| 173 |
else |
| 174 |
{ |
| 175 |
*tval = t.tv_sec; |
| 176 |
assign_string (sval, input); |
| 177 |
} |
| 178 |
} |
| 179 |
|
| 180 |
static void |
| 181 |
xheader_set_keyword_equal (char *kw, char *eq) |
| 182 |
{ |
| 183 |
bool global = true; |
| 184 |
char *p = eq; |
| 185 |
|
| 186 |
if (eq == kw) |
| 187 |
USAGE_ERROR ((0, 0, _("Malformed pax option: %s"), quote (kw))); |
| 188 |
|
| 189 |
if (eq[-1] == ':') |
| 190 |
{ |
| 191 |
p--; |
| 192 |
global = false; |
| 193 |
} |
| 194 |
|
| 195 |
while (p > kw && isspace ((unsigned char) *p)) |
| 196 |
p--; |
| 197 |
|
| 198 |
*p = 0; |
| 199 |
|
| 200 |
for (p = eq + 1; *p && isspace ((unsigned char) *p); p++) |
| 201 |
; |
| 202 |
|
| 203 |
if (strcmp (kw, "delete") == 0) |
| 204 |
{ |
| 205 |
if (xheader_protected_pattern_p (p)) |
| 206 |
USAGE_ERROR ((0, 0, _("Pattern %s cannot be used"), quote (p))); |
| 207 |
xheader_list_append (&keyword_pattern_list, p, NULL); |
| 208 |
} |
| 209 |
else if (strcmp (kw, "exthdr.name") == 0) |
| 210 |
assign_string (&exthdr_name, p); |
| 211 |
else if (strcmp (kw, "globexthdr.name") == 0) |
| 212 |
assign_string (&globexthdr_name, p); |
| 213 |
else if (strcmp (kw, "exthdr.mtime") == 0) |
| 214 |
assign_time_option (&exthdr_mtime_option, &exthdr_mtime, p); |
| 215 |
else if (strcmp (kw, "globexthdr.mtime") == 0) |
| 216 |
assign_time_option (&globexthdr_mtime_option, &globexthdr_mtime, p); |
| 217 |
else |
| 218 |
{ |
| 219 |
if (xheader_protected_keyword_p (kw)) |
| 220 |
USAGE_ERROR ((0, 0, _("Keyword %s cannot be overridden"), kw)); |
| 221 |
if (global) |
| 222 |
xheader_list_append (&keyword_global_override_list, kw, p); |
| 223 |
else |
| 224 |
xheader_list_append (&keyword_override_list, kw, p); |
| 225 |
} |
| 226 |
} |
| 227 |
|
| 228 |
void |
| 229 |
xheader_set_option (char *string) |
| 230 |
{ |
| 231 |
char *token; |
| 232 |
for (token = strtok (string, ","); token; token = strtok (NULL, ",")) |
| 233 |
{ |
| 234 |
char *p = strchr (token, '='); |
| 235 |
if (!p) |
| 236 |
xheader_set_single_keyword (token); |
| 237 |
else |
| 238 |
xheader_set_keyword_equal (token, p); |
| 239 |
} |
| 240 |
} |
| 241 |
|
| 242 |
/* |
| 243 |
string Includes: Replaced By: |
| 244 |
%d The directory name of the file, |
| 245 |
equivalent to the result of the |
| 246 |
dirname utility on the translated |
| 247 |
file name. |
| 248 |
%f The filename of the file, equivalent |
| 249 |
to the result of the basename |
| 250 |
utility on the translated file name. |
| 251 |
%p The process ID of the pax process. |
| 252 |
%n The value of the 3rd argument. |
| 253 |
%% A '%' character. */ |
| 254 |
|
| 255 |
char * |
| 256 |
xheader_format_name (struct tar_stat_info *st, const char *fmt, size_t n) |
| 257 |
{ |
| 258 |
char *buf; |
| 259 |
size_t len; |
| 260 |
char *q; |
| 261 |
const char *p; |
| 262 |
char *dirp = NULL; |
| 263 |
char *dir = NULL; |
| 264 |
char *base = NULL; |
| 265 |
char pidbuf[UINTMAX_STRSIZE_BOUND]; |
| 266 |
char const *pptr = NULL; |
| 267 |
char nbuf[UINTMAX_STRSIZE_BOUND]; |
| 268 |
char const *nptr = NULL; |
| 269 |
|
| 270 |
len = 0; |
| 271 |
for (p = fmt; *p; p++) |
| 272 |
{ |
| 273 |
if (*p == '%' && p[1]) |
| 274 |
{ |
| 275 |
switch (*++p) |
| 276 |
{ |
| 277 |
case '%': |
| 278 |
len++; |
| 279 |
break; |
| 280 |
|
| 281 |
case 'd': |
| 282 |
if (st) |
| 283 |
{ |
| 284 |
if (!dirp) |
| 285 |
dirp = dir_name (st->orig_file_name); |
| 286 |
dir = safer_name_suffix (dirp, false, absolute_names_option); |
| 287 |
len += strlen (dir); |
| 288 |
} |
| 289 |
break; |
| 290 |
|
| 291 |
case 'f': |
| 292 |
if (st) |
| 293 |
{ |
| 294 |
base = last_component (st->orig_file_name); |
| 295 |
len += strlen (base); |
| 296 |
} |
| 297 |
break; |
| 298 |
|
| 299 |
case 'p': |
| 300 |
pptr = umaxtostr (getpid (), pidbuf); |
| 301 |
len += pidbuf + sizeof pidbuf - 1 - pptr; |
| 302 |
break; |
| 303 |
|
| 304 |
case 'n': |
| 305 |
nptr = umaxtostr (n, nbuf); |
| 306 |
len += nbuf + sizeof nbuf - 1 - nptr; |
| 307 |
break; |
| 308 |
|
| 309 |
default: |
| 310 |
len += 2; |
| 311 |
} |
| 312 |
} |
| 313 |
else |
| 314 |
len++; |
| 315 |
} |
| 316 |
|
| 317 |
buf = xmalloc (len + 1); |
| 318 |
for (q = buf, p = fmt; *p; ) |
| 319 |
{ |
| 320 |
if (*p == '%') |
| 321 |
{ |
| 322 |
switch (p[1]) |
| 323 |
{ |
| 324 |
case '%': |
| 325 |
*q++ = *p++; |
| 326 |
p++; |
| 327 |
break; |
| 328 |
|
| 329 |
case 'd': |
| 330 |
if (dir) |
| 331 |
q = stpcpy (q, dir); |
| 332 |
p += 2; |
| 333 |
break; |
| 334 |
|
| 335 |
case 'f': |
| 336 |
if (base) |
| 337 |
q = stpcpy (q, base); |
| 338 |
p += 2; |
| 339 |
break; |
| 340 |
|
| 341 |
case 'p': |
| 342 |
q = stpcpy (q, pptr); |
| 343 |
p += 2; |
| 344 |
break; |
| 345 |
|
| 346 |
case 'n': |
| 347 |
q = stpcpy (q, nptr); |
| 348 |
p += 2; |
| 349 |
break; |
| 350 |
|
| 351 |
|
| 352 |
default: |
| 353 |
*q++ = *p++; |
| 354 |
if (*p) |
| 355 |
*q++ = *p++; |
| 356 |
} |
| 357 |
} |
| 358 |
else |
| 359 |
*q++ = *p++; |
| 360 |
} |
| 361 |
|
| 362 |
free (dirp); |
| 363 |
|
| 364 |
/* Do not allow it to end in a slash */ |
| 365 |
while (q > buf && ISSLASH (q[-1])) |
| 366 |
q--; |
| 367 |
*q = 0; |
| 368 |
return buf; |
| 369 |
} |
| 370 |
|
| 371 |
/* Table of templates for the names of POSIX extended headers. |
| 372 |
Indexed by the the type of the header (per-file or global) |
| 373 |
and POSIX compliance mode (0 or q depending on whether |
| 374 |
POSIXLY_CORRECT environment variable is set. */ |
| 375 |
static const char *header_template[][2] = { |
| 376 |
/* Individual header templates: */ |
| 377 |
{ "%d/PaxHeaders/%f", "%d/PaxHeaders.%p/%f" }, |
| 378 |
/* Global header templates: */ |
| 379 |
{ "/GlobalHead.%n", "/GlobalHead.%p.%n" } |
| 380 |
}; |
| 381 |
/* Indices to the above table */ |
| 382 |
enum { |
| 383 |
pax_file_header, |
| 384 |
pax_global_header |
| 385 |
}; |
| 386 |
/* Return the name for the POSIX extended header T */ |
| 387 |
#define HEADER_TEMPLATE(t) header_template[t][posixly_correct] |
| 388 |
|
| 389 |
char * |
| 390 |
xheader_xhdr_name (struct tar_stat_info *st) |
| 391 |
{ |
| 392 |
if (!exthdr_name) |
| 393 |
assign_string (&exthdr_name, HEADER_TEMPLATE (pax_file_header)); |
| 394 |
return xheader_format_name (st, exthdr_name, 0); |
| 395 |
} |
| 396 |
|
| 397 |
char * |
| 398 |
xheader_ghdr_name (void) |
| 399 |
{ |
| 400 |
if (!globexthdr_name) |
| 401 |
{ |
| 402 |
size_t len; |
| 403 |
const char *global_header_template = HEADER_TEMPLATE (pax_global_header); |
| 404 |
const char *tmp = getenv ("TMPDIR"); |
| 405 |
if (!tmp) |
| 406 |
tmp = "/tmp"; |
| 407 |
len = strlen (tmp) + strlen (global_header_template) + 1; |
| 408 |
globexthdr_name = xmalloc (len); |
| 409 |
strcpy(globexthdr_name, tmp); |
| 410 |
strcat(globexthdr_name, global_header_template); |
| 411 |
} |
| 412 |
|
| 413 |
return xheader_format_name (NULL, globexthdr_name, global_header_count + 1); |
| 414 |
} |
| 415 |
|
| 416 |
void |
| 417 |
xheader_write (char type, char *name, time_t t, struct xheader *xhdr) |
| 418 |
{ |
| 419 |
union block *header; |
| 420 |
size_t size; |
| 421 |
char *p; |
| 422 |
|
| 423 |
size = xhdr->size; |
| 424 |
switch (type) |
| 425 |
{ |
| 426 |
case XGLTYPE: |
| 427 |
if (globexthdr_mtime_option) |
| 428 |
t = globexthdr_mtime; |
| 429 |
break; |
| 430 |
|
| 431 |
case XHDTYPE: |
| 432 |
if (exthdr_mtime_option) |
| 433 |
t = exthdr_mtime; |
| 434 |
break; |
| 435 |
} |
| 436 |
header = start_private_header (name, size, t); |
| 437 |
header->header.typeflag = type; |
| 438 |
|
| 439 |
simple_finish_header (header); |
| 440 |
|
| 441 |
p = xhdr->buffer; |
| 442 |
|
| 443 |
do |
| 444 |
{ |
| 445 |
size_t len; |
| 446 |
|
| 447 |
header = find_next_block (); |
| 448 |
len = BLOCKSIZE; |
| 449 |
if (len > size) |
| 450 |
len = size; |
| 451 |
memcpy (header->buffer, p, len); |
| 452 |
if (len < BLOCKSIZE) |
| 453 |
memset (header->buffer + len, 0, BLOCKSIZE - len); |
| 454 |
p += len; |
| 455 |
size -= len; |
| 456 |
set_next_block_after (header); |
| 457 |
} |
| 458 |
while (size > 0); |
| 459 |
xheader_destroy (xhdr); |
| 460 |
|
| 461 |
if (type == XGLTYPE) |
| 462 |
global_header_count++; |
| 463 |
} |
| 464 |
|
| 465 |
void |
| 466 |
xheader_write_global (struct xheader *xhdr) |
| 467 |
{ |
| 468 |
if (keyword_global_override_list) |
| 469 |
{ |
| 470 |
struct keyword_list *kp; |
| 471 |
|
| 472 |
xheader_init (xhdr); |
| 473 |
for (kp = keyword_global_override_list; kp; kp = kp->next) |
| 474 |
code_string (kp->value, kp->pattern, xhdr); |
| 475 |
} |
| 476 |
if (xhdr->stk) |
| 477 |
{ |
| 478 |
char *name; |
| 479 |
|
| 480 |
xheader_finish (xhdr); |
| 481 |
name = xheader_ghdr_name (); |
| 482 |
xheader_write (XGLTYPE, name, start_time.tv_sec, xhdr); |
| 483 |
free (name); |
| 484 |
} |
| 485 |
} |
| 486 |
|
| 487 |
/* Forbid modifications of the global extended header */ |
| 488 |
void |
| 489 |
xheader_forbid_global (void) |
| 490 |
{ |
| 491 |
if (keyword_global_override_list) |
| 492 |
USAGE_ERROR ((0, 0, _("can't update global extended header record"))); |
| 493 |
} |
| 494 |
|
| 495 |
/* This is reversal function for xattr_encode_keyword. See comment for |
| 496 |
xattr_encode_keyword() for more info. */ |
| 497 |
static void |
| 498 |
xattr_decode_keyword (char *keyword) |
| 499 |
{ |
| 500 |
char *kpr, *kpl; /* keyword pointer left/right */ |
| 501 |
kpr = kpl = keyword; |
| 502 |
|
| 503 |
for (;;) |
| 504 |
{ |
| 505 |
if (*kpr == '%') |
| 506 |
{ |
| 507 |
if (kpr[1] == '3' && kpr[2] == 'D') |
| 508 |
{ |
| 509 |
*kpl = '='; |
| 510 |
kpr += 3; |
| 511 |
kpl ++; |
| 512 |
continue; |
| 513 |
} |
| 514 |
else if (kpr[1] == '2' && kpr[2] == '5') |
| 515 |
{ |
| 516 |
*kpl = '%'; |
| 517 |
kpr += 3; |
| 518 |
kpl ++; |
| 519 |
continue; |
| 520 |
} |
| 521 |
} |
| 522 |
|
| 523 |
*kpl = *kpr; |
| 524 |
|
| 525 |
if (*kpr == 0) |
| 526 |
break; |
| 527 |
|
| 528 |
kpr++; |
| 529 |
kpl++; |
| 530 |
} |
| 531 |
} |
| 532 |
|
| 533 |
/* General Interface */ |
| 534 |
|
| 535 |
#define XHDR_PROTECTED 0x01 |
| 536 |
#define XHDR_GLOBAL 0x02 |
| 537 |
|
| 538 |
struct xhdr_tab |
| 539 |
{ |
| 540 |
char const *keyword; |
| 541 |
void (*coder) (struct tar_stat_info const *, char const *, |
| 542 |
struct xheader *, void const *data); |
| 543 |
void (*decoder) (struct tar_stat_info *, char const *, char const *, size_t); |
| 544 |
int flags; |
| 545 |
bool prefix; /* select handler comparing prefix only */ |
| 546 |
}; |
| 547 |
|
| 548 |
/* This declaration must be extern, because ISO C99 section 6.9.2 |
| 549 |
prohibits a tentative definition that has both internal linkage and |
| 550 |
incomplete type. If we made it static, we'd have to declare its |
| 551 |
size which would be a maintenance pain; if we put its initializer |
| 552 |
here, we'd need a boatload of forward declarations, which would be |
| 553 |
even more of a pain. */ |
| 554 |
extern struct xhdr_tab const xhdr_tab[]; |
| 555 |
|
| 556 |
static struct xhdr_tab const * |
| 557 |
locate_handler (char const *keyword) |
| 558 |
{ |
| 559 |
struct xhdr_tab const *p; |
| 560 |
for (p = xhdr_tab; p->keyword; p++) |
| 561 |
if (p->prefix) |
| 562 |
{ |
| 563 |
size_t kwlen = strlen (p->keyword); |
| 564 |
if (strncmp (p->keyword, keyword, kwlen) == 0 && keyword[kwlen] == '.') |
| 565 |
return p; |
| 566 |
} |
| 567 |
else |
| 568 |
{ |
| 569 |
if (strcmp (p->keyword, keyword) == 0) |
| 570 |
return p; |
| 571 |
} |
| 572 |
|
| 573 |
return NULL; |
| 574 |
} |
| 575 |
|
| 576 |
static bool |
| 577 |
xheader_protected_pattern_p (const char *pattern) |
| 578 |
{ |
| 579 |
struct xhdr_tab const *p; |
| 580 |
|
| 581 |
for (p = xhdr_tab; p->keyword; p++) |
| 582 |
if (!p->prefix && (p->flags & XHDR_PROTECTED) |
| 583 |
&& fnmatch (pattern, p->keyword, 0) == 0) |
| 584 |
return true; |
| 585 |
return false; |
| 586 |
} |
| 587 |
|
| 588 |
static bool |
| 589 |
xheader_protected_keyword_p (const char *keyword) |
| 590 |
{ |
| 591 |
struct xhdr_tab const *p; |
| 592 |
|
| 593 |
for (p = xhdr_tab; p->keyword; p++) |
| 594 |
if (!p->prefix && (p->flags & XHDR_PROTECTED) |
| 595 |
&& strcmp (p->keyword, keyword) == 0) |
| 596 |
return true; |
| 597 |
return false; |
| 598 |
} |
| 599 |
|
| 600 |
/* Decode a single extended header record, advancing *PTR to the next record. |
| 601 |
Return true on success, false otherwise. */ |
| 602 |
static bool |
| 603 |
decode_record (struct xheader *xhdr, |
| 604 |
char **ptr, |
| 605 |
void (*handler) (void *, char const *, char const *, size_t), |
| 606 |
void *data) |
| 607 |
{ |
| 608 |
char *start = *ptr; |
| 609 |
char *p = start; |
| 610 |
size_t len; |
| 611 |
char *len_lim; |
| 612 |
char const *keyword; |
| 613 |
char *nextp; |
| 614 |
size_t len_max = xhdr->buffer + xhdr->size - start; |
| 615 |
|
| 616 |
while (*p == ' ' || *p == '\t') |
| 617 |
p++; |
| 618 |
|
| 619 |
if (! ISDIGIT (*p)) |
| 620 |
{ |
| 621 |
if (*p) |
| 622 |
ERROR ((0, 0, _("Malformed extended header: missing length"))); |
| 623 |
return false; |
| 624 |
} |
| 625 |
|
| 626 |
len = strtoumax (p, &len_lim, 10); |
| 627 |
|
| 628 |
if (len_max < len) |
| 629 |
{ |
| 630 |
int len_len = len_lim - p; |
| 631 |
ERROR ((0, 0, _("Extended header length %.*s is out of range"), |
| 632 |
len_len, p)); |
| 633 |
return false; |
| 634 |
} |
| 635 |
|
| 636 |
nextp = start + len; |
| 637 |
|
| 638 |
for (p = len_lim; *p == ' ' || *p == '\t'; p++) |
| 639 |
continue; |
| 640 |
if (p == len_lim) |
| 641 |
{ |
| 642 |
ERROR ((0, 0, |
| 643 |
_("Malformed extended header: missing blank after length"))); |
| 644 |
return false; |
| 645 |
} |
| 646 |
|
| 647 |
keyword = p; |
| 648 |
p = strchr (p, '='); |
| 649 |
if (! (p && p < nextp)) |
| 650 |
{ |
| 651 |
ERROR ((0, 0, _("Malformed extended header: missing equal sign"))); |
| 652 |
return false; |
| 653 |
} |
| 654 |
|
| 655 |
if (nextp[-1] != '\n') |
| 656 |
{ |
| 657 |
ERROR ((0, 0, _("Malformed extended header: missing newline"))); |
| 658 |
return false; |
| 659 |
} |
| 660 |
|
| 661 |
*p = nextp[-1] = '\0'; |
| 662 |
handler (data, keyword, p + 1, nextp - p - 2); /* '=' + trailing '\n' */ |
| 663 |
*p = '='; |
| 664 |
nextp[-1] = '\n'; |
| 665 |
*ptr = nextp; |
| 666 |
return true; |
| 667 |
} |
| 668 |
|
| 669 |
static void |
| 670 |
run_override_list (struct keyword_list *kp, struct tar_stat_info *st) |
| 671 |
{ |
| 672 |
for (; kp; kp = kp->next) |
| 673 |
{ |
| 674 |
struct xhdr_tab const *t = locate_handler (kp->pattern); |
| 675 |
if (t) |
| 676 |
t->decoder (st, t->keyword, kp->value, strlen (kp->value)); |
| 677 |
} |
| 678 |
} |
| 679 |
|
| 680 |
static void |
| 681 |
decx (void *data, char const *keyword, char const *value, size_t size) |
| 682 |
{ |
| 683 |
struct xhdr_tab const *t; |
| 684 |
struct tar_stat_info *st = data; |
| 685 |
|
| 686 |
if (xheader_keyword_deleted_p (keyword) |
| 687 |
|| xheader_keyword_override_p (keyword)) |
| 688 |
return; |
| 689 |
|
| 690 |
t = locate_handler (keyword); |
| 691 |
if (t) |
| 692 |
t->decoder (st, keyword, value, size); |
| 693 |
else |
| 694 |
WARNOPT (WARN_UNKNOWN_KEYWORD, |
| 695 |
(0, 0, _("Ignoring unknown extended header keyword '%s'"), |
| 696 |
keyword)); |
| 697 |
} |
| 698 |
|
| 699 |
void |
| 700 |
xheader_decode (struct tar_stat_info *st) |
| 701 |
{ |
| 702 |
run_override_list (keyword_global_override_list, st); |
| 703 |
run_override_list (global_header_override_list, st); |
| 704 |
|
| 705 |
if (st->xhdr.size) |
| 706 |
{ |
| 707 |
char *p = st->xhdr.buffer + BLOCKSIZE; |
| 708 |
while (decode_record (&st->xhdr, &p, decx, st)) |
| 709 |
continue; |
| 710 |
} |
| 711 |
run_override_list (keyword_override_list, st); |
| 712 |
|
| 713 |
/* The archived (effective) file size is always set directly in tar header |
| 714 |
field, possibly overridden by "size" extended header - in both cases, |
| 715 |
result is now decoded in st->stat.st_size */ |
| 716 |
st->archive_file_size = st->stat.st_size; |
| 717 |
|
| 718 |
/* The real file size (given by stat()) may be redefined for sparse |
| 719 |
files in "GNU.sparse.realsize" extended header */ |
| 720 |
if (st->real_size_set) |
| 721 |
st->stat.st_size = st->real_size; |
| 722 |
} |
| 723 |
|
| 724 |
static void |
| 725 |
decg (void *data, char const *keyword, char const *value, |
| 726 |
MAYBE_UNUSED size_t size) |
| 727 |
{ |
| 728 |
struct keyword_list **kwl = data; |
| 729 |
struct xhdr_tab const *tab = locate_handler (keyword); |
| 730 |
if (tab && (tab->flags & XHDR_GLOBAL)) |
| 731 |
tab->decoder (data, keyword, value, size); |
| 732 |
else |
| 733 |
xheader_list_append (kwl, keyword, value); |
| 734 |
} |
| 735 |
|
| 736 |
void |
| 737 |
xheader_decode_global (struct xheader *xhdr) |
| 738 |
{ |
| 739 |
if (xhdr->size) |
| 740 |
{ |
| 741 |
char *p = xhdr->buffer + BLOCKSIZE; |
| 742 |
|
| 743 |
xheader_list_destroy (&global_header_override_list); |
| 744 |
while (decode_record (xhdr, &p, decg, &global_header_override_list)) |
| 745 |
continue; |
| 746 |
} |
| 747 |
} |
| 748 |
|
| 749 |
static void |
| 750 |
xheader_init (struct xheader *xhdr) |
| 751 |
{ |
| 752 |
if (!xhdr->stk) |
| 753 |
{ |
| 754 |
xhdr->stk = xmalloc (sizeof *xhdr->stk); |
| 755 |
obstack_init (xhdr->stk); |
| 756 |
} |
| 757 |
} |
| 758 |
|
| 759 |
void |
| 760 |
xheader_store (char const *keyword, struct tar_stat_info *st, |
| 761 |
void const *data) |
| 762 |
{ |
| 763 |
struct xhdr_tab const *t; |
| 764 |
|
| 765 |
if (st->xhdr.buffer) |
| 766 |
return; |
| 767 |
t = locate_handler (keyword); |
| 768 |
if (!t || !t->coder) |
| 769 |
return; |
| 770 |
if (xheader_keyword_deleted_p (keyword)) |
| 771 |
return; |
| 772 |
xheader_init (&st->xhdr); |
| 773 |
if (!xheader_keyword_override_p (keyword)) |
| 774 |
t->coder (st, keyword, &st->xhdr, data); |
| 775 |
} |
| 776 |
|
| 777 |
void |
| 778 |
xheader_read (struct xheader *xhdr, union block *p, off_t size) |
| 779 |
{ |
| 780 |
size_t j = 0; |
| 781 |
|
| 782 |
if (size < 0) |
| 783 |
size = 0; /* Already diagnosed. */ |
| 784 |
|
| 785 |
if (SIZE_MAX - BLOCKSIZE <= size) |
| 786 |
xalloc_die (); |
| 787 |
|
| 788 |
size += BLOCKSIZE; |
| 789 |
xhdr->size = size; |
| 790 |
xhdr->buffer = xmalloc (size + 1); |
| 791 |
xhdr->buffer[size] = '\0'; |
| 792 |
|
| 793 |
do |
| 794 |
{ |
| 795 |
size_t len = size; |
| 796 |
|
| 797 |
if (len > BLOCKSIZE) |
| 798 |
len = BLOCKSIZE; |
| 799 |
|
| 800 |
if (!p) |
| 801 |
FATAL_ERROR ((0, 0, _("Unexpected EOF in archive"))); |
| 802 |
|
| 803 |
memcpy (&xhdr->buffer[j], p->buffer, len); |
| 804 |
set_next_block_after (p); |
| 805 |
|
| 806 |
p = find_next_block (); |
| 807 |
|
| 808 |
j += len; |
| 809 |
size -= len; |
| 810 |
} |
| 811 |
while (size > 0); |
| 812 |
} |
| 813 |
|
| 814 |
/* xattr_encode_keyword() substitutes '=' ~~> '%3D' and '%' ~~> '%25' |
| 815 |
in extended attribute keywords. This is needed because the '=' character |
| 816 |
has special purpose in extended attribute header - it splits keyword and |
| 817 |
value part of header. If there was the '=' occurrence allowed inside |
| 818 |
keyword, there would be no unambiguous way how to decode this extended |
| 819 |
attribute. |
| 820 |
|
| 821 |
(http://lists.gnu.org/archive/html/bug-tar/2012-10/msg00017.html) |
| 822 |
*/ |
| 823 |
static char * |
| 824 |
xattr_encode_keyword(const char *keyword) |
| 825 |
{ |
| 826 |
static char *encode_buffer = NULL; |
| 827 |
static size_t encode_buffer_size = 0; |
| 828 |
size_t bp; /* keyword/buffer pointers */ |
| 829 |
|
| 830 |
if (!encode_buffer) |
| 831 |
{ |
| 832 |
encode_buffer_size = 256; |
| 833 |
encode_buffer = xmalloc (encode_buffer_size); |
| 834 |
} |
| 835 |
else |
| 836 |
*encode_buffer = 0; |
| 837 |
|
| 838 |
for (bp = 0; *keyword != 0; ++bp, ++keyword) |
| 839 |
{ |
| 840 |
char c = *keyword; |
| 841 |
|
| 842 |
if (bp + 3 /* enough for URL encoding also.. */ >= encode_buffer_size) |
| 843 |
{ |
| 844 |
encode_buffer = x2realloc (encode_buffer, &encode_buffer_size); |
| 845 |
} |
| 846 |
|
| 847 |
if (c == '%') |
| 848 |
{ |
| 849 |
strcpy (encode_buffer + bp, "%25"); |
| 850 |
bp += 2; |
| 851 |
} |
| 852 |
else if (c == '=') |
| 853 |
{ |
| 854 |
strcpy (encode_buffer + bp, "%3D"); |
| 855 |
bp += 2; |
| 856 |
} |
| 857 |
else |
| 858 |
encode_buffer[bp] = c; |
| 859 |
} |
| 860 |
|
| 861 |
encode_buffer[bp] = 0; |
| 862 |
|
| 863 |
return encode_buffer; |
| 864 |
} |
| 865 |
|
| 866 |
static void |
| 867 |
xheader_print_n (struct xheader *xhdr, char const *keyword, |
| 868 |
char const *value, size_t vsize) |
| 869 |
{ |
| 870 |
size_t p; |
| 871 |
size_t n = 0; |
| 872 |
char nbuf[UINTMAX_STRSIZE_BOUND]; |
| 873 |
char const *np; |
| 874 |
size_t len, klen; |
| 875 |
|
| 876 |
keyword = xattr_encode_keyword (keyword); |
| 877 |
klen = strlen (keyword); |
| 878 |
len = klen + vsize + 3; /* ' ' + '=' + '\n' */ |
| 879 |
|
| 880 |
do |
| 881 |
{ |
| 882 |
p = n; |
| 883 |
np = umaxtostr (len + p, nbuf); |
| 884 |
n = nbuf + sizeof nbuf - 1 - np; |
| 885 |
} |
| 886 |
while (n != p); |
| 887 |
|
| 888 |
x_obstack_grow (xhdr, np, n); |
| 889 |
x_obstack_1grow (xhdr, ' '); |
| 890 |
x_obstack_grow (xhdr, keyword, klen); |
| 891 |
x_obstack_1grow (xhdr, '='); |
| 892 |
x_obstack_grow (xhdr, value, vsize); |
| 893 |
x_obstack_1grow (xhdr, '\n'); |
| 894 |
} |
| 895 |
|
| 896 |
static void |
| 897 |
xheader_print (struct xheader *xhdr, char const *keyword, char const *value) |
| 898 |
{ |
| 899 |
xheader_print_n (xhdr, keyword, value, strlen (value)); |
| 900 |
} |
| 901 |
|
| 902 |
void |
| 903 |
xheader_finish (struct xheader *xhdr) |
| 904 |
{ |
| 905 |
struct keyword_list *kp; |
| 906 |
|
| 907 |
for (kp = keyword_override_list; kp; kp = kp->next) |
| 908 |
code_string (kp->value, kp->pattern, xhdr); |
| 909 |
|
| 910 |
xhdr->buffer = obstack_finish (xhdr->stk); |
| 911 |
} |
| 912 |
|
| 913 |
void |
| 914 |
xheader_destroy (struct xheader *xhdr) |
| 915 |
{ |
| 916 |
if (xhdr->stk) |
| 917 |
{ |
| 918 |
obstack_free (xhdr->stk, NULL); |
| 919 |
free (xhdr->stk); |
| 920 |
xhdr->stk = NULL; |
| 921 |
} |
| 922 |
else |
| 923 |
free (xhdr->buffer); |
| 924 |
xhdr->buffer = 0; |
| 925 |
xhdr->size = 0; |
| 926 |
} |
| 927 |
|
| 928 |
|
| 929 |
/* Buildable strings */ |
| 930 |
|
| 931 |
void |
| 932 |
xheader_string_begin (struct xheader *xhdr) |
| 933 |
{ |
| 934 |
xhdr->string_length = 0; |
| 935 |
} |
| 936 |
|
| 937 |
void |
| 938 |
xheader_string_add (struct xheader *xhdr, char const *s) |
| 939 |
{ |
| 940 |
if (xhdr->buffer) |
| 941 |
return; |
| 942 |
xheader_init (xhdr); |
| 943 |
xhdr->string_length += strlen (s); |
| 944 |
x_obstack_grow (xhdr, s, strlen (s)); |
| 945 |
} |
| 946 |
|
| 947 |
bool |
| 948 |
xheader_string_end (struct xheader *xhdr, char const *keyword) |
| 949 |
{ |
| 950 |
uintmax_t len; |
| 951 |
uintmax_t p; |
| 952 |
uintmax_t n = 0; |
| 953 |
size_t size; |
| 954 |
char nbuf[UINTMAX_STRSIZE_BOUND]; |
| 955 |
char const *np; |
| 956 |
char *cp; |
| 957 |
|
| 958 |
if (xhdr->buffer) |
| 959 |
return false; |
| 960 |
xheader_init (xhdr); |
| 961 |
|
| 962 |
len = strlen (keyword) + xhdr->string_length + 3; /* ' ' + '=' + '\n' */ |
| 963 |
|
| 964 |
do |
| 965 |
{ |
| 966 |
p = n; |
| 967 |
np = umaxtostr (len + p, nbuf); |
| 968 |
n = nbuf + sizeof nbuf - 1 - np; |
| 969 |
} |
| 970 |
while (n != p); |
| 971 |
|
| 972 |
p = strlen (keyword) + n + 2; |
| 973 |
size = p; |
| 974 |
if (size != p) |
| 975 |
{ |
| 976 |
ERROR ((0, 0, |
| 977 |
_("Generated keyword/value pair is too long (keyword=%s, length=%s)"), |
| 978 |
keyword, nbuf)); |
| 979 |
obstack_free (xhdr->stk, obstack_finish (xhdr->stk)); |
| 980 |
return false; |
| 981 |
} |
| 982 |
x_obstack_blank (xhdr, p); |
| 983 |
x_obstack_1grow (xhdr, '\n'); |
| 984 |
cp = (char*) obstack_next_free (xhdr->stk) - xhdr->string_length - p - 1; |
| 985 |
memmove (cp + p, cp, xhdr->string_length); |
| 986 |
cp = stpcpy (cp, np); |
| 987 |
*cp++ = ' '; |
| 988 |
cp = stpcpy (cp, keyword); |
| 989 |
*cp++ = '='; |
| 990 |
return true; |
| 991 |
} |
| 992 |
|
| 993 |
|
| 994 |
/* Implementations */ |
| 995 |
|
| 996 |
static void |
| 997 |
out_of_range_header (char const *keyword, char const *value, |
| 998 |
intmax_t minval, uintmax_t maxval) |
| 999 |
{ |
| 1000 |
char minval_buf[INT_BUFSIZE_BOUND (intmax_t)]; |
| 1001 |
char maxval_buf[UINTMAX_STRSIZE_BOUND]; |
| 1002 |
char *minval_string = imaxtostr (minval, minval_buf); |
| 1003 |
char *maxval_string = umaxtostr (maxval, maxval_buf); |
| 1004 |
|
| 1005 |
/* TRANSLATORS: The first %s is the pax extended header keyword |
| 1006 |
(atime, gid, etc.). */ |
| 1007 |
ERROR ((0, 0, _("Extended header %s=%s is out of range %s..%s"), |
| 1008 |
keyword, value, minval_string, maxval_string)); |
| 1009 |
} |
| 1010 |
|
| 1011 |
static void |
| 1012 |
code_string (char const *string, char const *keyword, struct xheader *xhdr) |
| 1013 |
{ |
| 1014 |
char *outstr; |
| 1015 |
if (!utf8_convert (true, string, &outstr)) |
| 1016 |
{ |
| 1017 |
/* FIXME: report error */ |
| 1018 |
outstr = xstrdup (string); |
| 1019 |
} |
| 1020 |
xheader_print (xhdr, keyword, outstr); |
| 1021 |
free (outstr); |
| 1022 |
} |
| 1023 |
|
| 1024 |
static void |
| 1025 |
decode_string (char **string, char const *arg) |
| 1026 |
{ |
| 1027 |
if (*string) |
| 1028 |
{ |
| 1029 |
free (*string); |
| 1030 |
*string = NULL; |
| 1031 |
} |
| 1032 |
if (!utf8_convert (false, arg, string)) |
| 1033 |
{ |
| 1034 |
/* FIXME: report error and act accordingly to --pax invalid=UTF-8 */ |
| 1035 |
assign_string (string, arg); |
| 1036 |
} |
| 1037 |
} |
| 1038 |
|
| 1039 |
static void |
| 1040 |
code_time (struct timespec t, char const *keyword, struct xheader *xhdr) |
| 1041 |
{ |
| 1042 |
char buf[TIMESPEC_STRSIZE_BOUND]; |
| 1043 |
xheader_print (xhdr, keyword, code_timespec (t, buf)); |
| 1044 |
} |
| 1045 |
|
| 1046 |
static bool |
| 1047 |
decode_time (struct timespec *ts, char const *arg, char const *keyword) |
| 1048 |
{ |
| 1049 |
char *arg_lim; |
| 1050 |
struct timespec t = decode_timespec (arg, &arg_lim, true); |
| 1051 |
|
| 1052 |
if (! valid_timespec (t)) |
| 1053 |
{ |
| 1054 |
if (arg < arg_lim && !*arg_lim) |
| 1055 |
out_of_range_header (keyword, arg, TYPE_MINIMUM (time_t), |
| 1056 |
TYPE_MAXIMUM (time_t)); |
| 1057 |
else |
| 1058 |
ERROR ((0, 0, _("Malformed extended header: invalid %s=%s"), |
| 1059 |
keyword, arg)); |
| 1060 |
return false; |
| 1061 |
} |
| 1062 |
if (*arg_lim) |
| 1063 |
{ |
| 1064 |
ERROR ((0, 0, _("Malformed extended header: invalid %s=%s"), |
| 1065 |
keyword, arg)); |
| 1066 |
return false; |
| 1067 |
} |
| 1068 |
|
| 1069 |
*ts = t; |
| 1070 |
return true; |
| 1071 |
} |
| 1072 |
|
| 1073 |
static void |
| 1074 |
code_signed_num (uintmax_t value, char const *keyword, |
| 1075 |
intmax_t minval, uintmax_t maxval, struct xheader *xhdr) |
| 1076 |
{ |
| 1077 |
char sbuf[SYSINT_BUFSIZE]; |
| 1078 |
xheader_print (xhdr, keyword, sysinttostr (value, minval, maxval, sbuf)); |
| 1079 |
} |
| 1080 |
|
| 1081 |
static void |
| 1082 |
code_num (uintmax_t value, char const *keyword, struct xheader *xhdr) |
| 1083 |
{ |
| 1084 |
code_signed_num (value, keyword, 0, UINTMAX_MAX, xhdr); |
| 1085 |
} |
| 1086 |
|
| 1087 |
static bool |
| 1088 |
decode_signed_num (intmax_t *num, char const *arg, |
| 1089 |
intmax_t minval, uintmax_t maxval, |
| 1090 |
char const *keyword) |
| 1091 |
{ |
| 1092 |
char *arg_lim; |
| 1093 |
intmax_t u = strtosysint (arg, &arg_lim, minval, maxval); |
| 1094 |
|
| 1095 |
if (errno == EINVAL || *arg_lim) |
| 1096 |
{ |
| 1097 |
ERROR ((0, 0, _("Malformed extended header: invalid %s=%s"), |
| 1098 |
keyword, arg)); |
| 1099 |
return false; |
| 1100 |
} |
| 1101 |
|
| 1102 |
if (errno == ERANGE) |
| 1103 |
{ |
| 1104 |
out_of_range_header (keyword, arg, minval, maxval); |
| 1105 |
return false; |
| 1106 |
} |
| 1107 |
|
| 1108 |
*num = u; |
| 1109 |
return true; |
| 1110 |
} |
| 1111 |
|
| 1112 |
static bool |
| 1113 |
decode_num (uintmax_t *num, char const *arg, uintmax_t maxval, |
| 1114 |
char const *keyword) |
| 1115 |
{ |
| 1116 |
intmax_t i; |
| 1117 |
if (! decode_signed_num (&i, arg, 0, maxval, keyword)) |
| 1118 |
return false; |
| 1119 |
*num = i; |
| 1120 |
return true; |
| 1121 |
} |
| 1122 |
|
| 1123 |
static void |
| 1124 |
dummy_coder (MAYBE_UNUSED struct tar_stat_info const *st, |
| 1125 |
MAYBE_UNUSED char const *keyword, |
| 1126 |
MAYBE_UNUSED struct xheader *xhdr, |
| 1127 |
MAYBE_UNUSED void const *data) |
| 1128 |
{ |
| 1129 |
} |
| 1130 |
|
| 1131 |
static void |
| 1132 |
dummy_decoder (MAYBE_UNUSED struct tar_stat_info *st, |
| 1133 |
MAYBE_UNUSED char const *keyword, |
| 1134 |
MAYBE_UNUSED char const *arg, |
| 1135 |
MAYBE_UNUSED size_t size) |
| 1136 |
{ |
| 1137 |
} |
| 1138 |
|
| 1139 |
static void |
| 1140 |
atime_coder (struct tar_stat_info const *st, char const *keyword, |
| 1141 |
struct xheader *xhdr, MAYBE_UNUSED void const *data) |
| 1142 |
{ |
| 1143 |
code_time (st->atime, keyword, xhdr); |
| 1144 |
} |
| 1145 |
|
| 1146 |
static void |
| 1147 |
atime_decoder (struct tar_stat_info *st, |
| 1148 |
char const *keyword, |
| 1149 |
char const *arg, |
| 1150 |
MAYBE_UNUSED size_t size) |
| 1151 |
{ |
| 1152 |
struct timespec ts; |
| 1153 |
if (decode_time (&ts, arg, keyword)) |
| 1154 |
st->atime = ts; |
| 1155 |
} |
| 1156 |
|
| 1157 |
static void |
| 1158 |
gid_coder (struct tar_stat_info const *st, char const *keyword, |
| 1159 |
struct xheader *xhdr, MAYBE_UNUSED void const *data) |
| 1160 |
{ |
| 1161 |
code_signed_num (st->stat.st_gid, keyword, |
| 1162 |
TYPE_MINIMUM (gid_t), TYPE_MAXIMUM (gid_t), xhdr); |
| 1163 |
} |
| 1164 |
|
| 1165 |
static void |
| 1166 |
gid_decoder (struct tar_stat_info *st, |
| 1167 |
char const *keyword, |
| 1168 |
char const *arg, |
| 1169 |
MAYBE_UNUSED size_t size) |
| 1170 |
{ |
| 1171 |
intmax_t u; |
| 1172 |
if (decode_signed_num (&u, arg, TYPE_MINIMUM (gid_t), |
| 1173 |
TYPE_MAXIMUM (gid_t), keyword)) |
| 1174 |
st->stat.st_gid = u; |
| 1175 |
} |
| 1176 |
|
| 1177 |
static void |
| 1178 |
gname_coder (struct tar_stat_info const *st, char const *keyword, |
| 1179 |
struct xheader *xhdr, MAYBE_UNUSED void const *data) |
| 1180 |
{ |
| 1181 |
code_string (st->gname, keyword, xhdr); |
| 1182 |
} |
| 1183 |
|
| 1184 |
static void |
| 1185 |
gname_decoder (struct tar_stat_info *st, |
| 1186 |
MAYBE_UNUSED char const *keyword, |
| 1187 |
char const *arg, |
| 1188 |
MAYBE_UNUSED size_t size) |
| 1189 |
{ |
| 1190 |
decode_string (&st->gname, arg); |
| 1191 |
} |
| 1192 |
|
| 1193 |
static void |
| 1194 |
linkpath_coder (struct tar_stat_info const *st, char const *keyword, |
| 1195 |
struct xheader *xhdr, MAYBE_UNUSED void const *data) |
| 1196 |
{ |
| 1197 |
code_string (st->link_name, keyword, xhdr); |
| 1198 |
} |
| 1199 |
|
| 1200 |
static void |
| 1201 |
linkpath_decoder (struct tar_stat_info *st, |
| 1202 |
MAYBE_UNUSED char const *keyword, |
| 1203 |
char const *arg, |
| 1204 |
MAYBE_UNUSED size_t size) |
| 1205 |
{ |
| 1206 |
decode_string (&st->link_name, arg); |
| 1207 |
} |
| 1208 |
|
| 1209 |
static void |
| 1210 |
ctime_coder (struct tar_stat_info const *st, char const *keyword, |
| 1211 |
struct xheader *xhdr, MAYBE_UNUSED void const *data) |
| 1212 |
{ |
| 1213 |
code_time (st->ctime, keyword, xhdr); |
| 1214 |
} |
| 1215 |
|
| 1216 |
static void |
| 1217 |
ctime_decoder (struct tar_stat_info *st, |
| 1218 |
char const *keyword, |
| 1219 |
char const *arg, |
| 1220 |
MAYBE_UNUSED size_t size) |
| 1221 |
{ |
| 1222 |
struct timespec ts; |
| 1223 |
if (decode_time (&ts, arg, keyword)) |
| 1224 |
st->ctime = ts; |
| 1225 |
} |
| 1226 |
|
| 1227 |
static void |
| 1228 |
mtime_coder (struct tar_stat_info const *st, char const *keyword, |
| 1229 |
struct xheader *xhdr, void const *data) |
| 1230 |
{ |
| 1231 |
struct timespec const *mtime = data; |
| 1232 |
code_time (mtime ? *mtime : st->mtime, keyword, xhdr); |
| 1233 |
} |
| 1234 |
|
| 1235 |
static void |
| 1236 |
mtime_decoder (struct tar_stat_info *st, |
| 1237 |
char const *keyword, |
| 1238 |
char const *arg, |
| 1239 |
MAYBE_UNUSED size_t size) |
| 1240 |
{ |
| 1241 |
struct timespec ts; |
| 1242 |
if (decode_time (&ts, arg, keyword)) |
| 1243 |
st->mtime = ts; |
| 1244 |
} |
| 1245 |
|
| 1246 |
static void |
| 1247 |
path_coder (struct tar_stat_info const *st, char const *keyword, |
| 1248 |
struct xheader *xhdr, MAYBE_UNUSED void const *data) |
| 1249 |
{ |
| 1250 |
code_string (st->file_name, keyword, xhdr); |
| 1251 |
} |
| 1252 |
|
| 1253 |
static void |
| 1254 |
raw_path_decoder (struct tar_stat_info *st, char const *arg) |
| 1255 |
{ |
| 1256 |
if (*arg) |
| 1257 |
{ |
| 1258 |
decode_string (&st->orig_file_name, arg); |
| 1259 |
decode_string (&st->file_name, arg); |
| 1260 |
st->had_trailing_slash = strip_trailing_slashes (st->file_name); |
| 1261 |
} |
| 1262 |
} |
| 1263 |
|
| 1264 |
|
| 1265 |
static void |
| 1266 |
path_decoder (struct tar_stat_info *st, |
| 1267 |
MAYBE_UNUSED char const *keyword, |
| 1268 |
char const *arg, |
| 1269 |
MAYBE_UNUSED size_t size) |
| 1270 |
{ |
| 1271 |
if (! st->sparse_name_done) |
| 1272 |
raw_path_decoder (st, arg); |
| 1273 |
} |
| 1274 |
|
| 1275 |
static void |
| 1276 |
sparse_path_decoder (struct tar_stat_info *st, |
| 1277 |
MAYBE_UNUSED char const *keyword, |
| 1278 |
char const *arg, |
| 1279 |
MAYBE_UNUSED size_t size) |
| 1280 |
{ |
| 1281 |
st->sparse_name_done = true; |
| 1282 |
raw_path_decoder (st, arg); |
| 1283 |
} |
| 1284 |
|
| 1285 |
static void |
| 1286 |
size_coder (struct tar_stat_info const *st, char const *keyword, |
| 1287 |
struct xheader *xhdr, MAYBE_UNUSED void const *data) |
| 1288 |
{ |
| 1289 |
code_num (st->stat.st_size, keyword, xhdr); |
| 1290 |
} |
| 1291 |
|
| 1292 |
static void |
| 1293 |
size_decoder (struct tar_stat_info *st, |
| 1294 |
char const *keyword, |
| 1295 |
char const *arg, |
| 1296 |
MAYBE_UNUSED size_t size) |
| 1297 |
{ |
| 1298 |
uintmax_t u; |
| 1299 |
if (decode_num (&u, arg, TYPE_MAXIMUM (off_t), keyword)) |
| 1300 |
st->stat.st_size = u; |
| 1301 |
} |
| 1302 |
|
| 1303 |
static void |
| 1304 |
uid_coder (struct tar_stat_info const *st, char const *keyword, |
| 1305 |
struct xheader *xhdr, MAYBE_UNUSED void const *data) |
| 1306 |
{ |
| 1307 |
code_signed_num (st->stat.st_uid, keyword, |
| 1308 |
TYPE_MINIMUM (uid_t), TYPE_MAXIMUM (uid_t), xhdr); |
| 1309 |
} |
| 1310 |
|
| 1311 |
static void |
| 1312 |
uid_decoder (struct tar_stat_info *st, |
| 1313 |
char const *keyword, |
| 1314 |
char const *arg, |
| 1315 |
MAYBE_UNUSED size_t size) |
| 1316 |
{ |
| 1317 |
intmax_t u; |
| 1318 |
if (decode_signed_num (&u, arg, TYPE_MINIMUM (uid_t), |
| 1319 |
TYPE_MAXIMUM (uid_t), keyword)) |
| 1320 |
st->stat.st_uid = u; |
| 1321 |
} |
| 1322 |
|
| 1323 |
static void |
| 1324 |
uname_coder (struct tar_stat_info const *st, char const *keyword, |
| 1325 |
struct xheader *xhdr, MAYBE_UNUSED void const *data) |
| 1326 |
{ |
| 1327 |
code_string (st->uname, keyword, xhdr); |
| 1328 |
} |
| 1329 |
|
| 1330 |
static void |
| 1331 |
uname_decoder (struct tar_stat_info *st, |
| 1332 |
MAYBE_UNUSED char const *keyword, |
| 1333 |
char const *arg, |
| 1334 |
MAYBE_UNUSED size_t size) |
| 1335 |
{ |
| 1336 |
decode_string (&st->uname, arg); |
| 1337 |
} |
| 1338 |
|
| 1339 |
static void |
| 1340 |
sparse_size_coder (struct tar_stat_info const *st, char const *keyword, |
| 1341 |
struct xheader *xhdr, void const *data) |
| 1342 |
{ |
| 1343 |
size_coder (st, keyword, xhdr, data); |
| 1344 |
} |
| 1345 |
|
| 1346 |
static void |
| 1347 |
sparse_size_decoder (struct tar_stat_info *st, |
| 1348 |
char const *keyword, |
| 1349 |
char const *arg, |
| 1350 |
MAYBE_UNUSED size_t size) |
| 1351 |
{ |
| 1352 |
uintmax_t u; |
| 1353 |
if (decode_num (&u, arg, TYPE_MAXIMUM (off_t), keyword)) |
| 1354 |
{ |
| 1355 |
st->real_size_set = true; |
| 1356 |
st->real_size = u; |
| 1357 |
} |
| 1358 |
} |
| 1359 |
|
| 1360 |
static void |
| 1361 |
sparse_numblocks_coder (struct tar_stat_info const *st, char const *keyword, |
| 1362 |
struct xheader *xhdr, |
| 1363 |
MAYBE_UNUSED void const *data) |
| 1364 |
{ |
| 1365 |
code_num (st->sparse_map_avail, keyword, xhdr); |
| 1366 |
} |
| 1367 |
|
| 1368 |
static void |
| 1369 |
sparse_numblocks_decoder (struct tar_stat_info *st, |
| 1370 |
char const *keyword, |
| 1371 |
char const *arg, |
| 1372 |
MAYBE_UNUSED size_t size) |
| 1373 |
{ |
| 1374 |
uintmax_t u; |
| 1375 |
if (decode_num (&u, arg, SIZE_MAX, keyword)) |
| 1376 |
{ |
| 1377 |
st->sparse_map_size = u; |
| 1378 |
st->sparse_map = xcalloc (u, sizeof st->sparse_map[0]); |
| 1379 |
st->sparse_map_avail = 0; |
| 1380 |
} |
| 1381 |
} |
| 1382 |
|
| 1383 |
static void |
| 1384 |
sparse_offset_coder (struct tar_stat_info const *st, char const *keyword, |
| 1385 |
struct xheader *xhdr, void const *data) |
| 1386 |
{ |
| 1387 |
size_t const *pi = data; |
| 1388 |
code_num (st->sparse_map[*pi].offset, keyword, xhdr); |
| 1389 |
} |
| 1390 |
|
| 1391 |
static void |
| 1392 |
sparse_offset_decoder (struct tar_stat_info *st, |
| 1393 |
char const *keyword, |
| 1394 |
char const *arg, |
| 1395 |
MAYBE_UNUSED size_t size) |
| 1396 |
{ |
| 1397 |
uintmax_t u; |
| 1398 |
if (decode_num (&u, arg, TYPE_MAXIMUM (off_t), keyword)) |
| 1399 |
{ |
| 1400 |
if (st->sparse_map_avail < st->sparse_map_size) |
| 1401 |
st->sparse_map[st->sparse_map_avail].offset = u; |
| 1402 |
else |
| 1403 |
ERROR ((0, 0, _("Malformed extended header: excess %s=%s"), |
| 1404 |
"GNU.sparse.offset", arg)); |
| 1405 |
} |
| 1406 |
} |
| 1407 |
|
| 1408 |
static void |
| 1409 |
sparse_numbytes_coder (struct tar_stat_info const *st, char const *keyword, |
| 1410 |
struct xheader *xhdr, void const *data) |
| 1411 |
{ |
| 1412 |
size_t const *pi = data; |
| 1413 |
code_num (st->sparse_map[*pi].numbytes, keyword, xhdr); |
| 1414 |
} |
| 1415 |
|
| 1416 |
static void |
| 1417 |
sparse_numbytes_decoder (struct tar_stat_info *st, |
| 1418 |
char const *keyword, |
| 1419 |
char const *arg, |
| 1420 |
MAYBE_UNUSED size_t size) |
| 1421 |
{ |
| 1422 |
uintmax_t u; |
| 1423 |
if (decode_num (&u, arg, TYPE_MAXIMUM (off_t), keyword)) |
| 1424 |
{ |
| 1425 |
if (st->sparse_map_avail < st->sparse_map_size) |
| 1426 |
st->sparse_map[st->sparse_map_avail++].numbytes = u; |
| 1427 |
else |
| 1428 |
ERROR ((0, 0, _("Malformed extended header: excess %s=%s"), |
| 1429 |
keyword, arg)); |
| 1430 |
} |
| 1431 |
} |
| 1432 |
|
| 1433 |
static void |
| 1434 |
sparse_map_decoder (struct tar_stat_info *st, |
| 1435 |
char const *keyword, |
| 1436 |
char const *arg, |
| 1437 |
MAYBE_UNUSED size_t size) |
| 1438 |
{ |
| 1439 |
int offset = 1; |
| 1440 |
struct sp_array e; |
| 1441 |
|
| 1442 |
st->sparse_map_avail = 0; |
| 1443 |
while (1) |
| 1444 |
{ |
| 1445 |
intmax_t u; |
| 1446 |
char *delim; |
| 1447 |
|
| 1448 |
if (!ISDIGIT (*arg)) |
| 1449 |
{ |
| 1450 |
ERROR ((0, 0, _("Malformed extended header: invalid %s=%s"), |
| 1451 |
keyword, arg)); |
| 1452 |
return; |
| 1453 |
} |
| 1454 |
|
| 1455 |
errno = 0; |
| 1456 |
u = strtoimax (arg, &delim, 10); |
| 1457 |
if (TYPE_MAXIMUM (off_t) < u) |
| 1458 |
{ |
| 1459 |
u = TYPE_MAXIMUM (off_t); |
| 1460 |
errno = ERANGE; |
| 1461 |
} |
| 1462 |
if (offset) |
| 1463 |
{ |
| 1464 |
e.offset = u; |
| 1465 |
if (errno == ERANGE) |
| 1466 |
{ |
| 1467 |
out_of_range_header (keyword, arg, 0, TYPE_MAXIMUM (off_t)); |
| 1468 |
return; |
| 1469 |
} |
| 1470 |
} |
| 1471 |
else |
| 1472 |
{ |
| 1473 |
e.numbytes = u; |
| 1474 |
if (errno == ERANGE) |
| 1475 |
{ |
| 1476 |
out_of_range_header (keyword, arg, 0, TYPE_MAXIMUM (off_t)); |
| 1477 |
return; |
| 1478 |
} |
| 1479 |
if (st->sparse_map_avail < st->sparse_map_size) |
| 1480 |
st->sparse_map[st->sparse_map_avail++] = e; |
| 1481 |
else |
| 1482 |
{ |
| 1483 |
ERROR ((0, 0, _("Malformed extended header: excess %s=%s"), |
| 1484 |
keyword, arg)); |
| 1485 |
return; |
| 1486 |
} |
| 1487 |
} |
| 1488 |
|
| 1489 |
offset = !offset; |
| 1490 |
|
| 1491 |
if (*delim == 0) |
| 1492 |
break; |
| 1493 |
else if (*delim != ',') |
| 1494 |
{ |
| 1495 |
ERROR ((0, 0, |
| 1496 |
_("Malformed extended header: invalid %s: unexpected delimiter %c"), |
| 1497 |
keyword, *delim)); |
| 1498 |
return; |
| 1499 |
} |
| 1500 |
|
| 1501 |
arg = delim + 1; |
| 1502 |
} |
| 1503 |
|
| 1504 |
if (!offset) |
| 1505 |
ERROR ((0, 0, |
| 1506 |
_("Malformed extended header: invalid %s: odd number of values"), |
| 1507 |
keyword)); |
| 1508 |
} |
| 1509 |
|
| 1510 |
static void |
| 1511 |
dumpdir_coder (MAYBE_UNUSED struct tar_stat_info const *st, char const *keyword, |
| 1512 |
struct xheader *xhdr, void const *data) |
| 1513 |
{ |
| 1514 |
xheader_print_n (xhdr, keyword, data, dumpdir_size (data)); |
| 1515 |
} |
| 1516 |
|
| 1517 |
static void |
| 1518 |
dumpdir_decoder (struct tar_stat_info *st, |
| 1519 |
MAYBE_UNUSED char const *keyword, |
| 1520 |
char const *arg, |
| 1521 |
size_t size) |
| 1522 |
{ |
| 1523 |
st->dumpdir = xmalloc (size); |
| 1524 |
memcpy (st->dumpdir, arg, size); |
| 1525 |
} |
| 1526 |
|
| 1527 |
static void |
| 1528 |
volume_label_coder (MAYBE_UNUSED struct tar_stat_info const *st, |
| 1529 |
char const *keyword, |
| 1530 |
struct xheader *xhdr, void const *data) |
| 1531 |
{ |
| 1532 |
code_string (data, keyword, xhdr); |
| 1533 |
} |
| 1534 |
|
| 1535 |
static void |
| 1536 |
volume_label_decoder (MAYBE_UNUSED struct tar_stat_info *st, |
| 1537 |
MAYBE_UNUSED char const *keyword, |
| 1538 |
char const *arg, |
| 1539 |
MAYBE_UNUSED size_t size) |
| 1540 |
{ |
| 1541 |
decode_string (&volume_label, arg); |
| 1542 |
} |
| 1543 |
|
| 1544 |
static void |
| 1545 |
volume_size_coder (MAYBE_UNUSED struct tar_stat_info const *st, |
| 1546 |
char const *keyword, |
| 1547 |
struct xheader *xhdr, void const *data) |
| 1548 |
{ |
| 1549 |
off_t const *v = data; |
| 1550 |
code_num (*v, keyword, xhdr); |
| 1551 |
} |
| 1552 |
|
| 1553 |
static void |
| 1554 |
volume_size_decoder (MAYBE_UNUSED struct tar_stat_info *st, |
| 1555 |
char const *keyword, |
| 1556 |
char const *arg, MAYBE_UNUSED size_t size) |
| 1557 |
{ |
| 1558 |
uintmax_t u; |
| 1559 |
if (decode_num (&u, arg, TYPE_MAXIMUM (uintmax_t), keyword)) |
| 1560 |
continued_file_size = u; |
| 1561 |
} |
| 1562 |
|
| 1563 |
/* FIXME: Merge with volume_size_coder */ |
| 1564 |
static void |
| 1565 |
volume_offset_coder (MAYBE_UNUSED struct tar_stat_info const *st, |
| 1566 |
char const *keyword, |
| 1567 |
struct xheader *xhdr, void const *data) |
| 1568 |
{ |
| 1569 |
off_t const *v = data; |
| 1570 |
code_num (*v, keyword, xhdr); |
| 1571 |
} |
| 1572 |
|
| 1573 |
static void |
| 1574 |
volume_offset_decoder (MAYBE_UNUSED struct tar_stat_info *st, |
| 1575 |
char const *keyword, |
| 1576 |
char const *arg, MAYBE_UNUSED size_t size) |
| 1577 |
{ |
| 1578 |
uintmax_t u; |
| 1579 |
if (decode_num (&u, arg, TYPE_MAXIMUM (uintmax_t), keyword)) |
| 1580 |
continued_file_offset = u; |
| 1581 |
} |
| 1582 |
|
| 1583 |
static void |
| 1584 |
volume_filename_decoder (MAYBE_UNUSED struct tar_stat_info *st, |
| 1585 |
MAYBE_UNUSED char const *keyword, |
| 1586 |
char const *arg, |
| 1587 |
MAYBE_UNUSED size_t size) |
| 1588 |
{ |
| 1589 |
decode_string (&continued_file_name, arg); |
| 1590 |
} |
| 1591 |
|
| 1592 |
static void |
| 1593 |
xattr_selinux_coder (struct tar_stat_info const *st, char const *keyword, |
| 1594 |
struct xheader *xhdr, MAYBE_UNUSED void const *data) |
| 1595 |
{ |
| 1596 |
code_string (st->cntx_name, keyword, xhdr); |
| 1597 |
} |
| 1598 |
|
| 1599 |
static void |
| 1600 |
xattr_selinux_decoder (struct tar_stat_info *st, |
| 1601 |
MAYBE_UNUSED char const *keyword, char const *arg, |
| 1602 |
MAYBE_UNUSED size_t size) |
| 1603 |
{ |
| 1604 |
decode_string (&st->cntx_name, arg); |
| 1605 |
} |
| 1606 |
|
| 1607 |
static void |
| 1608 |
xattr_acls_a_coder (struct tar_stat_info const *st , char const *keyword, |
| 1609 |
struct xheader *xhdr, MAYBE_UNUSED void const *data) |
| 1610 |
{ |
| 1611 |
xheader_print_n (xhdr, keyword, st->acls_a_ptr, st->acls_a_len); |
| 1612 |
} |
| 1613 |
|
| 1614 |
static void |
| 1615 |
xattr_acls_a_decoder (struct tar_stat_info *st, |
| 1616 |
MAYBE_UNUSED char const *keyword, |
| 1617 |
char const *arg, size_t size) |
| 1618 |
{ |
| 1619 |
st->acls_a_ptr = xmemdup (arg, size + 1); |
| 1620 |
st->acls_a_len = size; |
| 1621 |
} |
| 1622 |
|
| 1623 |
static void |
| 1624 |
xattr_acls_d_coder (struct tar_stat_info const *st , char const *keyword, |
| 1625 |
struct xheader *xhdr, MAYBE_UNUSED void const *data) |
| 1626 |
{ |
| 1627 |
xheader_print_n (xhdr, keyword, st->acls_d_ptr, st->acls_d_len); |
| 1628 |
} |
| 1629 |
|
| 1630 |
static void |
| 1631 |
xattr_acls_d_decoder (struct tar_stat_info *st, |
| 1632 |
MAYBE_UNUSED char const *keyword, char const *arg, |
| 1633 |
size_t size) |
| 1634 |
{ |
| 1635 |
st->acls_d_ptr = xmemdup (arg, size + 1); |
| 1636 |
st->acls_d_len = size; |
| 1637 |
} |
| 1638 |
|
| 1639 |
static void |
| 1640 |
xattr_coder (struct tar_stat_info const *st, char const *keyword, |
| 1641 |
struct xheader *xhdr, void const *data) |
| 1642 |
{ |
| 1643 |
size_t n = *(size_t *)data; |
| 1644 |
xheader_print_n (xhdr, keyword, |
| 1645 |
st->xattr_map.xm_map[n].xval_ptr, |
| 1646 |
st->xattr_map.xm_map[n].xval_len); |
| 1647 |
} |
| 1648 |
|
| 1649 |
static void |
| 1650 |
xattr_decoder (struct tar_stat_info *st, |
| 1651 |
char const *keyword, char const *arg, size_t size) |
| 1652 |
{ |
| 1653 |
char *xkey; |
| 1654 |
|
| 1655 |
/* copy keyword */ |
| 1656 |
xkey = xstrdup (keyword); |
| 1657 |
|
| 1658 |
xattr_decode_keyword (xkey); |
| 1659 |
|
| 1660 |
xattr_map_add (&st->xattr_map, xkey, arg, size); |
| 1661 |
|
| 1662 |
free (xkey); |
| 1663 |
} |
| 1664 |
|
| 1665 |
static void |
| 1666 |
sparse_major_coder (struct tar_stat_info const *st, char const *keyword, |
| 1667 |
struct xheader *xhdr, MAYBE_UNUSED void const *data) |
| 1668 |
{ |
| 1669 |
code_num (st->sparse_major, keyword, xhdr); |
| 1670 |
} |
| 1671 |
|
| 1672 |
static void |
| 1673 |
sparse_major_decoder (struct tar_stat_info *st, |
| 1674 |
char const *keyword, |
| 1675 |
char const *arg, |
| 1676 |
MAYBE_UNUSED size_t size) |
| 1677 |
{ |
| 1678 |
uintmax_t u; |
| 1679 |
if (decode_num (&u, arg, TYPE_MAXIMUM (unsigned), keyword)) |
| 1680 |
st->sparse_major = u; |
| 1681 |
} |
| 1682 |
|
| 1683 |
static void |
| 1684 |
sparse_minor_coder (struct tar_stat_info const *st, char const *keyword, |
| 1685 |
struct xheader *xhdr, MAYBE_UNUSED void const *data) |
| 1686 |
{ |
| 1687 |
code_num (st->sparse_minor, keyword, xhdr); |
| 1688 |
} |
| 1689 |
|
| 1690 |
static void |
| 1691 |
sparse_minor_decoder (struct tar_stat_info *st, |
| 1692 |
char const *keyword, |
| 1693 |
char const *arg, |
| 1694 |
MAYBE_UNUSED size_t size) |
| 1695 |
{ |
| 1696 |
uintmax_t u; |
| 1697 |
if (decode_num (&u, arg, TYPE_MAXIMUM (unsigned), keyword)) |
| 1698 |
st->sparse_minor = u; |
| 1699 |
} |
| 1700 |
|
| 1701 |
struct xhdr_tab const xhdr_tab[] = { |
| 1702 |
{ "atime", atime_coder, atime_decoder, 0, false }, |
| 1703 |
{ "comment", dummy_coder, dummy_decoder, 0, false }, |
| 1704 |
{ "charset", dummy_coder, dummy_decoder, 0, false }, |
| 1705 |
{ "ctime", ctime_coder, ctime_decoder, 0, false }, |
| 1706 |
{ "gid", gid_coder, gid_decoder, 0, false }, |
| 1707 |
{ "gname", gname_coder, gname_decoder, 0, false }, |
| 1708 |
{ "linkpath", linkpath_coder, linkpath_decoder, 0, false }, |
| 1709 |
{ "mtime", mtime_coder, mtime_decoder, 0, false }, |
| 1710 |
{ "path", path_coder, path_decoder, 0, false }, |
| 1711 |
{ "size", size_coder, size_decoder, 0, false }, |
| 1712 |
{ "uid", uid_coder, uid_decoder, 0, false }, |
| 1713 |
{ "uname", uname_coder, uname_decoder, 0, false }, |
| 1714 |
|
| 1715 |
/* Sparse file handling */ |
| 1716 |
{ "GNU.sparse.name", path_coder, sparse_path_decoder, |
| 1717 |
XHDR_PROTECTED, false }, |
| 1718 |
{ "GNU.sparse.major", sparse_major_coder, sparse_major_decoder, |
| 1719 |
XHDR_PROTECTED, false }, |
| 1720 |
{ "GNU.sparse.minor", sparse_minor_coder, sparse_minor_decoder, |
| 1721 |
XHDR_PROTECTED, false }, |
| 1722 |
{ "GNU.sparse.realsize", sparse_size_coder, sparse_size_decoder, |
| 1723 |
XHDR_PROTECTED, false }, |
| 1724 |
{ "GNU.sparse.numblocks", sparse_numblocks_coder, sparse_numblocks_decoder, |
| 1725 |
XHDR_PROTECTED, false }, |
| 1726 |
|
| 1727 |
/* tar 1.14 - 1.15.90 keywords. */ |
| 1728 |
{ "GNU.sparse.size", sparse_size_coder, sparse_size_decoder, |
| 1729 |
XHDR_PROTECTED, false }, |
| 1730 |
/* tar 1.14 - 1.15.1 keywords. Multiple instances of these appeared in 'x' |
| 1731 |
headers, and each of them was meaningful. It confilcted with POSIX specs, |
| 1732 |
which requires that "when extended header records conflict, the last one |
| 1733 |
given in the header shall take precedence." */ |
| 1734 |
{ "GNU.sparse.offset", sparse_offset_coder, sparse_offset_decoder, |
| 1735 |
XHDR_PROTECTED, false }, |
| 1736 |
{ "GNU.sparse.numbytes", sparse_numbytes_coder, sparse_numbytes_decoder, |
| 1737 |
XHDR_PROTECTED, false }, |
| 1738 |
/* tar 1.15.90 keyword, introduced to remove the above-mentioned conflict. */ |
| 1739 |
{ "GNU.sparse.map", NULL /* Unused, see pax_dump_header() */, |
| 1740 |
sparse_map_decoder, 0, false }, |
| 1741 |
|
| 1742 |
{ "GNU.dumpdir", dumpdir_coder, dumpdir_decoder, |
| 1743 |
XHDR_PROTECTED, false }, |
| 1744 |
|
| 1745 |
/* Keeps the tape/volume label. May be present only in the global headers. |
| 1746 |
Equivalent to GNUTYPE_VOLHDR. */ |
| 1747 |
{ "GNU.volume.label", volume_label_coder, volume_label_decoder, |
| 1748 |
XHDR_PROTECTED | XHDR_GLOBAL, false }, |
| 1749 |
|
| 1750 |
/* These may be present in a first global header of the archive. |
| 1751 |
They provide the same functionality as GNUTYPE_MULTIVOL header. |
| 1752 |
The GNU.volume.size keeps the real_s_sizeleft value, which is |
| 1753 |
otherwise kept in the size field of a multivolume header. The |
| 1754 |
GNU.volume.offset keeps the offset of the start of this volume, |
| 1755 |
otherwise kept in oldgnu_header.offset. */ |
| 1756 |
{ "GNU.volume.filename", volume_label_coder, volume_filename_decoder, |
| 1757 |
XHDR_PROTECTED | XHDR_GLOBAL, false }, |
| 1758 |
{ "GNU.volume.size", volume_size_coder, volume_size_decoder, |
| 1759 |
XHDR_PROTECTED | XHDR_GLOBAL, false }, |
| 1760 |
{ "GNU.volume.offset", volume_offset_coder, volume_offset_decoder, |
| 1761 |
XHDR_PROTECTED | XHDR_GLOBAL, false }, |
| 1762 |
|
| 1763 |
/* We get the SELinux value from filecon, so add a namespace for SELinux |
| 1764 |
instead of storing it in SCHILY.xattr.* (which would be RAW). */ |
| 1765 |
{ "RHT.security.selinux", |
| 1766 |
xattr_selinux_coder, xattr_selinux_decoder, 0, false }, |
| 1767 |
|
| 1768 |
/* ACLs, use the star format... */ |
| 1769 |
{ "SCHILY.acl.access", |
| 1770 |
xattr_acls_a_coder, xattr_acls_a_decoder, 0, false }, |
| 1771 |
|
| 1772 |
{ "SCHILY.acl.default", |
| 1773 |
xattr_acls_d_coder, xattr_acls_d_decoder, 0, false }, |
| 1774 |
|
| 1775 |
/* We are storing all extended attributes using this rule even if some of them |
| 1776 |
were stored by some previous rule (duplicates) -- we just have to make sure |
| 1777 |
they are restored *only once* during extraction later on. */ |
| 1778 |
{ "SCHILY.xattr", xattr_coder, xattr_decoder, 0, true }, |
| 1779 |
|
| 1780 |
{ NULL, NULL, NULL, 0, false } |
| 1781 |
}; |