ServerConfigCheck.cpp 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /*
  2. * Copyright 2005 - 2016 Zarafa and its licensors
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU Affero General Public License, version 3,
  6. * as published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU Affero General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU Affero General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. *
  16. */
  17. #include <kopano/platform.h>
  18. #include "ServerConfigCheck.h"
  19. #include <kopano/stringutil.h>
  20. ServerConfigCheck::ServerConfigCheck(const char *lpszConfigFile) : ECConfigCheck("Server Configuration file", lpszConfigFile)
  21. {
  22. std::string setting;
  23. setting = getSetting("enable_hosted_kopano");
  24. if (!setting.empty())
  25. setHosted(parseBool(setting.c_str()));
  26. setting = getSetting("enable_distributed_kopano");
  27. if (!setting.empty())
  28. setMulti(parseBool(setting.c_str()));
  29. }
  30. void ServerConfigCheck::loadChecks()
  31. {
  32. addCheck("attachment_storage", 0, &testAttachment);
  33. addCheck("attachment_storage", "attachment_path", 0, &testAttachmentPath);
  34. addCheck("user_plugin", 0, &testPlugin);
  35. addCheck("user_plugin", "user_plugin_config", 0, &testPluginConfig);
  36. addCheck("user_plugin", "plugin_path", 0, &testPluginPath);
  37. addCheck("createuser_script", 0, &testFile);
  38. addCheck("deleteuser_script", 0, &testFile);
  39. addCheck("creategroup_script", 0, &testFile);
  40. addCheck("deletegroup_script", 0, &testFile);
  41. addCheck("createcompany_script", CONFIG_HOSTED_USED, &testFile);
  42. addCheck("deletecompany_script", CONFIG_HOSTED_USED, &testFile);
  43. addCheck("enable_hosted_kopano", 0, &testBoolean);
  44. addCheck("storename_format", 0, &testStorename);
  45. addCheck("user_plugin", "loginname_format", 0, &testLoginname);
  46. addCheck("enable_distributed_kopano", 0, &testBoolean);
  47. addCheck("server_name", CONFIG_MULTI_USED);
  48. // addCheck("thread_stacksize", 0, &testMinInt, 25);
  49. addCheck("enable_gab", 0, &testBoolean);
  50. addCheck("enable_sso_ntlmauth", 0, &testBoolean);
  51. addCheck("client_update_enabled", 0, &testBoolean);
  52. addCheck("hide_everyone", 0, &testBoolean);
  53. addCheck("index_services_enabled", 0, &testBoolean);
  54. addCheck("enable_enhanced_ics", 0, &testBoolean);
  55. addCheck("softdelete_lifetime", 0, &testNonZero);
  56. addCheck("auth_method", 0, &testAuthMethod);
  57. }
  58. int ServerConfigCheck::testAttachment(const config_check_t *check)
  59. {
  60. if (check->value1.empty())
  61. return CHECK_OK;
  62. if (check->value1 == "database" || check->value1 == "files")
  63. return CHECK_OK;
  64. printError(check->option1, "contains unknown storage type: \"" + check->value1 + "\"");
  65. return CHECK_ERROR;
  66. }
  67. int ServerConfigCheck::testAttachmentPath(const config_check_t *check)
  68. {
  69. if (check->value1 != "files")
  70. return CHECK_OK;
  71. config_check_t check2;
  72. check2.hosted = check->hosted;
  73. check2.multi = check->multi;
  74. check2.option1 = check->option2;
  75. check2.value1 = check->value2;
  76. return testDirectory(&check2);
  77. }
  78. int ServerConfigCheck::testPlugin(const config_check_t *check)
  79. {
  80. if (check->value1.empty()) {
  81. printWarning(check->option1, "Plugin not set, defaulting to 'db' plugin");
  82. return CHECK_OK;
  83. }
  84. if (check->hosted && check->value1 == "unix") {
  85. printError(check->option1, "Unix plugin does not support multi-tenancy");
  86. return CHECK_ERROR;
  87. }
  88. if (check->multi && check->value1 != "ldapms") {
  89. printError(check->option1, check->value1 + " plugin does not support multiserver");
  90. return CHECK_ERROR;
  91. }
  92. if (check->multi && check->value1 == "ldap") {
  93. printError(check->option1, "Unix plugin does not support multiserver");
  94. return CHECK_ERROR;
  95. }
  96. if (check->value1 == "ldap" || check->value1 == "ldapms" || check->value1 == "unix" || check->value1 == "db")
  97. return CHECK_OK;
  98. printError(check->option1, "contains unknown plugin: \"" + check->value1 + "\"");
  99. return CHECK_ERROR;
  100. }
  101. int ServerConfigCheck::testPluginConfig(const config_check_t *check)
  102. {
  103. if (check->value1 != "ldap" && check->value1 != "unix")
  104. return CHECK_OK;
  105. config_check_t check2;
  106. check2.hosted = check->hosted;
  107. check2.option1 = check->option2;
  108. check2.value1 = check->value2;
  109. return testFile(&check2);
  110. }
  111. int ServerConfigCheck::testPluginPath(const config_check_t *check)
  112. {
  113. if (check->value1 != "ldap" && check->value1 != "unix")
  114. return CHECK_OK;
  115. config_check_t check2;
  116. check2.hosted = check->hosted;
  117. check2.option1 = check->option2;
  118. check2.value1 = check->value2;
  119. return testDirectory(&check2);
  120. }
  121. int ServerConfigCheck::testStorename(const config_check_t *check)
  122. {
  123. if (!check->hosted) {
  124. if (check->value1.find("%c") != std::string::npos) {
  125. printError(check->option1, "multi-tenancy disabled, but value contains %c: " + check->value1);
  126. return CHECK_ERROR;
  127. }
  128. }
  129. return CHECK_OK;
  130. }
  131. int ServerConfigCheck::testLoginname(const config_check_t *check)
  132. {
  133. /* LDAP has no rules for loginname */
  134. if (check->value1 == "ldap")
  135. return CHECK_OK;
  136. if (check->value1 == "unix") {
  137. if (check->value2.find("%c") != std::string::npos) {
  138. printError(check->option2, "contains %c but this is not supported by Unix plugin");
  139. return CHECK_ERROR;
  140. }
  141. return CHECK_OK;
  142. }
  143. /* DB plugin, must have %c in loginname format when hosted is enabled */
  144. if (check->hosted) {
  145. if (check->value2.find("%c") == std::string::npos) {
  146. printError(check->option2, "multi-tenancy enabled, but value does not contain %c: \"" + check->value2 + "\"");
  147. return CHECK_ERROR;
  148. }
  149. } else if (check->value2.find("%c") != std::string::npos) {
  150. printError(check->option2, "multi-tenancy disabled, but value contains %c: \"" + check->value2 + "\"");
  151. return CHECK_ERROR;
  152. }
  153. return CHECK_OK;
  154. }
  155. int ServerConfigCheck::testAuthMethod(const config_check_t *check)
  156. {
  157. if (check->value1.empty() || check->value1 == "plugin" || check->value1 == "pam" || check->value1 == "kerberos")
  158. return CHECK_OK;
  159. printError(check->option1, "must be one of 'plugin', 'pam' or 'kerberos': " + check->value1);
  160. return CHECK_ERROR;
  161. }