Microsoft KB Archive/100389: Difference between revisions

From BetaArchive Wiki
(importing KB archive)
 
m (Text replacement - """ to """)
Line 44: Line 44:
== SUMMARY ==
== 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:
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 ===
=== Text from the Programmer's Reference ===


Line 55: Line 55:
                     NULL,            // User to logon or null=logoff
                     NULL,            // User to logon or null=logoff
                     NULL,            // User password if logon
                     NULL,            // User password if logon
                     "",              // Reserved; must be null string
                     "",              // Reserved; must be null string
                     0,                // Logoff force
                     0,                // Logoff force
                     1,                // Level; must be 1
                     1,                // Level; must be 1
Line 69: Line 69:
                     pszUserName,      // User to logon or null=logoff
                     pszUserName,      // User to logon or null=logoff
                     pszPassword,      // User password if logon
                     pszPassword,      // User password if logon
                     "",              // Reserved; must be null string
                     "",              // Reserved; must be null string
                     usLogoffForce,    // Logoff force
                     usLogoffForce,    // Logoff force
                     1,                // Level; must be 1
                     1,                // Level; must be 1
Line 75: Line 75:
                     cbBuflen,        // Size of buffer, in bytes
                     cbBuflen,        // Size of buffer, in bytes
                     &cbTotalAvail);  // Count of total bytes available
                     &cbTotalAvail);  // Count of total bytes available
   printf("NetWkstaSetUID2 returned %u\n", uRetCode);
   printf("NetWkstaSetUID2 returned %u\n", uRetCode);


/********************************************************************/  
/********************************************************************/  
Line 81: Line 81:
=== Problems ===
=== 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 &quot;NULL&quot; for the username/password and data return fields.<br />
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.<br />
<br />
<br />
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.
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.

Revision as of 12:58, 19 July 2020

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