views:

662

answers:

3

Does anyone have any sample code in objective-c for connecting to an external Open Directory server and searching a specific node like /Users/?

I looked through the OD guide on Apple and I couldn't figure it out.

Thanks!

+2  A: 

Is this the "OD guide" you looked through? Seems to come with pretty rich and extensive code examples -- which of those examples are you finding yourself stumped at?

Alex Martelli
+1  A: 

There's actually a much nicer CoreFoundation and Objective-C wrapper around those APIs in Leopard, although it's a private framework in 10.5.

The good news is that it's open-sourced, so you can grab the source code directly from Apple. The bad news is that it references a couple of headers in other private frameworks (DirectoryServiceCore/CSharedData.h and CoreFoundation/CFRuntime.h), which makes it somewhat difficult to build your own copy for embedding. You can do so, however, but you'd need to grab the relevant headers from those other projects to do so.

In the meantime however, you may find the code in that project illustrative for writing your own.

For more useful embeddable code, you can look at the open-source DSTools project, most specifically at the DSObjCWrappers routines. This used to be part of the loginwindow application but got separated out in 10.3 or 10.4 as I recall. However, unlike the new one it doesn't require access to any private APIs. I also know from personal experience that it's possible to just copy & import the whole DSObjCWrappers folder straight into your own project and use it in-place, although I'd suggest changing all the class names using Xcode's refactoring support to avoid namespace clashes (i.e. change 'DSoAttribute' to 'MyDSAttribute', etc.).

Jim Dovey
A: 

Thanks for all the good suggestions guys, I think just using C is the way to go for my needs. I found this site helpful: http://www.mozilla.org/directory/csdk-docs/writing.htm

christo16