Android: 啟動init.rc 中service的許可權問題【轉】

來源:互聯網
上載者:User

標籤:

轉自:http://www.linuxidc.com/Linux/2011-04/35014.htm

 

通過property_set("ctl.start", service_xx);

來啟動init.rc中的service是一個很方便方法來調用某個可執行程式或某個指令碼程式

service service_xx  /system/bin/xx

disabled

    oneshot

但在非AID_ROOT、AID_SYSTEM 使用者的進程中調用ctl.start ctl.stop會碰到許可權問題:

system/core/init/property_service.c

/*  
 * White list of UID that are allowed to start/stop services.  
 * Currently there are no user apps that require.  
 */  
struct {   
    const char *service;   
    unsigned int uid;   
    unsigned int gid;   
} control_perms[] = {   
    { "dumpstate",AID_SHELL, AID_LOG },   
     {NULL, 0, 0 }   
};   
  
/*  
 * Checks permissions for starting/stoping system services.  
 * AID_SYSTEM and AID_ROOT are always allowed.  
 *  
 * Returns 1 if uid allowed, 0 otherwise.  
 */  
static int check_control_perms(const char *name, int uid, int gid) {   
    int i;   
    if (uid == AID_SYSTEM || uid == AID_ROOT)   
        return 1;   
  
    /* Search the ACL */  
    for (i = 0; control_perms[i].service; i++) {   
        if (strcmp(control_perms[i].service, name) == 0) {   
            if ((uid && control_perms[i].uid == uid) ||   
                (gid && control_perms[i].gid == gid)) {   
                return 1;   
            }   
        }   
    }   
    return 0;   
} 


本文來自CSDN部落格,轉載請標明出處:http://blog.csdn.net/zmyde2010/archive/2011/04/09/6312615.aspx

只有uid == AID_SYSTEM || uid == AID_ROOT

或符合 control_perms[] = {
    { "dumpstate",AID_SHELL, AID_LOG },
     {NULL, 0, 0 }
}; 的uid進程才有許可權star/stop services

因此,如果我們碰到了許可權問題,根據log提示,在/system/core/include/private/Android_filesystem_config.h

中查到進程定義,添加到control_perms[]列表

比如,uid ==AID_WIFI的某個程式需要許可權啟動service_xx

control_perms[] = {
    { "dumpstate",AID_SHELL, AID_LOG },

+  { "service_xx ",AID_WIFI, AID_WIFI},
     {NULL, 0, 0 }
};

Android: 啟動init.rc 中service的許可權問題【轉】

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.