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.
http://bugs.winehq.org/show_bug.cgi?id=27339
--- Comment #1 from kevin.hendricks@sympatico.ca 2011-05-30 18:25:13 CDT --- Created an attachment (id=34966) --> (http://bugs.winehq.org/attachment.cgi?id=34966) python 2.6 test program to confirm bug in last error value
Using Windows Xp or Windows 7, use python 2.7 (or 2.6) to run this program:
python wine_GetUserNameW_test.py
and it will properly print your username.
Then under wine using (Windows Python 2.6 or 2.7) run the wine_GetUserNameW_test.py and you will see the difference.
http://bugs.winehq.org/show_bug.cgi?id=27339
Austin English austinenglish@gmail.com changed:
What |Removed |Added ---------------------------------------------------------------------------- Keywords| |download, testcase CC| |austinenglish@gmail.com
http://bugs.winehq.org/show_bug.cgi?id=27339
Dan Kegel dank@kegel.com changed:
What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |NEW CC| |dank@kegel.com Ever Confirmed|0 |1
--- Comment #2 from Dan Kegel dank@kegel.com 2011-05-30 23:14:25 CDT --- Patch sent, http://www.winehq.org/pipermail/wine-patches/2011-May/102541.html
http://bugs.winehq.org/show_bug.cgi?id=27339
--- Comment #3 from kevin.hendricks@sympatico.ca 2011-05-31 12:17:14 CDT --- Hi,
That same problem exists in GetUserNameA in that same file.
If I set too small a buffer and invoke GetUserNameA under Windows, it returns 122 "ERROR_INSUFFICIENT_BUFFER" and not 234 "ERROR_MORE_DATA".
Here is the problem snippet of code from GetUserNameA
53 BOOL WINAPI 54 GetUserNameA( LPSTR lpszName, LPDWORD lpSize ) 55 {
...
65 ret = GetUserNameW( buffer, &sizeW ); 66 if (ret) 67 { 68 if (!(*lpSize = WideCharToMultiByte( CP_ACP, 0, buffer, -1, lpszName, *lpSize, NULL, NULL ))) 69 { 70 *lpSize = WideCharToMultiByte( CP_ACP, 0, buffer, -1, NULL, 0, NULL, NULL ); 71 SetLastError( ERROR_MORE_DATA ); 72 ret = FALSE; 73 } 74 } 75 else *lpSize = sizeW * 2; 76 HeapFree( GetProcessHeap(), 0, buffer ); 77 return ret; 78 }
GetUserNameA knows to loop and double its own internal buffer size until it holds the username generated by GetUserNameW but still has to return "ERROR_INSUFFICIENT_BUFFER" to its caller to tell it to grow the size of its buffer to match otherwise there is no way to return the username value to the caller.
So "ERROR_MORE_DATA" should be changed to "ERROR_INSUFFICIENT_BUFFER" here as well to match what GetLastError on Windows returns for GetUserNameA.
If you need an modified python test program that shows this error, please let me know and I will attach it.
http://bugs.winehq.org/show_bug.cgi?id=27339
--- Comment #4 from kevin.hendricks@sympatico.ca 2011-05-31 12:30:06 CDT --- Created an attachment (id=34970) --> (http://bugs.winehq.org/attachment.cgi?id=34970) python 2.6 test program for both GetUserNameW and GetUserNameA
If run under python 2.6 or 2.7 on Windows the username of the user is successfully returned. If run under wine with windows python 2.6 or 2.7, the test program fails since the incorrect LastError code is set.
http://bugs.winehq.org/show_bug.cgi?id=27339
--- Comment #5 from Austin English austinenglish@gmail.com 2011-05-31 13:10:41 CDT --- Tests committed: http://source.winehq.org/git/wine.git/commitdiff/750cadd2ffd1c82b97eef44c0ad...
http://bugs.winehq.org/show_bug.cgi?id=27339
Dan Kegel dank@kegel.com changed:
What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |RESOLVED Resolution| |FIXED
--- Comment #6 from Dan Kegel dank@kegel.com 2011-06-01 12:17:23 CDT --- Andrew's fix committed:
http://source.winehq.org/git/wine.git/?a=commit;h=c0b7345e386ac1ccc1e99577cc...
http://bugs.winehq.org/show_bug.cgi?id=27339
Alexandre Julliard julliard@winehq.org changed:
What |Removed |Added ---------------------------------------------------------------------------- Status|RESOLVED |CLOSED
--- Comment #7 from Alexandre Julliard julliard@winehq.org 2011-06-10 13:17:30 CDT --- Closing bugs fixed in 1.3.22.