note 68933 deleted from function.exec by cmb
| From: | cmb@php.net | Date: | Sun, 22 Sep 2019 07:25:27 +0000 |
| Subject: | note 68933 deleted from function.exec by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-212284@lists.php.net to get a copy of this message | ||
Note Submitter: sinisa dot dukaric at gmail dot com
----
Recently I had to do some "root" stuff via PHP - I could do it through cronjob based on
the database, but since I was too lazy with doing that, I just wrote a shell script to create all
the IMAP stuff, chown properly all the Maildirs and provision the user on the local system.
Executing that command as another user from inside of PHP was like this...
<code>
@exec("echo 'apache' | /usr/bin/sudo -u mail -S /var/www/html/mailset.sh
$name");
</code>
"Advantage" is that you can run in this way commands as any sudoer on your system which
can be fine-tuned and pretty useful. But again - password is echoed in cleartext and option
"-S" tells sudo to take password from stdin which he does of course.
Major security risk - do it only if you really need to run some commands as different users (nologin
users) and if you are really lazy :)
Now, my solution is a cronjob which runs every 5 mins and gets datasets from the MySQL table and
does the work without exploiting any exec() from within PHP - which is the right way to do it.