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.

185 lines
3.6 KiB

  1. //----------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 2000.
  5. //
  6. // File: ldaputils.c
  7. //
  8. // Contents: Utilities for LDAP.
  9. //
  10. //
  11. // History: KrishnaG
  12. // AbhisheV
  13. //
  14. //----------------------------------------------------------------------------
  15. #include "precomp.h"
  16. void
  17. FreeLDAPModWs(
  18. struct ldapmodW ** AttributeList
  19. )
  20. {
  21. DWORD i = 0;
  22. PLDAPModW attr = NULL;
  23. DWORD dwValCount = 0;
  24. PLDAP_BERVAL berValue = NULL;
  25. PWCHAR strValue = NULL;
  26. if (AttributeList == NULL) {
  27. return;
  28. }
  29. while (AttributeList[i] != NULL) {
  30. attr = AttributeList[i++];
  31. if (attr->mod_type != NULL) {
  32. FreePolStr(attr->mod_type);
  33. }
  34. if (attr->mod_op & LDAP_MOD_BVALUES) {
  35. if (attr->mod_vals.modv_bvals != NULL) {
  36. dwValCount = 0;
  37. while (attr->mod_vals.modv_bvals[dwValCount]) {
  38. berValue = attr->mod_vals.modv_bvals[dwValCount++];
  39. FreePolMem(berValue);
  40. }
  41. FreePolMem(attr->mod_vals.modv_bvals);
  42. }
  43. } else {
  44. if (attr->mod_vals.modv_strvals != NULL) {
  45. dwValCount = 0;
  46. while (attr->mod_vals.modv_strvals[dwValCount]) {
  47. strValue = attr->mod_vals.modv_strvals[dwValCount];
  48. FreePolMem(strValue);
  49. dwValCount++;
  50. }
  51. FreePolMem(attr->mod_vals.modv_strvals);
  52. }
  53. }
  54. }
  55. FreePolMem(AttributeList[0]);
  56. FreePolMem(AttributeList);
  57. return;
  58. }
  59. DWORD
  60. AllocateLDAPStringValue(
  61. LPWSTR pszString,
  62. PLDAPOBJECT * ppLdapObject
  63. )
  64. {
  65. PLDAPOBJECT pLdapObject = NULL;
  66. DWORD dwError = 0;
  67. LPWSTR pszNewString = NULL;
  68. pLdapObject = (PLDAPOBJECT)AllocPolMem(
  69. (1 + 1)*sizeof(LDAPOBJECT)
  70. );
  71. if (!pLdapObject) {
  72. dwError = ERROR_OUTOFMEMORY;
  73. BAIL_ON_WIN32_ERROR(dwError);
  74. }
  75. dwError = AllocatePolString(
  76. pszString,
  77. &pszNewString
  78. );
  79. BAIL_ON_WIN32_ERROR(dwError);
  80. LDAPOBJECT_STRING(pLdapObject) = pszNewString;
  81. *ppLdapObject = pLdapObject;
  82. return(dwError);
  83. error:
  84. *ppLdapObject = NULL;
  85. if (pLdapObject) {
  86. FreePolMem(
  87. pLdapObject
  88. );
  89. }
  90. return(dwError);
  91. }
  92. DWORD
  93. AllocateLDAPBinaryValue(
  94. LPBYTE pByte,
  95. DWORD dwNumBytes,
  96. PLDAPOBJECT * ppLdapObject
  97. )
  98. {
  99. PLDAPOBJECT pLdapObject = NULL;
  100. DWORD dwError = 0;
  101. LPBYTE pNewMem = NULL;
  102. pLdapObject = (PLDAPOBJECT)AllocPolMem(
  103. (1 + 1)*sizeof(LDAPOBJECT)
  104. );
  105. if (!pLdapObject) {
  106. dwError = ERROR_OUTOFMEMORY;
  107. BAIL_ON_WIN32_ERROR(dwError);
  108. }
  109. LDAPOBJECT_BERVAL(pLdapObject) =
  110. (struct berval *) AllocPolMem( sizeof(struct berval) + dwNumBytes );
  111. if (!LDAPOBJECT_BERVAL(pLdapObject)) {
  112. dwError = ERROR_OUTOFMEMORY;
  113. BAIL_ON_WIN32_ERROR(dwError);
  114. }
  115. LDAPOBJECT_BERVAL_LEN(pLdapObject) = dwNumBytes;
  116. LDAPOBJECT_BERVAL_VAL(pLdapObject) = (CHAR *) ((LPBYTE) LDAPOBJECT_BERVAL(pLdapObject) + sizeof(struct berval));
  117. memcpy( LDAPOBJECT_BERVAL_VAL(pLdapObject),
  118. pByte,
  119. dwNumBytes );
  120. *ppLdapObject = pLdapObject;
  121. return(dwError);
  122. error:
  123. *ppLdapObject = NULL;
  124. if (pLdapObject) {
  125. FreePolMem(
  126. pLdapObject
  127. );
  128. }
  129. return(dwError);
  130. }