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
2a2e1236
Commit
2a2e1236
authored
Dec 01, 2018
by
topjohnwu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use magic macros
parent
9b170f2b
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
35 deletions
+34
-35
rules.cpp
native/jni/magiskpolicy/rules.cpp
+5
-4
sepolicy.c
native/jni/magiskpolicy/sepolicy.c
+14
-25
sepolicy.h
native/jni/magiskpolicy/sepolicy.h
+15
-6
No files found.
native/jni/magiskpolicy/rules.cpp
View file @
2a2e1236
...
...
@@ -171,10 +171,11 @@ void sepol_magisk_rules() {
sepol_allow
(
"update_engine"
,
"adb_data_file"
,
"dir"
,
ALL
);
// Remove all dontaudit
for_each_avtab_node
([](
auto
p
)
->
void
{
if
(
p
->
key
.
specified
==
AVTAB_AUDITDENY
||
p
->
key
.
specified
==
AVTAB_XPERMS_DONTAUDIT
)
avtab_remove_node
(
&
policydb
->
te_avtab
,
p
);
});
avtab_ptr_t
av
;
avtab_for_each
(
&
policydb
->
te_avtab
,
av
,
{
if
(
av
->
key
.
specified
==
AVTAB_AUDITDENY
||
av
->
key
.
specified
==
AVTAB_XPERMS_DONTAUDIT
)
avtab_remove_node
(
&
policydb
->
te_avtab
,
av
);
})
log_cb
.
w
=
bak
;
}
native/jni/magiskpolicy/sepolicy.c
View file @
2a2e1236
...
...
@@ -138,20 +138,20 @@ static int add_rule_auto(type_datum_t *src, type_datum_t *tgt, class_datum_t *cl
int
ret
=
0
;
if
(
src
==
NULL
)
{
hashtab_for_each
(
policydb
->
p_types
.
table
,
&
cur
)
{
hashtab_for_each
(
policydb
->
p_types
.
table
,
cur
,
{
src
=
cur
->
datum
;
ret
|=
add_rule_auto
(
src
,
tgt
,
cls
,
perm
,
effect
,
not
);
}
}
)
}
else
if
(
tgt
==
NULL
)
{
hashtab_for_each
(
policydb
->
p_types
.
table
,
&
cur
)
{
hashtab_for_each
(
policydb
->
p_types
.
table
,
cur
,
{
tgt
=
cur
->
datum
;
ret
|=
add_rule_auto
(
src
,
tgt
,
cls
,
perm
,
effect
,
not
);
}
}
)
}
else
if
(
cls
==
NULL
)
{
hashtab_for_each
(
policydb
->
p_classes
.
table
,
&
cur
)
{
hashtab_for_each
(
policydb
->
p_classes
.
table
,
cur
,
{
cls
=
cur
->
datum
;
ret
|=
add_rule_auto
(
src
,
tgt
,
cls
,
perm
,
effect
,
not
);
}
}
)
}
else
{
key
.
source_type
=
src
->
s
.
value
;
key
.
target_type
=
tgt
->
s
.
value
;
...
...
@@ -210,20 +210,20 @@ static int add_xperm_rule_auto(type_datum_t *src, type_datum_t *tgt, class_datum
int
ret
=
0
;
if
(
src
==
NULL
)
{
hashtab_for_each
(
policydb
->
p_types
.
table
,
&
cur
)
{
hashtab_for_each
(
policydb
->
p_types
.
table
,
cur
,
{
src
=
cur
->
datum
;
ret
|=
add_xperm_rule_auto
(
src
,
tgt
,
cls
,
low
,
high
,
effect
,
not
);
}
}
)
}
else
if
(
tgt
==
NULL
)
{
hashtab_for_each
(
policydb
->
p_types
.
table
,
&
cur
)
{
hashtab_for_each
(
policydb
->
p_types
.
table
,
cur
,
{
tgt
=
cur
->
datum
;
ret
|=
add_xperm_rule_auto
(
src
,
tgt
,
cls
,
low
,
high
,
effect
,
not
);
}
}
)
}
else
if
(
cls
==
NULL
)
{
hashtab_for_each
(
policydb
->
p_classes
.
table
,
&
cur
)
{
hashtab_for_each
(
policydb
->
p_classes
.
table
,
cur
,
{
cls
=
cur
->
datum
;
ret
|=
add_xperm_rule_auto
(
src
,
tgt
,
cls
,
low
,
high
,
effect
,
not
);
}
}
)
}
else
{
key
.
source_type
=
src
->
s
.
value
;
key
.
target_type
=
tgt
->
s
.
value
;
...
...
@@ -407,28 +407,17 @@ int create_domain(const char *d) {
return
set_attr
(
"domain"
,
value
);
}
void
for_each_avtab_node
(
void
(
*
callback
)(
avtab_ptr_t
))
{
avtab_ptr_t
cur
,
next
;
for
(
int
i
=
0
;
i
<
policydb
->
te_avtab
.
nslot
;
++
i
)
{
for
(
cur
=
policydb
->
te_avtab
.
htable
[
i
];
cur
;
cur
=
next
)
{
// cur could be removed after callback
next
=
cur
->
next
;
callback
(
cur
);
}
}
}
int
set_domain_state
(
const
char
*
s
,
int
state
)
{
type_datum_t
*
type
;
hashtab_ptr_t
cur
;
if
(
s
==
NULL
)
{
hashtab_for_each
(
policydb
->
p_types
.
table
,
&
cur
)
{
hashtab_for_each
(
policydb
->
p_types
.
table
,
cur
,
{
type
=
cur
->
datum
;
if
(
ebitmap_set_bit
(
&
policydb
->
permissive_map
,
type
->
s
.
value
,
state
))
{
LOGW
(
"Could not set bit in permissive map
\n
"
);
return
1
;
}
}
}
)
}
else
{
type
=
hashtab_search
(
policydb
->
p_types
.
table
,
s
);
if
(
type
==
NULL
)
{
...
...
native/jni/magiskpolicy/sepolicy.h
View file @
2a2e1236
...
...
@@ -13,13 +13,22 @@ extern "C" {
// Global policydb
extern
policydb_t
*
policydb
;
// hashtab traversal macro
#define hashtab_for_each(table, ptr) \
for (int _i = 0; _i < table->size; ++_i) \
for (*ptr = table->htable[_i]; *ptr != NULL; *ptr = (*ptr)->next)
// General hash table traversal
#define hash_for_each(table, slots, tab, cur, block) \
for (int __i = 0; __i < (tab)->slots; ++__i) { \
__typeof__(cur) __next; \
for (cur = (tab)->table[__i]; cur; cur = __next) { \
__next = cur->next; \
block \
} \
} \
// hashtab traversal
#define hashtab_for_each(hashtab, cur, block) hash_for_each(htable, size, hashtab, cur, block)
// avtab traversal
#define avtab_for_each(avtab, cur, block) hash_for_each(htable, nslot, avtab, cur, block)
// sepolicy manipulation functions
void
for_each_avtab_node
(
void
(
*
callback
)(
avtab_ptr_t
));
int
create_domain
(
const
char
*
d
);
int
set_domain_state
(
const
char
*
s
,
int
state
);
int
add_typeattribute
(
const
char
*
domainS
,
const
char
*
attr
);
...
...
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