Leaked source code of windows server 2003
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.

115 lines
3.0 KiB

  1. /****************************************************************************/
  2. // tempdir.c
  3. //
  4. // Copyright (C) 1997-1999 Microsoft Corp.
  5. /****************************************************************************/
  6. #include "precomp.h"
  7. #pragma hdrstop
  8. #define VOLATILE_PATH TEXT("Volatile Environment")
  9. PWSTR gszTmpDirPath;
  10. PWSTR gszTempDirPath;
  11. VOID RemovePerSessionTempDirs()
  12. {
  13. HKEY hKey;
  14. ULONG ultemp, ulType, ulValueData, fDelTemp = 1;
  15. NTSTATUS Status;
  16. if (!gszTempDirPath && !gszTmpDirPath)
  17. return;
  18. //
  19. // See if the registry value is set to delete the Per Session temp directory
  20. //
  21. if (RegOpenKeyExW(HKEY_LOCAL_MACHINE,
  22. REG_CONTROL_TSERVER,
  23. 0,
  24. KEY_READ,
  25. &hKey) == ERROR_SUCCESS) {
  26. ultemp = sizeof(fDelTemp);
  27. RegQueryValueEx(hKey,
  28. REG_CITRIX_DELETETEMPDIRSONEXIT,
  29. NULL,
  30. &ulType,
  31. (LPBYTE)&fDelTemp,
  32. &ultemp);
  33. RegCloseKey(hKey);
  34. }
  35. //
  36. // See if the POLICY registry value is set to delete the Per Session temp directory
  37. //
  38. if (RegOpenKeyExW(HKEY_LOCAL_MACHINE,
  39. TS_POLICY_SUB_TREE,
  40. 0,
  41. KEY_READ,
  42. &hKey) == ERROR_SUCCESS)
  43. {
  44. ultemp = sizeof(fDelTemp);
  45. if ( ERROR_SUCCESS == RegQueryValueEx(hKey,
  46. REG_CITRIX_DELETETEMPDIRSONEXIT,
  47. NULL,
  48. &ulType,
  49. (LPBYTE)&ulValueData,
  50. &ultemp) )
  51. {
  52. fDelTemp = ulValueData;
  53. }
  54. RegCloseKey(hKey);
  55. }
  56. if (fDelTemp) {
  57. if (gszTempDirPath) {
  58. RemoveDir(gszTempDirPath);
  59. free(gszTempDirPath);
  60. gszTempDirPath = NULL;
  61. }
  62. if (gszTmpDirPath) {
  63. RemoveDir(gszTmpDirPath);
  64. free(gszTmpDirPath);
  65. gszTmpDirPath = NULL;
  66. }
  67. }
  68. }
  69. BOOL
  70. TermsrvCreateTempDir( PVOID *pEnv,
  71. HANDLE UserToken,
  72. PSECURITY_DESCRIPTOR SD
  73. )
  74. {
  75. CTX_USER_DATA Ctx_User_Data;
  76. PCTX_USER_DATA pCtx_User_Data = NULL;
  77. BOOL retval;
  78. WCHAR pwcSessionId[16];
  79. if(UserToken || SD)
  80. {
  81. Ctx_User_Data.UserToken = UserToken;
  82. Ctx_User_Data.NewThreadTokenSD = SD;
  83. pCtx_User_Data = &Ctx_User_Data;
  84. }
  85. wsprintf(pwcSessionId,L"%lx",NtCurrentPeb()->SessionId);
  86. retval = CtxCreateTempDir(L"TEMP", pwcSessionId, pEnv,
  87. &gszTempDirPath, pCtx_User_Data );
  88. retval = CtxCreateTempDir(L"TMP", pwcSessionId, pEnv,
  89. &gszTmpDirPath, pCtx_User_Data );
  90. return retval;
  91. }