Changeset View
Changeset View
Standalone View
Standalone View
head/bin/dd/dd.c
Show First 20 Lines • Show All 136 Lines • ▼ Show 20 Lines | setup(void) | ||||
if (in.name == NULL) { | if (in.name == NULL) { | ||||
in.name = "stdin"; | in.name = "stdin"; | ||||
in.fd = STDIN_FILENO; | in.fd = STDIN_FILENO; | ||||
} else { | } else { | ||||
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); | cap_rights_init(&rights, CAP_READ, CAP_SEEK); | ||||
if (cap_rights_limit(in.fd, &rights) == -1 && errno != ENOSYS) | if (cap_rights_limit(in.fd, &rights) == -1 && errno != ENOSYS) | ||||
err(1, "unable to limit capability rights"); | err(1, "unable to limit capability rights"); | ||||
Show All 16 Lines | #define OFLAGS \ | ||||
*/ | */ | ||||
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); | 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) | if (cap_rights_limit(out.fd, &rights) == -1 && errno != ENOSYS) | ||||
err(1, "unable to limit capability rights"); | err(1, "unable to limit capability rights"); | ||||
if (cap_ioctls_limit(out.fd, cmds, nitems(cmds)) == -1 && | if (cap_ioctls_limit(out.fd, cmds, nitems(cmds)) == -1 && | ||||
errno != ENOSYS) | errno != ENOSYS) | ||||
err(1, "unable to limit capability rights"); | err(1, "unable to limit capability rights"); | ||||
if (in.fd != STDIN_FILENO && out.fd != STDIN_FILENO) { | |||||
if (caph_limit_stdin() == -1) | |||||
err(1, "unable to limit capability rights"); | |||||
} | |||||
if (in.fd != STDOUT_FILENO && out.fd != STDOUT_FILENO) { | |||||
if (caph_limit_stdout() == -1) | |||||
err(1, "unable to limit capability rights"); | |||||
} | |||||
if (in.fd != STDERR_FILENO && out.fd != STDERR_FILENO) { | if (in.fd != STDERR_FILENO && out.fd != STDERR_FILENO) { | ||||
if (caph_limit_stderr() == -1) | if (caph_limit_stderr() == -1) | ||||
err(1, "unable to limit capability rights"); | 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 | ||||
▲ Show 20 Lines • Show All 389 Lines • Show Last 20 Lines |