/* * pwlock * * Copyright 2012 Samsung Electronics Co., Ltd * * Licensed under the Flora License, Version 1.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://floralicense.org/license/ * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "util.h" #define LINEMAX 256 #define MAXFILELEN 1048576 /* 32000 */ #define PHLOCK_SOCK_PREFIX "/tmp/phlock" #define PHLOCK_SOCK_MAXBUFF 65535 const char *sys_str_table[] = { "IDS_COM_SK_DONE", /* 0 */ "IDS_COM_BODY_ENTER_PASSWORD", "IDS_COM_BODY_PREVIOUS", "IDS_COM_SK_NEXT", "IDS_COM_SK_OK", "IDS_COM_SK_CANCEL", "IDS_COM_SK_START" }; const char *app_str_table[] = { "IDS_IDLE_BODY_AUTOMATIC", "IDS_IDLE_HEADER_NETWORK_LOCK", "IDS_IDLE_HEADER_PIN_LOCK", "IDS_IDLE_HEADER_PUK_LOCK", "IDS_IDLE_HEADER_SIM_BLOCKED", "IDS_IDLE_HEADER_SIM_LOCK", "IDS_IDLE_BODY_1_ATTEMPT_LEFT", "IDS_IDLE_BODY_CORPORATE_PERSONALISATION_ON_ENTER_CONTROL_KEY", "IDS_IDLE_BODY_ENTER_NEW_PIN", "IDS_IDLE_BODY_ENTER_PIN", "IDS_IDLE_BODY_ENTER_PUK", "IDS_IDLE_BODY_INCORRECT_PIN", "IDS_IDLE_BODY_INCORRECT_PIN_TRY_AGAIN", "IDS_IDLE_BODY_NETWORK_PERSONALISATION_ON_ENTER_CONTROL_KEY", "IDS_IDLE_BODY_NETWORK_SUBSET_PERSONALISATION_ON_ENTER_CONTROL_KEY", "IDS_IDLE_BODY_PD_ATTEMPTS_LEFT", "IDS_IDLE_BODY_SERVICE_PROVIDER_PERSONALISATION_ON_ENTER_CONTROL_KEY", "IDS_IDLE_BODY_SIM_CARD_NOT_AVAILABLE_CONTACT_YOUR_SERVICE_PROVIDER", "IDS_IDLE_BODY_WRONG_PASSWORD", "IDS_IDLE_BUTTON_DIALER", "IDS_IDLE_HEADER_DISPLAY_LANGUAGE", "IDS_IDLE_BODY_PASSWORD_EMPTY", "IDS_IDLE_BODY_PD_TO_PD_DIGITS_REQUIRED", "Passwords do not match", /* TODO: System string request */ "PIN code has been changed", /* TODO: String request */ "SIM card error", /* TODO: String request */ "IDS_IDLE_POP_CHECKING_SIM_CARD_ING", "Welcome to your", /* TODO: String request */ "IDS_SCM_BODY_WELCOME_E", "IDS_STU_BODY_SELECT_LANGUAGE", "IDS_ST_SK_EMERGENCY_CALL", "IDS_ST_BODY_TAP_TO_SET_UP", "IDS_COM_SK_SKIP", "IDS_ST_BODY_INSTALTAB_FINISH", "IDS_STU_BODY_DEVICE_IS_SET_UP_AND_READY_TO_USE", "IDS_STU_POP_SETUP_COMPLETE", "IDS_COM_BODY_NO_SIM_CARD_IN_DEVICE", "IDS_STU_BODY_HOW_TO_INSERT_SIM_CARD_HELP_MSG", "IDS_ST_BUTTON_TRY_AGAIN_ABB" }; static void _log(char *msg) { FILE *fp; fp = fopen(LOGFILE, "a"); if (fp == NULL) return; fprintf(fp, "%s\n", msg); fclose(fp); } void pwlock_log(char *fmt, ...) { va_list ap; char buf[LINEMAX]; va_start(ap, fmt); vsnprintf(buf, sizeof(buf), fmt, ap); va_end(ap); _log(buf); } void pwlock_log_t(char *fmt, ...) { va_list ap; FILE *fd = 0; char buf[LINEMAX] = { 0, }; char debugString[LINEMAX] = { 0, }; va_start(ap, fmt); vsnprintf(buf, sizeof(buf), fmt, ap); va_end(ap); int fileLen = 0; struct tm local_t; time_t current_time = 0; bzero((char *)&debugString, LINEMAX); time(¤t_time); gmtime_r(¤t_time, &local_t); /* for prevent 53555 */ int len = snprintf(debugString, sizeof(debugString), "[%d-%02d-%02d, %02d:%02d:%02d]: ", local_t.tm_year + 1900, local_t.tm_mon + 1, local_t.tm_mday, local_t.tm_hour, local_t.tm_min, local_t.tm_sec); if (len == -1) { return; } else { debugString[len] = '\0'; } len = g_strlcat(debugString, buf, LINEMAX); if (len >= LINEMAX) { /* TODO:ERROR handling */ return; } else { debugString[len] = '\n'; } /* FIXME this is for permission.. later we should fix and remove this... */ if ((fd = fopen(LOGFILE, "at+")) == NULL) { PWLOCK_ERR("File fopen fail for writing Pwlock information"); } else { int pid = -1; if (fwrite(debugString, strlen(debugString), 1, fd) < 1) { PWLOCK_ERR ("File fwrite fail for writing Pwlock information"); fclose(fd); if ((pid = fork()) < 0) { } else if (pid == 0) { execl("/bin/rm", "rm", "-f", LOGFILE, (char *)0); } } else { fseek(fd, 0l, SEEK_END); fileLen = ftell(fd); if (fileLen > MAXFILELEN) { fclose(fd); if ((pid = fork()) < 0) { return; } else if (pid == 0) { execl("/bin/rm", "rm", "-f", LOGFILE, (char *)0); } } else fclose(fd); } } } static void win_del(void *data, Evas_Object * obj, void *event) { elm_exit(); } Evas_Object *create_win(const char *name) { Evas_Object *eo; int w, h; eo = elm_win_add(NULL, name, ELM_WIN_BASIC); if (eo) { elm_win_title_set(eo, name); elm_win_borderless_set(eo, EINA_TRUE); elm_win_conformant_set(eo, EINA_TRUE); evas_object_smart_callback_add(eo, "delete,request", win_del, NULL); ecore_x_window_size_get(ecore_x_window_root_first_get(), &w, &h); evas_object_resize(eo, w, h); } return eo; } Evas_Object *load_edj(Evas_Object * parent, const char *file, const char *group) { Evas_Object *eo; int r; eo = elm_layout_add(parent); if (eo) { r = elm_layout_file_set(eo, file, group); if (!r) { evas_object_del(eo); return NULL; } evas_object_size_hint_weight_set(eo, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); } return eo; } char *pwlock_get_string(int id) { _DBG("get string id : %d\n", id); char *str = NULL; if (id < IDS_PWLOCK_SYSTEM_STRING_MAX) { /* get system string */ str = dgettext("sys_string", sys_str_table[id]); } else { /* get application string */ str = dgettext("pwlock", app_str_table[id - IDS_PWLOCK_SYSTEM_STRING_MAX]); } _DBG("get string : %s\n", str); return str; } void pwlock_tolower(char *src, char *dest) { int i; int src_len=0; if (!src || !dest) { _DBG(" src=%p, dest=%p\n", src, dest); return; } src_len = strlen(src); for(i=0;i