Operating System - HP-UX
1829535 Members
1738 Online
109992 Solutions
New Discussion

Updating passwords using PAM functions

 
SOLVED
Go to solution
Kristin_1
Occasional Contributor

Updating passwords using PAM functions

Hi,
I'm creating a login program that uses functions supported by PAM. It compares passwords with another system & if the passwords are different I want to update the password on the unix machine to match the machine I'm checking with. Right now I'm using fgetpwent to find the user & keep a file pointer to the position in the file to update. I'm using putpwent to overwrite the password file entry. This means I must know which file to open. Is this the correct way to be updating passwords or is there a better way?

Also at a later date I need to be able to get this working with systems running NIS. Are there different functions used to update passwords?

Thanks,
Kristin
3 REPLIES 3
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: Updating passwords using PAM functions

Unless you specifically are wanting to examine files other then /etc/passwd you can use getpwent(),putpwent() and no worry about the pathname. You should also be aware of another wrinkle; trused & non-trusted systems. On trusted systems you must augment your getpwent()'s and putpwent()'s with getprpwent()'s and setprpwent()'s which update the trusted database entries.
With NIS, check out the yppasswd (3) function
which will update the NIS map's on the fly. You can always choose to use the standard passwd functions on the primary NIS server and then invoke ypmake to update and push the NIS maps. In any event, you are basically on the right track.
--- Hope some of this helps, Clay
If it ain't broke, I can fix that.
Kristin_1
Occasional Contributor

Re: Updating passwords using PAM functions

Hi,
Putpwent function requires a file pointer to that specific file. I want to overwrite the existing password for that user in that file which means I need a pointer to where it exists. Is there another function that will allow me to overwrite a specific user record within a file?
I need to be able to manipulate these files to replace the existing password with the password being sent to me by the other machine when these passwords are different. The 2 functions I am using don't use the nsswitch.conf file. Any solutions?
A. Clay Stephenson
Acclaimed Contributor

Re: Updating passwords using PAM functions

You're right Kristin. Putpwent does need a file pointer. I probably don't need to remind you but anytime you are doing this development make sure that you are logged in as root in at least two places with a saved copy of /etc/passwd somewhere - just in case.

Clay
If it ain't broke, I can fix that.