[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How do I programaticlly change a password...
On Mon, 15 Mar 1999, James Olin Oden wrote:
>Hi,
>
>I have been trying to write a program that will change a users password
>(yes I know there is passwd). I have found the various api's to read
>the password and shadow password file, but I am having trouble finding
>api/system calls to change the this information (specifically the user's
>password). I have gotten so far as to be able to "authenticate" (take
>their old password crypt it, find them in the password or shadow file,
>and compare the crypted passwords). Its just this last step of actually
>making the change that is proving to be stumbling block. I know I could
>just open the passwd or shadow file (whichever one is being used to
>store the password) up for update and make this change manually, but I
>would like to do things the "right"way if possible.
>
>Could anyone point me to a man page, web site, or anything?
The general idea when modifying a password file is, to make a new copy of
the entire file (with your changes) and then lock, move the file into the
place of the old one, and unlock it. The lock/unlock is needed if syscalls
are interruptible (Linux's are). Spend as little time as possible locking
the file (logins etc are impossible during this time).
Note that you must cope with all the versions of password files that exist
(including possibly auto detect) because if you ***** up then the system
may become un-usable. As extra biblography, I'd recommend the sources of
the program 'passwd' ;)
hope this helps,
Peter
PS: Did I mention that you back up the old passwd file ? PS2: Your
program must of course be concurrent access, f.ex. someone else may be
running passwd just then. Enjoy ;)