问题描述
使用 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.
没有回答问题的类似帖子:
如何获取通过 Active Directory 登录 Mac 的用户的域名
推荐答案
我正在寻找如何检测用户是否拥有本地帐户或任何网络目录帐户(ActiveDir 或 OpenDir).所以我使用 Open Directory 框架所做的事情是这样的:
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:
- 获取默认的 ODSession 会话
- 获取本地节点 – kODNodeTypeLocalNodes(我不想一直向服务器发送查询)
- kODAttributeTypeNFSHomeDirectory 的查询节点,查询值设置为当前用户的主目录
- 如果找到则表示用户是本地的,否则表示用户是本地的(因为我们只查询本地节点)——用户拥有网络帐户
像这样:
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:
- 获取当前用户的身份 (CSIdentityQueryCreateForCurrentUser)
- 从中获取权限 (CSIdentityGetAuthority)
- 看看是不是地方当局 (CSGetLocalIdentityAuthority)
希望这会有所帮助.
这篇关于Mac OSX:使用 Objective-c 确定用户帐户是 Active Directory 用户还是本地用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!