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

Function AddSeSecurityNamePrivilege

cppcryptfs/dokan/cryptdokan.cpp:245–302  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

243}
244
245static BOOL AddSeSecurityNamePrivilege() {
246
247 HANDLE token = 0;
248 DbgPrint(
249 L"## Attempting to add SE_SECURITY_NAME privilege to process token ##\n");
250 DWORD err;
251 LUID luid;
252 if (!LookupPrivilegeValue(0, SE_SECURITY_NAME, &luid)) {
253 err = GetLastError();
254 if (err != ERROR_SUCCESS) {
255 DbgPrint(L" failed: Unable to lookup privilege value. error = %u\n",
256 err);
257 return FALSE;
258 }
259 }
260
261 LUID_AND_ATTRIBUTES attr;
262 attr.Attributes = SE_PRIVILEGE_ENABLED;
263 attr.Luid = luid;
264
265 TOKEN_PRIVILEGES priv;
266 priv.PrivilegeCount = 1;
267 priv.Privileges[0] = attr;
268
269 if (!OpenProcessToken(GetCurrentProcess(),
270 TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY, &token)) {
271 err = GetLastError();
272 if (err != ERROR_SUCCESS) {
273 DbgPrint(L" failed: Unable obtain process token. error = %u\n", err);
274 return FALSE;
275 }
276 }
277
278 TOKEN_PRIVILEGES oldPriv;
279 DWORD retSize;
280 AdjustTokenPrivileges(token, FALSE, &priv, sizeof(TOKEN_PRIVILEGES), &oldPriv,
281 &retSize);
282 err = GetLastError();
283 if (err != ERROR_SUCCESS) {
284 DbgPrint(L" failed: Unable to adjust token privileges: %u\n", err);
285 CloseHandle(token);
286 return FALSE;
287 }
288
289 BOOL privAlreadyPresent = FALSE;
290 for (unsigned int i = 0; i < oldPriv.PrivilegeCount; i++) {
291 if (oldPriv.Privileges[i].Luid.HighPart == luid.HighPart &&
292 oldPriv.Privileges[i].Luid.LowPart == luid.LowPart) {
293 privAlreadyPresent = TRUE;
294 break;
295 }
296 }
297 DbgPrint(privAlreadyPresent ? L" success: privilege already present\n"
298 : L" success: privilege added\n");
299 if (token)
300 CloseHandle(token);
301 return TRUE;
302}

Callers 1

Calls 1

DbgPrintFunction · 0.85

Tested by

no test coverage detected