Cleanup headers

This commit is contained in:
topjohnwu 2019-11-19 02:04:47 -05:00
parent 7681fde4d0
commit 9aff1a57d3
11 changed files with 45 additions and 89 deletions

View File

@ -51,6 +51,11 @@ int sepol_typemember(const char *s, const char *t, const char *c, const char *d)
return add_type_rule(s, t, c, d, AVTAB_MEMBER);
}
int sepol_nametrans(const char *s, const char *t, const char *c, const char *d, const char *o) {
// printf("name_trans %s %s %s %s %s\n", s, t, c, d, o);
return add_filename_trans(s, t, c, d, o);
}
int sepol_permissive(const char *s) {
// printf("permissive %s\n", s);
return set_domain_state(s, 1);

View File

@ -8,8 +8,6 @@
#define ALL NULL
__BEGIN_DECLS
// policydb functions
int load_policydb(const char *file);
int load_split_cil();
@ -37,5 +35,3 @@ int sepol_exists(const char *source);
// Built in rules
void sepol_magisk_rules();
__END_DECLS

View File

@ -1,12 +1,13 @@
#include <stdlib.h>
#include <sepol/policydb/expand.h>
#include <utils.h>
#include <logging.h>
#include "magiskpolicy.h"
#include "sepolicy.h"
extern void *xmalloc(size_t size);
extern void *xcalloc(size_t nmemb, size_t size);
extern void *xrealloc(void *ptr, size_t size);
extern int policydb_index_decls(sepol_handle_t * handle, policydb_t * p);
static int get_attr(const char *type, int value) {
@ -39,9 +40,9 @@ static int set_attr(const char *type, int value) {
if (attr->flavor != TYPE_ATTRIB)
return 1;
if(ebitmap_set_bit(&policydb->type_attr_map[value-1], attr->s.value-1, 1))
if(ebitmap_set_bit(&policydb->type_attr_map[value - 1], attr->s.value - 1, 1))
return 1;
if(ebitmap_set_bit(&policydb->attr_type_map[attr->s.value-1], value-1, 1))
if(ebitmap_set_bit(&policydb->attr_type_map[attr->s.value - 1], value - 1, 1))
return 1;
return 0;
@ -223,7 +224,7 @@ int create_domain(const char *d) {
return 0;
}
type_datum_t *typedatum = (type_datum_t *) malloc(sizeof(type_datum_t));
type_datum_t *typedatum = (type_datum_t *) xmalloc(sizeof(type_datum_t));
type_datum_init(typedatum);
typedatum->primary = 1;
typedatum->flavor = TYPE_TYPE;
@ -236,8 +237,8 @@ int create_domain(const char *d) {
return 1;
}
policydb->type_attr_map = realloc(policydb->type_attr_map, sizeof(ebitmap_t) * policydb->p_types.nprim);
policydb->attr_type_map = realloc(policydb->attr_type_map, sizeof(ebitmap_t) * policydb->p_types.nprim);
policydb->type_attr_map = xrealloc(policydb->type_attr_map, sizeof(ebitmap_t) * policydb->p_types.nprim);
policydb->attr_type_map = xrealloc(policydb->attr_type_map, sizeof(ebitmap_t) * policydb->p_types.nprim);
ebitmap_init(&policydb->type_attr_map[value-1]);
ebitmap_init(&policydb->attr_type_map[value-1]);
ebitmap_set_bit(&policydb->type_attr_map[value-1], value-1, 1);
@ -292,7 +293,7 @@ int set_domain_state(const char *s, int state) {
return 0;
}
int sepol_nametrans(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) {
type_datum_t *src, *tgt, *def;
class_datum_t *cls;
@ -350,12 +351,12 @@ int add_typeattribute(const char *domainS, const char *attr) {
int typeId = get_attr_id(attr);
//Now let's update all constraints!
//(kernel doesn't support (yet?) type_names rules)
for(int i=0; i<policydb->p_classes.nprim; ++i) {
for(int i = 0; i < policydb->p_classes.nprim; ++i) {
class_datum_t *cl = policydb->class_val_to_struct[i];
for(constraint_node_t *n = cl->constraints; n ; n=n->next) {
for(constraint_expr_t *e = n->expr; e; e=e->next) {
for(constraint_expr_t *e = n->expr; e; e = e->next) {
if(e->expr_type == CEXPR_NAMES) {
if(ebitmap_get_bit(&e->type_names->types, typeId-1)) {
if(ebitmap_get_bit(&e->type_names->types, typeId - 1)) {
ebitmap_set_bit(&e->names, domain->s.value-1, 1);
}
}

View File

@ -1,6 +1,3 @@
/* sepolicy.h - Header for magiskpolicy non-public APIs
*/
#pragma once
#include <sepol/policydb/policydb.h>
@ -21,10 +18,12 @@ extern policydb_t *policydb;
} \
// hashtab traversal
#define hashtab_for_each(hashtab, cur, block) hash_for_each(htable, size, hashtab, cur, block)
#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)
#define avtab_for_each(avtab, cur, block) \
hash_for_each(htable, nslot, avtab, cur, block)
int create_domain(const char *d);
int set_domain_state(const char *s, int state);
@ -32,5 +31,6 @@ int add_typeattribute(const char *domainS, const char *attr);
int add_rule(const char *s, const char *t, const char *c, const char *p, int effect, int n);
int add_xperm_rule(const char *s, const char *t, const char *c, const char *range, int effect, int n);
int add_type_rule(const char *s, const char *t, const char *c, const char *d, int effect);
int add_filename_trans(const char *s, const char *t, const char *c, const char *d, const char *o);
__END_DECLS

View File

@ -11,4 +11,4 @@
#endif
#define getline __getline
#define fsetxattr(...) syscall(__NR_fsetxattr, __VA_ARGS__)
extern "C" ssize_t __getline(char **, size_t *, FILE *);
ssize_t __getline(char **, size_t *, FILE *);

View File

@ -1,5 +1,8 @@
#pragma once
#include <functional>
#include <string_view>
#define do_align(p, a) (((p) + (a) - 1) / (a) * (a))
#define align_off(p, a) (do_align(p, a) - (p))
@ -8,10 +11,6 @@ struct file_attr {
char con[128];
};
#ifdef __cplusplus
extern "C" {
#endif
ssize_t fd_path(int fd, char *path, size_t size);
int fd_pathat(int dirfd, const char *name, char *path, size_t size);
int mkdirs(const char *pathname, mode_t mode);
@ -32,12 +31,6 @@ void fd_full_read(int fd, void **buf, size_t *size);
void full_read(const char *filename, void **buf, size_t *size);
void write_zero(int fd, size_t size);
#ifdef __cplusplus
}
#include <functional>
#include <string_view>
void file_readline(const char *file, const std::function<bool (std::string_view)> &fn, bool trim = false);
void parse_prop_file(const char *file, const std::function
<bool(std::string_view, std::string_view)> &fn);
@ -81,5 +74,3 @@ void mmap_rw(const char *filename, B &buf, L &sz) {
buf = (B) __mmap(filename, &__sz, true);
sz = __sz;
}
#endif

View File

@ -1,15 +1,10 @@
/* logging.h - Error handling and logging
*/
#pragma once
#include <errno.h>
#include <stdarg.h>
#include <string.h>
#ifdef __cplusplus
extern "C" {
#endif
__BEGIN_DECLS
typedef enum {
L_DEBUG,
@ -43,6 +38,4 @@ void cmdline_logging();
int log_handler(log_type t, const char *fmt, ...);
#ifdef __cplusplus
}
#endif
__END_DECLS

View File

@ -18,8 +18,6 @@
#define SEPOL_PROC_DOMAIN "magisk"
#define SEPOL_FILE_DOMAIN "magisk_file"
__BEGIN_DECLS
extern void (*freecon)(char *con);
extern int (*setcon)(const char *con);
extern int (*getfilecon)(const char *path, char **con);
@ -35,5 +33,3 @@ void selinux_builtin_impl();
void dload_selinux();
void restorecon();
void restore_rootcon();
__END_DECLS

View File

@ -1,30 +1,11 @@
#pragma once
#define UID_ROOT 0
#define UID_SHELL 2000
#ifdef __cplusplus
extern "C" {
#endif
int fork_dont_care();
int fork_no_zombie();
int strend(const char *s1, const char *s2);
char *rtrim(char *str);
void init_argv0(int argc, char **argv);
void set_nice_name(const char *name);
int parse_int(const char *s);
uint32_t binary_gcd(uint32_t u, uint32_t v);
int switch_mnt_ns(int pid);
#ifdef __cplusplus
}
#include <string>
#include <functional>
#include <string_view>
void gen_rand_str(char *buf, int len, bool varlen = true);
#define UID_ROOT 0
#define UID_SHELL 2000
#define str_contains(s, ss) ((ss) != nullptr && (s).find(ss) != std::string::npos)
#define str_starts(s, ss) ((ss) != nullptr && (s).compare(0, strlen(ss), ss) == 0)
@ -78,8 +59,8 @@ reversed_container<T> reversed(T &base) {
return reversed_container<T>(base);
}
int parse_int(const char *s);
static inline int parse_int(std::string s) { return parse_int(s.data()); }
static inline int parse_int(std::string_view s) { return parse_int(s.data()); }
int new_daemon_thread(void *(*start_routine) (void *), void *arg = nullptr,
@ -115,5 +96,12 @@ int exec_command_sync(Args &&...args) {
}
bool ends_with(const std::string_view &s1, const std::string_view &s2);
#endif
int fork_dont_care();
int fork_no_zombie();
int strend(const char *s1, const char *s2);
char *rtrim(char *str);
void init_argv0(int argc, char **argv);
void set_nice_name(const char *name);
uint32_t binary_gcd(uint32_t u, uint32_t v);
int switch_mnt_ns(int pid);
void gen_rand_str(char *buf, int len, bool varlen = true);

View File

@ -19,8 +19,6 @@
#define endmntent __endmntent
#define hasmntopt __hasmntopt
__BEGIN_DECLS
ssize_t __getline(char **lineptr, size_t *n, FILE *stream);
ssize_t __getdelim(char **lineptr, size_t *n, int delim, FILE *stream);
struct mntent *__getmntent_r(FILE* fp, struct mntent* e, char* buf, int buf_len);
@ -60,5 +58,3 @@ static inline int __linkat(int olddirfd, const char *oldpath,
static inline int __inotify_init1(int flags) {
return syscall(__NR_inotify_init1, flags);
}
__END_DECLS

View File

@ -1,11 +1,9 @@
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
FILE *xfopen(const char *pathname, const char *mode);
FILE *xfdopen(int fd, const char *mode);
int xopen(const char *pathname, int flags);
int xopen(const char *pathname, int flags, mode_t mode);
int xopenat(int dirfd, const char *pathname, int flags);
ssize_t xwrite(int fd, const void *buf, size_t count);
ssize_t xread(int fd, void *buf, size_t count);
@ -22,9 +20,9 @@ int xbind(int sockfd, const struct sockaddr *addr, socklen_t addrlen);
int xconnect(int sockfd, const struct sockaddr *addr, socklen_t addrlen);
int xlisten(int sockfd, int backlog);
int xaccept4(int sockfd, struct sockaddr *addr, socklen_t *addrlen, int flags);
void *xmalloc(size_t size);
void *xcalloc(size_t nmemb, size_t size);
void *xrealloc(void *ptr, size_t size);
extern "C" void *xmalloc(size_t size);
extern "C" void *xcalloc(size_t nmemb, size_t size);
extern "C" void *xrealloc(void *ptr, size_t size);
ssize_t xsendmsg(int sockfd, const struct msghdr *msg, int flags);
ssize_t xrecvmsg(int sockfd, struct msghdr *msg, int flags);
int xpthread_create(pthread_t *thread, const pthread_attr_t *attr,
@ -54,11 +52,3 @@ pid_t xfork();
int xpoll(struct pollfd *fds, nfds_t nfds, int timeout);
int xinotify_init1(int flags);
#ifdef __cplusplus
}
int xopen(const char *pathname, int flags);
int xopen(const char *pathname, int flags, mode_t mode);
#endif