Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!igor!rutabaga!mcuddy From: mcuddy@rutabaga.Rational.COM (Mike Cuddy) Newsgroups: comp.unix.aix Subject: Re: How can I set passwords from script/file? Message-ID: Date: 15 May 91 23:52:34 GMT References: <1991May13.155155.258@vax1.cc.lehigh.edu> Sender: news@Rational.COM Lines: 63 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 #include #include main(argc,argv) int argc; char **argv; { struct userpw *pw; if (argc < 2 || argc > 3) { fprintf(stderr,"Usage: setpass []\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