Prompt user before truncating a file to zero bytes. Bug #922.
This commit is contained in:
@@ -25,7 +25,7 @@
|
|||||||
.nr BA @BAMAN@
|
.nr BA @BAMAN@
|
||||||
.nr LC @LCMAN@
|
.nr LC @LCMAN@
|
||||||
.nr PS @PSMAN@
|
.nr PS @PSMAN@
|
||||||
.TH "SUDO" "@mansectsu@" "May 7, 2020" "Sudo @PACKAGE_VERSION@" "System Manager's Manual"
|
.TH "SUDO" "@mansectsu@" "July 22, 2020" "Sudo @PACKAGE_VERSION@" "System Manager's Manual"
|
||||||
.nh
|
.nh
|
||||||
.if n .ad l
|
.if n .ad l
|
||||||
.SH "NAME"
|
.SH "NAME"
|
||||||
@@ -354,6 +354,8 @@ If the specified file does not exist, it will be created.
|
|||||||
Note that unlike most commands run by
|
Note that unlike most commands run by
|
||||||
\fIsudo\fR,
|
\fIsudo\fR,
|
||||||
the editor is run with the invoking user's environment unmodified.
|
the editor is run with the invoking user's environment unmodified.
|
||||||
|
If the temporary file becomes empty after editing, the user will
|
||||||
|
be prompted before it is installed.
|
||||||
If, for some reason,
|
If, for some reason,
|
||||||
\fBsudo\fR
|
\fBsudo\fR
|
||||||
is unable to update a file with its edited version, the user will
|
is unable to update a file with its edited version, the user will
|
||||||
|
@@ -24,7 +24,7 @@
|
|||||||
.nr BA @BAMAN@
|
.nr BA @BAMAN@
|
||||||
.nr LC @LCMAN@
|
.nr LC @LCMAN@
|
||||||
.nr PS @PSMAN@
|
.nr PS @PSMAN@
|
||||||
.Dd May 7, 2020
|
.Dd July 22, 2020
|
||||||
.Dt SUDO @mansectsu@
|
.Dt SUDO @mansectsu@
|
||||||
.Os Sudo @PACKAGE_VERSION@
|
.Os Sudo @PACKAGE_VERSION@
|
||||||
.Sh NAME
|
.Sh NAME
|
||||||
@@ -336,6 +336,8 @@ If the specified file does not exist, it will be created.
|
|||||||
Note that unlike most commands run by
|
Note that unlike most commands run by
|
||||||
.Em sudo ,
|
.Em sudo ,
|
||||||
the editor is run with the invoking user's environment unmodified.
|
the editor is run with the invoking user's environment unmodified.
|
||||||
|
If the temporary file becomes empty after editing, the user will
|
||||||
|
be prompted before it is installed.
|
||||||
If, for some reason,
|
If, for some reason,
|
||||||
.Nm
|
.Nm
|
||||||
is unable to update a file with its edited version, the user will
|
is unable to update a file with its edited version, the user will
|
||||||
|
@@ -86,6 +86,17 @@ sudo_copy_file(const char *src, int src_fd, off_t src_len, const char *dst,
|
|||||||
ssize_t nwritten, nread;
|
ssize_t nwritten, nread;
|
||||||
debug_decl(sudo_copy_file, SUDO_DEBUG_UTIL);
|
debug_decl(sudo_copy_file, SUDO_DEBUG_UTIL);
|
||||||
|
|
||||||
|
/* Prompt the user before zeroing out an existing file. */
|
||||||
|
if (dst_len > 0 && src_len == 0) {
|
||||||
|
fprintf(stderr, U_("%s: truncate %s to zero bytes? (y/n) [n] "),
|
||||||
|
getprogname(), dst);
|
||||||
|
if (fgets(buf, sizeof(buf), stdin) == NULL ||
|
||||||
|
(buf[0] != 'y' && buf[0] != 'Y')) {
|
||||||
|
sudo_warnx(U_("not overwriting %s"), dst);
|
||||||
|
debug_return_int(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/* Extend the file to the new size if larger before copying. */
|
/* Extend the file to the new size if larger before copying. */
|
||||||
if (dst_len > 0 && src_len > dst_len) {
|
if (dst_len > 0 && src_len > dst_len) {
|
||||||
if (sudo_extend_file(dst_fd, dst, src_len) == -1)
|
if (sudo_extend_file(dst_fd, dst, src_len) == -1)
|
||||||
|
Reference in New Issue
Block a user