]> git.cameronkatri.com Git - pw-darwin.git/commitdiff
pw: respect path specified using -V when writing pw.conf, and -C is not
authorYuri Pankov <yuripv@FreeBSD.org>
Mon, 15 Oct 2018 20:11:53 +0000 (20:11 +0000)
committerYuri Pankov <yuripv@FreeBSD.org>
Mon, 15 Oct 2018 20:11:53 +0000 (20:11 +0000)
explicitly specified.  -V path is already used to determine which file
to read default values from, so it's only logical to write them to the
same file.

PR: 231653
Reviewed by: eugen, bapt
Approved by: re (gjb), kib (mentor)
Differential Revision: https://reviews.freebsd.org/D17566

pw/pw.h
pw/pw_conf.c
pw/pw_utils.c

diff --git a/pw/pw.h b/pw/pw.h
index fde3ce3ef69db95f98ee523d65e94c2bfbdb8df1..d5e2c600079f141aac0a4c48a7a987e26b8fc7fc 100644 (file)
--- a/pw/pw.h
+++ b/pw/pw.h
@@ -64,6 +64,7 @@ enum _which
 };
 
 #define        _DEF_DIRMODE    (S_IRWXU | S_IRWXG | S_IRWXO)
+#define        _PW_CONF        "pw.conf"
 #define _PATH_PW_CONF  "/etc/pw.conf"
 #define _UC_MAXLINE    1024
 #define _UC_MAXSHELLS  32
index 36bb8b61e9d14b0e7b63d2b3034c9e72578db2b5..f7b98f188f7767a5cf6632e5b2e82782a6e7ca03 100644 (file)
@@ -417,9 +417,13 @@ write_userconfig(struct userconf *cnf, const char *file)
        int             i, j;
        struct sbuf     *buf;
        FILE           *fp;
+       char            cfgfile[MAXPATHLEN];
 
-       if (file == NULL)
-               file = _PATH_PW_CONF;
+       if (file == NULL) {
+               snprintf(cfgfile, sizeof(cfgfile), "%s/" _PW_CONF,
+                   conf.etcpath);
+               file = cfgfile;
+       }
 
        if ((fd = open(file, O_CREAT|O_RDWR|O_TRUNC|O_EXLOCK, 0644)) == -1)
                return (0);
index e4839779e15f05d0c490c22882df12a6bc87de86..fbf4a3f5f560c08773b473175ffbc5751265ef25 100644 (file)
@@ -71,7 +71,7 @@ get_userconfig(const char *config)
 
        if (config != NULL)
                return (read_userconfig(config));
-       snprintf(defaultcfg, sizeof(defaultcfg), "%s/pw.conf", conf.etcpath);
+       snprintf(defaultcfg, sizeof(defaultcfg), "%s/" _PW_CONF, conf.etcpath);
        return (read_userconfig(defaultcfg));
 }