33#include "common/io.h"
44#include "common/windows/nt.h"
55
6+ #include <ntstatus.h>
67#include <windows.h>
78
89const char * enablePrivilege (const wchar_t * privilege )
910{
1011 FF_AUTO_CLOSE_FD HANDLE token = NULL ;
11- if (!OpenProcessToken ( NtCurrentProcess (), TOKEN_ADJUST_PRIVILEGES | TOKEN_QUERY , & token ))
12- return "OpenProcessToken () failed" ;
12+ if (!NT_SUCCESS ( NtOpenProcessToken ( NtCurrentProcess (), TOKEN_ADJUST_PRIVILEGES , & token ) ))
13+ return "NtOpenProcessToken () failed" ;
1314
1415 TOKEN_PRIVILEGES tp = {
1516 .PrivilegeCount = 1 ,
@@ -20,19 +21,21 @@ const char* enablePrivilege(const wchar_t* privilege)
2021 if (!LookupPrivilegeValueW (NULL , privilege , & tp .Privileges [0 ].Luid ))
2122 return "LookupPrivilegeValue() failed" ;
2223
23- if (!AdjustTokenPrivileges (token , false, & tp , sizeof (tp ), NULL , NULL ))
24- return "AdjustTokenPrivileges() failed" ;
24+ NTSTATUS status = NtAdjustPrivilegesToken (token , false, & tp , sizeof (tp ), NULL , NULL );
25+ if (!NT_SUCCESS (status ))
26+ return "NtAdjustPrivilegesToken() failed" ;
2527
26- if (GetLastError () == ERROR_NOT_ALL_ASSIGNED )
27- return "The token does not have the specified privilege" ;
28+ if (status == STATUS_NOT_ALL_ASSIGNED )
29+ return "The token does not have the specified privilege; try sudo please " ;
2830
2931 return NULL ;
3032}
3133
3234const char * ffDetectBootmgr (FFBootmgrResult * result )
3335{
34- if (enablePrivilege (L"SeSystemEnvironmentPrivilege" ) != NULL )
35- return "Failed to enable SeSystemEnvironmentPrivilege" ;
36+ const char * err = enablePrivilege (L"SeSystemEnvironmentPrivilege" );
37+ if (err != NULL )
38+ return err ;
3639
3740 GUID efiGlobalGuid ;
3841 if (!NT_SUCCESS (RtlGUIDFromString (& (UNICODE_STRING ) RTL_CONSTANT_STRING (L"{" FF_EFI_GLOBAL_GUID L"}" ), & efiGlobalGuid )))
0 commit comments