I've done some research and I'm still struggling with the passwd structure.
http://www.opengroup.org/onlinepubs/000095399/basedefs/pwd.h.html
I need to obtain the user ID, however, I don't think I'm understanding the function for this at all:
int getpwuid_r(uid_t, struct passwd *, char *, size_t, struct passwd **);
This function call returns a pointer to a structure that will contain all the data I need. I'm a little confused about the function parameters, such as:
struct passwd
Do I need to declare this first? Something like struct passwd passwd?
I'm just totally lost on how to use the function.
Lastly, once I "fill" my pointer, what calls can I use to obtain the data?
Thanks for any help.
In the
getpwuid_rsignature:uidis an input parameter - it is the UID of the user that you want to look up. The rest are essentially output parameters: the structure pointed to bypwbufwill be filled with the password information, and the pointer pointed to bypwbufpwill be set to the value ofpwbufif the call was successful (andNULLif it was not). Thebufandbuflenpair of parameters specify a user-supplied buffer that will be used to store the strings pointed to by members of thestruct passwdstructure that is returned.You would use it like so (this looks up the user with UID 101):
If instread you want to look up a user by name to find their ID, use
getpwnam_rand examine thepw_uidfield of the returned struct.