MCPcopy Create free account
hub / github.com/bailey27/cppcryptfs / read_dir_iv

Function read_dir_iv

libcppcryptfs/util/fileutil.cpp:139–191  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

137
138#ifdef _WIN32
139static bool
140read_dir_iv(const TCHAR *path, unsigned char *diriv, FILETIME& LastWriteTime)
141{
142
143 HANDLE hfile = INVALID_HANDLE_VALUE;
144 DWORD nRead = 0;
145
146 bool caught_wstring = false;
147
148 try {
149 wstring path_str;
150
151 path_str.append(path);
152
153 if (path_str[path_str.size() - 1] != '\\') {
154 path_str.push_back('\\');
155 }
156
157 path_str.append(DIR_IV_NAME);
158
159 hfile = ::CreateFile(&path_str[0], GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
160
161 if (hfile == INVALID_HANDLE_VALUE) {
162 auto lasterr =::GetLastError();
163 throw(L"\terror opening diriv file " + path_str + L" lasterr = " + to_wstring(lasterr));
164 }
165
166 if (!::ReadFile(hfile, diriv, DIR_IV_LEN, &nRead, NULL)) {
167 auto lasterr = ::GetLastError();
168 throw(L"\terror reading diriv file " + path_str + L" lasterr = " + to_wstring(lasterr));
169 }
170
171 if (!::GetFileTime(hfile, NULL, NULL, &LastWriteTime)) {
172 auto lasterr = ::GetLastError();
173 throw(L"\terror getting filetime of diriv file " + path_str + L" lasterr = " + to_wstring(lasterr));
174 }
175 } catch (const wstring& mes) {
176 DbgPrint(L"\tget_diriv: %s\n", mes.c_str());
177 nRead = 0;
178 caught_wstring = true;
179 } catch (...) {
180 nRead = 0;
181 }
182
183 if (hfile != INVALID_HANDLE_VALUE)
184 ::CloseHandle(hfile);
185
186 if (!caught_wstring && nRead != DIR_IV_LEN) {
187 DbgPrint(L"\tget_diriv read incorrect number of bytes from %s, read %u bytes instead of %u\n", path, nRead, DIR_IV_LEN);
188 }
189
190 return nRead == DIR_IV_LEN;
191}
192
193#endif // _WIN32
194

Callers 1

get_dir_ivFunction · 0.85

Calls 2

DbgPrintFunction · 0.85
sizeMethod · 0.80

Tested by

no test coverage detected