是否可以替换Mac登录屏幕? [英] Is it possible to replace the Mac login screen?
问题描述
是否可以用自定义登录窗口应用程序替换Mac OS X登录窗口/System/Library/CoreServices/loginwindow.app? (请参阅我这样做的理由.)
Is it possible to replace the Mac OS X login window, /System/Library/CoreServices/loginwindow.app, with a custom login window application? (See my rational for doing so.)
恐怕我的可可编程技能还很初级.我确实发现有趣的一点是,当我运行探针CGSession时(它是一个未记录的实用程序,它会执行快速切换用户),通过执行操作查看
I'm afraid my Cocoa programming skills are rudimentary. I do find it interesting that, when I run probe CGSession (which is a undocumented utility that performs fast user switching) to see what functions it uses, by doing
nm -mg /System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession
链接功能之一是:
(undefined [lazy bound]) external _CGSCreateLoginSession (from ApplicationServices)
我还没有找到有关ApplicationServices框架的文档.我怀疑我正在深入研究服务提供商接口,而不是应用程序程序员接口.
I haven't found documentation on the ApplicationServices framework. I suspect I'm getting deep into Service Provider Interfaces instead of Application Programmer Interfaces.
我确实发现了这个非常有趣的代码段:(直接链接到下一页;似乎该网站正在重新组织),该应用程序声称即使用户快速切换也可以切换到登录窗口被禁用.
I did find this really interesting snippet: (google cache) (direct link to down page; it appears the site is undergoing re-organization) from an application that claims to switch to the login window even if fast user switching is disabled.
#include "CGSInternal.h"
int main (int argc, const char * argv[]) {
// switch to the login window
CGSCreateLoginSession(NULL);
return 0;
}
我以CG表示CoreGraphics,但不了解与登录有什么关系(除非可能在当前用户的工作上放置一个登录对话框).
I take CG to mean CoreGraphics, and don't understand what that has to do with logging in (except with perhaps putting a login dialog up over the current user's work).
即使无法替代登录窗口,我也想知道(不为Apple工作的人)可以采取哪些措施.
Even if it is not possible to achieve a replacement for the login window, I'd be interested to know what can be done along these lines (by people who don't work for Apple).
推荐答案
登录窗口应用程序被定义为/System/Library/LaunchDaemons/com.apple.loginwindow.plist .
The login window application is defined as part of the launchd configuration in /System/Library/LaunchDaemons/com.apple.loginwindow.plist.
理论上,您可以用自己的登录窗口替换,但是我不知道您在新应用程序中必须执行的操作-我认为登录窗口的功能比身份验证和设置用户会话还要多->其他情况,似乎是在做一些相关的琐事.
In theory you can replace the login window with your own but I don't know what you have to do in the new app - I think the login window does a bit more then authentication and setting up the user session -> amongst others, it looks like its doing some launchd related chores.
我已经编译了一个调用 CGSCreateLoginSession 的应用程序,一旦运行它,它就会通过旋转的多维数据集转换到登录窗口.我想这就是为什么它需要CoreGraphics的原因-它只是一个图形函数,最后需要注销.
I've compiled an application that calls CGSCreateLoginSession and once you run it it transitions to the login window via the rotating cube. I imagine this is why it requires CoreGraphics - it's just a graphics function that calls logout at the end.
您可以尝试使用InputManager并查看登录窗口是否加载了代码->如果这样做,则可以更改loginwindow NIB( LoginWindowUI.nib )并添加一些按钮以显示新的用户浏览器打开的窗口.学生选择了自己的照片后,您可以在登录窗口中自动填写用户名和密码字段.
You could try an InputManager and see it the login window loads the code -> if it does, you could then alter the loginwindow NIB (LoginWindowUI.nib) and add some buttons to display a new window with the user browser. Once the student chooses a picture of him/herself you could autofill the username and password fields in the loginwindow.
这完全是理论上的事,它看起来非常脆弱且不安全.
Node this is all theory, and it looks very fragile and unsafe.
祝你好运.
稍后编辑
请注意,这是非常不安全的,因此请谨慎使用-在尝试使用此工具时,我确实用了几次软管
这是一个概念验证的实现,可将代码注入到登录窗口中.
Here's a proof-of-concept implementation that injects code in the loginwindow.
#include <stdio.h>
#include <unistd.h>
#include <sys/time.h>
#include <strings.h>
#include <syslog.h>
#import <Cocoa/Cocoa.h>
#include <execinfo.h>
@interface LLApp:NSApplication
@end
@implementation LLApp
- (void)run
{
syslog(LOG_ERR, "LLApp being run");
[super run];
}
@end
void my_openlog(const char *ident, int logopt, int facility);
typedef struct interpose_s
{
void * new_func;
void * orig_func;
} interpose_t;
int MyNSApplicationMain(int argc, const char ** argv);
static const interpose_t interposers[] __attribute__ ((section("__DATA, __interpose"))) = {
{ (void *) my_openlog, (void *) openlog },
};
void my_openlog(const char *ident, int logopt, int facility)
{
openlog(ident, logopt, facility);
if(!strcmp(ident, "/System/Library/CoreServices/loginwindow.app/Contents/MacOS/loginwindow"))
{
[LLApp poseAsClass:[NSApplication class]];
}
else
{
syslog(LOG_ERR, "Ignoring unknown indent: >%s<", ident);
}
return;
}
代码使用以下代码进行编译:
The code compiles with:
gcc -Wall -dynamiclib -undefined dynamic_lookup -o ~/Desktop/libinterposers.dylib testin.m -framework Cocoa
代码加载是基于插入的,因此loginwindow的启动定义必须包含一个附加条目(以允许在动态链接器中进行插入),即:
Code loading is based on interposing so the launchd definition of loginwindow has to contain an additional entry (to enable interposing in the dynamic linker), i.e.:
<key>EnvironmentVariables</key>
<dict>
<key>DYLD_INSERT_LIBRARIES</key>
<string>path_to/Desktop/libinterposers.dylib</string>
</dict>
这篇关于是否可以替换Mac登录屏幕?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!