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

FileStorage: set permissions of files and directories #1199

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

fabik
Copy link
Contributor

@fabik fabik commented Aug 12, 2013

I am still having troubles with issue #1039. It was closed because of umask() problems, but nobody mentioned chmod(). Why cannot FileStorage just get file and directory mode as optional constructor parameters and change file permissions itself?

So, for instance

$storage = new FileStorage($dir, $journal, 0664, 0775);

would call chmod(..., 0664) on all created files and mkdir(..., 0775) on created dirs.

There would be no problems with thread safety as in the case of umask(), or am I wrong?

@JanTvrdik
Copy link
Contributor

But both chmod and mkdir respects umask setting. So if umask is wrong, using chmod won't make a difference. Or am I wrong?

@fabik
Copy link
Contributor Author

fabik commented Aug 11, 2013

I don't think so. I've tried this code

umask(0777);
$file = __DIR__ . '/test.txt';
touch($file);
chmod($file, 0777);

and it worked, so the example in the PHP doc doesn't make sense to me.

@milo
Copy link
Member

milo commented Aug 11, 2013

umask() only restricts default values in fopen(), mkdir() and similar. Default value for files is 0666, for directories 0777. If you call chmod(), you set exactly the permissions which you wish.

But for mkdir() it is quite tricky.

mkdir('test1'); # depends on system umask

umask(0777);
mkdir('test2'); # depends on PHP's umask
mkdir('test3', 0666); # still depends on PHP's umask, even mode is specified

So chmod() shoud be always called if exact permissions are required.

@milo
Copy link
Member

milo commented Aug 11, 2013

@fabik Yes, that PHP example is wrong. They should use mkdir() instead of chmod().

@fabik
Copy link
Contributor Author

fabik commented Aug 11, 2013

Well, that's great! I'll create a pull request that adds chmod() to FileStorage.

@dg
Copy link
Member

dg commented Aug 11, 2013

Is it really needed to configure permissions?

@fabik
Copy link
Contributor Author

fabik commented Aug 11, 2013

I use the same cache storage for web and its CLI. The web server runs on a different user than CLI, but both users are in the same group. So, I would like to set the permissions of the cached files to 0664 and directories to 0775.

@fprochazka
Copy link
Contributor

Hey, I had to change the http server to run under my user on dev mashine to have no problems in CLI. And on production I have to login as the httpserver user... But I guess it is more secure this way.

@fabik
Copy link
Contributor Author

fabik commented Aug 12, 2013

Yes, it is more secure. For instance, the CLI user has access to the backup directory, which I don't want to be accessible via web server user.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants