11 #include "manager/pkginfo_manager.h"
12 #include "pkgmgr-info.h"
13 #include "pkgmgrinfo_debug.h"
14 #include "pkgmgrinfo_internal.h"
15 #include "pkgmgrinfo_private.h"
16 #include "pkgmgr_parser.h"
18 API int pkgmgrinfo_pkginfo_create_certinfo(pkgmgrinfo_certinfo_h *handle) {
19 retvm_if(handle == NULL, PMINFO_R_EINVAL,
20 "Argument supplied to hold return value is NULL\n");
21 pkgmgr_certinfo_x *certinfo = NULL;
22 certinfo = calloc(1, sizeof(pkgmgr_certinfo_x));
24 retvm_if(certinfo == NULL, PMINFO_R_ERROR, "Malloc Failed\n");
25 *handle = (void *)certinfo;
30 API int pkgmgrinfo_pkginfo_compare_usr_pkg_cert_info(
31 const char *lhs_package_id, const char *rhs_package_id, uid_t uid,
32 pkgmgrinfo_cert_compare_result_type_e *compare_result) {
33 if (lhs_package_id == NULL || rhs_package_id == NULL ||
34 compare_result == NULL) {
35 _LOGE("invalid parameter");
36 return PMINFO_R_EINVAL;
39 return _certinfo_compare_pkg_certinfo(lhs_package_id, rhs_package_id,
43 API int pkgmgrinfo_pkginfo_compare_pkg_cert_info(
44 const char *lhs_package_id, const char *rhs_package_id,
45 pkgmgrinfo_cert_compare_result_type_e *compare_result) {
46 return pkgmgrinfo_pkginfo_compare_usr_pkg_cert_info(
47 lhs_package_id, rhs_package_id, _getuid(), compare_result);
50 static int _pkginfo_get_pkgid_from_appid(uid_t uid, const char *appid,
54 query = sqlite3_mprintf(
55 "SELECT package FROM package_app_info WHERE app_id=%Q", appid);
57 _LOGE("Out of memory");
61 // TODO: need to use pkginfo-client APIs
67 API int pkgmgrinfo_pkginfo_compare_usr_app_cert_info(
68 const char *lhs_app_id, const char *rhs_app_id, uid_t uid,
69 pkgmgrinfo_cert_compare_result_type_e *compare_result) {
74 if (lhs_app_id == NULL || rhs_app_id == NULL || compare_result == NULL) {
75 _LOGE("invalid parameter");
76 return PMINFO_R_EINVAL;
79 ret = _pkginfo_get_pkgid_from_appid(uid, lhs_app_id, &l_pkgid);
80 if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
81 ret = _pkginfo_get_pkgid_from_appid(GLOBAL_USER, lhs_app_id, &l_pkgid);
83 if (ret != PMINFO_R_OK) return ret;
85 ret = _pkginfo_get_pkgid_from_appid(uid, rhs_app_id, &r_pkgid);
86 if (ret == PMINFO_R_ENOENT && uid != GLOBAL_USER)
87 ret = _pkginfo_get_pkgid_from_appid(GLOBAL_USER, rhs_app_id, &r_pkgid);
89 if (ret != PMINFO_R_OK) {
94 ret = pkgmgrinfo_pkginfo_compare_usr_pkg_cert_info(l_pkgid, r_pkgid, uid,
103 API int pkgmgrinfo_pkginfo_compare_app_cert_info(
104 const char *lhs_app_id, const char *rhs_app_id,
105 pkgmgrinfo_cert_compare_result_type_e *compare_result) {
106 return pkgmgrinfo_pkginfo_compare_usr_app_cert_info(
107 lhs_app_id, rhs_app_id, _getuid(), compare_result);
110 API int pkgmgrinfo_pkginfo_load_certinfo(const char *pkgid,
111 pkgmgrinfo_certinfo_h handle,
114 pkgmgr_certinfo_x *info = (pkgmgr_certinfo_x *)handle;
116 if (pkgid == NULL || handle == NULL) {
117 _LOGE("invalid parameter");
118 return PMINFO_R_EINVAL;
121 ret = _pkginfo_get_certinfo(pkgid, &info, uid);
122 if (ret != PMINFO_R_OK) _LOGE("failed to get certinfo of %s ", pkgid);
127 API int pkgmgrinfo_pkginfo_get_cert_value(pkgmgrinfo_certinfo_h handle,
128 pkgmgrinfo_cert_type cert_type,
129 const char **cert_value) {
130 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
131 retvm_if(cert_value == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
132 retvm_if(cert_type < PMINFO_AUTHOR_ROOT_CERT, PMINFO_R_EINVAL,
133 "Invalid certificate type\n");
134 retvm_if(cert_type > PMINFO_DISTRIBUTOR2_SIGNER_CERT, PMINFO_R_EINVAL,
135 "Invalid certificate type\n");
136 pkgmgr_certinfo_x *certinfo = NULL;
137 certinfo = (pkgmgr_certinfo_x *)handle;
138 if ((certinfo->cert_info)[cert_type])
139 *cert_value = (certinfo->cert_info)[cert_type];
145 API int pkgmgrinfo_pkginfo_destroy_certinfo(pkgmgrinfo_certinfo_h handle) {
146 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
148 pkgmgr_certinfo_x *certinfo = NULL;
149 certinfo = (pkgmgr_certinfo_x *)handle;
150 if (certinfo->pkgid) {
151 free(certinfo->pkgid);
152 certinfo->pkgid = NULL;
154 for (i = 0; i < MAX_CERT_TYPE; i++) {
155 if ((certinfo->cert_info)[i]) {
156 free((certinfo->cert_info)[i]);
157 (certinfo->cert_info)[i] = NULL;
165 API int pkgmgrinfo_create_certinfo_set_handle(
166 pkgmgrinfo_instcertinfo_h *handle) {
167 retvm_if(handle == NULL, PMINFO_R_EINVAL,
168 "Argument supplied to hold return value is NULL\n");
169 pkgmgr_certinfo_x *certinfo = NULL;
171 certinfo = calloc(1, sizeof(pkgmgr_certinfo_x));
172 retvm_if(certinfo == NULL, PMINFO_R_ERROR, "Malloc Failed\n");
173 *handle = (void *)certinfo;
177 API int pkgmgrinfo_set_cert_value(pkgmgrinfo_instcertinfo_h handle,
178 pkgmgrinfo_instcert_type cert_type,
180 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
181 retvm_if(cert_value == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
182 retvm_if(cert_type < PMINFO_SET_AUTHOR_ROOT_CERT, PMINFO_R_EINVAL,
183 "Invalid certificate type\n");
184 retvm_if(cert_type > PMINFO_SET_DISTRIBUTOR2_SIGNER_CERT, PMINFO_R_EINVAL,
185 "Invalid certificate type\n");
186 pkgmgr_certinfo_x *certinfo = NULL;
187 certinfo = (pkgmgr_certinfo_x *)handle;
188 if (certinfo->cert_info[cert_type]) free(certinfo->cert_info[cert_type]);
189 (certinfo->cert_info)[cert_type] = strdup(cert_value);
193 API int pkgmgrinfo_save_certinfo(const char *pkgid,
194 pkgmgrinfo_instcertinfo_h handle, uid_t uid) {
195 if (pkgid == NULL || handle == NULL) {
196 _LOGE("invalid parameter");
197 return PMINFO_R_EINVAL;
199 pkgmgr_certinfo_x *certinfo = (pkgmgr_certinfo_x *)handle;
200 return _pkginfo_insert_certinfo(pkgid, certinfo, uid);
203 API int pkgmgrinfo_destroy_certinfo_set_handle(
204 pkgmgrinfo_instcertinfo_h handle) {
205 retvm_if(handle == NULL, PMINFO_R_EINVAL, "Argument supplied is NULL\n");
207 pkgmgr_certinfo_x *certinfo = NULL;
208 certinfo = (pkgmgr_certinfo_x *)handle;
209 if (certinfo->pkgid) {
210 free(certinfo->pkgid);
211 certinfo->pkgid = NULL;
213 for (i = 0; i < MAX_CERT_TYPE; i++) {
214 if ((certinfo->cert_info)[i]) {
215 free((certinfo->cert_info)[i]);
216 (certinfo->cert_info)[i] = NULL;
224 API int pkgmgrinfo_delete_usr_certinfo(const char *pkgid, uid_t uid) {
226 _LOGE("invalid parameter");
227 return PMINFO_R_EINVAL;
230 return _pkginfo_delete_certinfo(pkgid);
233 API int pkgmgrinfo_delete_certinfo(const char *pkgid) {
234 return pkgmgrinfo_delete_usr_certinfo(pkgid, _getuid());