]> git.cameronkatri.com Git - pw-darwin.git/blobdiff - pw/pw_user.c
Partially revert r367756 (chpass(1) synopsis changes)
[pw-darwin.git] / pw / pw_user.c
index b797c04ef445b6ac31cf514f15ef8c708f08dd6b..2eec317b5e5b55253d00fb0e887ce6b9ca743048 100644 (file)
@@ -589,7 +589,7 @@ print_user(struct passwd * pwd, bool pretty, bool v7)
        }
        if (pwd->pw_expire > (time_t)0 && (tptr = localtime(&pwd->pw_expire)) != NULL)
                strftime(acexpire, sizeof acexpire, "%c", tptr);
-               if (pwd->pw_change > (time_t)0 && (tptr = localtime(&pwd->pw_change)) != NULL)
+       if (pwd->pw_change > (time_t)0 && (tptr = localtime(&pwd->pw_change)) != NULL)
                strftime(pwexpire, sizeof pwexpire, "%c", tptr);
        printf("Login Name: %-15s   #%-12ju Group: %-15s   #%ju\n"
               " Full Name: %s\n"
@@ -632,7 +632,7 @@ pw_checkname(char *name, int gecos)
        reject = 0;
        if (gecos) {
                /* See if the name is valid as a gecos (comment) field. */
-               badchars = ":!@";
+               badchars = ":";
                showtype = "gecos field";
        } else {
                /* See if the name is valid as a userid or group. */
@@ -712,24 +712,24 @@ rmopie(char const * name)
 {
        char tmp[1014];
        FILE *fp;
-       int fd;
        size_t len;
-       off_t   atofs = 0;
-       
+       long atofs;
+       int fd;
+
        if ((fd = openat(conf.rootfd, "etc/opiekeys", O_RDWR)) == -1)
                return;
 
        fp = fdopen(fd, "r+");
        len = strlen(name);
 
-       while (fgets(tmp, sizeof(tmp), fp) != NULL) {
+       for (atofs = 0; fgets(tmp, sizeof(tmp), fp) != NULL && atofs >= 0;
+           atofs = ftell(fp)) {
                if (strncmp(name, tmp, len) == 0 && tmp[len]==' ') {
                        /* Comment username out */
                        if (fseek(fp, atofs, SEEK_SET) == 0)
                                fwrite("#", 1, 1, fp);
                        break;
                }
-               atofs = ftell(fp);
        }
        /*
         * If we got an error of any sort, don't update!
@@ -1385,11 +1385,12 @@ pw_user_add(int argc, char **argv, char *arg1)
        pwd->pw_uid = pw_uidpolicy(cmdcnf, id);
        pwd->pw_gid = pw_gidpolicy(cnf, grname, pwd->pw_name,
            (gid_t) pwd->pw_uid, dryrun);
-       
+
+       /* cmdcnf->password_days and cmdcnf->expire_days hold unixtime here */
        if (cmdcnf->password_days > 0)
-               pwd->pw_change = now + cmdcnf->password_days * 86400L;
+               pwd->pw_change = cmdcnf->password_days;
        if (cmdcnf->expire_days > 0)
-               pwd->pw_expire = now + cmdcnf->expire_days * 86400L;
+               pwd->pw_expire = cmdcnf->expire_days;
 
        pwd->pw_dir = pw_homepolicy(cmdcnf, homedir, pwd->pw_name);
        pwd->pw_shell = pw_shellpolicy(cmdcnf);
@@ -1523,9 +1524,9 @@ pw_user_mod(int argc, char **argv, char *arg1)
        bool quiet, createhome, pretty, dryrun, nis, edited;
        bool precrypted;
        mode_t homemode = 0;
-       time_t expire_days, password_days, now;
+       time_t expire_time, password_time, now;
 
-       expire_days = password_days = -1;
+       expire_time = password_time = -1;
        gecos = homedir = grname = name = newname = skel = shell =NULL;
        passwd = NULL;
        class = nispasswd = NULL;
@@ -1561,10 +1562,10 @@ pw_user_mod(int argc, char **argv, char *arg1)
                        homedir = optarg;
                        break;
                case 'e':
-                       expire_days = parse_date(now, optarg);
+                       expire_time = parse_date(now, optarg);
                        break;
                case 'p':
-                       password_days = parse_date(now, optarg);
+                       password_time = parse_date(now, optarg);
                        break;
                case 'g':
                        group_from_name_or_id(optarg);
@@ -1699,13 +1700,13 @@ pw_user_mod(int argc, char **argv, char *arg1)
        }
 
 
-       if (password_days >= 0) {
-               pwd->pw_change = now + password_days * 86400L;
+       if (password_time >= 0 && pwd->pw_change != password_time) {
+               pwd->pw_change = password_time;
                edited = true;
        }
 
-       if (expire_days >= 0) {
-               pwd->pw_expire = now + expire_days * 86400L;
+       if (expire_time >= 0 && pwd->pw_expire != expire_time) {
+               pwd->pw_expire = expire_time;
                edited = true;
        }