summaryrefslogtreecommitdiffstats
path: root/src/privsep.c
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2020-01-21 20:08:56 +0000
committerRoy Marples <roy@marples.name>2020-01-21 20:08:56 +0000
commit8a4cd387823dc5e122839af9d9463985cb99f383 (patch)
treeab7c08ca4294a4286b081d78ba35fc86966ba2fc /src/privsep.c
parent744a752ca1a4ad3373b4835e8d1d2c1367bf3da0 (diff)
downloaddhcpcd-8a4cd387823dc5e122839af9d9463985cb99f383.tar.xz
privsep: copy configuration file into chroot
Only if it has changed. Saves having to maintian it outside of dhcpcdm in a script or something.
Diffstat (limited to 'src/privsep.c')
-rw-r--r--src/privsep.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/privsep.c b/src/privsep.c
index e9ec25f2..ffd32de0 100644
--- a/src/privsep.c
+++ b/src/privsep.c
@@ -36,6 +36,7 @@
*/
#include <sys/socket.h>
+#include <sys/stat.h>
#include <sys/types.h>
#include <sys/wait.h>
@@ -69,9 +70,31 @@
#endif
int
+ps_mkdir(char *path)
+{
+ char *slash;
+ bool done;
+
+ slash = path;
+ for (;;) {
+ slash += strspn(slash, "/");
+ slash += strcspn(slash, "/");
+ done = (*slash == '\0');
+ *slash = '\0';
+ if (mkdir(path, 0755) == -1 && errno != EEXIST)
+ return -1;
+ if (done)
+ break;
+ *slash = '/';
+ }
+ return 0;
+}
+
+int
ps_init(struct dhcpcd_ctx *ctx)
{
struct passwd *pw;
+ char path[PATH_MAX];
errno = 0;
if ((pw = getpwnam(PRIVSEP_USER)) == NULL) {
@@ -85,6 +108,13 @@ ps_init(struct dhcpcd_ctx *ctx)
return -1;
}
+ /* Create the database directory. */
+ if (snprintf(path, sizeof(path), "%s%s", pw->pw_dir, DBDIR) == -1 ||
+ ps_mkdir(path) == -1 ||
+ chown(path, pw->pw_uid, pw->pw_gid) == -1 ||
+ chmod(path, 0755) == -1)
+ logerr("%s: %s", __func__, path);
+
ctx->options |= DHCPCD_PRIVSEP;
return 0;
}