电竞比分网-中国电竞赛事及体育赛事平台

分享

Android: 啟動init.rc 中service的權限問題

 jemeen 2012-02-13

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

來啟動init.rc中的service是一個很方便方法來調用某個可執(zhí)行程序或某個腳本程序

service service_xx  /system/bin/xx

    disabled
    oneshot

 

但在非AID_ROOT、AID_SYSTEM 用戶的進程中調用ctl.start ctl.stop會碰到權限問題:

system/core/init/property_service.c

 

  1. /* 
  2.  * White list of UID that are allowed to start/stop services. 
  3.  * Currently there are no user apps that require. 
  4.  */  
  5. struct {  
  6.     const char *service;  
  7.     unsigned int uid;  
  8.     unsigned int gid;  
  9. } control_perms[] = {  
  10.     { "dumpstate",AID_SHELL, AID_LOG },  
  11.      {NULL, 0, 0 }  
  12. };  
  13.   
  14. /* 
  15.  * Checks permissions for starting/stoping system services. 
  16.  * AID_SYSTEM and AID_ROOT are always allowed. 
  17.  * 
  18.  * Returns 1 if uid allowed, 0 otherwise. 
  19.  */  
  20. static int check_control_perms(const char *name, int uid, int gid) {  
  21.     int i;  
  22.     if (uid == AID_SYSTEM || uid == AID_ROOT)  
  23.         return 1;  
  24.   
  25.     /* Search the ACL */  
  26.     for (i = 0; control_perms[i].service; i++) {  
  27.         if (strcmp(control_perms[i].service, name) == 0) {  
  28.             if ((uid && control_perms[i].uid == uid) ||  
  29.                 (gid && control_perms[i].gid == gid)) {  
  30.                 return 1;  
  31.             }  
  32.         }  
  33.     }  
  34.     return 0;  
  35. }  

 

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

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

 

因此,如果我們碰到了權限問題,根據(jù)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 }
};

    本站是提供個人知識管理的網(wǎng)絡存儲空間,所有內容均由用戶發(fā)布,不代表本站觀點。請注意甄別內容中的聯(lián)系方式、誘導購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權內容,請點擊一鍵舉報。
    轉藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多