How to run ejabberdctl from www-root?

I have written a PHP script to register web users to XMPP. I want to have the script execute ejabberdctl from a shell, but it's not working.

<?php
  $return
= shell_exec("ejabberdctl register $username $domain $password");
?>

That returns NULL, which would normally leave me to believe it's successful. However, the user isn't actually created. After further testing, I learned the following:

<?php
function my_exec($cmd, $input='')
         {
$proc=proc_open($cmd, array(0=>array('pipe', 'r'), 1=>array('pipe', 'w'), 2=>array('pipe', 'w')), $pipes);
         
fwrite($pipes[0], $input);fclose($pipes[0]);
         
$stdout=stream_get_contents($pipes[1]);fclose($pipes[1]);
         
$stderr=stream_get_contents($pipes[2]);fclose($pipes[2]);
         
$rtn=proc_close($proc);
          return array(
'stdout'=>$stdout,
                      
'stderr'=>$stderr,
                      
'return'=>$rtn
                     
);
         }
var_export(my_exec('ejabberdctl status'));
?>

returns

array (
  'stdout' => '',
  'stderr' => 'sh: ejabberdctl: command not found
',
  'return' => 127,
)

I discovered from the CLI that running as a normal user, rather than root, that's the same error returned when attempting to run ejabberdctl. So then I searched for the executable, and changed it to /usr/sbin/ejabberdctl. Running that from the command line gives me:

$ /usr/sbin/ejabberdctl status
RPC failed on the node ejabberd@vserver147: nodedown
$ /usr/sbin/ejabberdctl ejabberd@vserver147 status
RPC failed on the node ejabberd@vserver147: nodedown
$ /usr/sbin/ejabberdctl ejabberd@xmpp.example.com status
RPC failed on the node ejabberd@vserver147: nodedown

To make matters more confusing sending /usr/sbin/ejabberd, from PHP, I now get:

array (
  'stdout' => '',
  'stderr' => 'erlexec: HOME must be set
',
  'return' => 1,
)

Searching around, I now discovered that erl REQUIRES a user have the $HOME variable set, which apparently the www-root user doesn't get by default. I tried running $HOME=/tmp before the ejabberd command, but that didn't seem to work. I guess I can dig into how to assign the variable to a user I don't have command line access to, but I suspect it still won't work because of the RPC failure.

Help!

Thanks,
Aaron

and yes, i've also tried

and yes, i've also tried running the commands as root -- they execute properly.

how to allow non-root users to run ejabberdctl?

So now I added at the beginning,

putenv("HOME=/tmp");

and got:

array (
  'stdout' => 'RPC failed on the node ejabberd@vserver147: nodedown
',
  'stderr' => '',
  'return' => 3,
)

At least it's now at the same place as other users. So now the question is how to allow non-root users to run ejabberdctl...

The ejabberd installation

The ejabberd installation when using the source package assumes that only root can run ejabberdctl.

However, if you add the option

./configure --enable-user=somesystemuser

and then install it, then both root and somesystemuser will be able to run ejabberdctl.

I checked if it was possible to get any other system user to run ejabberdctl, by adding him to the somesystemuser group, but it didn't work:

$ /sbin/ejabberdctl
This command can only be run by root or the user somesystemuser
Syndicate content