nixCraft Linux Forum

nixCraft

Linux Tech Support Forum

let users change password using perl script?

This is a discussion on let users change password using perl script? within the Getting started tutorials forums, part of the Linux Getting Started category; Hi all, I am following this thread by what its not working. You really don't need a perl script. All ...


Go Back   nixCraft Linux Forum > Linux Getting Started > Getting started tutorials

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 05-23-2007, 08:42 PM
Junior Member
User
 
Join Date: May 2007
My distro: Debian
Posts: 5
Rep Power: 0
james bond is on a distinguished road
Default let users change password using perl script?

Hi all,

I am following this thread by what its not working.
Quote:
You really don't need a perl script. All you need is following shell script and expect tool:
Code:
vi npasswd
Add following lines to it:
Code:
#!/bin/sh
# \
exec expect -f "$0" ${1+"$@"}
set password [lindex $argv 1]
spawn passwd [lindex $argv 0]
expect "assword:"
send "$password\r"
expect "assword:"
send "$password\r"
expect eof
To change password for user vivek:

Code:
npasswd vivek 123456
Where,
npasswd : script name
vivek : username
123456: Newpassword


Script must be run as a root user, it can be call from perl, php or any other lanauge. Download expect tool here: Expect - Expect - Home Page
it works from command line but when put it in php page it doesn't. For that I followed this link.
Change Linux or UNIX system password using PHP script | nixCraft

But it doesn't work.
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 05-23-2007, 09:55 PM
rockdalinux's Avatar
Contributors
User
 
Join Date: May 2005
Location: Bangalore
My distro: RHEL, HP-UX, Solaris, FreeBSD, Ubuntu
Posts: 557
Rep Power: 6
rockdalinux is a jewel in the rough rockdalinux is a jewel in the rough rockdalinux is a jewel in the rough
Default

can you paste your php or perl script here???
__________________
Rocky Jr.
You may have my body & soul, but you will never touch my pride!

If you have knowledge, let others light their candles at it.

Certified to work on HP-UX / Sun Solaris / RedHat
Reply With Quote
  #3 (permalink)  
Old 05-24-2007, 06:08 AM
Junior Member
User
 
Join Date: May 2007
My distro: Debian
Posts: 5
Rep Power: 0
james bond is on a distinguished road
Default

Hi, thanks for your quick response.

Here is my php code which is exactly same as in the link I posted. I just changed this one line with my shell script name
Code:
<?php

$shellscript = “/usr/bin/sudo autopasswd”;
.....
.......
// display footer 
function writeFoot(){
echo 
; } ?>
Also added the line using "visudo" command
Code:
www-data  ALL=NOPASSWD: /var/www/html/autopasswd
And here is my shell script of "autopasswd"
Code:
#!/usr/bin/expect -f

set password [lindex $argv 1]
spawn password [lindex $argv 0]
expect "assword:"
send --"$password\r"

expect "assword:"
send --"$password\r"
expect eof
this script works when i run it as
Code:
 ./autopasswd username password
But when run the php script it shows nothing. Any help will be greatly appreciated.
I want to give a web interface to users to change their password.
thanks in advance.
Reply With Quote
  #4 (permalink)  
Old 05-24-2007, 10:54 AM
Member
User
 
Join Date: Jun 2005
Posts: 78
Rep Power: 0
jerry
Default

Hmm...
Replace
Code:
$shellscript = “/usr/bin/sudo autopasswd”;
With
Code:
$shellscript = “/usr/bin/sudo /var/www/html/autopasswd”;
Also when you run a php script just look at apahce error and access log using tail -f command - you will get error message
Code:
tail -f access.log
tail -f error.log
Reply With Quote
  #5 (permalink)  
Old 05-24-2007, 10:55 AM
Member
User
 
Join Date: Jun 2005
Posts: 78
Rep Power: 0
jerry
Default

Also make sure you do not get any error message when you run command from a shell:
Code:
php your-script-name.php
if you get any error please paste your output here
Reply With Quote
  #6 (permalink)  
Old 05-24-2007, 03:25 PM
Junior Member
User
 
Join Date: May 2007
My distro: Debian
Posts: 5
Rep Power: 0
james bond is on a distinguished road
Default

Jerry,

when I run this
Code:
$ php my-script-name.php
then it prints the whole php file. No errors.

This is the output of access.log when run that php page from browser

