From f6975773c5ebf939f9e3f22b2b600d2c821604bc Mon Sep 17 00:00:00 2001 From: Baptiste Daroussin Date: Sun, 12 Jul 2015 20:29:51 +0000 Subject: Rework the home directory creation and copy or the skel content to use *at functions This allows to simplify the code a bit for -R by not having to keep modifying path and also prepare the code to improve support -R in userdel While here, add regression tests for the functionality --- pw/pw.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'pw/pw.c') diff --git a/pw/pw.c b/pw/pw.c index 532d77b..d81cfb0 100644 --- a/pw/pw.c +++ b/pw/pw.c @@ -136,6 +136,7 @@ main(int argc, char *argv[]) name = NULL; relocated = nis = false; memset(&conf, 0, sizeof(conf)); + strlcpy(conf.rootdir, "/", sizeof(conf.rootdir)); strlcpy(conf.etcpath, _PATH_PWD, sizeof(conf.etcpath)); conf.fd = -1; @@ -215,6 +216,9 @@ main(int argc, char *argv[]) if (mode == -1 || which == -1) cmdhelp(mode, which); + conf.rootfd = open(conf.rootdir, O_DIRECTORY|O_CLOEXEC); + if (conf.rootfd == -1) + errx(EXIT_FAILURE, "Unable to open '%s'", conf.rootdir); conf.which = which; /* * We know which mode we're in and what we're about to do, so now -- cgit v1.2.3-56-ge451