Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I was looking to how to detect if user has local account or ANY network directory account (ActiveDir or OpenDir). So what I have done using Open Directory framework is like this:</p> <ol> <li>get default ODSession session</li> <li>get local node – kODNodeTypeLocalNodes (I don't want to send queries to server all the time)</li> <li>query node for kODAttributeTypeNFSHomeDirectory with querying value set to current user's home directory</li> <li>if found then it means user is local if not (bacause we query local node ony) – user has network account</li> </ol> <p>so something like this:</p> <pre><code>static BOOL isLocalUser = NO; static BOOL shouldKeepRunning = YES; // global -(BOOL)isLocalUser { isLocalUser = NO; // set default to NO here NSError* err; ODSession *mySession = [ODSession defaultSession]; ODNode *myNode = [ODNode nodeWithSession:mySession type:kODNodeTypeLocalNodes error:&amp;err]; ODQuery *myQuery = [ODQuery queryWithNode: myNode forRecordTypes: kODRecordTypeUsers attribute: kODAttributeTypeNFSHomeDirectory matchType: kODMatchEqualTo queryValues: NSHomeDirectory() returnAttributes: kODAttributeTypeStandardOnly maximumResults: 0 error: &amp;err]; [myQuery retain]; [myQuery setDelegate: self]; [myQuery scheduleInRunLoop: [NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode]; NSRunLoop *theRunLoop = [NSRunLoop currentRunLoop]; while (shouldKeepRunning &amp;&amp; [theRunLoop runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]]); return isLocalUser; } - (void)query:(ODQuery *)inSearch foundResults:(NSArray *)inResults error:(NSError *)inError { if (!inResults &amp;&amp; !inError) { [inSearch removeFromRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode]; [inSearch release]; shouldKeepRunning = NO; // end of search } ... // check what you found here // if found any nodes, user is local so isLocalUser = YES; } </code></pre> <p>Another idea is to use Identity services:</p> <ol> <li>get the current user's identity (CSIdentityQueryCreateForCurrentUser)</li> <li>get the authority from that (CSIdentityGetAuthority)</li> <li>see if it's the local authority (CSGetLocalIdentityAuthority)</li> </ol> <p>Hope this helps.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload