Author: bapt
Date: Sun Jan 22 20:03:18 2017
New Revision: 312650
URL: https://svnweb.freebsd.org/changeset/base/312650

Log:
  Really restore the old behaviour for pw usermod -m
  
  It again reinstall missing skel files without overwriting changed one
  Add a regression test about it
  
  Reported by:  ae
  MFC after:    3 days

Modified:
  head/usr.sbin/pw/psdate.c
  head/usr.sbin/pw/pw_user.c
  head/usr.sbin/pw/tests/pw_usermod.sh

Modified: head/usr.sbin/pw/psdate.c
==============================================================================
--- head/usr.sbin/pw/psdate.c   Sun Jan 22 19:50:23 2017        (r312649)
+++ head/usr.sbin/pw/psdate.c   Sun Jan 22 20:03:18 2017        (r312650)
@@ -41,12 +41,8 @@ static const char rcsid[] =
 static int
 numerics(char const * str)
 {
-       int             rc = isdigit((unsigned char)*str);
 
-       if (rc)
-               while (isdigit((unsigned char)*str) || *str == 'x')
-                       ++str;
-       return rc && !*str;
+       return (str[strspn(str, "0123456789x")] == '\0');
 }
 
 static int

Modified: head/usr.sbin/pw/pw_user.c
==============================================================================
--- head/usr.sbin/pw/pw_user.c  Sun Jan 22 19:50:23 2017        (r312649)
+++ head/usr.sbin/pw/pw_user.c  Sun Jan 22 20:03:18 2017        (r312650)
@@ -1493,7 +1493,7 @@ pw_user_mod(int argc, char **argv, char 
        intmax_t id = -1;
        int ch, fd = -1;
        size_t i, j;
-       bool quiet, createhome, pretty, dryrun, nis, edited, docreatehome;
+       bool quiet, createhome, pretty, dryrun, nis, edited;
        bool precrypted;
        mode_t homemode = 0;
        time_t expire_days, password_days, now;
@@ -1503,7 +1503,7 @@ pw_user_mod(int argc, char **argv, char 
        passwd = NULL;
        class = nispasswd = NULL;
        quiet = createhome = pretty = dryrun = nis = precrypted = false;
-       edited = docreatehome = false;
+       edited = false;
 
        if (arg1 != NULL) {
                if (arg1[strspn(arg1, "0123456789")] == '\0')
@@ -1697,10 +1697,6 @@ pw_user_mod(int argc, char **argv, char 
                edited = true;
        }
 
-       if (createhome && fstatat(conf.rootfd, pwd->pw_dir, &st, 0) == -1) {
-               docreatehome = true;
-       }
-
        if (homedir && strcmp(pwd->pw_dir, homedir) != 0) {
                pwd->pw_dir = homedir;
                edited = true;
@@ -1708,8 +1704,6 @@ pw_user_mod(int argc, char **argv, char 
                        if (!createhome)
                                warnx("WARNING: home `%s' does not exist",
                                    pwd->pw_dir);
-                       else
-                               docreatehome = true;
                } else if (!S_ISDIR(st.st_mode)) {
                        warnx("WARNING: home `%s' is not a directory",
                            pwd->pw_dir);
@@ -1801,7 +1795,7 @@ pw_user_mod(int argc, char **argv, char 
         * that this also `works' for editing users if -m is used, but
         * existing files will *not* be overwritten.
         */
-       if (PWALTDIR() != PWF_ALT && docreatehome && pwd->pw_dir &&
+       if (PWALTDIR() != PWF_ALT && createhome && pwd->pw_dir &&
            *pwd->pw_dir == '/' && pwd->pw_dir[1]) {
                if (!skel)
                        skel = cnf->dotdir;

Modified: head/usr.sbin/pw/tests/pw_usermod.sh
==============================================================================
--- head/usr.sbin/pw/tests/pw_usermod.sh        Sun Jan 22 19:50:23 2017        
(r312649)
+++ head/usr.sbin/pw/tests/pw_usermod.sh        Sun Jan 22 20:03:18 2017        
(r312650)
@@ -253,6 +253,26 @@ user_mod_w_yes_body() {
                $(atf_get_srcdir)/crypt $passhash "foo"
 }
 
+atf_test_case user_mod_m
+user_mod_m_body() {
+       populate_root_etc_skel
+
+       mkdir -p ${HOME}/home
+       mkdir -p ${HOME}/skel
+       echo "entry" > ${HOME}/skel/.file
+       atf_check -s exit:0 ${RPW} useradd foo
+       ! test -d ${HOME}/home/foo || atf_fail "Directory should not have been 
created"
+       atf_check -s exit:0 ${RPW} usermod foo -m -k /skel
+       test -d ${HOME}/home/foo || atf_fail "Directory should have been 
created"
+       test -f ${HOME}/home/foo/.file || atf_fail "Skell files not added"
+       echo "entry" > ${HOME}/skel/.file2
+       atf_check -s exit:0 ${RPW} usermod foo -m -k /skel
+       test -f ${HOME}/home/foo/.file2 || atf_fail "Skell files not added"
+       echo > ${HOME}/home/foo/.file2
+       atf_check -s exit:0 ${RPW} usermod foo -m -k /skel
+       atf_check -s exit:0 -o inline:"\n" cat ${HOME}/home/foo/.file2
+}
+
 
 atf_init_test_cases() {
        atf_add_test_case user_mod
@@ -275,4 +295,5 @@ atf_init_test_cases() {
        atf_add_test_case user_mod_w_none
        atf_add_test_case user_mod_w_random
        atf_add_test_case user_mod_w_yes
+       atf_add_test_case user_mod_m
 }
_______________________________________________
svn-src-all@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to