summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVojtech Bocek <vbocek@gmail.com>2013-08-29 22:38:20 +0200
committerGerrit Code Review <gerrit@198.50.184.117>2013-08-30 04:35:02 +0200
commit37aeb8d6786c0f0456bf1f9633199cd79818a920 (patch)
tree7bc873341ac21a907228f70798ee8995060a0dc9
parentignore extra = on install cmd (diff)
downloadandroid_bootable_recovery-37aeb8d6786c0f0456bf1f9633199cd79818a920.tar
android_bootable_recovery-37aeb8d6786c0f0456bf1f9633199cd79818a920.tar.gz
android_bootable_recovery-37aeb8d6786c0f0456bf1f9633199cd79818a920.tar.bz2
android_bootable_recovery-37aeb8d6786c0f0456bf1f9633199cd79818a920.tar.lz
android_bootable_recovery-37aeb8d6786c0f0456bf1f9633199cd79818a920.tar.xz
android_bootable_recovery-37aeb8d6786c0f0456bf1f9633199cd79818a920.tar.zst
android_bootable_recovery-37aeb8d6786c0f0456bf1f9633199cd79818a920.zip
-rw-r--r--twrp-functions.cpp73
-rw-r--r--twrp-functions.hpp2
2 files changed, 42 insertions, 33 deletions
diff --git a/twrp-functions.cpp b/twrp-functions.cpp
index 3c379d10e..48a9552a5 100644
--- a/twrp-functions.cpp
+++ b/twrp-functions.cpp
@@ -621,101 +621,110 @@ bool TWFunc::Fix_su_Perms(void) {
return true;
}
-int TWFunc::tw_chmod(string fn, string mode) {
+int TWFunc::tw_chmod(const string& fn, const string& mode) {
long mask = 0;
+ std::string::size_type n = mode.length();
+ int cls = 0;
- std::string::size_type n = (mode.length() == 3) ? 1 : 0;
- for (; n < mode.length(); ++n) {
- if (n == 0) {
+ if(n == 3)
+ ++cls;
+ else if(n != 4)
+ {
+ LOGERR("TWFunc::tw_chmod used with %u long mode string (should be 3 or 4)!\n", mode.length());
+ return -1;
+ }
+
+ for (n = 0; n < mode.length(); ++n, ++cls) {
+ if (cls == 0) {
if (mode[n] == '0')
continue;
- if (mode[n] == '1')
+ else if (mode[n] == '1')
mask |= S_ISVTX;
- if (mode[n] == '2')
+ else if (mode[n] == '2')
mask |= S_ISGID;
- if (mode[n] == '4')
+ else if (mode[n] == '4')
mask |= S_ISUID;
- if (mode[n] == '5') {
+ else if (mode[n] == '5') {
mask |= S_ISVTX;
mask |= S_ISUID;
}
- if (mode[n] == '6') {
+ else if (mode[n] == '6') {
mask |= S_ISGID;
mask |= S_ISUID;
}
- if (mode[n] == '7') {
+ else if (mode[n] == '7') {
mask |= S_ISVTX;
mask |= S_ISGID;
mask |= S_ISUID;
}
}
- else if (n == 1) {
+ else if (cls == 1) {
if (mode[n] == '7') {
mask |= S_IRWXU;
}
- if (mode[n] == '6') {
+ else if (mode[n] == '6') {
mask |= S_IRUSR;
mask |= S_IWUSR;
}
- if (mode[n] == '5') {
+ else if (mode[n] == '5') {
mask |= S_IRUSR;
mask |= S_IXUSR;
}
- if (mode[n] == '4')
+ else if (mode[n] == '4')
mask |= S_IRUSR;
- if (mode[n] == '3') {
+ else if (mode[n] == '3') {
mask |= S_IWUSR;
mask |= S_IRUSR;
}
- if (mode[n] == '2')
+ else if (mode[n] == '2')
mask |= S_IWUSR;
- if (mode[n] == '1')
+ else if (mode[n] == '1')
mask |= S_IXUSR;
}
- else if (n == 2) {
+ else if (cls == 2) {
if (mode[n] == '7') {
mask |= S_IRWXG;
}
- if (mode[n] == '6') {
+ else if (mode[n] == '6') {
mask |= S_IRGRP;
mask |= S_IWGRP;
}
- if (mode[n] == '5') {
+ else if (mode[n] == '5') {
mask |= S_IRGRP;
mask |= S_IXGRP;
}
- if (mode[n] == '4')
+ else if (mode[n] == '4')
mask |= S_IRGRP;
- if (mode[n] == '3') {
+ else if (mode[n] == '3') {
mask |= S_IWGRP;
mask |= S_IXGRP;
}
- if (mode[n] == '2')
+ else if (mode[n] == '2')
mask |= S_IWGRP;
- if (mode[n] == '1')
+ else if (mode[n] == '1')
mask |= S_IXGRP;
}
- else if (n == 3) {
+ else if (cls == 3) {
if (mode[n] == '7') {
mask |= S_IRWXO;
}
- if (mode[n] == '6') {
+ else if (mode[n] == '6') {
mask |= S_IROTH;
mask |= S_IWOTH;
}
- if (mode[n] == '5') {
+ else if (mode[n] == '5') {
mask |= S_IROTH;
mask |= S_IXOTH;
}
- if (mode[n] == '4')
- mask |= S_IROTH;
- if (mode[n] == '3') {
+ else if (mode[n] == '4')
+ mask |= S_IROTH;
+ else if (mode[n] == '3') {
mask |= S_IWOTH;
mask |= S_IXOTH;
}
- if (mode[n] == '2')
+ else if (mode[n] == '2')
mask |= S_IWOTH;
- if (mode[n] == '1')
+ else if (mode[n] == '1')
mask |= S_IXOTH;
}
}
diff --git a/twrp-functions.hpp b/twrp-functions.hpp
index 8531c0939..4040d2ef0 100644
--- a/twrp-functions.hpp
+++ b/twrp-functions.hpp
@@ -48,7 +48,7 @@ public:
static int drop_caches(void); //drop linux cache memory
static int Check_su_Perms(void); // check perms and owner of su binary in various locations
static bool Fix_su_Perms(void); // sets proper permissions for su binaries and superuser apk
- static int tw_chmod(string fn, string mode); // chmod function that converts a 4 char string into st_mode automatically
+ static int tw_chmod(const string& fn, const string& mode); // chmod function that converts a 3 or 4 char string into st_mode automatically
static bool Install_SuperSU(void); // Installs su binary and apk and sets proper permissions
static vector<string> split_string(const string &in, char del, bool skip_empty);
static int Get_File_Type(string fn); // Determines file type, 0 for unknown, 1 for gzip, 2 for OAES encrypted