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.

260 lines
6.4 KiB

  1. /******************************************************************************
  2. *
  3. * Copyright (c) 2000 Microsoft Corporation
  4. *
  5. * Module Name:
  6. * rpcapi.cpp
  7. *
  8. * Abstract:
  9. * callthroughs for server-side rpc api
  10. *
  11. * Revision History:
  12. * Brijesh Krishnaswami (brijeshk) 04/13/2000
  13. * created
  14. *
  15. *****************************************************************************/
  16. #include "precomp.h"
  17. #ifdef THIS_FILE
  18. #undef THIS_FILE
  19. #endif
  20. static char __szTraceSourceFile[] = __FILE__;
  21. #define THIS_FILE __szTraceSourceFile
  22. BOOL CallerIsAdminOrSystem ()
  23. {
  24. BOOL fAdminOrSystem = FALSE;
  25. if (RPC_S_OK == RpcImpersonateClient (NULL))
  26. {
  27. fAdminOrSystem = IsAdminOrSystem();
  28. RpcRevertToSelf();
  29. }
  30. return fAdminOrSystem;
  31. };
  32. BOOL CallerIsAdminOrSystemOrPowerUsers()
  33. {
  34. BOOL fPowerUsers = FALSE;
  35. if (RPC_S_OK == RpcImpersonateClient (NULL))
  36. {
  37. fPowerUsers = IsAdminOrSystem() || IsPowerUsers();
  38. RpcRevertToSelf();
  39. }
  40. return fPowerUsers;
  41. }
  42. extern "C" DWORD DisableSRS(handle_t hif, LPCWSTR pszDrive)
  43. {
  44. tenter ("DisableSRS");
  45. if (!CallerIsAdminOrSystem())
  46. {
  47. trace (0, "DisableSRS Caller is not admin nor system");
  48. return ERROR_ACCESS_DENIED;
  49. }
  50. return g_pEventHandler ? g_pEventHandler->DisableSRS((LPWSTR) pszDrive) : ERROR_SERVICE_DISABLED;
  51. }
  52. extern "C" DWORD EnableSRS(handle_t hif, LPCWSTR pszDrive)
  53. {
  54. if (!CallerIsAdminOrSystem())
  55. {
  56. return ERROR_ACCESS_DENIED;
  57. }
  58. return g_pEventHandler ? g_pEventHandler->EnableSRS((LPWSTR) pszDrive) : ERROR_SERVICE_DISABLED;
  59. }
  60. extern "C" DWORD ResetSRS(handle_t hif, LPCWSTR pszDrive)
  61. {
  62. if (!CallerIsAdminOrSystem())
  63. {
  64. return ERROR_ACCESS_DENIED;
  65. }
  66. return g_pEventHandler ? g_pEventHandler->OnReset((LPWSTR) pszDrive) : ERROR_SERVICE_DISABLED;
  67. }
  68. extern "C" DWORD DisableFIFOS(handle_t hif, DWORD dwRPNum)
  69. {
  70. if (!CallerIsAdminOrSystem())
  71. {
  72. return ERROR_ACCESS_DENIED;
  73. }
  74. return g_pEventHandler ? g_pEventHandler->DisableFIFOS(dwRPNum) : ERROR_SERVICE_DISABLED;
  75. }
  76. extern "C" BOOL SRSetRestorePointS(
  77. handle_t hif,
  78. PRESTOREPOINTINFOW pRPInfo,
  79. PSTATEMGRSTATUS pSMgrStatus)
  80. {
  81. tenter("SRSetRestorePointS");
  82. if (pRPInfo == NULL || pRPInfo->dwRestorePtType != FIRSTRUN)
  83. {
  84. if (!CallerIsAdminOrSystemOrPowerUsers())
  85. {
  86. trace (0, "SRSetRestorePointS caller is not admin nor system nor powerusers");
  87. if (pSMgrStatus != NULL)
  88. {
  89. pSMgrStatus->nStatus = ERROR_ACCESS_DENIED;
  90. pSMgrStatus->llSequenceNumber = 0;
  91. }
  92. return FALSE;
  93. }
  94. }
  95. return g_pEventHandler ? g_pEventHandler->SRSetRestorePointS(pRPInfo, pSMgrStatus) : FALSE;
  96. }
  97. extern "C" DWORD SRRemoveRestorePointS(
  98. handle_t hif,
  99. DWORD dwRPNum)
  100. {
  101. tenter("SRRemoveRestorePointS");
  102. if (!CallerIsAdminOrSystemOrPowerUsers())
  103. {
  104. trace (0, "SRSetRestorePointS caller is not admin nor system nor powerusers");
  105. return ERROR_ACCESS_DENIED;
  106. }
  107. return g_pEventHandler ? g_pEventHandler->SRRemoveRestorePointS(dwRPNum) : ERROR_SERVICE_DISABLED;
  108. }
  109. extern "C" DWORD EnableFIFOS(handle_t hif)
  110. {
  111. if (!CallerIsAdminOrSystem())
  112. {
  113. return ERROR_ACCESS_DENIED;
  114. }
  115. return g_pEventHandler ? g_pEventHandler->EnableFIFOS() : ERROR_SERVICE_DISABLED;
  116. }
  117. extern "C" DWORD SRUpdateMonitoredListS(handle_t hif, LPCWSTR pszXMLFile)
  118. {
  119. if (!CallerIsAdminOrSystem())
  120. {
  121. return ERROR_ACCESS_DENIED;
  122. }
  123. return g_pEventHandler ? g_pEventHandler->SRUpdateMonitoredListS((LPWSTR) pszXMLFile) : ERROR_SERVICE_DISABLED;
  124. }
  125. extern "C" DWORD SRUpdateDSSizeS(handle_t hif, LPCWSTR pszDrive, UINT64 ullSizeLimit)
  126. {
  127. if (!CallerIsAdminOrSystem())
  128. {
  129. return ERROR_ACCESS_DENIED;
  130. }
  131. return g_pEventHandler ? g_pEventHandler->SRUpdateDSSizeS((LPWSTR) pszDrive, ullSizeLimit) : ERROR_SERVICE_DISABLED;
  132. }
  133. extern "C" DWORD SRSwitchLogS(handle_t hif)
  134. {
  135. if (!CallerIsAdminOrSystem())
  136. {
  137. return ERROR_ACCESS_DENIED;
  138. }
  139. return g_pEventHandler ? g_pEventHandler->SRSwitchLogS() : ERROR_SERVICE_DISABLED;
  140. }
  141. extern "C" DWORD FifoS(handle_t hif, LPCWSTR pszDrive, DWORD dwTargetRp, int nPercent, BOOL fIncludeCurrentRp, BOOL fFifoAtleastOneRp)
  142. {
  143. if (!CallerIsAdminOrSystem())
  144. {
  145. return ERROR_ACCESS_DENIED;
  146. }
  147. return g_pEventHandler ? g_pEventHandler->OnFifo((LPWSTR) pszDrive,
  148. dwTargetRp,
  149. nPercent,
  150. fIncludeCurrentRp,
  151. fFifoAtleastOneRp) : ERROR_SERVICE_DISABLED;
  152. }
  153. extern "C" DWORD CompressS(handle_t hif, LPCWSTR pszDrive)
  154. {
  155. if (!CallerIsAdminOrSystem())
  156. {
  157. return ERROR_ACCESS_DENIED;
  158. }
  159. return g_pEventHandler ? g_pEventHandler->OnCompress((LPWSTR) pszDrive) : ERROR_SERVICE_DISABLED;
  160. }
  161. extern "C" DWORD FreezeS(handle_t hif, LPCWSTR pszDrive)
  162. {
  163. if (!CallerIsAdminOrSystem())
  164. {
  165. return ERROR_ACCESS_DENIED;
  166. }
  167. return g_pEventHandler ? g_pEventHandler->OnFreeze((LPWSTR) pszDrive) : ERROR_SERVICE_DISABLED;
  168. }
  169. // fImproving - TRUE means going up
  170. // FALSE means going down
  171. extern "C" void SRNotifyS(handle_t hif, LPCWSTR pszDrive, DWORD dwFreeSpaceInMB, BOOL fImproving)
  172. {
  173. tenter("SRNotifyS");
  174. trace(0, "**Shell : drive = %S, dwFreeSpaceInMB = %ld, fImproving = %d",
  175. pszDrive, dwFreeSpaceInMB, fImproving);
  176. if (!CallerIsAdminOrSystem())
  177. {
  178. trace(0, "SRNotifyS caller is not admin nor system");
  179. return;
  180. }
  181. WORKITEMFUNC pf = NULL;
  182. if (g_pEventHandler)
  183. {
  184. if (dwFreeSpaceInMB >= 200 && fImproving == TRUE)
  185. {
  186. pf = OnDiskFree_200;
  187. }
  188. else if (dwFreeSpaceInMB <= 49 && fImproving == FALSE)
  189. {
  190. pf = OnDiskFree_50;
  191. }
  192. else if (dwFreeSpaceInMB <= 79 && fImproving == FALSE)
  193. {
  194. pf = OnDiskFree_80;
  195. }
  196. if (pf != NULL)
  197. {
  198. g_pEventHandler->QueueWorkItem(pf, (PVOID) pszDrive);
  199. }
  200. }
  201. }
  202. extern "C" DWORD SRPrintStateS(handle_t hif)
  203. {
  204. if (!CallerIsAdminOrSystem())
  205. {
  206. return ERROR_ACCESS_DENIED;
  207. }
  208. return g_pEventHandler ? g_pEventHandler->SRPrintStateS() : ERROR_SERVICE_DISABLED;
  209. }