MCPcopy Create free account
hub / github.com/ModOrganizer2/modorganizer / getSecurityDescriptor

Function getSecurityDescriptor

src/envsecurity.cpp:421–462  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

419};
420
421MallocPtr<SECURITY_DESCRIPTOR> getSecurityDescriptor(const QString& path)
422{
423 const auto wpath = path.toStdWString();
424 BOOL ret = FALSE;
425
426 DWORD length = 0;
427 ret = ::GetFileSecurityW(wpath.c_str(),
428 DACL_SECURITY_INFORMATION | OWNER_SECURITY_INFORMATION,
429 nullptr, 0, &length);
430
431 if (!ret || length == 0) {
432 const auto e = GetLastError();
433
434 if (e != ERROR_INSUFFICIENT_BUFFER) {
435 if (e == ERROR_ACCESS_DENIED) {
436 // if this fails, the user doesn't even have permissions to get the
437 // security descriptor, which probably means they're not the owner and
438 // their effective access is none
439 throw failed(e, "cannot get security descriptor");
440 } else {
441 // other error
442 throw failed(e, "GetFileSecurity() for length failed");
443 }
444 }
445 }
446
447 MallocPtr<SECURITY_DESCRIPTOR> sd(
448 static_cast<SECURITY_DESCRIPTOR*>(std::malloc(length)));
449
450 std::memset(sd.get(), 0, length);
451
452 ret = ::GetFileSecurityW(wpath.c_str(),
453 DACL_SECURITY_INFORMATION | OWNER_SECURITY_INFORMATION,
454 sd.get(), length, &length);
455
456 if (!ret) {
457 const auto e = GetLastError();
458 throw failed(e, "GetFileSecurity()");
459 }
460
461 return sd;
462}
463
464PACL getDacl(SECURITY_DESCRIPTOR* sd)
465{

Callers 1

getFileSecurityFunction · 0.85

Calls 2

failedClass · 0.70
getMethod · 0.45

Tested by

no test coverage detected