Codebase list slapi-nis / 4d91ad3
Merge branch 'upstream' Timo Aaltonen 4 years ago
22 changed file(s) with 1093 addition(s) and 60 deletion(s). Raw diff Collapse all Expand all
0 VERSION != grep AC_INIT configure.ac|cut -d, -f2|tr -d ")"
1 outdir=.
2 SUDO=
3
4 srpm:
5 $(SUDO) dnf -y install rpm-build autoconf automake libtool \
6 /usr/bin/rpcgen 389-ds-base-devel libnsl2-devel \
7 libsss_nss_idmap-devel nspr-devel nss-devel \
8 openldap-devel pam-devel ; \
9 ./autogen.sh; \
10 ./configure; \
11 tmpdir=`mktemp -d /tmp/make_archive_XXXXXX`;\
12 make dist;\
13 mv slapi-nis-$(VERSION).tar.gz $$tmpdir; \
14 touch $$tmpdir/slapi-nis-$(VERSION).tar.gz.sig;\
15 rpmbuild \
16 --define "_topdir $$tmpdir" \
17 --define "_sourcedir $$tmpdir" \
18 --define "_specdir $$tmpdir" \
19 --define "_builddir $$tmpdir" \
20 --define "_srcrpmdir $$tmpdir" \
21 --define "_rpmdir $$tmpdir" \
22 --build-in-place \
23 -ts $$tmpdir/slapi-nis-$(VERSION).tar.gz;\
24 cp -v $$tmpdir/slapi-nis-$(VERSION)-*.src.rpm $(outdir)/; \
25 rm -rf $$tmpdir
0 0.56.3 * Bug 1694263: On some 'cn=config' updates bepost_op are not called
1 that leads to lock leak
2 * Bug 1435663: deadlock between write and search operation in
3 schema-compat plugin
04 0.52 * Properly note in the nsslapd-pluginVersion attribute whether or
15 not transaction support is available.
26 * Fix a pair of incorrect memcpy()-instead-of-memmove() cases which
0 AC_INIT(slapi-nis,0.56.2)
0 AC_INIT(slapi-nis,0.56.4)
11 AC_CONFIG_MACRO_DIR([m4])
22 AM_INIT_AUTOMAKE(foreign)
33 LT_INIT([disable-static])
272272 ])
273273 if test $use_tirpc = yes ; then
274274 PKG_CHECK_MODULES(TIRPC,libtirpc)
275 fi
276
277 PKG_CHECK_MODULES(NSL,libnsl,[use_libnsl=yes],[use_libnsl=no])
278 if test "$use_libnsl" = yes ; then
279 RPC_CFLAGS="$NSL_CFLAGS"
280 RPC_LIBS="$NSL_LIBS"
275281 else
276282 RPC_CFLAGS=
277283 RPC_LIBS=-lnsl
99 %endif
1010
1111 Name: slapi-nis
12 Version: 0.56.2
12 Version: 0.56.4
1313 Release: 1%{?dist}
1414 Summary: NIS Server and Schema Compatibility plugins for Directory Server
15 Group: System Environment/Daemons
1615 License: GPLv2
17 URL: http://slapi-nis.fedorahosted.org/
18 Source0: https://fedorahosted.org/releases/s/l/slapi-nis/slapi-nis-%{version}.tar.gz
19 #Source1: https://fedorahosted.org/releases/s/l/slapi-nis/slapi-nis-%{version}.tar.gz.sig
20 BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n)
16 URL: http://pagure.io/slapi-nis/
17 Source0: https://releases.pagure.org/slapi-nis/slapi-nis-%{version}.tar.gz
18 Source1: https://releases.pagure.org/slapi-nis/slapi-nis-%{version}.tar.gz.sig
19 BuildRequires: autoconf
20 BuildRequires: automake
21 BuildRequires: libtool
2122 BuildRequires: 389-ds-base-devel >= 1.3.5.6, %{ldap_impl}-devel
2223 BuildRequires: nspr-devel, nss-devel, /usr/bin/rpcgen
2324 %if 0%{?fedora} > 18 || 0%{?rhel} > 6
2728 %define sss_nss_opts %{nil}
2829 %endif
2930 BuildRequires: pam-devel
30 %if 0%{?fedora} > 6 || 0%{?rhel} > 5
31 BuildRequires: tcp_wrappers-devel
32 %else
33 BuildRequires: tcp_wrappers
34 %endif
35 %if 0%{?fedora} > 14 || 0%{?rhel} > 6
31 %if (0%{?fedora} > 14 && 0%{?fedora} < 28) || (0%{?rhel} > 6 && 0%{?rhel} < 8)
3632 BuildRequires: libtirpc-devel
37 %endif
38 %if 0%{?rhel} > 0 && 0%{?rhel} < 7
39 ExclusiveArch: x86_64 %{ix86}
33 %else:
34 BuildRequires: libnsl2-devel
35 %endif
36 %if 0%{?fedora} > 27
37 ExcludeArch: %{ix86}
4038 %endif
4139 Requires: 389-ds-base >= 1.3.5.6
4240
5755 %setup -q
5856
5957 %build
60 %configure --disable-static --with-tcp-wrappers --with-ldap=%{ldap_impl} \
58 autoconf --force
59 %configure --disable-static --with-ldap=%{ldap_impl} \
6160 --with-nsswitch --with-pam --with-pam-service=system-auth \
6261 %{sss_nss_opts} %{betxn_opts}
6362 sed -i -e 's,%{_libdir}/dirsrv/plugins/,,g' -e 's,.so$,,g' doc/examples/*.ldif
7473 make check
7574 %endif
7675
77 %clean
78 rm -rf $RPM_BUILD_ROOT
79
8076 %files
81 %defattr(-,root,root,-)
8277 %doc COPYING NEWS README STATUS doc/*.txt doc/examples/*.ldif doc/ipa
8378 %{_mandir}/man1/*
8479 %{_libdir}/dirsrv/plugins/*.so
8580 %{_sbindir}/nisserver-plugin-defs
8681
8782 %changelog
83 * Fri Feb 07 2020 Alexander Bokovoy <abokovoy@redhat.com> - 0.56.4-1
84 - New upstream release
85 - Fix build with newer gcc versions
86 - Resolves rhbz#1800097
87
88 * Wed Jun 05 2019 Alexander Bokovoy <abokovoy@redhat.com> - 0.56.3-1
89 - New upstream release
90
91 * Sat Feb 02 2019 Fedora Release Engineering <releng@fedoraproject.org> - 0.56.2-8
92 - Rebuilt for https://fedoraproject.org/wiki/Fedora_30_Mass_Rebuild
93
94 * Sat Jul 14 2018 Fedora Release Engineering <releng@fedoraproject.org> - 0.56.2-7
95 - Rebuilt for https://fedoraproject.org/wiki/Fedora_29_Mass_Rebuild
96
97 * Wed May 02 2018 Alexander Bokovoy <abokovoy@redhat.com> - 0.56.2-6
98 - Force rebuild of configure
99
100 * Wed May 02 2018 Alexander Bokovoy <abokovoy@redhat.com> - 0.56.2-5
101 - Link with libnsl explicitly in Fedora 28 or later
102 - Require libnsl2-devel for build
103 - Resolves rhbz#1573636
104
105 * Thu Mar 15 2018 Alexander Bokovoy <abokovoy@redhat.com> - 0.56.2-4
106 - Remove tcpwrappers support as they aren't available in Fedora anymore
107
108 * Thu Mar 15 2018 Alexander Bokovoy <abokovoy@redhat.com> - 0.56.2-3
109 - Do not build on i686 in Fedora 28 or later as 389-ds-base is not available there anymore
110 - Resolves rhbz#1556448
111 - Remove outdated ExclusiveArch for RHEL6
112
113 * Fri Feb 09 2018 Fedora Release Engineering <releng@fedoraproject.org> - 0.56.2-2
114 - Rebuilt for https://fedoraproject.org/wiki/Fedora_28_Mass_Rebuild
115
88116 * Fri Jan 19 2018 Alexander Bokovoy <abokovoy@redhat.com> - 0.56.2-1
89117 - New upstream release
118 - Update links to the upstream project page and releases
90119 - Use extended SSSD API to signal that an entry should not be cached anymore
91120 - Add support for timeout-based NSS queries with libsss_nss_idmap
121
122 * Thu Aug 03 2017 Fedora Release Engineering <releng@fedoraproject.org> - 0.56.1-4
123 - Rebuilt for https://fedoraproject.org/wiki/Fedora_27_Binutils_Mass_Rebuild
124
125 * Thu Jul 27 2017 Fedora Release Engineering <releng@fedoraproject.org> - 0.56.1-3
126 - Rebuilt for https://fedoraproject.org/wiki/Fedora_27_Mass_Rebuild
92127
93128 * Sat Feb 11 2017 Fedora Release Engineering <releng@fedoraproject.org> - 0.56.1-2
94129 - Rebuilt for https://fedoraproject.org/wiki/Fedora_26_Mass_Rebuild
848848 request_set(state->request_info, RQ_DAEMON,
849849 DEFAULT_TCPWRAP_NAME);
850850 }
851 #else
852 (void)tmp;
851853 #endif
852854 use_be_txns = backend_shr_get_vattr_boolean(state, our_entry,
853855 "nsslapd-pluginbetxn",
5555 idview_get_overrides(struct backend_search_cbdata *cbdata)
5656 {
5757 char *dn = NULL;
58 int ret = 0, result = 0;
58 int result = 0;
5959 const Slapi_DN *suffix = NULL;
6060 Slapi_PBlock *pb;
6161
7575 slapi_search_internal_set_pb(pb, dn, LDAP_SCOPE_SUBTREE,
7676 "(objectclass=ipaOverrideAnchor)", NULL, 0,
7777 NULL, NULL, cbdata->state->plugin_identity, 0);
78 ret = slapi_search_internal_pb(pb);
78 slapi_search_internal_pb(pb);
7979 slapi_ch_free_string(&dn);
8080 slapi_pblock_get(pb, SLAPI_PLUGIN_INTOP_RESULT, &result);
8181
179179 }
180180 result = slapi_attr_get_valueset(override_attr, &override_valueset);
181181 result = slapi_entry_add_valueset(entry, override_type, override_valueset);
182 slapi_valueset_free(override_valueset);
182183 }
183184 result = slapi_entry_next_attr(override_entry, override_attr, &override_attr);
184185 }
286287 new_target = slapi_ch_smprintf("%s", cnviews+10);
287288 }
288289 cnviews[0] = ',';
290 slapi_ch_free_string(target);
289291 *target = new_target;
290292 }
291293 }
410412 {
411413 struct backend_search_filter_config config =
412414 {FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, FALSE, NULL, NULL, NULL};
413 int res = 0;
414
415415 if (cbdata->idview == NULL) {
416416 return;
417417 }
420420 config.callback_data = cbdata;
421421
422422 /* Ignore the return code as it will always be SLAPI_FILTER_SCAN_NO_MORE */
423 res = backend_analyze_search_filter(cbdata->filter, &config);
423 (void)backend_analyze_search_filter(cbdata->filter, &config);
424424
425425 if (config.name != NULL) {
426426 slapi_ch_free_string(&config.name);
167167 }
168168 } else {
169169 if (rc == PAM_SUCCESS) {
170 *errmsg = PR_smprintf("PAM %s succeeds for user \"%s\" "
171 "(bind DN \"%s\")",
172 fn, user, binddn);
170 *errmsg = PR_smprintf("PAM %s succeeds for bind DN \"%s\"",
171 fn, binddn);
173172 } else {
174173 if (pamh != NULL) {
175174 *errmsg = PR_smprintf("PAM %s error for invalid user "
5353 #include "plugin.h"
5454 #include "map.h"
5555 #include "back-sch.h"
56
57 /*
58 * This is not a public function in 389-ds but we need to use it in backend_search_cb(),
59 * see a comment there on the difference between slapi_send_ldap_result() and send_ldap_result().
60 */
61 extern void send_ldap_result(Slapi_PBlock *pb, int err, char *matched, char *text, int nentries, struct berval **urls);
5662
5763 static int backend_passwdmod_extop(Slapi_PBlock *pb);
5864 backend_extop_handlers_t extop_handlers[] = {{EXTOP_PASSWD_OID, (IFP) backend_passwdmod_extop},
431437 * plugin want to override the values using the configuration, they
432438 * can. */
433439 if (gmtime_r(&timestamp, &timestamp_tm) == &timestamp_tm) {
434 sprintf(timestamp_str, "%04d%02d%02d%02d%02d%02dZ",
435 timestamp_tm.tm_year + 1900,
436 timestamp_tm.tm_mon + 1,
437 timestamp_tm.tm_mday,
438 timestamp_tm.tm_hour,
439 timestamp_tm.tm_min,
440 timestamp_tm.tm_sec);
440 strftime(timestamp_str, sizeof(timestamp_str),
441 "%Y%m%d%H%M%SZ", &timestamp_tm);
441442 slapi_entry_add_string(e, "createTimestamp", timestamp_str);
442443 slapi_entry_add_string(e, "modifyTimestamp", timestamp_str);
443444 }
15231524 struct entries_to_send *e_to_send = NULL;
15241525 struct cached_entry *entry = NULL;
15251526 bool_t dont_cache = FALSE;
1527 void *ndn_key = (void *) slapi_entry_get_ndn(e);
15261528 PLHashTable* ht = (PLHashTable*) cbdata->state->cached_entries;
15271529
1528 if ((cbdata == NULL) || (e == NULL)) return;
1530 if ((cbdata == NULL) || (e == NULL) || (ndn_key == NULL)) return;
15291531
15301532 e_to_send = (struct entries_to_send *) slapi_ch_calloc(1, sizeof(struct entries_to_send));
15311533
15321534 dont_cache = cbdata->state->use_entry_cache ? FALSE : TRUE;
15331535
15341536 if (!wrap_rwlock_wrlock(cbdata->state->cached_entries_lock)) {
1535 entry = PL_HashTableLookup(ht, slapi_entry_get_ndn(e));
1537 entry = PL_HashTableLookup(ht, ndn_key);
15361538 if (entry != NULL) {
15371539 /* There is an entry in the hash table but is it the same? */
15381540 char *e_modifyTimestamp = slapi_entry_attr_get_charptr(e, "modifyTimestamp");
16461648 cbdata->entries_tail = NULL;
16471649 }
16481650
1651 static void
1652 backend_search_free_staged(struct backend_search_cbdata *cbdata)
1653 {
1654 struct backend_staged_search *staged, *next;
1655 int i;
1656 int nb_entries = 0;
1657 int nb_stages = 0;
1658
1659 if (cbdata == NULL) {
1660 return;
1661 }
1662
1663 staged = cbdata->staged;
1664 while (staged != NULL) {
1665 nb_stages++;
1666 for (i = 0;
1667 (i < staged->count) &&
1668 (staged->entries != NULL) &&
1669 (staged->entries[i] != NULL);
1670 i++) {
1671 slapi_entry_free(staged->entries[i]);
1672 staged->entries[i] = NULL;
1673 }
1674 nb_entries += i;
1675 slapi_ch_free_string(&staged->map_group);
1676 slapi_ch_free_string(&staged->map_set);
1677 slapi_ch_free_string(&staged->name);
1678 slapi_ch_free_string(&staged->container_sdn);
1679 next = staged->next;
1680 free(staged);
1681 staged = next;
1682 }
1683 slapi_log_error(SLAPI_LOG_PLUGIN,
1684 cbdata->state->plugin_desc->spd_id,
1685 "backend_search_free_staged freed %d stages with %d entries\n",
1686 nb_stages,
1687 nb_entries);
1688 cbdata->staged = NULL;
1689 }
16491690 static int
16501691 backend_search_cb(Slapi_PBlock *pb)
16511692 {
18501891 map_unlock();
18511892 /* Return newly acquired entries */
18521893 backend_send_mapped_entries(&cbdata);
1894 backend_search_free_staged(&cbdata);
18531895 } else {
18541896 slapi_log_error(SLAPI_LOG_PLUGIN,
18551897 cbdata.state->plugin_desc->spd_id,
23022344 slapi_pblock_get(pb, SLAPI_PLUGIN_PRIVATE, &state);
23032345 return state->use_be_txns ? backend_write_cb(pb, state) : 0;
23042346 }
2347 static PRBool
2348 backend_be_write_ignore(Slapi_PBlock *pb)
2349 {
2350 char *dn = NULL;
2351 Slapi_DN *target_sdn = NULL;
2352 int check;
2353 int i = 0;
2354 PRBool ignore = PR_FALSE;
2355
2356 /* Check if the target DN is a subordinates of
2357 * on of the ignored containers
2358 */
2359 slapi_pblock_get(pb, SLAPI_ORIGINAL_TARGET, &dn);
2360 target_sdn = slapi_sdn_new_dn_byval(dn);
2361
2362 for (i = 0; ignored_containers_sdn[i]; i++) {
2363 check = slapi_sdn_issuffix(target_sdn, ignored_containers_sdn[i]);
2364 if (check != 0) {
2365 /* This entry is an ignored container */
2366 ignore = PR_TRUE;
2367 break;
2368 }
2369 }
2370 slapi_sdn_free(&target_sdn);
2371 return ignore;
2372 }
2373
2374
2375 static int
2376 backend_be_pre_write_cb(Slapi_PBlock *pb) {
2377 int ret = 0;
2378 int lock_status;
2379 int lock_count;
2380 struct plugin_state *state;
2381
2382 slapi_pblock_get(pb, SLAPI_PLUGIN_PRIVATE, &state);
2383
2384 if (wrap_get_call_level() > 0) {
2385 return 0;
2386 }
2387 if (state->ready_to_serve == 0) {
2388 /* No data to serve yet */
2389 return 0;
2390 }
2391 if (rw_monitor_enabled() == MAP_MONITOR_DISABLED) {
2392 return 0;
2393 }
2394 if (backend_be_write_ignore(pb)) {
2395 #if DEBUG_MAP_LOCK
2396 slapi_log_error(SLAPI_LOG_FATAL, "schemacompat",
2397 "backend_be_pre_write_cb: (%p) operation is not impacting schema compat\n", PR_MyThreadId(), 1);
2398 #endif
2399 return 0;
2400 }
2401
2402
2403
2404 wrap_inc_call_level();
2405
2406 lock_status = get_plugin_monitor_status();
2407 lock_count = get_plugin_monitor_count();
2408 if (lock_status == MAP_RWLOCK_UNINIT) {
2409 return 0;
2410 }
2411
2412 if (lock_status == MAP_RWLOCK_FREE) {
2413 /* This thread does not hold the map lock */
2414 set_plugin_monitor_count(1);
2415
2416 if (plugin_wrlock() == 0) {
2417 ret = 0;
2418 } else {
2419 slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id,
2420 "backend_be_pre_write_cb: unable to acquire write lock\n");
2421 ret = -1;
2422 }
2423 #if DEBUG_MAP_LOCK
2424 slapi_log_error(SLAPI_LOG_FATAL, "schemacompat",
2425 "backend_be_pre_write_cb: (%p) MAP_RWLOCK_FREE -> MAP_WLOCK_HELD : count=%d\n", (void *) PR_MyThreadId(), 1);
2426 #endif
2427 } else {
2428 set_plugin_monitor_count(lock_count + 1);
2429 #if DEBUG_MAP_LOCK
2430 slapi_log_error(SLAPI_LOG_FATAL, "schema-compat",
2431 "backend_be_pre_write_cb: (%p) %s --> MAP_WLOCK_HELD : count=%d\n",
2432 (void *) PR_MyThreadId(),
2433 (lock_status == MAP_WLOCK_HELD) ? "MAP_WLOCK_HELD": "MAP_RLOCK_HELD",
2434 lock_count + 1);
2435 #endif
2436 ret = 0;
2437 if (lock_status == MAP_RLOCK_HELD) {
2438 /* lock is already acquired in read */
2439
2440 #if DEBUG_MAP_LOCK
2441 slapi_log_error(SLAPI_LOG_FATAL, "schema-compat",
2442 "map backend_be_pre_write_cb: weird situation map lock is held in read and now required in write mode\n");
2443 #endif
2444 /* First free the lock held in read */
2445 ret = plugin_unlock();
2446 if (ret) {
2447 slapi_log_error(SLAPI_LOG_FATAL, "schema-compat",
2448 "backend_be_pre_write_cb: fail to unlock plugin lock (%d)\n", ret);
2449 }
2450
2451 /* Second acquire it in write */
2452 ret = plugin_wrlock();
2453 if (ret) {
2454 slapi_log_error(SLAPI_LOG_FATAL, "schema-compat",
2455 "backend_be_pre_write_cb: fail to write lock plugin lock (%d)\n", ret);
2456 }
2457 }
2458 }
2459
2460 set_plugin_monitor_status(MAP_WLOCK_HELD);
2461 wrap_dec_call_level();
2462
2463 return ret;
2464 }
2465
2466 static int
2467 backend_be_post_write_cb(Slapi_PBlock *pb)
2468 {
2469 int ret = 0;
2470 int lock_status;
2471 int lock_count;
2472 struct plugin_state *state;
2473
2474 slapi_pblock_get(pb, SLAPI_PLUGIN_PRIVATE, &state);
2475
2476 if (wrap_get_call_level() > 0) {
2477 return 0;
2478 }
2479 if (state->ready_to_serve == 0) {
2480 /* No data to serve yet */
2481 return 0;
2482 }
2483 if (rw_monitor_enabled() == MAP_MONITOR_DISABLED) {
2484 return 0;
2485 }
2486 if (backend_be_write_ignore(pb)) {
2487 #if DEBUG_MAP_LOCK
2488 slapi_log_error(SLAPI_LOG_FATAL, "schemacompat",
2489 "backend_be_post_write_cb: (%p) operation was not impacting schema compat\n", PR_MyThreadId(), 1);
2490 #endif
2491 return 0;
2492 }
2493
2494 wrap_inc_call_level();
2495
2496 lock_status = get_plugin_monitor_status();
2497 lock_count = get_plugin_monitor_count();
2498 if (lock_status == MAP_RWLOCK_UNINIT) {
2499 return 0;
2500 }
2501
2502 if (lock_count == 1) {
2503 set_plugin_monitor_status(MAP_RWLOCK_FREE);
2504 if (plugin_unlock() == 0) {
2505 ret = 0;
2506 } else {
2507 slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id,
2508 "backend_be_post_write_cb: unable to release write lock\n");
2509 ret = -1;
2510 }
2511 #if DEBUG_MAP_LOCK
2512 slapi_log_error(SLAPI_LOG_FATAL, "schema-compat",
2513 "backend_be_post_write_cb: (%p) %s --> MAP_RWLOCK_FREE : count=%d\n",
2514 (void *) PR_MyThreadId(),
2515 (lock_status == MAP_WLOCK_HELD) ? "MAP_WLOCK_HELD" : (lock_status == MAP_RLOCK_HELD) ? "MAP_RLOCK_HELD" : "MAP_RWLOCK_FREE",
2516 0);
2517 #endif
2518 }
2519 if (lock_count >= 1) {
2520 set_plugin_monitor_count(lock_count - 1);
2521 #if DEBUG_MAP_LOCK
2522 if (lock_count > 1) {
2523 slapi_log_error(SLAPI_LOG_FATAL, "schema-compat",
2524 "backend_be_post_write_cb: (%p) keep %s : count=%d\n",
2525 (void *) PR_MyThreadId(),
2526 (lock_status == MAP_WLOCK_HELD) ? "MAP_WLOCK_HELD" : (lock_status == MAP_RLOCK_HELD) ? "MAP_RLOCK_HELD" : "MAP_RWLOCK_FREE",
2527 lock_count - 1);
2528 } else {
2529 slapi_log_error(SLAPI_LOG_FATAL, "schema-compat",
2530 "backend_be_post_write_cb: (%p) is now %s : count=%d\n",
2531 (void *) PR_MyThreadId(),
2532 "MAP_RWLOCK_FREE",
2533 lock_count - 1);
2534 }
2535 #endif
2536 }
2537 wrap_dec_call_level();
2538
2539 return ret;
2540 }
23052541
23062542 #ifdef USE_PAM
23072543 static int
28143050 }
28153051
28163052 int
3053 backend_init_be_preop(Slapi_PBlock *pb, struct plugin_state *state)
3054 {
3055 slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id,
3056 "hooking up bet preoperation callbacks\n");
3057 /* Intercept write requests and return an insufficient-access error for
3058 * attempts to write to anything we're managing. */
3059 if (slapi_pblock_set(pb, SLAPI_PLUGIN_BE_PRE_ADD_FN,
3060 backend_be_pre_write_cb) != 0) {
3061 slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id,
3062 "error hooking up betxn pre add callback\n");
3063 return -1;
3064 }
3065 if (slapi_pblock_set(pb, SLAPI_PLUGIN_BE_PRE_MODIFY_FN,
3066 backend_be_pre_write_cb) != 0) {
3067 slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id,
3068 "error hooking up betxn pre modify callback\n");
3069 return -1;
3070 }
3071 if (slapi_pblock_set(pb, SLAPI_PLUGIN_BE_PRE_MODRDN_FN,
3072 backend_be_pre_write_cb) != 0) {
3073 slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id,
3074 "error hooking up betxn pre modrdn callback\n");
3075 return -1;
3076 }
3077 if (slapi_pblock_set(pb, SLAPI_PLUGIN_BE_PRE_DELETE_FN,
3078 backend_be_pre_write_cb) != 0) {
3079 slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id,
3080 "error hooking up betxn pre delete callback\n");
3081 return -1;
3082 }
3083 /* We don't hook abandonment requests. */
3084 /* We don't hook unbind requests. */
3085 return 0;
3086 }
3087
3088 int
28173089 backend_init_betxn_postop(Slapi_PBlock *pb, struct plugin_state *state)
28183090 {
28193091 slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id,
28203092 "hooking up betxn postoperation callbacks\n");
28213093 return backend_shr_betxn_postop_init(pb, state);
28223094 }
3095
3096
3097 int
3098 backend_init_be_postop(Slapi_PBlock *pb, struct plugin_state *state)
3099 {
3100 if (slapi_pblock_set(pb, SLAPI_PLUGIN_BE_POST_ADD_FN,
3101 backend_be_post_write_cb) != 0) {
3102 slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id,
3103 "error hooking up betxn post add callback\n");
3104 return -1;
3105 }
3106 if (slapi_pblock_set(pb, SLAPI_PLUGIN_BE_POST_MODIFY_FN,
3107 backend_be_post_write_cb) != 0) {
3108 slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id,
3109 "error hooking up betxn post modify "
3110 "callback\n");
3111 return -1;
3112 }
3113 if (slapi_pblock_set(pb, SLAPI_PLUGIN_BE_POST_MODRDN_FN,
3114 backend_be_post_write_cb) != 0) {
3115 slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id,
3116 "error hooking up betxn post modrdn "
3117 "callback\n");
3118 return -1;
3119 }
3120 if (slapi_pblock_set(pb, SLAPI_PLUGIN_BE_POST_DELETE_FN,
3121 backend_be_post_write_cb) != 0) {
3122 slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id,
3123 "error hooking up betxn post delete "
3124 "callback\n");
3125 return -1;
3126 }
3127 return 0;
3128 }
28233129 #endif
28243130
28253131 int
3636 #endif
3737
3838 #include <rpc/xdr.h>
39 #include <prtypes.h>
40 /* NSPR private API for thread-local variables */
41 #include <private/prpriv.h>
3942 #include "../yp/yp.h"
4043
4144 #ifdef HAVE_TCPD_H
776779 backend_shr_data_initialize_thread(time_t when, void *arg)
777780 {
778781 struct backend_shr_data_init_cbdata *cbdata = (struct backend_shr_data_init_cbdata *)arg;
779 PRThread *thread = NULL;
780
781782 if (slapi_is_shutting_down()) {
782783 return;
783784 }
28652866 }
28662867 return 0;
28672868 }
2869
2870 int
2871 PR_MyThreadId(void)
2872 {
2873 PRThread *thr = PR_GetCurrentThread();
2874 PRUint32 myself = PR_GetThreadID(thr);
2875 return myself;
2876 }
2877 PRBool use_lock_status = PR_FALSE;
2878 static unsigned int thread_plugin_lock_status;
2879 PRBool use_lock_count = PR_FALSE;
2880 static unsigned int thread_plugin_lock_count;
2881 /*
2882 * https://developer.mozilla.org/en-US/docs/Mozilla/Projects/NSPR/Reference/PR_NewThreadPrivateIndex
2883 * It is called each time:
2884 * - PR_SetThreadPrivate is call with a not NULL private value
2885 * - on thread exit
2886 */
2887 static void
2888 lock_status_free(void *ptr)
2889 {
2890 int *lock_status = ptr;
2891 if (lock_status) {
2892 slapi_ch_free((void **)&lock_status);
2893 }
2894 }
2895 static void
2896 lock_count_free(void *ptr)
2897 {
2898 int *lock_count = ptr;
2899 if (lock_count) {
2900 slapi_ch_free((void **)&lock_count);
2901 }
2902 }
2903
2904 /* This is used to ignore some write operations
2905 * if they target subordinates entry of ignored containers
2906 */
2907 Slapi_DN **ignored_containers_sdn = NULL;
2908 void
2909 init_map_lock(void)
2910 {
2911 #if DEBUG_MAP_LOCK
2912 /* The plugin lock is initialized as free */
2913 slapi_log_error(SLAPI_LOG_FATAL, "init_plugin_lock",
2914 "thread_id = %p\n", PR_MyThreadId());
2915 #endif
2916 if (ignored_containers_sdn == NULL) {
2917 /* allocates ignored_containers_sdn of Slapi_DN* only once
2918 * It will be used later in be_pre/post_write_cb
2919 */
2920 int cnt;
2921 char *ignored_containers[4] = { "cn=config", "cn=schema", "cn=changelog", NULL};
2922
2923 for (cnt = 0; ignored_containers[cnt]; cnt++);
2924 ignored_containers_sdn = (Slapi_DN **) slapi_ch_calloc(cnt + 1, sizeof(Slapi_DN *));
2925
2926 for (cnt = 0; ignored_containers[cnt]; cnt++) {
2927 ignored_containers_sdn[cnt] = slapi_sdn_new_dn_byval(ignored_containers[cnt]);
2928 }
2929 }
2930
2931 if (PR_NewThreadPrivateIndex(&thread_plugin_lock_status, lock_status_free) == PR_SUCCESS) {
2932 use_lock_status = PR_TRUE;
2933 }
2934 if (PR_NewThreadPrivateIndex(&thread_plugin_lock_count, lock_count_free) == PR_SUCCESS) {
2935 use_lock_count = PR_TRUE;
2936 }
2937
2938 #if DEBUG_MAP_LOCK
2939 slapi_log_error(SLAPI_LOG_FATAL, "init_plugin_lock",
2940 "thread_plugin_lock_status = %d\n", thread_plugin_lock_status);
2941 slapi_log_error(SLAPI_LOG_FATAL, "init_map_lock",
2942 "thread_plugin_lock_count = %d\n", thread_plugin_lock_count);
2943 #endif
2944 }
2945
2946 int
2947 rw_monitor_enabled(void)
2948 {
2949 if (use_lock_status)
2950 return (int) MAP_MONITOR_ENABLED;
2951 else
2952 return (int) MAP_MONITOR_DISABLED;
2953 }
2954
2955 int
2956 get_plugin_monitor_status(void)
2957 {
2958 int ret;
2959
2960 if (use_lock_status) {
2961 int *lock_status_p;
2962 lock_status_p = (int *) PR_GetThreadPrivate(thread_plugin_lock_status);
2963 if (lock_status_p == NULL) {
2964 /* if it was not initialized then allocates a structure
2965 * that will be private to that thread.
2966 * Later when the structure is retrieved (PR_GetThreadPrivate), the
2967 * content of the structure can be read/write without allocating
2968 * this private structure PR_SetThreadPrivate.
2969 * So this branch is processed one time per each thread
2970 */
2971 lock_status_p = (int *) slapi_ch_calloc(1, sizeof (int));
2972 PR_SetThreadPrivate(thread_plugin_lock_status, (void *) lock_status_p);
2973 *lock_status_p = MAP_RWLOCK_FREE;
2974 }
2975 ret = *lock_status_p;
2976 } else
2977 ret = (int) MAP_RWLOCK_UNINIT;
2978 #if DEBUG_MAP_LOCK
2979 slapi_log_error(SLAPI_LOG_FATAL, "get_plugin_monitor_status",
2980 "(%s) lock_status = %d (%p)\n", use_lock_status ? "TRUE" : "FALSE", ret, (void *) PR_MyThreadId());
2981 #endif
2982 return ret;
2983 }
2984
2985 void
2986 set_plugin_monitor_status(int lock_status)
2987 {
2988 #if DEBUG_MAP_LOCK
2989 slapi_log_error(SLAPI_LOG_FATAL, "set_plugin_monitor_status",
2990 "(%s) lock_status = %d --> %d (%p)\n", use_lock_status ? "TRUE" : "FALSE", get_plugin_monitor_status(), (int) lock_status, (void *) PR_MyThreadId());
2991 #endif
2992
2993 if (use_lock_status) {
2994 int *lock_status_p;
2995
2996 lock_status_p = (int *) PR_GetThreadPrivate(thread_plugin_lock_status);
2997 if (lock_status_p == NULL) {
2998 /* if it was not initialized then allocates a structure
2999 * that will be private to that thread.
3000 * Later when the structure is retrieved (PR_GetThreadPrivate), the
3001 * content of the structure can be read/write without allocating
3002 * this private structure PR_SetThreadPrivate.
3003 * So this branch is processed one time per each thread
3004 */
3005 lock_status_p = (int *) slapi_ch_calloc(1, sizeof (int));
3006 PR_SetThreadPrivate(thread_plugin_lock_status, (void *) lock_status_p);
3007 }
3008 *lock_status_p = lock_status;
3009 }
3010 }
3011
3012 int
3013 get_plugin_monitor_count(void)
3014 {
3015 int ret;
3016
3017 if (use_lock_count) {
3018 int *lock_count;
3019 lock_count = (int *) PR_GetThreadPrivate(thread_plugin_lock_count);
3020 if (lock_count == NULL) {
3021 /* if it was not initialized then allocates a structure
3022 * that will be private to that thread.
3023 * Later when the structure is retrieved (PR_GetThreadPrivate), the
3024 * content of the structure can be read/write without allocating
3025 * this private structure PR_SetThreadPrivate.
3026 * So this branch is processed one time per each thread
3027 */
3028 lock_count = (int *) slapi_ch_calloc(1, sizeof (int));
3029 PR_SetThreadPrivate(thread_plugin_lock_count, (void *) lock_count);
3030 *lock_count = 0;
3031 }
3032 ret = *lock_count;
3033 } else
3034 ret = (int) MAP_RWLOCK_UNINIT;
3035 #if DEBUG_MAP_LOCK
3036 slapi_log_error(SLAPI_LOG_FATAL, "get_plugin_monitor_count",
3037 "(%s) lock_count = %d (%p)\n", use_lock_count ? "TRUE" : "FALSE", ret, (void *) PR_MyThreadId());
3038 #endif
3039 return ret;
3040 }
3041
3042 void
3043 set_plugin_monitor_count(int lock_count)
3044 {
3045 #if DEBUG_MAP_LOCK
3046 slapi_log_error(SLAPI_LOG_FATAL, "set_plugin_monitor_count",
3047 "(%s) lock_count = %d --> %d (%p)\n", use_lock_count ? "TRUE" : "FALSE", get_plugin_monitor_count(), (int) lock_count, (void *) PR_MyThreadId());
3048 #endif
3049 if (use_lock_count) {
3050 int *lock_count_p;
3051
3052 lock_count_p = (int *) PR_GetThreadPrivate(thread_plugin_lock_count);
3053 if (lock_count_p == NULL) {
3054 /* if it was not initialized then allocates a structure
3055 * that will be private to that thread.
3056 * Later when the structure is retrieved (PR_GetThreadPrivate), the
3057 * content of the structure can be read/write without allocating
3058 * this private structure PR_SetThreadPrivate.
3059 * So this branch is processed one time per each thread
3060 */
3061 lock_count_p = (int *) slapi_ch_calloc(1, sizeof (int));
3062 PR_SetThreadPrivate(thread_plugin_lock_count, (void *) lock_count_p);
3063 }
3064 *lock_count_p = lock_count;
3065 }
3066 }
2020
2121 #ifndef back_shr_h
2222 #define back_shr_h
23
24 #define DEBUG_MAP_LOCK 0
25 #define MAP_MONITOR_DISABLED 0
26 #define MAP_MONITOR_ENABLED 1
27
28 #define MAP_RWLOCK_UNINIT 3
29 #define MAP_WLOCK_HELD 2
30 #define MAP_RLOCK_HELD 1
31 #define MAP_RWLOCK_FREE 0
32 int PR_MyThreadId(void);
33 int rw_monitor_enabled(void);
34 int get_plugin_monitor_status(void);
35 void set_plugin_monitor_status(int lock_status);
36 int get_plugin_monitor_count(void);
37 void set_plugin_monitor_count(int lock_count);
38 void init_map_lock(void);
39 extern Slapi_DN **ignored_containers_sdn;
40
2341
2442 struct plugin_state;
2543
6767 int backend_init_internal_postop(struct slapi_pblock *pb,
6868 struct plugin_state *state);
6969
70 /* Only used for schema compatibility plugin*/
71 int backend_init_be_preop(Slapi_PBlock *pb, struct plugin_state *state);
72 int backend_init_be_postop(Slapi_PBlock *pb, struct plugin_state *state);
73
74
7075 /* Read the server's name. */
7176 int backend_read_master_name(struct plugin_state *state,
7277 struct slapi_pblock *pb,
2222 #include "config.h"
2323 #endif
2424
25 #include <inttypes.h>
2526 #include <sys/types.h>
2627 #include <search.h>
2728 #include <stdlib.h>
3940
4041 #include <rpc/rpc.h>
4142
43 /* NSPR private API for thread-local variables */
44 #include <private/prpriv.h>
45
4246 #include "backend.h"
4347 #include "disp-nis.h"
4448 #include "map.h"
4549 #include "portmap.h"
4650 #include "wrap.h"
51 #include "back-shr.h"
4752
4853 /* The singleton for the cache. */
4954 static struct {
9095 } *domains;
9196 int n_domains;
9297 struct wrapped_rwlock *lock;
98 struct wrapped_rwlock *plugin_lock;
9399 } map_data;
94100
95101 static void *
11541160 if (map_data.lock == NULL) {
11551161 return -1;
11561162 }
1163 map_data.plugin_lock = wrap_new_rwlock();
1164 if (map_data.plugin_lock == NULL) {
1165 return -1;
1166 }
11571167 return 0;
11581168 }
11591169
11921202 }
11931203 wrap_free_rwlock(map_data.lock);
11941204 map_data.lock = NULL;
1205 wrap_free_rwlock(map_data.plugin_lock);
1206 map_data.plugin_lock = NULL;
11951207 }
11961208
11971209 int
12181230 }
12191231
12201232 int
1233 plugin_rdlock(void)
1234 {
1235 return wrap_rwlock_rdlock(map_data.plugin_lock);
1236 }
1237
1238 int
1239 plugin_wrlock(void)
1240 {
1241 return wrap_rwlock_wrlock(map_data.plugin_lock);
1242 }
1243
1244 int
1245 plugin_unlock(void)
1246 {
1247 return wrap_rwlock_unlock(map_data.plugin_lock);
1248 }
1249
1250 int
12211251 map_rdlock(void)
12221252 {
1223 return wrap_rwlock_rdlock(map_data.lock);
1224 }
1253 int lock_status;
1254 int lock_count;
1255 int rc = 0;
1256
1257 if (rw_monitor_enabled() == MAP_MONITOR_DISABLED) {
1258 /* This is not initialized used the old way */
1259 slapi_log_error(SLAPI_LOG_FATAL, "schemacompat",
1260 "map rdlock: old way MAP_MONITOR_DISABLED\n");
1261 return wrap_rwlock_rdlock(map_data.lock);
1262 }
1263
1264
1265 lock_status = get_plugin_monitor_status();
1266 lock_count = get_plugin_monitor_count();
1267
1268 #if DEBUG_MAP_LOCK
1269 slapi_log_error(SLAPI_LOG_FATAL, "map_rdlock",
1270 "thread_id = %"PRIx32" (call level = %d)\n", PR_MyThreadId(), wrap_get_call_level());
1271 #endif
1272 if (lock_status == MAP_RWLOCK_UNINIT) {
1273 /* This is not initialized used the old way */
1274 slapi_log_error(SLAPI_LOG_FATAL, "schemacompat",
1275 "map rdlock: old way lock_status == MAP_RWLOCK_UNINIT\n");
1276 return wrap_rwlock_rdlock(map_data.lock);
1277 }
1278
1279 if (lock_status == MAP_RWLOCK_FREE) {
1280 /* The plugin lock is free, acquire it */
1281 #if DEBUG_MAP_LOCK
1282 slapi_log_error(SLAPI_LOG_FATAL, "schemacompat",
1283 "map rdlock: current lock_status == MAP_RWLOCK_FREE\n");
1284 #endif
1285 set_plugin_monitor_status(MAP_RLOCK_HELD);
1286 set_plugin_monitor_count(1);
1287 #if DEBUG_MAP_LOCK
1288 if (lock_count != 0) {
1289 slapi_log_error(SLAPI_LOG_FATAL, "schemacompat",
1290 "map rdlock: (%"PRIx32") ALERT !!! count was %d -> 1\n", PR_MyThreadId(), lock_count);
1291 }
1292 #endif
1293
1294 /* Acquire the slapi plugin in read */
1295 rc = plugin_rdlock();
1296 if (rc) {
1297 slapi_log_error(SLAPI_LOG_FATAL, "schemacompat",
1298 "map rdlock: (%"PRIx32") MAP_RWLOCK_FREE -> MAP_RLOCK_HELD: fail to read lock plugin lock (%d)\n", PR_MyThreadId(), rc);
1299 return rc;
1300 }
1301 #if DEBUG_MAP_LOCK
1302 slapi_log_error(SLAPI_LOG_FATAL, "schemacompat",
1303 "map rdlock: (%"PRIx32") MAP_RWLOCK_FREE -> MAP_RLOCK_HELD : count=%d\n", PR_MyThreadId(), 1);
1304 #endif
1305 rc = wrap_rwlock_rdlock(map_data.lock);
1306 if (rc) {
1307 slapi_log_error(SLAPI_LOG_FATAL, "schemacompat",
1308 "Fail to acquire map lock in read (%d)\n", rc);
1309 plugin_unlock();
1310 return rc;
1311 }
1312 return 0;
1313 }
1314
1315 #if DEBUG_MAP_LOCK
1316 slapi_log_error(SLAPI_LOG_FATAL, "schemacompat",
1317 "map rdlock: (%x"PRIx32") was already hold %s : count=%d > %d!!!\n",
1318 PR_MyThreadId(),
1319 (lock_status == MAP_WLOCK_HELD) ? "MAP_WLOCK_HELD" : "MAP_RLOCK_HELD",
1320 lock_count, lock_count + 1);
1321 #endif
1322 set_plugin_monitor_count(lock_count + 1);
1323 return 0;
1324 }
12251325
12261326 int
12271327 map_wrlock(void)
12281328 {
1229 return wrap_rwlock_wrlock(map_data.lock);
1230 }
1329 int lock_status;
1330 int lock_count;
1331 int rc = 0;
1332
1333 if (rw_monitor_enabled() == MAP_MONITOR_DISABLED) {
1334 /* This is not initialized used the old way */
1335 slapi_log_error(SLAPI_LOG_FATAL, "schema-compat",
1336 "map wrlock: old way MAP_MONITOR_DISABLED\n");
1337 return wrap_rwlock_wrlock(map_data.lock);
1338 }
1339
1340 lock_status = get_plugin_monitor_status();
1341 lock_count = get_plugin_monitor_count();
1342
1343 #if DEBUG_MAP_LOCK
1344 slapi_log_error(SLAPI_LOG_FATAL, "map wrlock",
1345 "thread_id = %p (call level = %d)\n", (void *) PR_MyThreadId(), wrap_get_call_level());
1346 #endif
1347 if (lock_status == MAP_RWLOCK_UNINIT) {
1348 /* This is not initialized used the old way */
1349 slapi_log_error(SLAPI_LOG_FATAL, "schema-compat",
1350 "map wrlock: old way lock_status == MAP_LOCK_UNINIT\n");
1351
1352 return wrap_rwlock_wrlock(map_data.lock);
1353 }
1354
1355 if (lock_status == MAP_RWLOCK_FREE) {
1356 /* The lock is free, acquire it */
1357 #if DEBUG_MAP_LOCK
1358 slapi_log_error(SLAPI_LOG_FATAL, "schema-compat",
1359 "map wrlock: current lock_status == MAP_LOCK_FREE\n");
1360 #endif
1361
1362 set_plugin_monitor_count(1);
1363 #if DEBUG_MAP_LOCK
1364 if (lock_count != 0) {
1365 slapi_log_error(SLAPI_LOG_FATAL, "schema-compat",
1366 "map wrlock: (%"PRIx32") ALERT !!! count was %d --> 1\n", PR_MyThreadId(), lock_count);
1367 }
1368 #endif
1369 /* Acquire the slapi plugin in write */
1370 rc = plugin_wrlock();
1371 if (rc) {
1372 slapi_log_error(SLAPI_LOG_FATAL, "schemacompat",
1373 "map wrlock: (%"PRIx32") MAP_RWLOCK_FREE -> MAP_RLOCK_HELD: fail to read lock plugin lock (%d)\n", PR_MyThreadId(), rc);
1374 return rc;
1375 }
1376 #if DEBUG_MAP_LOCK
1377 slapi_log_error(SLAPI_LOG_FATAL, "schema-compat",
1378 "map wrlock: (%"PRIx32") MAP_RWLOCK_FREE --> MAP_WLOCK_HELD : count=%d\n", PR_MyThreadId(), 1);
1379 #endif
1380
1381 rc = wrap_rwlock_wrlock(map_data.lock);
1382 if (rc) {
1383 slapi_log_error(SLAPI_LOG_FATAL, "schema-compat",
1384 "map wrlock: (%"PRIx32") MAP_RWLOCK_FREE --> MAP_WLOCK_HELD : fail to write lock map lock (%d)\n", PR_MyThreadId(), rc);
1385 plugin_unlock();
1386 goto common;
1387 }
1388 } else {
1389 set_plugin_monitor_count(lock_count + 1);
1390 #if DEBUG_MAP_LOCK
1391 slapi_log_error(SLAPI_LOG_FATAL, "schema-compat",
1392 "map wrlock: (%"PRIx32") %s --> MAP_WLOCK_HELD : count=%d\n",
1393 PR_MyThreadId(),
1394 (lock_status == MAP_WLOCK_HELD) ? "MAP_WLOCK_HELD" : "MAP_RLOCK_HELD",
1395 lock_count + 1);
1396 #endif
1397
1398 if (lock_status == MAP_RLOCK_HELD) {
1399 /* lock is already acquired in read */
1400 #if DEBUG_MAP_LOCK
1401 slapi_log_error(SLAPI_LOG_FATAL, "schema-compat",
1402 "map wrlock: weird situation map lock is held in read and now required in write mode\n");
1403 #endif
1404 /* First free the lock held in read */
1405 rc = plugin_unlock();
1406 if (rc) {
1407 slapi_log_error(SLAPI_LOG_FATAL, "schema-compat",
1408 "map wrlock: fail to unlock plugin lock (%d)\n", rc);
1409 goto common;
1410 }
1411
1412 /* Second acquire it in write */
1413 rc = plugin_wrlock();
1414 if (rc) {
1415 slapi_log_error(SLAPI_LOG_FATAL, "schema-compat",
1416 "map wrlock: fail to write lock plugin lock (%d)\n", rc);
1417 goto common;
1418 }
1419 }
1420 }
1421
1422 common:
1423 set_plugin_monitor_status(MAP_WLOCK_HELD);
1424 return rc;
1425 }
12311426
12321427 int
12331428 map_unlock(void)
1234 {
1235 return wrap_rwlock_unlock(map_data.lock);
1236 }
1429 {
1430 int lock_status;
1431 int lock_count;
1432 int rc = 0;
1433
1434 if (rw_monitor_enabled() == MAP_MONITOR_DISABLED) {
1435 /* This is not initialized used the old way */
1436 slapi_log_error(SLAPI_LOG_FATAL, "schema-compat",
1437 "map_unlock: old way MAP_MONITOR_DISABLED\n");
1438 return wrap_rwlock_unlock(map_data.lock);
1439 }
1440
1441 lock_status = get_plugin_monitor_status();
1442 lock_count = get_plugin_monitor_count();
1443
1444 #if DEBUG_MAP_LOCK
1445 slapi_log_error(SLAPI_LOG_FATAL, "map_unlock",
1446 "thread_id = %p (call level = %d)\n", (void *) PR_MyThreadId(), wrap_get_call_level());
1447 #endif
1448 if (lock_status == MAP_RWLOCK_UNINIT) {
1449 /* This is not initialized used the old way */
1450 slapi_log_error(SLAPI_LOG_FATAL, "schema-compat",
1451 "map_unlock: old way lock_status == MAP_RWLOCK_UNINIT\n");
1452
1453 return wrap_rwlock_unlock(map_data.lock);
1454 }
1455
1456 if (lock_count == 1) {
1457 set_plugin_monitor_status(MAP_RWLOCK_FREE);
1458 rc = plugin_unlock();
1459 if (rc) {
1460 slapi_log_error(SLAPI_LOG_FATAL, "schema-compat",
1461 "map unlock: fail to unlock plugin lock (%d)\n", rc);
1462 goto common;
1463 }
1464 #if DEBUG_MAP_LOCK
1465 slapi_log_error(SLAPI_LOG_FATAL, "schema-compat",
1466 "map_unlock: (%p) %s --> MAP_RWLOCK_FREE : count=%d\n",
1467 (void *) PR_MyThreadId(),
1468 (lock_status == MAP_WLOCK_HELD) ? "MAP_WLOCK_HELD" : (lock_status == MAP_RLOCK_HELD) ? "MAP_RLOCK_HELD" : "MAP_RWLOCK_FREE",
1469 0);
1470 #endif
1471 rc = wrap_rwlock_unlock(map_data.lock);
1472 if (rc) {
1473 slapi_log_error(SLAPI_LOG_FATAL, "schema-compat",
1474 "map_unlock: fail to unlock map lock (%d)\n", rc);
1475 goto common;
1476 }
1477 }
1478 if (lock_count >= 1) {
1479 set_plugin_monitor_count(lock_count - 1);
1480 #if DEBUG_MAP_LOCK
1481 if (lock_count > 1) {
1482 slapi_log_error(SLAPI_LOG_FATAL, "schema-compat",
1483 "map_unlock: (%p) keep %s : count=%d\n",
1484 (void *) PR_MyThreadId(),
1485 (lock_status == MAP_WLOCK_HELD) ? "MAP_WLOCK_HELD" : (lock_status == MAP_RLOCK_HELD) ? "MAP_RLOCK_HELD" : "MAP_RWLOCK_FREE",
1486 lock_count - 1);
1487 } else {
1488 slapi_log_error(SLAPI_LOG_FATAL, "schema-compat",
1489 "map_unlock: (%p) is now %s : count=%d\n",
1490 (void *) PR_MyThreadId(),
1491 "MAP_RWLOCK_FREE",
1492 lock_count - 1);
1493 }
1494 #endif
1495 }
1496
1497 common:
1498 return rc;
1499 }
114114 const char *domain_name);
115115 int map_data_get_map_size(struct plugin_state *state,
116116 const char *domain_name, const char *map_name);
117 int plugin_rdlock(void);
118 int plugin_wrlock(void);
119 int plugin_unlock(void);
117120 int map_rdlock(void);
118121 int map_wrlock(void);
119122 int map_unlock(void);
966966 AUTH *request_auth, *reply_auth;
967967 char auth_buf[MAX_AUTH_BYTES];
968968 struct rpc_msg request, reply;
969 int auth_flavor, auth_len;
969 int auth_flavor;
970970 struct ypresp_val reply_val;
971971 struct ypresp_key_val reply_key_val;
972972 struct ypresp_all reply_all;
10561056 }
10571057 auth_marshall(reply_auth, &auth_xdrs);
10581058 auth_destroy(reply_auth);
1059 auth_len = xdr_getpos(&auth_xdrs);
1059 (void)xdr_getpos(&auth_xdrs);
10601060 xdr_destroy(&auth_xdrs);
10611061 slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id,
10621062 "built reply authenticator\n");
6161 #define PLUGIN_ID "schema-compat-plugin"
6262 #define PLUGIN_PREOP_ID PLUGIN_ID "-preop"
6363 #define PLUGIN_BETXN_PREOP_ID PLUGIN_ID "-betxn_preop"
64 #define PLUGIN_BE_POSTOP_ID PLUGIN_ID "-be_postop"
65 #define PLUGIN_BE_PREOP_ID PLUGIN_ID "-be_preop"
6466 #define PLUGIN_BETXN_POSTOP_ID PLUGIN_ID "-betxn_postop"
6567 #define PLUGIN_POSTOP_ID PLUGIN_ID "-postop"
6668 #define PLUGIN_INTERNAL_POSTOP_ID PLUGIN_ID "-internal-postop"
194196 if (state->plugin_base != NULL) {
195197 slapi_ch_free((void **)&state->plugin_base);
196198 }
199 if (ignored_containers_sdn) {
200 int i;
201 for (i = 0; ignored_containers_sdn[i]; i++) {
202 slapi_sdn_free(&ignored_containers_sdn[i]);
203 }
204 slapi_ch_free((void **)&ignored_containers_sdn);
205 }
197206 slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id,
198207 "plugin shutdown completed\n");
199208 return 0;
252261 slapi_log_error(SLAPI_LOG_PLUGIN,
253262 global_plugin_state->plugin_desc->spd_id,
254263 "error registering betxn postoperation "
264 "hooks\n");
265 return -1;
266 }
267 return 0;
268 }
269 static int
270 schema_compat_plugin_init_bepreop(Slapi_PBlock *pb)
271 {
272 slapi_pblock_set(pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_VERSION_03);
273 slapi_pblock_set(pb, SLAPI_PLUGIN_DESCRIPTION, &plugin_description);
274 slapi_pblock_set(pb, SLAPI_PLUGIN_PRIVATE, global_plugin_state);
275 if (backend_init_be_preop(pb, global_plugin_state) == -1) {
276 slapi_log_error(SLAPI_LOG_PLUGIN,
277 global_plugin_state->plugin_desc->spd_id,
278 "error registering be preoperation hooks\n");
279 return -1;
280 }
281 return 0;
282 }
283 static int
284 schema_compat_plugin_init_bepostop(Slapi_PBlock *pb)
285 {
286 slapi_pblock_set(pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_VERSION_03);
287 slapi_pblock_set(pb, SLAPI_PLUGIN_DESCRIPTION, &plugin_description);
288 slapi_pblock_set(pb, SLAPI_PLUGIN_PRIVATE, global_plugin_state);
289 if (backend_init_be_postop(pb, global_plugin_state) == -1) {
290 slapi_log_error(SLAPI_LOG_PLUGIN,
291 global_plugin_state->plugin_desc->spd_id,
292 "error registering be postoperation "
255293 "hooks\n");
256294 return -1;
257295 }
299337 "error setting up plugin\n");
300338 return -1;
301339 }
340
341 init_map_lock();
342
302343 /* Read global configuration. */
303344 if ((slapi_pblock_get(pb, SLAPI_PLUGIN_CONFIG_ENTRY,
304345 &plugin_entry) == 0) &&
340381 "error registering betxn preoperation plugin\n");
341382 return -1;
342383 }
384 if (slapi_register_plugin("bepreoperation", TRUE,
385 "schema_compat_plugin_init_bepreop",
386 schema_compat_plugin_init_bepreop,
387 PLUGIN_BE_PREOP_ID, NULL,
388 state->plugin_identity) != 0) {
389 slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id,
390 "error registering betxn preoperation plugin\n");
391 return -1;
392 }
343393 #endif
344394 if (slapi_register_plugin("postoperation", TRUE,
345395 "schema_compat_plugin_init_postop",
364414 "schema_compat_plugin_init_betxn_postop",
365415 schema_compat_plugin_init_betxn_postop,
366416 PLUGIN_BETXN_POSTOP_ID, NULL,
417 state->plugin_identity) != 0) {
418 slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id,
419 "error registering betxn postoperation plugin\n");
420 return -1;
421 }
422 if (slapi_register_plugin("bepostoperation", TRUE,
423 "schema_compat_plugin_init_bepostop",
424 schema_compat_plugin_init_bepostop,
425 PLUGIN_BE_POSTOP_ID, NULL,
367426 state->plugin_identity) != 0) {
368427 slapi_log_error(SLAPI_LOG_PLUGIN, state->plugin_desc->spd_id,
369428 "error registering betxn postoperation plugin\n");
7676 int
7777 main(int argc, char **argv)
7878 {
79 int s, ret, port;
79 int s, port;
80 int ret __attribute__ ((unused));
8081 s = socket(PF_INET, SOCK_DGRAM, 0);
8182 if (s == -1) {
8283 printf("error allocating socket\n");
9394 printf("error creating portmap/rpcbind client socket\n");
9495 return 1;
9596 }
96 setregid(2516, 2516);
97 setreuid(2510, 2510);
97 if (setregid(2516, 2516) == -1) {
98 printf("error setting real and effective group id %s\n",
99 strerror(errno));
100 return 1;
101 }
102 if (setreuid(2510, 2510) == -1) {
103 printf("error setting real and effective user id %s\n",
104 strerror(errno));
105 return 1;
106 }
98107 sleep(60);
99108 portmap_unregister("portmap", &s, port, YPPROG, YPVERS,
100109 AF_INET, IPPROTO_TCP, 0);
152152 wrap_stop_thread(struct wrapped_thread *t)
153153 {
154154 void *returned = NULL;
155 int ret __attribute__ ((unused));
155156 #ifdef USE_PTHREADS
156 write(t->stopfd[1], "", 1);
157 ret = write(t->stopfd[1], "", 1);
157158 close(t->stopfd[1]);
158159 pthread_join(t->tid, &returned);
159160 #endif
160161 #ifdef USE_NSPR_THREADS
161 write(t->stopfd[1], "", 1);
162 ret = write(t->stopfd[1], "", 1);
162163 close(t->stopfd[1]);
163164 PR_JoinThread(t->tid);
164165 returned = t->args.result;
0 Test with azure pipelines
1
2 Add pipeline definition that can be used to run build and test jobs in
3 dev.azure.com environment.
4
5 Following needs to be done to use the Azure Pipelines definition for
6 slapi-nis:
7
8 - Configure Azure DevOps organization
9 - Create public project there
10 - Clone your Git repository for slapi-nis from pagure.io
11 - On Azure side, navigate to Repos -> Files, choose your repo top
12 directory and click 'Clone'
13 - The 'Clone Repository' dialog will show how to clone the repository
14 with HTTPS or SSH. Choose SSH tab and note the URL.
15 - Set mirroring hook on Pagure's project site (Settings -> Hooks ->
16 Mirroring) by providing this URL
17 - Return back to the hook settings in Pagure and copy public SSH key
18 from there
19 - Choose 'Manage SSH keys' in the 'Clone Repository' dialog and add a
20 public SSH key there
21
22 After these actions a push to pagure project will automatically be
23 mirrored to Azure Repos repository.
24
25 Now a pipeline can be set up in Azure by picking up azure-pipelines.yml
26 file from the repo.
0 jobs:
1 - job: Build
2 pool:
3 vmImage: 'Ubuntu-16.04'
4 variables:
5 builddir: /__w/1/s
6 container:
7 image: f30/fedora-toolbox
8 endpoint: fedora-project-registry
9 steps:
10 - script: |
11 sudo rm -rf /var/cache/dnf/*
12 cd $(builddir)
13 sudo dnf makecache || :
14 sudo dnf -y install dnf-plugins-core rpm-build autoconf automake libtool \
15 /usr/bin/rpcgen 389-ds-base-devel libnsl2-devel \
16 libsss_nss_idmap-devel nspr-devel nss-devel \
17 openldap-devel pam-devel gdb gcc annobin make
18 sudo dnf builddep -y --spec slapi-nis.spec --best --allowerasing --setopt=install_weak_deps=False
19 displayName: Prepare build environment
20 - script: |
21 mkdir -p $(builddir)/dist
22 make -f .copr/Makefile outdir=$(builddir)/dist SUDO=sudo srpm
23 rpmbuild --rebuild \
24 --define "_topdir $(builddir)/build" \
25 --define "_sourcedir $(builddir)/build" \
26 --define "_specdir $(builddir)/build" \
27 --define "_builddir $(builddir)/build" \
28 --define "_srcrpmdir $(builddir)/dist" \
29 --define "_rpmdir $(builddir)/dist" \
30 $(builddir)/dist/*.src.rpm
31 displayName: Build packages
32 - script: |
33 mv $(builddir)/dist/*/*.rpm $(builddir)/dist/
34 ls -la $(builddir)/dist
35 displayName: List packages
36 - task: PublishPipelineArtifact@0
37 displayName: Publish packages
38 inputs:
39 artifactName: 'packages-$(Build.BuildId)-$(Agent.OS)-$(Agent.OSArchitecture)'
40 targetPath: $(Build.Repository.LocalPath)/dist
41 condition: always()
42
43 - job: Install_with_FreeIPA_packages
44 dependsOn: Build
45 condition: succeeded()
46 pool:
47 vmImage: 'Ubuntu-16.04'
48 variables:
49 builddir: /__w/1/s
50 container:
51 image: f30/fedora-toolbox
52 endpoint: fedora-project-registry
53 steps:
54 - checkout: none
55 - task: DownloadPipelineArtifact@0
56 displayName: Download pre-built packages
57 inputs:
58 artifactName: 'packages-$(Build.BuildId)-$(Agent.OS)-$(Agent.OSArchitecture)'
59 targetPath: $(Build.Repository.LocalPath)/dist
60 - script: |
61 rm -f $(builddir)/dist/*.src.rpm
62 displayName: Remove source package
63 - script: |
64 sudo rm -rf /var/cache/dnf/*
65 cd $(builddir)
66 sudo dnf makecache || :
67 sudo dnf -y install freeipa-server-dns freeipa-server $(builddir)/dist/*.rpm
68 displayName: Attempt package installation
69
1111 $(RPCGEN) -h -o $@ $^
1212 yp_xdr.c: ../../yp/yp.x
1313 $(RM) -f $@
14 $(RPCGEN) -c -o $@ $^
14 $(RPCGEN) -c -i 0 -o $@ $^
1515 yp_clnt.c: ../../yp/yp.x
1616 $(RM) -f $@
1717 $(RPCGEN) -l -o $@ $^
3333 #include <rpc/rpc.h>
3434 #include "../../yp/yp.h"
3535
36 typedef int (*xdrrec_proc_t)(void *, void *, int);
37
3638 static struct sockaddr_in server;
3739 static int connected;
3840
161163 static int
162164 all(CLIENT *client, FILE *output, int argc, char **argv)
163165 {
164 ypresp_all *ret;
165 int i, sock;
166 int sock;
166167 ypreq_nokey nokey;
167168 struct rpc_msg req, rep;
168169 struct ypresp_all resp;
188189 }
189190
190191 memset(&s, 0, sizeof(s));
191 xdrrec_create(&s, 0, 0, (char *) &sock, &readjunk, &writejunk);
192 xdrrec_create(&s, 0, 0, (char *) &sock, (xdrrec_proc_t) &readjunk, (xdrrec_proc_t) &writejunk);
192193 s.x_op = XDR_ENCODE;
193194
194195 memset(&req, 0, sizeof(req));
217218 xdr_destroy(&s);
218219
219220 memset(&s, 0, sizeof(s));
220 xdrrec_create(&s, 0, 0, (char *) &sock, &readjunk, &writejunk);
221 xdrrec_create(&s, 0, 0, (char *) &sock, (xdrrec_proc_t) &readjunk, (xdrrec_proc_t) &writejunk);
221222 s.x_op = XDR_DECODE;
222223 xdrrec_skiprecord(&s);
223224
66 $(RPCGEN) -h -o $@ $^
77 yp_xdr.c: yp.x
88 $(RM) -f $@
9 $(RPCGEN) -c -o $@ $^
9 $(RPCGEN) -c -i 0 -o $@ $^
1010 yp_clnt.c: yp.x
1111 $(RM) -f $@
1212 $(RPCGEN) -l -o $@ $^