[CONC-418] Use FormatMessage to get error string for unknown Schannel error codes Created: 2019-06-04 Updated: 2019-11-15 Resolved: 2019-09-21 |
|
| Status: | Closed |
| Project: | MariaDB Connector/C |
| Component/s: | None |
| Affects Version/s: | 3.0.8, 3.1.0 |
| Fix Version/s: | 3.1.5 |
| Type: | Task | Priority: | Major |
| Reporter: | Geoff Montee (Inactive) | Assignee: | Georg Richter |
| Resolution: | Fixed | Votes: | 1 |
| Labels: | None | ||
| Issue Links: |
|
||||||||||||||||||||||||||||
| Description |
|
If MariaDB Connector/C encounters an unknown Schannel error, then it currently prints a message like this:
It does this here: https://github.com/MariaDB/mariadb-connector-c/blob/v3.1.0/libmariadb/secure/ma_schannel.c#L80 This is not very user friendly. It would probably be better if it could print the textual error message instead. The windows API has the FormatMessage function that can be used to get the textual error message from the error code. https://docs.microsoft.com/en-us/windows/desktop/api/winbase/nf-winbase-formatmessage For an example, see this: |
| Comments |
| Comment by Vladislav Vaintroub [ 2019-06-04 ] |
|
I think it is good that it outputs a code in hex. If it outputs a Japanese message, on localized version of Windows, it would be much harder to make it actionable. 0x80090308 is about as user-friendly as "invalid token" to the end user, the end user cannot make anything out of the message. But 0x80090308 can gbe easily googled. 0x80090308 SEC_E_INVALID_TOKEN - The function encountered an invalid token ,in AcquireSecurityContext() More often than not, when client gets this message, it might mean that server sent an error packet "08S1 Bad handshake", while client is trying to parse this as part TLS handshake (ServerHello, or anything like that) |
| Comment by Geoff Montee (Inactive) [ 2019-06-05 ] |
|
Hi wlad,
I agree with all of that. If we want to ensure that we get English error messages even on localized versions of Windows, it actually looks like the FormatMessage function accepts a dwLanguageId parameter that can be used to choose the desired language.
https://docs.microsoft.com/en-us/windows/desktop/api/winbase/nf-winbase-formatmessage It looks like the LANGID of English is LANG_ENGLISH (0x09). It looks like the LANGID of US English specifically is SUBLANG_ENGLISH_US (0x0409). https://docs.microsoft.com/en-us/windows/desktop/Intl/language-identifiers https://docs.microsoft.com/en-us/windows/desktop/Intl/language-identifier-constants-and-strings If we did also want to get a callstack, then it looks like we may be able to use the CaptureStackBackTrace function. https://docs.microsoft.com/en-us/windows/desktop/debug/capturestackbacktrace |
| Comment by Vladislav Vaintroub [ 2019-06-05 ] |
|
I remember to have struggled to produce English system messages, on localized Windows, even with passing 0x09/0x0409. I think English MUI needs to be installed for that to succeed. Hardcoded on the other hand, is guaranteed to be English , but yes there should be a fallback. |
| Comment by Georg Richter [ 2019-09-21 ] |
|
rev. 9ba8e32f6d0fe449114d8eb369cf29303257b460 |
| Comment by Geoff Montee (Inactive) [ 2019-11-15 ] |
|
See also: |