Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
M
Magisk
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Magisk
Commits
8c52dfb8
Commit
8c52dfb8
authored
Sep 15, 2017
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cleanup
parent
9be2844c
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
26 additions
and
58 deletions
+26
-58
activity.c
activity.c
+8
-0
misc.c
misc.c
+0
-51
su.c
su.c
+17
-1
su.h
su.h
+1
-6
No files found.
activity.c
View file @
8c52dfb8
...
...
@@ -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
())
...
...
misc.c
deleted
100644 → 0
View file @
9be2844c
/* 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
;
}
}
su.c
View file @
8c52dfb8
...
...
@@ -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
));
...
...
su.h
View file @
8c52dfb8
...
...
@@ -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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment