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.

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