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.

229 lines
5.5 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1995.
  5. //
  6. // File: ntcopy.cxx
  7. //
  8. // Contents: NT Object Copy Routines
  9. //
  10. // Functions:
  11. //
  12. // History: 17-June-96 RamV Created.
  13. // cloned off NDS copy code.
  14. //
  15. //
  16. // Issues: Check null ptrs for AllocADsMem and AllocADsStr
  17. //
  18. //
  19. //
  20. //----------------------------------------------------------------------------
  21. //
  22. // NtType objects copy code
  23. //
  24. #include "winnt.hxx"
  25. #pragma hdrstop
  26. #define INITGUID
  27. HRESULT
  28. NtTypeCopy(
  29. PNTOBJECT lpNtSrcObject,
  30. PNTOBJECT lpNtDestObject
  31. )
  32. {
  33. HRESULT hr = S_OK;
  34. switch (lpNtSrcObject->NTType) {
  35. case NT_SYNTAX_ID_BOOL:
  36. lpNtDestObject->NTType = NT_SYNTAX_ID_BOOL;
  37. (lpNtDestObject->NTValue).fValue = (lpNtSrcObject->NTValue).fValue;
  38. break;
  39. case NT_SYNTAX_ID_SYSTEMTIME:
  40. lpNtDestObject->NTType = NT_SYNTAX_ID_SYSTEMTIME;
  41. (lpNtDestObject->NTValue).stSystemTimeValue =
  42. (lpNtSrcObject->NTValue).stSystemTimeValue;
  43. break;
  44. case NT_SYNTAX_ID_DATE_1970:
  45. lpNtDestObject->NTType = NT_SYNTAX_ID_DATE_1970;
  46. (lpNtDestObject->NTValue).dwSeconds1970 =
  47. (lpNtSrcObject->NTValue).dwSeconds1970;
  48. break;
  49. case NT_SYNTAX_ID_DWORD:
  50. lpNtDestObject->NTType = NT_SYNTAX_ID_DWORD;
  51. (lpNtDestObject->NTValue).dwValue =
  52. (lpNtSrcObject->NTValue).dwValue;
  53. break;
  54. case NT_SYNTAX_ID_DATE:
  55. lpNtDestObject->NTType = NT_SYNTAX_ID_DATE;
  56. (lpNtDestObject->NTValue).dwValue =
  57. (lpNtSrcObject->NTValue).dwValue;
  58. break;
  59. case NT_SYNTAX_ID_LPTSTR:
  60. lpNtDestObject->NTType = NT_SYNTAX_ID_LPTSTR;
  61. if(!(lpNtSrcObject->NTValue).pszValue){
  62. (lpNtDestObject->NTValue).pszValue = NULL;
  63. hr = S_OK;
  64. goto error;
  65. }
  66. (lpNtDestObject->NTValue).pszValue =
  67. AllocADsStr((lpNtSrcObject->NTValue).pszValue);
  68. hr =((lpNtDestObject->NTValue).pszValue == NULL)
  69. ? E_OUTOFMEMORY :S_OK;
  70. break;
  71. case NT_SYNTAX_ID_DelimitedString:
  72. lpNtDestObject->NTType = NT_SYNTAX_ID_DelimitedString;
  73. if(!(lpNtSrcObject->NTValue).pszValue){
  74. (lpNtDestObject->NTValue).pszValue = NULL;
  75. hr = S_OK;
  76. goto error;
  77. }
  78. (lpNtDestObject->NTValue).pszValue =
  79. AllocADsStr((lpNtSrcObject->NTValue).pszValue);
  80. hr =((lpNtDestObject->NTValue).pszValue == NULL)
  81. ? E_OUTOFMEMORY :S_OK;
  82. break;
  83. case NT_SYNTAX_ID_NulledString:
  84. lpNtDestObject->NTType = NT_SYNTAX_ID_NulledString;
  85. if(!(lpNtSrcObject->NTValue).pszValue){
  86. (lpNtDestObject->NTValue).pszValue = NULL;
  87. hr = S_OK;
  88. goto error;
  89. }
  90. (lpNtDestObject->NTValue).pszValue =
  91. AllocADsStr((lpNtSrcObject->NTValue).pszValue);
  92. hr =((lpNtDestObject->NTValue).pszValue == NULL)
  93. ? E_OUTOFMEMORY :S_OK;
  94. break;
  95. case NT_SYNTAX_ID_EncryptedString:
  96. lpNtDestObject->NTType = NT_SYNTAX_ID_EncryptedString;
  97. if(!(lpNtSrcObject->NTValue).pszValue){
  98. (lpNtDestObject->NTValue).pszValue = NULL;
  99. hr = S_OK;
  100. goto error;
  101. }
  102. (lpNtDestObject->NTValue).pszValue =
  103. AllocADsStr((lpNtSrcObject->NTValue).pszValue);
  104. hr =((lpNtDestObject->NTValue).pszValue == NULL)
  105. ? E_OUTOFMEMORY :S_OK;
  106. break;
  107. case NT_SYNTAX_ID_OCTETSTRING:
  108. lpNtDestObject->NTType = NT_SYNTAX_ID_OCTETSTRING;
  109. (lpNtDestObject->NTValue).octetstring.dwSize =
  110. (lpNtSrcObject->NTValue).octetstring.dwSize;
  111. if ((lpNtSrcObject->NTValue).octetstring.dwSize == 0) {
  112. (lpNtDestObject->NTValue).octetstring.pByte = NULL;
  113. }
  114. else {
  115. (lpNtDestObject->NTValue).octetstring.pByte =
  116. (BYTE*)AllocADsMem(sizeof(BYTE)*(lpNtSrcObject->NTValue).octetstring.dwSize);
  117. if (!(lpNtDestObject->NTValue).octetstring.pByte) {
  118. RRETURN(E_OUTOFMEMORY);
  119. }
  120. memcpy((lpNtDestObject->NTValue).octetstring.pByte,
  121. (lpNtSrcObject->NTValue).octetstring.pByte,
  122. (lpNtSrcObject->NTValue).octetstring.dwSize);
  123. }
  124. break;
  125. default:
  126. hr = E_FAIL;
  127. break;
  128. }
  129. error:
  130. RRETURN(hr);
  131. }
  132. HRESULT
  133. NtTypeCopyConstruct(
  134. LPNTOBJECT pNtSrcObjects,
  135. DWORD dwNumObjects,
  136. LPNTOBJECT * ppNtDestObjects
  137. )
  138. {
  139. DWORD i = 0;
  140. LPNTOBJECT pNtDestObjects = NULL;
  141. HRESULT hr = S_OK;
  142. pNtDestObjects = (LPNTOBJECT)AllocADsMem(
  143. dwNumObjects * sizeof(NTOBJECT)
  144. );
  145. if (!pNtDestObjects) {
  146. RRETURN(E_FAIL);
  147. }
  148. //
  149. // Zero out so we can clear the memory on an error
  150. //
  151. memset(pNtDestObjects, 0, dwNumObjects * sizeof(NTOBJECT));
  152. for (i = 0; i < dwNumObjects; i++ ) {
  153. hr = NtTypeCopy(pNtSrcObjects + i, pNtDestObjects + i);
  154. BAIL_ON_FAILURE(hr);
  155. }
  156. *ppNtDestObjects = pNtDestObjects;
  157. RRETURN(S_OK);
  158. error:
  159. NTTypeFreeNTObjects(pNtDestObjects, dwNumObjects);
  160. RRETURN(hr);
  161. }