Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

228 lines
4.7 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. servenam.c
  5. Abstract:
  6. Routines to service name requests. This file contains the following
  7. functions:
  8. FindNewName
  9. NewName
  10. ServeNameReqs
  11. Author:
  12. Dan Lafferty (danl) 26-Jul-1991
  13. Environment:
  14. User Mode -Win32
  15. Revision History:
  16. 26-Jul-1991 danl
  17. ported from LM2.0
  18. 17-Oct-1991 JohnRo
  19. Got rid of a MIPS compiler warning.
  20. --*/
  21. #include "msrv.h"
  22. #include <smbtypes.h> // needed for smb.h
  23. #include <smb.h> // Server Message Block definitions
  24. #include <string.h> // memcpy
  25. #include "msgdata.h"
  26. #include "msgdbg.h" // MSG_LOG
  27. //
  28. // Local Functions
  29. //
  30. DWORD
  31. MsgFindNewName(
  32. IN DWORD net
  33. );
  34. /*
  35. * MsgFindNewName - find a new name
  36. *
  37. * This function scans the name table for a new entry and returns its index.
  38. *
  39. * FindNewName (net)
  40. *
  41. * ENTRY
  42. * net - the network index to use
  43. *
  44. * RETURN
  45. * int - index of new name if found, -1 if none found
  46. *
  47. * This function assumes the shared data segment is accessible.
  48. */
  49. DWORD
  50. MsgFindNewName(
  51. IN DWORD net
  52. )
  53. {
  54. ULONG i;
  55. //
  56. // Loop to find new name
  57. //
  58. for(i = 0; i < NCBMAX(net); ++i) {
  59. if(SD_NAMEFLAGS(net,i) & NFNEW)
  60. //
  61. // Return index if new name found
  62. //
  63. return(i);
  64. }
  65. return(0xffffffff); // No new names
  66. }
  67. /*
  68. * MsgNewName - process a new name
  69. *
  70. * This function initializes the Network Control Block for a new name
  71. * and calls the appropriate function to issue the first net bios call
  72. * for that name.
  73. *
  74. * MsgNewName (neti,ncbi)
  75. *
  76. * ENTRY
  77. * neti - Network index
  78. * ncbi - Network Control Block index
  79. *
  80. * RETURN
  81. * This function returns the status from calls to MsgStartListen().
  82. * In NT when we add a name, we also need to make sure that we can
  83. * get a session for that name before telling the user that the
  84. * name was added successfully. If a failure occurs in StartListen,
  85. * that will be returned thru here.
  86. *
  87. *
  88. * This function assumes the shared data area is accessible.
  89. */
  90. NET_API_STATUS
  91. MsgNewName(
  92. IN DWORD neti, // Network index
  93. IN DWORD ncbi // Name index
  94. )
  95. {
  96. unsigned char flags;
  97. NET_API_STATUS status = NERR_Success;
  98. PNCB_DATA pNcbData;
  99. PNCB pNcb;
  100. PNET_DATA pNetData;
  101. //
  102. // Block until shared data area is free
  103. //
  104. MsgDatabaseLock(MSG_GET_EXCLUSIVE,"NetName");
  105. pNetData = GETNETDATA(neti);
  106. pNcbData = GETNCBDATA(neti,ncbi);
  107. pNcb = &pNcbData->Ncb;
  108. //
  109. // If name still marked as new
  110. //
  111. if (SD_NAMEFLAGS(neti,ncbi) & NFNEW) {
  112. //
  113. // Turn off the new name bit
  114. //
  115. pNcbData->NameFlags &= ~NFNEW;
  116. //
  117. // copy the name into the NCB
  118. //
  119. memcpy(pNcb->ncb_name, pNcbData->Name,NCBNAMSZ);
  120. //
  121. // Set the buffer address
  122. //
  123. pNcb->ncb_buffer = pNcbData->Buffer;
  124. //
  125. // Wake up semaphore address
  126. //
  127. pNcb->ncb_event = (HANDLE) wakeupSem[neti];
  128. //
  129. // Use the LANMAN adapter
  130. //
  131. pNcb->ncb_lana_num = pNetData->net_lana_num;
  132. //
  133. // Set the name number
  134. //
  135. pNcb->ncb_num = pNcbData->NameNum;
  136. flags = pNcbData->NameFlags;
  137. //
  138. // Unlock the share table
  139. //
  140. MsgDatabaseLock(MSG_RELEASE, "NewName");
  141. status = MsgStartListen(neti,ncbi); // Start listening for messages
  142. MSG_LOG(TRACE,"MsgNewName: MsgStartListen Status = %ld\n",status);
  143. }
  144. else {
  145. //
  146. // Unlock the share table
  147. //
  148. MsgDatabaseLock(MSG_RELEASE, "NewName");
  149. }
  150. return(status);
  151. }
  152. /*
  153. * MsgServeNameReqs - service new names
  154. *
  155. * This function scans the name table for new names to process. It scans
  156. * and processes names until no more new names can be found.
  157. *
  158. * MsgServeNameReqs ()
  159. *
  160. * RETURN
  161. * nothing
  162. *
  163. * This function gains access to the shared data area, finds and processes
  164. * new names until no more can be found, and then releases the shared data
  165. * area.
  166. */
  167. VOID
  168. MsgServeNameReqs(
  169. IN DWORD net // Net Index
  170. )
  171. {
  172. DWORD i; // Name index
  173. //
  174. // While new names are found, add them.
  175. //
  176. while( (i = MsgFindNewName(net)) != -1) {
  177. MsgNewName(net,i);
  178. }
  179. }