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.

134 lines
2.6 KiB

  1. /*++
  2. Copyright (c) 1990 Microsoft Corporation
  3. Module Name:
  4. bind.c
  5. Abstract:
  6. Contains the RPC bind and un-bind routines
  7. Author:
  8. Dave Snipp (davesn) 01-Jun-1991
  9. Environment:
  10. User Mode -Win32
  11. Revision History:
  12. --*/
  13. #include "precomp.h"
  14. #pragma hdrstop
  15. LPWSTR InterfaceAddress = L"\\pipe\\spoolss";
  16. handle_t GlobalBindHandle;
  17. handle_t
  18. STRING_HANDLE_bind (
  19. STRING_HANDLE lpStr)
  20. /*++
  21. Routine Description:
  22. This routine calls a common bind routine that is shared by all services.
  23. This routine is called from the server service client stubs when
  24. it is necessary to bind to a server.
  25. Arguments:
  26. lpStr - \\ServerName\PrinterName
  27. Return Value:
  28. The binding handle is returned to the stub routine. If the
  29. binding is unsuccessful, a NULL will be returned.
  30. --*/
  31. {
  32. RPC_STATUS RpcStatus;
  33. LPWSTR StringBinding;
  34. handle_t BindingHandle;
  35. WCHAR ServerName[MAX_PATH+2];
  36. DWORD i;
  37. if (lpStr && lpStr[0] == L'\\' && lpStr[1] == L'\\')
  38. {
  39. // We have a servername
  40. for (i = 2 ; lpStr[i] && lpStr[i] != L'\\' ; ++i)
  41. ;
  42. if (i >= COUNTOF(ServerName))
  43. return FALSE;
  44. wcsncpy(ServerName, lpStr, i);
  45. ServerName[i] = L'\0';
  46. }
  47. else
  48. {
  49. return NULL;
  50. }
  51. RpcStatus = RpcStringBindingComposeW(0, L"ncacn_np", ServerName,
  52. InterfaceAddress,
  53. L"Security=Impersonation Static True",
  54. &StringBinding);
  55. if ( RpcStatus != RPC_S_OK )
  56. {
  57. return NULL;
  58. }
  59. RpcStatus = RpcBindingFromStringBindingW(StringBinding, &BindingHandle);
  60. RpcStringFreeW(&StringBinding);
  61. if ( RpcStatus != RPC_S_OK )
  62. {
  63. return NULL;
  64. }
  65. return(BindingHandle);
  66. }
  67. void
  68. STRING_HANDLE_unbind (
  69. STRING_HANDLE lpStr,
  70. handle_t BindingHandle)
  71. /*++
  72. Routine Description:
  73. This routine calls a common unbind routine that is shared by
  74. all services.
  75. This routine is called from the server service client stubs when
  76. it is necessary to unbind to a server.
  77. Arguments:
  78. ServerName - This is the name of the server from which to unbind.
  79. BindingHandle - This is the binding handle that is to be closed.
  80. Return Value:
  81. none.
  82. --*/
  83. {
  84. RPC_STATUS RpcStatus;
  85. RpcStatus = RpcBindingFree(&BindingHandle);
  86. ASSERT(RpcStatus == RPC_S_OK);
  87. return;
  88. }