0

I know this is a security threat and is bad from a security aspect alltogether, but for a specific reason, i need this to work. I have a program running on Ubuntu 16.04. Let's say for this example, that it's a DNS server or whatever.

What i'm trying to do, is edit the DNS server configuration file, located in /etc/xxx from a web page, which is using PHP fopen, fwrite and fclose. Because you can't access a file directly located in /etc/xxx/somecfg.cfg anyways, since it doesn't have www-data permissions, i've tried linking it to /var/www/html, both soft and hard linking it. When i create a hard link, it changes the original cfg file too if i edit it by hand, but as soon as i edit it via PHP, only the hard-link file changes, but not the original file.

I've been trying to fix this during the weekend but i can't seem to be able to do it.

Does anyone have an idea on how i would go about fixing this? I'm open to other ideas too. The main goal is to edit a package configuration file from within a web page.

TL;DR: I'm trying to edit a config file in /etc/xxx from /var/www/html/someaction.php and doing it directly doesn't work (obviously), but hard links and soft links are acting weird - the links' content changes, but the original cfg file doesn't.

Thanks!

  • The answer to your question lies in setting the right permissions for the user you want to edit the files with or setting the permission for the file being edited. Links do not let you circumvent this. The original file will not have the rights to be updated after the link is edited. – nrm Apr 09 '18 at 10:41
  • @nrm The original file has the proper permissions, but i've set the hard link's permissions to www-data:www-data so that it can be edited. It edits the file correctly, but the changes don't show on the hardlink's targets location – Thunderzzu Apr 09 '18 at 10:50

1 Answers1

0

The issue was that i accidentally put unlink at the beginning of the code and the hard link was deleted, so i basically made a new file each time i wrote to it.

It's fixed now.