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.

443 lines
8.6 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1992 - 1997.
  5. //
  6. // File: odssz.cxx
  7. //
  8. // Contents: DSObject Size Routines
  9. //
  10. // Functions:
  11. //
  12. // History: 25-Feb-97 KrishnaG Created.
  13. //
  14. //----------------------------------------------------------------------------
  15. #include "ldapc.hxx"
  16. DWORD
  17. AdsTypeDNStringSize(
  18. PADSVALUE lpAdsSrcValue
  19. )
  20. {
  21. DWORD dwSize = 0;
  22. if(lpAdsSrcValue->dwType != ADSTYPE_DN_STRING){
  23. return(0);
  24. }
  25. //
  26. // strings must be WCHAR (WORD) aligned
  27. //
  28. dwSize = (wcslen(lpAdsSrcValue->DNString) + 1)*sizeof(WCHAR) +
  29. (ALIGN_WORD-1);
  30. return(dwSize);
  31. }
  32. DWORD
  33. AdsTypeCaseExactStringSize(
  34. PADSVALUE lpAdsSrcValue
  35. )
  36. {
  37. DWORD dwSize = 0;
  38. if(lpAdsSrcValue->dwType != ADSTYPE_CASE_EXACT_STRING){
  39. return(0);
  40. }
  41. //
  42. // strings must be WCHAR (WORD) aligned
  43. //
  44. dwSize = (wcslen(lpAdsSrcValue->CaseExactString) + 1) *sizeof(WCHAR) +
  45. (ALIGN_WORD-1);
  46. return(dwSize);
  47. }
  48. DWORD
  49. AdsTypeCaseIgnoreStringSize(
  50. PADSVALUE lpAdsSrcValue
  51. )
  52. {
  53. DWORD dwSize = 0;
  54. if(lpAdsSrcValue->dwType != ADSTYPE_CASE_IGNORE_STRING){
  55. return(0);
  56. }
  57. //
  58. // strings must be WCHAR (WORD) aligned
  59. //
  60. dwSize = (wcslen(lpAdsSrcValue->CaseIgnoreString) + 1) *sizeof(WCHAR) +
  61. (ALIGN_WORD-1);
  62. return(dwSize);
  63. }
  64. DWORD
  65. AdsTypePrintableStringSize(
  66. PADSVALUE lpAdsSrcValue
  67. )
  68. {
  69. DWORD dwSize = 0;
  70. if(lpAdsSrcValue->dwType != ADSTYPE_PRINTABLE_STRING){
  71. return(0);
  72. }
  73. //
  74. // strings must be WCHAR (WORD) aligned
  75. //
  76. dwSize = (wcslen(lpAdsSrcValue->PrintableString) + 1) *sizeof(WCHAR) +
  77. (ALIGN_WORD-1);
  78. return(dwSize);
  79. }
  80. DWORD
  81. AdsTypeNumericStringSize(
  82. PADSVALUE lpAdsSrcValue
  83. )
  84. {
  85. DWORD dwSize = 0;
  86. if(lpAdsSrcValue->dwType != ADSTYPE_NUMERIC_STRING){
  87. return(0);
  88. }
  89. //
  90. // strings must be WCHAR (WORD) aligned
  91. //
  92. dwSize = (wcslen(lpAdsSrcValue->NumericString) + 1)* sizeof(WCHAR) +
  93. (ALIGN_WORD-1);
  94. return(dwSize);
  95. }
  96. DWORD
  97. AdsTypeBooleanSize(
  98. PADSVALUE lpAdsSrcValue
  99. )
  100. {
  101. if(lpAdsSrcValue->dwType != ADSTYPE_BOOLEAN){
  102. return(0);
  103. }
  104. return(0);
  105. }
  106. DWORD
  107. AdsTypeIntegerSize(
  108. PADSVALUE lpAdsSrcValue
  109. )
  110. {
  111. if(lpAdsSrcValue->dwType != ADSTYPE_INTEGER){
  112. return(0);
  113. }
  114. return(0);
  115. }
  116. DWORD
  117. AdsTypeOctetStringSize(
  118. PADSVALUE lpAdsSrcValue
  119. )
  120. {
  121. DWORD dwNumBytes = 0;
  122. if(lpAdsSrcValue->dwType != ADSTYPE_OCTET_STRING){
  123. return(0);
  124. }
  125. //
  126. // Add bytes to the size as we need to align all the
  127. // OctetStrings on at least 8 byte boundaries. We'll
  128. // worst-case align to be conservative for IA64.
  129. // ALIGN_WORST is defined in priv inc which also defines
  130. // the ROUND_UP macro used.
  131. //
  132. dwNumBytes = lpAdsSrcValue->OctetString.dwLength + ALIGN_WORST - 1;
  133. return(dwNumBytes);
  134. }
  135. DWORD
  136. AdsTypeSecurityDescriptorSize(
  137. PADSVALUE lpAdsSrcValue
  138. )
  139. {
  140. DWORD dwNumBytes = 0;
  141. if(lpAdsSrcValue->dwType != ADSTYPE_NT_SECURITY_DESCRIPTOR){
  142. return(0);
  143. }
  144. //
  145. // Security Descriptors need to be DWORD aligned but we
  146. // provide worst case alignment as C structs have 8 bytes alignment
  147. // (at least on x86).
  148. // ALIGN_WORST defined in align.h in priv inc, which also
  149. // has the round up macro used.
  150. //
  151. dwNumBytes = lpAdsSrcValue->SecurityDescriptor.dwLength + ALIGN_WORST - 1;
  152. return(dwNumBytes);
  153. }
  154. DWORD
  155. AdsTypeTimeSize(
  156. PADSVALUE lpAdsSrcValue
  157. )
  158. {
  159. if(lpAdsSrcValue->dwType != ADSTYPE_UTC_TIME){
  160. return(0);
  161. }
  162. return(0);
  163. }
  164. DWORD
  165. AdsTypeLargeIntegerSize(
  166. PADSVALUE lpAdsSrcValue
  167. )
  168. {
  169. if(lpAdsSrcValue->dwType != ADSTYPE_LARGE_INTEGER){
  170. return(0);
  171. }
  172. return(0);
  173. }
  174. DWORD
  175. AdsTypeProvSpecificSize(
  176. PADSVALUE lpAdsSrcValue
  177. )
  178. {
  179. DWORD dwNumBytes = 0;
  180. if(lpAdsSrcValue->dwType != ADSTYPE_PROV_SPECIFIC){
  181. return(0);
  182. }
  183. //
  184. // We don't know what it contains, so assume worst-case alignment
  185. //
  186. dwNumBytes = lpAdsSrcValue->ProviderSpecific.dwLength + (ALIGN_WORST-1);
  187. return(dwNumBytes);
  188. }
  189. //
  190. // Computes size of the data in the DNWithBinary object
  191. //
  192. DWORD
  193. AdsTypeDNWithBinarySize(
  194. PADSVALUE lpAdsSrcValue
  195. )
  196. {
  197. DWORD dwSize = 0;
  198. DWORD dwStrLen = 0;
  199. if (lpAdsSrcValue->dwType != ADSTYPE_DN_WITH_BINARY) {
  200. return 0;
  201. }
  202. if (!lpAdsSrcValue->pDNWithBinary) {
  203. return(0);
  204. }
  205. //
  206. // The length is EncodedBinLen+dnlen+:+:+:+B+10 (for int len)
  207. //
  208. if (lpAdsSrcValue->pDNWithBinary->pszDNString) {
  209. dwStrLen = (wcslen(lpAdsSrcValue->pDNWithBinary->pszDNString)+1);
  210. //
  211. // strings must be WCHAR (WORD) aligned
  212. //
  213. dwSize += dwStrLen * sizeof(WCHAR) + (ALIGN_WORD-1);
  214. }
  215. //
  216. // Each byte is 2 wchars in the final string
  217. //
  218. if (lpAdsSrcValue->pDNWithBinary->dwLength) {
  219. dwSize += (lpAdsSrcValue->pDNWithBinary->dwLength);
  220. //
  221. // our cushion when reading from string encoded binary value
  222. // to byte array and one WCHAR for \0 of string
  223. //
  224. // worst-case align the binary data, since we don't know
  225. // how it will be accessed
  226. //
  227. dwSize += sizeof(DWORD) + sizeof(WCHAR) + (ALIGN_WORST-1);
  228. }
  229. //
  230. // provide worst-case alignment of the structure
  231. //
  232. dwSize += sizeof(ADS_DN_WITH_BINARY) + (ALIGN_WORST-1);
  233. return dwSize;
  234. }
  235. //
  236. // Computes size of the data in the DNWithString object.
  237. //
  238. DWORD
  239. AdsTypeDNWithStringSize(
  240. PADSVALUE pAdsSrcValue
  241. )
  242. {
  243. DWORD dwSize = 0;
  244. DWORD dwStrLen = 0;
  245. if (pAdsSrcValue->dwType != ADSTYPE_DN_WITH_STRING) {
  246. return 0;
  247. }
  248. if (!pAdsSrcValue->pDNWithString) {
  249. return(0);
  250. }
  251. //
  252. // align the strings on WCHAR (WORD) boundaries
  253. // provide worst-case alignment for the structure
  254. //
  255. if (pAdsSrcValue->pDNWithString->pszDNString) {
  256. dwStrLen = wcslen(pAdsSrcValue->pDNWithString->pszDNString) + 1;
  257. dwSize += dwStrLen * sizeof(WCHAR) + (ALIGN_WORD-1);
  258. }
  259. if (pAdsSrcValue->pDNWithString->pszStringValue) {
  260. dwStrLen = wcslen(pAdsSrcValue->pDNWithString->pszStringValue) + 1;
  261. dwSize += dwStrLen * sizeof(WCHAR) + (ALIGN_WORD-1);
  262. }
  263. //
  264. // Now for the strcut itself.
  265. //
  266. dwSize += sizeof(ADS_DN_WITH_STRING) + (ALIGN_WORST-1);
  267. return dwSize;
  268. }
  269. DWORD
  270. AdsTypeSize(
  271. PADSVALUE lpAdsSrcValue
  272. )
  273. {
  274. DWORD dwSize = 0;
  275. switch (lpAdsSrcValue->dwType){
  276. case ADSTYPE_DN_STRING:
  277. dwSize = AdsTypeDNStringSize(
  278. lpAdsSrcValue
  279. );
  280. break;
  281. case ADSTYPE_CASE_EXACT_STRING:
  282. dwSize = AdsTypeCaseExactStringSize(
  283. lpAdsSrcValue
  284. );
  285. break;
  286. case ADSTYPE_CASE_IGNORE_STRING:
  287. dwSize = AdsTypeCaseIgnoreStringSize(
  288. lpAdsSrcValue
  289. );
  290. break;
  291. case ADSTYPE_PRINTABLE_STRING:
  292. dwSize = AdsTypePrintableStringSize(
  293. lpAdsSrcValue
  294. );
  295. break;
  296. case ADSTYPE_NUMERIC_STRING:
  297. dwSize = AdsTypeNumericStringSize(
  298. lpAdsSrcValue
  299. );
  300. break;
  301. case ADSTYPE_BOOLEAN:
  302. dwSize = AdsTypeBooleanSize(
  303. lpAdsSrcValue
  304. );
  305. break;
  306. case ADSTYPE_INTEGER:
  307. dwSize = AdsTypeIntegerSize(
  308. lpAdsSrcValue
  309. );
  310. break;
  311. case ADSTYPE_OCTET_STRING:
  312. dwSize = AdsTypeOctetStringSize(
  313. lpAdsSrcValue
  314. );
  315. break;
  316. case ADSTYPE_UTC_TIME:
  317. dwSize = AdsTypeTimeSize(
  318. lpAdsSrcValue
  319. );
  320. break;
  321. case ADSTYPE_LARGE_INTEGER:
  322. dwSize = AdsTypeLargeIntegerSize(
  323. lpAdsSrcValue
  324. );
  325. break;
  326. case ADSTYPE_PROV_SPECIFIC:
  327. dwSize = AdsTypeProvSpecificSize(
  328. lpAdsSrcValue
  329. );
  330. break;
  331. case ADSTYPE_NT_SECURITY_DESCRIPTOR:
  332. dwSize = AdsTypeSecurityDescriptorSize(
  333. lpAdsSrcValue
  334. );
  335. break;
  336. case ADSTYPE_DN_WITH_BINARY:
  337. dwSize = AdsTypeDNWithBinarySize(
  338. lpAdsSrcValue
  339. );
  340. break;
  341. case ADSTYPE_DN_WITH_STRING:
  342. dwSize = AdsTypeDNWithStringSize(
  343. lpAdsSrcValue
  344. );
  345. break;
  346. default:
  347. break;
  348. }
  349. return(dwSize);
  350. }