Go Back   HowtoForge Forums | HowtoForge - Linux Howtos and Tutorials > Linux Forums > Programming/Scripts

Do you like HowtoForge? Please consider supporting us by becoming a subscriber.
Reply
 
Thread Tools Display Modes
  #1  
Old 4th September 2007, 19:00
firemission firemission is offline
Junior Member
 
Join Date: Sep 2007
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default help php adding a user in linux

hello all. I seem to be having difficulties with my lifestyle today. You see my problem is that I am writing a custom php script for a small hosting company, they want the user to be able to sign up and pay (got all that working) then the server is to autoprovision their account and create the user where everything should be. now the problem i am having is this is all done with php. and when salling the useradd command from withing php it is barfing so i edit the sudoers file to let the webserver user execute the useraddcommand as root without a password. this also is barfing i know it is not a syntax problem wih the command itself cause if i SSH into the server and execute the command the webserver is trying it woorks perfect. so my question is why when i ssh into the box and execute the coomand it works perfect but when php simply sends the command to the box using the exec() function it barfs. i have alse tried passthru() and system() all of them barf. and it is getting smelly in here due to all the barfing. any insight would be much appreciated./
Reply With Quote
Sponsored Links
  #2  
Old 5th September 2007, 20:25
falko falko is offline
Super Moderator
 
Join Date: Apr 2005
Location: Lüneburg, Germany
Posts: 41,701
Thanks: 1,900
Thanked 2,741 Times in 2,575 Posts
Default

Do you get any error messages? What's in Apache's error log? What's in /etc/sudoers?
__________________
Falko
--
Download the ISPConfig 3 Manual! | Check out the ISPConfig 3 Billing Module!

FB: http://www.facebook.com/howtoforge

nginx-Webhosting: Timme Hosting | Follow me on:
Reply With Quote
  #3  
Old 5th September 2007, 23:22
firemission firemission is offline
Junior Member
 
Join Date: Sep 2007
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default no errors

I get no errors in the apache error log and nothing in the system log. and the lines I added to the sudoers file is.

[apache user] ALL=/usr/sbin/passwd,/usr/sbin/useradd,/usr/sbin/userdel NOPASSWD: ALL.

so i dont get it
Reply With Quote
  #4  
Old 6th September 2007, 23:27
falko falko is offline
Super Moderator
 
Join Date: Apr 2005
Location: Lüneburg, Germany
Posts: 41,701
Thanks: 1,900
Thanked 2,741 Times in 2,575 Posts
Default

Do you get any errors in your browser?

Maybe the exec() function isn't allowed in your php.ini?
__________________
Falko
--
Download the ISPConfig 3 Manual! | Check out the ISPConfig 3 Billing Module!

FB: http://www.facebook.com/howtoforge

nginx-Webhosting: Timme Hosting | Follow me on:
Reply With Quote
  #5  
Old 7th September 2007, 22:08
firemission firemission is offline
Junior Member
 
Join Date: Sep 2007
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by falko
Maybe the exec() function isn't allowed in your php.ini?
I wrote the php.ini . It is allowed. I have also tried the system() and passthru() functions, they don't work either. I have built a workaround for this by writing a bash shell script that is called from within php by an exec() call, and sent the pertinent variables. It works now but I dont like how i had to do it for security reasons.
Reply With Quote
  #6  
Old 8th September 2007, 13:00
falko falko is offline
Super Moderator
 
Join Date: Apr 2005
Location: Lüneburg, Germany
Posts: 41,701
Thanks: 1,900
Thanked 2,741 Times in 2,575 Posts
Default

Did you use the full path to useradd (/usr/sbin/useradd) in exec() or just useradd? It's possible that the PATH variable is different within your PHP script.
__________________
Falko
--
Download the ISPConfig 3 Manual! | Check out the ISPConfig 3 Billing Module!

FB: http://www.facebook.com/howtoforge

nginx-Webhosting: Timme Hosting | Follow me on:
Reply With Quote
  #7  
Old 8th September 2007, 14:52
firemission firemission is offline
Junior Member
 
Join Date: Sep 2007
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by falko
Did you use the full path to useradd (/usr/sbin/useradd) in exec() or just useradd? It's possible that the PATH variable is different within your PHP script.
the exact code used is as follows
// pulls user from MySql Database
$user = get_user($UID,'','');
//building command
$command = "sudo /usr/sbin/useradd -g 100 -d ".$user['rootDir']." -k
/srv/www/htdocs/skel -s /bin/false -c \"".$user['firstName']."
".$user['lastName']."\" ".$user['userName'];
//execute command
exec($command,$return);
//getting return
if (is_array($return)){
//if return we send output to browser
print_r($return);
}
Reply With Quote
  #8  
Old 8th September 2007, 15:04
firemission firemission is offline
Junior Member
 
Join Date: Sep 2007
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default

on a side note I have developed a workaround to this particular problem. It is much more complex and by that virtue less secure and unreliable. I have written a shell script that accepts 2 arguments, username and password, then the shell script creates the user as root and returns an exit status to the php exec() function. The real problem is that if is someone knows the exact path to the shell script they could create users arbitrarily on the server as the shell script needs to be r-x by the www server.
Reply With Quote
  #9  
Old 9th September 2007, 20:06
falko falko is offline
Super Moderator
 
Join Date: Apr 2005
Location: Lüneburg, Germany
Posts: 41,701
Thanks: 1,900
Thanked 2,741 Times in 2,575 Posts
Default

Quote:
Originally Posted by firemission
the exact code used is as follows
// pulls user from MySql Database
$user = get_user($UID,'','');
//building command
$command = "sudo /usr/sbin/useradd -g 100 -d ".$user['rootDir']." -k
/srv/www/htdocs/skel -s /bin/false -c \"".$user['firstName']."
".$user['lastName']."\" ".$user['userName'];
//execute command
exec($command,$return);
//getting return
if (is_array($return)){
//if return we send output to browser
print_r($return);
}
You can try to use the full path to sudo as well.
__________________
Falko
--
Download the ISPConfig 3 Manual! | Check out the ISPConfig 3 Billing Module!

FB: http://www.facebook.com/howtoforge

nginx-Webhosting: Timme Hosting | Follow me on:
Reply With Quote
  #10  
Old 9th September 2007, 21:54
firemission firemission is offline
Junior Member
 
Join Date: Sep 2007
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
 
Default

that didn't work either. I have developed a workaround that secure enough for my tastes and also does what i need it to. it puts the username, password, home dir and all that stuff into a database. then i have a chrontab job that runs every 5 min as root that pulls the info and creates the user then deletes the info from the database. I am happy with that solution. maybe i should submit this as a bug to php.net?
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Statistic not working mzo Installation/Configuration 49 20th April 2011 12:19
Freebsd 6.1 support misterm Installation/Configuration 10 9th April 2009 09:29
Apache2 Freezes celtic Server Operation 31 28th May 2007 17:18
KErnel not showing all my memory Jorem Kernel Questions 8 13th April 2006 12:59


All times are GMT +2. The time now is 03:34.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2014, vBulletin Solutions, Inc.