title: How can I get the domain name for a user logged into a Mac via Active Directory
body: <p>In my Cocoa app how can I get the current user's domain when they're logged in via Active Directory?</p>
  
  <p>I need to determine two things:</p>
  
  <ol>
  <li>If the current user is logged on to an Active Directory domain (only need to handle Active Directory).</li>
  <li>If 1, the domain of the user.</li>
  </ol>
  
  <p>I've found references to <a href="http://developer.apple.com/Mac/library/documentation/Networking/Reference/Open%5FDirectory%5FRef/Reference/reference.html" rel="noreferrer">Directory Services</a> and the <a href="http://developer.apple.com/mac/library/documentation/Networking/Conceptual/Open%5FDirectory/Introduction/Introduction.html" rel="noreferrer">Open Directory Programming Guide</a> 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.</p>