note 23388 added to function.fopen

From: Date: Wed, 17 Jul 2002 10:41:28 +0000
Subject: note 23388 added to function.fopen
Groups: php.notes 
Request: Send a blank email to php-notes+get-33199@lists.php.net to get a copy of this message
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)] -- http://www.php.net/manual/en/function.fopen.php http://master.php.net/manage/user-notes.php?action=edit+23388 http://master.php.net/manage/user-notes.php?action=delete+23388 http://master.php.net/manage/user-notes.php?action=reject+23388

« previous php.notes (#33199) next »