How can I set passwords from script/file?

Mike Cuddy mcuddy at rutabaga.Rational.COM
Thu May 16 09:52:34 AEST 1991


lusgr at 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 at 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



More information about the Comp.unix.aix mailing list