* limitations under the License.
*/
+#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "isf_control.h"
#include <dlog.h>
+#include <unistd.h>
+#include <privilege_checker_private.h>
#include <inputmethod_manager.h>
#ifdef LOG_TAG
#endif
#define LOG_TAG "INPUTMETHOD_MANAGER"
+ime_manager_error_e _check_privilege()
+{
+ char uid[16];
+ ime_manager_error_e ret = IME_MANAGER_ERROR_NONE;
+
+ if (inputmethod_cynara_initialize() == false) {
+ LOGE("inputmethod_cynara_initialize () == false");
+ return IME_MANAGER_ERROR_PERMISSION_DENIED;
+ }
+
+ snprintf(uid, 16, "%d", getuid());
+ if (check_privilege(uid, IME_MANAGER_PRIVILEGE) == false) {
+ LOGE("check_privilege(uid, IME_MANAGER_PRIVILEGE) == false");
+ LOGE("uid : %s.", uid);
+ ret = IME_MANAGER_ERROR_PERMISSION_DENIED;
+ }
+
+ inputmethod_cynara_finish ();
+
+ return ret;
+}
+
int ime_manager_show_ime_list(void)
{
+ ime_manager_error_e retVal = IME_MANAGER_ERROR_NONE;
+
+ retVal = _check_privilege();
+ if (retVal != IME_MANAGER_ERROR_NONE) {
+ LOGE("_check_privilege returned %d.", retVal);
+ return retVal;
+ }
+
int ret = isf_control_show_ime_list();
if (ret == 0)
return IME_MANAGER_ERROR_NONE;
int ime_manager_show_ime_selector(void)
{
+ ime_manager_error_e retVal = IME_MANAGER_ERROR_NONE;
+
+ retVal = _check_privilege();
+ if (retVal != IME_MANAGER_ERROR_NONE) {
+ LOGE("_check_privilege returned %d.", retVal);
+ return retVal;
+ }
+
int ret = isf_control_show_ime_selector();
if (ret == 0)
return IME_MANAGER_ERROR_NONE;
int ime_manager_is_ime_enabled(const char *app_id, bool *enabled)
{
+ ime_manager_error_e retVal = IME_MANAGER_ERROR_NONE;
+
+ retVal = _check_privilege();
+ if (retVal != IME_MANAGER_ERROR_NONE) {
+ LOGE("_check_privilege returned %d.", retVal);
+ return retVal;
+ }
+
if (!app_id || !enabled) {
LOGW("IME_MANAGER_ERROR_INVALID_PARAMETER");
return IME_MANAGER_ERROR_INVALID_PARAMETER;
int ime_manager_get_active_ime(char **app_id)
{
+ ime_manager_error_e retVal = IME_MANAGER_ERROR_NONE;
+
+ retVal = _check_privilege();
+ if (retVal != IME_MANAGER_ERROR_NONE) {
+ LOGE("_check_privilege returned %d.", retVal);
+ return retVal;
+ }
+
if (!app_id) {
LOGW("IME_MANAGER_ERROR_INVALID_PARAMETER");
return IME_MANAGER_ERROR_INVALID_PARAMETER;
--- /dev/null
+#include "privilege_checker_private.h"
+
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <dlog.h>
+#include <unistd.h>
+
+#include <cynara-client.h>
+#include <cynara-error.h>
+#include <cynara-creds-socket.h>
+#include <cynara-session.h>
+
+#ifdef LOG_TAG
+#undef LOG_TAG
+#endif
+#define LOG_TAG "INPUTMETHOD_MANAGER"
+
+namespace
+{
+
+cynara *p_cynara = NULL;
+
+}
+
+bool
+inputmethod_cynara_initialize()
+{
+ int ret = cynara_initialize(&p_cynara, NULL);
+ LOGD("[inputmethod_cynara_initialize]_check_privilege returned %d.", ret);
+ return ret == CYNARA_API_SUCCESS;
+}
+
+void
+inputmethod_cynara_finish()
+{
+ if (p_cynara)
+ cynara_finish(p_cynara);
+
+ p_cynara = NULL;
+}
+
+bool
+check_privilege(const char *uid, const char *privilege)
+{
+ FILE *fp = NULL;
+ char smack_label[1024] = "/proc/self/attr/current";
+
+ if (!p_cynara) {
+ return false;
+ }
+
+ fp = fopen("/proc/self/attr/current", "r");
+ if (fp != NULL) {
+ if (fread(smack_label, 1, sizeof(smack_label), fp) <= 0)
+ LOGW("Error : fread");
+
+ fclose(fp);
+ }
+
+ pid_t pid = getpid();
+ char *session = cynara_session_from_pid(pid);
+ int ret = cynara_check(p_cynara, smack_label, session, uid, privilege);
+ LOGD("[check_privilege]_check_privilege returned %d.", ret);
+ if (session)
+ free(session);
+
+ if (ret != CYNARA_API_ACCESS_ALLOWED)
+ return false;
+ return true;
+}