2 * Unit test suite for fault reporting in XP and above
4 * Copyright 2010 Detlef Riekenberg
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
31 #include "wine/test.h"
33 static const char regpath_root
[] = "Software\\Microsoft\\PCHealth\\ErrorReporting";
34 static const char regpath_exclude
[] = "ExclusionList";
37 static BOOL
is_process_limited(void)
39 static BOOL (WINAPI
*pCheckTokenMembership
)(HANDLE
,PSID
,PBOOL
) = NULL
;
40 static BOOL (WINAPI
*pOpenProcessToken
)(HANDLE
, DWORD
, PHANDLE
) = NULL
;
41 SID_IDENTIFIER_AUTHORITY NtAuthority
= {SECURITY_NT_AUTHORITY
};
46 if (!pOpenProcessToken
)
48 HMODULE hadvapi32
= GetModuleHandleA("advapi32.dll");
49 pOpenProcessToken
= (void*)GetProcAddress(hadvapi32
, "OpenProcessToken");
50 pCheckTokenMembership
= (void*)GetProcAddress(hadvapi32
, "CheckTokenMembership");
51 if (!pCheckTokenMembership
|| !pOpenProcessToken
)
53 /* Win9x (power to the masses) or NT4 (no way to know) */
54 trace("missing pOpenProcessToken or CheckTokenMembership\n");
59 if (!AllocateAndInitializeSid(&NtAuthority
, 2, SECURITY_BUILTIN_DOMAIN_RID
,
60 DOMAIN_ALIAS_RID_ADMINS
,
61 0, 0, 0, 0, 0, 0, &Group
) ||
62 !pCheckTokenMembership(NULL
, Group
, &IsInGroup
))
64 trace("Could not check if the current user is an administrator\n");
70 if (!AllocateAndInitializeSid(&NtAuthority
, 2,
71 SECURITY_BUILTIN_DOMAIN_RID
,
72 DOMAIN_ALIAS_RID_POWER_USERS
,
73 0, 0, 0, 0, 0, 0, &Group
) ||
74 !pCheckTokenMembership(NULL
, Group
, &IsInGroup
))
76 trace("Could not check if the current user is a power user\n");
82 /* Only administrators and power users can be powerful */
87 if (pOpenProcessToken(GetCurrentProcess(), TOKEN_QUERY
, &token
))
90 TOKEN_ELEVATION_TYPE type
= TokenElevationTypeDefault
;
93 ret
= GetTokenInformation(token
, TokenElevationType
, &type
, sizeof(type
), &size
);
95 return (ret
&& type
== TokenElevationTypeLimited
);
103 static void test_AddERExcludedApplicationA(void)
111 lres
= RegCreateKeyA(HKEY_LOCAL_MACHINE
, regpath_root
, &hroot
);
112 if (lres
== ERROR_ACCESS_DENIED
)
114 skip("Not enough access rights\n");
119 lres
= RegOpenKeyA(hroot
, regpath_exclude
, &hexclude
);
122 RegDeleteValueA(hexclude
, "winetest_faultrep.exe");
125 SetLastError(0xdeadbeef);
126 res
= AddERExcludedApplicationA(NULL
);
127 ok(!res
, "got %d and 0x%x (expected FALSE)\n", res
, GetLastError());
129 SetLastError(0xdeadbeef);
130 res
= AddERExcludedApplicationA("");
131 ok(!res
, "got %d and 0x%x (expected FALSE)\n", res
, GetLastError());
133 SetLastError(0xdeadbeef);
134 /* existence of the path doesn't matter this function succeeded */
135 res
= AddERExcludedApplicationA("winetest_faultrep.exe");
136 if (is_process_limited())
138 /* LastError is not set! */
139 ok(!res
, "AddERExcludedApplicationA should have failed got %d\n", res
);
143 ok(res
, "AddERExcludedApplicationA failed (le=0x%x)\n", GetLastError());
145 /* add, when already present */
146 SetLastError(0xdeadbeef);
147 res
= AddERExcludedApplicationA("winetest_faultrep.exe");
148 ok(res
, "AddERExcludedApplicationA failed (le=0x%x)\n", GetLastError());
152 RegDeleteValueA(hexclude
, "winetest_faultrep.exe");
154 RegCloseKey(hexclude
);
158 /* ########################### */
162 test_AddERExcludedApplicationA();