/*++ Copyright (c) 1991-1993 Microsoft Corporation Module Name: svcsnb.c Abstract: NetBios support for services in svchost.exe. Background: In order to put the messenger service and the workstation service together in the same process, it became necessary to synchronize their use of NetBios. If NetSend did a reset and added the computername via netbios, it isn't desirable for the messenger to then do a reset, and destroy that computername. Purpose: These functions help to synchronize the use of netbios. A service that uses NetBios should first call the SvcsOpenNetBios function, then call SvcsResetNetBios. The open causes a use count to be incremented. The SvcsResetNetBios will only actually cause a NetBios reset if that Lan Adapter has not been reset yet. When the service stops it is necessary for it to call SvcsCloseNetBios. Thus when the last service using NetBios terminates, we clear all the state flags, and allow the next call to SvcsResetNetBios to actually do a reset. Author: Dan Lafferty (danl) 08-Nov-1993 Environment: User Mode -Win32 Revision History: 08-Nov-1993 danl created --*/ // // INCLUDES // #include "pch.h" #pragma hdrstop #include #include // NetBIOS 3.0 definitions #include // NERR_ #include // SvcNetBios prototypes // // DEFINES & MACROS // #define NUM_DWORD_BITS (sizeof(DWORD)*8) #define LANA_NUM_DWORDS ((MAX_LANA/NUM_DWORD_BITS)+1) // // These values correspond to the constants defined in ntos\netbios\nbconst.h // MAX_NUM_OF_SESSIONS=MAXIMUM_CONNECTION // MAX_NUM_OF_NAMES=MAXIMUM_ADDRESS -2 // #define MAX_NUM_OF_SESSIONS 254 #define MAX_NUM_OF_NAMES 253 // // GLOBALS // CRITICAL_SECTION SvcNetBiosCritSec={0}; DWORD LanaFlags[LANA_NUM_DWORDS]={0}; DWORD GlobalNetBiosUseCount=0; // // LOCAL FUNCTIONS // DWORD SvcNetBiosStatusToApiStatus( UCHAR NetBiosStatus ); VOID SetLanaFlag( UCHAR uCharLanaNum ); BOOL LanaFlagIsSet( UCHAR uCharLanaNum ); VOID SvcNetBiosInit( VOID ) /*++ Routine Description: Initializes a critical section and the global variable that it protects. Arguments: none Return Value: none --*/ { DWORD i; InitializeCriticalSection(&SvcNetBiosCritSec); for (i=0;i 0) { GlobalNetBiosUseCount--; if (GlobalNetBiosUseCount == 0) { DWORD i; for (i=0;i LANA_NUM_DWORDS) { return; } BitShift = LanaNum - (DwordOffset * NUM_DWORD_BITS); BitMask = BitMask << BitShift; LanaFlags[DwordOffset] |= BitMask; } BOOL LanaFlagIsSet( UCHAR uCharLanaNum ) { DWORD LanaNum = (DWORD)uCharLanaNum; DWORD BitMask=1; DWORD DwordOffset; DWORD BitShift; DwordOffset = LanaNum / NUM_DWORD_BITS; if (DwordOffset > LANA_NUM_DWORDS) { return(FALSE); } BitShift = LanaNum - (DwordOffset * NUM_DWORD_BITS); BitMask = BitMask << BitShift; return ((BOOL) LanaFlags[DwordOffset] & BitMask ); }