標籤:value word get frame kernel clip deb uid inux
本文轉載自:http://blog.csdn.net/liyongming1982/article/details/14108111
有的user使用者版本的log 不全,且push/pull某些檔案或者屬性檔案
常常會遇到許可權不夠的情況,給調試帶來很多便:
對於user 版本adb shell 開啟的還是shell 許可權,而不是root 許可權,
如果您需要root 許可權,需要再改一下system/core/adb/adb.c 裡面的should_drop_privileges()
這個函數,在#ifndef ALLOW_ADBD_ROOT 時return 0; 而不是return 1; 即可。
判斷是否降低許可權:
[cpp] view plain copy
- static int should_drop_privileges() {
- #ifndef ALLOW_ADBD_ROOT
- return 1;
- #else /* ALLOW_ADBD_ROOT */
- int secure = 0;
- char value[PROPERTY_VALUE_MAX];
-
- /* run adbd in secure mode if ro.secure is set and
- ** we are not in the emulator
- */
- property_get("ro.kernel.qemu", value, "");
- if (strcmp(value, "1") != 0) {
- property_get("ro.secure", value, "1");
- if (strcmp(value, "1") == 0) {
- // don‘t run as root if ro.secure is set...
- secure = 1;
-
- // ... except we allow running as root in userdebug builds if the
- // service.adb.root property has been set by the "adb root" command
- property_get("ro.debuggable", value, "");
- if (strcmp(value, "1") == 0) {
- property_get("service.adb.root", value, "");
- if (strcmp(value, "1") == 0) {
- secure = 0;
- }
- }
- }
- }
- return secure;
- #endif /* ALLOW_ADBD_ROOT */
- }
具體怎麼降低許可權:
[cpp] view plain copy
- if (should_drop_privileges()) {
- struct __user_cap_header_struct header;
- struct __user_cap_data_struct cap;
-
- if (prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0) != 0) {
- exit(1);
- }
-
- /* add extra groups:
- ** AID_ADB to access the USB driver
- ** AID_LOG to read system logs (adb logcat)
- ** AID_INPUT to diagnose input issues (getevent)
- ** AID_INET to diagnose network issues (netcfg, ping)
- ** AID_GRAPHICS to access the frame buffer
- ** AID_NET_BT and AID_NET_BT_ADMIN to diagnose bluetooth (hcidump)
- ** AID_SDCARD_R to allow reading from the SD card
- ** AID_SDCARD_RW to allow writing to the SD card
- ** AID_MOUNT to allow unmounting the SD card before rebooting
- ** AID_NET_BW_STATS to read out qtaguid statistics
- */
- gid_t groups[] = { AID_ADB, AID_LOG, AID_INPUT, AID_INET, AID_GRAPHICS,
- AID_NET_BT, AID_NET_BT_ADMIN, AID_SDCARD_R, AID_SDCARD_RW,
- AID_MOUNT, AID_NET_BW_STATS };
- if (setgroups(sizeof(groups)/sizeof(groups[0]), groups) != 0) {
- exit(1);
- }
-
- /* then switch user and group to "shell" */
- if (setgid(AID_SHELL) != 0) {
- exit(1);
- }
- if (setuid(AID_SHELL) != 0) {
- exit(1);
- }
-
- /* set CAP_SYS_BOOT capability, so "adb reboot" will succeed */
- header.version = _LINUX_CAPABILITY_VERSION;
- header.pid = 0;
- cap.effective = cap.permitted = (1 << CAP_SYS_BOOT);
- cap.inheritable = 0;
- capset(&header, &cap);
-
- D("Local port disabled\n");
- }
android user使用者版本提高adb許可權【轉】