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.

294 lines
6.5 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. svcclnt.cpp
  5. Abstract:
  6. SCE service Client APIs
  7. Author:
  8. Jin Huang (jinhuang) 23-Jun-1997 created
  9. Revision History:
  10. jinhuang 23-Jan-1998 split to client-server model
  11. --*/
  12. #include "headers.h"
  13. #include "scesvc.h"
  14. #include "scerpc.h"
  15. #include <rpcasync.h>
  16. #pragma hdrstop
  17. //
  18. // prototypes exported in scesvc.h (public\sdk)
  19. //
  20. SCESTATUS
  21. WINAPI
  22. SceSvcQueryInfo(
  23. IN SCE_HANDLE sceHandle,
  24. IN SCESVC_INFO_TYPE sceType,
  25. IN PWSTR lpPrefix OPTIONAL,
  26. IN BOOL bExact,
  27. OUT PVOID *ppvInfo,
  28. OUT PSCE_ENUMERATION_CONTEXT psceEnumHandle
  29. )
  30. /*
  31. Routine Description:
  32. Query information for the service in the configuration/analysis database
  33. which contains the modified configuration and last analysis information.
  34. One enumeration returns maximum SCESVC_ENUMERATION_MAX lines (key/value)
  35. matching the lpPrefix for the service. If lpPrefix is NULL, all information
  36. for the service is enumerated. If there is more information, psceEnumHandle
  37. must be used to get next set of keys/values, until *ppvInfo is NULL or Count is 0.
  38. When bExact is set and lpPrefix is not NULL, exact match on the lpPrefix is
  39. searched and only one line is returned.
  40. The output buffer must be freed by SceSvcFree
  41. Arguments:
  42. sceHandle - the opaque handle obtained from SCE
  43. sceType - the information type to query
  44. lpPrefix - the optional key name prefix for the query
  45. bExact - TRUE = exact match on key
  46. ppvInfo - the output buffer
  47. psceEnumHandle - the output enumeration handle for next enumeartion
  48. Return Value:
  49. SCE status for this operation
  50. */
  51. {
  52. if ( sceHandle == NULL || ppvInfo == NULL ||
  53. psceEnumHandle == NULL ) {
  54. return(SCESTATUS_INVALID_PARAMETER);
  55. }
  56. SCESTATUS rc=SCESTATUS_SUCCESS;
  57. //
  58. // Validate sceHandle
  59. //
  60. PVOID hProfile=NULL;
  61. __try {
  62. hProfile = ((SCEP_HANDLE *)sceHandle)->hProfile;
  63. if ( !hProfile ||
  64. ((SCEP_HANDLE *)sceHandle)->ServiceName == NULL ) {
  65. rc = SCESTATUS_INVALID_PARAMETER;
  66. }
  67. } __except(EXCEPTION_EXECUTE_HANDLER) {
  68. rc = SCESTATUS_INVALID_PARAMETER;
  69. }
  70. if ( SCESTATUS_SUCCESS == rc ) {
  71. RpcTryExcept {
  72. //
  73. // call the RPC interface to query info from the database.
  74. //
  75. rc = SceSvcRpcQueryInfo(
  76. (SCEPR_CONTEXT)hProfile,
  77. (SCEPR_SVCINFO_TYPE)sceType,
  78. (wchar_t *)(((SCEP_HANDLE *)sceHandle)->ServiceName),
  79. (wchar_t *)lpPrefix,
  80. bExact,
  81. (PSCEPR_SVCINFO *)ppvInfo,
  82. (PSCEPR_ENUM_CONTEXT)psceEnumHandle
  83. );
  84. } RpcExcept( I_RpcExceptionFilter( RpcExceptionCode()) ) {
  85. //
  86. // get exception code (DWORD) and convert it into SCESTATUS
  87. //
  88. rc = ScepDosErrorToSceStatus(
  89. RpcExceptionCode());
  90. } RpcEndExcept;
  91. }
  92. return(rc);
  93. }
  94. SCESTATUS
  95. WINAPI
  96. SceSvcSetInfo(
  97. IN SCE_HANDLE sceHandle,
  98. IN SCESVC_INFO_TYPE sceType,
  99. IN PWSTR lpPrefix OPTIONAL,
  100. IN BOOL bExact,
  101. IN PVOID pvInfo OPTIONAL
  102. )
  103. /*
  104. Routine Description:
  105. Save information of a service into security manager internal database. It's up
  106. to the service to collect/decide the information to write.
  107. Type indicates the type of internal database: CONFIGURATION or ANALYSIS.
  108. If the service section does not exist, create it.
  109. Arguments:
  110. sceHandle - the opaque handle obtained from SCE
  111. sceType - the service information type to set
  112. lpPrefix - the key prefix to overwrite
  113. bExact - TRUE = only overwrite if there is exact match, insert if no match
  114. FALSE = overwrite all information for the service then add all
  115. info in the pvInfo buffer
  116. pvInfo - the information to set
  117. Return Value:
  118. SCE status
  119. */
  120. {
  121. if ( sceHandle == NULL ) {
  122. return(SCESTATUS_INVALID_PARAMETER);
  123. }
  124. SCESTATUS rc=SCESTATUS_SUCCESS;
  125. //
  126. // Validate sceHandle
  127. //
  128. PVOID hProfile=NULL;
  129. __try {
  130. hProfile = ((SCEP_HANDLE *)sceHandle)->hProfile;
  131. if ( !hProfile ||
  132. ((SCEP_HANDLE *)sceHandle)->ServiceName == NULL ) {
  133. rc = SCESTATUS_INVALID_PARAMETER;
  134. }
  135. } __except(EXCEPTION_EXECUTE_HANDLER) {
  136. rc = SCESTATUS_INVALID_PARAMETER;
  137. }
  138. if ( SCESTATUS_SUCCESS == rc ) {
  139. RpcTryExcept {
  140. //
  141. // call the RPC interface to query info from the database.
  142. //
  143. rc = SceSvcRpcSetInfo(
  144. (SCEPR_CONTEXT)hProfile,
  145. (SCEPR_SVCINFO_TYPE)sceType,
  146. (wchar_t *)(((SCEP_HANDLE *)sceHandle)->ServiceName),
  147. (wchar_t *)lpPrefix,
  148. bExact,
  149. (PSCEPR_SVCINFO)pvInfo
  150. );
  151. } RpcExcept( I_RpcExceptionFilter( RpcExceptionCode()) ) {
  152. //
  153. // get exception code (DWORD) and convert it into SCESTATUS
  154. //
  155. rc = ScepDosErrorToSceStatus(
  156. RpcExceptionCode());
  157. } RpcEndExcept;
  158. }
  159. return(rc);
  160. }
  161. SCESTATUS
  162. WINAPI
  163. SceSvcFree(
  164. IN PVOID pvServiceInfo
  165. )
  166. {
  167. return (SceSvcpFreeMemory(pvServiceInfo) );
  168. }
  169. SCESTATUS
  170. WINAPI
  171. SceSvcConvertTextToSD (
  172. IN PWSTR pwszTextSD,
  173. OUT PSECURITY_DESCRIPTOR *ppSD,
  174. OUT PULONG pulSDSize,
  175. OUT PSECURITY_INFORMATION psiSeInfo
  176. )
  177. {
  178. DWORD Win32rc;
  179. Win32rc = ConvertTextSecurityDescriptor(
  180. pwszTextSD,
  181. ppSD,
  182. pulSDSize,
  183. psiSeInfo
  184. );
  185. return(ScepDosErrorToSceStatus(Win32rc));
  186. }
  187. SCESTATUS
  188. WINAPI
  189. SceSvcConvertSDToText (
  190. IN PSECURITY_DESCRIPTOR pSD,
  191. IN SECURITY_INFORMATION siSecurityInfo,
  192. OUT PWSTR *ppwszTextSD,
  193. OUT PULONG pulTextSize
  194. )
  195. {
  196. DWORD Win32rc;
  197. Win32rc = ConvertSecurityDescriptorToText(
  198. pSD,
  199. siSecurityInfo,
  200. ppwszTextSD,
  201. pulTextSize
  202. );
  203. return(ScepDosErrorToSceStatus(Win32rc));
  204. }