Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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? If it helps, the application will be running as root.

share|improve this question

2 Answers 2

up vote 8 down vote accepted

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.

share|improve this answer

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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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