Cleanup
This commit is contained in:
parent
9be2844c82
commit
8c52dfb804
@ -24,6 +24,14 @@
|
||||
|
||||
#define AM_PATH "/system/bin/app_process", "/system/bin", "com.android.commands.am.Am"
|
||||
|
||||
static char *get_command(const struct su_request *to) {
|
||||
if (to->command)
|
||||
return to->command;
|
||||
if (to->shell)
|
||||
return to->shell;
|
||||
return DEFAULT_SHELL;
|
||||
}
|
||||
|
||||
static void silent_run(char* const args[]) {
|
||||
set_identity(0);
|
||||
if (fork())
|
||||
|
51
misc.c
51
misc.c
@ -1,51 +0,0 @@
|
||||
/* misc.c - Miscellaneous stuffs for su
|
||||
*/
|
||||
|
||||
#define _GNU_SOURCE
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <signal.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/types.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
#include "magisk.h"
|
||||
#include "su.h"
|
||||
|
||||
void set_identity(unsigned uid) {
|
||||
/*
|
||||
* Set effective uid back to root, otherwise setres[ug]id will fail
|
||||
* if uid isn't root.
|
||||
*/
|
||||
if (seteuid(0)) {
|
||||
PLOGE("seteuid (root)");
|
||||
}
|
||||
if (setresgid(uid, uid, uid)) {
|
||||
PLOGE("setresgid (%u)", uid);
|
||||
}
|
||||
if (setresuid(uid, uid, uid)) {
|
||||
PLOGE("setresuid (%u)", uid);
|
||||
}
|
||||
}
|
||||
|
||||
char *get_command(const struct su_request *to) {
|
||||
if (to->command)
|
||||
return to->command;
|
||||
if (to->shell)
|
||||
return to->shell;
|
||||
return DEFAULT_SHELL;
|
||||
}
|
||||
|
||||
int fork_zero_fucks() {
|
||||
int pid = fork();
|
||||
if (pid) {
|
||||
int status;
|
||||
waitpid(pid, &status, 0);
|
||||
return pid;
|
||||
} else {
|
||||
if (fork() != 0)
|
||||
exit(0);
|
||||
return 0;
|
||||
}
|
||||
}
|
18
su.c
18
su.c
@ -86,6 +86,22 @@ static void populate_environment(const struct su_context *ctx) {
|
||||
}
|
||||
}
|
||||
|
||||
void set_identity(unsigned uid) {
|
||||
/*
|
||||
* Set effective uid back to root, otherwise setres[ug]id will fail
|
||||
* if uid isn't root.
|
||||
*/
|
||||
if (seteuid(0)) {
|
||||
PLOGE("seteuid (root)");
|
||||
}
|
||||
if (setresgid(uid, uid, uid)) {
|
||||
PLOGE("setresgid (%u)", uid);
|
||||
}
|
||||
if (setresuid(uid, uid, uid)) {
|
||||
PLOGE("setresuid (%u)", uid);
|
||||
}
|
||||
}
|
||||
|
||||
static __attribute__ ((noreturn)) void allow() {
|
||||
char *arg0;
|
||||
|
||||
@ -114,7 +130,7 @@ static __attribute__ ((noreturn)) void allow() {
|
||||
set_identity(su_ctx->to.uid);
|
||||
|
||||
setexeccon("u:r:su:s0");
|
||||
|
||||
|
||||
su_ctx->to.argv[--su_ctx->to.argc] = arg0;
|
||||
execvp(binary, su_ctx->to.argv + su_ctx->to.argc);
|
||||
fprintf(stderr, "Cannot execute %s: %s\n", binary, strerror(errno));
|
||||
|
7
su.h
7
su.h
@ -119,6 +119,7 @@ extern int pipefd[2];
|
||||
|
||||
int su_daemon_main(int argc, char **argv);
|
||||
__attribute__ ((noreturn)) void exit2(int status);
|
||||
void set_identity(unsigned uid);
|
||||
|
||||
// su_client.c
|
||||
|
||||
@ -136,10 +137,4 @@ void app_send_request(struct su_context *ctx);
|
||||
|
||||
void database_check(struct su_context *ctx);
|
||||
|
||||
// misc.c
|
||||
|
||||
void set_identity(unsigned uid);
|
||||
char *get_command(const struct su_request *to);
|
||||
int fork_zero_fucks();
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user