1500字范文,内容丰富有趣,写作好帮手!
1500字范文 > Android: 启动init.rc 中service的权限问题【转】

Android: 启动init.rc 中service的权限问题【转】

时间:2020-08-30 02:22:36

相关推荐

Android: 启动init.rc 中service的权限问题【转】

转自:/Linux/-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博客,转载请标明出处:/zmyde/archive//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 }

};

【作者】张昺华 【出处】/sky-heaven/ 【博客园】 /sky-heaven/ 【新浪博客】 /u/2049150530 【知乎】 /people/zhang-bing-hua 【我的作品---旋转倒立摆】 /v_show/id_XODM5NDAzNjQw.html?spm=a2hzp.8253869.0.0&from=y1.7-2 【我的作品---自平衡自动循迹车】 /v_show/id_XODM5MzYyNTIw.html?spm=a2hzp.8253869.0.0&from=y1.7-2 【新浪微博】 张昺华--sky 【twitter】 @sky2030_ 【facebook】 张昺华 zhangbinghua 本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。