Android User version increases ADB privilege "go"

Source: Internet
Author: User
Tags strcmp

This article was reproduced from: http://blog.csdn.net/liyongming1982/article/details/14108111

Some user version of the log is not complete, and push/pull some files or properties file

Often encounter insufficient permissions, to debug a lot of things:

For the user version of the ADB shell to open or shell permissions, rather than root permissions,
If you need root privileges, you need to change the SYSTEM/CORE/ADB/ADB.C inside the Should_drop_privileges ()
This function, return 0 at #ifndef Allow_adbd_root; instead of return 1; Can.

To determine whether to lower permissions:

[CPP]View PlainCopy
  1. static int should_drop_privileges () {
  2. #ifndef Allow_adbd_root
  3. return 1;
  4. #else/* Allow_adbd_root */
  5. int secure = 0;
  6. Char Value[property_value_max];
  7. / * Run ADBD in secure mode if Ro.secure is set and
  8. * * We is not in the emulator
  9. */
  10. Property_get ("Ro.kernel.qemu", Value, "");
  11. if (strcmp (Value, "1")! = 0) {
  12. Property_get ("Ro.secure", Value, "1");
  13. if (strcmp (Value, "1") = = 0) {
  14. //don ' t run as root if Ro.secure is set ...
  15. secure = 1;
  16. //... except we allow running as root in Userdebug builds if the
  17. //Service.adb.root property had been set by the "ADB root" command
  18. Property_get ("ro.debuggable", Value, "");
  19. if (strcmp (Value, "1") = = 0) {
  20. Property_get ("Service.adb.root", Value, "");
  21. if (strcmp (Value, "1") = = 0) {
  22. secure = 0;
  23. }
  24. }
  25. }
  26. }
  27. return secure;
  28. #endif/* Allow_adbd_root */
  29. }


Specifically how to reduce permissions:

[CPP]View PlainCopy
    1. if (Should_drop_privileges ()) {
    2. struct __user_cap_header_struct header;
    3. struct __user_cap_data_struct cap;
    4. if (Prctl (pr_set_keepcaps, 1, 0, 0, 0)! = 0) {
    5. Exit (1);
    6. }
    7. /* Add extra Groups:
    8. * * AID_ADB to access the USB driver
    9. * * Aid_log to read system logs (ADB logcat)
    10. * * Aid_input to diagnose INPUT issues (getevent)
    11. * * Aid_inet to diagnose network issues (netcfg, ping)
    12. * * Aid_graphics to access the frame buffer
    13. * * AID_NET_BT and aid_net_bt_admin to diagnose Bluetooth (hcidump)
    14. * * Aid_sdcard_r to allow reading from the SD card
    15. * * AID_SDCARD_RW to allow writing to the SD card
    16. * * Aid_mount to allow unmounting the SD card before rebooting
    17. * * Aid_net_bw_stats to read out Qtaguid statistics
    18. */
    19. gid_t groups[] = {aid_adb, aid_log, Aid_input, Aid_inet, Aid_graphics,
    20. AID_NET_BT, Aid_net_bt_admin, Aid_sdcard_r, AID_SDCARD_RW,
    21. Aid_mount, aid_net_bw_stats};
    22. if (setgroups (sizeof (groups)/sizeof (Groups[0]), groups)! = 0) {
    23. Exit (1);
    24. }
    25. / * Then switch the user and group to "Shell" * /
    26. if (setgid (aid_shell)! = 0) {
    27. Exit (1);
    28. }
    29. if (setuid (aid_shell)! = 0) {
    30. Exit (1);
    31. }
    32. / * Set cap_sys_boot capability, so "adb reboot" would succeed * /
    33. Header.version = _linux_capability_version;
    34. header.pid = 0;
    35. cap.effective = cap.permitted = (1 << cap_sys_boot);
    36. cap.inheritable = 0;
    37. Capset (&header, &cap);
    38. D ("Local Port disabled\n");
    39. }

Android User version increases ADB privilege "go"

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.