diff options
author | Claudio Jeker <claudio@cvs.openbsd.org> | 2021-05-17 11:59:10 +0000 |
---|---|---|
committer | Claudio Jeker <claudio@cvs.openbsd.org> | 2021-05-17 11:59:10 +0000 |
commit | 0b83a1437e20bfd43f3a3a22f845fa917b547b9d (patch) | |
tree | 28b70eac342769022dc7d94c1abfb6c4b369026c /usr.bin | |
parent | 949694e497d5eb6613ef91affabc7716ee884ec6 (diff) |
If pledge() or unveil() fails error out with ERR_IPC. Also error out in
the receiver when intial setup fails because of filesystem errors (unable
to open or create the base directory) or on memory failures.
OK benno@
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/rsync/client.c | 4 | ||||
-rw-r--r-- | usr.bin/rsync/receiver.c | 41 | ||||
-rw-r--r-- | usr.bin/rsync/server.c | 4 |
3 files changed, 19 insertions, 30 deletions
diff --git a/usr.bin/rsync/client.c b/usr.bin/rsync/client.c index 42e2628573b..129882230c8 100644 --- a/usr.bin/rsync/client.c +++ b/usr.bin/rsync/client.c @@ -1,4 +1,4 @@ -/* $Id: client.c,v 1.15 2019/05/08 20:00:25 benno Exp $ */ +/* $Id: client.c,v 1.16 2021/05/17 11:59:09 claudio Exp $ */ /* * Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv> * @@ -43,7 +43,7 @@ rsync_client(const struct opts *opts, int fd, const struct fargs *f) if (pledge("stdio unix rpath wpath cpath dpath fattr chown getpw unveil", NULL) == -1) - err(1, "pledge"); + err(ERR_IPC, "pledge"); memset(&sess, 0, sizeof(struct sess)); sess.opts = opts; diff --git a/usr.bin/rsync/receiver.c b/usr.bin/rsync/receiver.c index a7373fe6e25..054e62799a4 100644 --- a/usr.bin/rsync/receiver.c +++ b/usr.bin/rsync/receiver.c @@ -1,4 +1,4 @@ -/* $Id: receiver.c,v 1.26 2021/05/06 07:29:59 claudio Exp $ */ +/* $Id: receiver.c,v 1.27 2021/05/17 11:59:09 claudio Exp $ */ /* * Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv> @@ -20,6 +20,7 @@ #include <sys/stat.h> #include <assert.h> +#include <err.h> #include <errno.h> #include <fcntl.h> #include <inttypes.h> @@ -180,15 +181,12 @@ rsync_receiver(struct sess *sess, int fdin, int fdout, const char *root) struct upload *ul = NULL; mode_t oumask; - if (pledge("stdio unix rpath wpath cpath dpath fattr chown getpw unveil", NULL) == -1) { - ERR("pledge"); - goto out; - } + if (pledge("stdio unix rpath wpath cpath dpath fattr chown getpw unveil", NULL) == -1) + err(ERR_IPC, "pledge"); /* Client sends zero-length exclusions. */ - if (!sess->opts->server && - !io_write_int(sess, fdout, 0)) { + if (!sess->opts->server && !io_write_int(sess, fdout, 0)) { ERRX1("io_write_int"); goto out; } @@ -240,14 +238,10 @@ rsync_receiver(struct sess *sess, int fdin, int fdout, const char *root) */ if (!sess->opts->dry_run) { - if ((tofree = strdup(root)) == NULL) { - ERR("strdup"); - goto out; - } else if (mkpath(tofree) < 0) { - ERRX1("%s: mkpath", root); - free(tofree); - goto out; - } + if ((tofree = strdup(root)) == NULL) + err(ERR_NOMEM, NULL); + if (mkpath(tofree) < 0) + err(ERR_FILE_IO, "%s: mkpath", tofree); free(tofree); } @@ -260,10 +254,8 @@ rsync_receiver(struct sess *sess, int fdin, int fdout, const char *root) if (!sess->opts->dry_run) { dfd = open(root, O_RDONLY | O_DIRECTORY, 0); - if (dfd == -1) { - ERR("%s: open", root); - goto out; - } + if (dfd == -1) + err(ERR_FILE_IO, "%s: open", root); } /* @@ -285,13 +277,10 @@ rsync_receiver(struct sess *sess, int fdin, int fdout, const char *root) * writing into other parts of the file-system. */ - if (unveil(root, "rwc") == -1) { - ERR("%s: unveil", root); - goto out; - } else if (unveil(NULL, NULL) == -1) { - ERR("%s: unveil", root); - goto out; - } + if (unveil(root, "rwc") == -1) + err(ERR_IPC, "%s: unveil", root); + if (unveil(NULL, NULL) == -1) + err(ERR_IPC, "unveil"); /* If we have a local set, go for the deletion. */ diff --git a/usr.bin/rsync/server.c b/usr.bin/rsync/server.c index 2423637a276..0a4af893525 100644 --- a/usr.bin/rsync/server.c +++ b/usr.bin/rsync/server.c @@ -1,4 +1,4 @@ -/* $Id: server.c,v 1.12 2019/05/08 21:30:11 benno Exp $ */ +/* $Id: server.c,v 1.13 2021/05/17 11:59:09 claudio Exp $ */ /* * Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv> * @@ -57,7 +57,7 @@ rsync_server(const struct opts *opts, size_t argc, char *argv[]) if (pledge("stdio unix rpath wpath cpath dpath fattr chown getpw unveil", NULL) == -1) - err(1, "pledge"); + err(ERR_IPC, "pledge"); memset(&sess, 0, sizeof(struct sess)); sess.opts = opts; |