How do I get a user UID by username in Objective C/C in OS X? Currently I know how to get UID of user who launched app when I call this code:
uid_t uid = getuid();
NSLog(@"uid: %d", uid);
But I need to get the user's UID by username.
EDIT: Also tried:
struct passwd *ss = getpwnam("myusername");
NSLog(@"uid: %d", ss->pw_uid);
and it returns "502" which is correct. It's heppens in case when I run my application under "myusername".
If I run my app under root using the same code it returns "0" which is incorrect. I expect to receive "502" in both cases because I set parameter "myusername" in both cases.