Module Name: src
Committed By: chs
Date: Sat Dec 10 18:49:44 UTC 2022
Modified Files:
src/sbin/restore: dirs.c tape.c
Log Message:
apply this change from FreeBSD:
commit c028393d7072f1f88efd8d6e6c77bb9b15b3f3b6
Author: Kirk McKusick <[email protected]>
Date: Fri Apr 11 21:48:14 2008 +0000
Correctly set file group when restore is run by a user other than root.
To generate a diff of this commit:
cvs rdiff -u -r1.53 -r1.54 src/sbin/restore/dirs.c
cvs rdiff -u -r1.72 -r1.73 src/sbin/restore/tape.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sbin/restore/dirs.c
diff -u src/sbin/restore/dirs.c:1.53 src/sbin/restore/dirs.c:1.54
--- src/sbin/restore/dirs.c:1.53 Wed Jun 23 14:22:08 2021
+++ src/sbin/restore/dirs.c Sat Dec 10 18:49:44 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: dirs.c,v 1.53 2021/06/23 14:22:08 riastradh Exp $ */
+/* $NetBSD: dirs.c,v 1.54 2022/12/10 18:49:44 chs Exp $ */
/*
* Copyright (c) 1983, 1993
@@ -39,7 +39,7 @@
#if 0
static char sccsid[] = "@(#)dirs.c 8.7 (Berkeley) 5/1/95";
#else
-__RCSID("$NetBSD: dirs.c,v 1.53 2021/06/23 14:22:08 riastradh Exp $");
+__RCSID("$NetBSD: dirs.c,v 1.54 2022/12/10 18:49:44 chs Exp $");
#endif
#endif /* not lint */
@@ -598,6 +598,7 @@ setdirmodes(int flags)
struct entry *ep;
char *cp, *buf;
int bufsize;
+ uid_t myuid;
vprintf(stdout, "Set directory mode, owner, and times.\n");
if (command == 'r' || command == 'R')
@@ -618,6 +619,7 @@ setdirmodes(int flags)
clearerr(mf);
bufsize = 0;
buf = NULL;
+ myuid = getuid();
for (;;) {
(void) fread((char *)&node, 1, sizeof(struct modeinfo), mf);
if (ferror(mf)) {
@@ -683,10 +685,13 @@ setdirmodes(int flags)
"extended attributes for ", cp);
}
}
+ if (myuid != 0)
+ (void) chown(cp, myuid, node.gid);
+ else
+ (void) chown(cp, node.uid, node.gid);
+ (void) chmod(cp, node.mode);
(void) utimens(cp, node.ctimep);
(void) utimens(cp, node.mtimep);
- (void) chown(cp, node.uid, node.gid);
- (void) chmod(cp, node.mode);
if (Mtreefile) {
writemtree(cp, "dir",
node.uid, node.gid, node.mode,
Index: src/sbin/restore/tape.c
diff -u src/sbin/restore/tape.c:1.72 src/sbin/restore/tape.c:1.73
--- src/sbin/restore/tape.c:1.72 Thu May 5 07:45:43 2022
+++ src/sbin/restore/tape.c Sat Dec 10 18:49:44 2022
@@ -1,4 +1,4 @@
-/* $NetBSD: tape.c,v 1.72 2022/05/05 07:45:43 mrg Exp $ */
+/* $NetBSD: tape.c,v 1.73 2022/12/10 18:49:44 chs Exp $ */
/*
* Copyright (c) 1983, 1993
@@ -39,7 +39,7 @@
#if 0
static char sccsid[] = "@(#)tape.c 8.9 (Berkeley) 5/1/95";
#else
-__RCSID("$NetBSD: tape.c,v 1.72 2022/05/05 07:45:43 mrg Exp $");
+__RCSID("$NetBSD: tape.c,v 1.73 2022/12/10 18:49:44 chs Exp $");
#endif
#endif /* not lint */
@@ -656,7 +656,9 @@ extractfile(char *name)
ctimep[1].tv_nsec = curfile.birthtime_nsec;
}
extsize = curfile.extsize;
- uid = curfile.uid;
+ uid = getuid();
+ if (uid == 0)
+ uid = curfile.uid;
gid = curfile.gid;
mode = curfile.mode;
flags = curfile.file_flags;