Jump to content

PHP not using useradd/passwd (linux cmds) correctly.


Recommended Posts

Hello,

 

I'm new to this forum, but I have been searching for a great deal of time as to why I'm experiencing problems with shell_exec() through apache2.

 

First off, I'm using ubuntu Jaunty 86-64 with kernel 2.6.28-15-generic with PHP5 and apache2(.2.11).

Secondly, I have given apache2 (www-data) root, nopasswd access to the system via visudo.  Specifically to the useradd, userdel, and passwd scripts found on the ubuntu system.

 

Now, I feel as though I can execute these scripts (safely-with a variety of checks and counters like escapeshellcmd and as well as not passing any non-alphanumeric symbols to the shell_exec() call).  Thus:

 

escapeshellcmd($user);
escapeshellcmd($passwd1);
escapeshellcmd($passwd2);
shell_exec("/usr/bin/sudo /usr/sbin/useradd -d /home/chroot/ViBE/home/{$user} -m -g ViBE_Students {$user}");
shell_exec("/usr/bin/sudo /usr/bin/passwd {$user}");
shell_exec($passwd1);
shell_exec($passwd2);

 

This only creates a user..but it can not be logged in to.  Through terminal commands, this works perfectly fine, and everything can be accessed.  I'm really not sure what has happened as it used to work great.  Maybe a kernel change (I'm really just guessing)?

 

-SigmaOmega

 

P.S. safe_mode is not enabled.

I'm really not understanding what you mean by using expect.

 

I've tried using both popen and ctl after installing PECL extensions.

 

For further information regarding the issue, I've noticed that PAM isn't being called to authenticate the password.

 

The following is logged after "sudo passwd" is used via terminal.

passwd[20404]: pam_unix(passwd:chauthtok): password changed for

 

This isn't called when www-data is attempting to change the password.

 

Any help?

 

-Sigmaomega

Ok, so i got this far:

 


		$stream = expect_popen("/usr/bin/sudo /usr/bin/passwd testing");
		$case = array(array (0 => "password:", 1 => PASSWORD));
	 {			
		switch (expect_expectl ($stream, $case)) {
	case PASSWORD:
		fwrite ($stream, "welcome\n");
		fwrite ($stream, "welcome\n");
		break;
	default:
		die("Error");
}}	
		fclose($stream);


 

It is parsed correctly, but the password does not set.  Am I missing something?

 

-Sigmaomega

 

P.S. Thank you for the help btw, I'm a novice when it comes to php.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.