Do time correction when receiving rwhod entries #25

Open
opened 2026-01-06 04:50:50 +01:00 by oysteikt · 0 comments
Owner

The C daemon uses a trick to work around the 2038 year problem. Since we cannot modify the old protocol, we should probably try to do the same (also in reverse maybe).

Here is the relevant code:

		myrecvtime = w->wd_recvtime;
		/*
		 * After 2038 the rwho protocol, which sends int32s, will
		 * start to lose. However, by then, "now" will be an int64.
		 * So assume that if "now" is WAY bigger than myrecvtime, 
		 * the latter needs to be incremented by 2^32. 0x40000000 is
		 * 34 years, so it's _fairly_ safe to assume we won't have
		 * any packets that old in /var/spool/rwho.
		 * Increment the correction by values < 2^31 so it works 
		 * if time_t is still an int32. Save the correction for
		 * use on the login times.
		 */
		timecorrection = 0;
		while (now - myrecvtime + timecorrection > 0x40000000) {
			timecorrection += 0x70000000;
			timecorrection += 0x70000000;
			timecorrection += 0x20000000;
		}
The C daemon uses a trick to work around the 2038 year problem. Since we cannot modify the old protocol, we should probably try to do the same (also in reverse maybe). Here is the relevant code: ```c myrecvtime = w->wd_recvtime; /* * After 2038 the rwho protocol, which sends int32s, will * start to lose. However, by then, "now" will be an int64. * So assume that if "now" is WAY bigger than myrecvtime, * the latter needs to be incremented by 2^32. 0x40000000 is * 34 years, so it's _fairly_ safe to assume we won't have * any packets that old in /var/spool/rwho. * Increment the correction by values < 2^31 so it works * if time_t is still an int32. Save the correction for * use on the login times. */ timecorrection = 0; while (now - myrecvtime + timecorrection > 0x40000000) { timecorrection += 0x70000000; timecorrection += 0x70000000; timecorrection += 0x20000000; } ```
oysteikt added the good first issue label 2026-01-06 04:50:50 +01:00
oysteikt changed title from Do the time correction trick when receiving rwhod entries serverside to Do time correction when receiving rwhod entries 2026-01-07 04:35:13 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: Projects/roowho2#25