From: Dongik Lee Date: Mon, 19 May 2025 08:21:25 +0000 (+0900) Subject: Refactor log message X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=3b5e3931549f4f11f21731ea29a00a26ff663226;p=platform%2Fhal%2Fbackend%2Femulator%2Fsecurity-auth.git Refactor log message Change-Id: Ia041c03c0bd3c018425b17c7855ec20443d5e5cd --- diff --git a/src/hal_backend_security_auth.cpp b/src/hal_backend_security_auth.cpp index 7fb38f6..4602570 100644 --- a/src/hal_backend_security_auth.cpp +++ b/src/hal_backend_security_auth.cpp @@ -57,10 +57,11 @@ hal_backend_security_auth::hal_backend_security_auth(uid_t user_id, hal_security { m_maxAttempt = PASSWORD_INFINITE_ATTEMPT_COUNT; - LOGD("hal_backend_security_auth constructor user_id : "<< user_id << ", password_type : " << password_type); - LOGD(" default value max_attempt : "<< m_maxAttempt << ", max_history_size : " << m_maxHistorySize); - LOGD(" expire_time : "<< m_expireTime << ", expire_time_left : " << m_expireTimeLeft << ", password_is_active : " << m_passwordActive); - LOGD(" password_is_rcv_active : "<< m_passwordRcvActive << ", attempt : " << m_attempt); + LOGD("hal_backend_security_auth constructor"); + LOGD("user_id : "<< user_id << ", password_type : " << password_type); + LOGD("default value max_attempt : "<< m_maxAttempt << ", max_history_size : " << m_maxHistorySize); + LOGD("expire_time : "<< m_expireTime << ", expire_time_left : " << m_expireTimeLeft << ", password_is_active : " << m_passwordActive); + LOGD("password_is_rcv_active : "<< m_passwordRcvActive << ", attempt : " << m_attempt); std::string userDir = create_dir(RW_DATA_DIR, m_user); @@ -107,6 +108,9 @@ void hal_backend_security_auth::reset_state() m_expireTimeLeft = PASSWORD_INFINITE_EXPIRATION_TIME; m_passwordRcvActive = false; m_passwordActive = false; + LOGD("reset_state m_maxAtttempt : " << m_maxAttempt << " m_maxHistorySize : " << m_maxHistorySize + << " m_expireTime : " << m_expireTime << " m_expireTimeLeft : " << m_expireTimeLeft + << " m_passwordRcvActive : " << m_passwordRcvActive << " m_passwordActive : " << m_passwordActive); m_passwordCurrent.reset(new NoPassword()); } @@ -120,7 +124,7 @@ void hal_backend_security_auth::reset_timer() bool hal_backend_security_auth::load_memory_from_file(const std::string& passwdFilePath) { struct stat fileStat; - + LOGD("passwdFilePath : " << passwdFilePath); if (stat(passwdFilePath.c_str(), &fileStat) != 0) return false; @@ -160,12 +164,10 @@ bool hal_backend_security_auth::load_memory_from_file(const std::string& passwdF LOGE("Invaild password version: " << fileVersion); } - LOGD("loadMemoryFromFile: File=" << passwdFilePath << - ":: User: " << m_user << ", loaded max_att: " << m_maxAttempt << - ", history_size: " << m_maxHistorySize << ", m_expireTime: " << - m_expireTime << ", m_expireTimeLeft: " << m_expireTimeLeft << - ", isActive: " << m_passwordActive << ", isRcvActive: " << - m_passwordRcvActive<< ", m_passwordType: " << m_passwordType); + LOGD("m_user : " << m_user << " m_maxAttempt : " << m_maxAttempt + << " m_maxHistorySize : " << m_maxHistorySize << " m_expireTime : " << m_expireTime + << " m_expireTimeLeft: " << m_expireTimeLeft << " m_passwordActive : " << m_passwordActive + << " isRcvActive: " << m_passwordRcvActive<< " m_passwordType : " << m_passwordType); return true; } @@ -189,12 +191,12 @@ void hal_backend_security_auth::prepare_password_file() return; } - LOGE("PWD_DBG not found " << m_user << " password file. Creating."); + LOGE("m_user : " << m_user << " pwdFile : " << pwdFile << " pwdFile is Creating."); //create file write_memory_to_file(m_user); } else { //if file exists, load data - LOGE("PWD_DBG found " << m_user << " password file. Opening."); - + LOGE("pwdFile : " << pwdFile << " pwdFile found"); + LOGE("m_user : " << m_user << " password file. Opening."); try { load_memory_from_file(oldVersionPwdFile); } catch (...) { @@ -211,12 +213,13 @@ void hal_backend_security_auth::prepare_attempt_file() // check if attempt file exists if (!file_exists(attemptFile)) { - LOGE("PWD_DBG not found " << m_user << " attempt file. Creating."); + LOGE("attemptFile : " << attemptFile << " not found"); + LOGE("m_user : " << m_user << " attempt file. Creating."); write_attempt_to_file(m_user); } else { - LOGE("PWD_DBG found " << m_user << " attempt file. Opening."); + LOGE("attemptFile : " << attemptFile << " found"); + LOGE("m_user : " << m_user << " attempt file. Opening."); std::ifstream AttemptFile(attemptFile); - if (!AttemptFile) { LOGE("Failed to open " << m_user << " attempt file."); // ignore error @@ -226,7 +229,7 @@ void hal_backend_security_auth::prepare_attempt_file() AttemptFile.read(reinterpret_cast(&m_attempt), sizeof(unsigned int)); if (!AttemptFile) { - LOGE("Failed to read " << m_user << " attempt count."); + LOGE("Failed to read AttemptFile m_user : " << m_user); // ignore error reset_attempt(m_user); } @@ -235,16 +238,15 @@ void hal_backend_security_auth::prepare_attempt_file() int hal_backend_security_auth::write_memory_to_file(uid_t user_id) const { - LOGD("hal_backend_security_auth::write_memory_to_file"); + LOGD("hal_backend_security_auth::write_memory_to_file user_id : " << user_id << " m_user : " << m_user); if(user_id != m_user) return HAL_SECURITY_AUTH_ERROR_INPUT_PARAM; std::string pwdFile = create_dir(RW_DATA_DIR, m_user) + PASSWORD_FILE; PasswordFileBuffer pwdBuffer; - LOGD(" user: " << m_user << ", max_attempt: " << m_maxAttempt << - ", history_size: " << m_maxHistorySize << ", m_expireTime: " << - m_expireTime << ", m_expireTimeLeft: " << m_expireTimeLeft << - ", isActive: " << m_passwordActive << ", isRcvActive: " << - m_passwordRcvActive << ", m_passwordType: " << m_passwordType); + LOGD("m_user : " << m_user << " m_maxAttempt : " << m_maxAttempt << " m_maxHistorySize : " + << m_maxHistorySize << " m_expireTime : " << m_expireTime << " m_expireTimeLeft : " + << m_expireTimeLeft << " m_passwordActive : " << m_passwordActive << " m_passwordRcvActive : " + << m_passwordRcvActive << " m_passwordType : " << m_passwordType); //serialize password attributes Serialization::Serialize(pwdBuffer, CURRENT_FILE_VERSION); Serialization::Serialize(pwdBuffer, m_maxAttempt); @@ -259,32 +261,32 @@ int hal_backend_security_auth::write_memory_to_file(uid_t user_id) const pwdBuffer.Save(pwdFile); if (chmod(pwdFile.c_str(), FILE_MODE)) { - LOGE(" Failed to chmod for " << pwdFile << " Error: " << errnoToString()); + LOGE("Failed to chmod for " << pwdFile << " Error: " << errnoToString()); } return HAL_SECURITY_AUTH_ERROR_NONE; } int hal_backend_security_auth::write_attempt_to_file(uid_t user_id) const { - LOGD("hal_backend_security_auth::write_attempt_to_file"); + LOGD("hal_backend_security_auth::write_attempt_to_file user_id : " << user_id << " m_user : " << m_user); if(user_id != m_user) return HAL_SECURITY_AUTH_ERROR_INPUT_PARAM; std::string attemptFile = create_dir(RW_DATA_DIR, m_user) + ATTEMPT_FILE; std::ofstream AttemptFile(attemptFile, std::ofstream::trunc); if (!AttemptFile.good()) { - LOGE(" Failed to open " << m_user << " attempt file."); + LOGE("Failed to open " << m_user << " attempt file."); } AttemptFile.write(reinterpret_cast(&m_attempt), sizeof(unsigned int)); if (!AttemptFile) { - LOGE(" Failed to write " << m_user << " attempt count."); + LOGE("Failed to write " << m_user << " attempt count."); } AttemptFile.flush(); if (::fsync(FstreamAccessors::GetFd(AttemptFile)) != 0) - LOGE(" Failed to synchronize a file's state."); + LOGE("Failed to synchronize a file's state."); AttemptFile.close(); return HAL_SECURITY_AUTH_ERROR_NONE; @@ -292,7 +294,7 @@ int hal_backend_security_auth::write_attempt_to_file(uid_t user_id) const int hal_backend_security_auth::set_password(uid_t user_id, const char* password) { - LOGD("hal_backend_security_auth::set_password"); + LOGD("hal_backend_security_auth::set_password user_id : " << user_id << " m_user : " << m_user); if(user_id != m_user || password == nullptr) return HAL_SECURITY_AUTH_ERROR_INPUT_PARAM; if (password[0] == '\0') { @@ -310,7 +312,7 @@ int hal_backend_security_auth::set_password(uid_t user_id, const char* password) m_passwordActive = true; } - LOGD("hal_backend_security_auth::set_password: m_passwordActive=" << m_passwordActive); + LOGD("m_passwordActive : " << m_passwordActive); return HAL_SECURITY_AUTH_ERROR_NONE; } @@ -324,7 +326,7 @@ int hal_backend_security_auth::check_password(uid_t user_id, const char* passwor int hal_backend_security_auth::set_max_history_size(uid_t user_id, unsigned int history_size) { - LOGD("hal_backend_security_auth::set_max_history_size"); + LOGD("hal_backend_security_auth::set_max_history_size user_id : " << user_id << " m_user : " << m_user); if(user_id != m_user) return HAL_SECURITY_AUTH_ERROR_INPUT_PARAM; // put current password in history @@ -333,6 +335,7 @@ int hal_backend_security_auth::set_max_history_size(uid_t user_id, unsigned int //setting history should be independent from password being set m_maxHistorySize = history_size; + LOGE("m_maxHistorySize : " << m_maxHistorySize); while (m_passwordHistory.size() > history_size) m_passwordHistory.pop_back(); @@ -342,73 +345,75 @@ int hal_backend_security_auth::set_max_history_size(uid_t user_id, unsigned int int hal_backend_security_auth::get_max_history_size(uid_t user_id, unsigned int *history_size) const { - LOGD("hal_backend_security_auth::get_max_history_size"); + LOGD("hal_backend_security_auth::get_max_history_size user_id : " << user_id << " m_user : " << m_user); if(user_id != m_user) return HAL_SECURITY_AUTH_ERROR_INPUT_PARAM; *history_size = m_maxHistorySize; + LOGE("m_maxHistorySize : " << m_maxHistorySize); return HAL_SECURITY_AUTH_ERROR_NONE; } int hal_backend_security_auth::get_expire_time(uid_t user_id, unsigned int *expire_time) const { - LOGD("hal_backend_security_auth::get_expire_time"); + LOGD("hal_backend_security_auth::get_expire_time user_id : " << user_id << " m_user : " << m_user); if(user_id != m_user) return HAL_SECURITY_AUTH_ERROR_INPUT_PARAM; *expire_time = m_expireTime; - LOGE(" *expire_time : "<(timeLeft); - LOGD(" not eq expire_time_left : " << *expire_time_left << " timeLeft : " << timeLeft); + LOGD("*expire_time_left : " << *expire_time_left << " timeLeft : " << timeLeft); } else { *expire_time_left = PASSWORD_API_NO_EXPIRATION; - LOGD(" expire_time_left : " << *expire_time_left); + LOGD("*expire_time_left : " << *expire_time_left); } return HAL_SECURITY_AUTH_ERROR_NONE; @@ -416,7 +421,7 @@ int hal_backend_security_auth::get_expire_time_left(uid_t user_id, unsigned int int hal_backend_security_auth::reset_attempt(uid_t user_id) { - LOGD("hal_backend_security_auth::reset_attempt"); + LOGD("hal_backend_security_auth::reset_attempt user_id : " << user_id << " m_user : " << m_user); if(user_id != m_user) return HAL_SECURITY_AUTH_ERROR_INPUT_PARAM; m_attempt = 0; @@ -426,40 +431,41 @@ int hal_backend_security_auth::reset_attempt(uid_t user_id) int hal_backend_security_auth::increment_attempt(uid_t user_id) { - LOGD("hal_backend_security_auth::increment_attempt"); + LOGD("hal_backend_security_auth::increment_attempt user_id : " << user_id << " m_user : " << m_user); if(user_id != m_user) return HAL_SECURITY_AUTH_ERROR_INPUT_PARAM; m_attempt++; + LOGD("m_attempt : " << m_attempt); return HAL_SECURITY_AUTH_ERROR_NONE; } int hal_backend_security_auth::get_max_attempt(uid_t user_id, unsigned int *max_attempt) const { - LOGD("hal_backend_security_auth::get_max_attempt"); - + LOGD("hal_backend_security_auth::get_max_attempt user_id : " << user_id << " m_user : " << m_user); if(user_id != m_user) return HAL_SECURITY_AUTH_ERROR_INPUT_PARAM; *max_attempt = m_maxAttempt; + LOGD("*m_maxAttempt : " << m_maxAttempt); return HAL_SECURITY_AUTH_ERROR_NONE; } int hal_backend_security_auth::set_max_attempt(uid_t user_id, unsigned int max_attempt) { - LOGD("hal_backend_security_auth::set_max_attempt"); + LOGD("hal_backend_security_auth::set_max_attempt user_id : " << user_id << " m_user : " << m_user); if(user_id != m_user) return HAL_SECURITY_AUTH_ERROR_INPUT_PARAM; m_maxAttempt = max_attempt; + LOGD("max_attempt : " << max_attempt); return HAL_SECURITY_AUTH_ERROR_NONE; } int hal_backend_security_auth::is_password_active(uid_t user_id) const { - LOGD("hal_backend_security_auth::is_password_active"); - LOGD("hal_backend_security_auth::is_password_active: user_id=" << user_id << ", m_user=" << m_user <<", m_passwordActive=" << m_passwordActive); + LOGD("hal_backend_security_auth::is_password_active user_id : " << user_id << " m_user : " << m_user <<" m_passwordActive : " << m_passwordActive); if(user_id != m_user) return HAL_SECURITY_AUTH_ERROR_INPUT_PARAM; return m_passwordActive ? HAL_SECURITY_AUTH_ERROR_NONE : HAL_SECURITY_AUTH_ERROR_STATUS; @@ -467,11 +473,10 @@ int hal_backend_security_auth::is_password_active(uid_t user_id) const int hal_backend_security_auth::is_password_reused(uid_t user_id, const char* password) const { - LOGD("hal_backend_security_auth::is_password_reused"); + LOGD("hal_backend_security_auth::is_password_reused user_id : " << user_id << " m_user : " << m_user); if(user_id != m_user) return HAL_SECURITY_AUTH_ERROR_INPUT_PARAM; - LOGD(" user_id : "<< m_user << " history_size: " << - m_passwordHistory.size() << ", max_history_size: " << m_maxHistorySize); + LOGD("m_passwordHistory : " << m_passwordHistory.size() << " m_maxHistorySize : " << m_maxHistorySize); // go through history and check if password existed earlier if (std::any_of( @@ -480,27 +485,29 @@ int hal_backend_security_auth::is_password_reused(uid_t user_id, const char* pas [&password](const IPasswordPtr & pwd) { return pwd->match(password); })) { - LOGE(" password match!"); + LOGE("password match!"); return HAL_SECURITY_AUTH_ERROR_NONE; } - LOGE(" Failed isPasswordReused: No passwords match"); + LOGE("Failed isPasswordReused: No passwords match"); return HAL_SECURITY_AUTH_ERROR_STATUS; } int hal_backend_security_auth::check_expiration(uid_t user_id) const { - LOGD("hal_backend_security_auth::check_expiration"); + LOGD("hal_backend_security_auth::check_expiration user_id : " << user_id << " m_user : " << m_user); if(user_id != m_user) return HAL_SECURITY_AUTH_ERROR_INPUT_PARAM; - LOGD(" m_expireTimeLeft : " << m_expireTimeLeft << " PIET : "<< PASSWORD_INFINITE_EXPIRATION_TIME << " time: " << time(NULL) << " m_eTLeft : " << m_expireTimeLeft); + LOGD("m_expireTimeLeft : " << m_expireTimeLeft << " PASSWORD_INFINITE_EXPIRATION_TIME : " + << PASSWORD_INFINITE_EXPIRATION_TIME << " time : " << time(NULL) << " m_expireTimeLeft : " << m_expireTimeLeft); return ((m_expireTimeLeft != PASSWORD_INFINITE_EXPIRATION_TIME) && (time(NULL) > m_expireTimeLeft)) ? HAL_SECURITY_AUTH_ERROR_PASSWORD_EXPIRED : HAL_SECURITY_AUTH_ERROR_NONE; } int hal_backend_security_auth::check_attempt_exceeded(uid_t user_id) const { - LOGD("hal_backend_security_auth::check_attempt_exceeded"); - LOGD(" m_maxAttempt : " << m_maxAttempt << " P_I_A_C : " << PASSWORD_INFINITE_ATTEMPT_COUNT << " m_attempt : " << m_attempt); + LOGD("hal_backend_security_auth::check_attempt_exceeded user_id : " << user_id << " m_user : " << m_user); + LOGD("m_maxAttempt : " << m_maxAttempt << " PASSWORD_INFINITE_ATTEMPT_COUNT : " << PASSWORD_INFINITE_ATTEMPT_COUNT + << " m_attempt : " << m_attempt); if(user_id != m_user) return HAL_SECURITY_AUTH_ERROR_INPUT_PARAM; return ((m_maxAttempt != PASSWORD_INFINITE_ATTEMPT_COUNT) && (m_attempt > m_maxAttempt)) ? HAL_SECURITY_AUTH_ERROR_PASSWORD_MAX_ATTEMPTS_EXCEEDED : HAL_SECURITY_AUTH_ERROR_NONE; @@ -508,41 +515,45 @@ int hal_backend_security_auth::check_attempt_exceeded(uid_t user_id) const int hal_backend_security_auth::is_ignore_period(uid_t user_id) const { - LOGD("hal_backend_security_auth::is_ignore_period"); + LOGD("hal_backend_security_auth::is_ignore_period user_id : " << user_id << " m_user : " << m_user); if(user_id != m_user) return HAL_SECURITY_AUTH_ERROR_INPUT_PARAM; TimePoint retryTimerStop = ClockType::now(); TimeDiff diff = retryTimerStop - m_retryTimerStart; - m_retryTimerStart = retryTimerStop; + LOGD( "diff.count() : " << diff.count() << " RETRY_TIMEOUT : " << RETRY_TIMEOUT); + return (diff.count() < RETRY_TIMEOUT) ? HAL_SECURITY_AUTH_ERROR_NONE : HAL_SECURITY_AUTH_ERROR_PASSWORD_RETRY_TIMER; } int hal_backend_security_auth::is_history_active(uid_t user_id) const { - LOGD("hal_backend_security_auth::is_history_active"); + LOGD("hal_backend_security_auth::is_history_active user_id : " << user_id << " m_user : " << m_user); if(user_id != m_user) return HAL_SECURITY_AUTH_ERROR_INPUT_PARAM; + LOGD( "m_maxHistorySize : " << m_maxHistorySize); return (m_maxHistorySize != 0) ? HAL_SECURITY_AUTH_ERROR_NONE : HAL_SECURITY_AUTH_ERROR_STATUS; } int hal_backend_security_auth::get_password_type(uid_t user_id, hal_security_auth_password_type_e *password_type) const { - LOGD("hal_backend_security_auth::get_password_type"); + LOGD("hal_backend_security_auth::get_password_type user_id : " << user_id << " m_user : " << m_user); if(user_id != m_user) return HAL_SECURITY_AUTH_ERROR_INPUT_PARAM; *password_type = m_passwordType; + LOGD( "m_passwordType : " << m_passwordType); return HAL_SECURITY_AUTH_ERROR_NONE; } int hal_backend_security_auth::set_password_type(uid_t user_id, hal_security_auth_password_type_e password_type) { - LOGD("hal_backend_security_auth::set_password_type"); + LOGD("hal_backend_security_auth::set_password_type user_id : " << user_id << " m_user : " << m_user); if(user_id != m_user) return HAL_SECURITY_AUTH_ERROR_INPUT_PARAM; m_passwordType = password_type; + LOGD( "passwordType : " << password_type); return HAL_SECURITY_AUTH_ERROR_NONE; } @@ -550,6 +561,7 @@ uid_t hal_backend_security_auth::get_user_id() const { LOGD("hal_backend_security_auth::get_user_id"); uid_t user_id = getuid(); + LOGD( "user_id : " << user_id); return user_id; } @@ -567,23 +579,23 @@ hal_backend_security_auth* get_hal_backend_security_auth_instance(uid_t user_id, { hal_security_auth_password_type_e current_password_type; auto itAuth = hal_backend_security_auth_instance_map.find(user_id); - LOGD("get_hal_backend_security_auth_instance"); + LOGD("get_hal_backend_security_auth_instance user_id : " << user_id); if (itAuth != hal_backend_security_auth_instance_map.end()){ hal_backend_security_auth *authInstance = itAuth->second; authInstance->get_password_type(user_id, ¤t_password_type); if(current_password_type == password_type){ - LOGD(" found the user and the same type"); + LOGD("Found the same password_type : " << password_type); return authInstance; } else{ authInstance->set_password_type(user_id, password_type); - LOGD(" found the user and the diffent type, so changed."); + LOGD("Not found the same type. so, set the password_type : " << password_type); return authInstance; } } - LOGD(" Not found and created a new instance"); + LOGD("Not found and created a new instance"); hal_backend_security_auth* new_security_auth = new hal_backend_security_auth(user_id,password_type); hal_backend_security_auth_instance_map[user_id] = new_security_auth; return new_security_auth;