Any "fopen for write" with owner-params?
I have a RPI with Raspbian and I develop a project in Ansi-C. I use fopen() to write and read files. Are there any function where I can set the ownership and/or permissions in the same time I write the file? Like a fopen with more params....
- RaTTuS
- Posts: 10691
- Joined: Tue Nov 29, 2011 11:12 am
- Location: North West UK
- Contact: Twitter YouTube
Re: Any "fopen for write" with owner-params?
chmod($fname, 0777);
chown($fname, 'user');
I take it you are running as root and want to create it as another user ?
chown($fname, 'user');
I take it you are running as root and want to create it as another user ?
How To ask Questions :- http://www.catb.org/esr/faqs/smart-questions.html
WARNING - some parts of this post may be erroneous YMMV
1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe
WARNING - some parts of this post may be erroneous YMMV
1QC43qbL5FySu2Pi51vGqKqxy3UiJgukSX
Covfefe
Re: Any "fopen for write" with owner-params?
The program running as root (and creates files with root:root) and I'm a USER. The PHP/Apache2 have also problems to deal with those files.
I think I use the chmod/chown() already. As I remember, the files needed to be opened before calling chmod/chown?
Of course, I can do this when the files are opened for writing..
Thanks!
I think I use the chmod/chown() already. As I remember, the files needed to be opened before calling chmod/chown?
Of course, I can do this when the files are opened for writing..
Thanks!
Re: Any "fopen for write" with owner-params?
open (not fopen) will allow you to set permissions of the file.
setuid will allow you to set the uid of the process.
So, as an example (from memory not tested)
setuid(501) // assuming www-data is 501
fd = open(filename, O_RDRW | O_CREAT, 0644)
setuid will allow you to set the uid of the process.
So, as an example (from memory not tested)
setuid(501) // assuming www-data is 501
fd = open(filename, O_RDRW | O_CREAT, 0644)
Re: Any "fopen for write" with owner-params?
Great. That's a very nice way of setting the ownership and the p-bits as I want them.