From: Stefan Metzmacher Date: Thu, 5 Aug 2021 16:03:14 +0000 (+0200) Subject: lib/replace: use dlsym(RTLD_DEFAULT,) for {nss,nss_host,uid,socket}_wrapper_enabled() X-Git-Tag: tdb-1.4.6~500 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=05ca7b9809d7329aea93fc8f1b8b2e54703f1dbd;p=thirdparty%2Fsamba.git lib/replace: use dlsym(RTLD_DEFAULT,) for {nss,nss_host,uid,socket}_wrapper_enabled() 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 Reviewed-by: Andrew Bartlett Reviewed-by: Andreas Schneider --- diff --git a/lib/replace/cwrap.c b/lib/replace/cwrap.c deleted file mode 100644 index adc5c1e2a39..00000000000 --- a/lib/replace/cwrap.c +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Unix SMB/CIFS implementation. - * - * Replaceable functions by cwrap - * - * Copyright (c) 2014 Andreas Schneider - * - * ** 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 . - */ - -#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; -} diff --git a/lib/replace/replace.h b/lib/replace/replace.h index a546185d47a..8609d84322c 100644 --- a/lib/replace/replace.h +++ b/lib/replace/replace.h @@ -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) { diff --git a/lib/replace/wscript b/lib/replace/wscript index 8c69a0c2c39..df054797445 100644 --- a/lib/replace/wscript +++ b/lib/replace/wscript @@ -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'