summaryrefslogtreecommitdiffstats
path: root/sbin
diff options
context:
space:
mode:
authormaxim <maxim@FreeBSD.org>2006-08-25 05:46:47 +0000
committermaxim <maxim@FreeBSD.org>2006-08-25 05:46:47 +0000
commit73837f2df49445b9f599115029f3e2986e48e6de (patch)
treee5fadc0e629bb65ba5256679ba3decc9d0c15495 /sbin
parentd108c1d6d1c63e98fc2de27eb3fe5d4b2814ed7b (diff)
downloadFreeBSD-src-73837f2df49445b9f599115029f3e2986e48e6de.zip
FreeBSD-src-73837f2df49445b9f599115029f3e2986e48e6de.tar.gz
A bunch of fixes from NetBSD:
o Restore owner/group/mode/atime/mtime of symbolic links, rev. 1.30. o Extract file flags of symbolic link, rev. 1.42. o Call getfile() before altering file attributes. Open file with mode 0600 instead of 0666 so that file won't remain group or world readable/writable even if getfile() terminated. Move skipfile() before altering file attributes in IF{CHR,BLK} and IFIFO case for symmetry, rev. 1.32. o Use file mode 0600 when creating special file or fifo, revs. 1.33, 1.34. o Remove redundant -N check. PR: bin/101660 Submitted by: Andrey V. Elsukov Obtained from: NetBSD, enami@netbsd MFC after: 6 weeks
Diffstat (limited to 'sbin')
-rw-r--r--sbin/restore/tape.c40
1 files changed, 23 insertions, 17 deletions
diff --git a/sbin/restore/tape.c b/sbin/restore/tape.c
index 3245926..75cb5eb 100644
--- a/sbin/restore/tape.c
+++ b/sbin/restore/tape.c
@@ -551,6 +551,8 @@ int
extractfile(char *name)
{
int flags;
+ uid_t uid;
+ gid_t gid;
mode_t mode;
struct timeval mtimep[2], ctimep[2];
struct entry *ep;
@@ -565,6 +567,8 @@ extractfile(char *name)
ctimep[0].tv_usec = curfile.atime_nsec / 1000;
ctimep[1].tv_sec = curfile.birthtime_sec;
ctimep[1].tv_usec = curfile.birthtime_nsec / 1000;
+ uid = curfile.uid;
+ gid = curfile.gid;
mode = curfile.mode;
flags = curfile.file_flags;
switch (mode & IFMT) {
@@ -600,10 +604,11 @@ extractfile(char *name)
return (GOOD);
}
if (linkit(lnkbuf, name, SYMLINK) == GOOD) {
- (void) lchown(name, curfile.uid, curfile.gid);
+ (void) lchown(name, uid, gid);
(void) lchmod(name, mode);
(void) lutimes(name, ctimep);
(void) lutimes(name, mtimep);
+ (void) lchflags(name, flags);
return (GOOD);
}
return (FAIL);
@@ -614,20 +619,20 @@ extractfile(char *name)
skipfile();
return (GOOD);
}
- if (uflag && !Nflag)
- (void)unlink(name);
- if (mkfifo(name, mode) < 0) {
+ if (uflag)
+ (void) unlink(name);
+ if (mkfifo(name, 0600) < 0) {
fprintf(stderr, "%s: cannot create fifo: %s\n",
name, strerror(errno));
skipfile();
return (FAIL);
}
- (void) chown(name, curfile.uid, curfile.gid);
+ skipfile();
+ (void) chown(name, uid, gid);
(void) chmod(name, mode);
(void) utimes(name, ctimep);
(void) utimes(name, mtimep);
(void) chflags(name, flags);
- skipfile();
return (GOOD);
case IFCHR:
@@ -638,19 +643,20 @@ extractfile(char *name)
return (GOOD);
}
if (uflag)
- (void)unlink(name);
- if (mknod(name, mode, (int)curfile.rdev) < 0) {
+ (void) unlink(name);
+ if (mknod(name, (mode & (IFCHR | IFBLK)) | 0600,
+ (int)curfile.rdev) < 0) {
fprintf(stderr, "%s: cannot create special file: %s\n",
name, strerror(errno));
skipfile();
return (FAIL);
}
- (void) chown(name, curfile.uid, curfile.gid);
+ skipfile();
+ (void) chown(name, uid, gid);
(void) chmod(name, mode);
(void) utimes(name, ctimep);
(void) utimes(name, mtimep);
(void) chflags(name, flags);
- skipfile();
return (GOOD);
case IFREG:
@@ -660,21 +666,21 @@ extractfile(char *name)
return (GOOD);
}
if (uflag)
- (void)unlink(name);
+ (void) unlink(name);
if ((ofile = open(name, O_WRONLY | O_CREAT | O_TRUNC,
- 0666)) < 0) {
+ 0600)) < 0) {
fprintf(stderr, "%s: cannot create file: %s\n",
name, strerror(errno));
skipfile();
return (FAIL);
}
- (void) fchown(ofile, curfile.uid, curfile.gid);
- (void) fchmod(ofile, mode);
getfile(xtrfile, xtrskip);
+ (void) fchown(ofile, uid, gid);
+ (void) fchmod(ofile, mode);
+ (void) futimes(ofile, ctimep);
+ (void) futimes(ofile, mtimep);
+ (void) fchflags(ofile, flags);
(void) close(ofile);
- (void) utimes(name, ctimep);
- (void) utimes(name, mtimep);
- (void) chflags(name, flags);
return (GOOD);
}
/* NOTREACHED */
OpenPOWER on IntegriCloud