打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
Android: 启动init.rc 中service的权限问题

通过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

 

  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

 

因此,如果我们碰到了权限问题,根据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 }
};

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
云中漫步 ? Android应用程序获得root权限
深入讲解Android Property机制(一)
Android 的系统属性(SystemProperties)设置分析
Android系统root破解原理分析(续)
如何在init.rc中添加/dev/字符设备节点创建权限
Android的安全设计与架构
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服