I wrote a simple php crontab management program that updated the crontab of 'someuser' like so
crontab -u someuser /path/to/new/cronfile
however I was in need to run some php scripts as root so I decided to edit roots' crontab instead and add the required user field to each script:
crontab -u root /path/to/new/cronfile
Surprisingly that worked!
I was really wondering how that can be possible and checked /etc/crontab
for its' permissions.`
rw-r--r--
Well, how can any user run various planned scripts on roots behalf and with access to every single user?
That must be a bug, is it?
// edit (added php script due to comments)
$crontabCacheFile = PATH_CACHE . 'crontab.cache';
$cronFile = PATH_ROOT . '.crontab';
if(!is_file($crontabCacheFile) || (filemtime($cronFile) > filemtime($crontabCacheFile))) {
# install new cronfile
if(false === $result = system("crontab -u root $cronFile"))
logWrite("failed to install new crontab $cronFile", true);
else
file_put_contents($crontabCacheFile, date('Y-m-d H:i:s') . " installed new crontab $result\n", FILE_APPEND);
}
The script is running on www user (that owns PATH_* directories in /var/www/projectdir)
lsb_release -a
spits out:
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 18.04.6 LTS
Release: 18.04
Codename: bionic