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.

424 lines
7.5 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1995.
  5. //
  6. // File: nwumrshl.cxx
  7. //
  8. // Contents:
  9. //
  10. // Functions:
  11. //
  12. //
  13. // History: 17-June-1996 KrishnaG Cloned off NDS.
  14. //
  15. //
  16. // Notes :
  17. //
  18. //
  19. //----------------------------------------------------------------------------
  20. #include "nwcompat.hxx"
  21. #pragma hdrstop
  22. HRESULT
  23. NTTypeInit(
  24. PNTOBJECT pNtType
  25. )
  26. {
  27. memset(pNtType, 0, sizeof(NTOBJECT));
  28. RRETURN(S_OK);
  29. }
  30. HRESULT
  31. NTTypeClear(
  32. PNTOBJECT pNtObject
  33. )
  34. {
  35. if(!pNtObject)
  36. RRETURN(S_OK);
  37. switch (pNtObject->NTType) {
  38. case NT_SYNTAX_ID_LPTSTR:
  39. case NT_SYNTAX_ID_DelimitedString:
  40. FreeADsStr((pNtObject->NTValue).pszValue);
  41. break;
  42. case NT_SYNTAX_ID_NulledString:
  43. FreeADsMem((pNtObject->NTValue).pszValue);
  44. break;
  45. case NT_SYNTAX_ID_OCTETSTRING:
  46. FreeADsMem((pNtObject->NTValue).octetstring.pByte);
  47. break;
  48. default:
  49. break;
  50. }
  51. RRETURN(S_OK);
  52. }
  53. void
  54. NTTypeFreeNTObjects(
  55. PNTOBJECT pNtObject,
  56. DWORD dwNumValues
  57. )
  58. {
  59. DWORD i = 0;
  60. for (i = 0; i < dwNumValues; i++ ) {
  61. NTTypeClear(pNtObject + i);
  62. }
  63. FreeADsMem(pNtObject);
  64. return;
  65. }
  66. HRESULT
  67. CopyDWORDToNTOBJECT(
  68. PDWORD pdwSrcValue,
  69. PNTOBJECT lpNtDestValue
  70. )
  71. {
  72. HRESULT hr = S_OK;
  73. if(!lpNtDestValue){
  74. RRETURN(E_POINTER);
  75. }
  76. lpNtDestValue->NTType = NT_SYNTAX_ID_DWORD;
  77. (lpNtDestValue->NTValue).dwValue = *pdwSrcValue;
  78. RRETURN(hr);
  79. }
  80. HRESULT
  81. CopyDATEToNTOBJECT(
  82. PDWORD pdwSrcValue,
  83. PNTOBJECT lpNtDestValue
  84. )
  85. {
  86. HRESULT hr = S_OK;
  87. if(!lpNtDestValue){
  88. RRETURN(E_POINTER);
  89. }
  90. lpNtDestValue->NTType = NT_SYNTAX_ID_DATE;
  91. (lpNtDestValue->NTValue).dwValue = *pdwSrcValue;
  92. RRETURN(hr);
  93. }
  94. HRESULT
  95. CopyNw312DATEToNTOBJECT(
  96. PBYTE pbyDateTime,
  97. PNTOBJECT lpNtDestValue
  98. )
  99. {
  100. HRESULT hr = S_OK;
  101. if(!lpNtDestValue){
  102. RRETURN(E_POINTER);
  103. }
  104. lpNtDestValue->NTType = NT_SYNTAX_ID_NW312DATE;
  105. memcpy((lpNtDestValue->NTValue).Nw312Date, pbyDateTime, 6);
  106. RRETURN(hr);
  107. }
  108. HRESULT
  109. CopyBOOLToNTOBJECT(
  110. PBOOL pfSrcValue,
  111. PNTOBJECT lpNtObject
  112. )
  113. {
  114. if(!lpNtObject){
  115. RRETURN(E_POINTER);
  116. }
  117. lpNtObject->NTType = NT_SYNTAX_ID_BOOL;
  118. (lpNtObject->NTValue).fValue = *pfSrcValue;
  119. RRETURN(S_OK);
  120. }
  121. HRESULT
  122. CopySYSTEMTIMEToNTOBJECT(
  123. PSYSTEMTIME pSysTime,
  124. PNTOBJECT lpNtObject
  125. )
  126. {
  127. if(!lpNtObject){
  128. RRETURN(E_POINTER);
  129. }
  130. (lpNtObject->NTValue).stSystemTimeValue = *pSysTime;
  131. lpNtObject->NTType = NT_SYNTAX_ID_SYSTEMTIME;
  132. RRETURN(S_OK);
  133. }
  134. HRESULT
  135. CopyLPTSTRToNTOBJECT(
  136. LPTSTR pszSrcValue,
  137. PNTOBJECT lpNtObject
  138. )
  139. {
  140. if(!lpNtObject){
  141. RRETURN(E_POINTER);
  142. }
  143. lpNtObject->NTType = NT_SYNTAX_ID_LPTSTR;
  144. if(!pszSrcValue){
  145. (lpNtObject->NTValue). pszValue = NULL;
  146. } else {
  147. (lpNtObject->NTValue). pszValue = AllocADsStr(pszSrcValue);
  148. if (!((lpNtObject->NTValue). pszValue)){
  149. RRETURN(E_OUTOFMEMORY);
  150. }
  151. }
  152. RRETURN(S_OK);
  153. }
  154. HRESULT
  155. CopyOctetToNTOBJECT(
  156. PBYTE pOctetString,
  157. PNTOBJECT lpNtObject
  158. )
  159. {
  160. if(!lpNtObject){
  161. RRETURN(E_POINTER);
  162. }
  163. lpNtObject->NTType = NT_SYNTAX_ID_OCTETSTRING;
  164. if(!pOctetString){
  165. (lpNtObject->NTValue).octetstring.dwSize = 0;
  166. (lpNtObject->NTValue).octetstring.pByte = NULL;
  167. } else {
  168. OctetString *pOctString = (OctetString*)pOctetString;
  169. (lpNtObject->NTValue).octetstring.dwSize = pOctString->dwSize;
  170. (lpNtObject->NTValue).octetstring.pByte = (BYTE*)AllocADsMem(sizeof(BYTE)*pOctString->dwSize);
  171. if (!(lpNtObject->NTValue).octetstring.pByte) {
  172. RRETURN(E_OUTOFMEMORY);
  173. }
  174. memcpy((lpNtObject->NTValue).octetstring.pByte, pOctString->pByte,pOctString->dwSize);
  175. }
  176. RRETURN(S_OK);
  177. }
  178. //
  179. // BUGBUG Need to add conversion routines for Nulled and Delimited Strings
  180. //
  181. HRESULT
  182. CopyDelimitedStringToNTOBJECT(
  183. LPTSTR pszSrcValue,
  184. PNTOBJECT lpNtObject
  185. )
  186. {
  187. if(!pszSrcValue){
  188. RRETURN(E_POINTER);
  189. }
  190. if(!lpNtObject){
  191. RRETURN(E_POINTER);
  192. }
  193. lpNtObject->NTType = NT_SYNTAX_ID_DelimitedString;
  194. (lpNtObject->NTValue). pszValue = AllocADsStr(pszSrcValue);
  195. if (!((lpNtObject->NTValue). pszValue)){
  196. RRETURN(E_OUTOFMEMORY);
  197. }
  198. RRETURN(S_OK);
  199. }
  200. // BugBug the following is somewhat buggy
  201. HRESULT
  202. CopyNulledStringToNTOBJECT(
  203. LPTSTR pszSrcValue,
  204. PNTOBJECT lpNtObject
  205. )
  206. {
  207. HRESULT hr = S_OK;
  208. if(!pszSrcValue){
  209. RRETURN(E_POINTER);
  210. }
  211. if(!lpNtObject){
  212. RRETURN(E_POINTER);
  213. }
  214. lpNtObject->NTType = NT_SYNTAX_ID_NulledString;
  215. hr = CopyNulledString (pszSrcValue,
  216. &((lpNtObject->NTValue). pszValue) );
  217. if (FAILED(hr)){
  218. RRETURN(hr);
  219. }
  220. RRETURN(S_OK);
  221. }
  222. HRESULT
  223. CopyNTToNTSynId(
  224. DWORD dwSyntaxId,
  225. LPBYTE lpByte,
  226. PNTOBJECT lpNTObject
  227. )
  228. {
  229. HRESULT hr = S_OK;
  230. switch (dwSyntaxId) {
  231. case NT_SYNTAX_ID_BOOL:
  232. hr = CopyBOOLToNTOBJECT(
  233. (PBOOL)lpByte,
  234. lpNTObject
  235. );
  236. break;
  237. case NT_SYNTAX_ID_SYSTEMTIME:
  238. hr = CopySYSTEMTIMEToNTOBJECT(
  239. (PSYSTEMTIME)lpByte,
  240. lpNTObject
  241. );
  242. break;
  243. case NT_SYNTAX_ID_DWORD:
  244. hr = CopyDWORDToNTOBJECT(
  245. (PDWORD)lpByte,
  246. lpNTObject
  247. );
  248. break;
  249. case NT_SYNTAX_ID_DATE:
  250. hr = CopyDATEToNTOBJECT(
  251. (PDWORD)lpByte,
  252. lpNTObject
  253. );
  254. break;
  255. case NT_SYNTAX_ID_NW312DATE:
  256. hr = CopyNw312DATEToNTOBJECT(
  257. lpByte,
  258. lpNTObject
  259. );
  260. break;
  261. case NT_SYNTAX_ID_DelimitedString:
  262. hr = CopyDelimitedStringToNTOBJECT(
  263. (LPTSTR)lpByte,
  264. lpNTObject
  265. );
  266. break;
  267. case NT_SYNTAX_ID_NulledString:
  268. hr = CopyNulledStringToNTOBJECT(
  269. (LPTSTR)lpByte,
  270. lpNTObject
  271. );
  272. break;
  273. case NT_SYNTAX_ID_LPTSTR:
  274. hr = CopyLPTSTRToNTOBJECT(
  275. (LPTSTR)lpByte,
  276. lpNTObject
  277. );
  278. break;
  279. case NT_SYNTAX_ID_OCTETSTRING:
  280. hr = CopyOctetToNTOBJECT(
  281. lpByte,
  282. lpNTObject
  283. );
  284. break;
  285. default:
  286. break;
  287. }
  288. RRETURN(hr);
  289. }
  290. //
  291. // NT is always single-valued!!
  292. //
  293. HRESULT
  294. UnMarshallNTToNTSynId(
  295. DWORD dwSyntaxId,
  296. DWORD dwNumValues,
  297. LPBYTE lpValue,
  298. PNTOBJECT * ppNTObject
  299. )
  300. {
  301. LPBYTE lpByte = lpValue;
  302. DWORD i = 0;
  303. PNTOBJECT pNTObject = NULL;
  304. HRESULT hr = S_OK;
  305. pNTObject = (PNTOBJECT)AllocADsMem(
  306. sizeof(NTOBJECT)
  307. );
  308. if (!pNTObject) {
  309. RRETURN(E_FAIL);
  310. }
  311. hr = CopyNTToNTSynId(
  312. dwSyntaxId,
  313. lpByte,
  314. pNTObject
  315. );
  316. BAIL_ON_FAILURE(hr);
  317. *ppNTObject = pNTObject;
  318. RRETURN(hr);
  319. error:
  320. if (pNTObject) {
  321. FreeADsMem(pNTObject);
  322. }
  323. RRETURN(hr);
  324. }