Article ID: 100389
Article Last Modified on 9/30/2003
APPLIES TO
- Microsoft LAN Manager 2.2 Standard Edition
This article was previously published under Q100389
SUMMARY
The sample logoff program showing NetwkstaSetUid2 API call implementation in the LAN Manager "Programmers Reference Manual" can cause problems. The NetwkstaSetUid2 API call logs users on and off from the network and runs the logon script. Here is how the LAN Manager "Programmer's Reference Manual" explains implementation of the call on page 686:
Text from the Programmer's Reference
/********************************************************************/ // Make an initial call to determine the required return buffer size. uRetCode = NetWkstaSetUID2(NULL, // Reserved; must be NULL NULL, // Domain to log on to NULL, // User to logon or null=logoff NULL, // User password if logon "", // Reserved; must be null string 0, // Logoff force 1, // Level; must be 1 NULL, // Logon data returned 0, // Size of data area, in bytes &cbTotalAvail); // Count of total bytes available cbBuflen = cbTotalAvail; pbBuffer = SafeMalloc(cbBuflen); uRetCode = NetWkstaSetUID2(NULL, // Reserved; must be NULL pszDomainName, // Domain to log on to pszUserName, // User to logon or null=logoff pszPassword, // User password if logon "", // Reserved; must be null string usLogoffForce, // Logoff force 1, // Level; must be 1 pbBuffer, // Logon data returned cbBuflen, // Size of buffer, in bytes &cbTotalAvail); // Count of total bytes available printf("NetWkstaSetUID2 returned %u\n", uRetCode); /********************************************************************/
Problems
The initial call made to find the number of bytes required to SafeMalloc for the pbBuffer is valid in most API calls and works fine, but when you use the NetWkstaSetUID2 API call to logoff a user, the above implementation returns error 2123 (buffer too small). This is valid, as the example gives a "NULL" for the username/password and data return fields.
To work around this, set cbBuflen to a size that works in most cases. During the test on which this article is based, cbTotalAvail was normally about 8 bytes, so cbBuflen = 64 worked consistently. Fixing cbBuflen helps work around the problem because it uses the API call only once.
Keywords: KB100389