lib/replace: use dlsym(RTLD_DEFAULT,) for {nss,nss_host,uid,socket}_wrapper_enabled()
authorStefan Metzmacher <metze@samba.org>
Thu, 5 Aug 2021 16:03:14 +0000 (18:03 +0200)
committerStefan Metzmacher <metze@samba.org>
Tue, 30 Nov 2021 15:53:34 +0000 (15:53 +0000)
We should not provide the symbols ourself instead we should just check
if they are already available when we want to check the result.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14780

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
lib/replace/cwrap.c [deleted file]
lib/replace/replace.h
lib/replace/wscript

diff --git a/lib/replace/cwrap.c b/lib/replace/cwrap.c
deleted file mode 100644 (file)
index adc5c1e..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-/*
- * Unix SMB/CIFS implementation.
- *
- * Replaceable functions by cwrap
- *
- * Copyright (c) 2014      Andreas Schneider <asn@samba.org>
- *
- *   ** NOTE! The following LGPL license applies to the replace
- *   ** library. This does NOT imply that all of Samba is released
- *   ** under the LGPL
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, see <http://www.gnu.org/licenses/>.
- */
-
-#include "replace.h"
-
-bool nss_wrapper_enabled(void)
-{
-       return false;
-}
-
-bool nss_wrapper_hosts_enabled(void)
-{
-       return false;
-}
-
-bool socket_wrapper_enabled(void)
-{
-       return false;
-}
-
-bool uid_wrapper_enabled(void)
-{
-       return false;
-}
index a546185d47abb4822658cc76ad18ffd5fa04cd74..8609d84322cd6c2ed43bc111311aa281a759108b 100644 (file)
@@ -982,10 +982,59 @@ ssize_t rep_copy_file_range(int fd_in,
 # endif /* HAVE_FALLTHROUGH_ATTRIBUTE */
 #endif /* FALL_THROUGH */
 
-bool nss_wrapper_enabled(void);
-bool nss_wrapper_hosts_enabled(void);
-bool socket_wrapper_enabled(void);
-bool uid_wrapper_enabled(void);
+struct __rep_cwrap_enabled_state {
+       const char *fnname;
+       bool cached;
+       bool retval;
+};
+
+static inline bool __rep_cwrap_enabled_fn(struct __rep_cwrap_enabled_state *state)
+{
+       bool (*__wrapper_enabled_fn)(void) = NULL;
+
+       if (state->cached) {
+               return state->retval;
+       }
+       state->retval = false;
+       state->cached = true;
+
+       __wrapper_enabled_fn = dlsym(RTLD_DEFAULT, state->fnname);
+       if (__wrapper_enabled_fn == NULL) {
+               return state->retval;
+       }
+
+       state->retval = __wrapper_enabled_fn();
+       return state->retval;
+}
+
+static inline bool nss_wrapper_enabled(void)
+{
+       struct __rep_cwrap_enabled_state state = {
+               .fnname = "nss_wrapper_enabled",
+       };
+       return __rep_cwrap_enabled_fn(&state);
+}
+static inline bool nss_wrapper_hosts_enabled(void)
+{
+       struct __rep_cwrap_enabled_state state = {
+               .fnname = "nss_wrapper_hosts_enabled",
+       };
+       return __rep_cwrap_enabled_fn(&state);
+}
+static inline bool socket_wrapper_enabled(void)
+{
+       struct __rep_cwrap_enabled_state state = {
+               .fnname = "socket_wrapper_enabled",
+       };
+       return __rep_cwrap_enabled_fn(&state);
+}
+static inline bool uid_wrapper_enabled(void)
+{
+       struct __rep_cwrap_enabled_state state = {
+               .fnname = "uid_wrapper_enabled",
+       };
+       return __rep_cwrap_enabled_fn(&state);
+}
 
 static inline bool _hexcharval(char c, uint8_t *val)
 {
index 8c69a0c2c391b21081ff122e6b8fed6f024b8e3a..df054797445369bec5dfbfc46c4992278097909c 100644 (file)
@@ -882,7 +882,6 @@ def build(bld):
     )
 
     REPLACE_SOURCE = REPLACE_HOSTCC_SOURCE
-    REPLACE_SOURCE += ' cwrap.c'
 
     if not bld.CONFIG_SET('HAVE_DLOPEN'):        REPLACE_SOURCE += ' dlfcn.c'
     if not bld.CONFIG_SET('HAVE_POLL'):          REPLACE_SOURCE += ' poll.c'