diff options
author | Eric Andersen <andersen@codepoet.org> | 1999-11-29 04:29:13 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 1999-11-29 04:29:13 +0000 |
commit | 03018f7551377b944b85546c0b490740363c9f1e (patch) | |
tree | 72f3bfff8b6691e78f5ab467ff55e5756f247784 | |
parent | 1667fb4b633e8a250a17aea782baa18fc872d9d7 (diff) | |
download | busybox-w32-03018f7551377b944b85546c0b490740363c9f1e.tar.gz busybox-w32-03018f7551377b944b85546c0b490740363c9f1e.tar.bz2 busybox-w32-03018f7551377b944b85546c0b490740363c9f1e.zip |
Fixed tar so uid/gud/permissions on extracted tarballs will be correct.
-Erik
-rw-r--r-- | archival/tar.c | 34 | ||||
-rw-r--r-- | tar.c | 34 |
2 files changed, 50 insertions, 18 deletions
diff --git a/archival/tar.c b/archival/tar.c index bbd86628a..438770c03 100644 --- a/archival/tar.c +++ b/archival/tar.c | |||
@@ -382,8 +382,8 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable) | |||
382 | int uid; | 382 | int uid; |
383 | int gid; | 383 | int gid; |
384 | int checkSum; | 384 | int checkSum; |
385 | int major; | 385 | unsigned int major; |
386 | int minor; | 386 | unsigned int minor; |
387 | long size; | 387 | long size; |
388 | time_t mtime; | 388 | time_t mtime; |
389 | const char *name; | 389 | const char *name; |
@@ -488,10 +488,13 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable) | |||
488 | */ | 488 | */ |
489 | if (extractFlag==FALSE) { | 489 | if (extractFlag==FALSE) { |
490 | if (verboseFlag==TRUE) { | 490 | if (verboseFlag==TRUE) { |
491 | printf ("%s %3d/%-d %9ld %s %s", modeString (mode), | 491 | printf ("%s %3d/%-d ", modeString (mode), uid, gid); |
492 | uid, gid, size, timeString (mtime), name); | 492 | if( S_ISCHR (mode) || S_ISBLK (mode) ) |
493 | } else | 493 | printf ("%4d,%4d %s ", major,minor, timeString (mtime)); |
494 | printf ("%s", name); | 494 | else |
495 | printf ("%9ld %s ", size, timeString (mtime)); | ||
496 | } | ||
497 | printf ("%s", name); | ||
495 | 498 | ||
496 | if (hardLink) | 499 | if (hardLink) |
497 | printf (" (link to \"%s\")", hp->linkName); | 500 | printf (" (link to \"%s\")", hp->linkName); |
@@ -517,7 +520,8 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable) | |||
517 | if (hardLink) { | 520 | if (hardLink) { |
518 | if (link (hp->linkName, name) < 0) | 521 | if (link (hp->linkName, name) < 0) |
519 | perror (name); | 522 | perror (name); |
520 | 523 | chmod(name, mode); | |
524 | chown(name, uid, gid); | ||
521 | return; | 525 | return; |
522 | } | 526 | } |
523 | 527 | ||
@@ -525,24 +529,32 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable) | |||
525 | #ifdef S_ISLNK | 529 | #ifdef S_ISLNK |
526 | if (symlink (hp->linkName, name) < 0) | 530 | if (symlink (hp->linkName, name) < 0) |
527 | perror (name); | 531 | perror (name); |
532 | chmod(name, mode); | ||
533 | chown(name, uid, gid); | ||
528 | #else | 534 | #else |
529 | fprintf (stderr, "Cannot create symbolic links\n"); | 535 | fprintf (stderr, "Cannot create symbolic links\n"); |
530 | #endif | 536 | #endif |
531 | return; | 537 | return; |
532 | } | 538 | } |
533 | 539 | ||
540 | /* Set the umask for this process so it doesn't | ||
541 | * screw things up. */ | ||
542 | umask(0); | ||
543 | |||
534 | /* | 544 | /* |
535 | * If the file is a directory, then just create the path. | 545 | * If the file is a directory, then just create the path. |
536 | */ | 546 | */ |
537 | if (S_ISDIR (mode)) { | 547 | if (S_ISDIR (mode)) { |
538 | createPath (name, mode); | 548 | createPath (name, mode); |
549 | chmod(name, mode); | ||
550 | chown(name, uid, gid); | ||
539 | 551 | ||
540 | return; | 552 | return; |
541 | } | 553 | } |
542 | 554 | ||
543 | /* | 555 | /* |
544 | * There is a file to write. | 556 | * There is a file to write. |
545 | * First create the path to it if necessary with a default permission. | 557 | * First create the path to it if necessary with default permissions. |
546 | */ | 558 | */ |
547 | createPath (name, 0777); | 559 | createPath (name, 0777); |
548 | 560 | ||
@@ -572,6 +584,10 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable) | |||
572 | skipFileFlag = TRUE; | 584 | skipFileFlag = TRUE; |
573 | return; | 585 | return; |
574 | } | 586 | } |
587 | if (tostdoutFlag == FALSE) { | ||
588 | fchmod(outFd, mode); | ||
589 | fchown(outFd, uid, gid); | ||
590 | } | ||
575 | 591 | ||
576 | /* | 592 | /* |
577 | * If the file is empty, then that's all we need to do. | 593 | * If the file is empty, then that's all we need to do. |
@@ -672,7 +688,7 @@ static void writeTarFile (int fileCount, char **fileTable) | |||
672 | 688 | ||
673 | tarDev = statbuf.st_dev; | 689 | tarDev = statbuf.st_dev; |
674 | tarInode = statbuf.st_ino; | 690 | tarInode = statbuf.st_ino; |
675 | 691 | ||
676 | /* | 692 | /* |
677 | * Append each file name into the archive file. | 693 | * Append each file name into the archive file. |
678 | * Follow symbolic links for these top level file names. | 694 | * Follow symbolic links for these top level file names. |
@@ -382,8 +382,8 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable) | |||
382 | int uid; | 382 | int uid; |
383 | int gid; | 383 | int gid; |
384 | int checkSum; | 384 | int checkSum; |
385 | int major; | 385 | unsigned int major; |
386 | int minor; | 386 | unsigned int minor; |
387 | long size; | 387 | long size; |
388 | time_t mtime; | 388 | time_t mtime; |
389 | const char *name; | 389 | const char *name; |
@@ -488,10 +488,13 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable) | |||
488 | */ | 488 | */ |
489 | if (extractFlag==FALSE) { | 489 | if (extractFlag==FALSE) { |
490 | if (verboseFlag==TRUE) { | 490 | if (verboseFlag==TRUE) { |
491 | printf ("%s %3d/%-d %9ld %s %s", modeString (mode), | 491 | printf ("%s %3d/%-d ", modeString (mode), uid, gid); |
492 | uid, gid, size, timeString (mtime), name); | 492 | if( S_ISCHR (mode) || S_ISBLK (mode) ) |
493 | } else | 493 | printf ("%4d,%4d %s ", major,minor, timeString (mtime)); |
494 | printf ("%s", name); | 494 | else |
495 | printf ("%9ld %s ", size, timeString (mtime)); | ||
496 | } | ||
497 | printf ("%s", name); | ||
495 | 498 | ||
496 | if (hardLink) | 499 | if (hardLink) |
497 | printf (" (link to \"%s\")", hp->linkName); | 500 | printf (" (link to \"%s\")", hp->linkName); |
@@ -517,7 +520,8 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable) | |||
517 | if (hardLink) { | 520 | if (hardLink) { |
518 | if (link (hp->linkName, name) < 0) | 521 | if (link (hp->linkName, name) < 0) |
519 | perror (name); | 522 | perror (name); |
520 | 523 | chmod(name, mode); | |
524 | chown(name, uid, gid); | ||
521 | return; | 525 | return; |
522 | } | 526 | } |
523 | 527 | ||
@@ -525,24 +529,32 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable) | |||
525 | #ifdef S_ISLNK | 529 | #ifdef S_ISLNK |
526 | if (symlink (hp->linkName, name) < 0) | 530 | if (symlink (hp->linkName, name) < 0) |
527 | perror (name); | 531 | perror (name); |
532 | chmod(name, mode); | ||
533 | chown(name, uid, gid); | ||
528 | #else | 534 | #else |
529 | fprintf (stderr, "Cannot create symbolic links\n"); | 535 | fprintf (stderr, "Cannot create symbolic links\n"); |
530 | #endif | 536 | #endif |
531 | return; | 537 | return; |
532 | } | 538 | } |
533 | 539 | ||
540 | /* Set the umask for this process so it doesn't | ||
541 | * screw things up. */ | ||
542 | umask(0); | ||
543 | |||
534 | /* | 544 | /* |
535 | * If the file is a directory, then just create the path. | 545 | * If the file is a directory, then just create the path. |
536 | */ | 546 | */ |
537 | if (S_ISDIR (mode)) { | 547 | if (S_ISDIR (mode)) { |
538 | createPath (name, mode); | 548 | createPath (name, mode); |
549 | chmod(name, mode); | ||
550 | chown(name, uid, gid); | ||
539 | 551 | ||
540 | return; | 552 | return; |
541 | } | 553 | } |
542 | 554 | ||
543 | /* | 555 | /* |
544 | * There is a file to write. | 556 | * There is a file to write. |
545 | * First create the path to it if necessary with a default permission. | 557 | * First create the path to it if necessary with default permissions. |
546 | */ | 558 | */ |
547 | createPath (name, 0777); | 559 | createPath (name, 0777); |
548 | 560 | ||
@@ -572,6 +584,10 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable) | |||
572 | skipFileFlag = TRUE; | 584 | skipFileFlag = TRUE; |
573 | return; | 585 | return; |
574 | } | 586 | } |
587 | if (tostdoutFlag == FALSE) { | ||
588 | fchmod(outFd, mode); | ||
589 | fchown(outFd, uid, gid); | ||
590 | } | ||
575 | 591 | ||
576 | /* | 592 | /* |
577 | * If the file is empty, then that's all we need to do. | 593 | * If the file is empty, then that's all we need to do. |
@@ -672,7 +688,7 @@ static void writeTarFile (int fileCount, char **fileTable) | |||
672 | 688 | ||
673 | tarDev = statbuf.st_dev; | 689 | tarDev = statbuf.st_dev; |
674 | tarInode = statbuf.st_ino; | 690 | tarInode = statbuf.st_ino; |
675 | 691 | ||
676 | /* | 692 | /* |
677 | * Append each file name into the archive file. | 693 | * Append each file name into the archive file. |
678 | * Follow symbolic links for these top level file names. | 694 | * Follow symbolic links for these top level file names. |