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.

426 lines
8.0 KiB

  1. //-------------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1995.
  5. //
  6. // File: ntmrshl.cxx
  7. //
  8. // Contents:
  9. //
  10. // Functions:
  11. //
  12. // History: 17-June-1996 RamV Created.
  13. //
  14. //----------------------------------------------------------------------------
  15. #include "winnt.hxx"
  16. #pragma hdrstop
  17. #define INITGUID
  18. HRESULT
  19. CopyNTOBJECTToOctet(
  20. PNTOBJECT pNtSrcObject,
  21. OctetString *pOctet
  22. )
  23. {
  24. if(!pNtSrcObject){
  25. RRETURN(E_POINTER);
  26. }
  27. if(!(pNtSrcObject->NTType == NT_SYNTAX_ID_OCTETSTRING)){
  28. RRETURN(E_ADS_CANT_CONVERT_DATATYPE);
  29. }
  30. pOctet->dwSize = (pNtSrcObject->NTValue).octetstring.dwSize;
  31. pOctet->pByte = (BYTE*)AllocADsMem(sizeof(BYTE) * (pNtSrcObject->NTValue).octetstring.dwSize);
  32. if (!pOctet->pByte) {
  33. RRETURN(E_OUTOFMEMORY);
  34. }
  35. memcpy(pOctet->pByte,
  36. (pNtSrcObject->NTValue).octetstring.pByte,
  37. (pNtSrcObject->NTValue).octetstring.dwSize);
  38. RRETURN(S_OK);
  39. }
  40. HRESULT
  41. CopyNTOBJECTToDWORD(
  42. PNTOBJECT pNtSrcObject,
  43. PDWORD pdwRetval
  44. )
  45. {
  46. if(!pNtSrcObject){
  47. RRETURN(E_POINTER);
  48. }
  49. if(!(pNtSrcObject->NTType == NT_SYNTAX_ID_DWORD)){
  50. RRETURN(E_ADS_CANT_CONVERT_DATATYPE);
  51. }
  52. *pdwRetval = (pNtSrcObject->NTValue).dwValue;
  53. RRETURN(S_OK);
  54. }
  55. HRESULT
  56. CopyNTOBJECTToDATE(
  57. PNTOBJECT pNtSrcObject,
  58. PDWORD pdwRetval
  59. )
  60. {
  61. if(!pNtSrcObject){
  62. RRETURN(E_POINTER);
  63. }
  64. if(!(pNtSrcObject->NTType == NT_SYNTAX_ID_DATE)){
  65. RRETURN(E_ADS_CANT_CONVERT_DATATYPE);
  66. }
  67. *pdwRetval = (pNtSrcObject->NTValue).dwValue;
  68. RRETURN(S_OK);
  69. }
  70. HRESULT
  71. CopyNTOBJECTToDATE70(
  72. PNTOBJECT pNtSrcObject,
  73. PDWORD pdwRetval
  74. )
  75. {
  76. if(!pNtSrcObject){
  77. RRETURN(E_POINTER);
  78. }
  79. if(!(pNtSrcObject->NTType == NT_SYNTAX_ID_DATE_1970)){
  80. RRETURN(E_ADS_CANT_CONVERT_DATATYPE);
  81. }
  82. *pdwRetval = (pNtSrcObject->NTValue).dwSeconds1970;
  83. RRETURN(S_OK);
  84. }
  85. HRESULT
  86. CopyNTOBJECTToBOOL(
  87. PNTOBJECT pNtSrcObject,
  88. PBOOL pfRetval
  89. )
  90. {
  91. if(!pNtSrcObject){
  92. RRETURN(E_POINTER);
  93. }
  94. if(!(pNtSrcObject->NTType == NT_SYNTAX_ID_BOOL)){
  95. RRETURN(E_ADS_CANT_CONVERT_DATATYPE);
  96. }
  97. *pfRetval = (pNtSrcObject->NTValue).fValue;
  98. RRETURN(S_OK);
  99. }
  100. HRESULT
  101. CopyNTOBJECTToSYSTEMTIME(
  102. PNTOBJECT pNtSrcObject,
  103. SYSTEMTIME *pstRetVal
  104. )
  105. {
  106. if(!pNtSrcObject){
  107. RRETURN(E_POINTER);
  108. }
  109. if(!(pNtSrcObject->NTType == NT_SYNTAX_ID_SYSTEMTIME)){
  110. RRETURN(E_ADS_CANT_CONVERT_DATATYPE);
  111. }
  112. *pstRetVal = (pNtSrcObject->NTValue).stSystemTimeValue;
  113. RRETURN(S_OK);
  114. }
  115. HRESULT
  116. CopyNTOBJECTToLPTSTR(
  117. PNTOBJECT pNtSrcObject,
  118. LPTSTR *ppszRetval
  119. )
  120. {
  121. if(!pNtSrcObject){
  122. RRETURN(E_POINTER);
  123. }
  124. if(!(pNtSrcObject->NTType == NT_SYNTAX_ID_LPTSTR)){
  125. RRETURN(E_ADS_CANT_CONVERT_DATATYPE);
  126. }
  127. *ppszRetval = AllocADsStr((pNtSrcObject->NTValue).pszValue);
  128. if (! *ppszRetval && ((pNtSrcObject->NTValue).pszValue)){
  129. RRETURN(E_OUTOFMEMORY);
  130. }
  131. RRETURN(S_OK);
  132. }
  133. HRESULT
  134. CopyNTOBJECTToDelimitedString(
  135. PNTOBJECT pNtSrcObject,
  136. DWORD dwNumValues,
  137. LPTSTR *ppszRetval
  138. )
  139. {
  140. DWORD i= 0;
  141. HRESULT hr = S_OK;
  142. WCHAR szDelimStr[MAX_PATH];
  143. LPWSTR Delimiter = TEXT(",");
  144. if (!dwNumValues){
  145. *ppszRetval = NULL;
  146. RRETURN(S_OK);
  147. }
  148. wcscpy(szDelimStr, TEXT("")); // empty contents
  149. if(!pNtSrcObject){
  150. hr = E_POINTER;
  151. goto error;
  152. }
  153. if(!(pNtSrcObject->NTType == NT_SYNTAX_ID_DelimitedString)){
  154. hr = E_ADS_CANT_CONVERT_DATATYPE;
  155. goto error;
  156. }
  157. for(i=0; i<dwNumValues; i++){
  158. if(i>0){
  159. wcscat(szDelimStr, Delimiter);
  160. }
  161. wcscat(szDelimStr, pNtSrcObject[i].NTValue.pszValue);
  162. }
  163. *ppszRetval = AllocADsStr(szDelimStr);
  164. if(*ppszRetval == NULL){
  165. hr = E_OUTOFMEMORY;
  166. goto error;
  167. }
  168. error:
  169. RRETURN(hr);
  170. }
  171. HRESULT
  172. CopyNTOBJECTToNulledString(
  173. PNTOBJECT pNtSrcObject,
  174. DWORD dwNumValues,
  175. LPTSTR *ppszRetval
  176. )
  177. {
  178. DWORD i= 0;
  179. HRESULT hr = S_OK;
  180. LPWSTR pszNullStr = 0;
  181. WORD wStrLen = 0;
  182. if (!dwNumValues){
  183. *ppszRetval = NULL;
  184. RRETURN(S_OK);
  185. }
  186. pszNullStr = (LPWSTR)AllocADsMem(MAX_PATH); //max length of nulled string
  187. if(!pszNullStr){
  188. hr = E_OUTOFMEMORY;
  189. goto error;
  190. }
  191. wcscpy(pszNullStr, TEXT("")); // empty contents
  192. if(!pNtSrcObject){
  193. hr = E_POINTER;
  194. goto error;
  195. }
  196. if(!(pNtSrcObject->NTType == NT_SYNTAX_ID_NulledString)){
  197. hr = E_ADS_CANT_CONVERT_DATATYPE;
  198. goto error;
  199. }
  200. for(i=0; i<dwNumValues; i++){
  201. wcscpy(pszNullStr+wStrLen, pNtSrcObject[i].NTValue.pszValue);
  202. wStrLen += wcslen(pszNullStr+wStrLen) + 1;
  203. }
  204. wcscpy(pszNullStr + wStrLen, TEXT(""));
  205. *ppszRetval = pszNullStr;
  206. error:
  207. RRETURN(hr);
  208. }
  209. /* Delete after new implementation works fully
  210. HRESULT
  211. CopyNTOBJECTToNulledString(
  212. PNTOBJECT pNtSrcObject,
  213. LPTSTR *ppszRetval
  214. )
  215. {
  216. HRESULT hr = S_OK;
  217. if(!pNtSrcObject){
  218. RRETURN(E_POINTER);
  219. }
  220. if(!(pNtSrcObject->NTType == NT_SYNTAX_ID_NulledString)){
  221. RRETURN(E_ADS_CANT_CONVERT_DATATYPE);
  222. }
  223. hr = CopyNulledString((pNtSrcObject->NTValue).pszValue,
  224. ppszRetval );
  225. if ( FAILED (hr)){
  226. RRETURN(hr);
  227. }
  228. RRETURN(S_OK);
  229. }
  230. */
  231. HRESULT
  232. CopyNTOBJECTToNT(
  233. DWORD dwSyntaxId,
  234. PNTOBJECT lpNTObject,
  235. LPBYTE lpByte
  236. )
  237. {
  238. HRESULT hr = S_OK;
  239. switch (dwSyntaxId) {
  240. case NT_SYNTAX_ID_BOOL:
  241. hr = CopyNTOBJECTToBOOL(
  242. lpNTObject,
  243. (PBOOL)lpByte
  244. );
  245. break;
  246. case NT_SYNTAX_ID_SYSTEMTIME:
  247. hr = CopyNTOBJECTToSYSTEMTIME(
  248. lpNTObject,
  249. (PSYSTEMTIME)lpByte
  250. );
  251. break;
  252. case NT_SYNTAX_ID_DWORD:
  253. hr = CopyNTOBJECTToDWORD(
  254. lpNTObject,
  255. (PDWORD)lpByte
  256. );
  257. break;
  258. case NT_SYNTAX_ID_DATE:
  259. hr = CopyNTOBJECTToDATE(
  260. lpNTObject,
  261. (PDWORD)lpByte
  262. );
  263. break;
  264. case NT_SYNTAX_ID_DATE_1970:
  265. hr = CopyNTOBJECTToDATE70(
  266. lpNTObject,
  267. (PDWORD)lpByte
  268. );
  269. break;
  270. case NT_SYNTAX_ID_LPTSTR:
  271. hr = CopyNTOBJECTToLPTSTR(
  272. lpNTObject,
  273. (LPTSTR *)lpByte
  274. );
  275. break;
  276. case NT_SYNTAX_ID_OCTETSTRING:
  277. hr = CopyNTOBJECTToOctet(
  278. lpNTObject,
  279. (OctetString *)lpByte
  280. );
  281. break;
  282. default:
  283. break;
  284. }
  285. RRETURN(hr);
  286. }
  287. HRESULT
  288. MarshallNTSynIdToNT(
  289. DWORD dwSyntaxId,
  290. PNTOBJECT pNTObject,
  291. DWORD dwNumValues,
  292. LPBYTE lpValue
  293. )
  294. {
  295. HRESULT hr = S_OK;
  296. DWORD i = 0;
  297. //
  298. // Loop below does not really handle case other than 1 value
  299. //
  300. //
  301. // For handling multivalued cases, the loop is unnecessary
  302. //
  303. if(dwSyntaxId == NT_SYNTAX_ID_DelimitedString) {
  304. hr = CopyNTOBJECTToDelimitedString (
  305. pNTObject,
  306. dwNumValues,
  307. (LPWSTR *)lpValue
  308. );
  309. } else if (dwSyntaxId == NT_SYNTAX_ID_NulledString) {
  310. hr = CopyNTOBJECTToNulledString(
  311. pNTObject,
  312. dwNumValues,
  313. (LPWSTR *) lpValue
  314. );
  315. } else {
  316. for (i = 0; i < dwNumValues; i++) {
  317. hr = CopyNTOBJECTToNT(
  318. dwSyntaxId,
  319. (pNTObject + i) ,
  320. lpValue
  321. );
  322. }
  323. }
  324. RRETURN(hr);
  325. }