windows_private.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645
  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. /* windows_private.c */
  39. #include "repl.h"
  40. #include "repl5.h"
  41. #include "slap.h"
  42. #include "slapi-plugin.h"
  43. #include "windowsrepl.h"
  44. struct windowsprivate {
  45. Slapi_DN *windows_subtree; /* DN of synchronized subtree (on the windows side) */
  46. Slapi_DN *directory_subtree; /* DN of synchronized subtree on directory side */
  47. /* this simplifies the mapping as it's simply
  48. from the former to the latter container, or
  49. vice versa */
  50. int dirsync_flags;
  51. int dirsync_maxattributecount;
  52. char *dirsync_cookie;
  53. int dirsync_cookie_len;
  54. PRBool dirsync_cookie_has_more;
  55. PRBool create_users_from_dirsync;
  56. PRBool create_groups_from_dirsync;
  57. char *windows_domain;
  58. int isnt4;
  59. };
  60. static int
  61. true_value_from_string(char *val)
  62. {
  63. if (strcasecmp (val, "on") == 0 || strcasecmp (val, "yes") == 0 ||
  64. strcasecmp (val, "true") == 0 || strcasecmp (val, "1") == 0)
  65. {
  66. return 1;
  67. } else
  68. {
  69. return 0;
  70. }
  71. }
  72. void
  73. windows_init_agreement_from_entry(Repl_Agmt *ra, Slapi_Entry *e)
  74. {
  75. char *tmpstr = NULL;
  76. agmt_set_priv(ra,windows_private_new());
  77. /* DN of entry at root of replicated area */
  78. tmpstr = slapi_entry_attr_get_charptr(e, type_nsds7WindowsReplicaArea);
  79. if (NULL != tmpstr)
  80. {
  81. windows_private_set_windows_subtree(ra, slapi_sdn_new_dn_passin(tmpstr) );
  82. }
  83. tmpstr = slapi_entry_attr_get_charptr(e, type_nsds7DirectoryReplicaArea);
  84. if (NULL != tmpstr)
  85. {
  86. windows_private_set_directory_subtree(ra, slapi_sdn_new_dn_passin(tmpstr) );
  87. }
  88. tmpstr = slapi_entry_attr_get_charptr(e, type_nsds7CreateNewUsers);
  89. if (NULL != tmpstr && true_value_from_string(tmpstr))
  90. {
  91. windows_private_set_create_users(ra, PR_TRUE);
  92. slapi_ch_free((void**)&tmpstr);
  93. }
  94. else
  95. {
  96. windows_private_set_create_users(ra, PR_FALSE);
  97. }
  98. tmpstr = slapi_entry_attr_get_charptr(e, type_nsds7CreateNewGroups);
  99. if (NULL != tmpstr && true_value_from_string(tmpstr))
  100. {
  101. windows_private_set_create_groups(ra, PR_TRUE);
  102. slapi_ch_free((void**)&tmpstr);
  103. }
  104. else
  105. {
  106. windows_private_set_create_groups(ra, PR_FALSE);
  107. }
  108. tmpstr = slapi_entry_attr_get_charptr(e, type_nsds7WindowsDomain);
  109. if (NULL != tmpstr)
  110. {
  111. windows_private_set_windows_domain(ra,tmpstr);
  112. }
  113. }
  114. const char* windows_private_get_purl(const Repl_Agmt *ra)
  115. {
  116. const char* windows_purl;
  117. char *hostname;
  118. hostname = agmt_get_hostname(ra);
  119. windows_purl = slapi_ch_smprintf("ldap://%s:%d", hostname, agmt_get_port(ra));
  120. slapi_ch_free_string(&hostname);
  121. return windows_purl;
  122. }
  123. Dirsync_Private* windows_private_new()
  124. {
  125. Dirsync_Private *dp;
  126. LDAPDebug( LDAP_DEBUG_TRACE, "=> windows_private_new\n", 0, 0, 0 );
  127. dp = (Dirsync_Private *)slapi_ch_calloc(sizeof(Dirsync_Private),1);
  128. dp->dirsync_maxattributecount = -1;
  129. LDAPDebug( LDAP_DEBUG_TRACE, "<= windows_private_new\n", 0, 0, 0 );
  130. return dp;
  131. }
  132. void windows_agreement_delete(Repl_Agmt *ra)
  133. {
  134. Dirsync_Private *dp = (Dirsync_Private *) agmt_get_priv(ra);
  135. LDAPDebug( LDAP_DEBUG_TRACE, "=> windows_private_delete\n", 0, 0, 0 );
  136. PR_ASSERT(dp != NULL);
  137. /* DBDB: need to free payoad here */
  138. slapi_ch_free((void **)dp);
  139. LDAPDebug( LDAP_DEBUG_TRACE, "<= windows_private_delete\n", 0, 0, 0 );
  140. }
  141. int windows_private_get_isnt4(const Repl_Agmt *ra)
  142. {
  143. Dirsync_Private *dp;
  144. LDAPDebug( LDAP_DEBUG_TRACE, "=> windows_private_get_isnt4\n", 0, 0, 0 );
  145. PR_ASSERT(ra);
  146. dp = (Dirsync_Private *) agmt_get_priv(ra);
  147. PR_ASSERT (dp);
  148. LDAPDebug( LDAP_DEBUG_TRACE, "<= windows_private_get_isnt4\n", 0, 0, 0 );
  149. return dp->isnt4;
  150. }
  151. void windows_private_set_isnt4(const Repl_Agmt *ra, int isit)
  152. {
  153. Dirsync_Private *dp;
  154. LDAPDebug( LDAP_DEBUG_TRACE, "=> windows_private_set_isnt4\n", 0, 0, 0 );
  155. PR_ASSERT(ra);
  156. dp = (Dirsync_Private *) agmt_get_priv(ra);
  157. PR_ASSERT (dp);
  158. dp->isnt4 = isit;
  159. LDAPDebug( LDAP_DEBUG_TRACE, "<= windows_private_set_isnt4\n", 0, 0, 0 );
  160. }
  161. /* Returns a copy of the Slapi_DN pointer, no need to free it */
  162. const Slapi_DN* windows_private_get_windows_subtree (const Repl_Agmt *ra)
  163. {
  164. Dirsync_Private *dp;
  165. LDAPDebug( LDAP_DEBUG_TRACE, "=> windows_private_get_windows_subtree\n", 0, 0, 0 );
  166. PR_ASSERT(ra);
  167. dp = (Dirsync_Private *) agmt_get_priv(ra);
  168. PR_ASSERT (dp);
  169. LDAPDebug( LDAP_DEBUG_TRACE, "<= windows_private_get_windows_subtree\n", 0, 0, 0 );
  170. return dp->windows_subtree;
  171. }
  172. const char *
  173. windows_private_get_windows_domain(const Repl_Agmt *ra)
  174. {
  175. Dirsync_Private *dp;
  176. LDAPDebug( LDAP_DEBUG_TRACE, "=> windows_private_get_windows_domain\n", 0, 0, 0 );
  177. PR_ASSERT(ra);
  178. dp = (Dirsync_Private *) agmt_get_priv(ra);
  179. PR_ASSERT (dp);
  180. LDAPDebug( LDAP_DEBUG_TRACE, "<= windows_private_get_windows_domain\n", 0, 0, 0 );
  181. return dp->windows_domain;
  182. }
  183. static void
  184. windows_private_set_windows_domain(const Repl_Agmt *ra, char *domain)
  185. {
  186. Dirsync_Private *dp;
  187. LDAPDebug( LDAP_DEBUG_TRACE, "=> windows_private_set_windows_domain\n", 0, 0, 0 );
  188. PR_ASSERT(ra);
  189. dp = (Dirsync_Private *) agmt_get_priv(ra);
  190. PR_ASSERT (dp);
  191. dp->windows_domain = domain;
  192. LDAPDebug( LDAP_DEBUG_TRACE, "<= windows_private_set_windows_domain\n", 0, 0, 0 );
  193. }
  194. /* Returns a copy of the Slapi_DN pointer, no need to free it */
  195. const Slapi_DN* windows_private_get_directory_subtree (const Repl_Agmt *ra)
  196. {
  197. Dirsync_Private *dp;
  198. LDAPDebug( LDAP_DEBUG_TRACE, "=> windows_private_get_directory_replarea\n", 0, 0, 0 );
  199. PR_ASSERT(ra);
  200. dp = (Dirsync_Private *) agmt_get_priv(ra);
  201. PR_ASSERT (dp);
  202. LDAPDebug( LDAP_DEBUG_TRACE, "<= windows_private_get_directory_replarea\n", 0, 0, 0 );
  203. return dp->directory_subtree;
  204. }
  205. /* Takes a copy of the sdn passed in */
  206. void windows_private_set_windows_subtree (const Repl_Agmt *ra,const Slapi_DN* sdn )
  207. {
  208. Dirsync_Private *dp;
  209. LDAPDebug( LDAP_DEBUG_TRACE, "=> windows_private_set_windows_replarea\n", 0, 0, 0 );
  210. PR_ASSERT(ra);
  211. PR_ASSERT(sdn);
  212. dp = (Dirsync_Private *) agmt_get_priv(ra);
  213. PR_ASSERT (dp);
  214. dp->windows_subtree = slapi_sdn_dup(sdn);
  215. LDAPDebug( LDAP_DEBUG_TRACE, "<= windows_private_set_windows_replarea\n", 0, 0, 0 );
  216. }
  217. /* Takes a copy of the sdn passed in */
  218. void windows_private_set_directory_subtree (const Repl_Agmt *ra,const Slapi_DN* sdn )
  219. {
  220. Dirsync_Private *dp;
  221. LDAPDebug( LDAP_DEBUG_TRACE, "=> windows_private_set_directory_replarea\n", 0, 0, 0 );
  222. PR_ASSERT(ra);
  223. PR_ASSERT(sdn);
  224. dp = (Dirsync_Private *) agmt_get_priv(ra);
  225. PR_ASSERT (dp);
  226. dp->directory_subtree = slapi_sdn_dup(sdn);
  227. LDAPDebug( LDAP_DEBUG_TRACE, "<= windows_private_set_directory_replarea\n", 0, 0, 0 );
  228. }
  229. PRBool windows_private_create_users(const Repl_Agmt *ra)
  230. {
  231. Dirsync_Private *dp;
  232. LDAPDebug( LDAP_DEBUG_TRACE, "=> windows_private_create_users\n", 0, 0, 0 );
  233. PR_ASSERT(ra);
  234. dp = (Dirsync_Private *) agmt_get_priv(ra);
  235. PR_ASSERT (dp);
  236. LDAPDebug( LDAP_DEBUG_TRACE, "<= windows_private_create_users\n", 0, 0, 0 );
  237. return dp->create_users_from_dirsync;
  238. }
  239. void windows_private_set_create_users(const Repl_Agmt *ra, PRBool value)
  240. {
  241. Dirsync_Private *dp;
  242. LDAPDebug( LDAP_DEBUG_TRACE, "=> windows_private_set_create_users\n", 0, 0, 0 );
  243. PR_ASSERT(ra);
  244. dp = (Dirsync_Private *) agmt_get_priv(ra);
  245. PR_ASSERT (dp);
  246. dp->create_users_from_dirsync = value;
  247. LDAPDebug( LDAP_DEBUG_TRACE, "<= windows_private_set_create_users\n", 0, 0, 0 );
  248. }
  249. PRBool windows_private_create_groups(const Repl_Agmt *ra)
  250. {
  251. Dirsync_Private *dp;
  252. LDAPDebug( LDAP_DEBUG_TRACE, "=> windows_private_create_groups\n", 0, 0, 0 );
  253. PR_ASSERT(ra);
  254. dp = (Dirsync_Private *) agmt_get_priv(ra);
  255. PR_ASSERT (dp);
  256. LDAPDebug( LDAP_DEBUG_TRACE, "<= windows_private_create_groups\n", 0, 0, 0 );
  257. return dp->create_groups_from_dirsync;
  258. }
  259. void windows_private_set_create_groups(const Repl_Agmt *ra, PRBool value)
  260. {
  261. Dirsync_Private *dp;
  262. LDAPDebug( LDAP_DEBUG_TRACE, "=> windows_private_set_create_groups\n", 0, 0, 0 );
  263. PR_ASSERT(ra);
  264. dp = (Dirsync_Private *) agmt_get_priv(ra);
  265. PR_ASSERT (dp);
  266. dp->create_groups_from_dirsync = value;
  267. LDAPDebug( LDAP_DEBUG_TRACE, "<= windows_private_set_create_groups\n", 0, 0, 0 );
  268. }
  269. /*
  270. This function returns the current Dirsync_Private that's inside
  271. Repl_Agmt ra as a ldap control.
  272. */
  273. LDAPControl* windows_private_dirsync_control(const Repl_Agmt *ra)
  274. {
  275. LDAPControl *control = NULL;
  276. LDAPControl **lc = &control ;
  277. BerElement *ber;
  278. Dirsync_Private *dp;
  279. LDAPDebug( LDAP_DEBUG_TRACE, "=> windows_private_dirsync_control\n", 0, 0, 0 );
  280. PR_ASSERT(ra);
  281. dp = (Dirsync_Private *) agmt_get_priv(ra);
  282. PR_ASSERT (dp);
  283. ber = ber_alloc();
  284. ber_printf( ber, "{iio}", dp->dirsync_flags, dp->dirsync_maxattributecount, dp->dirsync_cookie, dp->dirsync_cookie_len );
  285. slapi_build_control( REPL_DIRSYNC_CONTROL_OID, ber, PR_TRUE, &control);
  286. ber_free(ber,1);
  287. LDAPDebug( LDAP_DEBUG_TRACE, "<= windows_private_dirsync_control\n", 0, 0, 0 );
  288. return control;
  289. }
  290. /*
  291. This function scans the array of controls and updates the Repl_Agmt's
  292. Dirsync_Private if the dirsync control is found.
  293. */
  294. void windows_private_update_dirsync_control(const Repl_Agmt *ra,LDAPControl **controls )
  295. {
  296. Dirsync_Private *dp;
  297. int foundDirsyncControl;
  298. int i;
  299. LDAPControl *dirsync;
  300. BerElement *ber;
  301. long hasMoreData;
  302. long maxAttributeCount;
  303. BerValue *serverCookie;
  304. int return_value = LDAP_SUCCESS;
  305. LDAPDebug( LDAP_DEBUG_TRACE, "=> windows_private_update_dirsync_control\n", 0, 0, 0 );
  306. PR_ASSERT(ra);
  307. dp = (Dirsync_Private *) agmt_get_priv(ra);
  308. PR_ASSERT (dp);
  309. if (NULL != controls )
  310. {
  311. foundDirsyncControl = 0;
  312. for ( i = 0; (( controls[i] != NULL ) && ( !foundDirsyncControl )); i++ ) {
  313. foundDirsyncControl = !strcmp( controls[i]->ldctl_oid, REPL_DIRSYNC_CONTROL_OID );
  314. }
  315. if ( !foundDirsyncControl )
  316. {
  317. return_value = LDAP_CONTROL_NOT_FOUND;
  318. goto choke;
  319. }
  320. else
  321. {
  322. dirsync = slapi_dup_control( controls[i-1]);
  323. }
  324. ber = ber_init( &dirsync->ldctl_value ) ;
  325. if (ber_scanf( ber, "{iiO}", &hasMoreData, &maxAttributeCount, &serverCookie) == LBER_ERROR)
  326. {
  327. return_value = LDAP_CONTROL_NOT_FOUND;
  328. goto choke;
  329. }
  330. slapi_ch_free(&dp->dirsync_cookie);
  331. dp->dirsync_cookie = ( char* ) slapi_ch_malloc(serverCookie->bv_len + 1);
  332. memcpy(dp->dirsync_cookie, serverCookie->bv_val, serverCookie->bv_len);
  333. dp->dirsync_cookie_len = (int) serverCookie->bv_len; /* XXX shouldn't cast? */
  334. /* dp->dirsync_maxattributecount = maxAttributeCount; We don't need to keep this */
  335. dp->dirsync_cookie_has_more = hasMoreData;
  336. choke:
  337. ber_bvfree(serverCookie);
  338. ber_free(ber,1);
  339. }
  340. else
  341. {
  342. return_value = LDAP_CONTROL_NOT_FOUND;
  343. }
  344. LDAPDebug( LDAP_DEBUG_TRACE, "<= windows_private_update_dirsync_control\n", 0, 0, 0 );
  345. /* return return_value; */
  346. }
  347. PRBool windows_private_dirsync_has_more(const Repl_Agmt *ra)
  348. {
  349. Dirsync_Private *dp;
  350. LDAPDebug( LDAP_DEBUG_TRACE, "=> windows_private_dirsync_has_more\n", 0, 0, 0 );
  351. PR_ASSERT(ra);
  352. dp = (Dirsync_Private *) agmt_get_priv(ra);
  353. PR_ASSERT (dp);
  354. LDAPDebug( LDAP_DEBUG_TRACE, "<= windows_private_dirsync_has_more\n", 0, 0, 0 );
  355. return dp->dirsync_cookie_has_more;
  356. }
  357. void windows_private_null_dirsync_cookie(const Repl_Agmt *ra)
  358. {
  359. Dirsync_Private *dp;
  360. LDAPDebug( LDAP_DEBUG_TRACE, "=> windows_private_null_dirsync_control\n", 0, 0, 0 );
  361. dp = (Dirsync_Private *) agmt_get_priv(ra);
  362. PR_ASSERT (dp);
  363. dp->dirsync_cookie_len = 0;
  364. slapi_ch_free(&dp->dirsync_cookie);
  365. dp->dirsync_cookie = NULL;
  366. LDAPDebug( LDAP_DEBUG_TRACE, "<= windows_private_null_dirsync_control\n", 0, 0, 0 );
  367. }
  368. static
  369. Slapi_Mods *windows_private_get_cookie_mod(Dirsync_Private *dp, int modtype)
  370. {
  371. Slapi_Mods *smods = NULL;
  372. smods = slapi_mods_new();
  373. slapi_mods_add( smods, modtype,
  374. "nsds7DirsyncCookie", dp->dirsync_cookie_len , dp->dirsync_cookie);
  375. return smods;
  376. }
  377. /* writes the current cookie into dse.ldif under the replication agreement entry
  378. returns: ldap result code of the operation. */
  379. int
  380. windows_private_save_dirsync_cookie(const Repl_Agmt *ra)
  381. {
  382. Dirsync_Private *dp = NULL;
  383. Slapi_PBlock *pb = NULL;
  384. const char* dn = NULL;
  385. Slapi_DN* sdn = NULL;
  386. int rc = 0;
  387. Slapi_Mods *mods = NULL;
  388. LDAPDebug( LDAP_DEBUG_TRACE, "=> windows_private_save_dirsync_cookie\n", 0, 0, 0 );
  389. PR_ASSERT(ra);
  390. dp = (Dirsync_Private *) agmt_get_priv(ra);
  391. PR_ASSERT (dp);
  392. pb = slapi_pblock_new ();
  393. mods = windows_private_get_cookie_mod(dp, LDAP_MOD_REPLACE);
  394. sdn = slapi_sdn_dup( agmt_get_dn_byref(ra) );
  395. dn = slapi_sdn_get_dn(sdn);
  396. slapi_modify_internal_set_pb (pb, dn, slapi_mods_get_ldapmods_byref(mods), NULL, NULL,
  397. repl_get_plugin_identity(PLUGIN_MULTIMASTER_REPLICATION), 0);
  398. slapi_modify_internal_pb (pb);
  399. slapi_pblock_get(pb, SLAPI_PLUGIN_INTOP_RESULT, &rc);
  400. if (rc == LDAP_NO_SUCH_ATTRIBUTE)
  401. { /* try again, but as an add instead */
  402. mods = windows_private_get_cookie_mod(dp, LDAP_MOD_ADD);
  403. slapi_modify_internal_set_pb (pb, dn, slapi_mods_get_ldapmods_byref(mods), NULL, NULL,
  404. repl_get_plugin_identity(PLUGIN_MULTIMASTER_REPLICATION), 0);
  405. slapi_modify_internal_pb (pb);
  406. slapi_pblock_get(pb, SLAPI_PLUGIN_INTOP_RESULT, &rc);
  407. }
  408. slapi_pblock_destroy (pb);
  409. slapi_mods_free(&mods);
  410. slapi_sdn_free(&sdn);
  411. LDAPDebug( LDAP_DEBUG_TRACE, "<= windows_private_save_dirsync_cookie\n", 0, 0, 0 );
  412. return rc;
  413. }
  414. /* reads the cookie in dse.ldif to the replication agreement entry
  415. returns: ldap result code of ldap operation, or
  416. LDAP_NO_SUCH_ATTRIBUTE. (this is the equilivent of a null cookie) */
  417. int windows_private_load_dirsync_cookie(const Repl_Agmt *ra)
  418. {
  419. Dirsync_Private *dp = NULL;
  420. Slapi_PBlock *pb = NULL;
  421. Slapi_DN* sdn = NULL;
  422. int rc = 0;
  423. Slapi_Entry *entry = NULL;
  424. char* cookie = NULL;
  425. Slapi_Attr *attr = NULL;
  426. LDAPDebug( LDAP_DEBUG_TRACE, "=> windows_private_load_dirsync_cookie\n", 0, 0, 0 );
  427. PR_ASSERT(ra);
  428. dp = (Dirsync_Private *) agmt_get_priv(ra);
  429. PR_ASSERT (dp);
  430. pb = slapi_pblock_new ();
  431. sdn = slapi_sdn_dup( agmt_get_dn_byref(ra) );
  432. rc = slapi_search_internal_get_entry(sdn, NULL, &entry,
  433. repl_get_plugin_identity (PLUGIN_MULTIMASTER_REPLICATION));
  434. if (rc == 0)
  435. {
  436. rc= slapi_entry_attr_find( entry, type_nsds7DirsyncCookie, &attr );
  437. if (attr)
  438. {
  439. struct berval **vals;
  440. rc = slapi_attr_get_bervals_copy(attr, &vals );
  441. if (vals)
  442. {
  443. dp->dirsync_cookie_len = (int) (vals[0])->bv_len;
  444. slapi_ch_free(&dp->dirsync_cookie);
  445. dp->dirsync_cookie = ( char* ) slapi_ch_malloc(dp->dirsync_cookie_len + 1);
  446. memcpy(dp->dirsync_cookie,(vals[0]->bv_val), (vals[0])->bv_len+1);
  447. }
  448. ber_bvecfree(vals);
  449. /* we do not free attr */
  450. }
  451. else
  452. {
  453. rc = LDAP_NO_SUCH_ATTRIBUTE;
  454. }
  455. }
  456. if (entry)
  457. {
  458. slapi_entry_free(entry);
  459. }
  460. slapi_sdn_free( &sdn);
  461. slapi_pblock_destroy (pb);
  462. LDAPDebug( LDAP_DEBUG_TRACE, "<= windows_private_load_dirsync_cookie\n", 0, 0, 0 );
  463. return rc;
  464. }