-/* $OpenBSD: extern.h,v 1.45 2021/02/18 16:23:17 claudio Exp $ */
+/* $OpenBSD: extern.h,v 1.46 2021/02/19 08:14:49 claudio Exp $ */
/*
* Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv>
*
void logx(const char *fmt, ...)
__attribute__((format(printf, 1, 2)));
-int mkpath(const char *);
+int mkpath(int, const char *);
#define RPKI_PATH_OUT_DIR "/var/db/rpki-client"
#define RPKI_PATH_BASE_DIR "/var/cache/rpki-client"
-/* $OpenBSD: main.c,v 1.101 2021/02/18 10:10:20 claudio Exp $ */
+/* $OpenBSD: main.c,v 1.102 2021/02/19 08:14:49 claudio Exp $ */
/*
* Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv>
*
#include <err.h>
#include <errno.h>
#include <dirent.h>
+#include <fcntl.h>
#include <fnmatch.h>
#include <fts.h>
#include <poll.h>
static struct filepath_tree fpt = RB_INITIALIZER(&fpt);
static struct msgbuf procq, rsyncq;
+static int cachefd;
const char *bird_tablename = "ROAS";
return;
}
+ /*
+ * Create destination location.
+ * Build up the tree to this point because GPL rsync(1)
+ * will not build the destination for us.
+ */
+
+ if (mkpath(cachefd, rp->local) == -1)
+ err(1, "%s", rp->local);
+
logx("%s: pulling from network", rp->local);
if ((b = ibuf_dynamic(256, UINT_MAX)) == NULL)
err(1, NULL);
}
static size_t
-repo_cleanup(const char *cachedir)
+repo_cleanup(int dirfd)
{
size_t i, delsz = 0;
char *argv[2], **del = NULL;
FTSENT *e;
/* change working directory to the cache directory */
- if (chdir(cachedir) == -1)
- err(1, "%s: chdir", cachedir);
+ if (fchdir(dirfd) == -1)
+ err(1, "fchdir");
for (i = 0; i < rt.reposz; i++) {
if (asprintf(&argv[0], "%s", rt.repos[i].local) == -1)
goto usage;
}
+ if ((cachefd = open(cachedir, O_RDONLY, 0)) == -1)
+ err(1, "cache directory %s", cachedir);
+
if (outformats == 0)
outformats = FORMAT_OPENBGPD;
close(fd[1]);
/* change working directory to the cache directory */
- if (chdir(cachedir) == -1)
- err(1, "%s: chdir", cachedir);
+ if (fchdir(cachefd) == -1)
+ err(1, "fchdir");
/* Only allow access to the cache directory. */
if (unveil(cachedir, "r") == -1)
close(fd[1]);
/* change working directory to the cache directory */
- if (chdir(cachedir) == -1)
- err(1, "%s: chdir", cachedir);
+ if (fchdir(cachefd) == -1)
+ err(1, "fchdir");
if (pledge("stdio rpath cpath proc exec unveil", NULL)
== -1)
if (outputfiles(&v, &stats))
rc = 1;
- stats.del_files = repo_cleanup(cachedir);
+ stats.del_files = repo_cleanup(cachefd);
logx("Route Origin Authorizations: %zu (%zu failed parse, %zu invalid)",
stats.roas, stats.roas_fail, stats.roas_invalid);
-/* $OpenBSD: mkdir.c,v 1.1 2021/02/02 18:33:11 claudio Exp $ */
+/* $OpenBSD: mkdir.c,v 1.2 2021/02/19 08:14:49 claudio Exp $ */
/*
* Copyright (c) 1983, 1992, 1993
* dir_mode - file mode of intermediate directories
*/
int
-mkpath(const char *dir)
+mkpath(int dirfd, const char *dir)
{
char *path, *slash;
int done;
done = (*slash == '\0');
*slash = '\0';
- if (mkdir(path, 0700) == -1 && errno != EEXIST) {
+ if (mkdirat(dirfd, path, 0700) == -1 && errno != EEXIST) {
free(path);
return (-1);
}
-/* $OpenBSD: rsync.c,v 1.17 2021/02/16 08:52:00 claudio Exp $ */
+/* $OpenBSD: rsync.c,v 1.18 2021/02/19 08:14:49 claudio Exp $ */
/*
* Copyright (c) 2019 Kristaps Dzonsons <kristaps@bsd.lv>
*
if (unveil(NULL, NULL) == -1)
err(1, "unveil");
- if (pledge("stdio cpath proc exec", NULL) == -1)
+ if (pledge("stdio proc exec", NULL) == -1)
err(1, "pledge");
/* Initialise retriever for children exiting. */
assert(dst);
assert(uri);
- /*
- * Create source and destination locations.
- * Build up the tree to this point because GPL rsync(1)
- * will not build the destination for us.
- */
-
- if (mkpath(dst) == -1)
- err(1, "%s", dst);
-
/* Run process itself, wait for exit, check error. */
if ((pid = fork()) == -1)