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.

451 lines
9.1 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. DWORD dwLength = 0;
  144. LPWSTR Delimiter = TEXT(",");
  145. if (!dwNumValues){
  146. *ppszRetval = NULL;
  147. RRETURN(S_OK);
  148. }
  149. wcscpy(szDelimStr, TEXT("")); // empty contents
  150. if(!pNtSrcObject){
  151. hr = E_POINTER;
  152. goto error;
  153. }
  154. if(!(pNtSrcObject->NTType == NT_SYNTAX_ID_DelimitedString)){
  155. hr = E_ADS_CANT_CONVERT_DATATYPE;
  156. goto error;
  157. }
  158. for(i=0; i<dwNumValues; i++){
  159. //
  160. // Make sure that the strings we are copying in fit into the buffer.
  161. //
  162. if ((dwLength += ((i==0)?0:1) + wcslen(pNtSrcObject[i].NTValue.pszValue)) < MAX_PATH)
  163. {
  164. if(i>0){
  165. wcscat(szDelimStr, Delimiter);
  166. }
  167. wcscat(szDelimStr, pNtSrcObject[i].NTValue.pszValue);
  168. }
  169. else
  170. {
  171. hr = E_ADS_BAD_PARAMETER;
  172. goto error;
  173. }
  174. }
  175. *ppszRetval = AllocADsStr(szDelimStr);
  176. if(*ppszRetval == NULL){
  177. hr = E_OUTOFMEMORY;
  178. goto error;
  179. }
  180. error:
  181. RRETURN(hr);
  182. }
  183. HRESULT
  184. CopyNTOBJECTToNulledString(
  185. PNTOBJECT pNtSrcObject,
  186. DWORD dwNumValues,
  187. LPTSTR *ppszRetval
  188. )
  189. {
  190. DWORD i= 0;
  191. HRESULT hr = S_OK;
  192. LPWSTR pszNullStr = 0;
  193. DWORD dwLength = 0;
  194. WORD wStrLen = 0;
  195. if (!dwNumValues){
  196. *ppszRetval = NULL;
  197. RRETURN(S_OK);
  198. }
  199. pszNullStr = (LPWSTR)AllocADsMem(MAX_PATH * sizeof(WCHAR)); //max length of nulled string
  200. if(!pszNullStr){
  201. hr = E_OUTOFMEMORY;
  202. goto error;
  203. }
  204. wcscpy(pszNullStr, TEXT("")); // empty contents
  205. if(!pNtSrcObject){
  206. hr = E_POINTER;
  207. goto error;
  208. }
  209. if(!(pNtSrcObject->NTType == NT_SYNTAX_ID_NulledString)){
  210. hr = E_ADS_CANT_CONVERT_DATATYPE;
  211. goto error;
  212. }
  213. for(i=0; i<dwNumValues; i++){
  214. //
  215. // Make sure the strings we are copying will fit into the buffer.
  216. //
  217. UINT uiLength = wcslen(pNtSrcObject[i].NTValue.pszValue);
  218. if ((wStrLen + uiLength) < MAX_PATH)
  219. {
  220. wcscpy(pszNullStr+wStrLen, pNtSrcObject[i].NTValue.pszValue);
  221. wStrLen += uiLength + 1;
  222. }
  223. else
  224. {
  225. hr = E_ADS_BAD_PARAMETER;
  226. goto error;
  227. }
  228. }
  229. wcscpy(pszNullStr + wStrLen, TEXT(""));
  230. *ppszRetval = pszNullStr;
  231. error:
  232. if (FAILED(hr))
  233. FreeADsMem(pszNullStr);
  234. RRETURN(hr);
  235. }
  236. /* Delete after new implementation works fully
  237. HRESULT
  238. CopyNTOBJECTToNulledString(
  239. PNTOBJECT pNtSrcObject,
  240. LPTSTR *ppszRetval
  241. )
  242. {
  243. HRESULT hr = S_OK;
  244. if(!pNtSrcObject){
  245. RRETURN(E_POINTER);
  246. }
  247. if(!(pNtSrcObject->NTType == NT_SYNTAX_ID_NulledString)){
  248. RRETURN(E_ADS_CANT_CONVERT_DATATYPE);
  249. }
  250. hr = CopyNulledString((pNtSrcObject->NTValue).pszValue,
  251. ppszRetval );
  252. if ( FAILED (hr)){
  253. RRETURN(hr);
  254. }
  255. RRETURN(S_OK);
  256. }
  257. */
  258. HRESULT
  259. CopyNTOBJECTToNT(
  260. DWORD dwSyntaxId,
  261. PNTOBJECT lpNTObject,
  262. LPBYTE lpByte
  263. )
  264. {
  265. HRESULT hr = S_OK;
  266. switch (dwSyntaxId) {
  267. case NT_SYNTAX_ID_BOOL:
  268. hr = CopyNTOBJECTToBOOL(
  269. lpNTObject,
  270. (PBOOL)lpByte
  271. );
  272. break;
  273. case NT_SYNTAX_ID_SYSTEMTIME:
  274. hr = CopyNTOBJECTToSYSTEMTIME(
  275. lpNTObject,
  276. (PSYSTEMTIME)lpByte
  277. );
  278. break;
  279. case NT_SYNTAX_ID_DWORD:
  280. hr = CopyNTOBJECTToDWORD(
  281. lpNTObject,
  282. (PDWORD)lpByte
  283. );
  284. break;
  285. case NT_SYNTAX_ID_DATE:
  286. hr = CopyNTOBJECTToDATE(
  287. lpNTObject,
  288. (PDWORD)lpByte
  289. );
  290. break;
  291. case NT_SYNTAX_ID_DATE_1970:
  292. hr = CopyNTOBJECTToDATE70(
  293. lpNTObject,
  294. (PDWORD)lpByte
  295. );
  296. break;
  297. case NT_SYNTAX_ID_LPTSTR:
  298. hr = CopyNTOBJECTToLPTSTR(
  299. lpNTObject,
  300. (LPTSTR *)lpByte
  301. );
  302. break;
  303. case NT_SYNTAX_ID_OCTETSTRING:
  304. hr = CopyNTOBJECTToOctet(
  305. lpNTObject,
  306. (OctetString *)lpByte
  307. );
  308. break;
  309. default:
  310. break;
  311. }
  312. RRETURN(hr);
  313. }
  314. HRESULT
  315. MarshallNTSynIdToNT(
  316. DWORD dwSyntaxId,
  317. PNTOBJECT pNTObject,
  318. DWORD dwNumValues,
  319. LPBYTE lpValue
  320. )
  321. {
  322. HRESULT hr = S_OK;
  323. DWORD i = 0;
  324. //
  325. // Loop below does not really handle case other than 1 value
  326. //
  327. //
  328. // For handling multivalued cases, the loop is unnecessary
  329. //
  330. if(dwSyntaxId == NT_SYNTAX_ID_DelimitedString) {
  331. hr = CopyNTOBJECTToDelimitedString (
  332. pNTObject,
  333. dwNumValues,
  334. (LPWSTR *)lpValue
  335. );
  336. } else if (dwSyntaxId == NT_SYNTAX_ID_NulledString) {
  337. hr = CopyNTOBJECTToNulledString(
  338. pNTObject,
  339. dwNumValues,
  340. (LPWSTR *) lpValue
  341. );
  342. } else {
  343. for (i = 0; i < dwNumValues; i++) {
  344. hr = CopyNTOBJECTToNT(
  345. dwSyntaxId,
  346. (pNTObject + i) ,
  347. lpValue
  348. );
  349. }
  350. }
  351. RRETURN(hr);
  352. }