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.

158 lines
3.9 KiB

  1. /********************************************************************
  2. Copyright (c) 1999 Microsoft Corporation
  3. Module Name:
  4. sfprpcs.cpp
  5. Abstract:
  6. implements server rpc thread - exported in SFPSAPI.LIB
  7. server shutdown - exported in SFPSAPI.LIB
  8. Revision History:
  9. Brijesh Krishnaswami (brijeshk) - 06/16/99 - Created
  10. ********************************************************************/
  11. #include <windows.h>
  12. #include <stdio.h>
  13. #include <stdlib.h>
  14. #include "srrpc.h" // header file generated by MIDL compiler
  15. #include "srdefs.h"
  16. #include "utils.h"
  17. #include <dbgtrace.h>
  18. #ifdef THIS_FILE
  19. #undef THIS_FILE
  20. #endif
  21. static char __szTraceSourceFile[] = __FILE__;
  22. #define THIS_FILE __szTraceSourceFile
  23. #define MIN_RPC_CALLS 1
  24. #define MAX_RPC_CALLS 5
  25. RPC_STATUS RPC_ENTRY SecurityCallBack (RPC_IF_HANDLE hInterface,
  26. handle_t hBinding)
  27. {
  28. RPC_STATUS status = RPC_S_OK;
  29. UINT fLocal = FALSE;
  30. RPC_AUTHZ_HANDLE hPrivs;
  31. DWORD dwAuthn;
  32. status = I_RpcBindingIsClientLocal (hBinding, &fLocal);
  33. if (status != RPC_S_OK || fLocal == FALSE)
  34. {
  35. status = ERROR_ACCESS_DENIED;
  36. goto done;
  37. }
  38. status = RpcBindingInqAuthClient (hBinding,
  39. &hPrivs,
  40. NULL,
  41. &dwAuthn,
  42. NULL,
  43. NULL);
  44. if (status != RPC_S_OK || dwAuthn < RPC_C_AUTHN_LEVEL_PKT_INTEGRITY)
  45. {
  46. status = ERROR_ACCESS_DENIED;
  47. goto done;
  48. }
  49. done:
  50. return status;
  51. }
  52. // RPC Server
  53. // registers as an rpc server and waits for requests
  54. extern "C" DWORD WINAPI
  55. RpcServerStart()
  56. {
  57. RPC_STATUS status;
  58. TENTER("RpcServerStart");
  59. status = RpcServerRegisterAuthInfo(L"NT AUTHORITY\\SYSTEM",
  60. RPC_C_AUTHN_WINNT,
  61. 0,
  62. 0);
  63. if (status != RPC_S_OK)
  64. {
  65. TRACE(0, "! RpcServerRegisterAuthInfo : %ld", status);
  66. goto exit;
  67. }
  68. // specify to use the local rpc protocol sequence
  69. status = RpcServerUseProtseqEp(s_cszRPCProtocol,
  70. MAX_RPC_CALLS,
  71. s_cszRPCEndPoint,
  72. NULL); // Security descriptor
  73. if (status != 0 && status != RPC_S_DUPLICATE_ENDPOINT)
  74. {
  75. TRACE(0, "! RpcServerUseProtseqEp : %ld", status);
  76. goto exit;
  77. }
  78. // register the srrpc interface
  79. status = RpcServerRegisterIfEx(srrpc_ServerIfHandle, // interface to register
  80. NULL, // MgrTypeUuid
  81. NULL, // MgrEpv; null means use default
  82. RPC_IF_AUTOLISTEN | // auto-listen interface
  83. RPC_IF_ALLOW_SECURE_ONLY,
  84. MAX_RPC_CALLS, // max concurrent calls
  85. SecurityCallBack); // callback
  86. if (status)
  87. {
  88. TRACE(0, "! RpcServerRegisterIfEx : %ld", status);
  89. goto exit;
  90. }
  91. TRACE(0, "Started to listen to RPC calls");
  92. exit:
  93. TLEAVE();
  94. return status;
  95. }
  96. // function to shut down the rpc server
  97. extern "C" DWORD WINAPI
  98. RpcServerShutdown()
  99. {
  100. RPC_STATUS status;
  101. TENTER("RpcServerShutdown");
  102. // unregister the server endpoint
  103. status = RpcServerUnregisterIf(srrpc_ServerIfHandle, NULL, TRUE);
  104. if (status)
  105. {
  106. TRACE(0, "! RpcServerUnregisterIf : %ld", status);
  107. goto exit;
  108. }
  109. exit:
  110. TLEAVE();
  111. return status;
  112. }
  113. // functions used by midl compiler to allocate and free memory
  114. void __RPC_FAR * __RPC_USER midl_user_allocate(size_t len)
  115. {
  116. return(SRMemAlloc((DWORD) len));
  117. }
  118. void __RPC_USER midl_user_free(void __RPC_FAR * ptr)
  119. {
  120. SRMemFree(ptr);
  121. }