Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

c program to change user's password?

332 views
Skip to first unread message

Vincent Chen

unread,
Nov 29, 1998, 3:00:00 AM11/29/98
to

Hi, All

I am trying to write a cgi in C to let our user changing their password
through browser. But some questions arised:

1. I referenced several source packages and it seems that my program
must create a new master.passwd file. Is this the only way or there
are system call to help me update user's password?

2. If I created a new master.passwd file, I have to run pwd_mkdb to update
my password database. What function call is available to do this?

3. If I want my program portable to linux or solaris, Is it true that all I have
to do is update shadow file directly?

any help would be greatly appreciated.

---

Vincent Chen
vcb...@ms1.hinet.net
Taipei,Taiwan
R.O.C.


W Gerald Hicks

unread,
Nov 29, 1998, 3:00:00 AM11/29/98
to
You might consider how the tkpasswd program which comes with Expect accomplishes
this. This should help with portability issues too. I would *not* go directly
mucking about in the user metadata.

If you implement your CGI script in Tcl, you can probably cut and paste a lot of
this code directly.

(see /usr/ports/lang/expect)

Hope this is a machine not open to the Internet, or at least is using SSL. I'd
be concerned about others seeing plaintext passwords flying around ;-)

Good Luck,

Jerry Hicks
wgh...@bellsouth.net

Wayne Cuddy

unread,
Nov 29, 1998, 3:00:00 AM11/29/98
to Vincent Chen
What about opening up a pipe to the passwd program from the cgi script
and displaying the results to the screen?

On Sun, 29 Nov 1998, Vincent Chen wrote:

> Date: Sun, 29 Nov 1998 15:35:05 GMT
> From: Vincent Chen <vcb...@ms1.hinet.net>
> Newsgroups: comp.unix.bsd.freebsd.misc
> Subject: c program to change user's password?

David Malone

unread,
Nov 29, 1998, 3:00:00 AM11/29/98
to
vcb...@ms1.hinet.net (Vincent Chen) writes:


> I am trying to write a cgi in C to let our user changing their password
>through browser. But some questions arised:

I'd suggest that you use expect or an expect like C program to
use /usr/bin/passwd to change the person's password from within
the CGI script. That way you know that it will be easy to port
to other OSs and you don't need to know anything about how their
password file works... Expect is in ports and packages.

David.


John J. Rushford Jr.

unread,
Dec 1, 1998, 3:00:00 AM12/1/98
to
Wayne Cuddy (wayne@*remove-this*crb-web.com) wrote:
: What about opening up a pipe to the passwd program from the cgi script

: and displaying the results to the screen?


For best portability accross Solaris, FreeBSD, etc, I'd exec()
the 'passwd' command to change the password. However, there is a
trick to doing this. It seems that /bin/passwd does not read
from 'stdin'. Instead, /bin/passwd opens /dev/tty to read
input. /dev/tty is a synonym in the kernel for a processes
controlling tty so a pipe(), fork(), exec() will not work.
I ran into exactly this problem awhile back and solved it using
a pseudo tty for interprocess commnunication in place of a
pipe(). A pseudo tty can be made to be a processes controlling
terminal. For the programming model to use, code snippets, etc,
see Stevens "UNIX Network Programming", ISBN 0-13-949876-1,
beginning on page 600.

regards

--
John J. Rushford
j...@sapphire.alisa.org
j...@cs.du.edu
http://www.cs.du.edu/~jjr

Michael Kondrashin

unread,
Dec 4, 1998, 3:00:00 AM12/4/98
to
>> I am trying to write a cgi in C to let our user changing their password
>>through browser. But some questions arised:
In FreeBSD, adduser(8) is perl script, you can refer to it, to see how
things of this kind done there.

0 new messages