lite_entries.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /** BEGIN COPYRIGHT BLOCK
  2. * This Program is free software; you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation; version 2 of the License.
  5. *
  6. * This Program is distributed in the hope that it will be useful, but WITHOUT
  7. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  8. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  9. *
  10. * You should have received a copy of the GNU General Public License along with
  11. * this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
  12. * Place, Suite 330, Boston, MA 02111-1307 USA.
  13. *
  14. * In addition, as a special exception, Red Hat, Inc. gives You the additional
  15. * right to link the code of this Program with code not covered under the GNU
  16. * General Public License ("Non-GPL Code") and to distribute linked combinations
  17. * including the two, subject to the limitations in this paragraph. Non-GPL Code
  18. * permitted under this exception must only link to the code of this Program
  19. * through those well defined interfaces identified in the file named EXCEPTION
  20. * found in the source code files (the "Approved Interfaces"). The files of
  21. * Non-GPL Code may instantiate templates or use macros or inline functions from
  22. * the Approved Interfaces without causing the resulting work to be covered by
  23. * the GNU General Public License. Only Red Hat, Inc. may make changes or
  24. * additions to the list of Approved Interfaces. You must obey the GNU General
  25. * Public License in all respects for all of the Program code and other code used
  26. * in conjunction with the Program except the Non-GPL Code covered by this
  27. * exception. If you modify this file, you may extend this exception to your
  28. * version of the file, but you are not obligated to do so. If you do not wish to
  29. * provide this exception without modification, you must delete this exception
  30. * statement from your version and license this file solely under the GPL without
  31. * exception.
  32. *
  33. *
  34. * Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
  35. * Copyright (C) 2005 Red Hat, Inc.
  36. * All rights reserved.
  37. * END COPYRIGHT BLOCK **/
  38. #ifdef HAVE_CONFIG_H
  39. # include <config.h>
  40. #endif
  41. /* lite_entries.c -
  42. *
  43. * These entries are added under cn=options,cn=features,cn=config for
  44. * Directory Lite. These entries tell the console which modules ( ds features )
  45. * are disabled, and which attributes in cn=config are disabled.
  46. */
  47. #include "slap.h"
  48. static void del_dslite_entries();
  49. static void add_dslite_entries();
  50. static const char *lite_entries[] =
  51. {
  52. "dn:" LITE_DISABLED_ATTRS_DN "\n"
  53. "cn:attributes\n"
  54. "objectclass:top\n"
  55. "objectclass:extensibleObject\n"
  56. "objectclass:directoryServerFeature\n"
  57. "cn=config|nsslapd-referral:off\n"
  58. "cn=config|nsslapd-maxdescriptors:off\n",
  59. "dn:" LITE_DISABLED_MODULES_DN "\n"
  60. "objectclass:top\n"
  61. "objectclass:directoryServerFeature\n"
  62. "objectclass:extensibleObject\n"
  63. "cn:modules\n"
  64. "replication:off\n"
  65. "passwordpolicy:off\n"
  66. "accountlockout:off\n"
  67. "snmpsettings:off\n"
  68. "backup:off\n",
  69. NULL
  70. };
  71. /* add_dslite_entries:
  72. *
  73. * Add the DirLite specific entries.
  74. * First we try to delete them in case they were already loaded from dse.ldif
  75. * but are in some sort of invalid state.
  76. * Then we add them back.
  77. * It would have been better to make sure that these entries never get written
  78. * to dse.ldif, but it doesn't look like we're able to add a dse_callback function
  79. * on the DN's of these entries but they get added at the wrong time.
  80. */
  81. static void
  82. add_dslite_entries() {
  83. int i;
  84. del_dslite_entries();
  85. LDAPDebug( LDAP_DEBUG_TRACE, "Adding lite entries.\n",0,0,0);
  86. for( i = 0; lite_entries[i]; i++ ) {
  87. Slapi_PBlock *resultpb;
  88. char *estr = slapi_ch_strdup ( lite_entries[i] );
  89. Slapi_Entry *e = slapi_str2entry( estr, 0 );
  90. if ( NULL != e ) {
  91. resultpb = slapi_add_entry_internal( e, NULL, 0 );
  92. slapi_ch_free ( (void **) &resultpb );
  93. slapi_ch_free ( (void **) &estr );
  94. }
  95. }
  96. }
  97. /* del_dslite_entries: delete the DirLite specific entries */
  98. static void
  99. del_dslite_entries() {
  100. Slapi_PBlock *resultpb;
  101. LDAPDebug( LDAP_DEBUG_TRACE, "Deleting lite entries if they exist\n",0,0,0);
  102. resultpb = slapi_delete_internal ( LITE_DISABLED_ATTRS_DN, NULL, 0 );
  103. slapi_pblock_destroy ( resultpb );
  104. resultpb = slapi_delete_internal ( LITE_DISABLED_MODULES_DN, NULL, 0 );
  105. slapi_pblock_destroy ( resultpb );
  106. }
  107. /* lite_entries_init()
  108. * Add the appropriate entries under cn=options,cn=features,cn=config if the
  109. * server is running as Directory Lite.
  110. *
  111. * Otherwise, if the server is the Full Directory, try to delete the entries if
  112. * they're already there.
  113. */
  114. void
  115. lite_entries_init() {
  116. if ( config_is_slapd_lite() ) {
  117. add_dslite_entries();
  118. }
  119. else {
  120. del_dslite_entries();
  121. }
  122. }