- Affected version
- 2.1.8
On a linux-like distro; If XenForo (or add-ons) is installed/upgraded via the CLI using root, the wrong file ownership for phrase/templates is trivial to encountered. This can lead to unexpected errors as the operations from the website UI fail because of operations doing on the CLI in a way which can be unexpected.
The very simple solution is if the POSIX functions are included (ie generally included by-default in the
It likely requires some new additional configuration items, and probably should make the
I've got the following code in a pile of site's config.php which ensures XF runs as the correct user.
The very simple solution is if the POSIX functions are included (ie generally included by-default in the
php-common
or php-process
package ); with a user/group combo, root can drop privilege's and ensure files are created by the right user.It likely requires some new additional configuration items, and probably should make the
cmd.php
warn-by-default if invoked by root.I've got the following code in a pile of site's config.php which ensures XF runs as the correct user.
PHP:
$config['drop_perms']['user'] = "<USER NAME>";
$config['drop_perms']['group'] = "<GROUP NAME>";
if (is_callable('posix_getuid') && posix_getuid() == 0)
{
if (!empty($config['drop_perms']['group']))
{
$name = $config['drop_perms']['group'];
$groupinfo = posix_getgrnam($name);
if (empty($groupinfo['gid']))
{
throw new \LogicException("Unknown group:".$name);
}
posix_setgid($groupinfo['gid']);
}
if (!empty($config['drop_perms']['user']))
{
$name = $config['drop_perms']['user'];
$userinfo = posix_getpwnam($name);
if (empty($userinfo['uid']))
{
throw new \LogicException("Unknown user:".$name);
}
posix_setuid($userinfo['uid']);
}
}