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.

678 lines
14 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1997.
  5. //
  6. // File: odsmrshl.cxx
  7. //
  8. // Contents: DSObject Copy Routines
  9. //
  10. // Functions:
  11. //
  12. // History: 25-Feb-97 yihsins Created.
  13. //
  14. //
  15. //----------------------------------------------------------------------------
  16. #include "ldapc.hxx"
  17. LPBYTE
  18. AdsTypeCopyDNString(
  19. PADSVALUE lpAdsSrcValue,
  20. PADSVALUE lpAdsDestValue,
  21. LPBYTE lpBuffer
  22. )
  23. {
  24. DWORD dwLength = 0;
  25. if(lpAdsSrcValue->dwType != ADSTYPE_DN_STRING){
  26. return(lpBuffer);
  27. }
  28. lpAdsDestValue->dwType = ADSTYPE_DN_STRING;
  29. //
  30. // The target buffer has to be WCHAR (WORD) aligned
  31. //
  32. lpBuffer = (LPBYTE) ROUND_UP_POINTER(lpBuffer, ALIGN_WORD);
  33. lpAdsDestValue->DNString = (LPWSTR)lpBuffer;
  34. wcscpy((LPWSTR)lpBuffer, lpAdsSrcValue->DNString);
  35. dwLength = (wcslen(lpAdsSrcValue->DNString) + 1)*sizeof(WCHAR);
  36. lpBuffer += dwLength;
  37. return(lpBuffer);
  38. }
  39. LPBYTE
  40. AdsTypeCopyCaseExactString(
  41. PADSVALUE lpAdsSrcValue,
  42. PADSVALUE lpAdsDestValue,
  43. LPBYTE lpBuffer
  44. )
  45. {
  46. DWORD dwLength = 0;
  47. if(lpAdsSrcValue->dwType != ADSTYPE_CASE_EXACT_STRING){
  48. return(lpBuffer);
  49. }
  50. lpAdsDestValue->dwType = ADSTYPE_CASE_EXACT_STRING;
  51. //
  52. // The target buffer has to be WCHAR (WORD) aligned
  53. //
  54. lpBuffer = (LPBYTE) ROUND_UP_POINTER(lpBuffer, ALIGN_WORD);
  55. lpAdsDestValue->CaseExactString = (LPWSTR)lpBuffer;
  56. wcscpy((LPWSTR)lpBuffer, lpAdsSrcValue->CaseExactString);
  57. dwLength = (wcslen(lpAdsSrcValue->CaseExactString) + 1)*sizeof(WCHAR);
  58. lpBuffer += dwLength;
  59. return(lpBuffer);
  60. }
  61. LPBYTE
  62. AdsTypeCopyCaseIgnoreString(
  63. PADSVALUE lpAdsSrcValue,
  64. PADSVALUE lpAdsDestValue,
  65. LPBYTE lpBuffer
  66. )
  67. {
  68. DWORD dwLength = 0;
  69. if(lpAdsSrcValue->dwType != ADSTYPE_CASE_IGNORE_STRING){
  70. return(lpBuffer);
  71. }
  72. lpAdsDestValue->dwType = ADSTYPE_CASE_IGNORE_STRING;
  73. //
  74. // The target buffer has to be WCHAR (WORD) aligned
  75. //
  76. lpBuffer = (LPBYTE) ROUND_UP_POINTER(lpBuffer, ALIGN_WORD);
  77. lpAdsDestValue->CaseIgnoreString = (LPWSTR)lpBuffer;
  78. wcscpy((LPWSTR)lpBuffer, lpAdsSrcValue->CaseIgnoreString);
  79. dwLength = (wcslen(lpAdsSrcValue->CaseIgnoreString) + 1)*sizeof(WCHAR);
  80. lpBuffer += dwLength;
  81. return(lpBuffer);
  82. }
  83. LPBYTE
  84. AdsTypeCopyPrintableString(
  85. PADSVALUE lpAdsSrcValue,
  86. PADSVALUE lpAdsDestValue,
  87. LPBYTE lpBuffer
  88. )
  89. {
  90. DWORD dwLength = 0;
  91. if(lpAdsSrcValue->dwType != ADSTYPE_PRINTABLE_STRING){
  92. return(lpBuffer);
  93. }
  94. lpAdsDestValue->dwType = ADSTYPE_PRINTABLE_STRING;
  95. //
  96. // The target buffer has to be WCHAR (WORD) aligned
  97. //
  98. lpBuffer = (LPBYTE) ROUND_UP_POINTER(lpBuffer, ALIGN_WORD);
  99. lpAdsDestValue->PrintableString = (LPWSTR)lpBuffer;
  100. wcscpy((LPWSTR)lpBuffer, lpAdsSrcValue->PrintableString);
  101. dwLength = (wcslen(lpAdsSrcValue->PrintableString) + 1)*sizeof(WCHAR);
  102. lpBuffer += dwLength;
  103. return(lpBuffer);
  104. }
  105. LPBYTE
  106. AdsTypeCopyNumericString(
  107. PADSVALUE lpAdsSrcValue,
  108. PADSVALUE lpAdsDestValue,
  109. LPBYTE lpBuffer
  110. )
  111. {
  112. DWORD dwLength = 0;
  113. if(lpAdsSrcValue->dwType != ADSTYPE_NUMERIC_STRING){
  114. return(lpBuffer);
  115. }
  116. lpAdsDestValue->dwType = ADSTYPE_NUMERIC_STRING;
  117. //
  118. // The target buffer has to be WCHAR (WORD) aligned
  119. //
  120. lpBuffer = (LPBYTE) ROUND_UP_POINTER(lpBuffer, ALIGN_WORD);
  121. lpAdsDestValue->NumericString = (LPWSTR)lpBuffer;
  122. wcscpy((LPWSTR)lpBuffer, lpAdsSrcValue->NumericString);
  123. dwLength = (wcslen(lpAdsSrcValue->NumericString) + 1)*sizeof(WCHAR);
  124. lpBuffer += dwLength;
  125. return(lpBuffer);
  126. }
  127. LPBYTE
  128. AdsTypeCopyBoolean(
  129. PADSVALUE lpAdsSrcValue,
  130. PADSVALUE lpAdsDestValue,
  131. LPBYTE lpBuffer
  132. )
  133. {
  134. if(lpAdsSrcValue->dwType != ADSTYPE_BOOLEAN){
  135. return(lpBuffer);
  136. }
  137. lpAdsDestValue->dwType = ADSTYPE_BOOLEAN;
  138. lpAdsDestValue->Boolean = lpAdsSrcValue->Boolean;
  139. return(lpBuffer);
  140. }
  141. LPBYTE
  142. AdsTypeCopyInteger(
  143. PADSVALUE lpAdsSrcValue,
  144. PADSVALUE lpAdsDestValue,
  145. LPBYTE lpBuffer
  146. )
  147. {
  148. if(lpAdsSrcValue->dwType != ADSTYPE_INTEGER){
  149. return(lpBuffer);
  150. }
  151. lpAdsDestValue->dwType = ADSTYPE_INTEGER;
  152. lpAdsDestValue->Integer = lpAdsSrcValue->Integer;
  153. return(lpBuffer);
  154. }
  155. LPBYTE
  156. AdsTypeCopyOctetString(
  157. PADSVALUE lpAdsSrcValue,
  158. PADSVALUE lpAdsDestValue,
  159. LPBYTE lpBuffer
  160. )
  161. {
  162. DWORD dwNumBytes = 0;
  163. if(lpAdsSrcValue->dwType != ADSTYPE_OCTET_STRING){
  164. return(lpBuffer);
  165. }
  166. lpAdsDestValue->dwType = ADSTYPE_OCTET_STRING;
  167. dwNumBytes = lpAdsSrcValue->OctetString.dwLength;
  168. //
  169. // The target buffer should be worst-case aligned
  170. //
  171. lpBuffer = (LPBYTE) ROUND_UP_POINTER(lpBuffer, ALIGN_WORST);
  172. memcpy(
  173. lpBuffer,
  174. lpAdsSrcValue->OctetString.lpValue,
  175. dwNumBytes
  176. );
  177. lpAdsDestValue->OctetString.dwLength = dwNumBytes;
  178. lpAdsDestValue->OctetString.lpValue = lpBuffer;
  179. lpBuffer += dwNumBytes;
  180. return(lpBuffer);
  181. }
  182. LPBYTE
  183. AdsTypeCopySecurityDescriptor(
  184. PADSVALUE lpAdsSrcValue,
  185. PADSVALUE lpAdsDestValue,
  186. LPBYTE lpBuffer
  187. )
  188. {
  189. DWORD dwNumBytes = 0;
  190. if(lpAdsSrcValue->dwType != ADSTYPE_NT_SECURITY_DESCRIPTOR){
  191. return(lpBuffer);
  192. }
  193. lpAdsDestValue->dwType = ADSTYPE_NT_SECURITY_DESCRIPTOR;
  194. dwNumBytes = lpAdsSrcValue->SecurityDescriptor.dwLength;
  195. //
  196. // The target buffer should be worst-case aligned
  197. //
  198. lpBuffer = (LPBYTE) ROUND_UP_POINTER(lpBuffer, ALIGN_WORST);
  199. memcpy(
  200. lpBuffer,
  201. lpAdsSrcValue->SecurityDescriptor.lpValue,
  202. dwNumBytes
  203. );
  204. lpAdsDestValue->SecurityDescriptor.dwLength = dwNumBytes;
  205. lpAdsDestValue->SecurityDescriptor.lpValue = lpBuffer;
  206. lpBuffer += dwNumBytes;
  207. return(lpBuffer);
  208. }
  209. LPBYTE
  210. AdsTypeCopyTime(
  211. PADSVALUE lpAdsSrcValue,
  212. PADSVALUE lpAdsDestValue,
  213. LPBYTE lpBuffer
  214. )
  215. {
  216. if(lpAdsSrcValue->dwType != ADSTYPE_UTC_TIME){
  217. return(lpBuffer);
  218. }
  219. lpAdsDestValue->dwType = ADSTYPE_UTC_TIME;
  220. lpAdsDestValue->UTCTime = lpAdsSrcValue->UTCTime;
  221. return(lpBuffer);
  222. }
  223. LPBYTE
  224. AdsTypeCopyLargeInteger(
  225. PADSVALUE lpAdsSrcValue,
  226. PADSVALUE lpAdsDestValue,
  227. LPBYTE lpBuffer
  228. )
  229. {
  230. if(lpAdsSrcValue->dwType != ADSTYPE_LARGE_INTEGER){
  231. return(lpBuffer);
  232. }
  233. lpAdsDestValue->dwType = ADSTYPE_LARGE_INTEGER;
  234. lpAdsDestValue->LargeInteger = lpAdsSrcValue->LargeInteger;
  235. return(lpBuffer);
  236. }
  237. LPBYTE
  238. AdsTypeCopyProvSpecific(
  239. PADSVALUE lpAdsSrcValue,
  240. PADSVALUE lpAdsDestValue,
  241. LPBYTE lpBuffer
  242. )
  243. {
  244. DWORD dwNumBytes = 0;
  245. if(lpAdsSrcValue->dwType != ADSTYPE_PROV_SPECIFIC){
  246. return(lpBuffer);
  247. }
  248. lpAdsDestValue->dwType = ADSTYPE_PROV_SPECIFIC;
  249. dwNumBytes = lpAdsSrcValue->ProviderSpecific.dwLength;
  250. //
  251. // The target buffer should be worst-case aligned
  252. //
  253. lpBuffer = (LPBYTE) ROUND_UP_POINTER(lpBuffer, ALIGN_WORST);
  254. memcpy(
  255. lpBuffer,
  256. lpAdsSrcValue->ProviderSpecific.lpValue,
  257. dwNumBytes
  258. );
  259. lpAdsDestValue->ProviderSpecific.dwLength = dwNumBytes;
  260. lpAdsDestValue->ProviderSpecific.lpValue = lpBuffer;
  261. lpBuffer += dwNumBytes;
  262. return(lpBuffer);
  263. }
  264. LPBYTE
  265. AdsTypeCopyDNWithBinary(
  266. PADSVALUE lpAdsSrcValue,
  267. PADSVALUE lpAdsDestValue,
  268. LPBYTE lpBuffer
  269. )
  270. {
  271. DWORD dwLength = 0;
  272. PADS_DN_WITH_BINARY pDNBin = NULL;
  273. if(lpAdsSrcValue->dwType != ADSTYPE_DN_WITH_BINARY){
  274. return(lpBuffer);
  275. }
  276. lpAdsDestValue->dwType = ADSTYPE_DN_WITH_BINARY;
  277. //
  278. // Worse-case align the target buffer for the structure itself
  279. //
  280. lpBuffer = (LPBYTE) ROUND_UP_POINTER(lpBuffer, ALIGN_WORST);
  281. lpAdsDestValue->pDNWithBinary = (PADS_DN_WITH_BINARY) lpBuffer;
  282. lpBuffer += sizeof(ADS_DN_WITH_BINARY);
  283. if (!lpAdsSrcValue->pDNWithBinary) {
  284. return(lpBuffer);
  285. }
  286. pDNBin = lpAdsSrcValue->pDNWithBinary;
  287. dwLength = pDNBin->dwLength;
  288. //
  289. // Copy the byte array over if applicable.
  290. //
  291. if (dwLength) {
  292. //
  293. // Worse-case align the target buffer for the binary data
  294. //
  295. lpBuffer = (LPBYTE) ROUND_UP_POINTER(lpBuffer, ALIGN_WORST);
  296. memcpy(
  297. lpBuffer,
  298. pDNBin->lpBinaryValue,
  299. lpAdsSrcValue->pDNWithBinary->dwLength
  300. );
  301. lpAdsDestValue->pDNWithBinary->dwLength = dwLength;
  302. lpAdsDestValue->pDNWithBinary->lpBinaryValue = lpBuffer;
  303. }
  304. lpBuffer += dwLength;
  305. //
  306. // Now for the string
  307. //
  308. if (pDNBin->pszDNString) {
  309. //
  310. // The target buffer has to be WCHAR (WORD) aligned
  311. // for the string
  312. //
  313. lpBuffer = (LPBYTE) ROUND_UP_POINTER(lpBuffer, ALIGN_WORD);
  314. dwLength = wcslen(pDNBin->pszDNString);
  315. wcscpy((LPWSTR) lpBuffer, pDNBin->pszDNString);
  316. lpAdsDestValue->pDNWithBinary->pszDNString = (LPWSTR) lpBuffer;
  317. //
  318. // For the trailing \0 of the string
  319. //
  320. dwLength++;
  321. lpBuffer += (dwLength * sizeof(WCHAR));
  322. }
  323. return lpBuffer;
  324. }
  325. LPBYTE
  326. AdsTypeCopyDNWithString(
  327. PADSVALUE lpAdsSrcValue,
  328. PADSVALUE lpAdsDestValue,
  329. LPBYTE lpBuffer
  330. )
  331. {
  332. DWORD dwStrLen = 0;
  333. DWORD dwDNLen = 0;
  334. PADS_DN_WITH_STRING pDNStr = NULL;
  335. if(lpAdsSrcValue->dwType != ADSTYPE_DN_WITH_STRING){
  336. return(lpBuffer);
  337. }
  338. lpAdsDestValue->dwType = ADSTYPE_DN_WITH_STRING;
  339. //
  340. // Worst-case align the target buffer for the structure
  341. //
  342. lpBuffer = (LPBYTE) ROUND_UP_POINTER(lpBuffer, ALIGN_WORST);
  343. lpAdsDestValue->pDNWithString = (PADS_DN_WITH_STRING) lpBuffer;
  344. lpBuffer += sizeof(ADS_DN_WITH_STRING);
  345. if (!lpAdsSrcValue->pDNWithString) {
  346. return(lpBuffer);
  347. }
  348. pDNStr = lpAdsSrcValue->pDNWithString;
  349. //
  350. // Copy the string over if applicable.
  351. //
  352. if (pDNStr->pszStringValue) {
  353. //
  354. // The target buffer has to be WCHAR (WORD) aligned
  355. //
  356. lpBuffer = (LPBYTE) ROUND_UP_POINTER(lpBuffer, ALIGN_WORD);
  357. dwStrLen = wcslen(pDNStr->pszStringValue);
  358. wcscpy((LPWSTR)lpBuffer, pDNStr->pszStringValue);
  359. lpAdsDestValue->pDNWithString->pszStringValue = (LPWSTR) lpBuffer;
  360. //
  361. // +1 for trailing \0
  362. //
  363. lpBuffer += (sizeof(WCHAR) * ( dwStrLen + 1));
  364. }
  365. //
  366. // Now for the DN String
  367. //
  368. if (pDNStr->pszDNString) {
  369. //
  370. // The target buffer has to be WCHAR (WORD) aligned
  371. //
  372. lpBuffer = (LPBYTE) ROUND_UP_POINTER(lpBuffer, ALIGN_WORD);
  373. dwDNLen = wcslen(pDNStr->pszDNString);
  374. wcscpy((LPWSTR) lpBuffer, pDNStr->pszDNString);
  375. lpAdsDestValue->pDNWithString->pszDNString = (LPWSTR) lpBuffer;
  376. //
  377. // For the trailing \0 of the string
  378. //
  379. dwDNLen++;
  380. lpBuffer += (dwDNLen * sizeof(WCHAR));
  381. }
  382. return lpBuffer;
  383. }
  384. LPBYTE
  385. AdsTypeCopy(
  386. PADSVALUE lpAdsSrcValue,
  387. PADSVALUE lpAdsDestValue,
  388. LPBYTE lpBuffer
  389. )
  390. {
  391. switch (lpAdsSrcValue->dwType){
  392. case ADSTYPE_DN_STRING:
  393. lpBuffer = AdsTypeCopyDNString(
  394. lpAdsSrcValue,
  395. lpAdsDestValue,
  396. lpBuffer
  397. );
  398. break;
  399. case ADSTYPE_CASE_EXACT_STRING:
  400. lpBuffer = AdsTypeCopyCaseExactString(
  401. lpAdsSrcValue,
  402. lpAdsDestValue,
  403. lpBuffer
  404. );
  405. break;
  406. case ADSTYPE_CASE_IGNORE_STRING:
  407. lpBuffer = AdsTypeCopyCaseIgnoreString(
  408. lpAdsSrcValue,
  409. lpAdsDestValue,
  410. lpBuffer
  411. );
  412. break;
  413. case ADSTYPE_PRINTABLE_STRING:
  414. lpBuffer = AdsTypeCopyPrintableString(
  415. lpAdsSrcValue,
  416. lpAdsDestValue,
  417. lpBuffer
  418. );
  419. break;
  420. case ADSTYPE_NUMERIC_STRING:
  421. lpBuffer = AdsTypeCopyNumericString(
  422. lpAdsSrcValue,
  423. lpAdsDestValue,
  424. lpBuffer
  425. );
  426. break;
  427. case ADSTYPE_BOOLEAN:
  428. lpBuffer = AdsTypeCopyBoolean(
  429. lpAdsSrcValue,
  430. lpAdsDestValue,
  431. lpBuffer
  432. );
  433. break;
  434. case ADSTYPE_INTEGER:
  435. lpBuffer = AdsTypeCopyInteger(
  436. lpAdsSrcValue,
  437. lpAdsDestValue,
  438. lpBuffer
  439. );
  440. break;
  441. case ADSTYPE_OCTET_STRING:
  442. lpBuffer = AdsTypeCopyOctetString(
  443. lpAdsSrcValue,
  444. lpAdsDestValue,
  445. lpBuffer
  446. );
  447. break;
  448. case ADSTYPE_UTC_TIME:
  449. lpBuffer = AdsTypeCopyTime(
  450. lpAdsSrcValue,
  451. lpAdsDestValue,
  452. lpBuffer
  453. );
  454. break;
  455. case ADSTYPE_LARGE_INTEGER:
  456. lpBuffer = AdsTypeCopyLargeInteger(
  457. lpAdsSrcValue,
  458. lpAdsDestValue,
  459. lpBuffer
  460. );
  461. break;
  462. case ADSTYPE_PROV_SPECIFIC:
  463. lpBuffer = AdsTypeCopyProvSpecific(
  464. lpAdsSrcValue,
  465. lpAdsDestValue,
  466. lpBuffer
  467. );
  468. break;
  469. case ADSTYPE_NT_SECURITY_DESCRIPTOR:
  470. lpBuffer = AdsTypeCopySecurityDescriptor(
  471. lpAdsSrcValue,
  472. lpAdsDestValue,
  473. lpBuffer
  474. );
  475. break;
  476. case ADSTYPE_DN_WITH_BINARY:
  477. lpBuffer = AdsTypeCopyDNWithBinary(
  478. lpAdsSrcValue,
  479. lpAdsDestValue,
  480. lpBuffer
  481. );
  482. break;
  483. case ADSTYPE_DN_WITH_STRING:
  484. lpBuffer = AdsTypeCopyDNWithString(
  485. lpAdsSrcValue,
  486. lpAdsDestValue,
  487. lpBuffer
  488. );
  489. break;
  490. default:
  491. break;
  492. }
  493. return(lpBuffer);
  494. }