ReactOS 0.4.15-dev-8145-ga541a46
faultrep.c File Reference
#include <stdarg.h>
#include <stdio.h>
#include "windef.h"
#include "winbase.h"
#include "winerror.h"
#include "winreg.h"
#include "errorrep.h"
#include "wine/test.h"
Include dependency graph for faultrep.c:

Go to the source code of this file.

Functions

static BOOL is_process_limited (void)
 
static void test_AddERExcludedApplicationA (void)
 
 START_TEST (faultrep)
 

Variables

static const char regpath_root [] = "Software\\Microsoft\\PCHealth\\ErrorReporting"
 
static const char regpath_exclude [] = "ExclusionList"
 

Function Documentation

◆ is_process_limited()

static BOOL is_process_limited ( void  )
static

Definition at line 37 of file faultrep.c.

38{
39 static BOOL (WINAPI *pCheckTokenMembership)(HANDLE,PSID,PBOOL) = NULL;
40 static BOOL (WINAPI *pOpenProcessToken)(HANDLE, DWORD, PHANDLE) = NULL;
42 PSID Group;
43 BOOL IsInGroup;
45
46 if (!pOpenProcessToken)
47 {
48 HMODULE hadvapi32 = GetModuleHandleA("advapi32.dll");
49 pOpenProcessToken = (void*)GetProcAddress(hadvapi32, "OpenProcessToken");
50 pCheckTokenMembership = (void*)GetProcAddress(hadvapi32, "CheckTokenMembership");
51 if (!pCheckTokenMembership || !pOpenProcessToken)
52 {
53 /* Win9x (power to the masses) or NT4 (no way to know) */
54 trace("missing pOpenProcessToken or CheckTokenMembership\n");
55 return FALSE;
56 }
57 }
58
61 0, 0, 0, 0, 0, 0, &Group) ||
62 !pCheckTokenMembership(NULL, Group, &IsInGroup))
63 {
64 trace("Could not check if the current user is an administrator\n");
65 return FALSE;
66 }
67 if (!IsInGroup)
68 {
72 0, 0, 0, 0, 0, 0, &Group) ||
73 !pCheckTokenMembership(NULL, Group, &IsInGroup))
74 {
75 trace("Could not check if the current user is a power user\n");
76 return FALSE;
77 }
78 if (!IsInGroup)
79 {
80 /* Only administrators and power users can be powerful */
81 return TRUE;
82 }
83 }
84
85 if (pOpenProcessToken(GetCurrentProcess(), TOKEN_QUERY, &token))
86 {
87 BOOL ret;
89 DWORD size;
90
93 return (ret && type == TokenElevationTypeLimited);
94 }
95 return FALSE;
96}
#define trace
Definition: atltest.h:70
static SID_IDENTIFIER_AUTHORITY NtAuthority
Definition: security.c:40
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
BOOL WINAPI GetTokenInformation(HANDLE TokenHandle, TOKEN_INFORMATION_CLASS TokenInformationClass, LPVOID TokenInformation, DWORD TokenInformationLength, PDWORD ReturnLength)
Definition: security.c:411
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
#define CloseHandle
Definition: compat.h:739
#define GetProcAddress(x, y)
Definition: compat.h:753
#define GetCurrentProcess()
Definition: compat.h:759
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:812
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
GLsizeiptr size
Definition: glext.h:5919
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat token
Definition: glfuncs.h:210
struct _SID * PSID
Definition: eventlog.c:35
_In_opt_ PSID Group
Definition: rtlfuncs.h:1646
#define BOOL
Definition: nt_native.h:43
#define DWORD
Definition: nt_native.h:44
PVOID *typedef PHANDLE
Definition: ntsecpkg.h:455
PVOID HANDLE
Definition: typedefs.h:73
int ret
BOOL * PBOOL
Definition: windef.h:161
#define WINAPI
Definition: msvc.h:6
enum _TOKEN_ELEVATION_TYPE TOKEN_ELEVATION_TYPE
@ TokenElevationTypeLimited
Definition: winnt_old.h:2488
@ TokenElevationTypeDefault
Definition: winnt_old.h:2486
#define SECURITY_BUILTIN_DOMAIN_RID
Definition: setypes.h:581
#define TOKEN_QUERY
Definition: setypes.h:928
#define SECURITY_NT_AUTHORITY
Definition: setypes.h:554
@ TokenElevationType
Definition: setypes.h:983
#define DOMAIN_ALIAS_RID_POWER_USERS
Definition: setypes.h:655
#define DOMAIN_ALIAS_RID_ADMINS
Definition: setypes.h:652

