Re: How do I access NetInfo from Cocoa?
Re: How do I access NetInfo from Cocoa?
- Subject: Re: How do I access NetInfo from Cocoa?
- From: email@hidden
- Date: Mon, 8 Oct 2001 20:43:04 -0500
On Monday, October 8, 2001, at 08:02 PM, Josh M. Hurd wrote:
Is there a Cocoa class that allows access to NetInfo?
How can I retrieve user info from the NetInfo database? I need the UID
of any given username.
I searched the docs and found only <netinfo/ni.h> which did not import
into my project. Complained about variable redefinitions.
If someone has a quick example I would appreciate it!
There was a great set of classes -- they're gone now, replaced by
DirectoryServices, which is a not-so-great set of C functions.
To do what you're asking, check out the posix function 'getpwuid'. It's
detailed in the system manual (enter 'man getpwuid' in Terminal, or use
one of the friendly Manual page browsers available on the net).
Here's an example:
#import <pwd.h>
struct passwd* pwdPtr;
int uid_number = 101;
pwdPtr = getpwuid(uid_number);
if(pwdPtr && pwdPtr->pw_name)
{
NSLog(@"User name = %s",pwdPtr->pw_name);
}
I haven't compiled this -- just typed it into Mail -- but it should be
close.
Brian
email@hidden
http://personalpages.tds.net/~brian_hill
"Why? I came into this game for adventure - go anywhere, travel
light, get in, get out, wherever there's trouble, a man alone.
Now they've got the whole country sectioned off and you can't
move without a form. I'm the last of a breed."
-- Archibald "Harry" Tuttle, Rogue HVAC Repairman