• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How do I access NetInfo from Cocoa?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How do I access NetInfo from Cocoa?


  • Subject: Re: How do I access NetInfo from Cocoa?
  • From: "Josh M. Hurd" <email@hidden>
  • Date: Mon, 8 Oct 2001 19:01:46 -0700

Excellent! Thank you both!

Here is what I came up with:

struct passwd *theUserInfo;
NSString *UID;

theUserInfo = getpwnam([[userName stringValue] cString]);

UID = [[NSNumber numberWithInt:theUserInfo->pw_uid] stringValue];

userName is a user editable TextField.
UID is an NSString because I need it in a pathname.

Thanks again!
M


On Monday, October 8, 2001, at 06:43 PM, email@hidden wrote:


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


  • Follow-Ups:
    • Re: How do I access NetInfo from Cocoa?
      • From: Douglas Davidson <email@hidden>
References: 
 >Re: How do I access NetInfo from Cocoa? (From: email@hidden)

  • Prev by Date: Re: How do I access NetInfo from Cocoa?
  • Next by Date: Another Table View Question
  • Previous by thread: Re: How do I access NetInfo from Cocoa?
  • Next by thread: Re: How do I access NetInfo from Cocoa?
  • Index(es):
    • Date
    • Thread