Page 1 of 1
Permission problem
Posted: Tue Nov 18, 2003 1:48 pm
by scubadiveflorida
I have a form that that t he client goes in and enters some data. This data is written to a text file in a directory on my server. The only way I can get this to work properly is to open the directory wide open chmod 777 but I am worried about security risks with this. Should I be worried? Is there a better way to do this?
This is what I am using:
$fh = fopen($file, 'w+');
fwrite($fh, $buff);
fclose($fh);
Thanks...
Posted: Tue Nov 18, 2003 1:56 pm
by m3mn0n
[php_man]chmod[/php_man]()
Are you sure 0600 doesn't work? That's the ideal security mode, IMO.
Maybe set the chmod before the script writes, then set it back when its done.
Note: Never tried it, only a theory I thought up just now.
Posted: Tue Nov 18, 2003 2:16 pm
by McGruff
What is the owner/group of the file and what is the owner/group which php scripts connect under? You can check this by looking at the site with an ftp program and doing a dirinfo command or similar.
I'm guessing that php uses a different owner/group to that under which the file was created. To fix that, create the file with php: thereafter php should be able to write to it with a safer CHMOD 755. You may need to CHMOD 777 the parent folder to allow php to write the file but, once it's written, the parent folder can be CHMOD'd back to 755. Php will be able to write to a file in a 755 folder with a different owner/group if the file itself has the php owner/group.
reply
Posted: Tue Nov 18, 2003 2:55 pm
by scubadiveflorida
ok In the function at the begining before being written I am doing:
$permissions = `chmod 777 ../directory_name`;
Then after the fwrite I am doing:
$permissions = `chmod 755 ../directory_name`;
This does not seem to work any ideas?
Posted: Tue Nov 18, 2003 3:00 pm
by m3mn0n
is that the exact php code??
exact
Posted: Tue Nov 18, 2003 3:04 pm
by scubadiveflorida
$permissions = `chmod 777 /home/users/create`;
# This grabs the correct template then puts the two files together
if ($filename == '')
{
$genericfile = "file.generic";
}else{
$genericfile = "$filename";
}
$buff = get_contents($genericfile);
$buff = $tempvar.$buff;
$file = "$file.txt";
$fh = fopen($file, 'w+');
fwrite($fh, $buff);
fclose($fh);
$permissions = `chmod 755 /home/ams/amsorm_create`;
Posted: Tue Nov 18, 2003 3:04 pm
by scubadiveflorida
The script works just not the permission changing
Posted: Tue Nov 18, 2003 3:06 pm
by scubadiveflorida
Sorry the bottom $permissions is the following
$permissions = `chmod 755 /home/users/create`