4 #include <gum/gum-user.h>
5 #include <gum/common/gum-user-types.h>
8 #include <tzplatform_config.h>
9 #include <pkgmgr-info.h>
11 #include "pkgmgr-server.h"
14 #define RETRY_WAIT_USEC (1000000 / 2) /* 0.5 sec */
16 struct manifest_and_type {
21 struct manifest_and_type type_map[] = {
22 { "res/wgt/config.xml", "wgt" },
23 { "config.xml", "wgt" },
24 { "tizen-manifest.xml", "tpk" },
28 static const char legacy_content_path[] = "/opt/usr/media";
30 const char *_get_pkgtype_from_file(const char *file_path)
32 const char *type = NULL;
36 uf = unzOpen(file_path);
38 ERR("failed to open zip file %s", file_path);
42 for (i = 0; type_map[i].manifest != NULL; i++) {
43 if (unzLocateFile(uf, type_map[i].manifest, 0) == UNZ_OK) {
44 DBG("pkgtype of %s: [%s]", file_path, type_map[i].type);
45 type = type_map[i].type;
55 char *_get_pkgtype_from_pkgid(const char *pkgid, uid_t uid)
59 pkgmgrinfo_pkginfo_h info;
62 ret = pkgmgrinfo_pkginfo_get_usr_all_pkginfo(pkgid, uid, &info);
63 if (ret != PMINFO_R_OK)
66 ret = pkgmgrinfo_pkginfo_get_type(info, &pkgtype);
67 if (ret != PMINFO_R_OK) {
68 pkgmgrinfo_pkginfo_destroy_pkginfo(info);
72 DBG("pkgtype of %s: [%s]", pkgid, pkgtype);
74 type = strdup(pkgtype);
75 pkgmgrinfo_pkginfo_destroy_pkginfo(info);
80 const char *_get_adjusted_pkgpath(const char *org_file_path, uid_t caller_uid)
82 const char *file_path;
84 if (caller_uid >= REGULAR_USER &&
85 strstr(org_file_path, legacy_content_path) == org_file_path) {
86 DBG("legacy media path!");
87 tzplatform_set_user(caller_uid);
88 file_path = tzplatform_mkpath(TZ_USER_CONTENT,
89 org_file_path + strlen(legacy_content_path));
90 tzplatform_reset_user();
92 file_path = org_file_path;
98 int __is_admin_user(uid_t uid)
101 GumUserType ut = GUM_USERTYPE_NONE;
105 guser = gum_user_get_sync(uid, FALSE);
107 ERR("cannot get user information from gumd, retry");
109 usleep(RETRY_WAIT_USEC);
113 } while (retry_cnt <= RETRY_MAX);
116 ERR("cannot get user information from gumd, failed");
120 g_object_get(G_OBJECT(guser), "usertype", &ut, NULL);
121 if (ut == GUM_USERTYPE_NONE) {
122 ERR("cannot get user type");
123 g_object_unref(guser);
125 } else if (ut != GUM_USERTYPE_ADMIN) {
126 g_object_unref(guser);
130 g_object_unref(guser);