2018-06-12 20:34:05 +00:00
|
|
|
#ifndef DB_H
|
|
|
|
#define DB_H
|
|
|
|
|
|
|
|
#include <sqlite3.h>
|
2018-06-13 21:09:54 +00:00
|
|
|
#include <sys/stat.h>
|
2018-06-12 20:34:05 +00:00
|
|
|
|
|
|
|
/***************
|
|
|
|
* DB Settings *
|
|
|
|
***************/
|
|
|
|
|
2018-10-04 05:49:52 +00:00
|
|
|
#define DB_SETTING_KEYS \
|
2018-11-01 17:23:12 +00:00
|
|
|
((const char *[]) { \
|
2018-06-12 20:34:05 +00:00
|
|
|
"root_access", \
|
|
|
|
"multiuser_mode", \
|
2018-11-16 06:15:34 +00:00
|
|
|
"mnt_ns", \
|
|
|
|
"magiskhide", \
|
2018-06-12 20:34:05 +00:00
|
|
|
})
|
|
|
|
|
2018-11-16 06:15:34 +00:00
|
|
|
#define DB_SETTINGS_NUM 4
|
2018-06-12 20:34:05 +00:00
|
|
|
|
2018-11-04 23:24:08 +00:00
|
|
|
// Settings keys
|
2018-06-12 20:34:05 +00:00
|
|
|
enum {
|
|
|
|
ROOT_ACCESS = 0,
|
|
|
|
SU_MULTIUSER_MODE,
|
2018-11-16 06:15:34 +00:00
|
|
|
SU_MNT_NS,
|
|
|
|
HIDE_CONFIG
|
2018-06-12 20:34:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// Values for root_access
|
|
|
|
enum {
|
|
|
|
ROOT_ACCESS_DISABLED = 0,
|
|
|
|
ROOT_ACCESS_APPS_ONLY,
|
|
|
|
ROOT_ACCESS_ADB_ONLY,
|
|
|
|
ROOT_ACCESS_APPS_AND_ADB
|
|
|
|
};
|
|
|
|
|
|
|
|
// Values for multiuser_mode
|
|
|
|
enum {
|
|
|
|
MULTIUSER_MODE_OWNER_ONLY = 0,
|
|
|
|
MULTIUSER_MODE_OWNER_MANAGED,
|
|
|
|
MULTIUSER_MODE_USER
|
|
|
|
};
|
|
|
|
|
|
|
|
// Values for mnt_ns
|
|
|
|
enum {
|
|
|
|
NAMESPACE_MODE_GLOBAL = 0,
|
|
|
|
NAMESPACE_MODE_REQUESTER,
|
|
|
|
NAMESPACE_MODE_ISOLATE
|
|
|
|
};
|
|
|
|
|
2018-11-04 23:24:08 +00:00
|
|
|
class db_settings {
|
|
|
|
public:
|
|
|
|
db_settings();
|
|
|
|
int& operator [](const char *);
|
|
|
|
const int& operator [](const char *) const;
|
|
|
|
int& operator [](const int);
|
|
|
|
const int& operator [](const int) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
int data[DB_SETTINGS_NUM + 1];
|
|
|
|
int getKeyIdx(const char *) const;
|
2018-06-12 20:34:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**************
|
|
|
|
* DB Strings *
|
|
|
|
**************/
|
|
|
|
|
2018-10-04 05:49:52 +00:00
|
|
|
#define DB_STRING_KEYS \
|
2018-11-01 17:23:12 +00:00
|
|
|
((const char *[]) { \
|
2018-10-04 05:49:52 +00:00
|
|
|
"requester", \
|
2018-06-12 20:34:05 +00:00
|
|
|
})
|
|
|
|
|
2018-11-04 08:38:06 +00:00
|
|
|
#define DB_STRING_NUM 1
|
2018-06-12 20:34:05 +00:00
|
|
|
|
2018-11-04 23:24:08 +00:00
|
|
|
// Strings keys
|
2018-06-12 20:34:05 +00:00
|
|
|
enum {
|
2018-06-13 18:47:43 +00:00
|
|
|
SU_MANAGER = 0
|
2018-06-12 20:34:05 +00:00
|
|
|
};
|
|
|
|
|
2018-11-04 23:24:08 +00:00
|
|
|
class db_strings {
|
|
|
|
public:
|
|
|
|
db_strings();
|
|
|
|
char * operator [](const char *);
|
|
|
|
const char * operator [](const char *) const;
|
|
|
|
char * operator [](const int);
|
|
|
|
const char * operator [](const int) const;
|
|
|
|
|
|
|
|
private:
|
|
|
|
char data[DB_STRING_NUM + 1][128];
|
|
|
|
int getKeyIdx(const char *) const;
|
2018-06-12 20:34:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*************
|
|
|
|
* SU Access *
|
|
|
|
*************/
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
QUERY = 0,
|
|
|
|
DENY = 1,
|
|
|
|
ALLOW = 2,
|
|
|
|
} policy_t;
|
|
|
|
|
|
|
|
struct su_access {
|
|
|
|
policy_t policy;
|
|
|
|
int log;
|
|
|
|
int notify;
|
|
|
|
};
|
|
|
|
|
2018-11-04 08:38:06 +00:00
|
|
|
#define DEFAULT_SU_ACCESS (su_access) { \
|
2018-06-12 20:34:05 +00:00
|
|
|
.policy = QUERY, \
|
|
|
|
.log = 1, \
|
|
|
|
.notify = 1 \
|
|
|
|
}
|
|
|
|
|
2018-11-04 08:38:06 +00:00
|
|
|
#define SILENT_SU_ACCESS (su_access) { \
|
2018-06-12 20:34:05 +00:00
|
|
|
.policy = ALLOW, \
|
|
|
|
.log = 0, \
|
|
|
|
.notify = 0 \
|
|
|
|
}
|
|
|
|
|
2018-11-04 08:38:06 +00:00
|
|
|
#define NO_SU_ACCESS (su_access) { \
|
2018-06-12 20:34:05 +00:00
|
|
|
.policy = DENY, \
|
|
|
|
.log = 0, \
|
|
|
|
.notify = 0 \
|
|
|
|
}
|
|
|
|
|
|
|
|
/********************
|
|
|
|
* Public Functions *
|
|
|
|
********************/
|
|
|
|
|
|
|
|
sqlite3 *get_magiskdb();
|
2018-11-16 06:15:34 +00:00
|
|
|
int get_db_settings(sqlite3 *db, db_settings *dbs, int key = -1);
|
|
|
|
int get_db_strings(sqlite3 *db, db_strings *str, int key = -1);
|
2018-06-12 20:34:05 +00:00
|
|
|
int get_uid_policy(sqlite3 *db, int uid, struct su_access *su);
|
2018-10-27 21:54:48 +00:00
|
|
|
int validate_manager(char *alt_pkg, int userid, struct stat *st);
|
|
|
|
int exec_sql(const char *sql);
|
2018-06-12 20:34:05 +00:00
|
|
|
|
|
|
|
#endif //DB_H
|