Fixed tar so uid/gud/permissions on extracted tarballs will be correct.
-Erik
This commit is contained in:
parent
1667fb4b63
commit
03018f7551
@ -382,8 +382,8 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable)
|
|||||||
int uid;
|
int uid;
|
||||||
int gid;
|
int gid;
|
||||||
int checkSum;
|
int checkSum;
|
||||||
int major;
|
unsigned int major;
|
||||||
int minor;
|
unsigned int minor;
|
||||||
long size;
|
long size;
|
||||||
time_t mtime;
|
time_t mtime;
|
||||||
const char *name;
|
const char *name;
|
||||||
@ -488,10 +488,13 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable)
|
|||||||
*/
|
*/
|
||||||
if (extractFlag==FALSE) {
|
if (extractFlag==FALSE) {
|
||||||
if (verboseFlag==TRUE) {
|
if (verboseFlag==TRUE) {
|
||||||
printf ("%s %3d/%-d %9ld %s %s", modeString (mode),
|
printf ("%s %3d/%-d ", modeString (mode), uid, gid);
|
||||||
uid, gid, size, timeString (mtime), name);
|
if( S_ISCHR (mode) || S_ISBLK (mode) )
|
||||||
} else
|
printf ("%4d,%4d %s ", major,minor, timeString (mtime));
|
||||||
printf ("%s", name);
|
else
|
||||||
|
printf ("%9ld %s ", size, timeString (mtime));
|
||||||
|
}
|
||||||
|
printf ("%s", name);
|
||||||
|
|
||||||
if (hardLink)
|
if (hardLink)
|
||||||
printf (" (link to \"%s\")", hp->linkName);
|
printf (" (link to \"%s\")", hp->linkName);
|
||||||
@ -517,7 +520,8 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable)
|
|||||||
if (hardLink) {
|
if (hardLink) {
|
||||||
if (link (hp->linkName, name) < 0)
|
if (link (hp->linkName, name) < 0)
|
||||||
perror (name);
|
perror (name);
|
||||||
|
chmod(name, mode);
|
||||||
|
chown(name, uid, gid);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -525,24 +529,32 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable)
|
|||||||
#ifdef S_ISLNK
|
#ifdef S_ISLNK
|
||||||
if (symlink (hp->linkName, name) < 0)
|
if (symlink (hp->linkName, name) < 0)
|
||||||
perror (name);
|
perror (name);
|
||||||
|
chmod(name, mode);
|
||||||
|
chown(name, uid, gid);
|
||||||
#else
|
#else
|
||||||
fprintf (stderr, "Cannot create symbolic links\n");
|
fprintf (stderr, "Cannot create symbolic links\n");
|
||||||
#endif
|
#endif
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Set the umask for this process so it doesn't
|
||||||
|
* screw things up. */
|
||||||
|
umask(0);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If the file is a directory, then just create the path.
|
* If the file is a directory, then just create the path.
|
||||||
*/
|
*/
|
||||||
if (S_ISDIR (mode)) {
|
if (S_ISDIR (mode)) {
|
||||||
createPath (name, mode);
|
createPath (name, mode);
|
||||||
|
chmod(name, mode);
|
||||||
|
chown(name, uid, gid);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* There is a file to write.
|
* There is a file to write.
|
||||||
* First create the path to it if necessary with a default permission.
|
* First create the path to it if necessary with default permissions.
|
||||||
*/
|
*/
|
||||||
createPath (name, 0777);
|
createPath (name, 0777);
|
||||||
|
|
||||||
@ -572,6 +584,10 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable)
|
|||||||
skipFileFlag = TRUE;
|
skipFileFlag = TRUE;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (tostdoutFlag == FALSE) {
|
||||||
|
fchmod(outFd, mode);
|
||||||
|
fchown(outFd, uid, gid);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If the file is empty, then that's all we need to do.
|
* If the file is empty, then that's all we need to do.
|
||||||
@ -672,7 +688,7 @@ static void writeTarFile (int fileCount, char **fileTable)
|
|||||||
|
|
||||||
tarDev = statbuf.st_dev;
|
tarDev = statbuf.st_dev;
|
||||||
tarInode = statbuf.st_ino;
|
tarInode = statbuf.st_ino;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Append each file name into the archive file.
|
* Append each file name into the archive file.
|
||||||
* Follow symbolic links for these top level file names.
|
* Follow symbolic links for these top level file names.
|
||||||
|
34
tar.c
34
tar.c
@ -382,8 +382,8 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable)
|
|||||||
int uid;
|
int uid;
|
||||||
int gid;
|
int gid;
|
||||||
int checkSum;
|
int checkSum;
|
||||||
int major;
|
unsigned int major;
|
||||||
int minor;
|
unsigned int minor;
|
||||||
long size;
|
long size;
|
||||||
time_t mtime;
|
time_t mtime;
|
||||||
const char *name;
|
const char *name;
|
||||||
@ -488,10 +488,13 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable)
|
|||||||
*/
|
*/
|
||||||
if (extractFlag==FALSE) {
|
if (extractFlag==FALSE) {
|
||||||
if (verboseFlag==TRUE) {
|
if (verboseFlag==TRUE) {
|
||||||
printf ("%s %3d/%-d %9ld %s %s", modeString (mode),
|
printf ("%s %3d/%-d ", modeString (mode), uid, gid);
|
||||||
uid, gid, size, timeString (mtime), name);
|
if( S_ISCHR (mode) || S_ISBLK (mode) )
|
||||||
} else
|
printf ("%4d,%4d %s ", major,minor, timeString (mtime));
|
||||||
printf ("%s", name);
|
else
|
||||||
|
printf ("%9ld %s ", size, timeString (mtime));
|
||||||
|
}
|
||||||
|
printf ("%s", name);
|
||||||
|
|
||||||
if (hardLink)
|
if (hardLink)
|
||||||
printf (" (link to \"%s\")", hp->linkName);
|
printf (" (link to \"%s\")", hp->linkName);
|
||||||
@ -517,7 +520,8 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable)
|
|||||||
if (hardLink) {
|
if (hardLink) {
|
||||||
if (link (hp->linkName, name) < 0)
|
if (link (hp->linkName, name) < 0)
|
||||||
perror (name);
|
perror (name);
|
||||||
|
chmod(name, mode);
|
||||||
|
chown(name, uid, gid);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -525,24 +529,32 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable)
|
|||||||
#ifdef S_ISLNK
|
#ifdef S_ISLNK
|
||||||
if (symlink (hp->linkName, name) < 0)
|
if (symlink (hp->linkName, name) < 0)
|
||||||
perror (name);
|
perror (name);
|
||||||
|
chmod(name, mode);
|
||||||
|
chown(name, uid, gid);
|
||||||
#else
|
#else
|
||||||
fprintf (stderr, "Cannot create symbolic links\n");
|
fprintf (stderr, "Cannot create symbolic links\n");
|
||||||
#endif
|
#endif
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Set the umask for this process so it doesn't
|
||||||
|
* screw things up. */
|
||||||
|
umask(0);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If the file is a directory, then just create the path.
|
* If the file is a directory, then just create the path.
|
||||||
*/
|
*/
|
||||||
if (S_ISDIR (mode)) {
|
if (S_ISDIR (mode)) {
|
||||||
createPath (name, mode);
|
createPath (name, mode);
|
||||||
|
chmod(name, mode);
|
||||||
|
chown(name, uid, gid);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* There is a file to write.
|
* There is a file to write.
|
||||||
* First create the path to it if necessary with a default permission.
|
* First create the path to it if necessary with default permissions.
|
||||||
*/
|
*/
|
||||||
createPath (name, 0777);
|
createPath (name, 0777);
|
||||||
|
|
||||||
@ -572,6 +584,10 @@ readHeader (const TarHeader * hp, int fileCount, char **fileTable)
|
|||||||
skipFileFlag = TRUE;
|
skipFileFlag = TRUE;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (tostdoutFlag == FALSE) {
|
||||||
|
fchmod(outFd, mode);
|
||||||
|
fchown(outFd, uid, gid);
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If the file is empty, then that's all we need to do.
|
* If the file is empty, then that's all we need to do.
|
||||||
@ -672,7 +688,7 @@ static void writeTarFile (int fileCount, char **fileTable)
|
|||||||
|
|
||||||
tarDev = statbuf.st_dev;
|
tarDev = statbuf.st_dev;
|
||||||
tarInode = statbuf.st_ino;
|
tarInode = statbuf.st_ino;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Append each file name into the archive file.
|
* Append each file name into the archive file.
|
||||||
* Follow symbolic links for these top level file names.
|
* Follow symbolic links for these top level file names.
|
||||||
|
Loading…
Reference in New Issue
Block a user