mirror of
https://github.com/topjohnwu/Magisk.git
synced 2024-11-30 21:45:27 +00:00
Adjustments for unified binary
This commit is contained in:
parent
e103676b65
commit
3800b4b45c
@ -2,10 +2,11 @@ LOCAL_PATH := $(call my-dir)
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
LOCAL_MODULE := su
|
||||
LOCAL_STATIC_LIBRARIES := libselinux
|
||||
LOCAL_C_INCLUDES := jni/selinux/libselinux/include/ jni/selinux/libsepol/include/ jni/su/sqlite3/
|
||||
LOCAL_SRC_FILES := su.c daemon.c activity.c db.c utils.c pts.c sqlite3/sqlite3.c
|
||||
LOCAL_CFLAGS := -DSQLITE_OMIT_LOAD_EXTENSION -std=gnu11
|
||||
LOCAL_STATIC_LIBRARIES := libselinux libsqlite3
|
||||
LOCAL_C_INCLUDES := jni/selinux/libselinux/include/ jni/selinux/libsepol/include/ jni/sqlite3/
|
||||
LOCAL_SRC_FILES := su.c daemon.c activity.c db.c utils.c pts.c
|
||||
LOCAL_CFLAGS := -DSQLITE_OMIT_LOAD_EXTENSION -DINDEP_BINARY
|
||||
include $(BUILD_EXECUTABLE)
|
||||
|
||||
include jni/selinux/libselinux/Android.mk
|
||||
include jni/sqlite3/Android.mk
|
||||
|
34
indep_bin.h
Normal file
34
indep_bin.h
Normal file
@ -0,0 +1,34 @@
|
||||
/* This file is here because is uses some same macros in magisk.h
|
||||
* So we have to remove them from su.h.
|
||||
* However, if we want to build our own binary, we still have to define them
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _INDEP_BIN_H_
|
||||
#define _INDEP_BIN_H_
|
||||
|
||||
#ifdef LOG_TAG
|
||||
#undef LOG_TAG
|
||||
#endif
|
||||
#define LOG_TAG "su"
|
||||
|
||||
// fallback to using /system/bin/log.
|
||||
// can't use liblog.so because this is a static binary.
|
||||
#ifndef LOGE
|
||||
#define LOGE exec_loge
|
||||
#endif
|
||||
#ifndef LOGD
|
||||
#define LOGD exec_logd
|
||||
#endif
|
||||
#ifndef LOGW
|
||||
#define LOGW exec_logw
|
||||
#endif
|
||||
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#define PLOGE(fmt,args...) LOGE(fmt " failed with %d: %s", ##args, errno, strerror(errno))
|
||||
#define PLOGEV(fmt,err,args...) LOGE(fmt " failed with %d: %s", ##args, err, strerror(err))
|
||||
|
||||
int su_main(int argc, char *argv[]);
|
||||
|
||||
#endif
|
137414
sqlite3/sqlite3.c
137414
sqlite3/sqlite3.c
File diff suppressed because it is too large
Load Diff
7160
sqlite3/sqlite3.h
7160
sqlite3/sqlite3.h
File diff suppressed because it is too large
Load Diff
18
su.c
18
su.c
@ -45,6 +45,12 @@
|
||||
#include "su.h"
|
||||
#include "utils.h"
|
||||
|
||||
#ifdef INDEP_BINARY
|
||||
int main(int argc, char *argv[]) {
|
||||
return su_main(argc, argv);
|
||||
}
|
||||
#endif
|
||||
|
||||
extern int is_daemon;
|
||||
extern int daemon_from_uid;
|
||||
extern int daemon_from_pid;
|
||||
@ -595,16 +601,12 @@ static char *concat_commands(int argc, char *argv[]) {
|
||||
return strdup(command);
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
int su_main(int argc, char *argv[]) {
|
||||
if (argc == 2 && strcmp(argv[1], "--daemon") == 0) {
|
||||
//Everything we'll exec will be in su, not su_daemon
|
||||
setexeccon("u:r:su:s0");
|
||||
return run_daemon();
|
||||
}
|
||||
return su_main(argc, argv);
|
||||
}
|
||||
|
||||
int su_main(int argc, char *argv[]) {
|
||||
int ppid = getppid();
|
||||
if ((geteuid() != AID_ROOT && getuid() != AID_ROOT) ||
|
||||
(get_api_version() >= 18 && getuid() == AID_SHELL) ||
|
||||
@ -863,7 +865,7 @@ int su_main_nodaemon(int argc, char **argv) {
|
||||
|
||||
mkdir(REQUESTOR_CACHE_PATH, 0770);
|
||||
if (chown(REQUESTOR_CACHE_PATH, st.st_uid, st.st_gid)) {
|
||||
PLOGE("chown (%s, %ld, %ld)", REQUESTOR_CACHE_PATH, st.st_uid, st.st_gid);
|
||||
PLOGE("chown (%s, %u, %u)", REQUESTOR_CACHE_PATH, st.st_uid, st.st_gid);
|
||||
deny(&ctx);
|
||||
}
|
||||
|
||||
@ -872,11 +874,11 @@ int su_main_nodaemon(int argc, char **argv) {
|
||||
deny(&ctx);
|
||||
}
|
||||
if (setegid(st.st_gid)) {
|
||||
PLOGE("setegid (%lu)", st.st_gid);
|
||||
PLOGE("setegid (%u)", st.st_gid);
|
||||
deny(&ctx);
|
||||
}
|
||||
if (seteuid(st.st_uid)) {
|
||||
PLOGE("seteuid (%lu)", st.st_uid);
|
||||
PLOGE("seteuid (%u)", st.st_uid);
|
||||
deny(&ctx);
|
||||
}
|
||||
|
||||
|
34
su.h
34
su.h
@ -18,10 +18,12 @@
|
||||
#ifndef SU_h
|
||||
#define SU_h 1
|
||||
|
||||
#ifdef LOG_TAG
|
||||
#undef LOG_TAG
|
||||
#ifdef INDEP_BINARY
|
||||
#include "indep_bin.h"
|
||||
#else
|
||||
#include "magisk.h"
|
||||
#endif
|
||||
#define LOG_TAG "su"
|
||||
|
||||
|
||||
#ifndef AID_SHELL
|
||||
#define AID_SHELL (get_shell_uid())
|
||||
@ -178,30 +180,4 @@ int su_main_nodaemon(int argc, char *argv[]);
|
||||
// deadbeat dad fork.
|
||||
int fork_zero_fucks();
|
||||
|
||||
// fallback to using /system/bin/log.
|
||||
// can't use liblog.so because this is a static binary.
|
||||
#ifndef LOGE
|
||||
#define LOGE exec_loge
|
||||
#endif
|
||||
#ifndef LOGD
|
||||
#define LOGD exec_logd
|
||||
#endif
|
||||
#ifndef LOGW
|
||||
#define LOGW exec_logw
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
#undef LOGE
|
||||
#define LOGE(fmt,args...) fprintf(stderr, fmt, ##args)
|
||||
#undef LOGD
|
||||
#define LOGD(fmt,args...) fprintf(stderr, fmt, ##args)
|
||||
#undef LOGW
|
||||
#define LOGW(fmt,args...) fprintf(stderr, fmt, ##args)
|
||||
#endif
|
||||
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#define PLOGE(fmt,args...) LOGE(fmt " failed with %d: %s", ##args, errno, strerror(errno))
|
||||
#define PLOGEV(fmt,err,args...) LOGE(fmt " failed with %d: %s", ##args, err, strerror(err))
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user