zoukankan      html  css  js  c++  java
  • mac上的应用提权

    一个mac上的app需要在/Applications/My.app/Contents/MacOS路径下创建一个配置文件,在开启root权限的账户下运行时ok,但是在没有开启root权限的账户下运行时,创建文件会失败,报"Permission Denied"

    花时间了解了一下mac上的应用提权,由于安全的原因,提权方式一直在调整,目前苹果推荐的方式是使用Security Manager,并提供了一个例子:SMJobBless

    以下引用自stackoverflow http://stackoverflow.com/questions/18404884/c-show-osx-permission-dialog

    "

    Originally, Apple provided a function 'AuthorizationExecuteWithPrivileges' that allowed an application to launch another with root privileges. This has since been deprecated for security reasons.

    The dialog here is a bit misleading. Apple provides authorization services that launches the dialog under various different situations, but usually from an application having called the function AuthorizationCopyRights, after having setup rules in an authorization database (the file at /etc/authorization) and having created the Authorization reference with AuthorizationCreate.

    Security on OSX is split between a security daemon, a security agent and applications. An application can restrict features using this system, or request authorisation for the user to enter credentials so it can launch a privileged application, which is what you need to do.

    It's important to note that the dialog has not been presented by the application, but by the Security Agent, which is solely responsible for the security GUI. The daemon actually processes the authorization.

    Apple's method for elevation is to have all applications run with Standard User rights and should a privileged task be required, then this must be factored out into a separate application which is registered to run with launchd and given the elevated privileges. The example Apple provides isSMJobBless.

    While the calling code of the example is written in Objective-C, the important functions are just C functions in the SMJobBlessAppController.m file, most notably AuthorizationCreate to create an authorisation reference and the code in the Objective-C function blessHelperWithLabel:error: at the bottom of the file.

    Begin with this help document on SMJobBless, which details the process.

    Finally, if you're using Qt, you'll need to include Apple's Security framework for the required function calls. To do that, just add the following to your .pro file: -

    QMAKE_LFLAGS += -F /System/Library/Frameworks/Security.framework/
    LIBS += -framework Security

    "

    附:

    1.Enable and using the "root" user in mac os x

    https://support.apple.com/en-us/HT204012

  • 相关阅读:
    Jquery EasyUI选项卡-Tabs的使用方法
    JS—正则表达式
    Visiual Studio2012 CLR20r3问题
    JSON.stringify 语法实例讲解
    JS中对数组的操作方法
    easyUI之datagrid
    (转帖)关于easyui中的datagrid在加载数据时候报错:无法获取属性"Length"的值,对象为null或未定义
    [转载]JQ 选择器大全[<font color=red>强记忆</font>]
    thinkphp函数学习(1)——header, get_magic_quotes_gpc, array_map, stripslashes, stripslashes_deep
    thinkphp函数学习(0)——开篇
  • 原文地址:https://www.cnblogs.com/bugchecker/p/get_root_privilege_for_app_on_mac.html
Copyright © 2011-2022 走看看