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
951273f8
Commit
951273f8
authored
May 24, 2020
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cleanup some implementations
parent
51eeb89f
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
246 additions
and
271 deletions
+246
-271
magiskpolicy.hpp
native/jni/include/magiskpolicy.hpp
+17
-17
magiskpolicy.cpp
native/jni/magiskpolicy/magiskpolicy.cpp
+2
-2
policydb.cpp
native/jni/magiskpolicy/policydb.cpp
+4
-4
sepolicy.cpp
native/jni/magiskpolicy/sepolicy.cpp
+212
-235
sepolicy.hpp
native/jni/magiskpolicy/sepolicy.hpp
+10
-12
statement.cpp
native/jni/magiskpolicy/statement.cpp
+1
-1
No files found.
native/jni/include/magiskpolicy.hpp
View file @
951273f8
...
@@ -18,35 +18,35 @@ public:
...
@@ -18,35 +18,35 @@ public:
static
sepolicy
*
compile_split
();
static
sepolicy
*
compile_split
();
// External APIs
// External APIs
int
to_file
(
c_str
file
);
bool
to_file
(
c_str
file
);
void
parse_statement
(
c_str
stmt
);
void
parse_statement
(
c_str
stmt
);
void
load_rule_file
(
c_str
file
);
void
load_rule_file
(
c_str
file
);
// Operation on types
// Operation on types
int
create
(
c_str
type
);
bool
create
(
c_str
type
);
int
permissive
(
c_str
type
);
bool
permissive
(
c_str
type
);
int
enforce
(
c_str
type
);
bool
enforce
(
c_str
type
);
int
typeattribute
(
c_str
type
,
c_str
attr
);
bool
typeattribute
(
c_str
type
,
c_str
attr
);
int
exists
(
c_str
type
);
bool
exists
(
c_str
type
);
// Access vector rules
// Access vector rules
int
allow
(
c_str
src
,
c_str
tgt
,
c_str
cls
,
c_str
perm
);
bool
allow
(
c_str
src
,
c_str
tgt
,
c_str
cls
,
c_str
perm
);
int
deny
(
c_str
src
,
c_str
tgt
,
c_str
cls
,
c_str
perm
);
bool
deny
(
c_str
src
,
c_str
tgt
,
c_str
cls
,
c_str
perm
);
int
auditallow
(
c_str
src
,
c_str
tgt
,
c_str
cls
,
c_str
perm
);
bool
auditallow
(
c_str
src
,
c_str
tgt
,
c_str
cls
,
c_str
perm
);
int
dontaudit
(
c_str
src
,
c_str
tgt
,
c_str
cls
,
c_str
perm
);
bool
dontaudit
(
c_str
src
,
c_str
tgt
,
c_str
cls
,
c_str
perm
);
// Extended permissions access vector rules
// Extended permissions access vector rules
int
allowxperm
(
c_str
src
,
c_str
tgt
,
c_str
cls
,
c_str
range
);
bool
allowxperm
(
c_str
src
,
c_str
tgt
,
c_str
cls
,
c_str
range
);
int
auditallowxperm
(
c_str
src
,
c_str
tgt
,
c_str
cls
,
c_str
range
);
bool
auditallowxperm
(
c_str
src
,
c_str
tgt
,
c_str
cls
,
c_str
range
);
int
dontauditxperm
(
c_str
src
,
c_str
tgt
,
c_str
cls
,
c_str
range
);
bool
dontauditxperm
(
c_str
src
,
c_str
tgt
,
c_str
cls
,
c_str
range
);
// Type rules
// Type rules
int
type_transition
(
c_str
s
,
c_str
t
,
c_str
c
,
c_str
d
,
c_str
o
=
nullptr
);
bool
type_transition
(
c_str
src
,
c_str
tgt
,
c_str
cls
,
c_str
def
,
c_str
obj
=
nullptr
);
int
type_change
(
c_str
src
,
c_str
tgt
,
c_str
cls
,
c_str
def
);
bool
type_change
(
c_str
src
,
c_str
tgt
,
c_str
cls
,
c_str
def
);
int
type_member
(
c_str
src
,
c_str
tgt
,
c_str
cls
,
c_str
def
);
bool
type_member
(
c_str
src
,
c_str
tgt
,
c_str
cls
,
c_str
def
);
// File system labeling
// File system labeling
int
genfscon
(
c_str
fs_name
,
c_str
path
,
c_str
ctx
);
bool
genfscon
(
c_str
fs_name
,
c_str
path
,
c_str
ctx
);
// Magisk
// Magisk
void
magisk_rules
();
void
magisk_rules
();
...
...
native/jni/magiskpolicy/magiskpolicy.cpp
View file @
951273f8
...
@@ -110,12 +110,12 @@ int magiskpolicy_main(int argc, char *argv[]) {
...
@@ -110,12 +110,12 @@ int magiskpolicy_main(int argc, char *argv[]) {
for
(;
i
<
argc
;
++
i
)
for
(;
i
<
argc
;
++
i
)
sepol
->
parse_statement
(
argv
[
i
]);
sepol
->
parse_statement
(
argv
[
i
]);
if
(
live
&&
sepol
->
to_file
(
SELINUX_LOAD
))
{
if
(
live
&&
!
sepol
->
to_file
(
SELINUX_LOAD
))
{
fprintf
(
stderr
,
"Cannot apply policy
\n
"
);
fprintf
(
stderr
,
"Cannot apply policy
\n
"
);
return
1
;
return
1
;
}
}
if
(
out_file
&&
sepol
->
to_file
(
out_file
))
{
if
(
out_file
&&
!
sepol
->
to_file
(
out_file
))
{
fprintf
(
stderr
,
"Cannot dump policy to %s
\n
"
,
out_file
);
fprintf
(
stderr
,
"Cannot dump policy to %s
\n
"
,
out_file
);
return
1
;
return
1
;
}
}
...
...
native/jni/magiskpolicy/policydb.cpp
View file @
951273f8
...
@@ -189,7 +189,7 @@ sepolicy::~sepolicy() {
...
@@ -189,7 +189,7 @@ sepolicy::~sepolicy() {
free
(
db
);
free
(
db
);
}
}
int
sepolicy
::
to_file
(
const
char
*
file
)
{
bool
sepolicy
::
to_file
(
const
char
*
file
)
{
uint8_t
*
data
;
uint8_t
*
data
;
size_t
len
;
size_t
len
;
...
@@ -205,14 +205,14 @@ int sepolicy::to_file(const char *file) {
...
@@ -205,14 +205,14 @@ int sepolicy::to_file(const char *file) {
pf
.
fp
=
fp
.
get
();
pf
.
fp
=
fp
.
get
();
if
(
policydb_write
(
db
,
&
pf
))
{
if
(
policydb_write
(
db
,
&
pf
))
{
LOGE
(
"Fail to create policy image
\n
"
);
LOGE
(
"Fail to create policy image
\n
"
);
return
1
;
return
false
;
}
}
int
fd
=
xopen
(
file
,
O_WRONLY
|
O_CREAT
|
O_TRUNC
|
O_CLOEXEC
,
0644
);
int
fd
=
xopen
(
file
,
O_WRONLY
|
O_CREAT
|
O_TRUNC
|
O_CLOEXEC
,
0644
);
if
(
fd
<
0
)
if
(
fd
<
0
)
return
1
;
return
false
;
xwrite
(
fd
,
data
,
len
);
xwrite
(
fd
,
data
,
len
);
close
(
fd
);
close
(
fd
);
return
0
;
return
true
;
}
}
native/jni/magiskpolicy/sepolicy.cpp
View file @
951273f8
This diff is collapsed.
Click to expand it.
native/jni/magiskpolicy/sepolicy.hpp
View file @
951273f8
...
@@ -8,19 +8,17 @@ struct sepol_impl : public sepolicy {
...
@@ -8,19 +8,17 @@ struct sepol_impl : public sepolicy {
int
set_attr
(
const
char
*
attr_name
,
int
type_val
);
int
set_attr
(
const
char
*
attr_name
,
int
type_val
);
void
check_avtab_node
(
avtab_ptr_t
node
);
void
check_avtab_node
(
avtab_ptr_t
node
);
avtab_ptr_t
get_avtab_node
(
avtab_key_t
*
key
,
avtab_extended_perms_t
*
xperms
);
avtab_ptr_t
get_avtab_node
(
avtab_key_t
*
key
,
avtab_extended_perms_t
*
xperms
);
int
add_avrule
(
avtab_key_t
*
key
,
int
val
,
bool
n
);
bool
add_rule
(
const
char
*
s
,
const
char
*
t
,
const
char
*
c
,
const
char
*
p
,
int
effect
,
bool
n
);
int
add_rule
(
const
char
*
s
,
const
char
*
t
,
const
char
*
c
,
const
char
*
p
,
int
effect
,
bool
n
);
void
add_rule
(
type_datum_t
*
src
,
type_datum_t
*
tgt
,
class_datum_t
*
cls
,
perm_datum_t
*
perm
,
int
effect
,
bool
n
);
int
add_rule
(
type_datum_t
*
src
,
type_datum_t
*
tgt
,
class_datum_t
*
cls
,
perm_datum_t
*
perm
,
int
effect
,
bool
n
);
void
add_xperm_rule
(
type_datum_t
*
src
,
type_datum_t
*
tgt
,
int
add_avxrule
(
avtab_key_t
*
key
,
uint16_t
low
,
uint16_t
high
,
bool
n
);
int
add_xperm_rule
(
type_datum_t
*
src
,
type_datum_t
*
tgt
,
class_datum_t
*
cls
,
uint16_t
low
,
uint16_t
high
,
int
effect
,
bool
n
);
class_datum_t
*
cls
,
uint16_t
low
,
uint16_t
high
,
int
effect
,
bool
n
);
int
add_xperm_rule
(
const
char
*
s
,
const
char
*
t
,
const
char
*
c
,
const
char
*
range
,
int
effect
,
bool
n
);
bool
add_xperm_rule
(
const
char
*
s
,
const
char
*
t
,
const
char
*
c
,
const
char
*
range
,
int
effect
,
bool
n
);
int
create_domain
(
const
char
*
type_name
);
bool
add_type_rule
(
const
char
*
s
,
const
char
*
t
,
const
char
*
c
,
const
char
*
d
,
int
effect
);
int
set_domain_state
(
const
char
*
s
,
bool
permissive
);
bool
add_filename_trans
(
const
char
*
s
,
const
char
*
t
,
const
char
*
c
,
const
char
*
d
,
const
char
*
o
);
int
add_filename_trans
(
const
char
*
s
,
const
char
*
t
,
const
char
*
c
,
const
char
*
d
,
const
char
*
o
);
bool
add_genfscon
(
const
char
*
fs_name
,
const
char
*
path
,
const
char
*
context
);
int
add_typeattribute
(
const
char
*
type
,
const
char
*
attr
);
bool
create_domain
(
const
char
*
type_name
);
int
add_type_rule
(
const
char
*
s
,
const
char
*
t
,
const
char
*
c
,
const
char
*
d
,
int
effect
);
bool
set_domain_state
(
const
char
*
s
,
bool
permissive
);
int
add_genfscon
(
const
char
*
fs_name
,
const
char
*
path
,
const
char
*
context
);
bool
add_typeattribute
(
const
char
*
type
,
const
char
*
attr
);
void
strip_dontaudit
();
void
strip_dontaudit
();
void
allow_su_client
(
const
char
*
type
);
void
allow_su_client
(
const
char
*
type
);
};
};
...
...
native/jni/magiskpolicy/statement.cpp
View file @
951273f8
...
@@ -133,7 +133,7 @@ static bool tokenize_and_check(char *stmt, vector<vector<char *>> &arr) {
...
@@ -133,7 +133,7 @@ static bool tokenize_and_check(char *stmt, vector<vector<char *>> &arr) {
template
<
typename
Func
,
typename
...
Args
>
template
<
typename
Func
,
typename
...
Args
>
static
void
run_and_check
(
const
Func
&
fn
,
const
char
*
action
,
Args
...
args
)
{
static
void
run_and_check
(
const
Func
&
fn
,
const
char
*
action
,
Args
...
args
)
{
if
(
fn
(
args
...))
{
if
(
!
fn
(
args
...))
{
string
s
=
"Error in: %s"
;
string
s
=
"Error in: %s"
;
for
(
int
i
=
0
;
i
<
sizeof
...(
args
);
++
i
)
s
+=
" %s"
;
for
(
int
i
=
0
;
i
<
sizeof
...(
args
);
++
i
)
s
+=
" %s"
;
s
+=
"
\n
"
;
s
+=
"
\n
"
;
...
...
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