3

On my system the man page of shadow defines the third column value this way:

The date of the last password change, expressed as the number of days since Jan 1, 1970.

I have an example value "17050". passwd -S says this is the "2016-09-06". But the seconds since 1970 are "1473112800.0". When I calculate 1473112800.0/(60*60*24) I get "17049.9166666666".

How is the "17050" calculated? Is it rounded or is it always the next greater integer?

ceving
  • 3,579
  • 5
  • 24
  • 30

2 Answers2

3

It's a number of days, not seconds, since the epoch.

$ date -I -d '1970-01-01 + 17050 days'
2016-09-06

(As a side note, technically you can't represent "365 days from now" in seconds; days do not have a fixed or even knowable length beyond 6 months out, due to leap seconds.)

derobert
  • 109,670
  • If it is not possible to know the length of a day, how is the value in /etc/shadow calculated? – ceving Sep 23 '17 at 13:44
  • @ceving the value is stored in days, not seconds, so there is no need to calculate it. Other than that, I suspect the code just ignores the problem, like most everyone. – derobert Sep 23 '17 at 17:18
  • The (for example) Linux kernel runs with a 250Hz timer. All time in the Linux kernel is a multiple of 0.004 seconds. And this means every value in days must be calculated by a value in seconds. – ceving Sep 25 '17 at 08:53
  • @ceving The realtime clocks (there are more than one, not all run at 250Hz, but that's not really relevant) all measure past days. We know the length of past days, but not (certain) future days. Even that, though, they don't actually do; date +%s does not actually give the number of seconds since Jan 1 1970 0000Z; it's currently 27s short. Most recently, there is no date +%s for 2016-12-31 23:59:60Z – derobert Sep 25 '17 at 16:34
1

Checking the source code (for the Debian version), it’s just scaled using integer division by 24 × 3600, so it’s truncated.

Note that the value you have is exactly two hours off in your calculation, which can probably be explained by timezone variations.

Stephen Kitt
  • 434,908