Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

access mode of files created by output_file is surprising #2530

Closed
berthubert opened this issue Oct 2, 2021 · 5 comments
Closed

access mode of files created by output_file is surprising #2530

berthubert opened this issue Oct 2, 2021 · 5 comments

Comments

@berthubert
Copy link

Hi,

In 8.0.1 at least, on POSIX, files created by fmt::output_file explicitly set themselves to be readable and writable by the user only.

This led to some issues after I moved to fmt::output_file since all of a sudden my files could no longer be read by the web server.

POSIX custom is to set a broader default permission (0660 for example), and let the operator tone that down using their umask setting.

Now it may be that fmt has a good reason for 0600 of course, but it is a bit surprising. There is also no way to change this mode.

Thoughts? Can I help?

Bert (formerly powerdns_bert)

@vitaut
Copy link
Contributor

vitaut commented Oct 3, 2021

Fixed in 4a85db1, now the default mode is -rw-r--r-- which is consistent with fopen. Thanks for reporting.

@vitaut vitaut closed this as completed Oct 3, 2021
@berthubert
Copy link
Author

Thanks!

Iniesta8 pushed a commit to jhnc-oss/fmt that referenced this issue Oct 28, 2021
PoetaKodu pushed a commit to pacc-repo/fmt that referenced this issue Nov 11, 2021
@arogge
Copy link
Contributor

arogge commented Jan 26, 2022

Sorry for digging this one up again.
If the intent is to mimic behaviour of fopen() then the patch is wrong.
While libfmt is setting S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH, POSIX mandates that it should be S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH.

fopen() in the Open Group Specification reads:

If mode is w, wb, a, ab, w+, wb+, w+b, a+, ab+, or a+b, and the file did not previously exist, the fopen() function shall create a file as if it called the creat() function with a value appropriate for the path argument interpreted from pathname and a value of S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH for the mode argument.

The system will usually strip S_IWGRP and S_IWOTH based on the process' umask, which will result in the observed -rw-r--r-- if umask was set to 022. However with a umask of 002 fopen() would produce -rw-rw-r-- and libfmt should probably do the same.

I can do a pull request for that if you want.

@vitaut
Copy link
Contributor

vitaut commented Jan 26, 2022

@arogge, good catch, thanks.

I can do a pull request for that if you want.

Please, do.

arogge added a commit to arogge/fmt that referenced this issue Jan 26, 2022
The previous fix for this in 4a85db1 was incomplete. The intent was to
mimic what `fopen()` is doing. As per standard[1] `fopen()` also sets
`S_IWGRP` and `S_IWOTH` and lets the umask handle the rest.

[1] https://pubs.opengroup.org/onlinepubs/9699919799.2018edition/functions/fopen.html
arogge added a commit to arogge/fmt that referenced this issue Jan 26, 2022
The previous fix for this in 4a85db1 was incomplete. The intent was to
mimic what `fopen()` is doing. As per standard[1] `fopen()` also sets
`S_IWGRP` and `S_IWOTH` and lets the umask handle the rest.

[1] https://pubs.opengroup.org/onlinepubs/9699919799.2018edition/functions/fopen.html
@arogge
Copy link
Contributor

arogge commented Jan 26, 2022

See PR #2733

vitaut pushed a commit that referenced this issue Jan 29, 2022
The previous fix for this in 4a85db1 was incomplete. The intent was to
mimic what `fopen()` is doing. As per standard[1] `fopen()` also sets
`S_IWGRP` and `S_IWOTH` and lets the umask handle the rest.

[1] https://pubs.opengroup.org/onlinepubs/9699919799.2018edition/functions/fopen.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants