remove CAP_MAC_OVERRIDE from app2sd-server
[platform/core/appfw/app2sd.git] / plugin / app2sd / src / app2sd_server.c
index 4cfea99..7744c43 100644 (file)
  *
  */
 
-#include <app2sd_internals.h>
-#include <app2sd_interface.h>
-#include <glib.h>
 #include <gio/gio.h>
 
+#include "app2sd_internals.h"
+
 GMainLoop *app2sd_mainloop = NULL;
 
 gboolean __exit_app2sd_server(void *data)
@@ -101,9 +100,8 @@ static int __app2sd_get_sender_uid(GDBusConnection *conn,
 
        uid = __app2sd_get_sender_unixinfo(conn, sender_name,
                "GetConnectionUnixUser");
-       if (uid < 0) {
+       if (uid < 0)
                _E("failed to get uid");
-       }
 
        _D("sender_name(%s), uid(%d)", sender_name, uid);
 
@@ -160,13 +158,30 @@ static const gchar introspection_xml[] =
 "                      <arg type='i' name='uid' direction='in'/>"
 "                      <arg type='i' name='result' direction='out'/>"
 "              </method>"
-"              <method name='MoveInstalledApp'>"
+"              <method name='PreMoveInstalledApp'>"
 "                      <arg type='s' name='pkgid' direction='in'/>"
 "                      <arg type='i' name='move_type' direction='in'/>"
 "                      <arg type='a(si)' name='dir_list' direction='in'/>"
 "                      <arg type='i' name='uid' direction='in'/>"
 "                      <arg type='i' name='result' direction='out'/>"
 "              </method>"
+"              <method name='PostMoveInstalledApp'>"
+"                      <arg type='s' name='pkgid' direction='in'/>"
+"                      <arg type='i' name='move_type' direction='in'/>"
+"                      <arg type='i' name='uid' direction='in'/>"
+"                      <arg type='i' name='result' direction='out'/>"
+"              </method>"
+"              <method name='ForceClean'>"
+"                      <arg type='s' name='pkgid' direction='in'/>"
+"                      <arg type='i' name='uid' direction='in'/>"
+"                      <arg type='i' name='result' direction='out'/>"
+"              </method>"
+"              <method name='EnableFullPkg'>"
+"                      <arg type='i' name='result' direction='out'/>"
+"              </method>"
+"              <method name='DisableFullPkg'>"
+"                      <arg type='i' name='result' direction='out'/>"
+"              </method>"
 "      </interface>"
 "</node>";
 
@@ -498,8 +513,9 @@ static void _app2sd_server_ondemand_setup_exit(GDBusConnection *connection, cons
        g_dbus_method_invocation_return_value(invocation, param);
 }
 
-static void _app2sd_server_move_installed_app(GDBusConnection *connection, const gchar *sender,
-       GVariant *parameters, GDBusMethodInvocation *invocation, uid_t sender_uid)
+static void _app2sd_server_pre_move_installed_app(GDBusConnection *connection,
+       const gchar *sender, GVariant *parameters,
+       GDBusMethodInvocation *invocation, uid_t sender_uid)
 {
        GVariant *param = NULL;
        int result = APP2EXT_SUCCESS;
@@ -554,9 +570,125 @@ static void _app2sd_server_move_installed_app(GDBusConnection *connection, const
        g_variant_iter_free(iter);
 
        dir_list = g_list_first(list);
-       ret = app2sd_usr_move_installed_app(pkgid, dir_list, move_type, target_uid);
+       ret = app2sd_usr_pre_move_installed_app(pkgid, dir_list, move_type, target_uid);
        if (ret) {
-               _E("usr_move error(%d)", ret);
+               _E("pre_move error(%d)", ret);
+               result = ret;
+       }
+
+       param = g_variant_new("(i)", result);
+       g_dbus_method_invocation_return_value(invocation, param);
+}
+
+static void _app2sd_server_post_move_installed_app(GDBusConnection *connection,
+       const gchar *sender, GVariant *parameters,
+       GDBusMethodInvocation *invocation, uid_t sender_uid)
+{
+       GVariant *param = NULL;
+       int result = APP2EXT_SUCCESS;
+       int move_type;
+       char *pkgid = NULL;
+       int ret = 0;
+       uid_t target_uid = -1;
+
+       g_variant_get(parameters, "(&sii)", &pkgid, &move_type, &target_uid);
+
+       _D("pkgid(%s), move_type(%d),sender_uid(%d), target_uid(%d)",
+               pkgid, move_type, sender_uid, target_uid);
+
+       if (sender_uid != 0 && sender_uid != target_uid) {
+               _E("Not permitted user!");
+               _app2sd_server_return_method_error(invocation,
+                       APP2EXT_ERROR_OPERATION_NOT_PERMITTED);
+               return;
+       }
+
+       ret = app2sd_usr_post_move_installed_app(pkgid, move_type, target_uid);
+       if (ret) {
+               _E("post_move error(%d)", ret);
+               result = ret;
+       }
+
+       param = g_variant_new("(i)", result);
+       g_dbus_method_invocation_return_value(invocation, param);
+}
+
+static void _app2sd_server_force_clean(GDBusConnection *connection, const gchar *sender,
+       GVariant *parameters, GDBusMethodInvocation *invocation, uid_t sender_uid)
+{
+       GVariant *param = NULL;
+       int result = APP2EXT_SUCCESS;
+       char *pkgid = NULL;
+       uid_t target_uid = -1;
+       int ret = 0;
+
+       g_variant_get(parameters, "(&si)", &pkgid, &target_uid);
+
+       _D("pkgid(%s), sender_uid(%d), target_uid(%d)",
+               pkgid, sender_uid, target_uid);
+
+       if (sender_uid != 0 && sender_uid != target_uid) {
+               _E("Not permitted user!");
+               _app2sd_server_return_method_error(invocation,
+                       APP2EXT_ERROR_OPERATION_NOT_PERMITTED);
+               return;
+       }
+
+       ret = app2sd_usr_force_clean(pkgid, target_uid);
+       if (ret) {
+               _E("error(%d)", ret);
+               result = ret;
+       }
+
+       param = g_variant_new("(i)", result);
+       g_dbus_method_invocation_return_value(invocation, param);
+}
+
+static void _app2sd_server_enable_full_pkg(GDBusConnection *connection, const gchar *sender,
+       GVariant *parameters, GDBusMethodInvocation *invocation, uid_t sender_uid)
+{
+       GVariant *param = NULL;
+       int result = APP2EXT_SUCCESS;
+       int ret = 0;
+
+       _D("sender_uid(%d)", sender_uid);
+
+       if (sender_uid >= REGULAR_USER) {
+               _E("Not permitted user!");
+               _app2sd_server_return_method_error(invocation,
+                       APP2EXT_ERROR_OPERATION_NOT_PERMITTED);
+               return;
+       }
+
+       ret = app2sd_enable_full_pkg();
+       if (ret) {
+               _E("error(%d)", ret);
+               result = ret;
+       }
+
+       param = g_variant_new("(i)", result);
+       g_dbus_method_invocation_return_value(invocation, param);
+}
+
+static void _app2sd_server_disable_full_pkg(GDBusConnection *connection, const gchar *sender,
+       GVariant *parameters, GDBusMethodInvocation *invocation, uid_t sender_uid)
+{
+       GVariant *param = NULL;
+       int result = APP2EXT_SUCCESS;
+       int ret = 0;
+
+       _D("sender_uid(%d)", sender_uid);
+
+       if (sender_uid >= REGULAR_USER) {
+               _E("Not permitted user!");
+               _app2sd_server_return_method_error(invocation,
+                       APP2EXT_ERROR_OPERATION_NOT_PERMITTED);
+               return;
+       }
+
+       ret = app2sd_disable_full_pkg();
+       if (ret) {
+               _E("error(%d)", ret);
                result = ret;
        }
 
@@ -598,8 +730,20 @@ static void handle_method_call(GDBusConnection *connection,
        } else if (g_strcmp0(method_name, "OndemandSetupExit") == 0) {
                _app2sd_server_ondemand_setup_exit(connection, sender,
                        parameters, invocation, sender_uid);
-       } else if (g_strcmp0(method_name, "MoveInstalledApp") == 0) {
-               _app2sd_server_move_installed_app(connection, sender,
+       } else if (g_strcmp0(method_name, "PreMoveInstalledApp") == 0) {
+               _app2sd_server_pre_move_installed_app(connection, sender,
+                       parameters, invocation, sender_uid);
+       } else if (g_strcmp0(method_name, "PostMoveInstalledApp") == 0) {
+               _app2sd_server_post_move_installed_app(connection, sender,
+                       parameters, invocation, sender_uid);
+       } else if (g_strcmp0(method_name, "ForceClean") == 0) {
+               _app2sd_server_force_clean(connection, sender,
+                       parameters, invocation, sender_uid);
+       } else if (g_strcmp0(method_name, "EnableFullPkg") == 0) {
+               _app2sd_server_enable_full_pkg(connection, sender,
+                       parameters, invocation, sender_uid);
+       } else if (g_strcmp0(method_name, "DisableFullPkg") == 0) {
+               _app2sd_server_disable_full_pkg(connection, sender,
                        parameters, invocation, sender_uid);
        }
 
@@ -641,6 +785,7 @@ static void __app2sd_on_name_lost(GDBusConnection *connection,
                const gchar *name, gpointer user_data)
 {
        _E("name lost(%s)", name);
+       g_main_loop_quit(app2sd_mainloop);
 }
 
 static int __app2sd_server_init()