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.

159 lines
3.5 KiB

  1. /*++
  2. Copyright (c) 1992 Microsoft Corporation
  3. Module Name:
  4. atbind.c
  5. Abstract:
  6. Routines which use RPC to bind and unbind the client to the schedule
  7. service.
  8. Author:
  9. Vladimir Z. Vulovic (vladimv) 06 - November - 1992
  10. Environment:
  11. User Mode -Win32
  12. Revision History:
  13. 06-Nov-1992 vladimv
  14. Created
  15. --*/
  16. #include "atclient.h"
  17. #include "stdio.h"
  18. #include "Ntdsapi.h"
  19. handle_t
  20. ATSVC_HANDLE_bind(
  21. ATSVC_HANDLE ServerName
  22. )
  23. /*++
  24. Routine Description:
  25. This routine calls a common bind routine that is shared by all services.
  26. This routine is called from the schedule service client stubs when
  27. it is necessary to bind to a server.
  28. Arguments:
  29. ServerName - A pointer to a string containing the name of the server
  30. to bind with.
  31. Return Value:
  32. The binding handle is returned to the stub routine. If the bind is
  33. unsuccessful, a NULL will be returned.
  34. --*/
  35. {
  36. handle_t BindingHandle = NULL;
  37. RPC_STATUS RpcStatus;
  38. RPC_SECURITY_QOS qos;
  39. DWORD size = MAX_PATH +1;
  40. WCHAR spn[MAX_PATH +1];
  41. WCHAR* pSpn = NULL;
  42. RpcStatus = NetpBindRpc (
  43. (LPTSTR)ServerName,
  44. AT_INTERFACE_NAME,
  45. TEXT("Security=impersonation static true"),
  46. &BindingHandle
  47. );
  48. if (RpcStatus != ERROR_SUCCESS)
  49. return NULL;
  50. if (ServerName != NULL)
  51. {
  52. RpcStatus = DsMakeSpn(AT_INTERFACE_NAME, ServerName, NULL, 0, NULL, &size, spn);
  53. if (RpcStatus == ERROR_SUCCESS)
  54. pSpn = spn;
  55. else
  56. {
  57. NetpUnbindRpc( BindingHandle);
  58. return NULL;
  59. }
  60. }
  61. ZeroMemory(&qos, sizeof(RPC_SECURITY_QOS));
  62. qos.Version = RPC_C_SECURITY_QOS_VERSION;
  63. qos.Capabilities = RPC_C_QOS_CAPABILITIES_DEFAULT;
  64. qos.IdentityTracking = RPC_C_QOS_IDENTITY_DYNAMIC;
  65. qos.ImpersonationType = RPC_C_IMP_LEVEL_IMPERSONATE;
  66. RpcStatus = RpcBindingSetAuthInfoEx(BindingHandle,
  67. pSpn,
  68. RPC_C_AUTHN_LEVEL_PKT_PRIVACY,
  69. RPC_C_AUTHN_GSS_NEGOTIATE,
  70. NULL,
  71. RPC_C_AUTHZ_NONE,
  72. &qos);
  73. if (RpcStatus != ERROR_SUCCESS)
  74. {
  75. NetpUnbindRpc( BindingHandle);
  76. return NULL;
  77. }
  78. // printf("RpcBindingSetAuthInfoEx returned %u\n", RpcStatus);
  79. #ifdef DEBUG
  80. if ( RpcStatus != ERRROR_SUCCESS) {
  81. DbgPrint("ATSVC_HANDLE_bind:NetpBindRpc RpcStatus=%d\n",RpcStatus);
  82. }
  83. DbgPrint("ATSVC_HANDLE_bind: handle=%d\n", BindingHandle);
  84. #endif
  85. return( BindingHandle);
  86. }
  87. void
  88. ATSVC_HANDLE_unbind(
  89. ATSVC_HANDLE ServerName,
  90. handle_t BindingHandle
  91. )
  92. /*++
  93. Routine Description:
  94. This routine calls a common unbind routine that is shared by all services.
  95. This routine is called from the Workstation service client stubs when it is
  96. necessary to unbind from the server end.
  97. Arguments:
  98. ServerName - This is the name of the server from which to unbind.
  99. BindingHandle - This is the binding handle that is to be closed.
  100. Return Value:
  101. None.
  102. --*/
  103. {
  104. UNREFERENCED_PARAMETER( ServerName);
  105. #ifdef DEBUG
  106. DbgPrint(" ATSVC_HANDLE_unbind: handle= 0x%x\n", BindingHandle);
  107. #endif // DEBUG
  108. NetpUnbindRpc( BindingHandle);
  109. }
  110.