diff options
author | Erik Andersen <andersen@codepoet.org> | 2000-01-23 02:14:20 +0000 |
---|---|---|
committer | Erik Andersen <andersen@codepoet.org> | 2000-01-23 02:14:20 +0000 |
commit | 06936df16411fff0fdc338cae28385d66cabcef8 (patch) | |
tree | 570cf3d9aea702854ebc8cf65d02a6c85cca09fa | |
parent | de552874d2074ac48ea4b834d61c54e1b6971be3 (diff) | |
download | busybox-w32-06936df16411fff0fdc338cae28385d66cabcef8.tar.gz busybox-w32-06936df16411fff0fdc338cae28385d66cabcef8.tar.bz2 busybox-w32-06936df16411fff0fdc338cae28385d66cabcef8.zip |
Fix a bug where tar could change perms and ownership of dirs pointed
to by symlink within a tarball.
-Erik
-rw-r--r-- | Changelog | 4 | ||||
-rw-r--r-- | archival/tar.c | 27 | ||||
-rw-r--r-- | internal.h | 2 | ||||
-rw-r--r-- | tar.c | 27 | ||||
-rw-r--r-- | utility.c | 13 |
5 files changed, 47 insertions, 26 deletions
@@ -1,6 +1,8 @@ | |||
1 | 0.42 | 1 | 0.42 |
2 | * Made tar creation support in busybox tar optional. | 2 | * Made tar creation support in busybox tar optional. |
3 | You no longer _have_ to put a "-" in front of tar options. | 3 | * You no longer _have_ to put a "-" in front of tar options. |
4 | * Tar could inadvertently change permissions and ownership on | ||
5 | certain directories pointed to by symlinks. | ||
4 | * Made grep and grep -h do the right thing wrt printing | 6 | * Made grep and grep -h do the right thing wrt printing |
5 | the file name (it failed to print files names in many cases). | 7 | the file name (it failed to print files names in many cases). |
6 | * Fix a namespace aliasing problem wereby if du was built in, the | 8 | * Fix a namespace aliasing problem wereby if du was built in, the |
diff --git a/archival/tar.c b/archival/tar.c index adae6c94c..21ef24dcb 100644 --- a/archival/tar.c +++ b/archival/tar.c | |||
@@ -542,8 +542,10 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable) | |||
542 | printf ("x %s\n", outName); | 542 | printf ("x %s\n", outName); |
543 | 543 | ||
544 | if (hardLink) { | 544 | if (hardLink) { |
545 | if (link (hp->linkName, outName) < 0) | 545 | if (link (hp->linkName, outName) < 0) { |
546 | perror (outName); | 546 | perror (outName); |
547 | return; | ||
548 | } | ||
547 | /* Set the file time */ | 549 | /* Set the file time */ |
548 | utb.actime = mtime; | 550 | utb.actime = mtime; |
549 | utb.modtime = mtime; | 551 | utb.modtime = mtime; |
@@ -556,8 +558,10 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable) | |||
556 | 558 | ||
557 | if (softLink) { | 559 | if (softLink) { |
558 | #ifdef S_ISLNK | 560 | #ifdef S_ISLNK |
559 | if (symlink (hp->linkName, outName) < 0) | 561 | if (symlink (hp->linkName, outName) < 0) { |
560 | perror (outName); | 562 | perror (outName); |
563 | return; | ||
564 | } | ||
561 | /* Try to change ownership of the symlink. | 565 | /* Try to change ownership of the symlink. |
562 | * If libs doesn't support that, don't bother. | 566 | * If libs doesn't support that, don't bother. |
563 | * Changing the pointed-to file is the Wrong Thing(tm). | 567 | * Changing the pointed-to file is the Wrong Thing(tm). |
@@ -582,15 +586,16 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable) | |||
582 | * If the file is a directory, then just create the path. | 586 | * If the file is a directory, then just create the path. |
583 | */ | 587 | */ |
584 | if (S_ISDIR (mode)) { | 588 | if (S_ISDIR (mode)) { |
585 | createPath (outName, mode); | 589 | if (createPath (outName, mode)==TRUE) { |
586 | /* Set the file time */ | 590 | /* Set the file time */ |
587 | utb.actime = mtime; | 591 | utb.actime = mtime; |
588 | utb.modtime = mtime; | 592 | utb.modtime = mtime; |
589 | utime (outName, &utb); | 593 | utime (outName, &utb); |
590 | /* Set the file permissions */ | 594 | /* Set the file permissions */ |
591 | chown(outName, uid, gid); | 595 | chown(outName, uid, gid); |
592 | chmod(outName, mode); | 596 | chmod(outName, mode); |
593 | return; | 597 | return; |
598 | } | ||
594 | } | 599 | } |
595 | 600 | ||
596 | /* | 601 | /* |
diff --git a/internal.h b/internal.h index e57096d4a..2b07d672d 100644 --- a/internal.h +++ b/internal.h | |||
@@ -156,7 +156,7 @@ int recursiveAction(const char *fileName, int recurse, int followLinks, int dept | |||
156 | int (*dirAction) (const char *fileName, struct stat* statbuf)); | 156 | int (*dirAction) (const char *fileName, struct stat* statbuf)); |
157 | const char* timeString(time_t timeVal); | 157 | const char* timeString(time_t timeVal); |
158 | 158 | ||
159 | extern void createPath (const char *name, int mode); | 159 | extern int createPath (const char *name, int mode); |
160 | extern int parse_mode( const char* s, mode_t* theMode); | 160 | extern int parse_mode( const char* s, mode_t* theMode); |
161 | extern void usage(const char *usage) __attribute__ ((noreturn)); | 161 | extern void usage(const char *usage) __attribute__ ((noreturn)); |
162 | 162 | ||
@@ -542,8 +542,10 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable) | |||
542 | printf ("x %s\n", outName); | 542 | printf ("x %s\n", outName); |
543 | 543 | ||
544 | if (hardLink) { | 544 | if (hardLink) { |
545 | if (link (hp->linkName, outName) < 0) | 545 | if (link (hp->linkName, outName) < 0) { |
546 | perror (outName); | 546 | perror (outName); |
547 | return; | ||
548 | } | ||
547 | /* Set the file time */ | 549 | /* Set the file time */ |
548 | utb.actime = mtime; | 550 | utb.actime = mtime; |
549 | utb.modtime = mtime; | 551 | utb.modtime = mtime; |
@@ -556,8 +558,10 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable) | |||
556 | 558 | ||
557 | if (softLink) { | 559 | if (softLink) { |
558 | #ifdef S_ISLNK | 560 | #ifdef S_ISLNK |
559 | if (symlink (hp->linkName, outName) < 0) | 561 | if (symlink (hp->linkName, outName) < 0) { |
560 | perror (outName); | 562 | perror (outName); |
563 | return; | ||
564 | } | ||
561 | /* Try to change ownership of the symlink. | 565 | /* Try to change ownership of the symlink. |
562 | * If libs doesn't support that, don't bother. | 566 | * If libs doesn't support that, don't bother. |
563 | * Changing the pointed-to file is the Wrong Thing(tm). | 567 | * Changing the pointed-to file is the Wrong Thing(tm). |
@@ -582,15 +586,16 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable) | |||
582 | * If the file is a directory, then just create the path. | 586 | * If the file is a directory, then just create the path. |
583 | */ | 587 | */ |
584 | if (S_ISDIR (mode)) { | 588 | if (S_ISDIR (mode)) { |
585 | createPath (outName, mode); | 589 | if (createPath (outName, mode)==TRUE) { |
586 | /* Set the file time */ | 590 | /* Set the file time */ |
587 | utb.actime = mtime; | 591 | utb.actime = mtime; |
588 | utb.modtime = mtime; | 592 | utb.modtime = mtime; |
589 | utime (outName, &utb); | 593 | utime (outName, &utb); |
590 | /* Set the file permissions */ | 594 | /* Set the file permissions */ |
591 | chown(outName, uid, gid); | 595 | chown(outName, uid, gid); |
592 | chmod(outName, mode); | 596 | chmod(outName, mode); |
593 | return; | 597 | return; |
598 | } | ||
594 | } | 599 | } |
595 | 600 | ||
596 | /* | 601 | /* |
@@ -495,11 +495,12 @@ recursiveAction(const char *fileName, int recurse, int followLinks, int depthFir | |||
495 | * while all previous ones get default protections. Errors are not reported | 495 | * while all previous ones get default protections. Errors are not reported |
496 | * here, as failures to restore files can be reported later. | 496 | * here, as failures to restore files can be reported later. |
497 | */ | 497 | */ |
498 | extern void createPath (const char *name, int mode) | 498 | extern int createPath (const char *name, int mode) |
499 | { | 499 | { |
500 | char *cp; | 500 | char *cp; |
501 | char *cpOld; | 501 | char *cpOld; |
502 | char buf[NAME_MAX]; | 502 | char buf[NAME_MAX]; |
503 | int retVal=0; | ||
503 | 504 | ||
504 | strcpy( buf, name); | 505 | strcpy( buf, name); |
505 | cp = strchr (buf, '/'); | 506 | cp = strchr (buf, '/'); |
@@ -507,9 +508,17 @@ extern void createPath (const char *name, int mode) | |||
507 | cpOld = cp; | 508 | cpOld = cp; |
508 | cp = strchr (cp + 1, '/'); | 509 | cp = strchr (cp + 1, '/'); |
509 | *cpOld = '\0'; | 510 | *cpOld = '\0'; |
510 | mkdir (buf, cp ? 0777 : mode); | 511 | retVal = mkdir (buf, cp ? 0777 : mode); |
511 | *cpOld = '/'; | 512 | *cpOld = '/'; |
512 | } | 513 | } |
514 | /* Return the result from the final directory, as that | ||
515 | * is the one that counts */ | ||
516 | if( retVal!=0) { | ||
517 | if ( errno!=EEXIST) { | ||
518 | return( FALSE); | ||
519 | } | ||
520 | } | ||
521 | return( TRUE); | ||
513 | } | 522 | } |
514 | #endif | 523 | #endif |
515 | 524 | ||