Code:
 10.10.192.49 - - [24/May/2007:15:41:45 +0600] "GET /changepassword.php HTTP/1.0" 200 1760 "-" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1"
  10.10.192.49 - - [24/May/2007:15:41:51 +0600] "POST /changepassword.php HTTP/1.0" 200 858 "http://10.10.4.200/changepassword.php" "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1"
Output from error.log
Code:
 [client 10.10.192.49] PHP Notice:  Use of undefined constant PHP_SELF - assumed 'PHP_SELF' in /var/www/html/changepassword.php on line 135
  unable to change to sudoers gid: Operation not permitted
autopasswd file:

Code:
#!/usr/bin/expect -f
# wrapper to make passwd(1) be non-interactive
# username is passed as 1st arg, passwd as 2nd
set password [lindex $argv 1]
spawn passwd [lindex $argv 0]
expect "assword:"
send -- "$password\r"
expect "assword:"
send -- "$password\r"
expect eof
changed "changepassword.php" as follows: just mentioned important lines..

Code:
$shellscript = "/usr/bin/sudo /var/www/html/autopasswd ";
....
....
 if ( $callshell == true ) {
  // command to change password
   $cmd="$shellscript" . $_POST['username'] . " " . $_POST['passwd'];
   echo $cmd;
   exec($cmd,$output,$status);
Waiting for your kind response.
Reply With Quote
  #7 (permalink)  
Old 05-24-2007, 04:05 PM
rockdalinux's Avatar
Contributors
User
 
Join Date: May 2005
Location: Bangalore
My distro: RHEL, HP-UX, Solaris, FreeBSD, Ubuntu
Posts: 557
Rep Power: 6
rockdalinux is a jewel in the rough rockdalinux is a jewel in the rough rockdalinux is a jewel in the rough
Default

Quote:
[client 10.10.192.49] PHP Notice: Use of undefined constant PHP_SELF - assumed 'PHP_SELF' in /var/www/html/changepassword.php on line 135
unable to change to sudoers gid: Operation not permitted
Setup correct permission on your PHP script to fix sudoers gid permission problem:
Code:
chown www-data:www-data /var/www/html/changepassword.php
I hope you are running Apache under www-data user, if not open httpd.conf and find out username and set that in sudo and same using chown command.
__________________
Rocky Jr.
You may have my body & soul, but you will never touch my pride!

If you have knowledge, let others light their candles at it.

Certified to work on HP-UX / Sun Solaris / RedHat
Reply With Quote
  #8 (permalink)  
Old 05-24-2007, 10:04 PM
Junior Member
User
 
Join Date: May 2007
My distro: Debian
Posts: 5
Rep Power: 0
james bond is on a distinguished road
Default

Hi,
I checked with chown command. but it doesn't work. And in httpd.conf file the user written is apache. So I changed the owner as apache and group apache. But same result.

using visudo command I added this line

www-data, apache, username ALL=NOPASSWD: /usr/bin/autopasswd

Am I still missing something?
Reply With Quote
  #9 (permalink)  
Old 05-24-2007, 10:11 PM
Member
User
 
Join Date: Jun 2005
Posts: 78
Rep Power: 0
jerry
Default

it is related to permission only, btw, correct syntax for sudo is as follows
Code:
apache ALL=NOPASSWD: /usr/bin/autopasswd
and
Code:
chown apache:apache /usr/bin/autopasswd
hope this help out
Reply With Quote
  #10 (permalink)  
Old 05-24-2007, 10:32 PM
Junior Member
User
 
Join Date: May 2007
My distro: Debian
Posts: 5
Rep Power: 0
james bond is on a distinguished road
Default

In error.log its saying this
Code:
setresuid(user_uid, user_uid, 0): Operation not permitted
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 
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 On
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads

Thread Thread Starter Forum Replies Last Post
Change root password using perl script? Raj1 Solaris/OpenSolaris 8 06-13-2008 11:01 PM
how to change root password sandromax Solaris/OpenSolaris 4 10-11-2007 02:43 AM
HP UX user lock password, change password, password aging rockdalinux HP-UX 0 12-20-2006 02:36 PM
How to Change Password puppen Linux software 6 06-06-2006 01:56 PM
change password under linux Linux software 1 01-18-2006 07:38 PM


All times are GMT +5.5. The time now is 12:06 PM.


Powered by vBulletin® Version 3.7.2 - Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36