1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-25 23:21:54 +03:00
samba-mirror/lib/util
Stefan Metzmacher 66e90b7391 nsswitch: reduce dependecies to private libraries and link static/builtin if possible
Over the last month I got more and more reports,
that it's not possible to use a custom Samba version
on systems with sssd being installed, which depends on some
specific samba libraries installed in the system.

One major problem is that the custom libnss_winbind.so.2
depends on the libreplace-samba4.so of the custom build
and also injects an RPATH into the running process.
When sssd uses any nss library call it will get this,
when it then tries to load some of its plugins via dlopen(),
e.g.

ldd /usr/lib64/sssd/libsss_ad.so| grep samba

   libsamba-util.so.0 => /lib64/libsamba-util.so.0
   libreplace-samba4.so => /usr/lib64/samba/libreplace-samba4.so
   libsamba-security-samba4.so => /usr/lib64/samba/libsamba-security-samba4.so
   libsamba-errors.so.1 => /lib64/libsamba-errors.so.1
   libsamba-debug-samba4.so => /usr/lib64/samba/libsamba-debug-samba4.so
   libgenrand-samba4.so => /usr/lib64/samba/libgenrand-samba4.so
   libsocket-blocking-samba4.so => /usr/lib64/samba/libsocket-blocking-samba4.so
   libtime-basic-samba4.so => /usr/lib64/samba/libtime-basic-samba4.so
   libsys-rw-samba4.so => /usr/lib64/samba/libsys-rw-samba4.so
   libiov-buf-samba4.so => /usr/lib64/samba/libiov-buf-samba4.so

When that loads dlopen() will fail as a soname libreplace-samba4.so is
already loaded, but the symbol version within the other one don't match, as the
contain the exact version, e.g. replace_dummy@@SAMBA_4.13.3.

This is just an example and similar things can happen in all situations
where we provide libraries, which are potentially injected into every
process of the running system. These should only depend on libc.so and
related basic system libraries in order to avoid the problem.

We have the following libraries, which are in the that category:

- libnss_winbind.so.2
- libnss_wins.so.2
- pam_winbind.so
- winbind_krb5_locator.so
- async_dns_krb5_locator.so

The rules of library loading are really complex and symbol versioning
is not enough to solve it, only the combination of unique soname and
unique symbol version suffix seem to solve the problem, but injecting
an RPATH is still a problem.

In order to solve the problem I experimented with adding SAMBA_SUBSYSTEM()
definitions with 'hide_symbols=True' in order to do some static linking
of selected components, e.g.

   bld.SAMBA_SUBSYSTEM('replace-hidden',
                       source=REPLACE_SOURCE,
                       group='base_libraries',
                       hide_symbols=True,
                       deps='dl attr' + extra_libs)

It's relatively simple to get to the point where the following are
completely static:

- libnss_winbind.so.2
- libnss_wins.so.2
- pam_winbind.so
- winbind_krb5_locator.so

But 'async_dns_krb5_locator.so' links in almost everything!
It seems we install the krb5 plugins into our own $MODULESDIR/krb5/,
so it may not be so critical, as long it's the admin who created
the desired symlinks into the location the kerberos libraries search
for plugins. Note the at least the locator plugins are always loaded
without any configuration, every .so in a special path are loaded with dlopen().
This is done by every application using kerberos, so we load a lot of samba libraries
into them.

Packagers should not put async_dns_krb5_locator.so (nor a symlink) into
the path that's reachable by libkrb5.so.

As a longterm solution we may want to change async_dns_krb5_locator.so
to use a helper process with posix_spawn() instead of doing everything
within the process.

Note I added hiden_symbols=True to the nss modules for Linux and
FreeBSD only, because these are the only platforms I'm able to test
on. We most likely should do the same on other platforms, but some
with access to the platform should provide a tested patch.

In order to avoid manual definitions of SAMBA_SUBSYSTEMS() with
'-hidden', I added the 'provide_builtin_linking=True' option,
as the logic is very similar to what we already have with the
'--builtin-libraries=BUILTIN_LIBRARIES' configure option.

SAMBA_PLUGIN() is used in order to use SAMBA_LIBRARY() in order
to make it more strict that these plugins can't be used as
normal depedency by other subsystems and libraries.

