| 36 | #include <list> |
| 37 | |
| 38 | int SavedPasswords::ClearSavedPasswords(BOOL bDelete) |
| 39 | { |
| 40 | |
| 41 | int count = 0; |
| 42 | |
| 43 | LPCWSTR reg_path = theApp.m_pszRegistryKey; |
| 44 | |
| 45 | HKEY hk_pws; |
| 46 | |
| 47 | LSTATUS status = RegOpenKeyEx(HKEY_CURRENT_USER, CPPCRYPTFS_REG_PATH SAVED_PASSWORDS_SECTION, 0, KEY_ALL_ACCESS, &hk_pws); |
| 48 | |
| 49 | if (status == ERROR_FILE_NOT_FOUND) |
| 50 | return count; |
| 51 | else if (status != ERROR_SUCCESS) |
| 52 | return -1; |
| 53 | |
| 54 | WCHAR hash[256]; |
| 55 | |
| 56 | DWORD index = 0; |
| 57 | |
| 58 | DWORD hash_len = sizeof(hash) / sizeof(hash[0]) - 1; |
| 59 | |
| 60 | DWORD type; |
| 61 | |
| 62 | list<wstring> hashes; |
| 63 | |
| 64 | hash_len = sizeof(hash) / sizeof(hash[0]); |
| 65 | |
| 66 | while ((status = RegEnumValue(hk_pws, index, hash, &hash_len, NULL, &type, NULL, NULL)) == ERROR_SUCCESS) { |
| 67 | index++; |
| 68 | hash_len = sizeof(hash) / sizeof(hash[0]); |
| 69 | if (type != REG_BINARY) |
| 70 | continue; |
| 71 | hashes.push_back(hash); |
| 72 | } |
| 73 | |
| 74 | if (status != ERROR_NO_MORE_ITEMS) { |
| 75 | RegCloseKey(hk_pws); |
| 76 | return -1; |
| 77 | } |
| 78 | |
| 79 | if (bDelete) { |
| 80 | |
| 81 | for (auto it : hashes) { |
| 82 | status = RegDeleteValue(hk_pws, it.c_str()); |
| 83 | if (status != ERROR_SUCCESS) { |
| 84 | RegCloseKey(hk_pws); |
| 85 | return -1; |
| 86 | } |
| 87 | count++; |
| 88 | } |
| 89 | } else { |
| 90 | count = (int)hashes.size(); |
| 91 | } |
| 92 | |
| 93 | RegCloseKey(hk_pws); |
| 94 | |
| 95 | return count; |