2017-03-18 09:52:38 +01:00
|
|
|
#ifndef MAGISKPOLICY_H
|
|
|
|
#define MAGISKPOLICY_H
|
2017-01-31 17:51:45 +01:00
|
|
|
|
|
|
|
#define ALL NULL
|
|
|
|
|
|
|
|
#include <getopt.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <sys/mman.h>
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <stdio.h>
|
2017-02-03 18:58:15 +01:00
|
|
|
#include <limits.h>
|
|
|
|
#include <string.h>
|
2017-01-31 17:51:45 +01:00
|
|
|
#include <sepol/debug.h>
|
|
|
|
#include <sepol/policydb/policydb.h>
|
|
|
|
#include <sepol/policydb/expand.h>
|
|
|
|
#include <sepol/policydb/link.h>
|
|
|
|
#include <sepol/policydb/services.h>
|
|
|
|
#include <sepol/policydb/avrule_block.h>
|
|
|
|
#include <sepol/policydb/conditional.h>
|
|
|
|
#include <sepol/policydb/constraint.h>
|
|
|
|
|
2017-02-03 21:24:22 +01:00
|
|
|
// 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)
|
|
|
|
|
2017-01-31 17:51:45 +01:00
|
|
|
// Global policydb
|
|
|
|
policydb_t *policy;
|
|
|
|
|
|
|
|
// sepolicy manipulation functions
|
2017-02-04 10:30:34 +01:00
|
|
|
int load_policy(const char *filename);
|
|
|
|
int dump_policy(const char *filename);
|
2017-02-03 23:36:15 +01:00
|
|
|
int create_domain(char *d);
|
2017-02-03 21:24:22 +01:00
|
|
|
int set_domain_state(char* s, int state);
|
2017-02-03 23:36:15 +01:00
|
|
|
int add_transition(char *s, char *t, char *c, char *d);
|
|
|
|
int add_file_transition(char *s, char *t, char *c, char *d, char* filename);
|
|
|
|
int add_typeattribute(char *domainS, char *attr);
|
2017-01-31 17:51:45 +01:00
|
|
|
int add_rule(char *s, char *t, char *c, char *p, int effect, int not);
|
|
|
|
|
|
|
|
// Handy functions
|
2017-02-03 23:36:15 +01:00
|
|
|
int allow(char *s, char *t, char *c, char *p);
|
|
|
|
int deny(char *s, char *t, char *c, char *p);
|
|
|
|
int auditallow(char *s, char *t, char *c, char *p);
|
|
|
|
int auditdeny(char *s, char *t, char *c, char *p);
|
|
|
|
int typetrans(char *s, char *t, char *c, char *d, char *o);
|
|
|
|
int create(char *s);
|
|
|
|
int permissive(char *s);
|
|
|
|
int enforce(char *s);
|
|
|
|
int attradd(char *s, char *a);
|
2017-01-31 17:51:45 +01:00
|
|
|
int exists(char *source);
|
|
|
|
|
2017-02-03 18:58:15 +01:00
|
|
|
// Vector of char*
|
2017-02-03 21:24:22 +01:00
|
|
|
typedef struct vector {
|
2017-02-03 18:58:15 +01:00
|
|
|
size_t size;
|
|
|
|
size_t cap;
|
|
|
|
char **data;
|
2017-02-03 21:24:22 +01:00
|
|
|
} vector;
|
|
|
|
void vec_init(vector *v);
|
|
|
|
void vec_push_back(vector *v, char* s);
|
|
|
|
void vec_destroy(vector *v);
|
2017-02-03 18:58:15 +01:00
|
|
|
|
2017-01-31 17:51:45 +01:00
|
|
|
// Built in rules
|
|
|
|
void su_rules();
|
2017-02-01 16:07:37 +01:00
|
|
|
void min_rules();
|
2017-01-31 17:51:45 +01:00
|
|
|
|
|
|
|
#endif
|