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.

256 lines
5.7 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1995.
  5. //
  6. // File: nwcopy.cxx
  7. //
  8. // Contents: Nw312 Object Copy Routines
  9. //
  10. // Functions:
  11. //
  12. // History: 17-June-96 KrishnaG 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 "nwcompat.hxx"
  25. #pragma hdrstop
  26. HRESULT
  27. NtTypeCopy(
  28. PNTOBJECT lpNtSrcObject,
  29. PNTOBJECT lpNtDestObject
  30. )
  31. {
  32. HRESULT hr = S_OK;
  33. switch (lpNtSrcObject->NTType) {
  34. case NT_SYNTAX_ID_BOOL:
  35. lpNtDestObject->NTType = NT_SYNTAX_ID_BOOL;
  36. (lpNtDestObject->NTValue).fValue = (lpNtSrcObject->NTValue).fValue;
  37. break;
  38. case NT_SYNTAX_ID_SYSTEMTIME:
  39. lpNtDestObject->NTType = NT_SYNTAX_ID_SYSTEMTIME;
  40. (lpNtDestObject->NTValue).stSystemTimeValue =
  41. (lpNtSrcObject->NTValue).stSystemTimeValue;
  42. break;
  43. case NT_SYNTAX_ID_DWORD:
  44. lpNtDestObject->NTType = NT_SYNTAX_ID_DWORD;
  45. (lpNtDestObject->NTValue).dwValue =
  46. (lpNtSrcObject->NTValue).dwValue;
  47. break;
  48. case NT_SYNTAX_ID_DATE:
  49. lpNtDestObject->NTType = NT_SYNTAX_ID_DATE;
  50. (lpNtDestObject->NTValue).dwValue =
  51. (lpNtSrcObject->NTValue).dwValue;
  52. break;
  53. case NT_SYNTAX_ID_NW312DATE:
  54. lpNtDestObject->NTType = NT_SYNTAX_ID_NW312DATE;
  55. memcpy(
  56. (lpNtDestObject->NTValue).Nw312Date,
  57. (lpNtSrcObject->NTValue).Nw312Date,
  58. 6
  59. );
  60. break;
  61. case NT_SYNTAX_ID_LPTSTR:
  62. lpNtDestObject->NTType = NT_SYNTAX_ID_LPTSTR;
  63. if(!(lpNtSrcObject->NTValue).pszValue){
  64. (lpNtDestObject->NTValue).pszValue = NULL;
  65. hr = S_OK;
  66. goto error;
  67. }
  68. (lpNtDestObject->NTValue).pszValue =
  69. AllocADsStr((lpNtSrcObject->NTValue).pszValue);
  70. hr =((lpNtDestObject->NTValue).pszValue == NULL)
  71. ? E_OUTOFMEMORY :S_OK;
  72. break;
  73. case NT_SYNTAX_ID_OCTETSTRING:
  74. lpNtDestObject->NTType = NT_SYNTAX_ID_OCTETSTRING;
  75. (lpNtDestObject->NTValue).octetstring.dwSize =
  76. (lpNtSrcObject->NTValue).octetstring.dwSize;
  77. if ((lpNtSrcObject->NTValue).octetstring.dwSize == 0) {
  78. (lpNtDestObject->NTValue).octetstring.pByte = NULL;
  79. }
  80. else {
  81. (lpNtDestObject->NTValue).octetstring.pByte =
  82. (BYTE*)AllocADsMem(sizeof(BYTE)*(lpNtSrcObject->NTValue).octetstring.dwSize);
  83. if (!(lpNtDestObject->NTValue).octetstring.pByte) {
  84. RRETURN(E_OUTOFMEMORY);
  85. }
  86. memcpy((lpNtDestObject->NTValue).octetstring.pByte,
  87. (lpNtSrcObject->NTValue).octetstring.pByte,
  88. (lpNtSrcObject->NTValue).octetstring.dwSize);
  89. }
  90. break;
  91. case NT_SYNTAX_ID_DelimitedString:
  92. lpNtDestObject->NTType = NT_SYNTAX_ID_DelimitedString;
  93. if(!(lpNtSrcObject->NTValue).pszValue){
  94. (lpNtDestObject->NTValue).pszValue = NULL;
  95. hr = S_OK;
  96. goto error;
  97. }
  98. (lpNtDestObject->NTValue).pszValue =
  99. AllocADsStr((lpNtSrcObject->NTValue).pszValue);
  100. hr =((lpNtDestObject->NTValue).pszValue == NULL)
  101. ? E_OUTOFMEMORY :S_OK;
  102. break;
  103. case NT_SYNTAX_ID_NulledString:
  104. lpNtDestObject->NTType = NT_SYNTAX_ID_NulledString;
  105. if(!(lpNtSrcObject->NTValue).pszValue){
  106. (lpNtDestObject->NTValue).pszValue = NULL;
  107. hr = S_OK;
  108. goto error;
  109. }
  110. hr = CopyNulledString((lpNtSrcObject->NTValue).pszValue,
  111. &(lpNtDestObject->NTValue).pszValue );
  112. BAIL_ON_FAILURE(hr);
  113. break;
  114. default:
  115. hr = E_FAIL;
  116. break;
  117. }
  118. error:
  119. RRETURN(hr);
  120. }
  121. HRESULT
  122. NtTypeCopyConstruct(
  123. LPNTOBJECT pNtSrcObjects,
  124. DWORD dwNumObjects,
  125. LPNTOBJECT * ppNtDestObjects
  126. )
  127. {
  128. DWORD i = 0;
  129. LPNTOBJECT pNtDestObjects = NULL;
  130. HRESULT hr = S_OK;
  131. pNtDestObjects = (LPNTOBJECT)AllocADsMem(
  132. dwNumObjects * sizeof(NTOBJECT)
  133. );
  134. if (!pNtDestObjects) {
  135. RRETURN(E_FAIL);
  136. }
  137. //
  138. // Zero out so we can clear the memory on an error
  139. //
  140. memset(pNtDestObjects, 0, dwNumObjects * sizeof(NTOBJECT));
  141. for (i = 0; i < dwNumObjects; i++ ) {
  142. hr = NtTypeCopy(pNtSrcObjects + i, pNtDestObjects + i);
  143. BAIL_ON_FAILURE(hr);
  144. }
  145. *ppNtDestObjects = pNtDestObjects;
  146. RRETURN(S_OK);
  147. error:
  148. //
  149. // pNtDestObjects is assumed to be non-NULL
  150. //
  151. NTTypeFreeNTObjects(pNtDestObjects, dwNumObjects);
  152. RRETURN(hr);
  153. }
  154. HRESULT
  155. CopyNulledString(
  156. LPTSTR pszSrcString,
  157. LPTSTR *ppszDestString
  158. )
  159. {
  160. HRESULT hr = S_OK;
  161. LPTSTR pszPosition = pszSrcString;
  162. DWORD dwLength = 0 ;
  163. DWORD dwCurrLen = 0;
  164. BOOL foundNULL = FALSE;
  165. DWORD i;
  166. ADsAssert(ppszDestString);
  167. *ppszDestString = NULL;
  168. if (!pszSrcString)
  169. RRETURN(S_OK);
  170. //
  171. // scan source string looking for 2 successive NULLS
  172. //
  173. if(*pszPosition == TEXT('\0')) {
  174. pszPosition++;
  175. dwLength++;
  176. }
  177. while(*pszPosition != TEXT('\0')){
  178. dwCurrLen = wcslen(pszPosition) +1;
  179. dwLength += dwCurrLen;
  180. pszPosition += dwCurrLen;
  181. }
  182. dwLength++;
  183. *ppszDestString = (LPTSTR)AllocADsMem (dwLength * sizeof(TCHAR));
  184. if ( !*ppszDestString){
  185. RRETURN(E_OUTOFMEMORY);
  186. }
  187. // copy one character at a time
  188. for ( i=0; i<dwLength; i++){
  189. (*ppszDestString)[i] = pszSrcString[i] ;
  190. }
  191. RRETURN (hr);
  192. }