/lwraft/server/middle-layer/schema.c

https://github.com/vmware/lightwave · C · 161 lines · 122 code · 20 blank · 19 comment · 13 complexity · 5ba17d54d9be4f0ee4ace1313de07794 MD5 · raw file

  1. /*
  2. * Copyright © 2017 VMware, Inc. All Rights Reserved.
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the “License”); you may not
  5. * use this file except in compliance with the License. You may obtain a copy
  6. * of the License at http://www.apache.org/licenses/LICENSE-2.0
  7. *
  8. * Unless required by applicable law or agreed to in writing, software
  9. * distributed under the License is distributed on an “AS IS” BASIS, without
  10. * warranties or conditions of any kind, EITHER EXPRESS OR IMPLIED. See the
  11. * License for the specific language governing permissions and limitations
  12. * under the License.
  13. */
  14. #include "includes.h"
  15. DWORD
  16. VmDirPluginSchemaLibUpdatePreModify(
  17. PVDIR_OPERATION pOperation,
  18. PVDIR_ENTRY pEntry,
  19. DWORD dwPriorResult
  20. )
  21. {
  22. DWORD dwRtn = 0;
  23. PVDIR_MODIFICATION pMod = NULL;
  24. if (pOperation->dwSchemaWriteOp)
  25. {
  26. for (pMod = pOperation->request.modifyReq.mods; pMod; pMod = pMod->next)
  27. {
  28. // reject the following changes:
  29. // - objectclass
  30. // - cn
  31. PSTR pszType = pMod->attr.type.lberbv.bv_val;
  32. if (VmDirStringCompareA(pszType, ATTR_OBJECT_CLASS, FALSE) == 0 ||
  33. VmDirStringCompareA(pszType, ATTR_CN, FALSE) == 0)
  34. {
  35. dwRtn = VMDIR_ERROR_SCHEMA_NOT_COMPATIBLE;
  36. BAIL_ON_VMDIR_ERROR(dwRtn);
  37. }
  38. }
  39. dwRtn = VmDirSchemaLibPrepareUpdateViaModify(pOperation, pEntry);
  40. BAIL_ON_VMDIR_ERROR(dwRtn);
  41. }
  42. error:
  43. return dwPriorResult ? dwPriorResult : dwRtn;
  44. }
  45. DWORD
  46. VmDirPluginSchemaLibUpdatePostModifyCommit(
  47. PVDIR_OPERATION pOperation,
  48. PVDIR_ENTRY pEntry,
  49. DWORD dwPriorResult
  50. )
  51. {
  52. DWORD dwRtn = 0;
  53. if (pOperation->dwSchemaWriteOp)
  54. {
  55. dwRtn = VmDirSchemaLibUpdate(dwPriorResult);
  56. }
  57. return dwPriorResult ? dwPriorResult : dwRtn;
  58. }
  59. DWORD
  60. VmDirPluginSchemaEntryPreAdd(
  61. PVDIR_OPERATION pOperation,
  62. PVDIR_ENTRY pEntry,
  63. DWORD dwPriorResult
  64. )
  65. {
  66. DWORD dwRtn = 0;
  67. PVDIR_ATTRIBUTE pCnAttr = NULL;
  68. PSTR pszSchemaIdGuid = NULL;
  69. if (pOperation->dwSchemaWriteOp)
  70. {
  71. // lDAPDisplayName attribute takes cn as default
  72. if (!VmDirFindAttrByName(pEntry, ATTR_LDAP_DISPLAYNAME))
  73. {
  74. pCnAttr = VmDirFindAttrByName(pEntry, ATTR_CN);
  75. if (!pCnAttr)
  76. {
  77. dwRtn = VMDIR_ERROR_INVALID_ENTRY;
  78. BAIL_ON_VMDIR_ERROR(dwRtn);
  79. }
  80. dwRtn = VmDirEntryAddSingleValueStrAttribute(
  81. pEntry,
  82. ATTR_LDAP_DISPLAYNAME,
  83. pCnAttr->vals[0].lberbv.bv_val);
  84. BAIL_ON_VMDIR_ERROR(dwRtn);
  85. }
  86. // schemaIDGUID attribute takes a generated guid as default
  87. if (!VmDirFindAttrByName(pEntry, ATTR_SCHEMAID_GUID))
  88. {
  89. dwRtn = VmDirGenerateGUID(&pszSchemaIdGuid);
  90. BAIL_ON_VMDIR_ERROR(dwRtn);
  91. dwRtn = VmDirEntryAddSingleValueStrAttribute(
  92. pEntry,
  93. ATTR_SCHEMAID_GUID,
  94. pszSchemaIdGuid);
  95. BAIL_ON_VMDIR_ERROR(dwRtn);
  96. }
  97. if (VmDirEntryIsObjectclass(pEntry, OC_CLASS_SCHEMA))
  98. {
  99. // defaultObjectCategory attribute takes dn as default
  100. if (!VmDirFindAttrByName(pEntry, ATTR_DEFAULT_OBJECT_CATEGORY))
  101. {
  102. dwRtn = VmDirEntryAddSingleValueStrAttribute(
  103. pEntry,
  104. ATTR_DEFAULT_OBJECT_CATEGORY,
  105. pEntry->dn.lberbv.bv_val);
  106. BAIL_ON_VMDIR_ERROR(dwRtn);
  107. }
  108. }
  109. }
  110. error:
  111. VMDIR_SAFE_FREE_MEMORY(pszSchemaIdGuid);
  112. return dwPriorResult ? dwPriorResult : dwRtn;
  113. }
  114. DWORD
  115. VmDirPluginSchemaLibUpdatePreAdd(
  116. PVDIR_OPERATION pOperation,
  117. PVDIR_ENTRY pEntry,
  118. DWORD dwPriorResult
  119. )
  120. {
  121. DWORD dwRtn = 0;
  122. if (pOperation->dwSchemaWriteOp)
  123. {
  124. dwRtn = VmDirSchemaCheck(pEntry);
  125. BAIL_ON_VMDIR_ERROR(dwRtn);
  126. dwRtn = VmDirSchemaLibPrepareUpdateViaModify(pOperation, pEntry);
  127. BAIL_ON_VMDIR_ERROR(dwRtn);
  128. }
  129. error:
  130. return dwPriorResult ? dwPriorResult : dwRtn;
  131. }
  132. DWORD
  133. VmDirPluginSchemaLibUpdatePostAddCommit(
  134. PVDIR_OPERATION pOperation,
  135. PVDIR_ENTRY pEntry,
  136. DWORD dwResult
  137. )
  138. {
  139. return VmDirPluginSchemaLibUpdatePostModifyCommit(
  140. pOperation, pEntry, dwResult);
  141. }