LinuxSA Mailing list archives

Index: [thread] [date] [subject] [author]
  From: Geoffrey D. Bennett <g@netcraft.com.au>
  To  : Darryl Ross <darryl@bachblue.com.au>
  Date: Mon, 15 Mar 1999 14:35:19 +1030 (CST)

Re: /etc/passwd

> I'm in the planning stages of writing a C program that I am going to set up
> as a CGI script and set it up so that I can add, delete and modify users on
> my RH5.2 system using a web interface and forms. As I see it, I have two
> options for doing this. Getting my program to directly open the /etc/passwd
> file and make the modifications, or get my program to call the useradd,
> userdel or usermod programs as required and pass the arguments to that to
> make the changes.

Hi there,

The standard passwd encryption algorithm is implemented using the C
function crypt().  I wouldn't recommend doing this though, since it's
not uncommon to use shadow or md5 passwords with Linux, both of which
will require different methods to add/remove users and change
passwords.

I'd suggest using useradd, userdel, and passwd since these will still
work if you use shadow or md5 passwords.  You can't call passwd
directly though since it expects to be used interactively; use
autopasswd (from the expect package).

One other thing -- autopasswd doesn't work too well out of the box;
try this version instead:

-----8<-----8<-----8<-----8<-----8<-----8<-----8<-----
#!/usr/bin/expect --
# 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 "password:"
sleep 0.1
send -- "$password\r"
expect "password:"
sleep 0.1
send -- "$password\r"
expect eof
-----8<-----8<-----8<-----8<-----8<-----8<-----8<-----

Regards,
-- 
Geoffrey D. Bennett (geoffrey@netcraft.com.au)
Computer Systems Manager, NetCraft Australia
http://www.netcraft.com.au/geoffrey/
Red Hat Linux Resellers: http://www.netcraft.com.au/linux/

-- 
Check out the LinuxSA web pages at http://www.linuxsa.org.au/
To unsubscribe from the LinuxSA list:
  mail linuxsa-request@linuxsa.org.au with "unsubscribe" as the subject


Index: [thread] [date] [subject] [author]
Return to the LinuxSA Mailing List Information Page