While being there it was easy enough to make libwbclient.so
also standalone without dependecies to other samba libraries.

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>
2021-11-30 15:53:34 +00:00
..
charset charset_macosxfs.c: fix compilation on macOS 2021-10-13 01:42:35 +00:00
tests lib: add a test for null_nttime(NTTIME_THAW) 2021-10-28 18:11:28 +00:00
access.c lib:util: Remove NIS support from string_match() 2021-04-22 17:57:30 +00:00
access.h lib: util: Add allow_access_nolog(). 2016-11-16 12:41:09 +01:00
asn1.c asn1: Remove unused function asn1_check_enumerated() 2021-04-01 17:50:49 +00:00
asn1.h asn1: Remove unused function asn1_check_enumerated() 2021-04-01 17:50:49 +00:00
attr.h replace, attr.: use function attributes only if supported by feature macro (or old gcc) 2020-05-24 23:55:36 +00:00
base64.c lib: Avoid includes.h in base64.c 2016-05-04 01:28:23 +02:00
base64.h lib: Give base64.c its own .h 2016-05-04 01:28:23 +02:00
become_daemon.c lib:util: Fix log level for normal startup message 2021-05-20 15:07:28 +00:00
become_daemon.h lib: Remove close_low_fds() 2021-04-27 13:24:35 +00:00
binsearch.h binsearch.h: Re-licence under LGPLv3 per agreement of the copyright holders 2017-09-22 21:20:23 +02:00
bitmap.c lib:util: Fix undefined behavior in bitmap.c 2018-11-22 22:13:27 +01:00
bitmap.h
blocking.c lib: Provide a meaningful errno if FD_CLOEXEC is missing 2021-01-26 00:10:31 +00:00
blocking.h lib/util: Add a generic definition for set_close_on_exec 2016-06-08 10:33:19 +02:00
bytearray.h lib:util: Add (PULL|PUSH)_(BE|LE)_I(8|16|32|64) byterarray macros 2020-02-21 03:35:58 +00:00
byteorder.h lib:util: Add comments to use bytearray.h to byteorder.h 2020-02-21 02:09:33 +00:00
charset_compat.h
close_low_fd.c
close_low_fd.h
data_blob.c lib: Use TALLOC_FREE() in data_blob_free() 2021-08-06 17:22:30 +00:00
data_blob.h
debug_s3.c debug: Add new smb.conf option "debug syslog format" 2021-11-01 07:29:47 +00:00
debug_s3.h
debug.c lib/debug: in debug_set_logfile() call reopen_logs_internal() 2021-11-11 13:49:32 +00:00
debug.h debug: Add debug_syslog_format setting 2021-11-01 06:37:32 +00:00
discard.h lib:util: Move discard_const(_p) to own header for libndr.h 2019-02-14 15:59:26 +01:00
dlinklist.h DLIST_REMOVE: clang: Fix dereference of a null pointer warning 2019-06-11 12:10:17 +00:00
Doxyfile
dprintf.c lib/util: Fix format-nonliteral warning 2016-08-24 01:33:50 +02:00
fault.c lib: Avoid all_string_sub() in smb_panic() 2021-01-12 00:10:30 +00:00
fault.h lib/util/fault.c: Unify printing of the stack trace with the INTERNAL ERROR string 2020-02-27 05:09:44 +00:00
fsusage.c
genrand_util.c lib: Move generate_unique_u64_state into generate_unique_u64() 2020-11-10 19:49:33 +00:00
genrand.c lib:util: Fix documentation for random number functions 2019-08-14 15:07:24 +00:00
genrand.h lib:util: Fix documentation for random number functions 2019-08-14 15:07:24 +00:00
getpass.c
gpfswrap.c lib/gpfswrap: add gpfs_set_times_path() wrapper 2021-08-26 19:18:31 +00:00
gpfswrap.h lib/gpfswrap: add gpfs_set_times_path() wrapper 2021-08-26 19:18:31 +00:00
idtree_random.c
idtree_random.h
idtree.c lib:util: Fix undefined behavior in idtree 2018-11-22 22:13:27 +01:00
idtree.h lib: Remove a duplicate function prototype 2019-08-19 23:14:38 +00:00
iov_buf.c lib/util: clang: Fix 'Null pointer passed as an argument' 2019-07-08 09:30:09 +00:00
iov_buf.h lib/util: add and use iov_concat 2017-04-18 22:54:15 +02:00
mainpage.dox
memcache.c lib:util: Avoid free'ing our own pointer 2021-02-03 10:57:01 +00:00
memcache.h memcache: Add new cache type for dfree information 2018-05-25 22:52:12 +02:00
memory.h lib:util: Sync memory.h with replace.h 2019-04-30 23:18:26 +00:00
mkdir_p.c lib:util: Fix string check in mkdir_p() 2018-05-17 17:30:09 +02:00
mkdir_p.h gpo: move mkdir_p to lib/util 2017-11-20 21:41:14 +01:00
modules.c lib: Give util_paths.c its own header 2017-06-24 01:21:10 +02:00
ms_fnmatch.c lib/util: clang: Fix a dereference of a null pointer warning(s) 2019-06-11 12:10:17 +00:00
msghdr.c util: Fix signed/unsigned comparisons by casting 2019-07-01 08:00:29 +00:00
msghdr.h lib: Move msghdr to lib/util/ 2016-06-07 14:34:10 +02:00
params.c lib/util: add pm_process_with_flags to allow parsing ini files with empty values 2017-01-06 12:28:19 +01:00
pidfile.c lib: Make pidfile_path_create() return the existing PID on conflict 2021-03-16 17:09:32 +00:00
pidfile.h lib: Make pidfile_path_create() return the existing PID on conflict 2021-03-16 17:09:32 +00:00
rbtree.c lib/util: clang: Fix dereference of a null pointer warning 2019-06-11 12:10:17 +00:00
rbtree.h
README
rfc1738.c lib: Use hex_byte() in rfc1738_unescape() 2021-01-08 20:31:33 +00:00
safe_string.h lib/util: remove extra safe_string.h file 2020-08-28 02:18:40 +00:00
samba_modules.h lib:util: Make probing of modules more secure 2017-06-06 18:36:07 +02:00
samba_util.h lib: Add talloc_asprintf_addbuf() 2021-10-08 19:28:31 +00:00
samba-util.pc.in
select.c lib: Avoid an includes.h 2017-03-20 12:20:08 +01:00
select.h
server_id_db.c lib: Fix return of server_id_db_prune_name() 2019-07-03 10:51:32 +00:00
server_id_db.h
server_id.c lib: Slightly simplify server_id_set_disconnected() 2021-06-04 17:34:06 +00:00
server_id.h lib: Add server_id_cmp() 2019-09-17 22:49:36 +00:00
setid.c lib:util: Always include unistd.h for setgroups 2018-11-22 22:13:27 +01:00
setid.h
signal.c
signal.h
smb_strtox.c lib: fix smb_strtox.[c|h] license header 2020-08-05 10:17:06 +00:00
smb_strtox.h lib: fix smb_strtox.[c|h] license header 2020-08-05 10:17:06 +00:00
smb_threads_internal.h
smb_threads.c
smb_threads.h lib: smb_threads: fix access before init bug 2018-07-04 21:07:09 +02:00
string_wrappers.h string_wrappers: include replace.h 2020-08-28 00:56:34 +00:00
strv_util.c util: Fix include file order 2018-11-30 08:12:31 +01:00
strv_util.h
strv.c lib: Allow parsing a strv from a non-talloc const buf 2017-11-29 16:59:16 +01:00
strv.h lib: Fix includes in strv.h 2021-04-19 18:18:31 +00:00
substitute.c util:str_sub: talloc_free on error 2021-03-11 21:42:43 +00:00
substitute.h lib/util: Replace buggy string_sub_talloc() with talloc_string_sub() in lib/util 2021-03-10 08:06:25 +00:00
sys_popen.c lib: Fix CID 1445648 Null pointer dereferences 2019-05-28 20:27:14 +00:00
sys_popen.h lib: util: Finally remove possibilities of using sys_popen() unsafely. 2019-05-24 19:00:06 +00:00
sys_rw_data.c util: Fix signed/unsigned comparisons by casting 2019-07-01 08:00:29 +00:00
sys_rw_data.h
sys_rw.c lib: add sys_block_align[_truncate]() 2021-10-08 19:28:32 +00:00
sys_rw.h lib: add sys_block_align[_truncate]() 2021-10-08 19:28:32 +00:00
system.c
talloc_keep_secret.c lib:util: Add support to keep talloc chunks secret 2019-04-03 06:48:21 +00:00
talloc_keep_secret.h lib:util: Add support to keep talloc chunks secret 2019-04-03 06:48:21 +00:00
talloc_report_printf.c lib: Add talloc_full_report_printf() 2019-09-18 20:10:24 +00:00
talloc_report_printf.h lib: Add talloc_full_report_printf() 2019-09-18 20:10:24 +00:00
talloc_report.c util: Fix signed/unsigned comparisons by casting 2019-07-01 08:00:29 +00:00
talloc_report.h
talloc_stack.c talloc_stack: Call talloc destructors while frame is still around 2018-06-23 04:56:44 +02:00
talloc_stack.h
tevent_debug.c
tevent_ntstatus.c
tevent_ntstatus.h
tevent_req_profile.c lib: Avoid the use of open_memstream in tevent_req_profile_string 2018-10-08 22:17:11 +02:00
tevent_req_profile.h lib: Avoid the use of open_memstream in tevent_req_profile_string 2018-10-08 22:17:11 +02:00
tevent_unix.c
tevent_unix.h
tevent_werror.c werror: replace WERR_NOMEM with WERR_NOT_ENOUGH_MEMORY in lib/util/tevent_werror.c 2016-09-28 00:04:18 +02:00
tevent_werror.h
tfork.c lib: Fix a typo 2021-04-19 19:07:01 +00:00
tfork.h lib: Fix a typo 2019-10-02 08:01:40 +00:00
tftw.c lib: Remove some unneeded #includes from tftw.c 2019-10-02 08:01:40 +00:00
tftw.h util: Add file tree walk interface 2019-01-28 15:44:18 +01:00
time_basic.c
time_basic.h
time.c lib: handle NTTIME_THAW in nt_time_to_full_timespec() 2021-10-28 18:11:28 +00:00
time.h lib: add NTTIME_THAW 2021-10-28 18:11:28 +00:00
tini.c lib/util: add pm_process_with_flags to allow parsing ini files with empty values 2017-01-06 12:28:19 +01:00
tini.h lib/util: add pm_process_with_flags to allow parsing ini files with empty values 2017-01-06 12:28:19 +01:00
tiniparser.c lib: CID 1452289: API usage errors (USE_AFTER_FREE) 2019-08-14 07:39:38 +00:00
tiniparser.h Add fuzzing binary for tiniparser 2019-08-07 06:07:28 +00:00
tsort.h
unix_match.c lib/util: Move unix_wild_match() from source3/lib/util to lib/util/ 2016-11-16 12:41:09 +01:00
unix_match.h lib/util: Move unix_wild_match() from source3/lib/util to lib/util/ 2016-11-16 12:41:09 +01:00
unix_privs.c
util_file.c lib: Fix file_lines_parse() to do what people expect. Much safer to use. 2020-11-13 16:22:32 +00:00
util_id.c
util_ldb.c
util_ldb.h
util_net.c lib: Fix samba_sockaddr_[get|set]_port 2021-03-09 22:36:28 +00:00
util_net.h lib: Add samba_sockaddr_[gs]et_port() 2021-01-11 13:19:32 +00:00
util_paths.c s3: lib: Fix missing TALLOC_FREE in error code path. 2020-07-14 07:42:54 +00:00
util_paths.h lib:util: Add path_expand_tilde() 2020-05-15 13:18:38 +00:00
util_process.c lib/util: Make prctl_set_comment take a printf format string 2020-02-27 03:42:35 +00:00
util_process.h lib/util: Make prctl_set_comment take a printf format string 2020-02-27 03:42:35 +00:00
util_pw.c lib: Avoid an includes.h 2017-03-28 17:45:19 +02:00
util_pw.h
util_runcmd.c lib: Fix the build on FreeBSD 2021-01-25 09:48:09 +00:00
util_str_common.c lib: Move ucs2_align() to 'charset' subsystem 2021-01-12 00:10:30 +00:00
util_str_escape.c lib/util: Add functions to escape log lines but not break all non-ascii 2017-03-29 02:37:26 +02:00
util_str_escape.h lib/util: Add functions to escape log lines but not break all non-ascii 2017-03-29 02:37:26 +02:00
util_str_hex.c lib: Simplify parse_guid_string() and ndr_syntax_id_from_string() 2021-01-28 16:58:35 +00:00
util_str_hex.h lib: Simplify parse_guid_string() and ndr_syntax_id_from_string() 2021-01-28 16:58:35 +00:00
util_str.c lib: Add talloc_asprintf_addbuf() 2021-10-08 19:28:31 +00:00
util_strlist_v3.c
util_strlist.c lib: Add str_list_add_printf() 2021-05-11 22:56:37 +00:00
util_strlist.h lib: Add str_list_add_printf() 2021-05-11 22:56:37 +00:00
util_tdb.c lib:util: Fix return value of tdb_fetch_uint32_byblob() 2021-05-12 21:19:03 +00:00
util_tdb.h lib: Remove unused tdb_traverse_delete_fn() 2021-04-19 18:18:31 +00:00
util.c util: Ensure debugger is not started until it is allowed to attach 2021-04-20 12:33:40 +00:00
util.h lib: relicense smb_strtoul(l) under LGPLv3 2020-08-03 22:21:02 +00:00
wscript lib: Use gpfs.h from third_party on Linux 2019-01-18 17:21:02 +01:00
wscript_build nsswitch: reduce dependecies to private libraries and link static/builtin if possible 2021-11-30 15:53:34 +00:00
wscript_configure lib/util: use better linux os detection in gpfs configure 2020-01-28 18:05:34 +00:00

This directory contains libutil (until we can think of a better name)

The idea is that this library contains simple but useful data structures 
and support functions that are generally useful; not just for Samba but for 
other projects as well. Functions here should not depend on any external 
libraries, just on libc (perhaps partially provided by libreplace).