[comp.unix.admin] Changing Passwords From A Batch File

brunette@sjuphil.uucp (Glenn M. Brunette) (11/12/90)

I was wondering if it is possible to change a users password by redirecting 
input from a data file.  At our installation, there are about 40 temporary
accounts that need to exist, but because of problems that we have been having
with them, we would like to set up a cron that would change the password 
as needed.  The cron part is easy, but getting the passwd program to 
recognise the input redirection is what is giving us the program. Does anyone
have any ideas?

Ideally we would want something like this:

   #changepw "oldpasswd" "newpasswd"

that would go through all of the desired accounts and change the passwords
to those directed.

BTW, we are running SunOS 4.1 on a Sun SparcServer 4/490.  


Thanks in advance,

   Glenn


-- 
******************************************************************************* 
 Glenn Brunette,  Academic Computing Consultant              sssss
                                                           ss      jjjjjjj
 Addresses:  brunette%sjuphil.sju.edu@bagate.bell-atl.com   sss      j
             brunette@sjuphil.UUCP                           ss     j  u    u
             brunette%sjuphil.sju@sh.cs.net             sssss      j  u    u

jik@athena.mit.edu (Jonathan I. Kamens) (11/12/90)

In article <1990Nov12.035942.14096@sjuphil.uucp>, brunette@sjuphil.uucp (Glenn M. Brunette) writes:
|> I was wondering if it is possible to change a users password by redirecting 
|> input from a data file.  At our installation, there are about 40 temporary
|> accounts that need to exist, but because of problems that we have been having
|> with them, we would like to set up a cron that would change the password 
|> as needed.  The cron part is easy, but getting the passwd program to 
|> recognise the input redirection is what is giving us the program. Does anyone
|> have any ideas?

  Well, presumably if you're changing passwords, you've got root access to the
system.  So write your own program to edit the passwd file.  You're allowed to
do that, you're root.  If you don't know any of (a) how to encrypt a password
in a C program, (b) how to store a new password in the passwd file from a C
program, or (c) how to not open security holes while doing the testing, I'd
suggest you not do things this way.

  Alternatively, get Dan Bernstein's "pty" package from the comp.sources.unix
archives and do

  (echo new-password; echo new-password) | pty passwd username

-- 
Jonathan Kamens			              USnail:
MIT Project Athena				11 Ashford Terrace
jik@Athena.MIT.EDU				Allston, MA  02134
Office: 617-253-8085			      Home: 617-782-0710

scs@lokkur.dexter.mi.us (Steve Simmons) (11/13/90)

brunette@sjuphil.uucp (Glenn M. Brunette) writes:

>I was wondering if it is possible to change a users password by redirecting 
>input from a data file.

Under normal circumstances, no.  You probably want to get a copy of
expect.  FTP it from durer.cme.nist.gov, or send the message 
  send pub/expect.shar.Z
library@durer.cme.nist.gov.  You will need the tcl library as well,
stored in the same place.  This will let you write the scripts you
want.
-- 
" . . . within a nanometer (about a billionth of a yard) . . . "
  Reader's Digest, November 1990, pp. 31

jfh@rpp386.cactus.org (John F. Haugh II) (11/14/90)

In article <1990Nov12.035942.14096@sjuphil.uucp> brunette@sjuphil.uucp (Glenn M. Brunette) writes:
>Ideally we would want something like this:
>
>   #changepw "oldpasswd" "newpasswd"
>
>that would go through all of the desired accounts and change the passwords
>to those directed.

Ideally you would want to read the user name, old password and
new password from a data file.  The reason is that ps would
be able to see the passwords as they were changed.
-- 
John F. Haugh II                             UUCP: ...!cs.utexas.edu!rpp386!jfh
Ma Bell: (512) 832-8832                           Domain: jfh@rpp386.cactus.org
"SCCS, the source motel!  Programs check in and never check out!"
		-- Ken Thompson

jfh@rpp386.cactus.org (John F. Haugh II) (11/14/90)

In article <18730@rpp386.cactus.org> jfh@rpp386.cactus.org (John F. Haugh II) writes:
>Ideally you would want to read the user name, old password and
>new password from a data file.  The reason is that ps would
>be able to see the passwords as they were changed.

I've written a utility which does exactly what I described above.
It does not work with SunOS (because of passwd.adjunct), but does
work with V7-format /etc/passwd, and SVR3.2 or SVR4-format
/etc/shadow files.  You pick which one you want at compile time,
and it gives that variety to you.  The code figures out the
difference between SVR3.2 and SVR4 /etc/shadow files (sort of,
it may have problems I don't know about just yet ...)

Depending on how many requests I get I'll either mail individual
copies or post the code to alt.sources.
-- 
John F. Haugh II                             UUCP: ...!cs.utexas.edu!rpp386!jfh
Ma Bell: (512) 832-8832                           Domain: jfh@rpp386.cactus.org
"SCCS, the source motel!  Programs check in and never check out!"
		-- Ken Thompson

jfh@rpp386.cactus.org (John F. Haugh II) (11/17/90)

In article <18731@rpp386.cactus.org> jfh@rpp386.cactus.org (John F. Haugh II) writes:
>Depending on how many requests I get I'll either mail individual
>copies or post the code to alt.sources.

Well, I got a number of requests, so I just posted it to alt.sources.
-- 
John F. Haugh II                             UUCP: ...!cs.utexas.edu!rpp386!jfh
Ma Bell: (512) 832-8832                           Domain: jfh@rpp386.cactus.org
"SCCS, the source motel!  Programs check in and never check out!"
		-- Ken Thompson