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.

200 lines
8.4 KiB

  1. /////////////////////////////////////////////////////////////
  2. // Copyright(c) 1998-2000, Microsoft Corporation
  3. //
  4. // usepa.h
  5. //
  6. // Created on 8/15/98 by Randyram
  7. // Revisions:
  8. // 2/29/00 - DKalin
  9. // Removed out-of-date PA routines
  10. // Added new ipsecpol service management routines
  11. //
  12. // Includes util routines enables you to call PA and ipsecpolsvc RPC API
  13. //
  14. /////////////////////////////////////////////////////////////
  15. #ifndef _USEPARPC_H_
  16. #define _USEPARPC_H_
  17. #include <tchar.h>
  18. #include <windows.h>
  19. // const defs
  20. const _TUCHAR szLOCALENDPT[] = TEXT("policyagent");
  21. const TCHAR szLOCAL_MACHINE[] = TEXT("\\\\.");
  22. const UINT USEPARPC_LOCLEN = sizeof(szLOCAL_MACHINE) / sizeof(TCHAR);
  23. ////////////////////////////////////////////////////////////////
  24. // Function: PAIsRunning
  25. // Purpose: checks to see if Policy Agent service is up
  26. //
  27. // Pre-conditions: none
  28. //
  29. // Parameters:
  30. // dwReturn OUT holds errors returned from SCM if any
  31. // szServ IN OPT if not NULL, name of remote machine
  32. // Returns:
  33. // true on success (dwReturn is set to ERROR_SUCCESS)
  34. // false && dwReturn == ERROR_SUCCESS means PA service is not running
  35. // false && dwReturn != ERROR_SUCCESS an SCM operation failed,
  36. // dwReturn holds GetLastError from SCM call
  37. bool PAIsRunning(OUT DWORD &dwReturn, OPTIONAL TCHAR *szServ = NULL);
  38. ////////////////////////////////////////////////////////////////
  39. // Function: StartPA
  40. // Purpose: starts policy agent service
  41. //
  42. // Pre-conditions: none
  43. //
  44. // Parameters:
  45. // dwReturn OUT holds errors returned from SCM if any
  46. // szServ IN OPT if not NULL, name of remote machine
  47. // Returns:
  48. // true on success (dwReturn is set to ERROR_SUCCESS)
  49. // false && dwReturn != ERROR_SUCCESS an SCM operation failed,
  50. // dwReturn holds GetLastError from SCM call
  51. bool StartPA(OUT DWORD &dwReturn, OPTIONAL TCHAR *szServ = NULL);
  52. /*********************************************************************
  53. FUNCTION: InstallIpsecpolService
  54. PURPOSE: Installs ipsecpolsvc service (incl. copying .exe to system32 dir)
  55. PARAMS:
  56. pszFilename - name of the .exe file (full path recommended)
  57. bFailIfExists - if TRUE, fail if service already exists,
  58. if FALSE, stop service, delete it and proceed
  59. ( default = TRUE )
  60. RETURNS: ERROR_SUCESS or GetLastError code
  61. COMMENTS:
  62. *********************************************************************/
  63. DWORD InstallIpsecpolService (IN LPCTSTR pszFilename, IN OPTIONAL BOOL bFailIfExists = TRUE );
  64. /*********************************************************************
  65. FUNCTION: StartIpsecpolService
  66. PURPOSE: Attempts to start ipsecpolsvc service
  67. PARAMS:
  68. pszServ - optional name of the server (default is NULL, start on local machine)
  69. RETURNS: ERROR_SUCESS or GetLastError code
  70. COMMENTS:
  71. *********************************************************************/
  72. DWORD StartIpsecpolService (IN OPTIONAL LPCTSTR pszServ = NULL);
  73. /*********************************************************************
  74. FUNCTION: StopIpsecpolService
  75. PURPOSE: Attempts to stop ipsecpolsvc service
  76. PARAMS:
  77. pszServ - optional name of the server (default is NULL, start on local machine)
  78. RETURNS: ERROR_SUCESS or GetLastError code
  79. COMMENTS:
  80. *********************************************************************/
  81. DWORD StopIpsecpolService (IN OPTIONAL LPCTSTR pszServ = NULL);
  82. /*********************************************************************
  83. FUNCTION: IsIpsecpolServiceRunning
  84. PURPOSE: Checks if ipsecpolsvc service is currently running
  85. PARAMS:
  86. dwReturn - holds errors retuned by SCM if any
  87. pszServ - optional name of the server (default is NULL, start on local machine)
  88. RETURNS: TRUE/FALSE
  89. COMMENTS: TRUE returned means service is running
  90. FALSE and dwReturn == ERROR_SUCCESS means service is not running
  91. FALSE and dwReturn != ERROR_SUCCESS means SCM operation failed (dwReturn is error code)
  92. *********************************************************************/
  93. BOOL IsIpsecpolServiceRunning (OUT DWORD &dwReturn, OPTIONAL LPCTSTR pszServ = NULL);
  94. /*********************************************************************
  95. FUNCTION: InitIpsecpolsvcRPC
  96. PURPOSE: Get an RPC handle from ipsecpolsvc that can be used to call its APIs
  97. PARAMS:
  98. pszServ - name of the server (pass NULL for the local machine)
  99. hIpsecpolsvc - returned handle
  100. RETURNS: RPC_S_OK or RPC api error code
  101. COMMENTS: Service running is not prereq
  102. *********************************************************************/
  103. RPC_STATUS InitIpsecpolsvcRPC (IN TCHAR* pszServ, OUT handle_t &hIpsecpolsvc);
  104. /*********************************************************************
  105. FUNCTION: ShutdownIpsecpolsvcRPC
  106. PURPOSE: Close RPC handle
  107. PARAMS:
  108. hIpsecpolsvc - handle
  109. RETURNS: RPC_S_OK or RPC api error code
  110. COMMENTS:
  111. *********************************************************************/
  112. RPC_STATUS ShutdownIpsecpolsvcRPC (IN handle_t hIpsecpolsvc);
  113. /*********************************************************************
  114. FUNCTION: PlumbIPSecPolicy
  115. PURPOSE: Plumbs IPSEC_IKE_POLICY to the specified machine
  116. PARAMS:
  117. pszServerName - machine name or NULL for local
  118. pIPSecIkePol - pointer to IPSEC_IKE_POLICY.
  119. GUIDs/names must be generated prior to the call
  120. bFailMMIfExists - specifies MM filter behavior
  121. bFailMMIfExists == FALSE will cause the call not to break
  122. on ERROR_MM_FILTER_EXISTS when duplicate MM filters are there
  123. bFailMMIfExists == TRUE will fail on any SPD API error
  124. ppMMFilterHandles - array of mm filter handles will be returned here
  125. ppFilterHandles - array of qm filter handles will be returned here
  126. bPersist - if TRUE, information will be persisted
  127. RETURNS: ERROR_SUCCESS or win32 error code
  128. COMMENTS: CALLER is responsible for freeing the memory for the handle arrays
  129. *********************************************************************/
  130. DWORD
  131. PlumbIPSecPolicy(
  132. IN LPWSTR pServerName,
  133. IN PIPSEC_IKE_POLICY pIPSecIkePol,
  134. IN BOOL bFailMMIfExists,
  135. OUT PHANDLE *ppMMFilterHandles,
  136. OUT PHANDLE *ppFilterHandles,
  137. IN OPTIONAL BOOL bPersist = FALSE
  138. );
  139. /*********************************************************************
  140. FUNCTION: DeleteIPSecPolicy
  141. PURPOSE: Complementary to PlumbIPSecPolicy, removes IPSEC_IKE_POLICY
  142. PARAMS:
  143. pszServerName - machine name or NULL for local
  144. pIPSecIkePol - pointer to IPSEC_IKE_POLICY.
  145. GUIDs/names must be generated prior to the call
  146. pMMFilterHandles - array of main mode filter handles
  147. pFilterHandles - array of quick mode filter handles
  148. RETURNS: ERROR_SUCCESS or win32 error code
  149. COMMENTS: Function will try to
  150. remove everything specified in the IPSEC_IKE_POLICY structure.
  151. It is possible that one or several errors will be encountered.
  152. Function will continue, but later first error will be returned.
  153. *********************************************************************/
  154. DWORD
  155. DeleteIPSecPolicy(
  156. IN LPWSTR pServerName,
  157. IN PIPSEC_IKE_POLICY pIPSecIkePol,
  158. IN PHANDLE pMMFilterHandles,
  159. IN PHANDLE pFilterHandles
  160. );
  161. /*********************************************************************
  162. FUNCTION: DeletePersistedIPSecPolicy
  163. PURPOSE: Complementary to PlumbIPSecPolicy with persistent flag on,
  164. removes persisted policy
  165. PARAMS:
  166. pszServerName - machine name or NULL for local
  167. pPolicyName - policy name prefix, if empty string of NULL,
  168. all persisted policy settings will be removed
  169. RETURNS: ERROR_SUCCESS or win32 error code
  170. COMMENTS: Function will try to
  171. remove everything specified.
  172. It is possible that one or several errors will be encountered.
  173. Function will continue, but later first error will be returned.
  174. *********************************************************************/
  175. DWORD
  176. DeletePersistedIPSecPolicy(
  177. IN LPWSTR pServerName,
  178. IN LPWSTR pPolicyName
  179. );
  180. #endif /* _USEPARPC_H_ */
  181.