Is there any reason the drift file should be mode 600?

Hal Murray hmurray at megapathdsl.net
Thu Dec 14 00:23:54 UTC 2017


This is from issue 409.
  https://gitlab.com/NTPsec/ntpsec/issues/409

The code that writes the drift file uses mkstemp and rename.  mkstemp uses 
mode 600.  I can't see a way to override that.  That gets inherited by the 
renamed file.

If you are using apparmor, ntpd can't read the drift file at startup because 
it is still root while the drift file is user ntp.

The old code (ntp classic) uses fopen so it gets the default mode bits, 
wherever they come from.

I think we should fix this.

The simple fix is to add a chmod to the existing code, but that embeds a 
magic constant (new mode bits) deep in our code.  So it looks cleaner to me 
to not use mkstemp.

--------

Big picture.  What if we just wrote to the existing file?  Are there any 
guarantees that writes that don't cross page boundaries are atomic?

--------

It also uses snprintf to a string buffer and then writes that to the file.  
Is there any reason not to use dprintf?

My Linux man page says:
       The dprintf() and vdprintf() functions were originally  GNU  extensions
       that were later standardized in POSIX.1-2008.


-- 
These are my opinions.  I hate spam.





More information about the devel mailing list