note 23388 deleted from function.fopen by danbrown
| From: | danbrown@php.net | Date: | Tue, 09 Jun 2009 00:53:11 +0000 |
| Subject: | note 23388 deleted from function.fopen by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-156576@lists.php.net to get a copy of this message | ||
Note Submitter: suraj at _nospam_nospam_symonds dot net
----
This note is relevant to the first few notes that talk about writing to files as user
'foobar'.
if one wanted to write to files as user 'foobar' when apache runs as 'root' the
new POSIX fucntions. Here's a code snippet explaining how this can be done
<?
$x = posix_getuid ();
if (0 == $x) {
echo "I'm root\n";
$pw_info = posix_getpwnam ("foobar");
$uid = $pw_info["uid"];
posix_setuid ($uid);
$fp = fopen ("/tmp/test.file", "w");
fclose ($fp);
} else {
echo "I'm not root! I'm not worthy... I'm not worthy....\n";
}
?>
[Note:
1. This would only set the uid... not the gid. If you wanted to write to files as
'foobar:foobar' then you also have to do a posix_setgid ($gid);
2. If you are using the CGI version of php4, you should setuid your php4 interpreter: chmod 4755
/path/to/cgi-bin/php4 (generally, /usr/lib/cgi-bin/php4)]