1 /* Copyright (c) 2019, IBM.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; version 2 of the License.
6
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 GNU General Public License for more details.
11
12 You should have received a copy of the GNU General Public License
13 along with this program; if not, write to the Free Software
14 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1335 USA */
15
16 #include "mysys_priv.h"
17
my_obtain_privilege(LPCSTR lpPrivilege)18 BOOL my_obtain_privilege(LPCSTR lpPrivilege)
19 {
20 HANDLE hAccessToken;
21 TOKEN_PRIVILEGES token;
22 BOOL ret_value= FALSE;
23
24 if (!OpenProcessToken(GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &hAccessToken))
25 {
26 return FALSE;
27 }
28
29 if (!LookupPrivilegeValue(NULL, lpPrivilege, &token.Privileges[0].Luid))
30 return FALSE;
31
32 token.PrivilegeCount= 1;
33 token.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
34
35 ret_value= AdjustTokenPrivileges(hAccessToken, FALSE, &token, 0, NULL, NULL);
36
37 if (!ret_value || (GetLastError() != ERROR_SUCCESS))
38 return FALSE;
39
40 CloseHandle(hAccessToken);
41 return TRUE;
42 }
43