Magisk/utils.c

67 lines
1.3 KiB
C
Raw Normal View History

2017-02-01 00:51:45 +08:00
#include "sepolicy-inject.h"
2017-02-04 04:24:22 +08:00
void vec_init(vector *v) {
2017-02-04 01:58:15 +08:00
v->size = 0;
v->cap = 1;
v->data = (char**) malloc(sizeof(char*));
}
2017-02-04 04:24:22 +08:00
void vec_push_back(vector *v, char* s) {
2017-02-04 01:58:15 +08:00
if (v == NULL) return;
if (v->size == v->cap) {
v->cap *= 2;
v->data = (char**) realloc(v->data, sizeof(char*) * v->cap);
}
v->data[v->size] = s;
++v->size;
}
2017-02-04 04:24:22 +08:00
void vec_destroy(vector *v) {
2017-02-04 01:58:15 +08:00
v->size = 0;
v->cap = 0;
free(v->data);
}
int allow(char *s, char *t, char *c, char *p) {
return add_rule(s, t, c, p, AVTAB_ALLOWED, 0);
2017-02-01 00:51:45 +08:00
}
int deny(char *s, char *t, char *c, char *p) {
return add_rule(s, t, c, p, AVTAB_ALLOWED, 1);
2017-02-01 00:51:45 +08:00
}
int auditallow(char *s, char *t, char *c, char *p) {
return add_rule(s, t, c, p, AVTAB_AUDITALLOW, 0);
2017-02-01 00:51:45 +08:00
}
int auditdeny(char *s, char *t, char *c, char *p) {
return add_rule(s, t, c, p, AVTAB_AUDITDENY, 0);
2017-02-01 00:51:45 +08:00
}
int typetrans(char *s, char *t, char *c, char *d, char *o) {
if (o == NULL)
return add_transition(s, t, c, d);
else
return add_file_transition(s, t, c, d, o);
2017-02-01 00:51:45 +08:00
}
int permissive(char *s) {
return set_domain_state(s, 1);
2017-02-01 00:51:45 +08:00
}
int enforce(char *s) {
return set_domain_state(s, 0);
}
int create(char *s) {
return create_domain(s);
}
int attradd(char *s, char *a) {
return add_typeattribute(s, a);
2017-02-01 00:51:45 +08:00
}
int exists(char* source) {
return !! hashtab_search(policy->p_types.table, source);
}