| 108 | |
| 109 | |
| 110 | bool |
| 111 | CryptConfig::read(wstring& mes, const WCHAR *config_file_path, bool reverse) |
| 112 | { |
| 113 | |
| 114 | auto File = cppcryptfs::unique_ptr(static_cast<FILE*>(nullptr), fclose); |
| 115 | FILE *fl = NULL; |
| 116 | |
| 117 | if (config_file_path) { |
| 118 | |
| 119 | if (_wfopen_s(&fl, config_file_path, L"rb")) { |
| 120 | mes = LocUtils::GetStringFromResources(IDS_FAILED_OPEN_CONF); |
| 121 | return false; |
| 122 | } |
| 123 | m_configPath = config_file_path; |
| 124 | m_reverse = reverse; |
| 125 | } else { |
| 126 | |
| 127 | wstring config_path; |
| 128 | |
| 129 | if (m_basedir.size() < 1) { |
| 130 | mes = LocUtils::GetStringFromResources(IDS_NOT_CONF_DIR_EMPTY); |
| 131 | return false; |
| 132 | } |
| 133 | |
| 134 | config_path = m_basedir; |
| 135 | |
| 136 | if (config_path[config_path.size() - 1] != '\\') |
| 137 | config_path.push_back('\\'); |
| 138 | |
| 139 | wstring config_file = config_path + REVERSE_CONFIG_NAME; |
| 140 | |
| 141 | if (_wfopen_s(&fl, &config_file[0], L"rb")) { |
| 142 | config_file = config_path + CONFIG_NAME; |
| 143 | if (_wfopen_s(&fl, &config_file[0], L"rb")) { |
| 144 | mes = LocUtils::GetStringFromResources(IDS_FAILED_OPEN_CONF); |
| 145 | return false; |
| 146 | } |
| 147 | m_reverse = false; |
| 148 | } else { |
| 149 | m_reverse = true; |
| 150 | } |
| 151 | |
| 152 | m_configPath = config_file; |
| 153 | } |
| 154 | |
| 155 | File.reset(fl); |
| 156 | |
| 157 | if (fseek(fl, 0, SEEK_END)) { |
| 158 | mes = LocUtils::GetStringFromResources(IDS_NOT_FOUND_END_CONF); |
| 159 | return false; |
| 160 | } |
| 161 | |
| 162 | long filesize = ftell(fl); |
| 163 | |
| 164 | if (filesize > MAX_CONFIG_FILE_SIZE) { |
| 165 | mes = LocUtils::GetStringFromResources(IDS_CONF_TOO_BIG); |
| 166 | return false; |
| 167 | } |
no test coverage detected