| 41 | |
| 42 | function get_expire(name) { |
| 43 | function parse_expire(data) { |
| 44 | let account_expiration = ''; |
| 45 | let account_date = null; |
| 46 | |
| 47 | let password_expiration = ''; |
| 48 | let password_days = null; |
| 49 | |
| 50 | data.split('\n').forEach(line => { |
| 51 | const fields = line.split(': '); |
| 52 | if (fields[0] && fields[0].indexOf("Password expires") === 0) { |
| 53 | if (fields[1].indexOf("never") === 0) { |
| 54 | password_expiration = _("Never expire password"); |
| 55 | } else if (fields[1].indexOf("password must be changed") === 0) { |
| 56 | password_expiration = _("Password must be changed"); |
| 57 | } else { |
| 58 | password_expiration = cockpit.format(_("Require password change on $0"), timeformat.date(new Date(fields[1]))); |
| 59 | } |
| 60 | } else if (fields[0] && fields[0].indexOf("Account expires") === 0) { |
| 61 | if (fields[1].indexOf("never") === 0) { |
| 62 | account_expiration = _("Never expire account"); |
| 63 | } else { |
| 64 | account_date = new Date(fields[1] + " 12:00:00 UTC"); |
| 65 | account_expiration = cockpit.format(_("Expire account on $0"), timeformat.date(new Date(fields[1]))); |
| 66 | } |
| 67 | } else if (fields[0] && fields[0].indexOf("Maximum number of days between password change") === 0) { |
| 68 | password_days = fields[1]; |
| 69 | } |
| 70 | }); |
| 71 | |
| 72 | // 99999 traditionally meant "never" but the modern value for |
| 73 | // that is -1. |
| 74 | // |
| 75 | // Modern versions of "chage" will not treat 99999 any special |
| 76 | // and will output bogus expiration dates somewhere in 2300. |
| 77 | // But let's recognize both, since old accounts will still use |
| 78 | // 99999, and /etc/login.def also still uses 99999 as the |
| 79 | // default for new accounts. |
| 80 | // |
| 81 | // Passord expiration is being removed completely from |
| 82 | // shadow-utils, and we probably should continue to recognize |
| 83 | // 99999 as "never" until we stop supporting password expiry |
| 84 | // entirely. |
| 85 | |
| 86 | if (parseInt(password_days) >= 99999 || parseInt(password_days) < 0) { |
| 87 | password_days = null; |
| 88 | password_expiration = _("Never expire password"); |
| 89 | } |
| 90 | |
| 91 | return { |
| 92 | account_text: account_expiration, |
| 93 | account_date, |
| 94 | password_text: password_expiration, |
| 95 | password_days |
| 96 | }; |
| 97 | } |
| 98 | |
| 99 | return cockpit.spawn(["chage", "-l", name], |
| 100 | { environ: ["LC_ALL=C"], err: "message", superuser: "try" }) |