LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 07-22-2003, 09:38 PM   #1
Rex_chaos
Member
 
Registered: Aug 2001
Location: GD, GZ, China
Posts: 240

Rep: Reputation: 30
help shell script


hi all,
please tell me how to implement the following functions with script

1) let user name as an argument, if this user exists return 0 otherwise return 1

2) call 'passwd' for changing the password of a user, catch the output code from passwd to see if the password inputed by user is valid. if not, ask the user to reinput the password until it valid

3) after a user have input the password, how can I save the password to file?

Thanks in advance.
 
Old 07-23-2003, 07:29 AM   #2
sidey
Member
 
Registered: Mar 2003
Location: Essex UK
Distribution: rh 8.0 bsd 5.0 slack 9.0 rc2 crux
Posts: 147

Rep: Reputation: 15
This is horrible untested code so it probably wont work, but it should give you the outline of what you need to do.


#!/usr/bin/sh

# We are taking user as an argument which will be stored in $1

if cat /etc/passwd | grep -s $1 >> /dev/null #So, does the user exist??? cat the current passfile and grep.
then
echo "User exists, continuing" #woo the prodigal son is found, and there was much rejoicing.
echo "Make my day punk, enter the new password " #erm......, i smoke crack.
read pass #read the new pass in.
grub-md5-crypt $pass #prints out md5 password

#now here you just have to type the format for the users /etc/pass entry
#taking into account /home dir and uid/gid etc. stick it all together
#and concatenate with current /etc/passwd, removing the old user entry

else #edited this from elif to else
echo "User has gone out for coffee, bailing......AIEEEEEEEEE I DIED" #oops the user is dead
exit 2 #lets get outta here nothing more we can do
fi

Last edited by sidey; 07-23-2003 at 01:37 PM.
 
Old 07-23-2003, 08:06 AM   #3
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,394
Blog Entries: 55

Rep: Reputation: 3566Reputation: 3566Reputation: 3566Reputation: 3566Reputation: 3566Reputation: 3566Reputation: 3566Reputation: 3566Reputation: 3566Reputation: 3566Reputation: 3566
3) after a user have input the password, how can I save the password to file?
I would like to first ask what *application* needs this functionality. If this is for external accounts needed for just one service like FTP or POP3, (not needing interactive shell on server) then possibly using a separate passwd database should be safer (provided the app has the correct PAM hooks). Look for instance at Vsftpd and how it uses PAM for virtual users.

Granted, you'll loose passwd checking PAM does itself, but if you look at for instance Solar Designer's PAM passwd check module you can see ways to do some of this validation yourself.
 
Old 07-24-2003, 02:55 AM   #4
sidey
Member
 
Registered: Mar 2003
Location: Essex UK
Distribution: rh 8.0 bsd 5.0 slack 9.0 rc2 crux
Posts: 147

Rep: Reputation: 15
i think he just wants a front end??!?!?!?! to passwd dunno why though :/
 
Old 07-24-2003, 10:02 AM   #5
oubipaws
Member
 
Registered: Mar 2003
Location: Frederick, MD
Distribution: Dux Linux 1 / Gentoo 1.4
Posts: 77

Rep: Reputation: 15
echo $PASSWORD >> ~/[I]filename

would output the password user inputted into a file in the home ditectory... but are you talking about a system wide password?
 
Old 07-24-2003, 10:47 PM   #6
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,394
Blog Entries: 55

Rep: Reputation: 3566Reputation: 3566Reputation: 3566Reputation: 3566Reputation: 3566Reputation: 3566Reputation: 3566Reputation: 3566Reputation: 3566Reputation: 3566Reputation: 3566
i think he just wants a front end??!?!?!?! to passwd dunno why though :/
That's what I mean. We're all trying to answer the question w/o actually knowing what he wants. I'm just hoping it aint for mucking with *real* user accounts.
 
Old 07-25-2003, 02:53 AM   #7
sidey
Member
 
Registered: Mar 2003
Location: Essex UK
Distribution: rh 8.0 bsd 5.0 slack 9.0 rc2 crux
Posts: 147

Rep: Reputation: 15
Yeah its just like being out in industry , except we're not getting paid
 
Old 07-29-2003, 11:48 AM   #8
Rex_chaos
Member
 
Registered: Aug 2001
Location: GD, GZ, China
Posts: 240

Original Poster
Rep: Reputation: 30
so, after a user's input a password, how can I check if the password is correct

BTW. I can get a prompt by reading PS1. But how can I get a prompt for root?

Last edited by Rex_chaos; 07-29-2003 at 11:50 AM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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



Similar Threads
Thread Thread Starter Forum Replies Last Post
Shell script inside shell script treotan Linux - General 4 02-19-2009 06:34 AM
Shell Scripting: Getting a pid and killing it via a shell script topcat Programming 15 10-28-2007 02:14 AM
shell script problem, want to use shell script auto update IP~! singying304 Programming 4 11-29-2005 05:32 PM
Directory listing - Calling shell script from a CGI script seran Programming 6 08-11-2005 11:08 PM
[SHELL SCRIPT] Write at the right of the shell window Creak Linux - General 2 04-02-2004 03:00 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 08:29 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration