#include <sys/stat.h>
#include <linux/limits.h>
+#include <glib.h>
+
#include <pkgmgr_parser.h>
#include <tzplatform_config.h>
return 0;
}
-static int _install_ug(char *manifest)
+static void _application_cb(gpointer data, gpointer user_data)
{
- manifest_x *mfx;
- application_x *tmp;
int ret;
+ application_x *app = (application_x *)data;
+ package_x *pkg = (package_x *)user_data;
- mfx = pkgmgr_parser_process_manifest_xml(manifest);
- if (mfx == NULL) {
- printf("Parse manifest failed\n");
- return -1;
- }
+ if (app->exec == NULL || app->ui_gadget == NULL ||
+ strcasecmp(app->ui_gadget, "true") != 0)
+ return;
- for (tmp = mfx->application; tmp; tmp = tmp->next) {
- if (tmp->exec == NULL || tmp->ui_gadget == NULL ||
- strcasecmp(tmp->ui_gadget, "true") != 0)
- continue;
+ if (_check_bin_directory(pkg->package))
+ return;
- if (_check_bin_directory(mfx->package))
- continue;
+ ret = symlink(UG_CLIENT, app->exec);
+ if (ret != 0)
+ printf("failed to install ug %s: %s\n", app->exec,
+ strerror(errno));
+}
- ret = symlink(UG_CLIENT, tmp->exec);
- if (ret != 0)
- printf("failed to install ug %s: %s\n", tmp->exec,
- strerror(errno));
+static int _install_ug(char *manifest)
+{
+ package_x *pkg;
+
+ pkg = pkgmgr_parser_process_manifest_xml(manifest);
+ if (pkg == NULL) {
+ printf("Parse manifest failed\n");
+ return -1;
}
- pkgmgr_parser_free_manifest_xml(mfx);
+ g_list_foreach(pkg->application, _application_cb, pkg);
+ pkgmgr_parser_free_manifest_xml(pkg);
return 0;
}
int main(int argc, char *argv[])
{
- int ret;
-
if (getuid() != OWNER_ROOT && getuid() != GLOBAL_USER) {
printf("Only root or tizenglobalapp user is allowed\n");
return -1;
return -1;
}
- ret = _install_ug(argv[1]);
-
- return ret;
+ return _install_ug(argv[1]);
}
#include <sys/types.h>
#include <linux/limits.h>
+#include <glib.h>
+
#include <tzplatform_config.h>
#include <security-manager.h>
#include <pkgmgr_parser.h>
#define OWNER_ROOT 0
#define GLOBAL_USER tzplatform_getuid(TZ_SYS_GLOBALAPP_USER)
-static const char *_get_pkg_root_path(const char *pkgid, uid_t uid)
+static const char *_get_pkg_root_path(const char *pkgid)
{
const char *path;
+ uid_t uid = getuid();
tzplatform_set_user(uid);
path = tzplatform_mkpath((uid == OWNER_ROOT || uid == GLOBAL_USER) ?
{NULL, SECURITY_MANAGER_ENUM_END}
};
-static app_inst_req *_prepare_request(const char *pkgid, const char *appid,
- uid_t uid)
+static app_inst_req *_prepare_request(const char *pkgid, const char *appid)
{
int ret;
app_inst_req *req;
return NULL;
}
- root_path = _get_pkg_root_path(pkgid, uid);
+ root_path = _get_pkg_root_path(pkgid);
/* TODO: should be fixed */
if (access(root_path, F_OK) == -1) {
printf("cannot find %s, but the smack rule for %s "
return req;
}
+static void _insert_privilege_cb(gpointer data, gpointer user_data)
+{
+ const char *privilege = (const char *)data;
+ app_inst_req *req = (app_inst_req *)user_data;
+
+ security_manager_app_inst_req_add_privilege(req, privilege);
+}
+
/* NOTE: We cannot use cert-svc api which checks signature level in this tool,
* because cert-svc does not provide c apis in Tizen 3.0.
* So we set default privilege as platform level temporarily.
#define DEFAULT_PRIVILEGE_PUBLIC "http://tizen.org/privilege/internal/default/public"
#define DEFAULT_PRIVILEGE_PARTNER "http://tizen.org/privilege/internal/default/partner"
#define DEFAULT_PRIVILEGE_PLATFORM "http://tizen.org/privilege/internal/default/platform"
-static int _insert_privilege(char *manifest, uid_t uid)
+static void _insert_application_cb(gpointer data, gpointer user_data)
{
int ret;
app_inst_req *req;
- manifest_x *mfx;
- privilege_x *priv;
- struct application_x *app;
+ application_x *app = (application_x *)data;
+ package_x *pkg = (package_x *)user_data;
- mfx = pkgmgr_parser_process_manifest_xml(manifest);
- if (mfx == NULL) {
- printf("Parse manifest failed\n");
- return -1;
+ req = _prepare_request(pkg->package, app->appid);
+ if (req == NULL) {
+ printf("out of memory\n");
+ return;
}
- app = mfx->application;
- while (app) {
- req = _prepare_request(mfx->package, app->appid, uid);
- if (req == NULL) {
- pkgmgr_parser_free_manifest_xml(mfx);
- return -1;
- }
- if (mfx->privileges != NULL) {
- for (priv = mfx->privileges->privilege; priv;
- priv = priv->next)
- security_manager_app_inst_req_add_privilege(req,
- priv->text);
- }
+ if (getuid() == OWNER_ROOT) {
+ security_manager_app_inst_req_add_privilege(req,
+ DEFAULT_PRIVILEGE_PUBLIC);
+ security_manager_app_inst_req_add_privilege(req,
+ DEFAULT_PRIVILEGE_PARTNER);
+ security_manager_app_inst_req_add_privilege(req,
+ DEFAULT_PRIVILEGE_PLATFORM);
+ }
- if (getuid() == OWNER_ROOT) {
- security_manager_app_inst_req_add_privilege(req,
- DEFAULT_PRIVILEGE_PUBLIC);
- security_manager_app_inst_req_add_privilege(req,
- DEFAULT_PRIVILEGE_PARTNER);
- security_manager_app_inst_req_add_privilege(req,
- DEFAULT_PRIVILEGE_PLATFORM);
- }
+ g_list_foreach(pkg->privileges, _insert_privilege_cb, (gpointer)req);
- ret = security_manager_app_install(req);
- if (ret != SECURITY_MANAGER_SUCCESS)
- printf("app install failed: %d\n", ret);
- security_manager_app_inst_req_free(req);
- app = app->next;
+ ret = security_manager_app_install(req);
+ if (ret != SECURITY_MANAGER_SUCCESS)
+ printf("app install failed: %d\n", ret);
+ security_manager_app_inst_req_free(req);
+}
+
+static int _insert_privilege(char *manifest)
+{
+ package_x *pkg;
+
+ pkg = pkgmgr_parser_process_manifest_xml(manifest);
+ if (pkg == NULL) {
+ printf("Parse manifest failed\n");
+ return -1;
}
- pkgmgr_parser_free_manifest_xml(mfx);
+ g_list_foreach(pkg->application, _insert_application_cb, (gpointer)pkg);
+ pkgmgr_parser_free_manifest_xml(pkg);
return 0;
}
-static int _remove_privilege(char *manifest, uid_t uid)
+static void _remove_application_cb(gpointer data, gpointer user_data)
{
int ret;
app_inst_req *req;
- manifest_x *mfx;
- struct application_x *app;
+ application_x *app = (application_x *)data;
+ package_x *pkg = (package_x *)user_data;
- mfx = pkgmgr_parser_process_manifest_xml(manifest);
- if (mfx == NULL) {
- printf("Parse manifest failed\n");
- return -1;
+ req = _prepare_request(pkg->package, app->appid);
+ if (req == NULL) {
+ printf("out of memory\n");
+ return;
}
- app = mfx->application;
- while (app) {
- req = _prepare_request(mfx->package, app->appid, uid);
- if (req == NULL) {
- pkgmgr_parser_free_manifest_xml(mfx);
- return -1;
- }
+ ret = security_manager_app_uninstall(req);
+ if (ret != SECURITY_MANAGER_SUCCESS)
+ printf("app uninstall failed: %d\n", ret);
- ret = security_manager_app_uninstall(req);
- if (ret != SECURITY_MANAGER_SUCCESS)
- printf("app uninstall failed: %d\n", ret);
+ security_manager_app_inst_req_free(req);
+}
- security_manager_app_inst_req_free(req);
- app = app->next;
+static int _remove_privilege(char *manifest)
+{
+ package_x *pkg;
+
+ pkg = pkgmgr_parser_process_manifest_xml(manifest);
+ if (pkg == NULL) {
+ printf("Parse manifest failed\n");
+ return -1;
}
- pkgmgr_parser_free_manifest_xml(mfx);
+ g_list_foreach(pkg->application, _remove_application_cb, (gpointer)pkg);
+ pkgmgr_parser_free_manifest_xml(pkg);
return 0;
}
}
if (!strcmp(argv[1], "-i")) {
- ret = _insert_privilege(argv[2], getuid());
+ ret = _insert_privilege(argv[2]);
} else if (!strcmp(argv[1], "-u")) {
- ret = _remove_privilege(argv[2], getuid());
+ ret = _remove_privilege(argv[2]);
} else {
_print_usage(argv[0]);
ret = -1;