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

Method Associate

libcppcryptfs/file/cryptfile.cpp:87–159  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

85}
86
87BOOL
88CryptFileForward::Associate(CryptContext *con, HANDLE hfile, LPCWSTR inputPath, bool bForWrite)
89{
90 m_openfile = con->m_openfiles.GetOpenFile(inputPath);
91
92 if (!m_openfile) {
93 assert(false);
94 return FALSE;
95 }
96
97 m_bExclusiveLock = bForWrite;
98
99 // the destructor does the unlocking
100 Lock();
101
102 static_assert(sizeof(m_header) == FILE_HEADER_LEN, "sizeof(m_header) != FILE_HEADER_LEN");
103
104 m_handle = hfile;
105
106 m_con = con;
107
108 LARGE_INTEGER l;
109
110 if (!GetFileSizeEx(hfile, &l)) {
111 DbgPrint(L"ASSOCIATE: failed to get size of file\n");
112 return FALSE;
113 }
114
115 m_real_file_size = l.QuadPart;
116
117 if (l.QuadPart == 0) {
118 m_header.version = CRYPT_VERSION;
119 m_is_empty = true;
120 return TRUE;
121 } else if (l.QuadPart < FILE_HEADER_LEN) {
122 DbgPrint(L"ASSOCIATE: missing file header\n");
123 return FALSE;
124 }
125
126 l.QuadPart = 0;
127
128 OVERLAPPED ov;
129 SetOverlapped(&ov, l.QuadPart);
130
131 DWORD nread;
132
133 if (!ReadFile(hfile, &m_header, sizeof(m_header), &nread, &ov)) {
134 DWORD error = GetLastError();
135 DbgPrint(L"ASSOCIATE: failed to read header, error = %d\n", error);
136 return FALSE;
137 }
138
139 if (nread != FILE_HEADER_LEN) {
140 DbgPrint(L"ASSOCIATE: wrong number of bytes read when reading file header\n");
141 return FALSE;
142 }
143
144 m_header.version = MakeBigEndianNative(m_header.version);

Calls 6

DbgPrintFunction · 0.85
SetOverlappedFunction · 0.85
MakeBigEndianNativeFunction · 0.85
derive_path_ivFunction · 0.85
GetOpenFileMethod · 0.80
GetConfigMethod · 0.80

Tested by

no test coverage detected