Minor code changes across all sources

This commit is contained in:
topjohnwu 2019-06-30 19:09:31 -07:00
parent db8dd9f186
commit ff3710de66
20 changed files with 50 additions and 82 deletions

View File

@ -8,7 +8,7 @@
#include <daemon.h>
#include <utils.h>
#include <magisk.h>
#include <logging.h>
#define ABS_SOCKET_LEN(sun) (sizeof(sa_family_t) + strlen(sun->sun_path + 1) + 1)
@ -34,7 +34,7 @@ int socket_accept(int sockfd, int timeout) {
.fd = sockfd,
.events = POLL_IN
};
return xpoll(&pfd, 1, timeout * 1000) <= 0 ? -1 : xaccept4(sockfd, NULL, NULL, SOCK_CLOEXEC);
return xpoll(&pfd, 1, timeout * 1000) <= 0 ? -1 : xaccept4(sockfd, nullptr, nullptr, SOCK_CLOEXEC);
}
void get_client_cred(int fd, struct ucred *cred) {
@ -86,7 +86,7 @@ int recv_fd(int sockfd) {
cmsg = CMSG_FIRSTHDR(&msg);
if (cmsg == NULL ||
if (cmsg == nullptr ||
cmsg->cmsg_len != CMSG_LEN(sizeof(int)) ||
cmsg->cmsg_level != SOL_SOCKET ||
cmsg->cmsg_type != SCM_RIGHTS) {

View File

@ -1,5 +1,5 @@
#include <magisk.h>
#include <magiskpolicy.h>
#include <selinux.h>
constexpr const char magiskrc[] =
"\n\n"

View File

@ -3,6 +3,7 @@
#include <fcntl.h>
#include <magisk.h>
#include <magiskpolicy.h>
#include <utils.h>
#include "init.h"

View File

@ -63,11 +63,6 @@ void hide_unmount(int pid) {
chmod(SELINUX_POLICY, 0440);
}
getprop([](const char *name, auto, auto) {
if (strstr(name, "magisk"))
deleteprop(name);
}, nullptr, false);
vector<string> targets;
// Unmount dummy skeletons and /sbin links

View File

@ -8,7 +8,6 @@
#include <sys/types.h>
#include <sys/mount.h>
#include <magisk.h>
#include <daemon.h>
#include <utils.h>
#include <flags.h>

View File

@ -13,7 +13,7 @@
#include <vector>
#include <bitset>
#include <magisk.h>
#include <logging.h>
#include <utils.h>
#include "magiskhide.h"

View File

@ -8,7 +8,7 @@
#include <vector>
#include <string>
#include <magisk.h>
#include <logging.h>
#include <utils.h>
#include <flags.h>

View File

@ -1,17 +1,14 @@
/* magiskpolicy.h - Public API for policy patching
*/
#ifndef _MAGISKPOLICY_H
#define _MAGISKPOLICY_H
#pragma once
#include <stdlib.h>
#include <selinux.h>
#define ALL NULL
#ifdef __cplusplus
extern "C" {
#endif
__BEGIN_DECLS
// policydb functions
int load_policydb(const char *file);
@ -41,8 +38,4 @@ int sepol_exists(const char *source);
// Built in rules
void sepol_magisk_rules();
#ifdef __cplusplus
};
#endif
#endif
__END_DECLS

View File

@ -1,8 +1,8 @@
#include <magisk.h>
#include <logging.h>
#include <flags.h>
#include "magiskpolicy.h"
#include "sepolicy.h"
#include "flags.h"
static void allowSuClient(const char *target) {
if (!sepol_exists(target))

View File

@ -1,14 +1,11 @@
/* sepolicy.h - Header for magiskpolicy non-public APIs
*/
#ifndef _SEPOLICY_H
#define _SEPOLICY_H
#pragma once
#include <sepol/policydb/policydb.h>
#ifdef __cplusplus
extern "C" {
#endif
__BEGIN_DECLS
// Global policydb
extern policydb_t *policydb;
@ -36,8 +33,4 @@ int add_rule(const char *s, const char *t, const char *c, const char *p, int eff
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);
#ifdef __cplusplus
};
#endif
#endif
__END_DECLS

View File

@ -11,7 +11,7 @@
#include <pb_encode.h>
#include <utils.h>
#include "_resetprop.h"
#include "private/resetprop.h"
using namespace std;

View File

@ -1,14 +1,9 @@
/* resetprop.h - Internal struct definitions
*/
#ifndef MAGISK_PROPS_H
#define MAGISK_PROPS_H
#pragma once
#include <string>
#include <logging.h>
#include "private/system_properties.h"
#include "system_properties.h"
struct prop_t {
char *name;
@ -28,7 +23,7 @@ struct prop_t {
bool operator<(const prop_t &prop) const {
return strcmp(name, prop.name) < 0;
}
prop_t& operator= (prop_t &&prop) {
prop_t& operator=(prop_t &&prop) {
if (this != &prop) {
free(name);
name = prop.name;
@ -60,5 +55,3 @@ std::string persist_getprop(const char *name);
void persist_getprop(read_cb_t *read_cb);
bool persist_deleteprop(const char *name);
void collect_props(const char *name, const char *value, void *v_plist);
#endif //MAGISK_PROPS_H

View File

@ -9,7 +9,7 @@
#include <vector>
#include <algorithm>
#include <magisk.h>
#include <logging.h>
#include <resetprop.h>
#include <utils.h>
#include <flags.h>
@ -17,7 +17,7 @@
#define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_
#include "private/_system_properties.h"
#include "private/system_properties.h"
#include "_resetprop.h"
#include "private/resetprop.h"
using namespace std;
@ -80,15 +80,14 @@ illegal:
static void read_props(const prop_info *pi, void *read_cb) {
__system_property_read_callback(
pi, [](auto cb, auto name, auto value, auto) -> void
{
pi, [](auto cb, auto name, auto value, auto) {
((read_cb_t *) cb)->exec(name, value);
}, read_cb);
}
void collect_props(const char *name, const char *value, void *v_plist) {
auto &prop_list = *static_cast<vector<prop_t> *>(v_plist);
prop_list.emplace_back(name, value);
auto prop_list = static_cast<vector<prop_t> *>(v_plist);
prop_list->emplace_back(name, value);
}
static void collect_unique_props(const char *name, const char *value, void *v_plist) {
@ -121,15 +120,18 @@ static void print_props(bool persist) {
* Implementations of functions in resetprop.h (APIs)
* **************************************************/
#define ENSURE_INIT(ret) if (init_resetprop()) return ret
int prop_exist(const char *name) {
if (init_resetprop()) return 0;
ENSURE_INIT(0);
return __system_property_find(name) != nullptr;
}
// Get prop by name, return string
string getprop(const char *name, bool persist) {
if (!check_legal_property_name(name) || init_resetprop())
if (!check_legal_property_name(name))
return string();
ENSURE_INIT(string());
const prop_info *pi = __system_property_find(name);
if (pi == nullptr) {
if (persist && strncmp(name, "persist.", 8) == 0) {
@ -151,7 +153,7 @@ string getprop(const char *name, bool persist) {
}
void getprop(void (*callback)(const char *, const char *, void *), void *cookie, bool persist) {
if (init_resetprop()) return;
ENSURE_INIT();
read_cb_t read_cb(callback, cookie);
__system_property_foreach(read_props, &read_cb);
if (persist) {
@ -163,8 +165,7 @@ void getprop(void (*callback)(const char *, const char *, void *), void *cookie,
int setprop(const char *name, const char *value, bool trigger) {
if (!check_legal_property_name(name))
return 1;
if (init_resetprop())
return -1;
ENSURE_INIT(-1);
int ret;
@ -197,7 +198,7 @@ int setprop(const char *name, const char *value, bool trigger) {
int deleteprop(const char *name, bool persist) {
if (!check_legal_property_name(name))
return 1;
if (init_resetprop()) return -1;
ENSURE_INIT(-1);
char path[PATH_MAX];
path[0] = '\0';
LOGD("resetprop: deleteprop [%s]\n", name);
@ -207,7 +208,7 @@ int deleteprop(const char *name, bool persist) {
}
void load_prop_file(const char *filename, bool trigger) {
if (init_resetprop()) return;
ENSURE_INIT();
LOGD("resetprop: Parse prop file [%s]\n", filename);
parse_prop_file(filename, [=](auto key, auto val) -> bool {
setprop(key.data(), val.data(), trigger);

View File

@ -5,7 +5,6 @@
#include <fcntl.h>
#include <stdio.h>
#include <magisk.h>
#include <daemon.h>
#include <utils.h>

View File

@ -17,7 +17,7 @@
#include <errno.h>
#include <pthread.h>
#include <magisk.h>
#include <logging.h>
#include "pts.h"

View File

@ -21,7 +21,6 @@
#include <sys/types.h>
#include <sys/stat.h>
#include <magisk.h>
#include <daemon.h>
#include <utils.h>
#include <flags.h>
@ -82,7 +81,7 @@ static void sighandler(int sig) {
memset(&act, 0, sizeof(act));
act.sa_handler = SIG_DFL;
for (int i = 0; quit_signals[i]; ++i) {
sigaction(quit_signals[i], &act, NULL);
sigaction(quit_signals[i], &act, nullptr);
}
}
@ -91,7 +90,7 @@ static void setup_sighandlers(void (*handler)(int)) {
memset(&act, 0, sizeof(act));
act.sa_handler = handler;
for (int i = 0; quit_signals[i]; ++i) {
sigaction(quit_signals[i], &act, NULL);
sigaction(quit_signals[i], &act, nullptr);
}
}
@ -107,15 +106,15 @@ su_request::su_request()
int su_client_main(int argc, char *argv[]) {
int c;
struct option long_opts[] = {
{ "command", required_argument, NULL, 'c' },
{ "help", no_argument, NULL, 'h' },
{ "login", no_argument, NULL, 'l' },
{ "preserve-environment", no_argument, NULL, 'p' },
{ "shell", required_argument, NULL, 's' },
{ "version", no_argument, NULL, 'v' },
{ "context", required_argument, NULL, 'z' },
{ "mount-master", no_argument, NULL, 'M' },
{ NULL, 0, NULL, 0 },
{ "command", required_argument, nullptr, 'c' },
{ "help", no_argument, nullptr, 'h' },
{ "login", no_argument, nullptr, 'l' },
{ "preserve-environment", no_argument, nullptr, 'p' },
{ "shell", required_argument, nullptr, 's' },
{ "version", no_argument, nullptr, 'v' },
{ "context", required_argument, nullptr, 'z' },
{ "mount-master", no_argument, nullptr, 'M' },
{ nullptr, 0, nullptr, 0 },
};
su_request su_req;
@ -128,7 +127,7 @@ int su_client_main(int argc, char *argv[]) {
strcpy(argv[i], "-M");
}
while ((c = getopt_long(argc, argv, "c:hlmps:Vvuz:M", long_opts, NULL)) != -1) {
while ((c = getopt_long(argc, argv, "c:hlmps:Vvuz:M", long_opts, nullptr)) != -1) {
switch (c) {
case 'c':
su_req.command = concat_commands(argc, argv);

View File

@ -8,7 +8,7 @@
#include <sys/types.h>
#include <sys/stat.h>
#include "db.h"
#include <db.h>
#define DEFAULT_SHELL "/system/bin/sh"

View File

@ -12,7 +12,7 @@
#include <sys/wait.h>
#include <sys/mount.h>
#include <magisk.h>
#include <logging.h>
#include <daemon.h>
#include <utils.h>
#include <selinux.h>

View File

@ -11,7 +11,6 @@
#include <string.h>
#include <libgen.h>
#include <magisk.h>
#include <utils.h>
#include <selinux.h>

View File

@ -18,9 +18,7 @@
#define SEPOL_PROC_DOMAIN "magisk"
#define SEPOL_FILE_DOMAIN "magisk_file"
#ifdef __cplusplus
extern "C" {
#endif
__BEGIN_DECLS
extern void (*freecon)(char *con);
extern int (*setcon)(const char *con);
@ -38,6 +36,4 @@ void dload_selinux();
void restorecon();
void restore_rootcon();
#ifdef __cplusplus
}
#endif
__END_DECLS