Apparently there is a function (getpwnam) that given a username, will return the appropriate entry in /etc/passwd with the other details for that user (shell, uid, gid, etc.).

However, I have no idea how to get that function working with the shadow password file (/etc/shadow). Is this possible? The application will be running as root.


The whole point of the shadow password file is that getpwnam doesn't return passwords from it. You need to look at man 3 shadow and getspnam in particular.


That is not possible due to 2 reasons:

  • The shadow file is one method of authentication in modern system. Some of them does not involve real password at all - what should return if user is authenticated by fingerprint? Why should it break any application?
  • Giving the hashed string for non-root application would enable off-line attacks.

It is system-specific file anyway with no so much complicated structure so if you need it you can write your own parser.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.