Minor code changes across all sources
This commit is contained in:
parent
db8dd9f186
commit
ff3710de66
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
#include <daemon.h>
|
#include <daemon.h>
|
||||||
#include <utils.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)
|
#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,
|
.fd = sockfd,
|
||||||
.events = POLL_IN
|
.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) {
|
void get_client_cred(int fd, struct ucred *cred) {
|
||||||
@ -86,7 +86,7 @@ int recv_fd(int sockfd) {
|
|||||||
|
|
||||||
cmsg = CMSG_FIRSTHDR(&msg);
|
cmsg = CMSG_FIRSTHDR(&msg);
|
||||||
|
|
||||||
if (cmsg == NULL ||
|
if (cmsg == nullptr ||
|
||||||
cmsg->cmsg_len != CMSG_LEN(sizeof(int)) ||
|
cmsg->cmsg_len != CMSG_LEN(sizeof(int)) ||
|
||||||
cmsg->cmsg_level != SOL_SOCKET ||
|
cmsg->cmsg_level != SOL_SOCKET ||
|
||||||
cmsg->cmsg_type != SCM_RIGHTS) {
|
cmsg->cmsg_type != SCM_RIGHTS) {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#include <magisk.h>
|
#include <magisk.h>
|
||||||
#include <magiskpolicy.h>
|
#include <selinux.h>
|
||||||
|
|
||||||
constexpr const char magiskrc[] =
|
constexpr const char magiskrc[] =
|
||||||
"\n\n"
|
"\n\n"
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
|
|
||||||
#include <magisk.h>
|
#include <magisk.h>
|
||||||
|
#include <magiskpolicy.h>
|
||||||
#include <utils.h>
|
#include <utils.h>
|
||||||
|
|
||||||
#include "init.h"
|
#include "init.h"
|
||||||
|
@ -63,11 +63,6 @@ void hide_unmount(int pid) {
|
|||||||
chmod(SELINUX_POLICY, 0440);
|
chmod(SELINUX_POLICY, 0440);
|
||||||
}
|
}
|
||||||
|
|
||||||
getprop([](const char *name, auto, auto) {
|
|
||||||
if (strstr(name, "magisk"))
|
|
||||||
deleteprop(name);
|
|
||||||
}, nullptr, false);
|
|
||||||
|
|
||||||
vector<string> targets;
|
vector<string> targets;
|
||||||
|
|
||||||
// Unmount dummy skeletons and /sbin links
|
// Unmount dummy skeletons and /sbin links
|
||||||
|
@ -8,7 +8,6 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/mount.h>
|
#include <sys/mount.h>
|
||||||
|
|
||||||
#include <magisk.h>
|
|
||||||
#include <daemon.h>
|
#include <daemon.h>
|
||||||
#include <utils.h>
|
#include <utils.h>
|
||||||
#include <flags.h>
|
#include <flags.h>
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <bitset>
|
#include <bitset>
|
||||||
|
|
||||||
#include <magisk.h>
|
#include <logging.h>
|
||||||
#include <utils.h>
|
#include <utils.h>
|
||||||
|
|
||||||
#include "magiskhide.h"
|
#include "magiskhide.h"
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
#include <magisk.h>
|
#include <logging.h>
|
||||||
#include <utils.h>
|
#include <utils.h>
|
||||||
#include <flags.h>
|
#include <flags.h>
|
||||||
|
|
||||||
|
@ -1,17 +1,14 @@
|
|||||||
/* magiskpolicy.h - Public API for policy patching
|
/* magiskpolicy.h - Public API for policy patching
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _MAGISKPOLICY_H
|
#pragma once
|
||||||
#define _MAGISKPOLICY_H
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <selinux.h>
|
#include <selinux.h>
|
||||||
|
|
||||||
#define ALL NULL
|
#define ALL NULL
|
||||||
|
|
||||||
#ifdef __cplusplus
|
__BEGIN_DECLS
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// policydb functions
|
// policydb functions
|
||||||
int load_policydb(const char *file);
|
int load_policydb(const char *file);
|
||||||
@ -41,8 +38,4 @@ int sepol_exists(const char *source);
|
|||||||
// Built in rules
|
// Built in rules
|
||||||
void sepol_magisk_rules();
|
void sepol_magisk_rules();
|
||||||
|
|
||||||
#ifdef __cplusplus
|
__END_DECLS
|
||||||
};
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
#include <magisk.h>
|
#include <logging.h>
|
||||||
|
#include <flags.h>
|
||||||
|
|
||||||
#include "magiskpolicy.h"
|
#include "magiskpolicy.h"
|
||||||
#include "sepolicy.h"
|
#include "sepolicy.h"
|
||||||
#include "flags.h"
|
|
||||||
|
|
||||||
static void allowSuClient(const char *target) {
|
static void allowSuClient(const char *target) {
|
||||||
if (!sepol_exists(target))
|
if (!sepol_exists(target))
|
||||||
|
@ -1,14 +1,11 @@
|
|||||||
/* sepolicy.h - Header for magiskpolicy non-public APIs
|
/* sepolicy.h - Header for magiskpolicy non-public APIs
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _SEPOLICY_H
|
#pragma once
|
||||||
#define _SEPOLICY_H
|
|
||||||
|
|
||||||
#include <sepol/policydb/policydb.h>
|
#include <sepol/policydb/policydb.h>
|
||||||
|
|
||||||
#ifdef __cplusplus
|
__BEGIN_DECLS
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Global policydb
|
// Global policydb
|
||||||
extern policydb_t *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_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_type_rule(const char *s, const char *t, const char *c, const char *d, int effect);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
__END_DECLS
|
||||||
};
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
@ -11,7 +11,7 @@
|
|||||||
#include <pb_encode.h>
|
#include <pb_encode.h>
|
||||||
#include <utils.h>
|
#include <utils.h>
|
||||||
|
|
||||||
#include "_resetprop.h"
|
#include "private/resetprop.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
|
@ -1,14 +1,9 @@
|
|||||||
/* resetprop.h - Internal struct definitions
|
#pragma once
|
||||||
*/
|
|
||||||
|
|
||||||
|
|
||||||
#ifndef MAGISK_PROPS_H
|
|
||||||
#define MAGISK_PROPS_H
|
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <logging.h>
|
#include <logging.h>
|
||||||
|
|
||||||
#include "private/system_properties.h"
|
#include "system_properties.h"
|
||||||
|
|
||||||
struct prop_t {
|
struct prop_t {
|
||||||
char *name;
|
char *name;
|
||||||
@ -28,7 +23,7 @@ struct prop_t {
|
|||||||
bool operator<(const prop_t &prop) const {
|
bool operator<(const prop_t &prop) const {
|
||||||
return strcmp(name, prop.name) < 0;
|
return strcmp(name, prop.name) < 0;
|
||||||
}
|
}
|
||||||
prop_t& operator= (prop_t &&prop) {
|
prop_t& operator=(prop_t &&prop) {
|
||||||
if (this != &prop) {
|
if (this != &prop) {
|
||||||
free(name);
|
free(name);
|
||||||
name = prop.name;
|
name = prop.name;
|
||||||
@ -60,5 +55,3 @@ std::string persist_getprop(const char *name);
|
|||||||
void persist_getprop(read_cb_t *read_cb);
|
void persist_getprop(read_cb_t *read_cb);
|
||||||
bool persist_deleteprop(const char *name);
|
bool persist_deleteprop(const char *name);
|
||||||
void collect_props(const char *name, const char *value, void *v_plist);
|
void collect_props(const char *name, const char *value, void *v_plist);
|
||||||
|
|
||||||
#endif //MAGISK_PROPS_H
|
|
@ -9,7 +9,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
#include <magisk.h>
|
#include <logging.h>
|
||||||
#include <resetprop.h>
|
#include <resetprop.h>
|
||||||
#include <utils.h>
|
#include <utils.h>
|
||||||
#include <flags.h>
|
#include <flags.h>
|
||||||
@ -17,7 +17,7 @@
|
|||||||
#define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_
|
#define _REALLY_INCLUDE_SYS__SYSTEM_PROPERTIES_H_
|
||||||
#include "private/_system_properties.h"
|
#include "private/_system_properties.h"
|
||||||
#include "private/system_properties.h"
|
#include "private/system_properties.h"
|
||||||
#include "_resetprop.h"
|
#include "private/resetprop.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
@ -80,15 +80,14 @@ illegal:
|
|||||||
|
|
||||||
static void read_props(const prop_info *pi, void *read_cb) {
|
static void read_props(const prop_info *pi, void *read_cb) {
|
||||||
__system_property_read_callback(
|
__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_t *) cb)->exec(name, value);
|
||||||
}, read_cb);
|
}, read_cb);
|
||||||
}
|
}
|
||||||
|
|
||||||
void collect_props(const char *name, const char *value, void *v_plist) {
|
void collect_props(const char *name, const char *value, void *v_plist) {
|
||||||
auto &prop_list = *static_cast<vector<prop_t> *>(v_plist);
|
auto prop_list = static_cast<vector<prop_t> *>(v_plist);
|
||||||
prop_list.emplace_back(name, value);
|
prop_list->emplace_back(name, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void collect_unique_props(const char *name, const char *value, void *v_plist) {
|
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)
|
* Implementations of functions in resetprop.h (APIs)
|
||||||
* **************************************************/
|
* **************************************************/
|
||||||
|
|
||||||
|
#define ENSURE_INIT(ret) if (init_resetprop()) return ret
|
||||||
|
|
||||||
int prop_exist(const char *name) {
|
int prop_exist(const char *name) {
|
||||||
if (init_resetprop()) return 0;
|
ENSURE_INIT(0);
|
||||||
return __system_property_find(name) != nullptr;
|
return __system_property_find(name) != nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get prop by name, return string
|
// Get prop by name, return string
|
||||||
string getprop(const char *name, bool persist) {
|
string getprop(const char *name, bool persist) {
|
||||||
if (!check_legal_property_name(name) || init_resetprop())
|
if (!check_legal_property_name(name))
|
||||||
return string();
|
return string();
|
||||||
|
ENSURE_INIT(string());
|
||||||
const prop_info *pi = __system_property_find(name);
|
const prop_info *pi = __system_property_find(name);
|
||||||
if (pi == nullptr) {
|
if (pi == nullptr) {
|
||||||
if (persist && strncmp(name, "persist.", 8) == 0) {
|
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) {
|
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);
|
read_cb_t read_cb(callback, cookie);
|
||||||
__system_property_foreach(read_props, &read_cb);
|
__system_property_foreach(read_props, &read_cb);
|
||||||
if (persist) {
|
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) {
|
int setprop(const char *name, const char *value, bool trigger) {
|
||||||
if (!check_legal_property_name(name))
|
if (!check_legal_property_name(name))
|
||||||
return 1;
|
return 1;
|
||||||
if (init_resetprop())
|
ENSURE_INIT(-1);
|
||||||
return -1;
|
|
||||||
|
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
@ -197,7 +198,7 @@ int setprop(const char *name, const char *value, bool trigger) {
|
|||||||
int deleteprop(const char *name, bool persist) {
|
int deleteprop(const char *name, bool persist) {
|
||||||
if (!check_legal_property_name(name))
|
if (!check_legal_property_name(name))
|
||||||
return 1;
|
return 1;
|
||||||
if (init_resetprop()) return -1;
|
ENSURE_INIT(-1);
|
||||||
char path[PATH_MAX];
|
char path[PATH_MAX];
|
||||||
path[0] = '\0';
|
path[0] = '\0';
|
||||||
LOGD("resetprop: deleteprop [%s]\n", name);
|
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) {
|
void load_prop_file(const char *filename, bool trigger) {
|
||||||
if (init_resetprop()) return;
|
ENSURE_INIT();
|
||||||
LOGD("resetprop: Parse prop file [%s]\n", filename);
|
LOGD("resetprop: Parse prop file [%s]\n", filename);
|
||||||
parse_prop_file(filename, [=](auto key, auto val) -> bool {
|
parse_prop_file(filename, [=](auto key, auto val) -> bool {
|
||||||
setprop(key.data(), val.data(), trigger);
|
setprop(key.data(), val.data(), trigger);
|
||||||
|
@ -5,7 +5,6 @@
|
|||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include <magisk.h>
|
|
||||||
#include <daemon.h>
|
#include <daemon.h>
|
||||||
#include <utils.h>
|
#include <utils.h>
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@
|
|||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <pthread.h>
|
#include <pthread.h>
|
||||||
|
|
||||||
#include <magisk.h>
|
#include <logging.h>
|
||||||
|
|
||||||
#include "pts.h"
|
#include "pts.h"
|
||||||
|
|
||||||
|
@ -21,7 +21,6 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
#include <magisk.h>
|
|
||||||
#include <daemon.h>
|
#include <daemon.h>
|
||||||
#include <utils.h>
|
#include <utils.h>
|
||||||
#include <flags.h>
|
#include <flags.h>
|
||||||
@ -82,7 +81,7 @@ static void sighandler(int sig) {
|
|||||||
memset(&act, 0, sizeof(act));
|
memset(&act, 0, sizeof(act));
|
||||||
act.sa_handler = SIG_DFL;
|
act.sa_handler = SIG_DFL;
|
||||||
for (int i = 0; quit_signals[i]; ++i) {
|
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));
|
memset(&act, 0, sizeof(act));
|
||||||
act.sa_handler = handler;
|
act.sa_handler = handler;
|
||||||
for (int i = 0; quit_signals[i]; ++i) {
|
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 su_client_main(int argc, char *argv[]) {
|
||||||
int c;
|
int c;
|
||||||
struct option long_opts[] = {
|
struct option long_opts[] = {
|
||||||
{ "command", required_argument, NULL, 'c' },
|
{ "command", required_argument, nullptr, 'c' },
|
||||||
{ "help", no_argument, NULL, 'h' },
|
{ "help", no_argument, nullptr, 'h' },
|
||||||
{ "login", no_argument, NULL, 'l' },
|
{ "login", no_argument, nullptr, 'l' },
|
||||||
{ "preserve-environment", no_argument, NULL, 'p' },
|
{ "preserve-environment", no_argument, nullptr, 'p' },
|
||||||
{ "shell", required_argument, NULL, 's' },
|
{ "shell", required_argument, nullptr, 's' },
|
||||||
{ "version", no_argument, NULL, 'v' },
|
{ "version", no_argument, nullptr, 'v' },
|
||||||
{ "context", required_argument, NULL, 'z' },
|
{ "context", required_argument, nullptr, 'z' },
|
||||||
{ "mount-master", no_argument, NULL, 'M' },
|
{ "mount-master", no_argument, nullptr, 'M' },
|
||||||
{ NULL, 0, NULL, 0 },
|
{ nullptr, 0, nullptr, 0 },
|
||||||
};
|
};
|
||||||
|
|
||||||
su_request su_req;
|
su_request su_req;
|
||||||
@ -128,7 +127,7 @@ int su_client_main(int argc, char *argv[]) {
|
|||||||
strcpy(argv[i], "-M");
|
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) {
|
switch (c) {
|
||||||
case 'c':
|
case 'c':
|
||||||
su_req.command = concat_commands(argc, argv);
|
su_req.command = concat_commands(argc, argv);
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
|
||||||
#include "db.h"
|
#include <db.h>
|
||||||
|
|
||||||
#define DEFAULT_SHELL "/system/bin/sh"
|
#define DEFAULT_SHELL "/system/bin/sh"
|
||||||
|
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
#include <sys/wait.h>
|
#include <sys/wait.h>
|
||||||
#include <sys/mount.h>
|
#include <sys/mount.h>
|
||||||
|
|
||||||
#include <magisk.h>
|
#include <logging.h>
|
||||||
#include <daemon.h>
|
#include <daemon.h>
|
||||||
#include <utils.h>
|
#include <utils.h>
|
||||||
#include <selinux.h>
|
#include <selinux.h>
|
||||||
|
@ -11,7 +11,6 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <libgen.h>
|
#include <libgen.h>
|
||||||
|
|
||||||
#include <magisk.h>
|
|
||||||
#include <utils.h>
|
#include <utils.h>
|
||||||
#include <selinux.h>
|
#include <selinux.h>
|
||||||
|
|
||||||
|
@ -18,9 +18,7 @@
|
|||||||
#define SEPOL_PROC_DOMAIN "magisk"
|
#define SEPOL_PROC_DOMAIN "magisk"
|
||||||
#define SEPOL_FILE_DOMAIN "magisk_file"
|
#define SEPOL_FILE_DOMAIN "magisk_file"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
__BEGIN_DECLS
|
||||||
extern "C" {
|
|
||||||
#endif
|
|
||||||
|
|
||||||
extern void (*freecon)(char *con);
|
extern void (*freecon)(char *con);
|
||||||
extern int (*setcon)(const char *con);
|
extern int (*setcon)(const char *con);
|
||||||
@ -38,6 +36,4 @@ void dload_selinux();
|
|||||||
void restorecon();
|
void restorecon();
|
||||||
void restore_rootcon();
|
void restore_rootcon();
|
||||||
|
|
||||||
#ifdef __cplusplus
|
__END_DECLS
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
Loading…
Reference in New Issue
Block a user