Re: Exec() command on UNIX

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Sitthipong Thuetham wrote:
> I have a question on an exec() command, if I would like to switch user
> right on Unix server, what command should I use?
>
> example: on the UNIX shell will be like below
> $su root
> Password:'password'
>
> but when I tried running exec() command on PHP, I couldn't do that
> exec("su root");
>
> I can't sent a password thru the exec() command, any way to do that?

Probably best to use 'sudo' in the shell to make the script run with the
rights of the user you want, or some similar shell-action.

You may also want to examine the Apache 2 directives that let a Module (EG
PHP) run as a specific user under certain circumstances.  I have not
investigated this avenue myself, but would surmise that you could restrict
this to a specific script in a specific directory, and could give over the
PHP thread to be run by some special user.  While I'm not certain, I'd be
willing to bet cold hard cash that doing this and using "root" as that
special user is a REALLY BAD IDEA.  You'd need to set up a new user with
*JUST* enough permission on the system to do the bare minimum of what you
need that user to do to get the task accomplished.

If, however, you are stuck on a server where you don't HAVE access to a
shell and/or httpd.conf...

Well, first, start looking for a new host where you DO have access to a
shell, at least.

In the meantime, you can sometimes do like this:

exec("echo _password_ | command $arg1 $arg2");

Note, however, that "su" itself specifically prohibits doing this from a
non TTY shell (EG from PHP) to prevent you from doing this inherently very
dangerous action.

Also note that depending on the version of PHP and other factors I never
quite figured out back in the day (PHP 3 & PHP 4) sometimes stdout/stdin
were bound up by PHP and sometimes not, so that the shell "echo" and "|"
trick would only work on some versions/servers.  Some PHP Developers
claimed this was simply not true, however, despite my experience.  YMMV.
:-)

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux