Restore dd changes included accidentally in r308857.
This commit is contained in:
parent
9a8f61fb5b
commit
6193edf4c5
30
bin/dd/dd.c
30
bin/dd/dd.c
@ -48,10 +48,13 @@ __FBSDID("$FreeBSD$");
|
|||||||
#include <sys/param.h>
|
#include <sys/param.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/conf.h>
|
#include <sys/conf.h>
|
||||||
|
#include <sys/capsicum.h>
|
||||||
#include <sys/disklabel.h>
|
#include <sys/disklabel.h>
|
||||||
#include <sys/filio.h>
|
#include <sys/filio.h>
|
||||||
|
#include <sys/mtio.h>
|
||||||
|
|
||||||
#include <assert.h>
|
#include <assert.h>
|
||||||
|
#include <capsicum_helpers.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include <err.h>
|
#include <err.h>
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
@ -92,6 +95,10 @@ main(int argc __unused, char *argv[])
|
|||||||
jcl(argv);
|
jcl(argv);
|
||||||
setup();
|
setup();
|
||||||
|
|
||||||
|
caph_cache_catpages();
|
||||||
|
if (cap_enter() == -1 && errno != ENOSYS)
|
||||||
|
err(1, "unable to enter capability mode");
|
||||||
|
|
||||||
(void)signal(SIGINFO, siginfo_handler);
|
(void)signal(SIGINFO, siginfo_handler);
|
||||||
(void)signal(SIGINT, terminate);
|
(void)signal(SIGINT, terminate);
|
||||||
|
|
||||||
@ -125,6 +132,8 @@ static void
|
|||||||
setup(void)
|
setup(void)
|
||||||
{
|
{
|
||||||
u_int cnt;
|
u_int cnt;
|
||||||
|
cap_rights_t rights;
|
||||||
|
unsigned long cmds[] = { FIODTYPE, MTIOCTOP };
|
||||||
|
|
||||||
if (in.name == NULL) {
|
if (in.name == NULL) {
|
||||||
in.name = "stdin";
|
in.name = "stdin";
|
||||||
@ -133,13 +142,20 @@ setup(void)
|
|||||||
in.fd = open(in.name, O_RDONLY, 0);
|
in.fd = open(in.name, O_RDONLY, 0);
|
||||||
if (in.fd == -1)
|
if (in.fd == -1)
|
||||||
err(1, "%s", in.name);
|
err(1, "%s", in.name);
|
||||||
|
if (caph_limit_stdin() == -1)
|
||||||
|
err(1, "unable to limit capability rights");
|
||||||
}
|
}
|
||||||
|
|
||||||
getfdtype(&in);
|
getfdtype(&in);
|
||||||
|
|
||||||
|
cap_rights_init(&rights, CAP_READ, CAP_SEEK);
|
||||||
|
if (cap_rights_limit(in.fd, &rights) == -1 && errno != ENOSYS)
|
||||||
|
err(1, "unable to limit capability rights");
|
||||||
|
|
||||||
if (files_cnt > 1 && !(in.flags & ISTAPE))
|
if (files_cnt > 1 && !(in.flags & ISTAPE))
|
||||||
errx(1, "files is not supported for non-tape devices");
|
errx(1, "files is not supported for non-tape devices");
|
||||||
|
|
||||||
|
cap_rights_set(&rights, CAP_WRITE, CAP_FTRUNCATE, CAP_IOCTL);
|
||||||
if (out.name == NULL) {
|
if (out.name == NULL) {
|
||||||
/* No way to check for read access here. */
|
/* No way to check for read access here. */
|
||||||
out.fd = STDOUT_FILENO;
|
out.fd = STDOUT_FILENO;
|
||||||
@ -156,13 +172,27 @@ setup(void)
|
|||||||
if (out.fd == -1) {
|
if (out.fd == -1) {
|
||||||
out.fd = open(out.name, O_WRONLY | OFLAGS, DEFFILEMODE);
|
out.fd = open(out.name, O_WRONLY | OFLAGS, DEFFILEMODE);
|
||||||
out.flags |= NOREAD;
|
out.flags |= NOREAD;
|
||||||
|
cap_rights_clear(&rights, CAP_READ);
|
||||||
}
|
}
|
||||||
if (out.fd == -1)
|
if (out.fd == -1)
|
||||||
err(1, "%s", out.name);
|
err(1, "%s", out.name);
|
||||||
|
if (caph_limit_stdout() == -1)
|
||||||
|
err(1, "unable to limit capability rights");
|
||||||
}
|
}
|
||||||
|
|
||||||
getfdtype(&out);
|
getfdtype(&out);
|
||||||
|
|
||||||
|
if (cap_rights_limit(out.fd, &rights) == -1 && errno != ENOSYS)
|
||||||
|
err(1, "unable to limit capability rights");
|
||||||
|
if (cap_ioctls_limit(out.fd, cmds, nitems(cmds)) == -1 &&
|
||||||
|
errno != ENOSYS)
|
||||||
|
err(1, "unable to limit capability rights");
|
||||||
|
|
||||||
|
if (in.fd != STDERR_FILENO && out.fd != STDERR_FILENO) {
|
||||||
|
if (caph_limit_stderr() == -1)
|
||||||
|
err(1, "unable to limit capability rights");
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Allocate space for the input and output buffers. If not doing
|
* Allocate space for the input and output buffers. If not doing
|
||||||
* record oriented I/O, only need a single buffer.
|
* record oriented I/O, only need a single buffer.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user