pkgmgrinfo_cert_compare_result_type_e *result)
{
static const char query[] =
- "SELECT author_signer_cert FROM package_cert_info "
+ "SELECT COALESCE(author_signer_cert, -1) FROM package_cert_info "
"WHERE package=?";
int ret;
sqlite3_stmt *stmt;
const char *pkgid[2];
- int certid[2] = {-1, };
+ int certid[2] = {-1, -1};
int i;
+ pkgid[0] = l_pkgid;
+ pkgid[1] = r_pkgid;
+
ret = sqlite3_prepare_v2(db, query, strlen(query), &stmt, NULL);
if (ret != SQLITE_OK) {
_LOGE("prepare error: %s", sqlite3_errmsg(db));
return PMINFO_R_ERROR;
}
- pkgid[0] = l_pkgid;
- pkgid[1] = r_pkgid;
for (i = 0; i < 2; i++) {
ret = sqlite3_bind_text(stmt, 1, pkgid[i], -1, SQLITE_STATIC);
if (ret != SQLITE_OK) {
*result = PMINFO_CERT_COMPARE_MISMATCH;
sqlite3_finalize(stmt);
-
return PMINFO_R_OK;
}
{
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)) {
API int pkgmgrinfo_pkginfo_compare_pkg_cert_info(const char *lhs_package_id, const char *rhs_package_id, pkgmgrinfo_cert_compare_result_type_e *compare_result)
{
- return pkgmgrinfo_pkginfo_compare_usr_pkg_cert_info(lhs_package_id, rhs_package_id, GLOBAL_USER, compare_result);
+ return pkgmgrinfo_pkginfo_compare_usr_pkg_cert_info(lhs_package_id, rhs_package_id, _getuid(), compare_result);
}
static int _pkginfo_get_pkgid_from_appid(uid_t uid, const char *appid,
"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) {
_save_column_str(stmt, 0, pkgid);
ret = PMINFO_R_OK;
} else if (ret == SQLITE_DONE) {
- _LOGE("cannot find pkgid of app %s", appid);
+ _LOGI("cannot find pkgid of app %s for uid %d", appid, (int)uid);
ret = PMINFO_R_ENOENT;
} else {
_LOGE("step error: %s", sqlite3_errmsg(db));
pkgmgrinfo_cert_compare_result_type_e *compare_result)
{
return pkgmgrinfo_pkginfo_compare_usr_app_cert_info(lhs_app_id,
- rhs_app_id, GLOBAL_USER, compare_result);
+ rhs_app_id, _getuid(), compare_result);
}
static int _pkginfo_get_cert(sqlite3 *db, int cert_id[],
{
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) {
char *cert_info[])
{
static const char query_insert[] =
- "INSERT INTO package_cert_info (package,"
+ "INSERT INTO package_cert_info (package, package_count,"
" author_root_cert, author_im_cert, author_signer_cert,"
" dist_root_cert, dist_im_cert, dist_signer_cert,"
" dist2_root_cert, dist2_im_cert, dist2_signer_cert) "
- "VALUES(?, "
+ "VALUES(?, 1,"
" (SELECT cert_id FROM package_cert_index_info"
" WHERE cert_info=?),"
" (SELECT cert_id FROM package_cert_index_info"
" (SELECT cert_id FROM package_cert_index_info"
" WHERE cert_info=?))";
static const char query_update[] =
- "UPDATE package_cert_info SET "
- " author_root_cert= "
- " (SELECT cert_id FROM package_cert_index_info"
- " WHERE cert_info=?),"
- " author_im_cert= "
- " (SELECT cert_id FROM package_cert_index_info"
- " WHERE cert_info=?),"
- " author_signer_cert= "
- " (SELECT cert_id FROM package_cert_index_info"
- " WHERE cert_info=?),"
- " dist_root_cert= "
- " (SELECT cert_id FROM package_cert_index_info"
- " WHERE cert_info=?),"
- " dist_im_cert= "
- " (SELECT cert_id FROM package_cert_index_info"
- " WHERE cert_info=?),"
- " dist_signer_cert= "
- " (SELECT cert_id FROM package_cert_index_info"
- " WHERE cert_info=?),"
- " dist2_root_cert= "
- " (SELECT cert_id FROM package_cert_index_info"
- " WHERE cert_info=?),"
- "dist2_im_cert= "
- " (SELECT cert_id FROM package_cert_index_info"
- " WHERE cert_info=?),"
- "dist2_signer_cert= "
- " (SELECT cert_id FROM package_cert_index_info"
- " WHERE cert_info=?) "
+ "UPDATE package_cert_info "
+ "SET package_count = package_count + 1 "
"WHERE package=?";
int ret;
sqlite3_stmt *stmt;
_LOGE("prepare error: %s", sqlite3_errmsg(db));
return PMINFO_R_ERROR;
}
- idx = 1;
- for (i = 0; i < MAX_CERT_TYPE; i++) {
- if (sqlite3_bind_text(stmt, idx++, cert_info[i], -1,
- SQLITE_STATIC)) {
- _LOGE("bind error: %s", sqlite3_errmsg(db));
- sqlite3_finalize(stmt);
- return PMINFO_R_ERROR;
- }
- }
- sqlite3_bind_text(stmt, idx++, pkgid, -1, SQLITE_STATIC);
+ sqlite3_bind_text(stmt, 1, pkgid, -1, SQLITE_STATIC);
ret = sqlite3_step(stmt);
sqlite3_finalize(stmt);
}
{
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) {
sqlite3_close_v2(db);
return PMINFO_R_ERROR;
}
+
if (_pkginfo_save_cert_info(db, pkgid, info->cert_info)) {
_LOGE("failed to save cert info, rollback now");
sqlite3_exec(GET_DB(cert_db), "ROLLBACK", NULL, NULL, NULL);
static int _pkginfo_delete_certinfo(sqlite3 *db, const char *pkgid)
{
static const char query[] =
- "DELETE FROM package_cert_info WHERE package=?";
+ "UPDATE package_cert_info "
+ "SET package_count = package_count - 1 "
+ "WHERE package=?";
int ret;
sqlite3_stmt *stmt;
{
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) {
API int pkgmgrinfo_delete_certinfo(const char *pkgid)
{
- return pkgmgrinfo_delete_usr_certinfo(pkgid, GLOBAL_USER);
+ return pkgmgrinfo_delete_usr_certinfo(pkgid, _getuid());
}