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.

340 lines
6.5 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1996.
  5. //
  6. // File: nwmrshl.cxx
  7. //
  8. // Contents:
  9. //
  10. // Functions:
  11. //
  12. // History: 23-June-1996 KrishnaG Created.
  13. //
  14. //----------------------------------------------------------------------------
  15. #include "nwcompat.hxx"
  16. #pragma hdrstop
  17. HRESULT
  18. CopyNTOBJECTToDWORD(
  19. PNTOBJECT pNtSrcObject,
  20. PDWORD pdwRetval
  21. )
  22. {
  23. if(!pNtSrcObject){
  24. RRETURN(E_POINTER);
  25. }
  26. if(!(pNtSrcObject->NTType == NT_SYNTAX_ID_DWORD)){
  27. RRETURN(E_ADS_CANT_CONVERT_DATATYPE);
  28. }
  29. *pdwRetval = (pNtSrcObject->NTValue).dwValue;
  30. RRETURN(S_OK);
  31. }
  32. HRESULT
  33. CopyNTOBJECTToDATE(
  34. PNTOBJECT pNtSrcObject,
  35. PDWORD pdwRetval
  36. )
  37. {
  38. if(!pNtSrcObject){
  39. RRETURN(E_POINTER);
  40. }
  41. if(!(pNtSrcObject->NTType == NT_SYNTAX_ID_DATE)){
  42. RRETURN(E_ADS_CANT_CONVERT_DATATYPE);
  43. }
  44. *pdwRetval = (pNtSrcObject->NTValue).dwValue;
  45. RRETURN(S_OK);
  46. }
  47. HRESULT
  48. CopyNTOBJECTToNw312DATE(
  49. PNTOBJECT pNtSrcObject,
  50. PBYTE pbyRetval
  51. )
  52. {
  53. if(!pNtSrcObject){
  54. RRETURN(E_POINTER);
  55. }
  56. if(!(pNtSrcObject->NTType == NT_SYNTAX_ID_NW312DATE)){
  57. RRETURN(E_ADS_CANT_CONVERT_DATATYPE);
  58. }
  59. memcpy(pbyRetval,(pNtSrcObject->NTValue).Nw312Date, 6);
  60. RRETURN(S_OK);
  61. }
  62. HRESULT
  63. CopyNTOBJECTToBOOL(
  64. PNTOBJECT pNtSrcObject,
  65. PBOOL pfRetval
  66. )
  67. {
  68. if(!pNtSrcObject){
  69. RRETURN(E_POINTER);
  70. }
  71. if(!(pNtSrcObject->NTType == NT_SYNTAX_ID_BOOL)){
  72. RRETURN(E_ADS_CANT_CONVERT_DATATYPE);
  73. }
  74. *pfRetval = (pNtSrcObject->NTValue).fValue;
  75. RRETURN(S_OK);
  76. }
  77. HRESULT
  78. CopyNTOBJECTToSYSTEMTIME(
  79. PNTOBJECT pNtSrcObject,
  80. SYSTEMTIME *pstRetVal
  81. )
  82. {
  83. if(!pNtSrcObject){
  84. RRETURN(E_POINTER);
  85. }
  86. if(!(pNtSrcObject->NTType == NT_SYNTAX_ID_SYSTEMTIME)){
  87. RRETURN(E_ADS_CANT_CONVERT_DATATYPE);
  88. }
  89. *pstRetVal = (pNtSrcObject->NTValue).stSystemTimeValue;
  90. RRETURN(S_OK);
  91. }
  92. HRESULT
  93. CopyNTOBJECTToLPTSTR(
  94. PNTOBJECT pNtSrcObject,
  95. LPTSTR *ppszRetval
  96. )
  97. {
  98. if(!pNtSrcObject){
  99. RRETURN(E_POINTER);
  100. }
  101. if(!(pNtSrcObject->NTType == NT_SYNTAX_ID_LPTSTR)){
  102. RRETURN(E_ADS_CANT_CONVERT_DATATYPE);
  103. }
  104. *ppszRetval = AllocADsStr((pNtSrcObject->NTValue).pszValue);
  105. if (! *ppszRetval && ((pNtSrcObject->NTValue).pszValue)) {
  106. RRETURN(E_OUTOFMEMORY);
  107. }
  108. RRETURN(S_OK);
  109. }
  110. HRESULT
  111. CopyNTOBJECTToOctet(
  112. PNTOBJECT pNtSrcObject,
  113. OctetString *pOctet
  114. )
  115. {
  116. if(!pNtSrcObject){
  117. RRETURN(E_POINTER);
  118. }
  119. if(!(pNtSrcObject->NTType == NT_SYNTAX_ID_OCTETSTRING)){
  120. RRETURN(E_ADS_CANT_CONVERT_DATATYPE);
  121. }
  122. pOctet->dwSize = (pNtSrcObject->NTValue).octetstring.dwSize;
  123. pOctet->pByte = (BYTE*)AllocADsMem(sizeof(BYTE) * (pNtSrcObject->NTValue).octetstring.dwSize);
  124. if (!pOctet->pByte) {
  125. RRETURN(E_OUTOFMEMORY);
  126. }
  127. memcpy(pOctet->pByte,
  128. (pNtSrcObject->NTValue).octetstring.pByte,
  129. (pNtSrcObject->NTValue).octetstring.dwSize);
  130. RRETURN(S_OK);
  131. }
  132. HRESULT
  133. CopyNTOBJECTToDelimitedString(
  134. PNTOBJECT pNtSrcObject,
  135. LPTSTR *ppszRetval
  136. )
  137. {
  138. if(!pNtSrcObject){
  139. RRETURN(E_POINTER);
  140. }
  141. if(!(pNtSrcObject->NTType == NT_SYNTAX_ID_DelimitedString)){
  142. RRETURN(E_ADS_CANT_CONVERT_DATATYPE);
  143. }
  144. if ((pNtSrcObject->NTValue).pszValue == NULL){
  145. *ppszRetval = NULL;
  146. } else {
  147. *ppszRetval = AllocADsStr((pNtSrcObject->NTValue).pszValue);
  148. }
  149. if (! *ppszRetval && ((pNtSrcObject->NTValue).pszValue)) {
  150. RRETURN(E_OUTOFMEMORY);
  151. }
  152. RRETURN(S_OK);
  153. }
  154. HRESULT
  155. CopyNTOBJECTToNulledString(
  156. PNTOBJECT pNtSrcObject,
  157. LPTSTR *ppszRetval
  158. )
  159. {
  160. HRESULT hr = S_OK;
  161. if(!pNtSrcObject){
  162. RRETURN(E_POINTER);
  163. }
  164. if(!(pNtSrcObject->NTType == NT_SYNTAX_ID_NulledString)){
  165. RRETURN(E_ADS_CANT_CONVERT_DATATYPE);
  166. }
  167. hr = CopyNulledString((pNtSrcObject->NTValue).pszValue,
  168. ppszRetval );
  169. if ( FAILED (hr)){
  170. RRETURN(hr);
  171. }
  172. RRETURN(S_OK);
  173. }
  174. HRESULT
  175. CopyNTOBJECTToNT(
  176. DWORD dwSyntaxId,
  177. PNTOBJECT lpNTObject,
  178. LPBYTE lpByte
  179. )
  180. {
  181. HRESULT hr = S_OK;
  182. switch (dwSyntaxId) {
  183. case NT_SYNTAX_ID_BOOL:
  184. hr = CopyNTOBJECTToBOOL(
  185. lpNTObject,
  186. (PBOOL)lpByte
  187. );
  188. break;
  189. case NT_SYNTAX_ID_SYSTEMTIME:
  190. hr = CopyNTOBJECTToSYSTEMTIME(
  191. lpNTObject,
  192. (PSYSTEMTIME)lpByte
  193. );
  194. break;
  195. case NT_SYNTAX_ID_DWORD:
  196. hr = CopyNTOBJECTToDWORD(
  197. lpNTObject,
  198. (PDWORD)lpByte
  199. );
  200. break;
  201. case NT_SYNTAX_ID_DATE:
  202. hr = CopyNTOBJECTToDATE(
  203. lpNTObject,
  204. (PDWORD)lpByte
  205. );
  206. break;
  207. case NT_SYNTAX_ID_NW312DATE:
  208. hr = CopyNTOBJECTToNw312DATE(
  209. lpNTObject,
  210. (LPBYTE)lpByte
  211. );
  212. break;
  213. case NT_SYNTAX_ID_DelimitedString:
  214. hr = CopyNTOBJECTToDelimitedString(
  215. lpNTObject,
  216. (LPTSTR *)lpByte
  217. );
  218. break;
  219. case NT_SYNTAX_ID_NulledString:
  220. hr = CopyNTOBJECTToNulledString(
  221. lpNTObject,
  222. (LPTSTR *)lpByte
  223. );
  224. break;
  225. case NT_SYNTAX_ID_LPTSTR:
  226. hr = CopyNTOBJECTToLPTSTR(
  227. lpNTObject,
  228. (LPTSTR *)lpByte
  229. );
  230. break;
  231. case NT_SYNTAX_ID_OCTETSTRING:
  232. hr = CopyNTOBJECTToOctet(
  233. lpNTObject,
  234. (OctetString *)lpByte
  235. );
  236. break;
  237. default:
  238. hr = E_FAIL;
  239. break;
  240. }
  241. RRETURN(hr);
  242. }
  243. HRESULT
  244. MarshallNTSynIdToNT(
  245. DWORD dwSyntaxId,
  246. PNTOBJECT pNTObject,
  247. DWORD dwNumValues,
  248. LPBYTE lpValue
  249. )
  250. {
  251. HRESULT hr = S_OK;
  252. DWORD i = 0;
  253. //
  254. // Loop below does not really handle case other than 1 value
  255. //
  256. for (i = 0; i < dwNumValues; i++) {
  257. hr = CopyNTOBJECTToNT(
  258. dwSyntaxId,
  259. (pNTObject + i) ,
  260. lpValue
  261. );
  262. }
  263. RRETURN(hr);
  264. }