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.

153 lines
3.2 KiB

  1. /*++
  2. Copyright (C) Microsoft Corporation, 1992 - 1999
  3. Module Name:
  4. sbind.cxx
  5. Abstract:
  6. This is the server side NSI service support layer. These functions
  7. provide for binding to the locator.
  8. Author:
  9. Steven Zeck (stevez) 03/04/92
  10. --*/
  11. #define NSI_ASCII
  12. #define RegistryIsWorking
  13. #include <nsi.h>
  14. #ifdef NTENV
  15. #include <windows.h>
  16. #endif
  17. #include <winreg.h>
  18. #include <string.h>
  19. #ifdef NTENV
  20. #include <startsvc.h>
  21. #endif
  22. RPC_BINDING_HANDLE NsiSvrBinding; // global binding handle to locator
  23. // *** The following functions are used to RPC to the locator *** ///
  24. RPC_STATUS RPC_ENTRY
  25. I_NsServerBindSearch (
  26. )
  27. /*++
  28. Routine Description:
  29. Servers keep their RPC binding open until they terminate.
  30. Returns:
  31. RPC_S_OK, RPC_S_CALL_FAILED_DNE, RpcStringBindingCompose(),
  32. RpcBindingFromStringBinding()
  33. --*/
  34. {
  35. RPC_STATUS status;
  36. long statusTmp;
  37. static RPC_BINDING_HANDLE NsiSvrBindingExport;
  38. unsigned char * StringBinding;
  39. HKEY RegHandle;
  40. unsigned char *ProtoSeq;
  41. unsigned char *NetworkAddress;
  42. unsigned char *Endpoint;
  43. RequestGlobalMutex();
  44. if (NsiSvrBinding = NsiSvrBindingExport)
  45. {
  46. ClearGlobalMutex();
  47. return(RPC_S_OK);
  48. }
  49. #ifndef RegistryIsWorking
  50. ProtoSeq = (unsigned char *)"ncacn_np";
  51. NetworkAddress = 0;
  52. Endpoint = (unsigned char *)"\\pipe\\locator";
  53. DefaultSyntax = 1;
  54. status = RpcStringBindingCompose(0, ProtoSeq,
  55. NetworkAddress, Endpoint, 0, &StringBinding);
  56. #else
  57. // We store the binding information on the name service in
  58. // the registry. Get the information into BindingHandle.
  59. #ifdef NTENV
  60. statusTmp = RegOpenKeyEx(RPC_REG_ROOT, REG_NSI, 0L, KEY_READ,
  61. (PHKEY) &RegHandle);
  62. #else
  63. statusTmp = RegOpenKey(RPC_REG_ROOT, REG_NSI, (PHKEY) &RegHandle);
  64. #endif
  65. if (statusTmp)
  66. {
  67. ClearGlobalMutex();
  68. return(RPC_S_CALL_FAILED_DNE);
  69. }
  70. GetDefaultEntrys((void *) RegHandle);
  71. ProtoSeq = RegGetString((void *) RegHandle, "Protocol");
  72. NetworkAddress = RegGetString((void *) RegHandle, "ServerNetWorkAddress");
  73. Endpoint = RegGetString((void *) RegHandle, "Endpoint");
  74. status = RpcStringBindingCompose(0, ProtoSeq,
  75. NetworkAddress, Endpoint, 0, &StringBinding);
  76. #ifdef NTENV
  77. if ( (NetworkAddress == NULL)
  78. || (NetworkAddress[0] == '\0')
  79. || (strcmp ((char *)NetworkAddress, "\\\\.") == 0)
  80. )
  81. {
  82. //We are binding to the local locator..
  83. //lets start the local locator if not already started
  84. StartServiceIfNecessary();
  85. }
  86. #endif
  87. delete ProtoSeq;
  88. delete NetworkAddress;
  89. delete Endpoint;
  90. statusTmp = RegCloseKey(RegHandle);
  91. ASSERT(!statusTmp);
  92. #endif
  93. if (status)
  94. {
  95. ClearGlobalMutex();
  96. return(status);
  97. }
  98. status = RpcBindingFromStringBinding(StringBinding, &NsiSvrBinding);
  99. if (status == RPC_S_OK)
  100. NsiSvrBindingExport = NsiSvrBinding;
  101. statusTmp = RpcStringFree(&StringBinding);
  102. ASSERT(!statusTmp);
  103. ClearGlobalMutex();
  104. return (status);
  105. }