summaryrefslogtreecommitdiff
path: root/su
diff options
context:
space:
mode:
authorThe Android Open Source Project <initial-contribution@android.com>2009-03-18 17:39:49 -0700
committerThe Android Open Source Project <initial-contribution@android.com>2009-03-18 17:39:49 -0700
commit26aaac4bf942c4f51de0f10ea85edf9751c234c8 (patch)
tree529ea759d6658c4b959166e3901ffda5b674a25b /su
parent8e325b2a5a6f7c333efe0db06007b049a8043e87 (diff)
downloadextras-26aaac4bf942c4f51de0f10ea85edf9751c234c8.tar.gz
auto import from //branches/cupcake_rel/...@140373
Diffstat (limited to 'su')
-rw-r--r--su/su.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/su/su.c b/su/su.c
index 5c9ca106..b87cece8 100644
--- a/su/su.c
+++ b/su/su.c
@@ -15,6 +15,8 @@
** limitations under the License.
*/
+#define LOG_TAG "su"
+
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -27,6 +29,8 @@
#include <pwd.h>
+#include <private/android_filesystem_config.h>
+
/*
* SU can be given a specific command to exec. UID _must_ be
* specified for this (ie argc => 3).
@@ -38,7 +42,7 @@
int main(int argc, char **argv)
{
struct passwd *pw;
- int uid, gid;
+ int uid, gid, myuid;
if(argc < 2) {
uid = gid = 0;
@@ -53,6 +57,13 @@ int main(int argc, char **argv)
}
}
+ /* Until we have something better, only root and the shell can use su. */
+ myuid = getuid();
+ if (myuid != AID_ROOT && myuid != AID_SHELL) {
+ fprintf(stderr,"su: uid %d not allowed to su\n", myuid);
+ return 1;
+ }
+
if(setgid(gid) || setuid(uid)) {
fprintf(stderr,"su: permission denied\n");
return 1;