Mac OSX上:Determing无论用户帐户是使用Objective-C的Active Directory用户与本地用户 [英] Mac OSX: Determing whether user account is an Active Directory user vs. local user using objective-c

查看:310
本文介绍了Mac OSX上:Determing无论用户帐户是使用Objective-C的Active Directory用户与本地用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用 dsconfigad -show 是可能的解析输出,并确定电脑是否被绑定到一个Active Directory域。

Using dsconfigad -show it's possible to parse the output and determine whether or the computer is bound to a Active Directory domain.

的问题是用户身份登录本地用户帐户的Active Directory域,则返回偶数。

注:理想情况下,我需要一个解决方案,在10.5作品,以及

Note: Ideally I need a solution that works in 10.5 as well.

类似的职位,不回答问题:

<一个href="http://stackoverflow.com/questions/2953378/how-can-i-get-the-domain-name-for-a-user-logged-into-a-mac-via-active-directory?rq=1">How我可以得到域名用户通过Active Directory 登录到一台Mac

推荐答案

我一直在寻找如何检测,如果用户有本地帐户或任何网络目录帐户(ActiveDir或执行opendir)。所以我做了什么用开放式目录的框架是这样的:

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:

  1. 在得到默认ODSession会议
  2. 在获得本地节点 - kODNodeTypeLocalNodes(我不想以发送查询到服务器的所有时间)
  3. 与查询值设置为当前用户的主目录kODAttributeTypeNFSHomeDirectory查询节点
  4. 如果找到,则意味着用户是本地的,如果不是(bacause我们查询本地节点ONY) - 用户网络帐户

所以是这样的:

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:&err];
    ODQuery *myQuery = [ODQuery  queryWithNode: myNode
                                forRecordTypes: kODRecordTypeUsers
                                     attribute: kODAttributeTypeNFSHomeDirectory
                                     matchType: kODMatchEqualTo
                                   queryValues: NSHomeDirectory()
                              returnAttributes: kODAttributeTypeStandardOnly
                                maximumResults: 0
                                         error: &err];

    [myQuery retain];
    [myQuery setDelegate: self];
    [myQuery scheduleInRunLoop: [NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];

    NSRunLoop *theRunLoop = [NSRunLoop currentRunLoop];
    while (shouldKeepRunning && [theRunLoop runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]]);

    return isLocalUser;
}

- (void)query:(ODQuery *)inSearch foundResults:(NSArray *)inResults error:(NSError *)inError
{

     if (!inResults && !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;
}

另一个想法是利用身份服务:

Another idea is to use Identity services:

  1. 获取当前用户的身份(CSIdentityQueryCreateForCurrentUser)
  2. 从那个(CSIdentityGetAuthority)获得授权
  3. 在看它是否是地方当局(CSGetLocalIdentityAuthority)

希望这有助于。

这篇关于Mac OSX上:Determing无论用户帐户是使用Objective-C的Active Directory用户与本地用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