Windows NT 4.0 source code leak
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.

296 lines
6.7 KiB

4 years ago
  1. /*++
  2. Copyright (c) 1992 Microsoft Corporation
  3. Module Name:
  4. locator.cxx
  5. Abstract:
  6. This file contains server initialization and other RPC control
  7. functions. The server has 3+ threads. The first thread
  8. initializes the locator and waits forever in ServerListen. The second
  9. thread listens on a mailslot for a request of GID's from the
  10. net. The final threads are created & used by the RPC runtime.
  11. Author:
  12. Steven Zeck (stevez) 07/01/90
  13. --*/
  14. #ifdef NTENV
  15. extern "C"
  16. {
  17. #include <nt.h>
  18. #include <ntrtl.h>
  19. #include <nturtl.h>
  20. #include <windef.h> // Base windows types
  21. #include <winbase.h>
  22. }
  23. #endif // NTENV
  24. #include "core.hxx"
  25. #include "locclass.hxx"
  26. CDEF
  27. #include "nsisvr.h"
  28. #include "nsiclt.h"
  29. #include "nsimgm.h"
  30. #include "loctoloc.h"
  31. #include "locsys.h"
  32. ENDDEF
  33. #if DBG
  34. ostream *OSdebug; // debug output buffer
  35. #else
  36. const long mainIdle = 0xffffffff;
  37. #endif
  38. int debug = -1; // debug trace level
  39. // Well known endpoint for the locator.
  40. #define pipeNameLoc "\\pipe\\locator"
  41. MUTEX *pESaccess, *pESnet; // Semaphores for serialized access
  42. long waitOnRead = 3000L; // time to wait on reading reply back
  43. ULONG maxCacheAge = EXPIRATION_DEFAULT; // max cache age, in seconds
  44. int fService = 1; // running as a service
  45. int fNet = 1; // enable network functionality
  46. PUZ OtherDomain; // other domain to look.
  47. SZ szOtherDomain; // ASCII other domain to look.
  48. PUZ DomainName; // name of current domain
  49. PUZ SelfName; // name of this workstation
  50. STATICTS perf; // performance statics
  51. ostream *cout; // console output.
  52. SZ szDebugName = "locator.log"; // debug log file name
  53. SwitchList aSwitchs = {
  54. {"/debug:*", ProcessInt, &debug,},
  55. {"/logfile:*", ProcessChar, &szDebugName,},
  56. {"/expirationage:*", ProcessLong, &maxCacheAge,},
  57. {"/querytimeout:*", ProcessLong, &waitOnRead,},
  58. {"/noservice", ProcessResetFlag, &fService,},
  59. {"/nonet", ProcessResetFlag, &fNet,},
  60. {"/otherdomain:*", ProcessChar, &szOtherDomain,},
  61. {0}
  62. };
  63. NATIVE_CLASS_LOCATOR * Locator;
  64. #ifdef NTENV
  65. int _CRTAPI1
  66. #else // NTENV
  67. int
  68. #endif // NTENV
  69. main (
  70. IN int cArgs,
  71. IN SZ *paSZargs
  72. )
  73. /*++
  74. Routine Description:
  75. Entry point for the locator server, Initialize data
  76. structures and start the various threads of excution.
  77. Arguments:
  78. cArgs - number of argument.
  79. paSZargs - vector of arguments.
  80. Returns:
  81. Allows 0
  82. --*/
  83. {
  84. USED(cArgs);
  85. SZ badArg;
  86. int Status = 0;
  87. unsigned long Role;
  88. BUFFER_STREAM_BASE *BuffStreamT;
  89. #if DBG
  90. if (!(BuffStreamT = new DEBUG_STREAM))
  91. AbortServer("Out of Memory");
  92. OSdebug = new ostream(BuffStreamT);
  93. if (!OSdebug)
  94. AbortServer("Out of Memory");
  95. OSdebug->setBuffer(BUFF_LINE);
  96. #endif
  97. if (!(BuffStreamT = new CONSOLE_STREAM))
  98. AbortServer("Out of Memory");
  99. if (!(cout = new ostream(BuffStreamT)))
  100. AbortServer("Out of Memory");
  101. cout->setBuffer(BUFF_FLUSH);
  102. ASSERT(AssertHeap());
  103. pESaccess = new MUTEX(&Status);
  104. if (Status)
  105. AbortServer("Can create Mutex", Status);
  106. pESnet = new MUTEX(&Status);
  107. if (Status)
  108. AbortServer("Can create Mutex", Status);
  109. EntryDict = new ENTRY_BASE_NODEDict;
  110. if (!pESaccess || !pESnet || !EntryDict)
  111. AbortServer("Out of Memory");
  112. ASSERT(AssertHeap());
  113. #ifndef NTENV
  114. // For OS/2 lose - the initial / on the switch list
  115. for (SWitch *pSW = aSwitchs; pSW->name; pSW++)
  116. pSW->name++;
  117. #endif
  118. badArg = ProcessArgs(aSwitchs, ++paSZargs);
  119. // Bail out on bad arguments.
  120. if (badArg) {
  121. char Buffer[200];
  122. fService = FALSE;
  123. AbortServer((SZ) strcat(strcpy(Buffer, "Command Line Error: "), badArg));
  124. }
  125. if (szOtherDomain)
  126. if (!(OtherDomain = UZFromSZ(szOtherDomain)))
  127. AbortServer("Out of Memory");
  128. Role = GetSystemType();
  129. DLIST(3, "..running on " << Role << nl);
  130. switch (Role)
  131. {
  132. case ROLE_WKSTA_MEMBER:
  133. case ROLE_LMNT_BACKUPDC:
  134. case ROLE_LMNT_PDC:
  135. Locator = (NATIVE_CLASS_LOCATOR *)
  136. new DOMAIN_MACHINE_LOCATOR(Role, &Status);
  137. break;
  138. case ROLE_WKSTA_WKGRP:
  139. Locator = (NATIVE_CLASS_LOCATOR *)
  140. new WRKGRP_MACHINE_LOCATOR(Role, &Status);
  141. break;
  142. default:
  143. ;
  144. };
  145. Locator->SetupHelperRoutine();
  146. SystemInit();
  147. return(0);
  148. }
  149. void
  150. StartServer(
  151. )
  152. /*++
  153. Routine Description:
  154. Call the runtime to create the server for the locator, the runtime
  155. will create it own threads to use to service calls.
  156. Returns:
  157. Never returns.
  158. --*/
  159. {
  160. RPC_STATUS result;
  161. #ifdef NTENV
  162. SECURITY_DESCRIPTOR SecurityDescriptor;
  163. BOOL Bool;
  164. #endif
  165. if (result = RpcServerRegisterIf(NsiS_ServerIfHandle, NIL, NIL))
  166. AbortServer("RpcServerRegisterIf", (int)result);
  167. if (result = RpcServerRegisterIf(NsiC_ServerIfHandle, NIL, NIL))
  168. AbortServer("RpcServerRegisterIf", (int)result);
  169. if (result = RpcServerRegisterIf(NsiM_ServerIfHandle, NIL, NIL))
  170. AbortServer("RpcServerRegisterIf", (int)result);
  171. if (result = RpcServerRegisterIf(LocToLoc_ServerIfHandle, NIL, NIL))
  172. AbortServer("RpcServerRegisterIf", (int)result);
  173. #ifdef NTENV
  174. //
  175. // Croft up a security descriptor that will grant everyone
  176. // all access to the object (basically, no security)
  177. //
  178. // We do this by putting in a NULL Dacl.
  179. //
  180. // BUGBUG: rpc should copy the security descriptor,
  181. // Since it currently doesn't, simply allocate it for now and
  182. // leave it around forever.
  183. //
  184. InitializeSecurityDescriptor(
  185. &SecurityDescriptor,
  186. SECURITY_DESCRIPTOR_REVISION
  187. );
  188. Bool = SetSecurityDescriptorDacl (
  189. &SecurityDescriptor,
  190. TRUE, // Dacl present
  191. (PACL)NULL, // NULL Dacl
  192. FALSE // Not defaulted
  193. );
  194. #endif
  195. if (result = RpcServerUseProtseqEp((unsigned char *) "ncacn_np",
  196. 1,
  197. (unsigned char *)pipeNameLoc,
  198. #ifdef NTENV
  199. &SecurityDescriptor
  200. #else
  201. NULL
  202. #endif
  203. ))
  204. {
  205. AbortServer("RpcServerUseProtseqEp named pipe", (int)result);
  206. }
  207. if (result = RpcServerListen(1, 1000, 1))
  208. AbortServer("RpcServerListen", (int)result);
  209. }