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.

419 lines
7.8 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. HRESULT
  179. CopyDelimitedStringToNTOBJECT(
  180. LPTSTR pszSrcValue,
  181. PNTOBJECT lpNtObject
  182. )
  183. {
  184. if(!pszSrcValue){
  185. RRETURN(E_POINTER);
  186. }
  187. if(!lpNtObject){
  188. RRETURN(E_POINTER);
  189. }
  190. lpNtObject->NTType = NT_SYNTAX_ID_DelimitedString;
  191. (lpNtObject->NTValue). pszValue = AllocADsStr(pszSrcValue);
  192. if (!((lpNtObject->NTValue). pszValue)){
  193. RRETURN(E_OUTOFMEMORY);
  194. }
  195. RRETURN(S_OK);
  196. }
  197. HRESULT
  198. CopyNulledStringToNTOBJECT(
  199. LPTSTR pszSrcValue,
  200. PNTOBJECT lpNtObject
  201. )
  202. {
  203. HRESULT hr = S_OK;
  204. if(!pszSrcValue){
  205. RRETURN(E_POINTER);
  206. }
  207. if(!lpNtObject){
  208. RRETURN(E_POINTER);
  209. }
  210. lpNtObject->NTType = NT_SYNTAX_ID_NulledString;
  211. hr = CopyNulledString (pszSrcValue,
  212. &((lpNtObject->NTValue). pszValue) );
  213. if (FAILED(hr)){
  214. RRETURN(hr);
  215. }
  216. RRETURN(S_OK);
  217. }
  218. HRESULT
  219. CopyNTToNTSynId(
  220. DWORD dwSyntaxId,
  221. LPBYTE lpByte,
  222. PNTOBJECT lpNTObject
  223. )
  224. {
  225. HRESULT hr = S_OK;
  226. switch (dwSyntaxId) {
  227. case NT_SYNTAX_ID_BOOL:
  228. hr = CopyBOOLToNTOBJECT(
  229. (PBOOL)lpByte,
  230. lpNTObject
  231. );
  232. break;
  233. case NT_SYNTAX_ID_SYSTEMTIME:
  234. hr = CopySYSTEMTIMEToNTOBJECT(
  235. (PSYSTEMTIME)lpByte,
  236. lpNTObject
  237. );
  238. break;
  239. case NT_SYNTAX_ID_DWORD:
  240. hr = CopyDWORDToNTOBJECT(
  241. (PDWORD)lpByte,
  242. lpNTObject
  243. );
  244. break;
  245. case NT_SYNTAX_ID_DATE:
  246. hr = CopyDATEToNTOBJECT(
  247. (PDWORD)lpByte,
  248. lpNTObject
  249. );
  250. break;
  251. case NT_SYNTAX_ID_NW312DATE:
  252. hr = CopyNw312DATEToNTOBJECT(
  253. lpByte,
  254. lpNTObject
  255. );
  256. break;
  257. case NT_SYNTAX_ID_DelimitedString:
  258. hr = CopyDelimitedStringToNTOBJECT(
  259. (LPTSTR)lpByte,
  260. lpNTObject
  261. );
  262. break;
  263. case NT_SYNTAX_ID_NulledString:
  264. hr = CopyNulledStringToNTOBJECT(
  265. (LPTSTR)lpByte,
  266. lpNTObject
  267. );
  268. break;
  269. case NT_SYNTAX_ID_LPTSTR:
  270. hr = CopyLPTSTRToNTOBJECT(
  271. (LPTSTR)lpByte,
  272. lpNTObject
  273. );
  274. break;
  275. case NT_SYNTAX_ID_OCTETSTRING:
  276. hr = CopyOctetToNTOBJECT(
  277. lpByte,
  278. lpNTObject
  279. );
  280. break;
  281. default:
  282. break;
  283. }
  284. RRETURN(hr);
  285. }
  286. //
  287. // NT is always single-valued!!
  288. //
  289. HRESULT
  290. UnMarshallNTToNTSynId(
  291. DWORD dwSyntaxId,
  292. DWORD dwNumValues,
  293. LPBYTE lpValue,
  294. PNTOBJECT * ppNTObject
  295. )
  296. {
  297. LPBYTE lpByte = lpValue;
  298. DWORD i = 0;
  299. PNTOBJECT pNTObject = NULL;
  300. HRESULT hr = S_OK;
  301. pNTObject = (PNTOBJECT)AllocADsMem(
  302. sizeof(NTOBJECT)
  303. );
  304. if (!pNTObject) {
  305. RRETURN(E_FAIL);
  306. }
  307. hr = CopyNTToNTSynId(
  308. dwSyntaxId,
  309. lpByte,
  310. pNTObject
  311. );
  312. BAIL_ON_FAILURE(hr);
  313. *ppNTObject = pNTObject;
  314. RRETURN(hr);
  315. error:
  316. if (pNTObject) {
  317. FreeADsMem(pNTObject);
  318. }
  319. RRETURN(hr);
  320. }