posix-winsync-config.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284
  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. slapi_log_error(SLAPI_LOG_FATAL, POSIX_WINSYNC_PLUGIN_NAME, "suffix not found for '%s'\n",
  79. slapi_dn_parent(slapi_sdn_get_dn(ds_subtree)));
  80. }
  81. slapi_log_error(SLAPI_LOG_PLUGIN, POSIX_WINSYNC_PLUGIN_NAME,
  82. "<-- posix_winsync_agmt_init -- end\n");
  83. return cbdata;
  84. }
  85. static int
  86. posix_winsync_apply_config(Slapi_PBlock *pb, Slapi_Entry* entryBefore, Slapi_Entry* e,
  87. int *returncode, char *returntext, void *arg);
  88. POSIX_WinSync_Config *
  89. posix_winsync_get_config()
  90. {
  91. return &theConfig;
  92. }
  93. PRBool
  94. posix_winsync_config_get_mapMemberUid()
  95. {
  96. return theConfig.mapMemberUID;
  97. }
  98. PRBool
  99. posix_winsync_config_get_lowercase()
  100. {
  101. return theConfig.lowercase;
  102. }
  103. PRBool
  104. posix_winsync_config_get_createMOFTask()
  105. {
  106. return theConfig.createMemberOfTask;
  107. }
  108. void
  109. posix_winsync_config_set_MOFTaskCreated()
  110. {
  111. theConfig.MOFTaskCreated = PR_TRUE;
  112. }
  113. void
  114. posix_winsync_config_reset_MOFTaskCreated()
  115. {
  116. theConfig.MOFTaskCreated = PR_FALSE;
  117. }
  118. PRBool
  119. posix_winsync_config_get_MOFTaskCreated()
  120. {
  121. return theConfig.MOFTaskCreated;
  122. }
  123. PRBool
  124. posix_winsync_config_get_msSFUSchema()
  125. {
  126. return theConfig.mssfuSchema;
  127. }
  128. Slapi_DN *
  129. posix_winsync_config_get_suffix()
  130. {
  131. return theConfig.rep_suffix;
  132. }
  133. /*
  134. * Read configuration and create a configuration data structure.
  135. * This is called after the server has configured itself so we can check
  136. * schema and whatnot.
  137. * Returns an LDAP error code (LDAP_SUCCESS if all goes well).
  138. */
  139. int
  140. posix_winsync_config(Slapi_Entry *config_e)
  141. {
  142. int returncode = LDAP_SUCCESS;
  143. char returntext[SLAPI_DSE_RETURNTEXT_SIZE];
  144. slapi_log_error(SLAPI_LOG_PLUGIN, POSIX_WINSYNC_PLUGIN_NAME, "--> _config %s -- begin\n",
  145. slapi_entry_get_dn_const(config_e));
  146. if (inited) {
  147. slapi_log_error(SLAPI_LOG_FATAL, POSIX_WINSYNC_PLUGIN_NAME,
  148. "Error: POSIX WinSync plug-in already configured. "
  149. "Please remove the plugin config entry [%s]\n",
  150. slapi_entry_get_dn_const(config_e));
  151. return (LDAP_PARAM_ERROR);
  152. }
  153. /* initialize fields */
  154. if ((theConfig.lock = slapi_new_mutex()) == NULL) {
  155. return (LDAP_LOCAL_ERROR);
  156. }
  157. /* init defaults */
  158. theConfig.config_e = slapi_entry_alloc();
  159. slapi_entry_init(theConfig.config_e, slapi_ch_strdup(""), NULL);
  160. theConfig.mssfuSchema = PR_FALSE;
  161. theConfig.mapMemberUID = PR_TRUE;
  162. theConfig.lowercase = PR_FALSE;
  163. theConfig.createMemberOfTask = PR_FALSE;
  164. theConfig.MOFTaskCreated = PR_FALSE;
  165. posix_winsync_apply_config(NULL, NULL, config_e, &returncode, returntext, NULL);
  166. /* config DSE must be initialized before we get here */
  167. {
  168. int rc = 0;
  169. const char *config_dn = slapi_entry_get_dn_const(config_e);
  170. if (!memberUidLockInit()) {
  171. slapi_log_error(SLAPI_LOG_PLUGIN, POSIX_WINSYNC_PLUGIN_NAME,
  172. "posix_winsync_config -- init Monitor failed\n");
  173. }
  174. slapi_config_register_callback(SLAPI_OPERATION_MODIFY, DSE_FLAG_POSTOP, config_dn,
  175. LDAP_SCOPE_BASE, POSIX_WINSYNC_CONFIG_FILTER,
  176. posix_winsync_apply_config, NULL);
  177. rc = slapi_task_register_handler("memberuid task", posix_group_task_add);
  178. if (rc) {
  179. slapi_log_error(SLAPI_LOG_PLUGIN, POSIX_WINSYNC_PLUGIN_NAME,
  180. "posix_winsync_config -- register memberuid task failed\n");
  181. }
  182. }
  183. inited = 1;
  184. if (returncode != LDAP_SUCCESS) {
  185. slapi_log_error(SLAPI_LOG_FATAL, POSIX_WINSYNC_PLUGIN_NAME, "Error %d: %s\n", returncode,
  186. returntext);
  187. }
  188. return returncode;
  189. }
  190. static int
  191. posix_winsync_apply_config(Slapi_PBlock *pb, Slapi_Entry* entryBefore, Slapi_Entry* e,
  192. int *returncode, char *returntext, void *arg)
  193. {
  194. PRBool mssfuSchema = PR_FALSE;
  195. PRBool mapMemberUID = PR_TRUE;
  196. PRBool createMemberOfTask = PR_FALSE;
  197. PRBool lowercase = PR_FALSE;
  198. Slapi_Attr *testattr = NULL;
  199. *returncode = LDAP_UNWILLING_TO_PERFORM; /* be pessimistic */
  200. /* get msfuSchema value */
  201. if (!slapi_entry_attr_find(e, POSIX_WINSYNC_MSSFU_SCHEMA, &testattr) && (NULL != testattr)) {
  202. mssfuSchema = slapi_entry_attr_get_bool(e, POSIX_WINSYNC_MSSFU_SCHEMA);
  203. slapi_log_error(SLAPI_LOG_PLUGIN, POSIX_WINSYNC_PLUGIN_NAME,
  204. "_apply_config: Config paramter %s: %d\n", POSIX_WINSYNC_MSSFU_SCHEMA,
  205. mssfuSchema);
  206. }
  207. /* get memberUid value */
  208. if (!slapi_entry_attr_find(e, POSIX_WINSYNC_MAP_MEMBERUID, &testattr) && (NULL != testattr)) {
  209. mapMemberUID = slapi_entry_attr_get_bool(e, POSIX_WINSYNC_MAP_MEMBERUID);
  210. slapi_log_error(SLAPI_LOG_PLUGIN, POSIX_WINSYNC_PLUGIN_NAME,
  211. "_apply_config: Config paramter %s: %d\n", POSIX_WINSYNC_MAP_MEMBERUID,
  212. mapMemberUID);
  213. }
  214. /* get create task value */
  215. if (!slapi_entry_attr_find(e, POSIX_WINSYNC_CREATE_MEMBEROFTASK, &testattr) && (NULL
  216. != testattr)) {
  217. createMemberOfTask = slapi_entry_attr_get_bool(e, POSIX_WINSYNC_CREATE_MEMBEROFTASK);
  218. slapi_log_error(SLAPI_LOG_PLUGIN, POSIX_WINSYNC_PLUGIN_NAME,
  219. "_apply_config: Config paramter %s: %d\n",
  220. POSIX_WINSYNC_CREATE_MEMBEROFTASK, createMemberOfTask);
  221. }
  222. /* get lower case UID in memberUID */
  223. if (!slapi_entry_attr_find(e, POSIX_WINSYNC_LOWER_CASE, &testattr) && (NULL != testattr)) {
  224. lowercase = slapi_entry_attr_get_bool(e, POSIX_WINSYNC_LOWER_CASE);
  225. slapi_log_error(SLAPI_LOG_PLUGIN, POSIX_WINSYNC_PLUGIN_NAME,
  226. "_apply_config: Config paramter %s: %d\n", POSIX_WINSYNC_LOWER_CASE,
  227. lowercase);
  228. }
  229. /* if we got here, we have valid values for everything
  230. set the config entry */
  231. slapi_lock_mutex(theConfig.lock);
  232. slapi_entry_free(theConfig.config_e);
  233. theConfig.config_e = slapi_entry_alloc();
  234. slapi_entry_init(theConfig.config_e, slapi_ch_strdup(""), NULL);
  235. /* all of the attrs and vals have been set - set the other values */
  236. theConfig.mssfuSchema = mssfuSchema;
  237. theConfig.mapMemberUID = mapMemberUID;
  238. theConfig.createMemberOfTask = createMemberOfTask;
  239. theConfig.lowercase = lowercase;
  240. /* success */
  241. slapi_log_error(SLAPI_LOG_PLUGIN, POSIX_WINSYNC_PLUGIN_NAME,
  242. "<-- _apply_config: config evaluated\n");
  243. *returncode = LDAP_SUCCESS;
  244. slapi_unlock_mutex(theConfig.lock);
  245. if (*returncode != LDAP_SUCCESS) {
  246. return SLAPI_DSE_CALLBACK_ERROR;
  247. } else {
  248. return SLAPI_DSE_CALLBACK_OK;
  249. }
  250. }