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
37860181
Commit
37860181
authored
Oct 04, 2018
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Finish su implementation
parent
d119dd9a
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
15 additions
and
17 deletions
+15
-17
su.c
native/jni/su/su.c
+3
-2
su.h
native/jni/su/su.h
+1
-0
su_daemon.c
native/jni/su/su_daemon.c
+11
-15
No files found.
native/jni/su/su.c
View file @
37860181
...
@@ -105,6 +105,7 @@ int su_client_main(int argc, char *argv[]) {
...
@@ -105,6 +105,7 @@ int su_client_main(int argc, char *argv[]) {
.
uid
=
UID_ROOT
,
.
uid
=
UID_ROOT
,
.
login
=
0
,
.
login
=
0
,
.
keepenv
=
0
,
.
keepenv
=
0
,
.
mount_master
=
0
,
.
shell
=
DEFAULT_SHELL
,
.
shell
=
DEFAULT_SHELL
,
.
command
=
""
,
.
command
=
""
,
};
};
...
@@ -147,7 +148,7 @@ int su_client_main(int argc, char *argv[]) {
...
@@ -147,7 +148,7 @@ int su_client_main(int argc, char *argv[]) {
// Do nothing, placed here for legacy support :)
// Do nothing, placed here for legacy support :)
break
;
break
;
case
'M'
:
case
'M'
:
/* TODO */
su_req
.
mount_master
=
1
;
break
;
break
;
default:
default:
/* Bionic getopt_long doesn't terminate its error output by newline */
/* Bionic getopt_long doesn't terminate its error output by newline */
...
@@ -181,7 +182,7 @@ int su_client_main(int argc, char *argv[]) {
...
@@ -181,7 +182,7 @@ int su_client_main(int argc, char *argv[]) {
write_int
(
fd
,
SUPERUSER
);
write_int
(
fd
,
SUPERUSER
);
// Send su_request
// Send su_request
xwrite
(
fd
,
&
su_req
,
3
*
sizeof
(
unsigned
));
xwrite
(
fd
,
&
su_req
,
4
*
sizeof
(
unsigned
));
write_string
(
fd
,
su_req
.
shell
);
write_string
(
fd
,
su_req
.
shell
);
write_string
(
fd
,
su_req
.
command
);
write_string
(
fd
,
su_req
.
command
);
...
...
native/jni/su/su.h
View file @
37860181
...
@@ -40,6 +40,7 @@ struct su_request {
...
@@ -40,6 +40,7 @@ struct su_request {
unsigned
uid
;
unsigned
uid
;
unsigned
login
;
unsigned
login
;
unsigned
keepenv
;
unsigned
keepenv
;
unsigned
mount_master
;
char
*
shell
;
char
*
shell
;
char
*
command
;
char
*
command
;
};
};
...
...
native/jni/su/su_daemon.c
View file @
37860181
...
@@ -126,18 +126,18 @@ static struct su_info *get_su_info(unsigned uid) {
...
@@ -126,18 +126,18 @@ static struct su_info *get_su_info(unsigned uid) {
// Check su access settings
// Check su access settings
switch
(
DB_SET
(
info
,
ROOT_ACCESS
))
{
switch
(
DB_SET
(
info
,
ROOT_ACCESS
))
{
case
ROOT_ACCESS_DISABLED
:
case
ROOT_ACCESS_DISABLED
:
LOG
E
(
"Root access is disabled!
\n
"
);
LOG
W
(
"Root access is disabled!
\n
"
);
info
->
access
=
NO_SU_ACCESS
;
info
->
access
=
NO_SU_ACCESS
;
break
;
break
;
case
ROOT_ACCESS_ADB_ONLY
:
case
ROOT_ACCESS_ADB_ONLY
:
if
(
info
->
uid
!=
UID_SHELL
)
{
if
(
info
->
uid
!=
UID_SHELL
)
{
LOG
E
(
"Root access limited to ADB only!
\n
"
);
LOG
W
(
"Root access limited to ADB only!
\n
"
);
info
->
access
=
NO_SU_ACCESS
;
info
->
access
=
NO_SU_ACCESS
;
}
}
break
;
break
;
case
ROOT_ACCESS_APPS_ONLY
:
case
ROOT_ACCESS_APPS_ONLY
:
if
(
info
->
uid
==
UID_SHELL
)
{
if
(
info
->
uid
==
UID_SHELL
)
{
LOG
E
(
"Root access is disabled for ADB!
\n
"
);
LOG
W
(
"Root access is disabled for ADB!
\n
"
);
info
->
access
=
NO_SU_ACCESS
;
info
->
access
=
NO_SU_ACCESS
;
}
}
break
;
break
;
...
@@ -282,7 +282,7 @@ void su_daemon_handler(int client, struct ucred *credential) {
...
@@ -282,7 +282,7 @@ void su_daemon_handler(int client, struct ucred *credential) {
}
}
// Read su_request
// Read su_request
xxread
(
client
,
&
ctx
.
req
,
3
*
sizeof
(
unsigned
));
xxread
(
client
,
&
ctx
.
req
,
4
*
sizeof
(
unsigned
));
ctx
.
req
.
shell
=
read_string
(
client
);
ctx
.
req
.
shell
=
read_string
(
client
);
ctx
.
req
.
command
=
read_string
(
client
);
ctx
.
req
.
command
=
read_string
(
client
);
...
@@ -338,6 +338,8 @@ void su_daemon_handler(int client, struct ucred *credential) {
...
@@ -338,6 +338,8 @@ void su_daemon_handler(int client, struct ucred *credential) {
close
(
client
);
close
(
client
);
// Handle namespaces
// Handle namespaces
if
(
ctx
.
req
.
mount_master
)
DB_SET
(
info
,
SU_MNT_NS
)
=
NAMESPACE_MODE_GLOBAL
;
switch
(
DB_SET
(
info
,
SU_MNT_NS
))
{
switch
(
DB_SET
(
info
,
SU_MNT_NS
))
{
case
NAMESPACE_MODE_GLOBAL
:
case
NAMESPACE_MODE_GLOBAL
:
LOGD
(
"su: use global namespace
\n
"
);
LOGD
(
"su: use global namespace
\n
"
);
...
@@ -355,13 +357,13 @@ void su_daemon_handler(int client, struct ucred *credential) {
...
@@ -355,13 +357,13 @@ void su_daemon_handler(int client, struct ucred *credential) {
break
;
break
;
}
}
if
(
info
->
access
.
policy
)
{
if
(
info
->
access
.
notify
||
info
->
access
.
log
)
app_log
(
&
ctx
);
if
(
info
->
access
.
policy
==
ALLOW
)
{
char
*
argv
[]
=
{
NULL
,
NULL
,
NULL
,
NULL
};
char
*
argv
[]
=
{
NULL
,
NULL
,
NULL
,
NULL
};
if
(
ctx
.
req
.
login
)
argv
[
0
]
=
ctx
.
req
.
login
?
"-"
:
ctx
.
req
.
shell
;
argv
[
0
]
=
"-"
;
else
argv
[
0
]
=
ctx
.
req
.
shell
;
if
(
ctx
.
req
.
command
[
0
])
{
if
(
ctx
.
req
.
command
[
0
])
{
argv
[
1
]
=
"-c"
;
argv
[
1
]
=
"-c"
;
...
@@ -373,17 +375,11 @@ void su_daemon_handler(int client, struct ucred *credential) {
...
@@ -373,17 +375,11 @@ void su_daemon_handler(int client, struct ucred *credential) {
populate_environment
(
&
ctx
.
req
);
populate_environment
(
&
ctx
.
req
);
set_identity
(
ctx
.
req
.
uid
);
set_identity
(
ctx
.
req
.
uid
);
if
(
info
->
access
.
notify
||
info
->
access
.
log
)
app_log
(
&
ctx
);
execvp
(
ctx
.
req
.
shell
,
argv
);
execvp
(
ctx
.
req
.
shell
,
argv
);
fprintf
(
stderr
,
"Cannot execute %s: %s
\n
"
,
ctx
.
req
.
shell
,
strerror
(
errno
));
fprintf
(
stderr
,
"Cannot execute %s: %s
\n
"
,
ctx
.
req
.
shell
,
strerror
(
errno
));
PLOGE
(
"exec"
);
PLOGE
(
"exec"
);
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
}
else
{
}
else
{
if
(
info
->
access
.
notify
||
info
->
access
.
log
)
app_log
(
&
ctx
);
LOGW
(
"su: request rejected (%u->%u)"
,
info
->
uid
,
ctx
.
req
.
uid
);
LOGW
(
"su: request rejected (%u->%u)"
,
info
->
uid
,
ctx
.
req
.
uid
);
fprintf
(
stderr
,
"%s
\n
"
,
strerror
(
EACCES
));
fprintf
(
stderr
,
"%s
\n
"
,
strerror
(
EACCES
));
exit
(
EXIT_FAILURE
);
exit
(
EXIT_FAILURE
);
...
...
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