API int pkgmgr_parser_initialize_db(uid_t uid)
{
int ret = -1;
+ char *db_path;
/*Manifest DB*/
ret = __initialize_db(pkgmgr_parser_db, QUERY_CREATE_TABLE_PACKAGE_INFO);
return ret;
}
- if (0 != __parserdb_change_perm(getUserPkgCertDBPathUID(GLOBAL_USER), GLOBAL_USER))
- _LOGD("Failed to change cert db permission\n");
+ db_path = getUserPkgCertDBPathUID(GLOBAL_USER);
+ if (db_path == NULL) {
+ _LOGD("Failed to get user cert db path - GLOBAL_USER");
+ } else {
+ ret = __parserdb_change_perm(db_path, GLOBAL_USER);
+ if (ret != 0)
+ _LOGD("Failed to change cert db permission");
+ free(db_path);
+ }
- if (0 != __parserdb_change_perm(getUserPkgParserDBPathUID(uid), uid))
- _LOGD("Failed to change parser db permission\n");
+ db_path = getUserPkgParserDBPathUID(uid);
+ if (db_path == NULL) {
+ _LOGD("Failed to get user pkg parser db path - %d", uid);
+ } else {
+ ret = __parserdb_change_perm(db_path, uid);
+ if (ret != 0)
+ _LOGD("Failed to change parser db permission\n");
+ free(db_path);
+ }
return 0;
}
API int pkgmgr_parser_create_and_initialize_db(uid_t uid)
{
int ret;
+ char *db_path;
if (getuid() != OWNER_ROOT) {
_LOGE("Only root user is allowed");
return -1;
}
- if (access(getUserPkgParserDBPathUID(uid), F_OK) != -1) {
+ db_path = getUserPkgParserDBPathUID(uid);
+ if (db_path == NULL) {
+ _LOGE("Failed to get pkg parser db path - %d", uid);
+ return -1;
+ }
+
+ if (access(db_path, F_OK) != -1) {
_LOGE("Manifest db for user %d is already exists", uid);
+ free(db_path);
+ return -1;
+ }
+ free(db_path);
+
+ db_path = getUserPkgCertDBPathUID(uid);
+ if (db_path == NULL) {
+ _LOGE("Failed to get pkg cert db path - %d", uid);
return -1;
}
- if (access(getUserPkgCertDBPathUID(uid), F_OK) != -1) {
+ if (access(db_path, F_OK) != -1) {
_LOGE("Cert db for user %d is already exists", uid);
+ free(db_path);
return -1;
}
+ free(db_path);
ret = pkgmgr_parser_check_and_create_db(uid);
if (ret < 0)
API int pkgmgr_parser_check_and_create_db(uid_t uid)
{
int ret = -1;
+ char *db_path;
+
+ db_path = getUserPkgParserDBPathUID(uid);
+ if (db_path == NULL) {
+ _LOGD("Failed to get pkg parser db path - %d", uid);
+ return -1;
+ }
+
/*Manifest DB*/
- ret = __pkgmgr_parser_create_db(&pkgmgr_parser_db, getUserPkgParserDBPathUID(uid));
+ ret = __pkgmgr_parser_create_db(&pkgmgr_parser_db, db_path);
if (ret) {
_LOGD("Manifest DB creation Failed\n");
+ free(db_path);
+ return -1;
+ }
+ free(db_path);
+
+ db_path = getUserPkgCertDBPathUID(GLOBAL_USER);
+ if (db_path == NULL) {
+ _LOGE("Failed to get pkg cert db path - GLOBAL_USER");
return -1;
}
/*Cert DB*/
- ret = __pkgmgr_parser_create_db(&pkgmgr_cert_db, getUserPkgCertDBPathUID(GLOBAL_USER));
+ ret = __pkgmgr_parser_create_db(&pkgmgr_cert_db, db_path);
if (ret) {
_LOGD("Cert DB creation Failed\n");
+ free(db_path);
return -1;
}
+
+ free(db_path);
+
return 0;
}
{
int ret;
sqlite3 *db;
- const char *dbpath;
+ char *dbpath;
if (lhs_package_id == NULL || rhs_package_id == NULL ||
compare_result == NULL) {
ret = sqlite3_open_v2(dbpath, &db, SQLITE_OPEN_READONLY, NULL);
if (ret != SQLITE_OK) {
_LOGE("failed to open db: %d", ret);
+ free(dbpath);
return PMINFO_R_ERROR;
}
+ free(dbpath);
if (_pkginfo_compare_certinfo(db, lhs_package_id, rhs_package_id,
compare_result)) {
"SELECT package FROM package_app_info WHERE app_id=?";
int ret;
sqlite3 *db;
- const char *dbpath;
+ char *dbpath;
sqlite3_stmt *stmt;
dbpath = getUserPkgParserDBPathUID(uid);
ret = sqlite3_open_v2(dbpath, &db, SQLITE_OPEN_READONLY, NULL);
if (ret != SQLITE_OK) {
_LOGE("failed to open db: %d", ret);
+ free(dbpath);
return PMINFO_R_ERROR;
}
+ free(dbpath);
ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
if (ret != SQLITE_OK) {
{
int ret;
sqlite3 *db;
- const char *dbpath;
+ char *dbpath;
/* open unified global cert db */
dbpath = getUserPkgCertDBPathUID(GLOBAL_USER);
ret = sqlite3_open_v2(dbpath, &db, SQLITE_OPEN_READONLY, NULL);
if (ret != SQLITE_OK) {
_LOGE("failed to open db: %d", ret);
+ free(dbpath);
return PMINFO_R_ERROR;
}
+ free(dbpath);
ret = _pkginfo_get_certid(db, pkgid, info->cert_id);
if (ret != PMINFO_R_OK) {
{
int ret;
sqlite3 *db;
- const char *dbpath;
+ char *dbpath;
pkgmgr_instcertinfo_x *info = (pkgmgr_instcertinfo_x *)handle;
if (pkgid == NULL || handle == NULL) {
ret = sqlite3_open_v2(dbpath, &db, SQLITE_OPEN_READWRITE, NULL);
if (ret != SQLITE_OK) {
_LOGE("failed to open db: %d", ret);
+ free(dbpath);
return PMINFO_R_ERROR;
}
+ free(dbpath);
ret = sqlite3_exec(db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
if (ret != SQLITE_OK) {
{
int ret;
sqlite3 *db;
- const char *dbpath;
+ char *dbpath;
if (pkgid == NULL) {
_LOGE("invalid parameter");
ret = sqlite3_open_v2(dbpath, &db, SQLITE_OPEN_READWRITE, NULL);
if (ret != SQLITE_OK) {
_LOGE("failed to open db: %d", ret);
+ free(dbpath);
return PMINFO_R_ERROR;
}
+ free(dbpath);
ret = sqlite3_exec(db, "BEGIN EXCLUSIVE", NULL, NULL, NULL);
if (ret != SQLITE_OK) {
return 0;
}
-static const char *_get_db_path(uid_t uid)
+static char *_get_db_path(uid_t uid)
{
- const char *db_path = NULL;
- if (uid != GLOBAL_USER && uid != ROOT_UID) {
- tzplatform_set_user(uid);
- db_path = tzplatform_getenv(TZ_USER_DB);
- tzplatform_reset_user();
- } else {
- db_path = tzplatform_getenv(TZ_SYS_DB);
+ const char *db_path;
+ char path[PATH_MAX];
+
+ db_path = tzplatform_getenv(TZ_SYS_DB);
+ if (db_path == NULL) {
+ _LOGE("Failed to get TZ_SYS_DB path");
+ return NULL;
}
- return db_path;
+
+ if (uid == GLOBAL_USER || uid == ROOT_UID)
+ return strdup(db_path);
+
+ snprintf(path, sizeof(path), "%s/user/%d", db_path, uid);
+
+ return strdup(path);
}
static int __attach_and_create_view(sqlite3 *handle, const char *db, const char *tables[], uid_t uid)
return path;
}
-API const char *getUserPkgParserDBPath(void)
+API char *getUserPkgParserDBPath(void)
{
return getUserPkgParserDBPathUID(_getuid());
}
-API const char *getUserPkgParserDBPathUID(uid_t uid)
+API char *getUserPkgParserDBPathUID(uid_t uid)
{
- const char *pkgmgr_parser_db = NULL;
+ char pkgmgr_parser_db[PATH_MAX];
uid_t uid_caller = getuid();
gid_t gid = ROOT_UID;
+ char *db_path;
+
+ db_path = _get_db_path(uid);
+ if (db_path == NULL) {
+ _LOGE("Failed to get db path %d", uid);
+ return NULL;
+ }
+ snprintf(pkgmgr_parser_db, sizeof(pkgmgr_parser_db),
+ "%s/.pkgmgr_parser.db", db_path);
if (uid != GLOBAL_USER && uid != ROOT_UID) {
tzplatform_set_user(uid);
- pkgmgr_parser_db = tzplatform_mkpath(TZ_USER_DB, ".pkgmgr_parser.db");
gid = _get_gid(tzplatform_getenv(TZ_SYS_USER_GROUP));
tzplatform_reset_user();
- } else {
- pkgmgr_parser_db = tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_parser.db");
}
- /* just allow certain users to create the dbspace directory if needed. */
- if (uid_caller == ROOT_UID || uid_caller == uid) {
- const char *db_path = _get_db_path(uid);
+ // just allow certain users to create the dbspace directory if needed.
+ if (uid_caller == ROOT_UID || uid_caller == uid)
_mkdir_for_user(db_path, uid, gid);
- }
- return pkgmgr_parser_db;
+ free(db_path);
+
+ return strdup(pkgmgr_parser_db);
}
-API const char *getUserPkgCertDBPath(void)
+API char *getUserPkgCertDBPath(void)
{
return getUserPkgCertDBPathUID(_getuid());
}
-API const char *getUserPkgCertDBPathUID(uid_t uid)
+API char *getUserPkgCertDBPathUID(uid_t uid)
{
- const char *pkgmgr_cert_db = NULL;
+ char pkgmgr_cert_db[PATH_MAX];
uid_t uid_caller = getuid();
gid_t gid = ROOT_UID;
+ char *db_path;
+
+ db_path = _get_db_path(uid);
+ if (db_path == NULL) {
+ _LOGE("Failed to get db path %d", uid);
+ return NULL;
+ }
+ snprintf(pkgmgr_cert_db, sizeof(pkgmgr_cert_db),
+ "%s/.pkgmgr_cert.db", db_path);
if (uid != GLOBAL_USER && uid != ROOT_UID) {
tzplatform_set_user(uid);
- pkgmgr_cert_db = tzplatform_mkpath(TZ_USER_DB, ".pkgmgr_cert.db");
gid = _get_gid(tzplatform_getenv(TZ_SYS_USER_GROUP));
tzplatform_reset_user();
- } else {
- pkgmgr_cert_db = tzplatform_mkpath(TZ_SYS_DB, ".pkgmgr_cert.db");
}
- /* just allow certain users to create the dbspace directory if needed. */
- if (uid_caller == ROOT_UID || uid_caller == uid) {
- const char *db_path = _get_db_path(uid);
+ // just allow certain users to create the dbspace directory if needed.
+ if (uid_caller == ROOT_UID || uid_caller == uid)
_mkdir_for_user(db_path, uid, gid);
- }
- return pkgmgr_cert_db;
+ free(db_path);
+
+ return strdup(pkgmgr_cert_db);
}
API const char *getUserManifestPath(uid_t uid, bool readonly)
int __open_manifest_db(uid_t uid, bool readonly)
{
int ret;
- const char *user_pkg_parser;
+ char *user_pkg_parser;
int flags;
if (manifest_db.ref) {
}
user_pkg_parser = getUserPkgParserDBPathUID(uid);
+ if (user_pkg_parser == NULL) {
+ _LOGE("Failed to get pkg parser db path - %d", uid);
+ return -1;
+ }
+
if (access(user_pkg_parser, F_OK) != 0) {
_LOGE("Manifest DB does not exists !!");
+ free(user_pkg_parser);
return -1;
}
flags = readonly ? SQLITE_OPEN_READONLY : SQLITE_OPEN_READWRITE;
ret = db_util_open_with_options(user_pkg_parser, &GET_DB(manifest_db),
flags, NULL);
- retvm_if(ret != SQLITE_OK, -1, "connect db [%s] failed!\n",
- user_pkg_parser);
+ if (ret != SQLITE_OK) {
+ _LOGE("connect db [%s] failed!\n", user_pkg_parser);
+ free(user_pkg_parser);
+ return -1;
+ }
+
manifest_db.ref++;
if (readonly) {
ret = __attach_and_create_view(GET_DB(manifest_db), MANIFEST_DB,
parserdb_tables, uid);
- retvm_if(ret != SQLITE_OK, -1, "attach db [%s] failed!\n",
- user_pkg_parser);
+ if (ret != SQLITE_OK) {
+ _LOGE("attach db [%s] failed!\n", user_pkg_parser);
+ free(user_pkg_parser);
+ return -1;
+ }
}
+
+ free(user_pkg_parser);
+
return 0;
}
int __open_cert_db(uid_t uid, bool readonly)
{
int ret;
- const char *user_cert_parser;
+ char *user_cert_parser;
int flags;
if (cert_db.ref) {
}
user_cert_parser = getUserPkgCertDBPathUID(uid);
+ if (user_cert_parser == NULL) {
+ _LOGE("Failed to get pkg cert db path - %d", uid);
+ return -1;
+ }
+
if (access(user_cert_parser, F_OK) != 0) {
_LOGE("Cert DB does not exists !!");
+ free(user_cert_parser);
return -1;
}
flags = readonly ? SQLITE_OPEN_READONLY : SQLITE_OPEN_READWRITE;
ret = db_util_open_with_options(user_cert_parser, &GET_DB(cert_db),
flags, NULL);
- retvm_if(ret != SQLITE_OK, -1, "connect db [%s] failed!",
- user_cert_parser);
+ if (ret != SQLITE_OK) {
+ _LOGE("connect db [%s] failed!", user_cert_parser);
+ free(user_cert_parser);
+ return -1;
+ }
cert_db.ref++;
if (readonly) {
ret = __attach_and_create_view(GET_DB(cert_db), CERT_DB,
certdb_tables, uid);
- retvm_if(ret != SQLITE_OK, -1, "attach db [%s] failed!",
- user_cert_parser);
+ if (ret != SQLITE_OK) {
+ _LOGE("attach db [%s] failed!", user_cert_parser);
+ free(user_cert_parser);
+ return -1;
+ }
}
+
+ free(user_cert_parser);
+
return 0;
}
/* Open db.*/
ret = __open_manifest_db(uid, false);
if (ret != SQLITE_OK) {
- _LOGE("connect db [%s] failed!\n", getUserPkgParserDBPathUID(uid));
+ _LOGE("connect db [%d] failed!\n", uid);
return PMINFO_R_ERROR;
}
char query[MAX_QUERY_LEN] = {'\0'};
char *errmsg;
sqlite3 *pkgmgr_parser_db;
+ char *db_path;
retvm_if(handle == NULL, PMINFO_R_EINVAL, "appinfo handle is NULL\n");
pkgmgr_appinfo_x *info = (pkgmgr_appinfo_x *)handle;
val = info->app_info->guestmode_visibility;
if (val) {
- ret = db_util_open_with_options(getUserPkgParserDBPathUID(uid), &pkgmgr_parser_db,
+ db_path = getUserPkgParserDBPathUID(uid);
+ if (db_path == NULL) {
+ _LOGE("Failed to get pkg parser db path - %d", uid);
+ return PMINFO_R_ERROR;
+ }
+
+ ret = db_util_open_with_options(db_path, &pkgmgr_parser_db,
SQLITE_OPEN_READWRITE, NULL);
if (ret != SQLITE_OK) {
_LOGE("DB Open Failed\n");
+ free(db_path);
return PMINFO_R_ERROR;
}
+ free(db_path);
/*TODO: Write to DB here*/
if (status == true)
int ret = -1;
sqlite3 *pkgmgr_parser_db = NULL;
char *query = NULL;
+ char *db_path;
- ret = db_util_open_with_options(getUserPkgParserDBPathUID(uid), &pkgmgr_parser_db,
+ db_path = getUserPkgParserDBPathUID(uid);
+ if (db_path == NULL) {
+ _LOGE("Failed to get pkg parser db path - %d", uid);
+ return PMINFO_R_ERROR;
+ }
+
+ ret = db_util_open_with_options(db_path, &pkgmgr_parser_db,
SQLITE_OPEN_READWRITE, NULL);
- retvm_if(ret != SQLITE_OK, PMINFO_R_ERROR, "connect db failed!");
+ if (ret != SQLITE_OK) {
+ _LOGE("connect db failed!");
+ free(db_path);
+ return PMINFO_R_ERROR;
+ }
+ free(db_path);
/*Begin transaction*/
/* Setting Manifest DB */