ReactOS 0.4.16-dev-1946-g52006dd
powrprof.c
Go to the documentation of this file.
1/*
2 * Copyright (C) 2005 Benjamin Cutler
3 * Copyright (C) 2008 Dmitry Chapyshev
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2.1 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
18 */
19
20
21#include <stdarg.h>
22
23#define WIN32_NO_STATUS
24#include <windef.h>
25#include <winbase.h>
26#include <winreg.h>
27#define NTOS_MODE_USER
28#include <ndk/pofuncs.h>
29#include <ndk/rtlfuncs.h>
30#include <ndk/setypes.h>
31#include <powrprof.h>
32#include <wine/debug.h>
33#include <wine/unicode.h>
34
36
37
38static const WCHAR szPowerCfgSubKey[] =
39 L"Software\\Microsoft\\Windows\\CurrentVersion\\Controls Folder\\PowerCfg";
41 L"Control Panel\\PowerCfg";
43 L"CurrentPowerPolicy";
44static const WCHAR szPolicies[] = L"Policies";
45static const WCHAR szName[] = L"Name";
46static const WCHAR szDescription[] = L"Description";
47static const WCHAR szDiskMax[] = L"DiskSpindownMax";
48static const WCHAR szDiskMin[] = L"DiskSpindownMin";
49static const WCHAR szLastID[] = L"LastID";
50
51static UINT g_LastID = (UINT)-1;
53
54
69static BOOLEAN
71 _Out_ PSECURITY_DESCRIPTOR *PowrProfSd)
72{
74 PSID AuthenticatedUsersSid = NULL, SystemSid = NULL, AdminsSid = NULL;
75 PACL Dacl = NULL;
77 ULONG DaclSize, RelSDSize = 0;
80
82 1,
84 0, 0, 0, 0, 0, 0, 0,
85 &AuthenticatedUsersSid))
86 {
87 return FALSE;
88 }
89
91 1,
93 0, 0, 0, 0, 0, 0, 0,
94 &SystemSid))
95 {
96 goto Quit;
97 }
98
100 2,
103 0, 0, 0, 0, 0, 0,
104 &AdminsSid))
105 {
106 goto Quit;
107 }
108
110 goto Quit;
111
112 /* Compute the size needed for the DACL and allocate it */
113 DaclSize = sizeof(ACL) +
114 sizeof(ACCESS_ALLOWED_ACE) + GetLengthSid(AuthenticatedUsersSid) +
115 sizeof(ACCESS_ALLOWED_ACE) + GetLengthSid(SystemSid) +
116 sizeof(ACCESS_ALLOWED_ACE) + GetLengthSid(AdminsSid);
117
120 goto Quit;
121
125 AuthenticatedUsersSid))
126 {
127 goto Quit;
128 }
129
133 SystemSid))
134 {
135 goto Quit;
136 }
137
141 AdminsSid))
142 {
143 goto Quit;
144 }
145
147 goto Quit;
148
149 if (!SetSecurityDescriptorOwner(&AbsSd, AdminsSid, FALSE))
150 goto Quit;
151
152 if (!SetSecurityDescriptorGroup(&AbsSd, SystemSid, FALSE))
153 goto Quit;
154
155 /* Retrieve the size needed for the relative SD */
156 if (MakeSelfRelativeSD(&AbsSd, NULL, &RelSDSize) ||
158 {
159 goto Quit;
160 }
161
162 /* Build the relative SD */
163 RelSd = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, RelSDSize);
164 if (!RelSd || !MakeSelfRelativeSD(&AbsSd, RelSd, &RelSDSize))
165 {
166 if (RelSd)
167 HeapFree(GetProcessHeap(), 0, RelSd);
168 goto Quit;
169 }
170
171 *PowrProfSd = RelSd;
172 Success = TRUE;
173
174Quit:
175 if (Dacl)
177
178 if (AdminsSid)
179 FreeSid(AdminsSid);
180
181 if (SystemSid)
182 FreeSid(SystemSid);
183
184 if (AuthenticatedUsersSid)
185 FreeSid(AuthenticatedUsersSid);
186
187 return Success;
188}
189
204static BOOLEAN
206{
207 SECURITY_ATTRIBUTES SecAttrs;
209 HANDLE hSemaphore;
210 DWORD dwError;
211
212 while (TRUE)
213 {
214 /* Return early if we have already obtained the semaphore handle */
215 if (PPRegSemaphore)
216 return TRUE;
217
218 /*
219 * Suppose first that the semaphore already exists and try only to open it
220 * with the necessary access rights. The semaphore may have been created
221 * by another instance from a different user (e.g. powrprof.dll loaded by
222 * a LocalSystem service) and attempting to create-or-open it instead would
223 * fail with ERROR_ACCESS_DENIED.
224 */
226 FALSE, L"PowerProfileRegistrySemaphore");
227 if (hSemaphore)
228 break;
229 dwError = GetLastError();
230 if (dwError == ERROR_ACCESS_DENIED)
231 {
232 ERR("Couldn't open POWRPROF semaphore: %ld\n", dwError);
233 return FALSE;
234 }
235
236 /* The semaphore may not exist. Create it so that all logged-in users
237 * can access it with the necessary but limited access rights. */
239 {
240 ERR("Couldn't create POWRPROF semaphore security descriptor\n");
241 return FALSE;
242 }
243 // TODO: Consider using no SD (or no security attributes i.e. falling back to defaults?) if creating the SD failed.
244
245 SecAttrs.nLength = sizeof(SecAttrs);
246 SecAttrs.lpSecurityDescriptor = Sd;
247 SecAttrs.bInheritHandle = FALSE;
248
249 hSemaphore = CreateSemaphoreW(&SecAttrs, 1, 1, L"PowerProfileRegistrySemaphore");
250 dwError = GetLastError();
251 HeapFree(GetProcessHeap(), 0, Sd);
252 if (hSemaphore)
253 break;
254
255 /* If a process from a different user created the semaphore in the
256 * meantime, we failed with ERROR_ACCESS_DENIED. Then, retry again
257 * by only opening the semaphore this time. Otherwise, bail out. */
258 if (dwError != ERROR_ACCESS_DENIED)
259 {
260 ERR("Couldn't create POWRPROF semaphore: %ld\n", dwError);
261 return FALSE;
262 }
263 }
264
265 /* Store the handle; if another thread already succeeded, close the handle */
267 CloseHandle(hSemaphore);
268 return TRUE;
269}
270
271static BOOLEAN
273{
275 return FALSE;
277}
278
279
280BOOLEAN WINAPI WritePwrPolicy(PUINT puiID, PPOWER_POLICY pPowerPolicy);
281
284 PVOID lpInputBuffer,
285 ULONG nInputBufferSize,
286 PVOID lpOutputBuffer,
287 ULONG nOutputBufferSize)
288{
289 BOOLEAN old;
290
291 //Lohnegrim: In order to get the right results, we have to adjust our Privileges
294
295 return NtPowerInformation(InformationLevel,
296 lpInputBuffer,
297 nInputBufferSize,
298 lpOutputBuffer,
299 nOutputBufferSize);
300}
301
304{
305 HKEY hKey = NULL;
306 LONG Ret;
307
308 TRACE("()\n");
309
311 if (Ret != ERROR_SUCCESS)
312 {
313 TRACE("RegOpenKeyEx failed: %d\n", Ret);
314 SetLastError(Ret);
315 return FALSE;
316 }
317
319 return TRUE;
320}
321
324{
325 WCHAR Buf[MAX_PATH];
326 UINT Current;
327 LONG Err;
328
329 swprintf(Buf, L"Control Panel\\PowerCfg\\PowerPolicies\\%d", uiIndex);
330
331 if (!GetActivePwrScheme(&Current))
332 return FALSE;
333
334 if (Current == uiIndex)
335 {
337 return FALSE;
338 }
339
341 if (Err != ERROR_SUCCESS)
342 {
343 TRACE("RegDeleteKey failed: %d\n", Err);
344 SetLastError(Err);
345 return FALSE;
346 }
347
348 return TRUE;
349}
350
351static BOOLEAN
353 PUSER_POWER_POLICY puserPwrPolicy,
355 DWORD cchDesc, LPWSTR szDesc)
356{
357 HKEY hSubKey = NULL;
359 LONG Err;
361 BOOL bRet = FALSE;
362
363 swprintf(szPath, L"Control Panel\\PowerCfg\\PowerPolicies\\%s", szNum);
364
365 Err = RegOpenKeyExW(HKEY_CURRENT_USER, szPath, 0, KEY_READ, &hSubKey);
366 if (Err != ERROR_SUCCESS)
367 {
368 ERR("RegOpenKeyExW failed: %d\n", Err);
369 SetLastError(Err);
370 return FALSE;
371 }
372
373 dwSize = cchName * sizeof(WCHAR);
374 Err = RegQueryValueExW(hSubKey, L"Name", NULL, NULL, (LPBYTE)szName, &dwSize);
375 if (Err != ERROR_SUCCESS)
376 {
377 ERR("RegQueryValueExW failed: %d\n", Err);
378 SetLastError(Err);
379 goto cleanup;
380 }
381
382 dwSize = cchDesc * sizeof(WCHAR);
383 Err = RegQueryValueExW(hSubKey, L"Description", NULL, NULL, (LPBYTE)szDesc, &dwSize);
384 if (Err != ERROR_SUCCESS)
385 {
386 ERR("RegQueryValueExW failed: %d\n", Err);
387 SetLastError(Err);
388 goto cleanup;
389 }
390
391 dwSize = sizeof(USER_POWER_POLICY);
392 Err = RegQueryValueExW(hSubKey, L"Policies", NULL, NULL, (LPBYTE)puserPwrPolicy, &dwSize);
393 if (Err != ERROR_SUCCESS)
394 {
395 ERR("RegQueryValueExW failed: %d\n", Err);
396 SetLastError(Err);
397 goto cleanup;
398 }
399
400 bRet = TRUE;
401
402cleanup:
403 RegCloseKey(hSubKey);
404
405 return bRet;
406}
407
408static BOOLEAN
410{
411 HKEY hKey;
412 LONG Err;
415
416 swprintf(szPath, L"Software\\Microsoft\\Windows\\CurrentVersion\\Controls Folder\\PowerCfg\\PowerPolicies\\%s", szNum);
417
419 if (Err != ERROR_SUCCESS)
420 {
421 ERR("RegOpenKeyExW failed: %d\n", Err);
422 SetLastError(Err);
423 return FALSE;
424 }
425
427 Err = RegQueryValueExW(hKey, L"Policies", NULL, NULL, (LPBYTE)pmachinePwrPolicy, &dwSize);
428
429 if (Err != ERROR_SUCCESS)
430 {
431 ERR("RegQueryValueExW failed: %d\n", Err);
432 SetLastError(Err);
434 return FALSE;
435 }
436
438
439 return TRUE;
440}
441
443EnumPwrSchemes(PWRSCHEMESENUMPROC lpfnPwrSchemesEnumProc,
445{
446 HKEY hKey;
447 LONG Err;
448 DWORD dwSize, dwNameSize = MAX_PATH, dwDescSize = MAX_PATH, dwIndex = 0;
449 WCHAR szNum[3 + 1], szName[MAX_PATH], szDesc[MAX_PATH];
450 POWER_POLICY PwrPolicy;
451 USER_POWER_POLICY userPwrPolicy;
452 MACHINE_POWER_POLICY machinePwrPolicy;
453 BOOLEAN bRet = FALSE;
454
455 if (!lpfnPwrSchemesEnumProc)
456 {
458 return FALSE;
459 }
460
461 Err = RegOpenKeyExW(HKEY_CURRENT_USER, L"Control Panel\\PowerCfg\\PowerPolicies", 0, KEY_READ, &hKey);
462 if (Err != ERROR_SUCCESS)
463 {
464 ERR("RegOpenKeyW failed: %d\n", Err);
465 SetLastError(Err);
466 return FALSE;
467 }
468
470
471 dwSize = sizeof(szNum) / sizeof(WCHAR);
472
473 while (RegEnumKeyExW(hKey, dwIndex, szNum, &dwSize, NULL, NULL, NULL, NULL) == ERROR_SUCCESS)
474 {
475 if (!POWRPROF_GetUserPowerPolicy(szNum, &userPwrPolicy,
476 dwNameSize, szName,
477 dwDescSize, szDesc))
478 {
479 WARN("POWRPROF_GetUserPowerPolicy failed\n");
480 goto cleanup;
481 }
482
483 if (!POWRPROF_GetMachinePowerPolicy(szNum, &machinePwrPolicy))
484 {
485 WARN("POWRPROF_GetMachinePowerPolicy failed\n");
486 goto cleanup;
487 }
488
489 memcpy(&PwrPolicy.user, &userPwrPolicy, sizeof(USER_POWER_POLICY));
490 memcpy(&PwrPolicy.mach, &machinePwrPolicy, sizeof(MACHINE_POWER_POLICY));
491
492 if (!lpfnPwrSchemesEnumProc(_wtoi(szNum), (wcslen(szName) + 1) * sizeof(WCHAR), szName, (wcslen(szDesc) + 1) * sizeof(WCHAR), szDesc, &PwrPolicy, lParam))
493 goto cleanup;
494 else
495 bRet = TRUE;
496
497 dwSize = sizeof(szNum) / sizeof(WCHAR);
498 dwIndex++;
499 }
500
501cleanup:
504
505 return bRet;
506}
507
510{
511 HKEY hKey;
512 WCHAR szBuf[MAX_PATH];
514 LONG Err;
515
516 TRACE("GetActivePwrScheme(%u)", puiID);
517
518 Err = RegOpenKeyExW(HKEY_CURRENT_USER, L"Control Panel\\PowerCfg", 0, KEY_READ, &hKey);
519 if (Err != ERROR_SUCCESS)
520 {
521 ERR("RegOpenKey failed: %d\n", Err);
522 SetLastError(Err);
523 return FALSE;
524 }
525
526 dwSize = sizeof(szBuf);
527 Err = RegQueryValueExW(hKey, L"CurrentPowerPolicy",
528 NULL, NULL,
529 (LPBYTE)&szBuf, &dwSize);
530 if (Err != ERROR_SUCCESS)
531 {
532 ERR("RegQueryValueEx failed: %d\n", Err);
534 SetLastError(Err);
535 return FALSE;
536 }
537
539 *puiID = _wtoi(szBuf);
540
541 return TRUE;
542}
543
546 PPOWER_POLICY pPowerPolicy)
547{
548 /*
549 SYSTEM_POWER_POLICY ACPower, DCPower;
550
551 FIXME("(%p, %p) stub!\n", pGlobalPowerPolicy, pPowerPolicy);
552
553 NtPowerInformation(SystemPowerPolicyAc, 0, 0, &ACPower, sizeof(SYSTEM_POWER_POLICY));
554 NtPowerInformation(SystemPowerPolicyDc, 0, 0, &DCPower, sizeof(SYSTEM_POWER_POLICY));
555
556 return FALSE;
557 */
558/*
559 Lohnegrim: I don't know why this Function should call NtPowerInformation, because as far as I know,
560 it simply returns the GlobalPowerPolicy and the AktivPowerScheme!
561 */
562 UINT uiID;
563
564 if (pGlobalPowerPolicy != NULL)
565 {
566 if (!ReadGlobalPwrPolicy(pGlobalPowerPolicy))
567 return FALSE;
568 }
569 if (pPowerPolicy != NULL)
570 {
571 if (!GetActivePwrScheme(&uiID))
572 return FALSE;
573
574 if (!ReadPwrScheme(uiID, pPowerPolicy))
575 return FALSE;
576 }
577
578 return TRUE;
579}
580
583{
585
586 TRACE("(%p)\n", lpSystemPowerCapabilities);
587
588 if (!lpSystemPowerCapabilities)
589 {
591 return FALSE;
592 }
593
594 Status = NtPowerInformation(SystemPowerCapabilities, 0, 0, lpSystemPowerCapabilities, sizeof(SYSTEM_POWER_CAPABILITIES));
595 if(!NT_SUCCESS(Status))
596 {
598 return FALSE;
599 }
600
601 return TRUE;
602}
603
606{
607 HKEY hKey;
608 BYTE lpValue[40];
609 LONG Ret;
610 DWORD cbValue = sizeof(lpValue);
611
612 TRACE("(%p, %p)\n", RangeMax, RangeMin);
613
614 if (RangeMax == NULL || RangeMin == NULL)
615 {
617 return FALSE;
618 }
619
621 return FALSE;
622
624 if (Ret != ERROR_SUCCESS)
625 {
626 TRACE("RegOpenKeyEx failed: %d\n", Ret);
627 TRACE("Using defaults: 3600, 3\n");
628 *RangeMax = 3600;
629 *RangeMin = 3;
631 return TRUE;
632 }
633
634 Ret = RegQueryValueExW(hKey, szDiskMax, 0, 0, lpValue, &cbValue);
635 if (Ret != ERROR_SUCCESS)
636 {
637 TRACE("Couldn't open DiskSpinDownMax: %d\n", Ret);
638 TRACE("Using default: 3600\n");
639 *RangeMax = 3600;
640 }
641 else
642 {
643 *RangeMax = _wtoi((LPCWSTR)lpValue);
644 }
645
646 cbValue = sizeof(lpValue);
647
648 Ret = RegQueryValueExW(hKey, szDiskMin, 0, 0, lpValue, &cbValue);
649 if (Ret != ERROR_SUCCESS)
650 {
651 TRACE("Couldn't open DiskSpinDownMin: %d\n", Ret);
652 TRACE("Using default: 3\n");
653 *RangeMin = 3;
654 }
655 else
656 {
657 *RangeMin = _wtoi((LPCWSTR)lpValue);
658 }
659
661
663
664 return TRUE;
665}
666
669{
670 FIXME("( %p) stub!\n", p);
671 return FALSE;
672}
673
676{
679 BOOLEAN old;
680
682
683 Status = NtPowerInformation(SystemPowerCapabilities, NULL, 0, &PowerCaps, sizeof(PowerCaps));
684 if (!NT_SUCCESS(Status))
685 {
687 return FALSE;
688 }
689
690 return IS_PWR_HIBERNATE_ALLOWED(&PowerCaps);
691}
692
695{
698 BOOLEAN old;
699
701
702 Status = NtPowerInformation(SystemPowerCapabilities, NULL, 0, &PowerCaps, sizeof(PowerCaps));
703 if (!NT_SUCCESS(Status))
704 {
706 return FALSE;
707 }
708
709 return IS_PWR_POWEROFF_ALLOWED(&PowerCaps);
710}
711
714{
717 BOOLEAN old;
718
720
721 Status = NtPowerInformation(SystemPowerCapabilities, NULL, 0, &PowerCaps, sizeof(PowerCaps));
722 if (!NT_SUCCESS(Status))
723 {
725 return FALSE;
726 }
727
728 // NOTE for possible future wine-syncs: wine erroneously use '&&'
729 // instead of: PowerCaps.SystemS1 || PowerCaps.SystemS2 || PowerCaps.SystemS3;
730 return IS_PWR_SUSPEND_ALLOWED(&PowerCaps);
731}
732
734PowerGetActiveScheme(HKEY UserRootPowerKey, GUID **polguid)
735{
736 FIXME("(%p,%p) stub!\n", UserRootPowerKey, polguid);
738}
739
740DWORD WINAPI PowerSetActiveScheme(HKEY UserRootPowerKey, GUID *polguid)
741{
742 FIXME("(%p,%s) stub!\n", UserRootPowerKey, wine_dbgstr_guid(polguid));
743 return ERROR_SUCCESS;
744}
745
747PowerReadDCValue(HKEY RootPowerKey, const GUID *Scheme, const GUID *SubGroup, const GUID *PowerSettings, PULONG Type, PUCHAR Buffer, DWORD *BufferSize)
748{
749 FIXME("(%p,%s,%s,%s,%p,%p,%p) stub!\n", RootPowerKey, debugstr_guid(Scheme), debugstr_guid(SubGroup), debugstr_guid(PowerSettings), Type, Buffer, BufferSize);
751}
752
753DWORD WINAPI PowerReadFriendlyName(HKEY RootPowerKey, const GUID *Scheme,
754 const GUID *SubGroup, const GUID *PowerSettings, UCHAR *Buffer,
756{
757 FIXME("(%p,%s,%s,%s,%p,%p) stub!\n", RootPowerKey, debugstr_guid(Scheme), debugstr_guid(SubGroup), debugstr_guid(PowerSettings), Buffer, BufferSize);
759}
760
762{
763 FIXME("stub\n");
764 return PlatformRoleDesktop;
765}
766
768{
769 FIXME("%lu stub.\n", version);
770 return PlatformRoleDesktop;
771}
772
775{
776 FIXME("(%p,%s,%s,%d,%ld,%p,%p) stub!\n", key, debugstr_guid(scheme), debugstr_guid(subgroup),
779}
780
782{
783 FIXME("(0x%08lx,%p,%p) stub!\n", flags, recipient, handle);
784 *handle = (HPOWERNOTIFY)0xdeadbeef;
785 return ERROR_SUCCESS;
786}
787
789{
790 FIXME("(%p) stub!\n", handle);
791 return ERROR_SUCCESS;
792}
793
795{
796 FIXME("(%s,0x%08lx,%p,%p) stub!\n", debugstr_guid(setting), flags, recipient, handle);
797 *handle = (PHPOWERNOTIFY)0xdeadbeef;
798 return ERROR_SUCCESS;
799}
800
802{
803 FIXME("(%p) stub!\n", handle);
804 return ERROR_SUCCESS;
805}
806
808{
809 FIXME("(%p,%s,%s,%s,0x%08lx) stub!\n", key, debugstr_guid(scheme), debugstr_guid(subgroup), debugstr_guid(setting), index);
810 return ERROR_SUCCESS;
811}
812
814 HKEY key,
815 const GUID *scheme,
816 const GUID *subgroup,
817 const GUID *setting,
819)
820{
821 FIXME("(%p,%s,%s,%s,0x%08lx) stub!\n", key, debugstr_guid(scheme), debugstr_guid(subgroup), debugstr_guid(setting), index);
822 return ERROR_SUCCESS;
823}
824
826 HKEY key,
827 const GUID *scheme,
828 const GUID *subgroup,
829 const GUID *setting,
830 LPDWORD AcValueIndex
831)
832{
833 FIXME("(%p,%s,%s,%s,0x%08lx) stub!\n", key, debugstr_guid(scheme), debugstr_guid(subgroup), debugstr_guid(setting));
834 return ERROR_SUCCESS;
835}
836
838 HKEY key,
839 const GUID *scheme,
840 const GUID *subgroup,
841 const GUID *setting,
842 LPDWORD DcValuetIndex
843)
844{
845 FIXME("(%p,%s,%s,%s,0x%08lx) stub!\n", key, debugstr_guid(scheme), debugstr_guid(subgroup), debugstr_guid(setting));
846 return ERROR_SUCCESS;
847}
848
850PowerReadACValue(HKEY RootPowerKey, const GUID *Scheme, const GUID *SubGroup, const GUID *PowerSettings, PULONG Type, PUCHAR Buffer, DWORD *BufferSize)
851{
852 FIXME("(%p,%s,%s,%s,%p,%p,%p) stub!\n", RootPowerKey, debugstr_guid(Scheme), debugstr_guid(SubGroup), debugstr_guid(PowerSettings), Type, Buffer, BufferSize);
854}
855
858{
859 GLOBAL_MACHINE_POWER_POLICY glMachPwrPolicy;
860 GLOBAL_USER_POWER_POLICY glUserPwrPolicy;
861 HKEY hKey = NULL;
863 LONG Err;
864 BOOL bRet = FALSE;
865
867
868 // Getting user global power policy
869 Err = RegOpenKeyExW(HKEY_CURRENT_USER, L"Control Panel\\PowerCfg\\GlobalPowerPolicy", 0, KEY_READ, &hKey);
870 if (Err != ERROR_SUCCESS)
871 {
872 ERR("RegOpenKeyW failed: %d\n", Err);
873 SetLastError(Err);
874 goto cleanup;
875 }
876
877 dwSize = sizeof(glUserPwrPolicy);
878 Err = RegQueryValueExW(hKey, L"Policies", NULL, NULL, (LPBYTE)&glUserPwrPolicy, &dwSize);
879 if (Err != ERROR_SUCCESS)
880 {
881 ERR("RegQueryValueExW failed: %d\n", Err);
882 SetLastError(Err);
883 goto cleanup;
884 }
885
887
888 // Getting machine global power policy
889 Err = RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Controls Folder\\PowerCfg\\GlobalPowerPolicy", 0, KEY_READ, &hKey);
890 if (Err != ERROR_SUCCESS)
891 {
892 ERR("RegOpenKeyW failed: %d\n", Err);
893 SetLastError(Err);
894 goto cleanup;
895 }
896
897 dwSize = sizeof(glMachPwrPolicy);
898 Err = RegQueryValueExW(hKey, L"Policies", NULL, NULL, (LPBYTE)&glMachPwrPolicy, &dwSize);
899 if (Err != ERROR_SUCCESS)
900 {
901 ERR("RegQueryValueExW failed: %d\n", Err);
902 SetLastError(Err);
903 goto cleanup;
904 }
905
906 memcpy(&pGlobalPowerPolicy->user, &glUserPwrPolicy, sizeof(GLOBAL_USER_POWER_POLICY));
907 memcpy(&pGlobalPowerPolicy->mach, &glMachPwrPolicy, sizeof(GLOBAL_MACHINE_POWER_POLICY));
908 bRet = TRUE;
909
910cleanup:
911 if(hKey)
914
915 return bRet;
916}
917
918
921 PMACHINE_PROCESSOR_POWER_POLICY pMachineProcessorPowerPolicy)
922{
923 HKEY hKey;
926
927 swprintf(szPath, L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Controls Folder\\PowerCfg\\ProcessorPolicies\\%i", uiID);
929 return FALSE;
930
931 if (RegQueryValueExW(hKey, szPolicies, NULL, 0, (LPBYTE)pMachineProcessorPowerPolicy, &dwSize) == ERROR_SUCCESS)
932 {
934 return TRUE;
935 }
936
938 if (uiID != 0)
939 return ReadProcessorPwrScheme(0, pMachineProcessorPowerPolicy);
940
941 return FALSE;
942}
943
944
947 PPOWER_POLICY pPowerPolicy)
948{
949 USER_POWER_POLICY userPwrPolicy;
950 MACHINE_POWER_POLICY machinePwrPolicy;
951 WCHAR szNum[16]; // max number - 999
952
954
955 swprintf(szNum, L"%d", uiID);
956
957 if (!POWRPROF_GetUserPowerPolicy(szNum, &userPwrPolicy, 0, NULL, 0, NULL))
958 {
960 return FALSE;
961 }
962
963 if (!POWRPROF_GetMachinePowerPolicy(szNum, &machinePwrPolicy))
964 {
966 return FALSE;
967 }
968
969 memcpy(&pPowerPolicy->user, &userPwrPolicy, sizeof(userPwrPolicy));
970 memcpy(&pPowerPolicy->mach, &machinePwrPolicy, sizeof(machinePwrPolicy));
971
973
974 return TRUE;
975}
976
979 PGLOBAL_POWER_POLICY lpGlobalPowerPolicy,
980 PPOWER_POLICY lpPowerPolicy)
981{
982 POWER_POLICY tmp;
983 HKEY hKey;
984 WCHAR Buf[16];
985
986 if (!ReadPwrScheme(uiID, &tmp))
987 return FALSE;
988
990 return FALSE;
991
992 swprintf(Buf, L"%i", uiID);
993
995 {
997 return FALSE;
998 }
1000
1001 if (lpGlobalPowerPolicy != NULL || lpPowerPolicy != NULL)
1002 {
1003 if (!ValidatePowerPolicies(lpGlobalPowerPolicy, lpPowerPolicy))
1004 return FALSE;
1005
1006 if (lpGlobalPowerPolicy != NULL && !WriteGlobalPwrPolicy(lpGlobalPowerPolicy))
1007 return FALSE;
1008
1009 if (lpPowerPolicy != NULL && !WritePwrPolicy(&uiID,lpPowerPolicy))
1010 return FALSE;
1011 }
1012
1013 return TRUE;
1014}
1015
1018 BOOLEAN ForceCritical,
1019 BOOLEAN DisableWakeEvent)
1020{
1021 FIXME("(%d, %d, %d) stub!\n", Hibernate, ForceCritical, DisableWakeEvent);
1022 return TRUE;
1023}
1024
1027{
1028 HKEY hKey;
1031
1032 gupp = pGlobalPowerPolicy->user;
1033 gmpp = pGlobalPowerPolicy->mach;
1034
1036 L"Control Panel\\PowerCfg\\GlobalPowerPolicy",
1037 0,
1038 KEY_WRITE,
1039 &hKey) != ERROR_SUCCESS)
1040 return FALSE;
1041
1042 if (RegSetValueExW(hKey, szPolicies, 0, REG_BINARY, (PBYTE)&gupp, sizeof(gupp)) != ERROR_SUCCESS)
1043 {
1045 return FALSE;
1046 }
1047
1049
1051 L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Controls Folder\\PowerCfg\\GlobalPowerPolicy",
1052 0,
1054 &hKey))
1055 return FALSE;
1056
1057 if (RegSetValueExW(hKey,szPolicies, 0, REG_BINARY, (PBYTE)&gmpp, sizeof(gmpp)) != ERROR_SUCCESS)
1058 {
1060 return FALSE;
1061 }
1062
1064 return TRUE;
1065}
1066
1069 PMACHINE_PROCESSOR_POWER_POLICY pMachineProcessorPowerPolicy)
1070{
1071 WCHAR Buf[MAX_PATH];
1072 HKEY hKey;
1073
1074 swprintf(Buf, L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Controls Folder\\PowerCfg\\ProcessorPolicies\\%i", ID);
1075
1077 return FALSE;
1078
1079 RegSetValueExW(hKey, szPolicies, 0, REG_BINARY, (PBYTE)pMachineProcessorPowerPolicy, sizeof(MACHINE_PROCESSOR_POWER_POLICY));
1081 return TRUE;
1082}
1083
1084static VOID
1086{
1087 WCHAR Buf[16];
1088 HKEY hKey;
1089
1092 0,
1093 KEY_WRITE,
1094 &hKey) != ERROR_SUCCESS)
1095 return;
1096 swprintf(Buf, L"%i", g_LastID);
1097 RegSetValueExW(hKey, szLastID, 0, REG_SZ, (PBYTE)Buf, strlenW(Buf)*sizeof(WCHAR));
1099}
1100
1103 LPWSTR lpszName,
1104 LPWSTR lpszDescription,
1105 PPOWER_POLICY pPowerPolicy)
1106{
1107 WCHAR Buf[MAX_PATH];
1108 HKEY hKey;
1109
1110 if (*puiID == -1)
1111 {
1112 g_LastID++;
1113 *puiID = g_LastID;
1114 SetLastID();
1115 }
1116
1117 swprintf(Buf, L"Control Panel\\PowerCfg\\PowerPolicies\\%i", *puiID);
1118
1120 return FALSE;
1121
1122 RegSetValueExW(hKey, szName, 0, REG_SZ, (PBYTE)lpszName, strlenW(lpszName)*sizeof(WCHAR));
1123 RegSetValueExW(hKey, szDescription, 0, REG_SZ, (PBYTE)lpszDescription, strlenW(lpszDescription)*sizeof(WCHAR));
1125 return WritePwrPolicy(puiID, pPowerPolicy);
1126}
1127
1128static BOOLEAN
1130{
1131/*
1132 Lohnegrim: this is an Helper function, it checks if the POWERACTIONPOLICY is valid
1133 Also, if the System doesn't support Hibernation, then change the PowerAction
1134*/
1135 switch (pPAP->Action)
1136 {
1137 case PowerActionNone:
1138 return TRUE;
1140 if (PowerCaps.SystemS1 || PowerCaps.SystemS2 || PowerCaps.SystemS3)
1141 pPAP->Action = PowerActionSleep;
1142 else
1144 case PowerActionSleep:
1145 return TRUE;
1147 if (!(PowerCaps.SystemS4 && PowerCaps.HiberFilePresent))
1148 {
1149 if (PowerCaps.SystemS1 || PowerCaps.SystemS2 || PowerCaps.SystemS3)
1150 pPAP->Action = PowerActionSleep;
1151 else
1153 }
1158 return TRUE;
1159 default:
1161 return FALSE;
1162 };
1163}
1164
1165static VOID
1167{
1168 //Lohnegrim: If the System doesn't support the Powerstates, then we have to change them
1169 if (!PowerCaps.SystemS1 && *Psps == PowerSystemSleeping1)
1170 *Psps = PowerSystemSleeping2;
1171 if (!PowerCaps.SystemS2 && *Psps == PowerSystemSleeping2)
1172 *Psps = PowerSystemSleeping3;
1173 if (!PowerCaps.SystemS3 && *Psps == PowerSystemSleeping3)
1174 *Psps = PowerSystemHibernate;
1175 if (!(PowerCaps.SystemS4 && PowerCaps.HiberFilePresent) && *Psps == PowerSystemHibernate)
1176 *Psps = PowerSystemSleeping2;
1177 if (!PowerCaps.SystemS1 && *Psps == PowerSystemSleeping1)
1178 *Psps = PowerSystemSleeping2;
1179 if (!PowerCaps.SystemS2 && *Psps == PowerSystemSleeping2)
1180 *Psps = PowerSystemSleeping3;
1181 if (!PowerCaps.SystemS3 && *Psps == PowerSystemSleeping3)
1182 *Psps = PowerSystemShutdown;
1183
1184}
1185
1188{
1189 SYSTEM_POWER_CAPABILITIES PowerCaps;
1190 NTSTATUS ret;
1191 BOOLEAN old;
1192
1194 ret = NtPowerInformation(SystemPowerCapabilities, NULL, 0, &PowerCaps, sizeof(PowerCaps));
1195 if (ret != STATUS_SUCCESS)
1196 {
1198 return FALSE;
1199 }
1200
1201 if (pGPP)
1202 {
1203 if (pGPP->user.Revision != 1 || pGPP->mach.Revision != 1)
1204 {
1206 return FALSE;
1207 }
1209 {
1211 return FALSE;
1212 }
1213 if ((int)pGPP->mach.LidOpenWakeAc > PowerSystemShutdown)
1214 {
1216 return FALSE;
1217 }
1219 {
1221 return FALSE;
1222 }
1223 if ((int)pGPP->mach.LidOpenWakeDc > PowerSystemShutdown)
1224 {
1226 return FALSE;
1227 }
1228 //Lohnegrim: unneeded
1229 /*if ((pGPP->mach.LidOpenWakeDc < PowerSystemWorking) || (pGPP->mach.LidOpenWakeDc >= PowerSystemMaximum))
1230 {
1231 SetLastError(ERROR_GEN_FAILURE);
1232 return FALSE;
1233 }*/
1234 if (!CheckPowerActionPolicy(&pGPP->user.LidCloseAc,PowerCaps))
1235 {
1236 return FALSE;
1237 }
1238 if (!CheckPowerActionPolicy(&pGPP->user.LidCloseDc,PowerCaps))
1239 {
1240 return FALSE;
1241 }
1242 if (!CheckPowerActionPolicy(&pGPP->user.PowerButtonAc,PowerCaps))
1243 {
1244 return FALSE;
1245 }
1246 if (!CheckPowerActionPolicy(&pGPP->user.PowerButtonDc,PowerCaps))
1247 {
1248 return FALSE;
1249 }
1250 if (!CheckPowerActionPolicy(&pGPP->user.SleepButtonAc,PowerCaps))
1251 {
1252 return FALSE;
1253 }
1254 if (!CheckPowerActionPolicy(&pGPP->user.SleepButtonDc,PowerCaps))
1255 {
1256 return FALSE;
1257 }
1258 //Lohnegrim: The BroadcastCapacityResolution presents the Powerlevel in Percent, if invalid set th 100 == FULL
1259 if (pGPP->mach.BroadcastCapacityResolution > 100)
1261
1262 //Lohnegrim: I have no idea, if they are really needed, or if they are specific for my System, or what they mean, so I removed them
1263 //pGPP->user.DischargePolicy[1].PowerPolicy.EventCode = pGPP->user.DischargePolicy[1].PowerPolicy.EventCode | 0x010000;
1264 //pGPP->user.DischargePolicy[2].PowerPolicy.EventCode = pGPP->user.DischargePolicy[2].PowerPolicy.EventCode | 0x020000;
1265 //pGPP->user.DischargePolicy[3].PowerPolicy.EventCode = pGPP->user.DischargePolicy[3].PowerPolicy.EventCode | 0x030000;
1266
1267 FixSystemPowerState(&pGPP->mach.LidOpenWakeAc,PowerCaps);
1268 FixSystemPowerState(&pGPP->mach.LidOpenWakeDc,PowerCaps);
1269
1270 }
1271
1272 if (pPP)
1273 {
1274 if (pPP->user.Revision != 1 || pPP->mach.Revision != 1)
1275 {
1277 return FALSE;
1278 }
1279
1280 //Lohnegrim: unneeded
1281 //if (pPP->mach.MinSleepAc < PowerSystemWorking)
1282 //{
1283 // SetLastError(ERROR_GEN_FAILURE);
1284 // return FALSE;
1285 //}
1286 if ((int)pPP->mach.MinSleepAc >= PowerSystemShutdown)
1287 {
1289 return FALSE;
1290 }
1291 //Lohnegrim: unneeded
1292 //if (pPP->mach.MinSleepDc < PowerSystemWorking)
1293 //{
1294 // SetLastError(ERROR_GEN_FAILURE);
1295 // return FALSE;
1296 //}
1297 if ((int)pPP->mach.MinSleepDc >= PowerSystemShutdown)
1298 {
1300 return FALSE;
1301 }
1303 {
1305 return FALSE;
1306 }
1308 {
1310 return FALSE;
1311 }
1313 {
1315 return FALSE;
1316 }
1318 {
1320 return FALSE;
1321 }
1322
1323 if (!CheckPowerActionPolicy(&pPP->mach.OverThrottledAc,PowerCaps))
1324 {
1325 return FALSE;
1326 }
1327 if (!CheckPowerActionPolicy(&pPP->mach.OverThrottledDc,PowerCaps))
1328 {
1329 return FALSE;
1330 }
1331 if (!CheckPowerActionPolicy(&pPP->user.IdleAc,PowerCaps))
1332 {
1333 return FALSE;
1334 }
1335 if (!CheckPowerActionPolicy(&pPP->user.IdleDc,PowerCaps))
1336 {
1337 return FALSE;
1338 }
1340 {
1342 return FALSE;
1343 }
1344 //Lohnegrim: unneeded
1345 /*if ((int)pPP->user.MaxSleepAc > PowerSystemShutdown)
1346 {
1347 SetLastError(ERROR_GEN_FAILURE);
1348 return FALSE;
1349 }*/
1351 {
1353 return FALSE;
1354 }
1355 //Lohnegrim: unneeded
1356 /*if ((int)pPP->user.MaxSleepDc >= PowerSystemShutdown)
1357 {
1358 SetLastError(ERROR_GEN_FAILURE);
1359 return FALSE;
1360 }*/
1361 if (PowerCaps.SystemS1)
1362 {
1365 }
1366 else if (PowerCaps.SystemS2)
1367 {
1370 }
1371 else if (PowerCaps.SystemS3)
1372 {
1375 }
1376
1377 if (PowerCaps.SystemS4)
1378 {
1381 }
1382 else if (PowerCaps.SystemS3)
1383 {
1386 }
1387 else if (PowerCaps.SystemS1)
1388 {
1391 }
1392 //Lohnegrim: I don't know where to get this info from, so I removed it
1393 //pPP->user.OptimizeForPowerAc=TRUE;
1394 //pPP->user.OptimizeForPowerDc=TRUE;
1395
1398 }
1399
1401 return TRUE;
1402}
1403
1405{
1406 WCHAR Buf[MAX_PATH];
1407 HKEY hKey;
1408
1409 swprintf(Buf, L"Control Panel\\PowerCfg\\PowerPolicies\\%i", *puiID);
1410
1412 return FALSE;
1413
1414 RegSetValueExW(hKey, szPolicies, 0, REG_BINARY, (const unsigned char *)&pPowerPolicy->user, sizeof(USER_POWER_POLICY));
1416
1417 swprintf(Buf, L"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Controls Folder\\PowerCfg\\PowerPolicies\\%i", *puiID);
1418
1420 return FALSE;
1421
1422 RegSetValueExW(hKey, szPolicies, 0, REG_BINARY, (const unsigned char *)&pPowerPolicy->mach, sizeof(MACHINE_POWER_POLICY));
1424
1425 return TRUE;
1426}
1427
1430{
1431 switch(fdwReason)
1432 {
1433 case DLL_PROCESS_ATTACH:
1434 {
1435 HKEY hKey;
1436 LONG Err;
1437
1438 DisableThreadLibraryCalls(hinstDLL);
1439
1441
1442 if (Err != ERROR_SUCCESS)
1443 {
1444 TRACE("Couldn't open registry key HKLM\\%s, using some sane(?) defaults\n", debugstr_w(szPowerCfgSubKey));
1445 }
1446 else
1447 {
1448 WCHAR lpValue[MAX_PATH];
1449 DWORD cbValue = sizeof(lpValue);
1450
1451 Err = RegQueryValueExW(hKey, szLastID, 0, 0, (BYTE*)lpValue, &cbValue);
1452 if (Err == ERROR_SUCCESS)
1453 {
1454 g_LastID = _wtoi(lpValue);
1455 }
1456 else
1457 {
1458 TRACE("Couldn't open registry entry HKLM\\%s\\LastID, using some sane(?) defaults\n", debugstr_w(szPowerCfgSubKey));
1459 }
1461 }
1462
1463 break;
1464 }
1465 case DLL_PROCESS_DETACH:
1466 if (lpvReserved) break;
1468 break;
1469 }
1470 return TRUE;
1471}
unsigned char BOOLEAN
Type
Definition: Type.h:7
static DWORD const fdwReason
#define WINE_DEFAULT_DEBUG_CHANNEL(t)
Definition: precomp.h:23
LONG NTSTATUS
Definition: precomp.h:26
#define FIXME(fmt,...)
Definition: precomp.h:53
#define WARN(fmt,...)
Definition: precomp.h:61
#define ERR(fmt,...)
Definition: precomp.h:57
static SID_IDENTIFIER_AUTHORITY NtAuthority
Definition: security.c:40
#define RegCloseKey(hKey)
Definition: registry.h:49
Definition: bufpool.h:45
LPARAM lParam
Definition: combotst.c:139
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:33
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3333
LONG WINAPI RegEnumKeyExW(_In_ HKEY hKey, _In_ DWORD dwIndex, _Out_ LPWSTR lpName, _Inout_ LPDWORD lpcbName, _Reserved_ LPDWORD lpReserved, _Out_opt_ LPWSTR lpClass, _Inout_opt_ LPDWORD lpcbClass, _Out_opt_ PFILETIME lpftLastWriteTime)
Definition: reg.c:2504
LONG WINAPI RegSetValueExW(_In_ HKEY hKey, _In_ LPCWSTR lpValueName, _In_ DWORD Reserved, _In_ DWORD dwType, _In_ CONST BYTE *lpData, _In_ DWORD cbData)
Definition: reg.c:4882
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4103
BOOL WINAPI AllocateAndInitializeSid(PSID_IDENTIFIER_AUTHORITY pIdentifierAuthority, BYTE nSubAuthorityCount, DWORD nSubAuthority0, DWORD nSubAuthority1, DWORD nSubAuthority2, DWORD nSubAuthority3, DWORD nSubAuthority4, DWORD nSubAuthority5, DWORD nSubAuthority6, DWORD nSubAuthority7, PSID *pSid)
Definition: security.c:674
BOOL WINAPI InitializeAcl(PACL pAcl, DWORD nAclLength, DWORD dwAclRevision)
Definition: security.c:1006
BOOL WINAPI InitializeSecurityDescriptor(PSECURITY_DESCRIPTOR pSecurityDescriptor, DWORD dwRevision)
Definition: security.c:929
BOOL WINAPI AddAccessAllowedAce(PACL pAcl, DWORD dwAceRevision, DWORD AccessMask, PSID pSid)
Definition: security.c:1039
DWORD WINAPI GetLengthSid(PSID pSid)
Definition: security.c:919
PVOID WINAPI FreeSid(PSID pSid)
Definition: security.c:698
#define CloseHandle
Definition: compat.h:739
#define GetProcessHeap()
Definition: compat.h:736
#define ERROR_CALL_NOT_IMPLEMENTED
Definition: compat.h:102
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define DLL_PROCESS_ATTACH
Definition: compat.h:131
#define DLL_PROCESS_DETACH
Definition: compat.h:130
#define SetLastError(x)
Definition: compat.h:752
#define HeapAlloc
Definition: compat.h:733
#define MAX_PATH
Definition: compat.h:34
#define HeapFree(x, y, z)
Definition: compat.h:735
#define ERROR_ACCESS_DENIED
Definition: compat.h:97
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
static const WCHAR version[]
Definition: asmname.c:66
static void cleanup(void)
Definition: main.c:1335
BOOL WINAPI DisableThreadLibraryCalls(IN HMODULE hLibModule)
Definition: loader.c:85
#define swprintf
Definition: precomp.h:40
return ret
Definition: mutex.c:146
#define L(x)
Definition: resources.c:13
#define INFINITE
Definition: serial.h:102
@ Success
Definition: eventcreate.c:712
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
FxAutoRegKey hKey
Status
Definition: gdiplustypes.h:25
GLuint buffer
Definition: glext.h:5915
GLuint index
Definition: glext.h:6031
GLbitfield flags
Definition: glext.h:7161
GLfloat GLfloat p
Definition: glext.h:8902
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
NTSYSAPI ULONG WINAPI RtlNtStatusToDosError(NTSTATUS)
#define InterlockedCompareExchangePointer
Definition: interlocked.h:144
#define debugstr_guid
Definition: kernel32.h:35
#define debugstr_w
Definition: kernel32.h:32
#define REG_SZ
Definition: layer.c:22
static IN DWORD IN LPVOID lpvReserved
LONG_PTR LPARAM
Definition: minwindef.h:175
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
LPCWSTR szPath
Definition: env.c:37
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:56
#define SEMAPHORE_QUERY_STATE
Definition: security.c:57
#define SE_SHUTDOWN_PRIVILEGE
Definition: security.c:673
#define SE_CREATE_PAGEFILE_PRIVILEGE
Definition: security.c:669
struct _ACL ACL
struct _ACCESS_ALLOWED_ACE ACCESS_ALLOWED_ACE
unsigned int * PUINT
Definition: ndis.h:50
unsigned int UINT
Definition: ndis.h:50
#define IS_PWR_SUSPEND_ALLOWED(PowerCaps)
Definition: potypes.h:63
#define IS_PWR_HIBERNATE_ALLOWED(PowerCaps)
Definition: potypes.h:70
#define IS_PWR_POWEROFF_ALLOWED(PowerCaps)
Definition: potypes.h:77
_Out_writes_bytes_to_opt_ AbsoluteSecurityDescriptorSize PSECURITY_DESCRIPTOR _Inout_ PULONG _Out_writes_bytes_to_opt_ DaclSize PACL Dacl
Definition: rtlfuncs.h:1625
_Out_writes_bytes_to_opt_ AbsoluteSecurityDescriptorSize PSECURITY_DESCRIPTOR _Inout_ PULONG _Out_writes_bytes_to_opt_ DaclSize PACL _Inout_ PULONG DaclSize
Definition: rtlfuncs.h:1626
NTSYSAPI NTSTATUS NTAPI RtlAdjustPrivilege(_In_ ULONG Privilege, _In_ BOOLEAN NewValue, _In_ BOOLEAN ForThread, _Out_ PBOOLEAN OldValue)
#define _Out_
Definition: no_sal2.h:160
#define SYNCHRONIZE
Definition: nt_native.h:61
#define REG_BINARY
Definition: nt_native.h:1499
#define KEY_ALL_ACCESS
Definition: nt_native.h:1044
#define KEY_READ
Definition: nt_native.h:1026
#define KEY_WRITE
Definition: nt_native.h:1034
#define READ_CONTROL
Definition: nt_native.h:58
NTSTATUS NTAPI NtPowerInformation(IN POWER_INFORMATION_LEVEL PowerInformationLevel, IN PVOID InputBuffer OPTIONAL, IN ULONG InputBufferLength, OUT PVOID OutputBuffer OPTIONAL, IN ULONG OutputBufferLength)
Definition: power.c:901
enum _SYSTEM_POWER_STATE * PSYSTEM_POWER_STATE
@ PowerSystemUnspecified
Definition: ntpoapi.h:35
@ PowerSystemSleeping1
Definition: ntpoapi.h:37
@ PowerSystemSleeping2
Definition: ntpoapi.h:38
@ PowerSystemSleeping3
Definition: ntpoapi.h:39
@ PowerSystemShutdown
Definition: ntpoapi.h:41
@ PowerSystemWorking
Definition: ntpoapi.h:36
@ PowerSystemHibernate
Definition: ntpoapi.h:40
@ PowerActionShutdownOff
Definition: ntpoapi.h:129
@ PowerActionNone
Definition: ntpoapi.h:123
@ PowerActionHibernate
Definition: ntpoapi.h:126
@ PowerActionShutdown
Definition: ntpoapi.h:127
@ PowerActionShutdownReset
Definition: ntpoapi.h:128
@ PowerActionWarmEject
Definition: ntpoapi.h:130
@ PowerActionReserved
Definition: ntpoapi.h:124
@ PowerActionSleep
Definition: ntpoapi.h:125
enum _POWER_INFORMATION_LEVEL POWER_INFORMATION_LEVEL
@ SystemPowerCapabilities
Definition: ntpoapi.h:71
BYTE * PBYTE
Definition: pedump.c:66
long LONG
Definition: pedump.c:60
static BOOLEAN CreatePwrProfSemaphore(VOID)
Creates or opens a registry-synchronizing semaphore, with access for SYNCHRONIZE | READ_CONTROL | SEM...
Definition: powrprof.c:205
DWORD WINAPI PowerSetActiveScheme(HKEY UserRootPowerKey, GUID *polguid)
Definition: powrprof.c:740
BOOLEAN WINAPI GetPwrCapabilities(PSYSTEM_POWER_CAPABILITIES lpSystemPowerCapabilities)
Definition: powrprof.c:582
static const WCHAR szCurrentPowerPolicies[]
Definition: powrprof.c:42
static BOOLEAN AcquirePwrProfSemaphore(VOID)
Definition: powrprof.c:272
DWORD WINAPI PowerWriteDCValueIndex(HKEY key, const GUID *scheme, const GUID *subgroup, const GUID *setting, DWORD index)
Definition: powrprof.c:813
static const WCHAR szDiskMin[]
Definition: powrprof.c:48
static const WCHAR szPowerCfgSubKey[]
Definition: powrprof.c:38
BOOLEAN WINAPI IsPwrHibernateAllowed(VOID)
Definition: powrprof.c:675
BOOLEAN WINAPI ReadProcessorPwrScheme(UINT uiID, PMACHINE_PROCESSOR_POWER_POLICY pMachineProcessorPowerPolicy)
Definition: powrprof.c:920
BOOLEAN WINAPI GetCurrentPowerPolicies(PGLOBAL_POWER_POLICY pGlobalPowerPolicy, PPOWER_POLICY pPowerPolicy)
Definition: powrprof.c:545
BOOLEAN WINAPI IsPwrShutdownAllowed(VOID)
Definition: powrprof.c:694
NTSTATUS WINAPI CallNtPowerInformation(POWER_INFORMATION_LEVEL InformationLevel, PVOID lpInputBuffer, ULONG nInputBufferSize, PVOID lpOutputBuffer, ULONG nOutputBufferSize)
Definition: powrprof.c:283
DWORD WINAPI PowerEnumerate(HKEY key, const GUID *scheme, const GUID *subgroup, POWER_DATA_ACCESSOR flags, ULONG index, UCHAR *buffer, DWORD *buffer_size)
Definition: powrprof.c:773
BOOLEAN WINAPI IsAdminOverrideActive(PADMINISTRATOR_POWER_POLICY p)
Definition: powrprof.c:668
BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
Definition: powrprof.c:1429
static const WCHAR szUserPowerConfigSubKey[]
Definition: powrprof.c:40
DWORD WINAPI PowerGetActiveScheme(HKEY UserRootPowerKey, GUID **polguid)
Definition: powrprof.c:734
BOOLEAN WINAPI ReadPwrScheme(UINT uiID, PPOWER_POLICY pPowerPolicy)
Definition: powrprof.c:946
BOOLEAN WINAPI GetActivePwrScheme(PUINT puiID)
Definition: powrprof.c:509
BOOLEAN WINAPI ValidatePowerPolicies(PGLOBAL_POWER_POLICY pGPP, PPOWER_POLICY pPP)
Definition: powrprof.c:1187
BOOLEAN WINAPI WritePwrScheme(PUINT puiID, LPWSTR lpszName, LPWSTR lpszDescription, PPOWER_POLICY pPowerPolicy)
Definition: powrprof.c:1102
static BOOLEAN POWRPROF_GetMachinePowerPolicy(LPWSTR szNum, PMACHINE_POWER_POLICY pmachinePwrPolicy)
Definition: powrprof.c:409
static VOID FixSystemPowerState(PSYSTEM_POWER_STATE Psps, SYSTEM_POWER_CAPABILITIES PowerCaps)
Definition: powrprof.c:1166
static const WCHAR szDiskMax[]
Definition: powrprof.c:47
DWORD WINAPI PowerWriteACValueIndex(HKEY key, const GUID *scheme, const GUID *subgroup, const GUID *setting, DWORD index)
Definition: powrprof.c:807
DWORD WINAPI PowerSettingRegisterNotification(const GUID *setting, DWORD flags, HANDLE recipient, PHPOWERNOTIFY handle)
Definition: powrprof.c:794
BOOLEAN WINAPI SetActivePwrScheme(UINT uiID, PGLOBAL_POWER_POLICY lpGlobalPowerPolicy, PPOWER_POLICY lpPowerPolicy)
Definition: powrprof.c:978
BOOLEAN WINAPI SetSuspendState(BOOLEAN Hibernate, BOOLEAN ForceCritical, BOOLEAN DisableWakeEvent)
Definition: powrprof.c:1017
DWORD WINAPI PowerReadFriendlyName(HKEY RootPowerKey, const GUID *Scheme, const GUID *SubGroup, const GUID *PowerSettings, UCHAR *Buffer, DWORD *BufferSize)
Definition: powrprof.c:753
DWORD WINAPI PowerReadACValue(HKEY RootPowerKey, const GUID *Scheme, const GUID *SubGroup, const GUID *PowerSettings, PULONG Type, PUCHAR Buffer, DWORD *BufferSize)
Definition: powrprof.c:850
DWORD WINAPI PowerReadACValueIndex(HKEY key, const GUID *scheme, const GUID *subgroup, const GUID *setting, LPDWORD AcValueIndex)
Definition: powrprof.c:825
BOOLEAN WINAPI EnumPwrSchemes(PWRSCHEMESENUMPROC lpfnPwrSchemesEnumProc, LPARAM lParam)
Definition: powrprof.c:443
BOOLEAN WINAPI DeletePwrScheme(UINT uiIndex)
Definition: powrprof.c:323
BOOLEAN WINAPI WriteProcessorPwrScheme(UINT ID, PMACHINE_PROCESSOR_POWER_POLICY pMachineProcessorPowerPolicy)
Definition: powrprof.c:1068
BOOLEAN WINAPI CanUserWritePwrScheme(VOID)
Definition: powrprof.c:303
BOOLEAN WINAPI WriteGlobalPwrPolicy(PGLOBAL_POWER_POLICY pGlobalPowerPolicy)
Definition: powrprof.c:1026
DWORD WINAPI PowerRegisterSuspendResumeNotification(DWORD flags, HANDLE recipient, PHPOWERNOTIFY handle)
Definition: powrprof.c:781
POWER_PLATFORM_ROLE WINAPI PowerDeterminePlatformRole(void)
Definition: powrprof.c:761
BOOLEAN WINAPI WritePwrPolicy(PUINT puiID, PPOWER_POLICY pPowerPolicy)
Definition: powrprof.c:1404
DWORD WINAPI PowerUnregisterSuspendResumeNotification(HPOWERNOTIFY handle)
Definition: powrprof.c:788
static UINT g_LastID
Definition: powrprof.c:51
static const WCHAR szPolicies[]
Definition: powrprof.c:44
static BOOLEAN CheckPowerActionPolicy(PPOWER_ACTION_POLICY pPAP, SYSTEM_POWER_CAPABILITIES PowerCaps)
Definition: powrprof.c:1129
static BOOLEAN POWRPROF_GetUserPowerPolicy(LPWSTR szNum, PUSER_POWER_POLICY puserPwrPolicy, DWORD cchName, LPWSTR szName, DWORD cchDesc, LPWSTR szDesc)
Definition: powrprof.c:352
DWORD WINAPI PowerReadDCValue(HKEY RootPowerKey, const GUID *Scheme, const GUID *SubGroup, const GUID *PowerSettings, PULONG Type, PUCHAR Buffer, DWORD *BufferSize)
Definition: powrprof.c:747
POWER_PLATFORM_ROLE WINAPI PowerDeterminePlatformRoleEx(ULONG version)
Definition: powrprof.c:767
BOOLEAN WINAPI ReadGlobalPwrPolicy(PGLOBAL_POWER_POLICY pGlobalPowerPolicy)
Definition: powrprof.c:857
static const WCHAR szLastID[]
Definition: powrprof.c:49
DWORD WINAPI PowerReadDCValueIndex(HKEY key, const GUID *scheme, const GUID *subgroup, const GUID *setting, LPDWORD DcValuetIndex)
Definition: powrprof.c:837
BOOLEAN WINAPI IsPwrSuspendAllowed(VOID)
Definition: powrprof.c:713
static const WCHAR szName[]
Definition: powrprof.c:45
DWORD WINAPI PowerSettingUnregisterNotification(HPOWERNOTIFY handle)
Definition: powrprof.c:801
static const WCHAR szDescription[]
Definition: powrprof.c:46
static BOOLEAN CreatePwrProfSemaphoreSecurity(_Out_ PSECURITY_DESCRIPTOR *PowrProfSd)
Creates a security descriptor for the registry semaphore.
Definition: powrprof.c:70
static VOID SetLastID(VOID)
Definition: powrprof.c:1085
static HANDLE PPRegSemaphore
Definition: powrprof.c:52
BOOLEAN WINAPI GetPwrDiskSpindownRange(PUINT RangeMax, PUINT RangeMin)
Definition: powrprof.c:605
PVOID * PHPOWERNOTIFY
Definition: powrprof.h:154
struct _USER_POWER_POLICY USER_POWER_POLICY
BOOLEAN(CALLBACK * PWRSCHEMESENUMPROC)(UINT, DWORD, LPWSTR, DWORD, LPWSTR, PPOWER_POLICY, LPARAM)
Definition: powrprof.h:153
PVOID HPOWERNOTIFY
Definition: powrprof.h:154
struct _MACHINE_POWER_POLICY MACHINE_POWER_POLICY
enum _POWER_DATA_ACCESSOR POWER_DATA_ACCESSOR
struct _MACHINE_PROCESSOR_POWER_POLICY MACHINE_PROCESSOR_POWER_POLICY
DWORD scheme
#define ID
Definition: ruserpass.c:36
_Check_return_ _CRTIMP int __cdecl _wtoi(_In_z_ const wchar_t *_Str)
static __inline const char * wine_dbgstr_guid(const GUID *id)
Definition: debug.h:197
BOOL WINAPI SetSecurityDescriptorDacl(PSECURITY_DESCRIPTOR pSecurityDescriptor, BOOL bDaclPresent, PACL pDacl, BOOL bDaclDefaulted)
Definition: sec.c:262
BOOL WINAPI SetSecurityDescriptorOwner(PSECURITY_DESCRIPTOR pSecurityDescriptor, PSID pOwner, BOOL bOwnerDefaulted)
Definition: sec.c:312
BOOL WINAPI MakeSelfRelativeSD(PSECURITY_DESCRIPTOR pAbsoluteSecurityDescriptor, PSECURITY_DESCRIPTOR pSelfRelativeSecurityDescriptor, LPDWORD lpdwBufferLength)
Definition: sec.c:214
BOOL WINAPI SetSecurityDescriptorGroup(PSECURITY_DESCRIPTOR pSecurityDescriptor, PSID pGroup, BOOL bGroupDefaulted)
Definition: sec.c:288
#define STATUS_SUCCESS
Definition: shellext.h:65
#define TRACE(s)
Definition: solgame.cpp:4
wchar_t const *const size_t const buffer_size
Definition: stat.cpp:95
SYSTEM_POWER_STATE LidOpenWakeDc
Definition: powrprof.h:41
SYSTEM_POWER_STATE LidOpenWakeAc
Definition: powrprof.h:40
GLOBAL_USER_POWER_POLICY user
Definition: powrprof.h:60
GLOBAL_MACHINE_POWER_POLICY mach
Definition: powrprof.h:61
POWER_ACTION_POLICY PowerButtonDc
Definition: powrprof.h:49
POWER_ACTION_POLICY LidCloseDc
Definition: powrprof.h:53
POWER_ACTION_POLICY SleepButtonDc
Definition: powrprof.h:51
POWER_ACTION_POLICY PowerButtonAc
Definition: powrprof.h:48
POWER_ACTION_POLICY SleepButtonAc
Definition: powrprof.h:50
POWER_ACTION_POLICY LidCloseAc
Definition: powrprof.h:52
SYSTEM_POWER_STATE MinSleepAc
Definition: powrprof.h:67
SYSTEM_POWER_STATE ReducedLatencySleepDc
Definition: powrprof.h:70
POWER_ACTION_POLICY OverThrottledDc
Definition: powrprof.h:79
SYSTEM_POWER_STATE ReducedLatencySleepAc
Definition: powrprof.h:69
POWER_ACTION_POLICY OverThrottledAc
Definition: powrprof.h:78
SYSTEM_POWER_STATE MinSleepDc
Definition: powrprof.h:68
POWER_ACTION Action
Definition: ntpoapi.h:409
MACHINE_POWER_POLICY mach
Definition: powrprof.h:118
USER_POWER_POLICY user
Definition: powrprof.h:117
LPVOID lpSecurityDescriptor
Definition: compat.h:193
SYSTEM_POWER_STATE MaxSleepAc
Definition: powrprof.h:100
SYSTEM_POWER_STATE MaxSleepDc
Definition: powrprof.h:101
POWER_ACTION_POLICY IdleAc
Definition: powrprof.h:92
POWER_ACTION_POLICY IdleDc
Definition: powrprof.h:93
Definition: copy.c:22
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
HANDLE WINAPI DECLSPEC_HOTPATCH OpenSemaphoreW(IN DWORD dwDesiredAccess, IN BOOL bInheritHandle, IN LPCWSTR lpName)
Definition: synch.c:529
HANDLE WINAPI DECLSPEC_HOTPATCH CreateSemaphoreW(IN LPSECURITY_ATTRIBUTES lpSemaphoreAttributes OPTIONAL, IN LONG lInitialCount, IN LONG lMaximumCount, IN LPCWSTR lpName OPTIONAL)
Definition: synch.c:444
BOOL WINAPI DECLSPEC_HOTPATCH ReleaseSemaphore(IN HANDLE hSemaphore, IN LONG lReleaseCount, IN LPLONG lpPreviousCount)
Definition: synch.c:542
uint32_t * PULONG
Definition: typedefs.h:59
unsigned char * LPBYTE
Definition: typedefs.h:53
uint32_t * LPDWORD
Definition: typedefs.h:59
unsigned char * PUCHAR
Definition: typedefs.h:53
uint32_t ULONG
Definition: typedefs.h:59
_In_ WDFMEMORY _Out_opt_ size_t * BufferSize
Definition: wdfmemory.h:254
#define SEMAPHORE_MODIFY_STATE
Definition: winbase.h:163
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define SEMAPHORE_ALL_ACCESS
Definition: winbase.h:162
#define WAIT_OBJECT_0
Definition: winbase.h:383
_In_ PSID _Out_writes_to_opt_ cchName LPSTR _Inout_ LPDWORD cchName
Definition: winbase.h:2521
#define WINAPI
Definition: msvc.h:6
#define strlenW(s)
Definition: unicode.h:34
#define ERROR_GEN_FAILURE
Definition: winerror.h:256
#define ERROR_INVALID_DATA
Definition: winerror.h:238
#define ERROR_REVISION_MISMATCH
Definition: winerror.h:1133
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
#define HKEY_CURRENT_USER
Definition: winreg.h:11
#define RegOpenKeyEx
Definition: winreg.h:527
#define RegDeleteKey
Definition: winreg.h:509
#define RegCreateKey
Definition: winreg.h:507
@ PlatformRoleDesktop
Definition: potypes.h:294
enum _POWER_PLATFORM_ROLE POWER_PLATFORM_ROLE
#define SECURITY_BUILTIN_DOMAIN_RID
Definition: setypes.h:581
#define SECURITY_LOCAL_SYSTEM_RID
Definition: setypes.h:574
#define SECURITY_AUTHENTICATED_USER_RID
Definition: setypes.h:568
#define SECURITY_NT_AUTHORITY
Definition: setypes.h:554
#define SECURITY_DESCRIPTOR_REVISION
Definition: setypes.h:58
#define ACL_REVISION
Definition: setypes.h:39
#define DOMAIN_ALIAS_RID_ADMINS
Definition: setypes.h:652
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
unsigned char UCHAR
Definition: xmlstorage.h:181
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184
const CHAR * LPCTSTR
Definition: xmlstorage.h:193
unsigned char BYTE
Definition: xxhash.c:193