diff options
author | Ethan Yonker <dees_troy@teamw.in> | 2014-12-10 23:17:55 +0100 |
---|---|---|
committer | Dees Troy <dees_troy@teamw.in> | 2014-12-18 21:17:26 +0100 |
commit | e3e8829e40a45dbf4787c7f5c812822ecfef6bc4 (patch) | |
tree | e1b4c98653678ca80ad87d3ca19b222994b49081 /twrp-functions.cpp | |
parent | Fix adb sideload page on 1440x2560 layout (diff) | |
download | android_bootable_recovery-e3e8829e40a45dbf4787c7f5c812822ecfef6bc4.tar android_bootable_recovery-e3e8829e40a45dbf4787c7f5c812822ecfef6bc4.tar.gz android_bootable_recovery-e3e8829e40a45dbf4787c7f5c812822ecfef6bc4.tar.bz2 android_bootable_recovery-e3e8829e40a45dbf4787c7f5c812822ecfef6bc4.tar.lz android_bootable_recovery-e3e8829e40a45dbf4787c7f5c812822ecfef6bc4.tar.xz android_bootable_recovery-e3e8829e40a45dbf4787c7f5c812822ecfef6bc4.tar.zst android_bootable_recovery-e3e8829e40a45dbf4787c7f5c812822ecfef6bc4.zip |
Diffstat (limited to 'twrp-functions.cpp')
-rw-r--r-- | twrp-functions.cpp | 159 |
1 files changed, 1 insertions, 158 deletions
diff --git a/twrp-functions.cpp b/twrp-functions.cpp index b51024cf1..4a7b340a5 100644 --- a/twrp-functions.cpp +++ b/twrp-functions.cpp @@ -737,127 +737,6 @@ int TWFunc::drop_caches(void) { return 0; } -int TWFunc::Check_su_Perms(void) { - struct stat st; - int ret = 0; - - if (!PartitionManager.Mount_By_Path("/system", false)) - return 0; - - // Check to ensure that perms are 6755 for all 3 file locations - if (stat("/system/bin/su", &st) == 0) { - if ((st.st_mode & (S_ISUID | S_ISGID | S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) != (S_ISUID | S_ISGID | S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) || st.st_uid != 0 || st.st_gid != 0) { - ret = 1; - } - } - if (stat("/system/xbin/su", &st) == 0) { - if ((st.st_mode & (S_ISUID | S_ISGID | S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) != (S_ISUID | S_ISGID | S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) || st.st_uid != 0 || st.st_gid != 0) { - ret += 2; - } - } - if (stat("/system/bin/.ext/.su", &st) == 0) { - if ((st.st_mode & (S_ISUID | S_ISGID | S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH)) != (S_ISUID | S_ISGID | S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) || st.st_uid != 0 || st.st_gid != 0) { - ret += 4; - } - } - return ret; -} - -bool TWFunc::Fix_su_Perms(void) { - if (!PartitionManager.Mount_By_Path("/system", true)) - return false; - - string propvalue = System_Property_Get("ro.build.version.sdk"); - string su_perms = "6755"; - if (!propvalue.empty()) { - int sdk_version = atoi(propvalue.c_str()); - if (sdk_version >= 18) - su_perms = "0755"; - } - - string file = "/system/bin/su"; - if (TWFunc::Path_Exists(file)) { - if (chown(file.c_str(), 0, 0) != 0) { - LOGERR("Failed to chown '%s'\n", file.c_str()); - return false; - } - if (tw_chmod(file, su_perms) != 0) { - LOGERR("Failed to chmod '%s'\n", file.c_str()); - return false; - } - } - file = "/system/xbin/su"; - if (TWFunc::Path_Exists(file)) { - if (chown(file.c_str(), 0, 0) != 0) { - LOGERR("Failed to chown '%s'\n", file.c_str()); - return false; - } - if (tw_chmod(file, su_perms) != 0) { - LOGERR("Failed to chmod '%s'\n", file.c_str()); - return false; - } - } - file = "/system/xbin/daemonsu"; - if (TWFunc::Path_Exists(file)) { - if (chown(file.c_str(), 0, 0) != 0) { - LOGERR("Failed to chown '%s'\n", file.c_str()); - return false; - } - if (tw_chmod(file, "0755") != 0) { - LOGERR("Failed to chmod '%s'\n", file.c_str()); - return false; - } - } - file = "/system/bin/.ext/.su"; - if (TWFunc::Path_Exists(file)) { - if (chown(file.c_str(), 0, 0) != 0) { - LOGERR("Failed to chown '%s'\n", file.c_str()); - return false; - } - if (tw_chmod(file, su_perms) != 0) { - LOGERR("Failed to chmod '%s'\n", file.c_str()); - return false; - } - } - file = "/system/etc/install-recovery.sh"; - if (TWFunc::Path_Exists(file)) { - if (chown(file.c_str(), 0, 0) != 0) { - LOGERR("Failed to chown '%s'\n", file.c_str()); - return false; - } - if (tw_chmod(file, "0755") != 0) { - LOGERR("Failed to chmod '%s'\n", file.c_str()); - return false; - } - } - file = "/system/etc/init.d/99SuperSUDaemon"; - if (TWFunc::Path_Exists(file)) { - if (chown(file.c_str(), 0, 0) != 0) { - LOGERR("Failed to chown '%s'\n", file.c_str()); - return false; - } - if (tw_chmod(file, "0755") != 0) { - LOGERR("Failed to chmod '%s'\n", file.c_str()); - return false; - } - } - file = "/system/app/Superuser.apk"; - if (TWFunc::Path_Exists(file)) { - if (chown(file.c_str(), 0, 0) != 0) { - LOGERR("Failed to chown '%s'\n", file.c_str()); - return false; - } - if (tw_chmod(file, "0644") != 0) { - LOGERR("Failed to chmod '%s'\n", file.c_str()); - return false; - } - } - sync(); - if (!PartitionManager.UnMount_By_Path("/system", true)) - return false; - return true; -} - int TWFunc::tw_chmod(const string& fn, const string& mode) { long mask = 0; std::string::size_type n = mode.length(); @@ -978,43 +857,7 @@ bool TWFunc::Install_SuperSU(void) { if (!PartitionManager.Mount_By_Path("/system", true)) return false; - TWFunc::Exec_Cmd("/sbin/chattr -i /system/xbin/su"); - if (copy_file("/supersu/su", "/system/xbin/su", 0755) != 0) { - LOGERR("Failed to copy su binary to /system/bin\n"); - return false; - } - if (!Path_Exists("/system/bin/.ext")) { - mkdir("/system/bin/.ext", 0777); - } - TWFunc::Exec_Cmd("/sbin/chattr -i /system/bin/.ext/su"); - if (copy_file("/supersu/su", "/system/bin/.ext/su", 0755) != 0) { - LOGERR("Failed to copy su binary to /system/bin/.ext/su\n"); - return false; - } - TWFunc::Exec_Cmd("/sbin/chattr -i /system/xbin/daemonsu"); - if (copy_file("/supersu/su", "/system/xbin/daemonsu", 0755) != 0) { - LOGERR("Failed to copy su binary to /system/xbin/daemonsu\n"); - return false; - } - if (Path_Exists("/system/etc/init.d")) { - TWFunc::Exec_Cmd("/sbin/chattr -i /system/etc/init.d/99SuperSUDaemon"); - if (copy_file("/supersu/99SuperSUDaemon", "/system/etc/init.d/99SuperSUDaemon", 0755) != 0) { - LOGERR("Failed to copy 99SuperSUDaemon to /system/etc/init.d/99SuperSUDaemon\n"); - return false; - } - } else { - TWFunc::Exec_Cmd("/sbin/chattr -i /system/etc/install-recovery.sh"); - if (copy_file("/supersu/install-recovery.sh", "/system/etc/install-recovery.sh", 0755) != 0) { - LOGERR("Failed to copy install-recovery.sh to /system/etc/install-recovery.sh\n"); - return false; - } - } - if (copy_file("/supersu/Superuser.apk", "/system/app/Superuser.apk", 0644) != 0) { - LOGERR("Failed to copy Superuser app to /system/app\n"); - return false; - } - if (!Fix_su_Perms()) - return false; + check_and_run_script("/supersu/install-supersu.sh", "SuperSU"); return true; } |