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.

170 lines
3.0 KiB

4 years ago
  1. /*++
  2. Copyright (c) 1992 Microsoft Corporation
  3. Module Name:
  4. cbind.cxx
  5. Abstract:
  6. This is the client side NSI service support layer. These functions
  7. provide for binding to the locator or other name server.
  8. Author:
  9. Steven Zeck (stevez) 03/04/92
  10. --*/
  11. extern "C"
  12. {
  13. #define NSI_ASCII
  14. #include <nsi.h>
  15. #ifndef USHORT
  16. #define USHORT unsigned short
  17. #endif
  18. #include <windows.h>
  19. #include <stdlib.h>
  20. #include <string.h>
  21. } // extern "C"
  22. RPC_BINDING_HANDLE NsiClntBinding = NULL;// global binding handle to locator
  23. WIDE_STRING *DefaultName;
  24. long DefaultSyntax = RPC_C_NS_SYNTAX_DCE;
  25. int fSyntaxDefaultsLoaded;
  26. unsigned char *
  27. RegGetString(
  28. IN void * RegHandle,
  29. IN char * KeyName
  30. )
  31. /*++
  32. Routine Description:
  33. Get a string from the registery.
  34. Arguments:
  35. KeyName - name of key to lookup.
  36. Returns:
  37. pointer to the allocated string, or Nil if not found
  38. --*/
  39. {
  40. char Buffer[300];
  41. DWORD BufferLength = sizeof(Buffer);
  42. DWORD Type;
  43. if (RegQueryValueEx((HKEY)RegHandle, KeyName, 0, &Type,
  44. (unsigned char far*)Buffer, &BufferLength))
  45. return(0);
  46. return(CopyString(Buffer));
  47. }
  48. RPC_STATUS RPC_ENTRY
  49. I_NsClientBindSearch(
  50. )
  51. /*++
  52. Routine Description:
  53. The function binds to the locator, first it tries to bind to a
  54. local machine, then it attempts to bind to the domain controller.
  55. Arguments:
  56. BindingSearchContext - context of search for the locator.
  57. Returns:
  58. RPC_S_OK, RPC_S_NO_BINDINGS, RPC_S_CANNOT_BIND, RPC_S_OUT_OF_RESOURCES
  59. --*/
  60. {
  61. RPC_STATUS RpcStatus;
  62. long status;
  63. unsigned char * Protseq;
  64. unsigned char * NetworkAddress;
  65. unsigned char * Endpoint;
  66. unsigned char * StringBinding;
  67. HKEY RegHandle;
  68. if (NsiClntBinding != NULL) {
  69. return (RPC_S_NAME_SERVICE_UNAVAILABLE);
  70. }
  71. status = RegOpenKeyEx(RPC_REG_ROOT, REG_NSI, 0L, KEY_READ,
  72. &RegHandle);
  73. if (status) {
  74. return(RPC_S_NAME_SERVICE_UNAVAILABLE);
  75. }
  76. Protseq = RegGetString((void *) RegHandle, "Protocol");
  77. if (Protseq == NULL) {
  78. return(RPC_S_NAME_SERVICE_UNAVAILABLE);
  79. }
  80. NetworkAddress = RegGetString((void *) RegHandle, "NetworkAddress");
  81. if (NetworkAddress == NULL) {
  82. return (RPC_S_NAME_SERVICE_UNAVAILABLE);
  83. }
  84. Endpoint = RegGetString((void *) RegHandle, "Endpoint");
  85. if (Endpoint == NULL) {
  86. return (RPC_S_NAME_SERVICE_UNAVAILABLE);
  87. }
  88. GetDefaultEntrys((void *)RegHandle);
  89. RpcStatus = RpcStringBindingCompose(0, Protseq, NetworkAddress, Endpoint,
  90. 0, &StringBinding);
  91. if (RpcStatus != RPC_S_OK) {
  92. return(status);
  93. }
  94. RpcStatus = RpcBindingFromStringBinding(StringBinding, &NsiClntBinding);
  95. RpcStringFree(&StringBinding);
  96. return (RpcStatus);
  97. }
  98. void RPC_ENTRY
  99. I_NsClientBindDone(
  100. )
  101. /*++
  102. Routine Description:
  103. The function cleans up after binding to the locator.
  104. Returns:
  105. --*/
  106. {
  107. RPC_STATUS RpcStatus;
  108. RpcStatus = RpcBindingFree(&NsiClntBinding);
  109. ASSERT(!RpcStatus);
  110. }