msvcrt: Don't read past end of string in _strnicoll/_wcsnicoll.
[wine.git] / dlls / wer / main.c
blob75a22a51d09c1c440e7f787526284f1388ee7b47
1 /*
2 * Copyright 2010 Louis Lenders
3 * Copyright 2010 Detlef Riekenberg
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.
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.
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
20 #include "config.h"
22 #include <stdarg.h>
24 #include "windef.h"
25 #include "winbase.h"
26 #include "winreg.h"
27 #include "werapi.h"
28 #include "wine/heap.h"
29 #include "wine/list.h"
30 #include "wine/unicode.h"
31 #include "wine/debug.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(wer);
35 typedef struct {
36 struct list entry;
37 WER_REPORT_INFORMATION info;
38 WER_REPORT_TYPE reporttype;
39 WCHAR eventtype[1];
40 } report_t;
43 static CRITICAL_SECTION report_table_cs;
44 static CRITICAL_SECTION_DEBUG report_table_cs_debug =
46 0, 0, &report_table_cs,
47 { &report_table_cs_debug.ProcessLocksList, &report_table_cs_debug.ProcessLocksList },
48 0, 0, { (DWORD_PTR)(__FILE__ ": report_table_cs") }
50 static CRITICAL_SECTION report_table_cs = { &report_table_cs_debug, -1, 0, 0, 0, 0 };
52 static struct list report_table = LIST_INIT(report_table);
54 static const WCHAR regpath_exclude[] =
55 {'S','o','f','t','w','a','r','e','\\',
56 'M','i','c','r','o','s','o','f','t','\\',
57 'W','i','n','d','o','w','s',' ','E','r','r','o','r',' ','R','e','p','o','r','t','i','n','g','\\',
58 'E','x','c','l','u','d','e','d','A','p','p','l','i','c','a','t','i','o','n','s',0};
60 BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
62 TRACE("(0x%p, %d, %p)\n", hinstDLL, fdwReason, lpvReserved);
64 switch (fdwReason)
66 case DLL_WINE_PREATTACH:
67 return FALSE; /* prefer native version */
68 case DLL_PROCESS_ATTACH:
69 DisableThreadLibraryCalls(hinstDLL);
70 break;
73 return TRUE;
76 /***********************************************************************
77 * WerAddExcludedApplication (wer.@)
79 * Add an application to the user specific or the system wide exclusion list
81 * PARAMS
82 * exeName [i] The application name
83 * allUsers [i] for all users (TRUE) or for the current user (FALSE)
85 * RETURNS
86 * Success: S_OK
87 * Failure: A HRESULT error code
90 HRESULT WINAPI WerAddExcludedApplication(PCWSTR exeName, BOOL allUsers)
92 HKEY hkey;
93 DWORD value = 1;
94 LPWSTR bs;
96 TRACE("(%s, %d)\n",debugstr_w(exeName), allUsers);
97 if (!exeName || !exeName[0])
98 return E_INVALIDARG;
100 bs = strrchrW(exeName, '\\');
101 if (bs) {
102 bs++; /* skip the backslash */
103 if (!bs[0]) {
104 return E_INVALIDARG;
106 } else
107 bs = (LPWSTR) exeName;
109 if (!RegCreateKeyW(allUsers ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER, regpath_exclude, &hkey)) {
110 RegSetValueExW(hkey, bs, 0, REG_DWORD, (LPBYTE)&value, sizeof(DWORD));
111 RegCloseKey(hkey);
112 return S_OK;
114 return E_ACCESSDENIED;
117 /***********************************************************************
118 * WerRemoveExcludedApplication (wer.@)
120 * remove an application from the exclusion list
122 * PARAMS
123 * exeName [i] The application name
124 * allUsers [i] for all users (TRUE) or for the current user (FALSE)
126 * RETURNS
127 * Success: S_OK
128 * Failure: A HRESULT error code
131 HRESULT WINAPI WerRemoveExcludedApplication(PCWSTR exeName, BOOL allUsers)
133 HKEY hkey;
134 LPWSTR bs;
135 LONG lres;
137 TRACE("(%s, %d)\n",debugstr_w(exeName), allUsers);
138 if (!exeName || !exeName[0])
139 return E_INVALIDARG;
141 bs = strrchrW(exeName, '\\');
142 if (bs) {
143 bs++; /* skip the backslash */
144 if (!bs[0]) {
145 return E_INVALIDARG;
147 } else
148 bs = (LPWSTR) exeName;
150 if (!RegCreateKeyW(allUsers ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER, regpath_exclude, &hkey)) {
151 lres = RegDeleteValueW(hkey, bs);
152 RegCloseKey(hkey);
153 return lres ? __HRESULT_FROM_WIN32(ERROR_ENVVAR_NOT_FOUND) : S_OK;
155 return E_ACCESSDENIED;
158 /***********************************************************************
159 * WerReportAddDump (wer.@)
161 * Add a dump of dumpType to hReportHandle.
163 * PARAMS
164 * hReportHandle [i] error reporting handle to add the dump
165 * hProcess [i] handle to the regarding process
166 * hThread [o] handle to the regarding thread
167 * dumpType [i] type of the dump
168 * pExceptionParam [o] pointer to a WER_EXCEPTION_INFORMATION
169 * pDumpCustomOptions [o] pointer to a WER_DUMP_CUSTOM_OPTIONS
170 * dwFlags [i] flag to control the heap dump
172 * RETURNS
173 * Success: S_OK
174 * Failure: A HRESULT error code
177 HRESULT WINAPI WerReportAddDump(HREPORT hReportHandle, HANDLE hProcess, HANDLE hThread,
178 WER_DUMP_TYPE dumpType, PWER_EXCEPTION_INFORMATION pExceptionParam,
179 PWER_DUMP_CUSTOM_OPTIONS pDumpCustomOptions, DWORD dwFlags)
181 FIXME("(%p, %p, %p, %d, %p, %p, %u) :stub\n", hReportHandle, hProcess, hThread, dumpType,
182 pExceptionParam, pDumpCustomOptions, dwFlags);
184 return E_NOTIMPL;
187 /***********************************************************************
188 * WerReportAddFile (wer.@)
190 * Add a file to an error report handle.
192 * PARAMS
193 * hreport [i] error reporting handle to add the file
194 * path [i] path to the file to add
195 * type [i] type of the file to add
196 * flags [i] flags for the file
198 * RETURNS
199 * Success: S_OK
200 * Failure: A HRESULT error code
203 HRESULT WINAPI WerReportAddFile(HREPORT hreport, PCWSTR path, WER_FILE_TYPE type, DWORD flags)
205 FIXME("(%p, %s, %d, 0x%x) :stub\n", hreport, debugstr_w(path), type, flags);
207 return S_OK;
210 /***********************************************************************
211 * WerReportCloseHandle (wer.@)
213 * Close an error reporting handle and free associated resources
215 * PARAMS
216 * hreport [i] error reporting handle to close
218 * RETURNS
219 * Success: S_OK
220 * Failure: A HRESULT error code
223 HRESULT WINAPI WerReportCloseHandle(HREPORT hreport)
225 report_t * report = (report_t *) hreport;
226 report_t * cursor;
227 BOOL found = FALSE;
229 TRACE("(%p)\n", hreport);
230 EnterCriticalSection(&report_table_cs);
231 if (report) {
232 LIST_FOR_EACH_ENTRY(cursor, &report_table, report_t, entry)
234 if (cursor == report) {
235 found = TRUE;
236 list_remove(&report->entry);
237 break;
241 LeaveCriticalSection(&report_table_cs);
242 if (!found)
243 return E_INVALIDARG;
245 heap_free(report);
247 return S_OK;
250 /***********************************************************************
251 * WerReportCreate (wer.@)
253 * Create an error report in memory and return a related HANDLE
255 * PARAMS
256 * eventtype [i] a name for the event type
257 * reporttype [i] what type of report should be created
258 * reportinfo [i] NULL or a ptr to a struct with some detailed information
259 * phandle [o] ptr, where the resulting handle should be saved
261 * RETURNS
262 * Success: S_OK
263 * Failure: A HRESULT error code
265 * NOTES
266 * The event type must be registered at microsoft. Predefined types are
267 * "APPCRASH" as the default on Windows, "Crash32" and "Crash64"
270 HRESULT WINAPI WerReportCreate(PCWSTR eventtype, WER_REPORT_TYPE reporttype, PWER_REPORT_INFORMATION reportinfo, HREPORT *phandle)
272 report_t *report;
274 TRACE("(%s, %d, %p, %p)\n", debugstr_w(eventtype), reporttype, reportinfo, phandle);
275 if (reportinfo) {
276 TRACE(".wzFriendlyEventName: %s\n", debugstr_w(reportinfo->wzFriendlyEventName));
277 TRACE(".wzApplicationName: %s\n", debugstr_w(reportinfo->wzApplicationName));
280 if (phandle) *phandle = NULL;
281 if (!eventtype || !eventtype[0] || !phandle) {
282 return E_INVALIDARG;
285 report = heap_alloc_zero(FIELD_OFFSET(report_t, eventtype[lstrlenW(eventtype) + 1]));
286 if (!report)
287 return __HRESULT_FROM_WIN32(ERROR_OUTOFMEMORY);
289 lstrcpyW(report->eventtype, eventtype);
290 report->reporttype = reporttype;
292 if (reportinfo) {
293 report->info = *reportinfo;
294 } else {
295 FIXME("build report information from scratch for %p\n", report);
298 EnterCriticalSection(&report_table_cs);
299 list_add_head(&report_table, &report->entry);
300 LeaveCriticalSection(&report_table_cs);
302 *phandle = report;
303 TRACE("=> %p\n", report);
304 return S_OK;
307 /***********************************************************************
308 * WerReportSetParameter (wer.@)
310 * Set one of 10 parameter / value pairs for a report handle
312 * PARAMS
313 * hreport [i] error reporting handle to add the parameter
314 * id [i] parameter to set (WER_P0 up to WER_P9)
315 * name [i] optional name of the parameter
316 * value [i] value of the parameter
318 * RETURNS
319 * Success: S_OK
320 * Failure: A HRESULT error code
323 HRESULT WINAPI WerReportSetParameter(HREPORT hreport, DWORD id, PCWSTR name, PCWSTR value)
325 FIXME("(%p, %d, %s, %s) :stub\n", hreport, id, debugstr_w(name), debugstr_w(value));
327 return S_OK;
330 /***********************************************************************
331 * WerReportSubmit (wer.@)
333 * Ask the user for permission and send the error report
334 * then kill or restart the application, when requested
336 * PARAMS
337 * hreport [i] error reporting handle to send
338 * consent [i] current transmit permission
339 * flags [i] flag to select dialog, transmission snd restart options
340 * presult [o] ptr, where the transmission result should be saved
342 * RETURNS
343 * Success: S_OK
344 * Failure: A HRESULT error code
347 HRESULT WINAPI WerReportSubmit(HREPORT hreport, WER_CONSENT consent, DWORD flags, PWER_SUBMIT_RESULT presult)
349 FIXME("(%p, %d, 0x%x, %p) :stub\n", hreport, consent, flags, presult);
351 if(!presult)
352 return E_INVALIDARG;
354 *presult = WerDisabled;
355 return S_OK;
358 /***********************************************************************
359 * WerReportSetUIOption (wer.@)
361 HRESULT WINAPI WerReportSetUIOption(HREPORT hreport, WER_REPORT_UI uitype, PCWSTR value)
363 FIXME("(%p, %d, %s) :stub\n", hreport, uitype, debugstr_w(value));
364 return E_NOTIMPL;