OSDN Git Service

C code fixups. Modify REQUESTOR if embedded in ROM.
authorKoushik Dutta <koushd@gmail.com>
Wed, 27 Feb 2013 07:46:44 +0000 (23:46 -0800)
committerKoushik Dutta <koushd@gmail.com>
Wed, 27 Feb 2013 07:46:44 +0000 (23:46 -0800)
Android.mk
Superuser/Android.mk
Superuser/jni/su/activity.c
Superuser/jni/su/su.c
Superuser/jni/su/su.h

index 927743f..6f853a4 100644 (file)
@@ -5,14 +5,18 @@ LOCAL_PATH := $(call my-dir)
 
 include $(CLEAR_VARS)
 
+
+ifeq ($(SUPERUSER_PACKAGE),)
+SUPERUSER_PACKAGE := com.thirdparty.superuser
+endif
+
 LOCAL_MODULE := su
 LOCAL_FORCE_STATIC_EXECUTABLE := true
 LOCAL_STATIC_LIBRARIES := libc
 LOCAL_C_INCLUDES := external/sqlite/dist
 LOCAL_SRC_FILES := Superuser/jni/su/su.c Superuser/jni/su/activity.c Superuser/jni/su/db.c Superuser/jni/su/utils.c ../../sqlite/dist/sqlite3.c
-LOCAL_CFLAGS := -DSQLITE_OMIT_LOAD_EXTENSION
+LOCAL_CFLAGS := -DSQLITE_OMIT_LOAD_EXTENSION -DREQUESTOR=\"$(SUPERUSER_PACKAGE)\"
 LOCAL_MODULE_PATH := $(TARGET_OUT_OPTIONAL_EXECUTABLES)
 include $(BUILD_EXECUTABLE)
 
-
 include $(LOCAL_PATH)/Superuser/Android.mk
\ No newline at end of file
index 650cf47..a50d1fe 100644 (file)
@@ -1,6 +1,4 @@
-ifeq ($(SUPERUSER_PACKAGE),)
-SUPERUSER_PACKAGE := com.thirdparty.superuser
-endif
+ifndef SUPERUSER_EMBEDDED
 
 LOCAL_PATH := $(call my-dir)
 include $(CLEAR_VARS)
@@ -13,3 +11,5 @@ LOCAL_AAPT_INCLUDE_ALL_RESOURCES := true
 LOCAL_AAPT_FLAGS := --extra-packages com.koushikdutta.widgets -S $(LOCAL_PATH)/../../Widgets/Widgets/res --auto-add-overlay --rename-manifest-package $(SUPERUSER_PACKAGE)
 
 include $(BUILD_PACKAGE)
+
+endif
index c48bf01..90588e6 100644 (file)
@@ -64,7 +64,7 @@ int get_owner_login_user_args(struct su_context *ctx, char* user, int user_len)
         snprintf(user, user_len, "--user %d", ctx->user.android_user_id);
     }
     else if (ctx->user.multiuser_mode == MULTIUSER_MODE_NONE) {
-        snprintf(user, user_len, "");
+        user[0] = '\0';
     }
     else {
         snprintf(user, user_len, "--user 0");
index d7b3a0d..b7586ec 100644 (file)
 #include "su.h"
 #include "utils.h"
 
-int get_shell_uid() {
+unsigned get_shell_uid() {
   struct passwd* ppwd = getpwnam("shell");
   if (NULL == ppwd) {
-    return -1;
+    return 2000;
   }
   
   return ppwd->pw_uid;
@@ -265,11 +265,6 @@ static void cleanup_signal(int sig) {
     exit(128 + sig);
 }
 
-void sigchld_handler(int sig) {
-    child_cleanup(su_ctx);
-    (void)sig;
-}
-
 static int socket_create_temp(char *path, size_t len) {
     int fd;
     struct sockaddr_un sun;
@@ -372,8 +367,8 @@ do {                                        \
 
     write_token(fd, "version", PROTO_VERSION);
     write_token(fd, "pid", ctx->from.pid);
-    write_token(fd, "from.name", ctx->from.name);
-    write_token(fd, "to.name", ctx->to.name);
+    write_string(fd, "from.name", ctx->from.name);
+    write_string(fd, "to.name", ctx->to.name);
     write_token(fd, "from.uid", ctx->from.uid);
     write_token(fd, "to.uid", ctx->to.uid);
     write_string(fd, "from.bin", ctx->from.bin);
index 48a0c21..4564803 100644 (file)
@@ -37,7 +37,9 @@
 #define CM_ROOT_ACCESS_ADB_ONLY      2
 #define CM_ROOT_ACCESS_APPS_AND_ADB  3
 
+#ifndef REQUESTOR
 #define REQUESTOR "com.koushikdutta.superuser"
+#endif
 #define REQUESTOR_DATA_PATH "/data/data/"
 #define REQUESTOR_FILES_PATH REQUESTOR_DATA_PATH REQUESTOR "/files"
 #define REQUESTOR_USER_PATH "/data/user/"
@@ -136,7 +138,6 @@ extern policy_t database_check(struct su_context *ctx);
 extern void set_identity(unsigned int uid);
 extern int send_request(struct su_context *ctx);
 extern int send_result(struct su_context *ctx, policy_t policy);
-extern void sigchld_handler(int sig);
 
 static inline char *get_command(const struct su_request *to)
 {