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
fe4b3df7
Commit
fe4b3df7
authored
Oct 11, 2017
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix selinux context on Magisk files
parent
25bdbcf5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
57 additions
and
8 deletions
+57
-8
bootstages.c
jni/daemon/bootstages.c
+19
-8
magisk.c
jni/daemon/magisk.c
+4
-0
daemon.h
jni/include/daemon.h
+1
-0
utils.h
jni/include/utils.h
+1
-0
file.c
jni/utils/file.c
+32
-0
No files found.
jni/daemon/bootstages.c
View file @
fe4b3df7
...
@@ -396,7 +396,7 @@ static void simple_mount(const char *path) {
...
@@ -396,7 +396,7 @@ static void simple_mount(const char *path) {
*****************/
*****************/
// A one time setup
// A one time setup
void
daemon_init
()
{
static
void
daemon_init
()
{
LOGI
(
"* Creating /sbin overlay"
);
LOGI
(
"* Creating /sbin overlay"
);
DIR
*
dir
;
DIR
*
dir
;
struct
dirent
*
entry
;
struct
dirent
*
entry
;
...
@@ -493,6 +493,12 @@ void daemon_init() {
...
@@ -493,6 +493,12 @@ void daemon_init() {
}
}
static
int
prepare_img
()
{
static
int
prepare_img
()
{
// First merge images
if
(
merge_img
(
"/data/magisk_merge.img"
,
MAINIMG
))
{
LOGE
(
"Image merge %s -> %s failed!
\n
"
,
"/data/magisk_merge.img"
,
MAINIMG
);
return
1
;
}
if
(
access
(
MAINIMG
,
F_OK
)
==
-
1
)
{
if
(
access
(
MAINIMG
,
F_OK
)
==
-
1
)
{
if
(
create_img
(
MAINIMG
,
64
))
if
(
create_img
(
MAINIMG
,
64
))
return
1
;
return
1
;
...
@@ -544,9 +550,20 @@ static int prepare_img() {
...
@@ -544,9 +550,20 @@ static int prepare_img() {
magiskloop
=
mount_image
(
MAINIMG
,
MOUNTPOINT
);
magiskloop
=
mount_image
(
MAINIMG
,
MOUNTPOINT
);
free
(
magiskloop
);
free
(
magiskloop
);
// Fix file seliux contexts
fix_filecon
();
return
0
;
return
0
;
}
}
void
fix_filecon
()
{
int
dirfd
=
xopen
(
MOUNTPOINT
,
O_RDONLY
|
O_CLOEXEC
);
restorecon
(
dirfd
,
0
);
close
(
dirfd
);
dirfd
=
xopen
(
DATABIN
,
O_RDONLY
|
O_CLOEXEC
);
restorecon
(
dirfd
,
1
);
close
(
dirfd
);
}
/****************
/****************
* Entry points *
* Entry points *
****************/
****************/
...
@@ -618,12 +635,6 @@ void post_fs_data(int client) {
...
@@ -618,12 +635,6 @@ void post_fs_data(int client) {
// Initialize
// Initialize
daemon_init
();
daemon_init
();
// Merge images
if
(
merge_img
(
"/data/magisk_merge.img"
,
MAINIMG
))
{
LOGE
(
"Image merge %s -> %s failed!
\n
"
,
"/data/magisk_merge.img"
,
MAINIMG
);
goto
unblock
;
}
// uninstaller
// uninstaller
if
(
access
(
UNINSTALLER
,
F_OK
)
==
0
)
{
if
(
access
(
UNINSTALLER
,
F_OK
)
==
0
)
{
close
(
open
(
UNBLOCKFILE
,
O_RDONLY
|
O_CREAT
));
close
(
open
(
UNBLOCKFILE
,
O_RDONLY
|
O_CREAT
));
...
@@ -632,7 +643,7 @@ void post_fs_data(int client) {
...
@@ -632,7 +643,7 @@ void post_fs_data(int client) {
return
;
return
;
}
}
//
T
rim, mount magisk.img, which will also travel through the modules
//
Merge, t
rim, mount magisk.img, which will also travel through the modules
// After this, it will create the module list
// After this, it will create the module list
if
(
prepare_img
())
if
(
prepare_img
())
goto
core_only
;
// Mounting fails, we can only do core only stuffs
goto
core_only
;
// Mounting fails, we can only do core only stuffs
...
...
jni/daemon/magisk.c
View file @
fe4b3df7
...
@@ -56,6 +56,7 @@ static void usage() {
...
@@ -56,6 +56,7 @@ static void usage() {
" --umountimg PATH LOOP unmount PATH and delete LOOP device
\n
"
" --umountimg PATH LOOP unmount PATH and delete LOOP device
\n
"
" --[init service] start init service
\n
"
" --[init service] start init service
\n
"
" --unlock-blocks set BLKROSET flag to OFF for all block devices
\n
"
" --unlock-blocks set BLKROSET flag to OFF for all block devices
\n
"
" --restorecon fix selinux context on Magisk files and folders
\n
"
"
\n
"
"
\n
"
"Supported init services:
\n
"
"Supported init services:
\n
"
" daemon post-fs, post-fs-data, service
\n
"
" daemon post-fs, post-fs-data, service
\n
"
...
@@ -146,6 +147,9 @@ int main(int argc, char *argv[]) {
...
@@ -146,6 +147,9 @@ int main(int argc, char *argv[]) {
}
else
if
(
strcmp
(
argv
[
1
],
"--unlock-blocks"
)
==
0
)
{
}
else
if
(
strcmp
(
argv
[
1
],
"--unlock-blocks"
)
==
0
)
{
unlock_blocks
();
unlock_blocks
();
return
0
;
return
0
;
}
else
if
(
strcmp
(
argv
[
1
],
"--restorecon"
)
==
0
)
{
fix_filecon
();
return
0
;
}
else
if
(
strcmp
(
argv
[
1
],
"--daemon"
)
==
0
)
{
}
else
if
(
strcmp
(
argv
[
1
],
"--daemon"
)
==
0
)
{
// Start daemon, this process won't return
// Start daemon, this process won't return
start_daemon
();
start_daemon
();
...
...
jni/include/daemon.h
View file @
fe4b3df7
...
@@ -59,6 +59,7 @@ void write_string(int fd, const char* val);
...
@@ -59,6 +59,7 @@ void write_string(int fd, const char* val);
void
post_fs
(
int
client
);
void
post_fs
(
int
client
);
void
post_fs_data
(
int
client
);
void
post_fs_data
(
int
client
);
void
late_start
(
int
client
);
void
late_start
(
int
client
);
void
fix_filecon
();
/**************
/**************
* MagiskHide *
* MagiskHide *
...
...
jni/include/utils.h
View file @
fe4b3df7
...
@@ -110,6 +110,7 @@ int setattrat(int dirfd, const char *pathname, struct file_attr *a);
...
@@ -110,6 +110,7 @@ int setattrat(int dirfd, const char *pathname, struct file_attr *a);
int
fsetattr
(
int
fd
,
struct
file_attr
*
a
);
int
fsetattr
(
int
fd
,
struct
file_attr
*
a
);
void
fclone_attr
(
const
int
sourcefd
,
const
int
targetfd
);
void
fclone_attr
(
const
int
sourcefd
,
const
int
targetfd
);
void
clone_attr
(
const
char
*
source
,
const
char
*
target
);
void
clone_attr
(
const
char
*
source
,
const
char
*
target
);
void
restorecon
(
int
dirfd
,
int
force
);
// img.c
// img.c
...
...
jni/utils/file.c
View file @
fe4b3df7
...
@@ -270,3 +270,35 @@ void fclone_attr(const int sourcefd, const int targetfd) {
...
@@ -270,3 +270,35 @@ void fclone_attr(const int sourcefd, const int targetfd) {
fgetattr
(
sourcefd
,
&
a
);
fgetattr
(
sourcefd
,
&
a
);
fsetattr
(
targetfd
,
&
a
);
fsetattr
(
targetfd
,
&
a
);
}
}
#define UNLABEL_CON "u:object_r:unlabeled:s0"
#define SYSTEM_CON "u:object_r:system_file:s0"
void
restorecon
(
int
dirfd
,
int
force
)
{
struct
dirent
*
entry
;
DIR
*
dir
;
int
fd
;
char
*
con
;
fgetfilecon
(
dirfd
,
&
con
);
if
(
force
||
strlen
(
con
)
==
0
||
strcmp
(
con
,
UNLABEL_CON
)
==
0
)
fsetfilecon
(
dirfd
,
SYSTEM_CON
);
freecon
(
con
);
dir
=
fdopendir
(
dirfd
);
while
((
entry
=
readdir
(
dir
)))
{
if
(
strcmp
(
entry
->
d_name
,
"."
)
==
0
||
strcmp
(
entry
->
d_name
,
".."
)
==
0
)
continue
;
if
(
entry
->
d_type
==
DT_DIR
)
{
fd
=
openat
(
dirfd
,
entry
->
d_name
,
O_RDONLY
|
O_CLOEXEC
);
restorecon
(
fd
,
force
);
}
else
{
fd
=
openat
(
dirfd
,
entry
->
d_name
,
O_PATH
|
O_NOFOLLOW
|
O_CLOEXEC
);
fgetfilecon
(
fd
,
&
con
);
if
(
force
||
strlen
(
con
)
==
0
||
strcmp
(
con
,
UNLABEL_CON
)
==
0
)
fsetfilecon
(
fd
,
SYSTEM_CON
);
freecon
(
con
);
}
close
(
fd
);
}
}
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