[comp.unix.aix] How can I set passwords from script/file?

lusgr@vax1.cc.lehigh.edu (Steve Roseman) (05/14/91)

Does anyone have a good way of setting user passwords from a file, script,
etc.?  Running "passwd username <file" gives a "Must run from tty" error
message.  I need this capability for administrative mass password setting, and
changing the user interface for passwd (not my idea.)

Thanks,
Steve

-------------------------------------------------------------------------
Steve Roseman
Lehigh University Computing Center
LUSGR@VAX1.CC.Lehigh.EDU
 

josevela@mtecv2.mty.itesm.mx (Jose Angel Vela Avila) (05/14/91)

lusgr@vax1.cc.lehigh.edu (Steve Roseman) writes:

>Does anyone have a good way of setting user passwords from a file, script,
>etc.?  Running "passwd username <file" gives a "Must run from tty" error
>message.  I need this capability for administrative mass password setting, and
>changing the user interface for passwd (not my idea.)



 You could use expect for do anything you want from a interactive process..

 All this in a script of course ....


 If you need more information, drop me an email...

 
Jose A. Vela A.
josevela@mtecv2.mty.itesm.mx

hugo@saturn.ucsc.edu (Hugo Calendar) (05/14/91)

In article <1991May13.155155.258@vax1.cc.lehigh.edu> lusgr@vax1.cc.lehigh.edu (Steve Roseman) writes:
>Does anyone have a good way of setting user passwords from a file, script,
>etc.?  Running "passwd username <file" gives a "Must run from tty" error
>message.  I need this capability for administrative mass password setting, and
>changing the user interface for passwd (not my idea.)

You could try writing some C code to alter the /etc/passwd file, or
use some C in conjunction with awk or something.  Use the "crypt()"
function to generate password encryptions, (see man crypt).  If you
don't get my drift, mail me, and I'll send you something workable.

Hugo

mcuddy@rutabaga.Rational.COM (Mike Cuddy) (05/16/91)

lusgr@vax1.cc.lehigh.edu (Steve Roseman) writes:

>Does anyone have a good way of setting user passwords from a file, script,
>etc.? ...

>Steve Roseman
>Lehigh University Computing Center
>LUSGR@VAX1.CC.Lehigh.EDU

I use this little program: (I call setpass.c) I think that this is even the
'right' way to do this. (mind ya', you'll have to get you're own password
encrypting function (Std. unix alg.)  I grabbed some stuff off of 
comp.sources.unix a couple of months ago.

---snip-da-do ---snip-da-do ---snip-da-do ---snip-da-do
#include <stdio.h>
#include <userpw.h>
#include <usersec.h>

main(argc,argv)
int argc;
char **argv;
{
    struct userpw *pw;

    if (argc < 2 || argc > 3) {
	fprintf(stderr,"Usage: setpass <user> [<encrypted-password>]\n");
	exit(1);
    }

    if (setpwdb(S_READ|S_WRITE) < 0) {
	perror("setpass: setpwdb"); exit(1);
    }

    if ((pw = getuserpw(argv[1])) == NULL) { 
	perror("setpass: getuserpw"); exit(1); 
    }

    if (argc == 2) { 
	printf("%s\n",pw->upw_passwd); exit(0); 
    }

    pw->upw_passwd = argv[2];

    pw->upw_flags |= PW_ADMCHG;
    pw->upw_lastupdate |= time(0);

    if (putuserpw(pw) < 0) { 
        perror("setpass: putuserpw"); exit(1); 
    }

    if (endpwdb() < 0) { 
	perror("setpass: endpwdb"); exit(1); 
    }

    exit(0);
}
---snip-da-do ---snip-da-do ---snip-da-do ---snip-da-do
--Mike Cuddy
"...He's a UNIX hack and he's okay, he works all night and he sleeps all day..."
Well, where I come from, we have a saying: "If you're not going to grab the 
bull by the horns while the iron is in the fire, then get off the pot." 
(There are a lot of chemicals in the water where I come from.) -- Dave Barry