Source code of Windows XP (NT5)
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.

81 lines
2.0 KiB

  1. /********************************************************************/
  2. /** Copyright(c) 1989 Microsoft Corporation. **/
  3. /********************************************************************/
  4. //***
  5. //
  6. // Filename: rpcutil.c
  7. //
  8. // Description: Contains RPC utiliry routines.
  9. //
  10. // History:
  11. // May 11,1992. NarenG Created original version.
  12. //
  13. #include "client.h"
  14. //**
  15. //
  16. // Call: AfpRPCBind
  17. //
  18. // Returns: NO_ERROR - success
  19. // ERROR_NOT_ENOUGH_MEMORY
  20. // AFPERR_InvalidComputername
  21. // non-sero returns from RPC calls.
  22. //
  23. // Description: This routine is called when it is necessary to bind to a server.
  24. // The binding is done to allow impersonation by the server since
  25. // that is necessary for the API calls.
  26. //
  27. DWORD
  28. AfpRPCBind(
  29. IN LPWSTR lpwsServerName,
  30. OUT PAFP_SERVER_HANDLE phAfpServer
  31. )
  32. {
  33. RPC_STATUS RpcStatus;
  34. LPWSTR lpwsStringBinding;
  35. LPWSTR lpwsEndpoint;
  36. // We need to concatenate \pipe\ to the front of the service
  37. // name.
  38. //
  39. lpwsEndpoint = (LPWSTR)LocalAlloc( 0, sizeof(NT_PIPE_PREFIX) +
  40. ((STRLEN(AFP_SERVICE_NAME)+1)*sizeof(WCHAR)));
  41. if ( lpwsEndpoint == NULL)
  42. return( ERROR_NOT_ENOUGH_MEMORY );
  43. STRCPY( lpwsEndpoint, NT_PIPE_PREFIX );
  44. STRCAT( lpwsEndpoint, AFP_SERVICE_NAME );
  45. RpcStatus = RpcStringBindingCompose(
  46. NULL,
  47. TEXT("ncacn_np"),
  48. lpwsServerName,
  49. lpwsEndpoint,
  50. TEXT("Security=Impersonation Static True"),
  51. &lpwsStringBinding);
  52. LocalFree( lpwsEndpoint );
  53. if ( RpcStatus != RPC_S_OK )
  54. return( I_RpcMapWin32Status( RpcStatus ) );
  55. RpcStatus = RpcBindingFromStringBinding( lpwsStringBinding,
  56. (handle_t *)phAfpServer );
  57. RpcStringFree( &lpwsStringBinding );
  58. if ( RpcStatus != RPC_S_OK ) {
  59. if ( ( RpcStatus == RPC_S_INVALID_ENDPOINT_FORMAT )
  60. ||
  61. ( RpcStatus == RPC_S_INVALID_NET_ADDR ) )
  62. return( (DWORD)AFPERR_InvalidComputername );
  63. else
  64. return( I_RpcMapWin32Status( RpcStatus ) );
  65. }
  66. return( NO_ERROR );
  67. }