LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Closed Thread
  Search this Thread
Old 02-04-2010, 03:00 AM   #1
saifurab
Member
 
Registered: Mar 2007
Posts: 30

Rep: Reputation: 15
script to change samba users password


hello,

I want to create a webpage where users can change their samba password and before I jump to PHP code i want to write perl code that can be called in php code.

I have created two file
1. main.pl - this script actually switch user and call passwd.pl
2. passwd.pl - this is actually changes the password

{main.pl}

#!/usr/bin/perl

my $username = $ARGV[0];
my $oldpass = $ARGV[1];
my $newpass1 = $ARGV[2];
my $newpass2 = $ARGV[3];

open(USER, "|su - $username -c /script/passwd.pl \" $oldpass $newpass1 $newpass2\" ");
close(USER);

{passwd.pl}

#!/usr/bin/perl

my $oldpw = $ARG[0];
my $newpw_1 = $ARG[1];
my $newpw_2 = $ARG[2];
my $smbpasswd = "/usr/bin/smbpasswd";

&pw_change($smbpasswd,$username,$oldpw,$newpw_1,$newpw_2);

sub pw_change(){
my ($smbpasswd,$username,$oldpw,$newpw_1,$newpw_2) = @_;

if ( "$newpw_1" eq "$newpw_2" ) {

open (FILE, "|$smbpasswd -s") or die("cannot pipe into $smbpasswd: $!");

print FILE qq|$oldpw\n|;
print FILE qq|$newpw_1\n|;
print FILE qq|$newpw_1\n|;
close (FILE);
}
}


if I switch to user whom i want to change the password passwd.pl allows me the change the password but when i call this script from my main.pl, the arguments doesn't passes to passwd.pl

e.g. I call it as

./main.pl <user name> <old_pass> <new_pass_1> <new_pass_2>


Hope this make sense

Saif

Last edited by saifurab; 02-04-2010 at 04:49 AM.
 
Old 02-04-2010, 05:12 AM   #2
catkin
LQ 5k Club
 
Registered: Dec 2008
Location: Tamil Nadu, India
Distribution: Debian
Posts: 8,578
Blog Entries: 31

Rep: Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208Reputation: 1208
Duplicate question. Removed from the zero reply list by this reply and reported.
 
  


Closed Thread



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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
script to change samba users password saifurab Programming 1 02-05-2010 12:59 AM
Avoid users to change password sinchan_ Linux - General 10 10-21-2009 02:48 PM
Help in LDAP; Users can change their password ashwintumma Linux - Software 1 08-22-2009 10:24 AM
How to make Samba users change password on first use eflester Linux - Security 0 10-12-2004 06:41 PM
Just change Samba password, not Unix password? sorrodos Linux - Networking 1 08-14-2003 07:52 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:40 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration