]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
lslogins: allow changing password changed and expiration time formats
authorSami Kerola <kerolasa@iki.fi>
Fri, 12 Dec 2014 22:46:04 +0000 (22:46 +0000)
committerSami Kerola <kerolasa@iki.fi>
Fri, 19 Dec 2014 09:11:02 +0000 (09:11 +0000)
The password change and expiry has are marked with resolution of a day,
so add a new short iso-8601 format.  With this system admins can easily
find users has not updated their password lately

$ lslogins --time-format=iso --user --output=pwd-change,user | sort -n

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
login-utils/lslogins.c

index 9929b147507666787ca1a4941beac332560fd2c1..f050595ea5ab5b92ea55ff6122039f9d7cee3102 100644 (file)
@@ -143,6 +143,7 @@ enum {
        TIME_SHORT,
        TIME_FULL,
        TIME_ISO,
+       TIME_ISO_SHORT,
 };
 
 /*
@@ -349,6 +350,9 @@ static char *make_time(int mode, time_t time)
        case TIME_ISO:
                strftime(buf, sizeof(buf), "%Y-%m-%dT%H:%M:%S%z", &tm);
                break;
+       case TIME_ISO_SHORT:
+               strftime(buf, sizeof(buf), "%Y-%m-%d", &tm);
+               break;
        default:
                errx(EXIT_FAILURE, _("unsupported time type"));
        }
@@ -693,7 +697,8 @@ static struct lslogins_user *get_user_info(struct lslogins_control *ctl, const c
                        break;
                case COL_PWD_EXPIR:
                        if (shadow && shadow->sp_expire >= 0)
-                               user->pwd_expire = make_time(TIME_SHORT,
+                               user->pwd_expire = make_time(ctl->time_mode == TIME_ISO ?
+                                               TIME_ISO_SHORT : ctl->time_mode,
                                                shadow->sp_expire * 86400);
                        break;
                case COL_PWD_CTIME:
@@ -701,7 +706,8 @@ static struct lslogins_user *get_user_info(struct lslogins_control *ctl, const c
                         * (especially in non-GMT timezones) would only serve
                         * to confuse */
                        if (shadow)
-                               user->pwd_ctime = make_time(TIME_SHORT,
+                               user->pwd_ctime = make_time(ctl->time_mode == TIME_ISO ?
+                                               TIME_ISO_SHORT : ctl->time_mode,
                                                shadow->sp_lstchg * 86400);
                        break;
                case COL_PWD_CTIME_MIN: