posix-winsync-config.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286
  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
  26. * used 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
  29. * to provide this exception without modification, you must delete this
  30. * exception statement from your version and license this file solely under the
  31. * GPL without exception.
  32. *
  33. * END COPYRIGHT BLOCK **/
  34. /*
  35. $Id: posix-winsync-config.c 42 2011-06-10 08:39:50Z grzemba $
  36. $HeadURL: file:///storejet/svn/posix-winsync-plugin/trunk/posix-winsync-config.c $
  37. */
  38. #ifdef WINSYNC_TEST_POSIX
  39. #include <slapi-plugin.h>
  40. #include "winsync-plugin.h"
  41. #else
  42. #include <dirsrv/slapi-plugin.h>
  43. #include <dirsrv/winsync-plugin.h>
  44. #endif
  45. #include "posix-wsp-ident.h"
  46. #include <string.h>
  47. #include "posix-group-func.h"
  48. #define POSIX_WINSYNC_CONFIG_FILTER "(objectclass=*)"
  49. /*
  50. * static variables
  51. */
  52. /* for now, there is only one configuration and it is global to the plugin */
  53. static POSIX_WinSync_Config theConfig;
  54. static int inited = 0;
  55. /* This is called when a new agreement is created or loaded
  56. at startup.
  57. */
  58. void *
  59. posix_winsync_agmt_init(const Slapi_DN *ds_subtree, const Slapi_DN *ad_subtree)
  60. {
  61. void *cbdata = NULL;
  62. void *node = NULL;
  63. Slapi_DN *sdn = NULL;
  64. slapi_log_error(SLAPI_LOG_PLUGIN, POSIX_WINSYNC_PLUGIN_NAME,
  65. "--> posix_winsync_agmt_init [%s] [%s] -- begin\n",
  66. slapi_sdn_get_dn(ds_subtree), slapi_sdn_get_dn(ad_subtree));
  67. sdn = slapi_get_first_suffix(&node, 0);
  68. while (sdn) {
  69. if (slapi_sdn_isparent(sdn, ds_subtree) == 0) {
  70. theConfig.rep_suffix = sdn;
  71. slapi_log_error(SLAPI_LOG_PLUGIN, POSIX_WINSYNC_PLUGIN_NAME, "Found suffix's '%s'\n",
  72. slapi_sdn_get_dn(sdn));
  73. break;
  74. }
  75. sdn = slapi_get_next_suffix(&node, 0);
  76. }
  77. if (!sdn) {
  78. char *pardn = slapi_dn_parent(slapi_sdn_get_dn(ds_subtree));
  79. slapi_log_error(SLAPI_LOG_FATAL, POSIX_WINSYNC_PLUGIN_NAME, "suffix not found for '%s'\n",
  80. pardn);
  81. slapi_ch_free_string(&pardn);
  82. }
  83. slapi_log_error(SLAPI_LOG_PLUGIN, POSIX_WINSYNC_PLUGIN_NAME,
  84. "<-- posix_winsync_agmt_init -- end\n");
  85. return cbdata;
  86. }
  87. static int
  88. posix_winsync_apply_config(Slapi_PBlock *pb, Slapi_Entry* entryBefore, Slapi_Entry* e,
  89. int *returncode, char *returntext, void *arg);
  90. POSIX_WinSync_Config *
  91. posix_winsync_get_config()
  92. {
  93. return &theConfig;
  94. }
  95. PRBool
  96. posix_winsync_config_get_mapMemberUid()
  97. {
  98. return theConfig.mapMemberUID;
  99. }
  100. PRBool
  101. posix_winsync_config_get_lowercase()
  102. {
  103. return theConfig.lowercase;
  104. }
  105. PRBool
  106. posix_winsync_config_get_createMOFTask()
  107. {
  108. return theConfig.createMemberOfTask;
  109. }
  110. void
  111. posix_winsync_config_set_MOFTaskCreated()
  112. {
  113. theConfig.MOFTaskCreated = PR_TRUE;
  114. }
  115. void
  116. posix_winsync_config_reset_MOFTaskCreated()
  117. {
  118. theConfig.MOFTaskCreated = PR_FALSE;
  119. }
  120. PRBool
  121. posix_winsync_config_get_MOFTaskCreated()
  122. {
  123. return theConfig.MOFTaskCreated;
  124. }
  125. PRBool
  126. posix_winsync_config_get_msSFUSchema()
  127. {
  128. return theConfig.mssfuSchema;
  129. }
  130. Slapi_DN *
  131. posix_winsync_config_get_suffix()
  132. {
  133. return theConfig.rep_suffix;
  134. }
  135. /*
  136. * Read configuration and create a configuration data structure.
  137. * This is called after the server has configured itself so we can check
  138. * schema and whatnot.
  139. * Returns an LDAP error code (LDAP_SUCCESS if all goes well).
  140. */
  141. int
  142. posix_winsync_config(Slapi_Entry *config_e)
  143. {
  144. int returncode = LDAP_SUCCESS;
  145. char returntext[SLAPI_DSE_RETURNTEXT_SIZE];
  146. slapi_log_error(SLAPI_LOG_PLUGIN, POSIX_WINSYNC_PLUGIN_NAME, "--> _config %s -- begin\n",
  147. slapi_entry_get_dn_const(config_e));
  148. if (inited) {
  149. slapi_log_error(SLAPI_LOG_FATAL, POSIX_WINSYNC_PLUGIN_NAME,
  150. "Error: POSIX WinSync plug-in already configured. "
  151. "Please remove the plugin config entry [%s]\n",
  152. slapi_entry_get_dn_const(config_e));
  153. return (LDAP_PARAM_ERROR);
  154. }
  155. /* initialize fields */
  156. if ((theConfig.lock = slapi_new_mutex()) == NULL) {
  157. return (LDAP_LOCAL_ERROR);
  158. }
  159. /* init defaults */
  160. theConfig.config_e = slapi_entry_alloc();
  161. slapi_entry_init(theConfig.config_e, slapi_ch_strdup(""), NULL);
  162. theConfig.mssfuSchema = PR_FALSE;
  163. theConfig.mapMemberUID = PR_TRUE;
  164. theConfig.lowercase = PR_FALSE;
  165. theConfig.createMemberOfTask = PR_FALSE;
  166. theConfig.MOFTaskCreated = PR_FALSE;
  167. posix_winsync_apply_config(NULL, NULL, config_e, &returncode, returntext, NULL);
  168. /* config DSE must be initialized before we get here */
  169. {
  170. int rc = 0;
  171. const char *config_dn = slapi_entry_get_dn_const(config_e);
  172. if (!memberUidLockInit()) {
  173. slapi_log_error(SLAPI_LOG_PLUGIN, POSIX_WINSYNC_PLUGIN_NAME,
  174. "posix_winsync_config -- init Monitor failed\n");
  175. }
  176. slapi_config_register_callback(SLAPI_OPERATION_MODIFY, DSE_FLAG_POSTOP, config_dn,
  177. LDAP_SCOPE_BASE, POSIX_WINSYNC_CONFIG_FILTER,
  178. posix_winsync_apply_config, NULL);
  179. rc = slapi_task_register_handler("memberuid task", posix_group_task_add);
  180. if (rc) {
  181. slapi_log_error(SLAPI_LOG_PLUGIN, POSIX_WINSYNC_PLUGIN_NAME,
  182. "posix_winsync_config -- register memberuid task failed\n");
  183. }
  184. }
  185. inited = 1;
  186. if (returncode != LDAP_SUCCESS) {
  187. slapi_log_error(SLAPI_LOG_FATAL, POSIX_WINSYNC_PLUGIN_NAME, "Error %d: %s\n", returncode,
  188. returntext);
  189. }
  190. return returncode;
  191. }
  192. static int
  193. posix_winsync_apply_config(Slapi_PBlock *pb, Slapi_Entry* entryBefore, Slapi_Entry* e,
  194. int *returncode, char *returntext, void *arg)
  195. {
  196. PRBool mssfuSchema = PR_FALSE;
  197. PRBool mapMemberUID = PR_TRUE;
  198. PRBool createMemberOfTask = PR_FALSE;
  199. PRBool lowercase = PR_FALSE;
  200. Slapi_Attr *testattr = NULL;
  201. *returncode = LDAP_UNWILLING_TO_PERFORM; /* be pessimistic */
  202. /* get msfuSchema value */
  203. if (!slapi_entry_attr_find(e, POSIX_WINSYNC_MSSFU_SCHEMA, &testattr) && (NULL != testattr)) {
  204. mssfuSchema = slapi_entry_attr_get_bool(e, POSIX_WINSYNC_MSSFU_SCHEMA);
  205. slapi_log_error(SLAPI_LOG_PLUGIN, POSIX_WINSYNC_PLUGIN_NAME,
  206. "_apply_config: Config paramter %s: %d\n", POSIX_WINSYNC_MSSFU_SCHEMA,
  207. mssfuSchema);
  208. }
  209. /* get memberUid value */
  210. if (!slapi_entry_attr_find(e, POSIX_WINSYNC_MAP_MEMBERUID, &testattr) && (NULL != testattr)) {
  211. mapMemberUID = slapi_entry_attr_get_bool(e, POSIX_WINSYNC_MAP_MEMBERUID);
  212. slapi_log_error(SLAPI_LOG_PLUGIN, POSIX_WINSYNC_PLUGIN_NAME,
  213. "_apply_config: Config paramter %s: %d\n", POSIX_WINSYNC_MAP_MEMBERUID,
  214. mapMemberUID);
  215. }
  216. /* get create task value */
  217. if (!slapi_entry_attr_find(e, POSIX_WINSYNC_CREATE_MEMBEROFTASK, &testattr) && (NULL
  218. != testattr)) {
  219. createMemberOfTask = slapi_entry_attr_get_bool(e, POSIX_WINSYNC_CREATE_MEMBEROFTASK);
  220. slapi_log_error(SLAPI_LOG_PLUGIN, POSIX_WINSYNC_PLUGIN_NAME,
  221. "_apply_config: Config paramter %s: %d\n",
  222. POSIX_WINSYNC_CREATE_MEMBEROFTASK, createMemberOfTask);
  223. }
  224. /* get lower case UID in memberUID */
  225. if (!slapi_entry_attr_find(e, POSIX_WINSYNC_LOWER_CASE, &testattr) && (NULL != testattr)) {
  226. lowercase = slapi_entry_attr_get_bool(e, POSIX_WINSYNC_LOWER_CASE);
  227. slapi_log_error(SLAPI_LOG_PLUGIN, POSIX_WINSYNC_PLUGIN_NAME,
  228. "_apply_config: Config paramter %s: %d\n", POSIX_WINSYNC_LOWER_CASE,
  229. lowercase);
  230. }
  231. /* if we got here, we have valid values for everything
  232. set the config entry */
  233. slapi_lock_mutex(theConfig.lock);
  234. slapi_entry_free(theConfig.config_e);
  235. theConfig.config_e = slapi_entry_alloc();
  236. slapi_entry_init(theConfig.config_e, slapi_ch_strdup(""), NULL);
  237. /* all of the attrs and vals have been set - set the other values */
  238. theConfig.mssfuSchema = mssfuSchema;
  239. theConfig.mapMemberUID = mapMemberUID;
  240. theConfig.createMemberOfTask = createMemberOfTask;
  241. theConfig.lowercase = lowercase;
  242. /* success */
  243. slapi_log_error(SLAPI_LOG_PLUGIN, POSIX_WINSYNC_PLUGIN_NAME,
  244. "<-- _apply_config: config evaluated\n");
  245. *returncode = LDAP_SUCCESS;
  246. slapi_unlock_mutex(theConfig.lock);
  247. if (*returncode != LDAP_SUCCESS) {
  248. return SLAPI_DSE_CALLBACK_ERROR;
  249. } else {
  250. return SLAPI_DSE_CALLBACK_OK;
  251. }
  252. }