diff --git a/usr.sbin/pw/pw.h b/usr.sbin/pw/pw.h index fde3ce3ef69d..d5e2c600079f 100644 --- a/usr.sbin/pw/pw.h +++ b/usr.sbin/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 diff --git a/usr.sbin/pw/pw_conf.c b/usr.sbin/pw/pw_conf.c index 36bb8b61e9d1..f7b98f188f77 100644 --- a/usr.sbin/pw/pw_conf.c +++ b/usr.sbin/pw/pw_conf.c @@ -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); diff --git a/usr.sbin/pw/pw_utils.c b/usr.sbin/pw/pw_utils.c index e4839779e15f..fbf4a3f5f560 100644 --- a/usr.sbin/pw/pw_utils.c +++ b/usr.sbin/pw/pw_utils.c @@ -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)); }