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.

139 lines
3.5 KiB

  1. #include <precomp.h>
  2. LPWSTR pszStrBindingOptions = L"Security=Impersonation Dynamic False";
  3. handle_t
  4. STRING_HANDLE_bind(
  5. STRING_HANDLE lpStr)
  6. {
  7. RPC_STATUS RpcStatus = RPC_S_OK;
  8. LPWSTR strSrv;
  9. LPWSTR pszStringBinding = NULL;
  10. handle_t hBinding = NULL;
  11. LPWSTR pszServerPrincipalName = NULL;
  12. BOOL bBound = FALSE;
  13. strSrv = (!lpStr || !*lpStr || !lstrcmp(L"127.0.0.1", lpStr)) ? NULL : lpStr;
  14. RpcStatus = RpcStringBindingComposeW(
  15. 0,
  16. (strSrv==NULL) ? L"ncalrpc" : L"ncacn_np",
  17. strSrv,
  18. (strSrv==NULL) ? L"wzcsvc" : L"\\pipe\\wzcsvc",
  19. pszStrBindingOptions,
  20. &pszStringBinding);
  21. if (RpcStatus == RPC_S_OK)
  22. {
  23. RpcStatus = RpcBindingFromStringBindingW(
  24. pszStringBinding,
  25. &hBinding);
  26. RpcStringFreeW(&pszStringBinding);
  27. bBound = (RpcStatus == RPC_S_OK);
  28. }
  29. if (RpcStatus == RPC_S_OK)
  30. {
  31. RpcStatus = RpcBindingSetOption(
  32. hBinding,
  33. RPC_C_OPT_UNIQUE_BINDING,
  34. (ULONG_PTR) 1);
  35. }
  36. if (RpcStatus == RPC_S_OK)
  37. {
  38. RpcStatus = RpcMgmtInqServerPrincName(
  39. hBinding,
  40. RPC_C_AUTHN_WINNT,
  41. &pszServerPrincipalName);
  42. }
  43. if (RpcStatus == RPC_S_OK)
  44. {
  45. RpcStatus = RpcBindingSetAuthInfoW(
  46. hBinding,
  47. pszServerPrincipalName,
  48. RPC_C_PROTECT_LEVEL_PKT_PRIVACY,
  49. (strSrv==NULL) ? RPC_C_AUTHN_WINNT : RPC_C_AUTHN_GSS_NEGOTIATE,
  50. NULL,
  51. RPC_C_AUTHZ_NONE);
  52. }
  53. if (pszServerPrincipalName)
  54. RpcStringFree(&pszServerPrincipalName);
  55. if ( bBound && RpcStatus != RPC_S_OK)
  56. {
  57. STRING_HANDLE_unbind(lpStr, hBinding);
  58. hBinding = NULL;
  59. }
  60. return (hBinding);
  61. }
  62. VOID
  63. STRING_HANDLE_unbind(
  64. STRING_HANDLE lpStr,
  65. handle_t hBinding)
  66. {
  67. RPC_STATUS RpcStatus = 0;
  68. RpcStatus = RpcBindingFree(&hBinding);
  69. }
  70. handle_t
  71. WZC_DBLOG_SESSION_HANDLE_bind(
  72. WZC_DBLOG_SESSION_HANDLE hSession,
  73. STRING_HANDLE lpStr
  74. )
  75. {
  76. RPC_STATUS RpcStatus = 0;
  77. LPWSTR strSrv = NULL;
  78. LPWSTR pszStringBinding = NULL;
  79. handle_t hBinding = NULL;
  80. strSrv = (!lpStr || !*lpStr || !lstrcmp(L"127.0.0.1", lpStr)) ? NULL : lpStr;
  81. RpcStatus = RpcStringBindingComposeW(
  82. 0,
  83. (strSrv==NULL) ? L"ncalrpc" : L"ncacn_np",
  84. strSrv,
  85. (strSrv==NULL) ? L"wzcsvc" : L"\\pipe\\wzcsvc",
  86. pszStrBindingOptions,
  87. &pszStringBinding
  88. );
  89. if (RpcStatus != RPC_S_OK) {
  90. return NULL;
  91. }
  92. RpcStatus = RpcBindingFromStringBindingW(
  93. pszStringBinding,
  94. &hBinding
  95. );
  96. RpcStringFreeW(&pszStringBinding);
  97. if (RpcStatus != RPC_S_OK) {
  98. return NULL;
  99. }
  100. return (hBinding);
  101. }
  102. VOID
  103. WZC_DBLOG_SESSION_HANDLE_unbind(
  104. WZC_DBLOG_SESSION_HANDLE hSession,
  105. handle_t hBinding
  106. )
  107. {
  108. RPC_STATUS RpcStatus = 0;
  109. RpcStatus = RpcBindingFree(&hBinding);
  110. ASSERT(RpcStatus == RPC_S_OK);
  111. return;
  112. }