2018-06-12 22:34:05 +02:00
|
|
|
#ifndef DB_H
|
|
|
|
#define DB_H
|
|
|
|
|
|
|
|
#include <sqlite3.h>
|
2018-06-13 23:09:54 +02:00
|
|
|
#include <sys/stat.h>
|
2018-06-12 22:34:05 +02:00
|
|
|
|
|
|
|
/***************
|
|
|
|
* DB Settings *
|
|
|
|
***************/
|
|
|
|
|
2018-10-04 07:49:52 +02:00
|
|
|
#define DB_SETTING_KEYS \
|
|
|
|
((char *[]) { \
|
2018-06-12 22:34:05 +02:00
|
|
|
"root_access", \
|
|
|
|
"multiuser_mode", \
|
|
|
|
"mnt_ns" \
|
|
|
|
})
|
|
|
|
|
|
|
|
#define DB_SETTINGS_NUM (sizeof(DB_SETTING_KEYS) / sizeof(char*))
|
|
|
|
|
|
|
|
// Settings indices
|
|
|
|
enum {
|
|
|
|
ROOT_ACCESS = 0,
|
|
|
|
SU_MULTIUSER_MODE,
|
|
|
|
SU_MNT_NS
|
|
|
|
};
|
|
|
|
|
|
|
|
// 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
|
|
|
|
};
|
|
|
|
|
|
|
|
struct db_settings {
|
|
|
|
int v[DB_SETTINGS_NUM];
|
|
|
|
};
|
|
|
|
|
2018-10-04 07:49:52 +02:00
|
|
|
#define DEFAULT_DB_SETTINGS \
|
|
|
|
(struct db_settings) { .v = { \
|
2018-06-12 22:34:05 +02:00
|
|
|
ROOT_ACCESS_APPS_AND_ADB, \
|
|
|
|
MULTIUSER_MODE_OWNER_ONLY, \
|
2018-10-04 07:49:52 +02:00
|
|
|
NAMESPACE_MODE_REQUESTER, \
|
2018-06-12 22:34:05 +02:00
|
|
|
}}
|
|
|
|
|
|
|
|
/**************
|
|
|
|
* DB Strings *
|
|
|
|
**************/
|
|
|
|
|
2018-10-04 07:49:52 +02:00
|
|
|
#define DB_STRING_KEYS \
|
|
|
|
((char *[]) { \
|
|
|
|
"requester", \
|
2018-06-12 22:34:05 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
#define DB_STRING_NUM (sizeof(DB_STRING_KEYS) / sizeof(char*))
|
|
|
|
|
|
|
|
// Strings indices
|
|
|
|
enum {
|
2018-06-13 20:47:43 +02:00
|
|
|
SU_MANAGER = 0
|
2018-06-12 22:34:05 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
struct db_strings {
|
|
|
|
char s[DB_STRING_NUM][128];
|
|
|
|
};
|
|
|
|
|
|
|
|
/*************
|
|
|
|
* SU Access *
|
|
|
|
*************/
|
|
|
|
|
|
|
|
typedef enum {
|
|
|
|
QUERY = 0,
|
|
|
|
DENY = 1,
|
|
|
|
ALLOW = 2,
|
|
|
|
} policy_t;
|
|
|
|
|
|
|
|
struct su_access {
|
|
|
|
policy_t policy;
|
|
|
|
int log;
|
|
|
|
int notify;
|
|
|
|
};
|
|
|
|
|
|
|
|
#define DEFAULT_SU_ACCESS (struct su_access) { \
|
|
|
|
.policy = QUERY, \
|
|
|
|
.log = 1, \
|
|
|
|
.notify = 1 \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define SILENT_SU_ACCESS (struct su_access) { \
|
|
|
|
.policy = ALLOW, \
|
|
|
|
.log = 0, \
|
|
|
|
.notify = 0 \
|
|
|
|
}
|
|
|
|
|
|
|
|
#define NO_SU_ACCESS (struct su_access) { \
|
|
|
|
.policy = DENY, \
|
|
|
|
.log = 0, \
|
|
|
|
.notify = 0 \
|
|
|
|
}
|
|
|
|
|
|
|
|
/********************
|
|
|
|
* Public Functions *
|
|
|
|
********************/
|
|
|
|
|
|
|
|
sqlite3 *get_magiskdb();
|
|
|
|
int get_db_settings(sqlite3 *db, int key, struct db_settings *dbs);
|
|
|
|
int get_db_strings(sqlite3 *db, int key, struct db_strings *str);
|
|
|
|
int get_uid_policy(sqlite3 *db, int uid, struct su_access *su);
|
2018-10-27 23:54:48 +02:00
|
|
|
int validate_manager(char *alt_pkg, int userid, struct stat *st);
|
|
|
|
int exec_sql(const char *sql);
|
2018-06-12 22:34:05 +02:00
|
|
|
|
|
|
|
#endif //DB_H
|