From c44f9ca81afa6cbf817159d37b0695d6462866eb Mon Sep 17 00:00:00 2001 From: Alexander Bokovoy Date: Apr 23 2019 06:39:08 +0000 Subject: [PATCH 1/4] Cast callbacks passed to xdrrec_create to a right type With newer compilers there are stricter checks on callback type validation. As result, we need to cast the callback signatures even though it makes no practical difference in our test case. --- diff --git a/tests/clients/yp.c b/tests/clients/yp.c index 200d591..bc2da1f 100644 --- a/tests/clients/yp.c +++ b/tests/clients/yp.c @@ -34,6 +34,8 @@ #include #include "../../yp/yp.h" +typedef int (*xdrrec_proc_t)(void *, void *, int); + static struct sockaddr_in server; static int connected; @@ -189,7 +191,7 @@ all(CLIENT *client, FILE *output, int argc, char **argv) } memset(&s, 0, sizeof(s)); - xdrrec_create(&s, 0, 0, (char *) &sock, &readjunk, &writejunk); + xdrrec_create(&s, 0, 0, (char *) &sock, (xdrrec_proc_t) &readjunk, (xdrrec_proc_t) &writejunk); s.x_op = XDR_ENCODE; memset(&req, 0, sizeof(req)); @@ -218,7 +220,7 @@ all(CLIENT *client, FILE *output, int argc, char **argv) xdr_destroy(&s); memset(&s, 0, sizeof(s)); - xdrrec_create(&s, 0, 0, (char *) &sock, &readjunk, &writejunk); + xdrrec_create(&s, 0, 0, (char *) &sock, (xdrrec_proc_t) &readjunk, (xdrrec_proc_t) &writejunk); s.x_op = XDR_DECODE; xdrrec_skiprecord(&s); From a4f645e09d92a8b8f7a80f939091689075d53de1 Mon Sep 17 00:00:00 2001 From: Alexander Bokovoy Date: Apr 23 2019 06:40:59 +0000 Subject: [PATCH 2/4] Define send_ldap_result as an external function prototype 389-ds does not expose send_ldap_result() as a public API. However, we depend on it because slapi_send_ldap_result() is not usable for the specific use case of the schema compatibility plugin. --- diff --git a/src/back-sch.c b/src/back-sch.c index 9201c2e..f6211bc 100644 --- a/src/back-sch.c +++ b/src/back-sch.c @@ -55,6 +55,12 @@ #include "map.h" #include "back-sch.h" +/* + * This is not a public function in 389-ds but we need to use it in backend_search_cb(), + * see a comment there on the difference between slapi_send_ldap_result() and send_ldap_result(). + */ +extern void send_ldap_result(Slapi_PBlock *pb, int err, char *matched, char *text, int nentries, struct berval **urls); + static int backend_passwdmod_extop(Slapi_PBlock *pb); backend_extop_handlers_t extop_handlers[] = {{EXTOP_PASSWD_OID, (IFP) backend_passwdmod_extop}, {NULL, NULL}}; From dc3c95cf5b5a2c2d5e7f81ed02f2d9bf3c9acb9f Mon Sep 17 00:00:00 2001 From: Alexander Bokovoy Date: Apr 23 2019 06:42:41 +0000 Subject: [PATCH 3/4] Declare transaction-aware callbacks for schema compat plugin Schema compatibility plugin provides two transaction-aware callbacks. The functions need to be declared as they are defined and used in different compilation units. --- diff --git a/src/backend.h b/src/backend.h index f0a5bbb..4034704 100644 --- a/src/backend.h +++ b/src/backend.h @@ -68,6 +68,11 @@ int backend_init_postop(struct slapi_pblock *pb, struct plugin_state *state); int backend_init_internal_postop(struct slapi_pblock *pb, struct plugin_state *state); +/* Only used for schema compatibility plugin*/ +int backend_init_be_preop(Slapi_PBlock *pb, struct plugin_state *state); +int backend_init_be_postop(Slapi_PBlock *pb, struct plugin_state *state); + + /* Read the server's name. */ int backend_read_master_name(struct plugin_state *state, struct slapi_pblock *pb, From 1d9e79557df660f4556edb59bedead00eda9b757 Mon Sep 17 00:00:00 2001 From: Alexander Bokovoy Date: Apr 23 2019 06:44:48 +0000 Subject: [PATCH 4/4] Use portable definitions for printing PRUint32 values Also include proper headers for NSPR thread-local variable handling. Fixes covscan warnings. --- diff --git a/src/back-shr.c b/src/back-shr.c index b348869..472846a 100644 --- a/src/back-shr.c +++ b/src/back-shr.c @@ -37,7 +37,9 @@ #endif #include -#include +#include +/* NSPR private API for thread-local variables */ +#include #include "../yp/yp.h" #ifdef HAVE_TCPD_H diff --git a/src/map.c b/src/map.c index f80f465..3be60b4 100644 --- a/src/map.c +++ b/src/map.c @@ -23,6 +23,7 @@ #include "config.h" #endif +#include #include #include #include @@ -40,6 +41,9 @@ #include +/* NSPR private API for thread-local variables */ +#include + #include "backend.h" #include "disp-nis.h" #include "map.h" @@ -1264,7 +1268,7 @@ map_rdlock(void) #if DEBUG_MAP_LOCK slapi_log_error(SLAPI_LOG_FATAL, "map_rdlock", - "thread_id = %p (call level = %d)\n", (void *) PR_MyThreadId(), wrap_get_call_level()); + "thread_id = %"PRIx32" (call level = %d)\n", PR_MyThreadId(), wrap_get_call_level()); #endif if (lock_status == MAP_RWLOCK_UNINIT) { /* This is not initialized used the old way */ @@ -1284,7 +1288,7 @@ map_rdlock(void) #if DEBUG_MAP_LOCK if (lock_count != 0) { slapi_log_error(SLAPI_LOG_FATAL, "schemacompat", - "map rdlock: (%p) ALERT !!! count was %d -> 1\n", (void *) PR_MyThreadId(), lock_count); + "map rdlock: (%"PRIx32") ALERT !!! count was %d -> 1\n", PR_MyThreadId(), lock_count); } #endif @@ -1292,12 +1296,12 @@ map_rdlock(void) rc = plugin_rdlock(); if (rc) { slapi_log_error(SLAPI_LOG_FATAL, "schemacompat", - "map rdlock: (%p) MAP_RWLOCK_FREE -> MAP_RLOCK_HELD: fail to read lock plugin lock (%d)\n", (void *) PR_MyThreadId(), rc); + "map rdlock: (%"PRIx32") MAP_RWLOCK_FREE -> MAP_RLOCK_HELD: fail to read lock plugin lock (%d)\n", PR_MyThreadId(), rc); return rc; } #if DEBUG_MAP_LOCK slapi_log_error(SLAPI_LOG_FATAL, "schemacompat", - "map rdlock: (%p) MAP_RWLOCK_FREE -> MAP_RLOCK_HELD : count=%d\n", (void *) PR_MyThreadId(), 1); + "map rdlock: (%"PRIx32") MAP_RWLOCK_FREE -> MAP_RLOCK_HELD : count=%d\n", PR_MyThreadId(), 1); #endif rc = wrap_rwlock_rdlock(map_data.lock); if (rc) { @@ -1311,8 +1315,8 @@ map_rdlock(void) #if DEBUG_MAP_LOCK slapi_log_error(SLAPI_LOG_FATAL, "schemacompat", - "map rdlock: (%p) was already hold %s : count=%d > %d!!!\n", - (void *) PR_MyThreadId(), + "map rdlock: (%x"PRIx32") was already hold %s : count=%d > %d!!!\n", + PR_MyThreadId(), (lock_status == MAP_WLOCK_HELD) ? "MAP_WLOCK_HELD" : "MAP_RLOCK_HELD", lock_count, lock_count + 1); #endif @@ -1360,25 +1364,25 @@ map_wrlock(void) #if DEBUG_MAP_LOCK if (lock_count != 0) { slapi_log_error(SLAPI_LOG_FATAL, "schema-compat", - "map wrlock: (%p) ALERT !!! count was %d --> 1\n", (void *) PR_MyThreadId(), lock_count); + "map wrlock: (%"PRIx32") ALERT !!! count was %d --> 1\n", PR_MyThreadId(), lock_count); } #endif /* Acquire the slapi plugin in write */ rc = plugin_wrlock(); if (rc) { slapi_log_error(SLAPI_LOG_FATAL, "schemacompat", - "map wrlock: (%p) MAP_RWLOCK_FREE -> MAP_RLOCK_HELD: fail to read lock plugin lock (%d)\n", (void *) PR_MyThreadId(), rc); + "map wrlock: (%"PRIx32") MAP_RWLOCK_FREE -> MAP_RLOCK_HELD: fail to read lock plugin lock (%d)\n", PR_MyThreadId(), rc); return rc; } #if DEBUG_MAP_LOCK slapi_log_error(SLAPI_LOG_FATAL, "schema-compat", - "map wrlock: (%p) MAP_RWLOCK_FREE --> MAP_WLOCK_HELD : count=%d\n", (void *) PR_MyThreadId(), 1); + "map wrlock: (%"PRIx32") MAP_RWLOCK_FREE --> MAP_WLOCK_HELD : count=%d\n", PR_MyThreadId(), 1); #endif rc = wrap_rwlock_wrlock(map_data.lock); if (rc) { slapi_log_error(SLAPI_LOG_FATAL, "schema-compat", - "map wrlock: (%p) MAP_RWLOCK_FREE --> MAP_WLOCK_HELD : fail to write lock map lock (%d)\n", (void *) PR_MyThreadId(), rc); + "map wrlock: (%"PRIx32") MAP_RWLOCK_FREE --> MAP_WLOCK_HELD : fail to write lock map lock (%d)\n", PR_MyThreadId(), rc); plugin_unlock(); goto common; } @@ -1386,8 +1390,8 @@ map_wrlock(void) set_plugin_monitor_count(lock_count + 1); #if DEBUG_MAP_LOCK slapi_log_error(SLAPI_LOG_FATAL, "schema-compat", - "map wrlock: (%p) %s --> MAP_WLOCK_HELD : count=%d\n", - (void *) PR_MyThreadId(), + "map wrlock: (%"PRIx32") %s --> MAP_WLOCK_HELD : count=%d\n", + PR_MyThreadId(), (lock_status == MAP_WLOCK_HELD) ? "MAP_WLOCK_HELD" : "MAP_RLOCK_HELD", lock_count + 1); #endif