posix-winsync-config.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  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. PRBool
  131. posix_winsync_config_get_mapNestedGrouping()
  132. {
  133. return theConfig.mapNestedGrouping;
  134. }
  135. Slapi_DN *
  136. posix_winsync_config_get_suffix()
  137. {
  138. return theConfig.rep_suffix;
  139. }
  140. /*
  141. * Read configuration and create a configuration data structure.
  142. * This is called after the server has configured itself so we can check
  143. * schema and whatnot.
  144. * Returns an LDAP error code (LDAP_SUCCESS if all goes well).
  145. */
  146. int
  147. posix_winsync_config(Slapi_Entry *config_e)
  148. {
  149. int returncode = LDAP_SUCCESS;
  150. char returntext[SLAPI_DSE_RETURNTEXT_SIZE];
  151. slapi_log_error(SLAPI_LOG_PLUGIN, POSIX_WINSYNC_PLUGIN_NAME, "--> _config %s -- begin\n",
  152. slapi_entry_get_dn_const(config_e));
  153. if (inited) {
  154. slapi_log_error(SLAPI_LOG_FATAL, POSIX_WINSYNC_PLUGIN_NAME,
  155. "Error: POSIX WinSync plug-in already configured. "
  156. "Please remove the plugin config entry [%s]\n",
  157. slapi_entry_get_dn_const(config_e));
  158. return (LDAP_PARAM_ERROR);
  159. }
  160. /* initialize fields */
  161. if ((theConfig.lock = slapi_new_mutex()) == NULL) {
  162. return (LDAP_LOCAL_ERROR);
  163. }
  164. /* init defaults */
  165. theConfig.config_e = slapi_entry_alloc();
  166. slapi_entry_init(theConfig.config_e, slapi_ch_strdup(""), NULL);
  167. theConfig.mssfuSchema = PR_FALSE;
  168. theConfig.mapMemberUID = PR_TRUE;
  169. theConfig.lowercase = PR_FALSE;
  170. theConfig.createMemberOfTask = PR_FALSE;
  171. theConfig.MOFTaskCreated = PR_FALSE;
  172. theConfig.mapNestedGrouping = PR_FALSE;
  173. posix_winsync_apply_config(NULL, NULL, config_e, &returncode, returntext, NULL);
  174. /* config DSE must be initialized before we get here */
  175. {
  176. int rc = 0;
  177. const char *config_dn = slapi_entry_get_dn_const(config_e);
  178. if (!memberUidLockInit()) {
  179. slapi_log_error(SLAPI_LOG_PLUGIN, POSIX_WINSYNC_PLUGIN_NAME,
  180. "posix_winsync_config -- init Monitor failed\n");
  181. }
  182. slapi_config_register_callback(SLAPI_OPERATION_MODIFY, DSE_FLAG_POSTOP, config_dn,
  183. LDAP_SCOPE_BASE, POSIX_WINSYNC_CONFIG_FILTER,
  184. posix_winsync_apply_config, NULL);
  185. rc = slapi_task_register_handler("memberuid task", posix_group_task_add);
  186. if (rc) {
  187. slapi_log_error(SLAPI_LOG_PLUGIN, POSIX_WINSYNC_PLUGIN_NAME,
  188. "posix_winsync_config -- register memberuid task failed\n");
  189. }
  190. }
  191. inited = 1;
  192. if (returncode != LDAP_SUCCESS) {
  193. slapi_log_error(SLAPI_LOG_FATAL, POSIX_WINSYNC_PLUGIN_NAME, "Error %d: %s\n", returncode,
  194. returntext);
  195. }
  196. return returncode;
  197. }
  198. static int
  199. posix_winsync_apply_config(Slapi_PBlock *pb, Slapi_Entry* entryBefore, Slapi_Entry* e,
  200. int *returncode, char *returntext, void *arg)
  201. {
  202. PRBool mssfuSchema = PR_FALSE;
  203. PRBool mapMemberUID = PR_TRUE;
  204. PRBool createMemberOfTask = PR_FALSE;
  205. PRBool lowercase = PR_FALSE;
  206. Slapi_Attr *testattr = NULL;
  207. PRBool mapNestedGrouping = PR_FALSE;
  208. *returncode = LDAP_UNWILLING_TO_PERFORM; /* be pessimistic */
  209. /* get msfuSchema value */
  210. if (!slapi_entry_attr_find(e, POSIX_WINSYNC_MSSFU_SCHEMA, &testattr) && (NULL != testattr)) {
  211. mssfuSchema = slapi_entry_attr_get_bool(e, POSIX_WINSYNC_MSSFU_SCHEMA);
  212. slapi_log_error(SLAPI_LOG_PLUGIN, POSIX_WINSYNC_PLUGIN_NAME,
  213. "_apply_config: Config paramter %s: %d\n", POSIX_WINSYNC_MSSFU_SCHEMA,
  214. mssfuSchema);
  215. }
  216. /* get memberUid value */
  217. if (!slapi_entry_attr_find(e, POSIX_WINSYNC_MAP_MEMBERUID, &testattr) && (NULL != testattr)) {
  218. mapMemberUID = slapi_entry_attr_get_bool(e, POSIX_WINSYNC_MAP_MEMBERUID);
  219. slapi_log_error(SLAPI_LOG_PLUGIN, POSIX_WINSYNC_PLUGIN_NAME,
  220. "_apply_config: Config paramter %s: %d\n", POSIX_WINSYNC_MAP_MEMBERUID,
  221. mapMemberUID);
  222. }
  223. /* get create task value */
  224. if (!slapi_entry_attr_find(e, POSIX_WINSYNC_CREATE_MEMBEROFTASK, &testattr) && (NULL
  225. != testattr)) {
  226. createMemberOfTask = slapi_entry_attr_get_bool(e, POSIX_WINSYNC_CREATE_MEMBEROFTASK);
  227. slapi_log_error(SLAPI_LOG_PLUGIN, POSIX_WINSYNC_PLUGIN_NAME,
  228. "_apply_config: Config paramter %s: %d\n",
  229. POSIX_WINSYNC_CREATE_MEMBEROFTASK, createMemberOfTask);
  230. }
  231. /* get lower case UID in memberUID */
  232. if (!slapi_entry_attr_find(e, POSIX_WINSYNC_LOWER_CASE, &testattr) && (NULL != testattr)) {
  233. lowercase = slapi_entry_attr_get_bool(e, POSIX_WINSYNC_LOWER_CASE);
  234. slapi_log_error(SLAPI_LOG_PLUGIN, POSIX_WINSYNC_PLUGIN_NAME,
  235. "_apply_config: Config paramter %s: %d\n", POSIX_WINSYNC_LOWER_CASE,
  236. lowercase);
  237. }
  238. /* propogate memberuids in nested grouping */
  239. if (!slapi_entry_attr_find(e, POSIX_WINSYNC_MAP_NESTED_GROUPING, &testattr) && (NULL != testattr)) {
  240. mapNestedGrouping = slapi_entry_attr_get_bool(e, POSIX_WINSYNC_MAP_NESTED_GROUPING);
  241. slapi_log_error(SLAPI_LOG_PLUGIN, POSIX_WINSYNC_PLUGIN_NAME,
  242. "_apply_config: Config paramter %s: %d\n", POSIX_WINSYNC_MAP_NESTED_GROUPING,
  243. mapNestedGrouping);
  244. }
  245. /* if we got here, we have valid values for everything
  246. set the config entry */
  247. slapi_lock_mutex(theConfig.lock);
  248. slapi_entry_free(theConfig.config_e);
  249. theConfig.config_e = slapi_entry_alloc();
  250. slapi_entry_init(theConfig.config_e, slapi_ch_strdup(""), NULL);
  251. /* all of the attrs and vals have been set - set the other values */
  252. theConfig.mssfuSchema = mssfuSchema;
  253. theConfig.mapMemberUID = mapMemberUID;
  254. theConfig.createMemberOfTask = createMemberOfTask;
  255. theConfig.lowercase = lowercase;
  256. theConfig.mapNestedGrouping = mapNestedGrouping;
  257. /* success */
  258. slapi_log_error(SLAPI_LOG_PLUGIN, POSIX_WINSYNC_PLUGIN_NAME,
  259. "<-- _apply_config: config evaluated\n");
  260. *returncode = LDAP_SUCCESS;
  261. slapi_unlock_mutex(theConfig.lock);
  262. if (*returncode != LDAP_SUCCESS) {
  263. return SLAPI_DSE_CALLBACK_ERROR;
  264. } else {
  265. return SLAPI_DSE_CALLBACK_OK;
  266. }
  267. }