http://bugs.winehq.org/show_bug.cgi?id=27339
Summary: improper last error code set by GetUserNameW Product: Wine Version: 1.3.20 Platform: x86 OS/Version: Linux Status: UNCONFIRMED Severity: normal Priority: P2 Component: advapi32 AssignedTo: wine-bugs@winehq.org ReportedBy: kevin.hendricks@sympatico.ca
There is a small bug in the wine implementation of GetUserNameW (and the same fix is needed in GetUserNameA to make it compatible with the needed change).
From wine:
dlls/advapi32/advapi.c starting at line 92
if (len > *lpSize) { SetLastError(ERROR_MORE_DATA); *lpSize = len; return FALSE; }
It seems the actual Window's implementation of GetUserNameW sets the last error to 122 not 234 which maps to ERROR_INSUFFICIENT_BUFFER and not ERROR_MORE_DATA when the buffer size to write the username to is too small.
This bug prevents the username from being properly read in all version of of Kindle for PC when run under wine. The Kindle for PC code allocates a buffer of 1 wchar and then calls GetUserNameW and upon error checks for the 122 error code (insufficient buffer) and if needed doubles the buffer size in question and tries again. It does not understand the 234 error code at all and so will error out unable to read the user's username.
The K4PC code luckily ignores the improper last error code value and simply replaces the username with the string "AlternateUserName" so the KindleForPC.exe will actually still work under wine even though this bug exists. The problem is that this bug actually changes how the DRM is created on the ebook as the Kindle DRM is tied to both the user's username and the volume serial number, making it impossible to post-process any ebook under wine.
Please fix this routine (and GetUserNameA which uses it) to use the last error code set to ERROR_INSUFFICIENT_BUFFER when the buffer size is too small to match what the Window's code does in this case.