Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get the domain name for a user logged into a Mac via Active Directory

In my Cocoa app how can I get the current user's domain when they're logged in via Active Directory?

I need to determine two things:

  1. If the current user is logged on to an Active Directory domain (only need to handle Active Directory).
  2. If 1, the domain of the user.

I've found references to Directory Services and the Open Directory Programming Guide but the latter is 10.6 only (I must support 10.5+) and I could not find any examples for the former that gave me an idea of what I needed to do.

like image 803
Lawrence Johnston Avatar asked Jun 01 '10 21:06

Lawrence Johnston


People also ask

Can a Mac join an Active Directory domain?

You can use the dsconfigad command to bind a Mac to Active Directory via the terminal app. All you need to do is run the following command. Note that you need to replace the domain name, computer name, password, etc. with your specific information.

Can you join a Mac to Azure AD?

As a result, your users can leverage their Azure AD user names (User Principal Name) and passwords as Managed Apple IDs. They can then use their Azure AD credentials to sign in to iCloud on their assigned iPad or Mac and even to iCloud on the web. Students and employees can also use it to sign in on Shared iPad.


2 Answers

dsconfigad -show

It will tell whether you are bound to a directory and details about that directory if bound. Then you will know how to script dscl.

like image 75
speeds images Avatar answered Sep 30 '22 23:09

speeds images


I think you can use same idea as here:

Mac OSX: Determing whether user account is an Active Directory user vs. local user using objective-c

you just need to look for Network or Authentication node (it's kODNodeTypeAuthentication type) and query it for kODAttributeTypeRecordName with query value set to current user name. Then look at search result, you'll find many interesting things there :)

like image 38
mcFactor Avatar answered Sep 30 '22 22:09

mcFactor