Referenced by test_AddERExcludedApplicationA().

◆ START_TEST()

START_TEST ( faultrep  )

Definition at line 158 of file faultrep.c.

159{
161}
static void test_AddERExcludedApplicationA(void)
Definition: faultrep.c:101

◆ test_AddERExcludedApplicationA()

static void test_AddERExcludedApplicationA ( void  )
static

Definition at line 101 of file faultrep.c.

102{
103 BOOL res;
104 LONG lres;
105 HKEY hroot;
106 HKEY hexclude = 0;
107
108 /* clean state */
110 if (lres == ERROR_ACCESS_DENIED)
111 {
112 skip("Not enough access rights\n");
113 return;
114 }
115
116 if (!lres)
117 lres = RegOpenKeyA(hroot, regpath_exclude, &hexclude);
118
119 if (!lres)
120 RegDeleteValueA(hexclude, "winetest_faultrep.exe");
121
122
123 SetLastError(0xdeadbeef);
125 ok(!res, "got %d and 0x%x (expected FALSE)\n", res, GetLastError());
126
127 SetLastError(0xdeadbeef);
129 ok(!res, "got %d and 0x%x (expected FALSE)\n", res, GetLastError());
130
131 SetLastError(0xdeadbeef);
132 /* existence of the path doesn't matter this function succeeded */
133 res = AddERExcludedApplicationA("winetest_faultrep.exe");
134 if (is_process_limited())
135 {
136 /* LastError is not set! */
137 ok(!res, "AddERExcludedApplicationA should have failed got %d\n", res);
138 }
139 else
140 {
141 ok(res, "AddERExcludedApplicationA failed (le=0x%x)\n", GetLastError());
142
143 /* add, when already present */
144 SetLastError(0xdeadbeef);
145 res = AddERExcludedApplicationA("winetest_faultrep.exe");
146 ok(res, "AddERExcludedApplicationA failed (le=0x%x)\n", GetLastError());
147 }
148
149 /* cleanup */
150 RegDeleteValueA(hexclude, "winetest_faultrep.exe");
151
152 RegCloseKey(hexclude);
153 RegCloseKey(hroot);
154}
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
#define RegCloseKey(hKey)
Definition: registry.h:49
LONG WINAPI RegCreateKeyA(HKEY hKey, LPCSTR lpSubKey, PHKEY phkResult)
Definition: reg.c:1179
LONG WINAPI RegOpenKeyA(HKEY hKey, LPCSTR lpSubKey, PHKEY phkResult)
Definition: reg.c:3234
LONG WINAPI RegDeleteValueA(HKEY hKey, LPCSTR lpValueName)
Definition: reg.c:2287
#define SetLastError(x)
Definition: compat.h:752
#define ERROR_ACCESS_DENIED
Definition: compat.h:97
BOOL WINAPI AddERExcludedApplicationA(LPCSTR lpAppFileName)
Definition: faultrep.c:88
GLuint res
Definition: glext.h:9613
static const char regpath_root[]
Definition: faultrep.c:33
static BOOL is_process_limited(void)
Definition: faultrep.c:37
static const char regpath_exclude[]
Definition: faultrep.c:34
long LONG
Definition: pedump.c:60
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12

Referenced by START_TEST().

Variable Documentation

◆ regpath_exclude

const char regpath_exclude[] = "ExclusionList"
static

Definition at line 34 of file faultrep.c.

Referenced by test_AddERExcludedApplicationA().

◆ regpath_root

const char regpath_root[] = "Software\\Microsoft\\PCHealth\\ErrorReporting"
static

Definition at line 33 of file faultrep.c.

Referenced by test_AddERExcludedApplicationA().