summaryrefslogtreecommitdiff
path: root/lib/replace/replace.h
AgeCommit message (Collapse)AuthorFilesLines
2026-03-20lib:replace add discard_align_pGary Lockyer1-0/+20
Add discard_align_p macro to allow the suppression of cast-align warnings Signed-off-by: Gary Lockyer <gary@catalyst.net.nz> Reviewed-by: Volker Lendecke <vl@samba.org>
2026-02-27vfs_aio_ratelimit: Add per-share TDB persistence for local rate limiter stateAvan Thakkar1-0/+8
Introduce local TDB storage for saving and restoring ratelimiter state (iops_tokens, bytes_tokens, last timestamp). Each share now persists its read/write limiter state under aio_ratelimit.tdb. Added VERSION pseudo-key for schema versioning On disconnect, save the latest state and close TDB. BUG: https://bugzilla.samba.org/show_bug.cgi?id=16000 Signed-off-by: Avan Thakkar <athakkar@redhat.com> Reviewed-by: Shweta Sodani <ssodani@redhat.com> Reviewed-by: Shachar Sharon <ssharon@redhat.com> Reviewed-by: Guenther Deschner <gd@samba.org> Reviewed-by: Anoop C S <anoopcs@samba.org>
2025-11-11lib:replace: Remove memset_s()Andreas Schneider1-5/+0
Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Autobuild-User(master): Andreas Schneider <asn@cryptomilk.org> Autobuild-Date(master): Tue Nov 11 14:51:45 UTC 2025 on atb-devel-224
2025-11-11Replace memset_s() with memset_explicit()Andreas Schneider1-9/+9
Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
2025-11-11lib:replace: Implement memset_explicit()Andreas Schneider1-0/+5
The memset_s() implementation is a bit obscure, as it requires a constraint handler to be set up. You don't really find any implmentations out there. With C23 memset_explicit() was added and this has been implemented for glibc 2.43 and also in FreeBSD. See https://sourceware.org/bugzilla/show_bug.cgi?id=32378 See https://reviews.freebsd.org/D47286 Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
2025-01-02remove usage of bzeroMichael Tokarev1-4/+0
bzero() function has been deprecated for a long time. In samba it is replaced with memset(). But samba also provides common memory-zeroing macros, like ZERO_STRUCT(). In all places where bzero() is used, it actually meant to zero a structure or an array. So replace these bzero() calls with ZERO_STRUCT() or ZERO_ARRAY() as appropriate, and remove bzero() replacement and testing entirely. While at it, also stop checking for presence of memset() - this function is standard for a very long time, and the only conditional where HAVE_MEMSET were used, was to provide replacement for bzero() - in all other places memset() is used unconditionally. Signed-off-by: Michael Tokarev <mjt@tls.msk.ru> Reviewed-by: Andreas Schneider <asn@samba.org> Reviewed-by: Pavel Filipenský <pfilipensky@samba.org>
2024-11-12libreplace: Introduce hexchars_{upper|lower}Volker Lendecke1-0/+3
We use that in quite a few places in our code. Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
2024-08-20libreplace: add rep_copy_reflink()Ralph Boehme1-0/+9
FICLONERANGE was introduced in kernel version 4.5, so I guess we can just assume it is present if HAVE_LINUX_IOCTL is defined. Signed-off-by: Ralph Boehme <slow@samba.org> Reviewed-by: David Disseldorp <ddiss@samba.org>
2024-03-12lib: Simplify _hexcharvalVolker Lendecke1-1/+1
Saves a few bytes and conditional jumps Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2023-08-14lib/replace: Ensure that __STDC_WANT_LIB_EXT1__ is set to 1Joseph Sutton1-1/+1
Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2023-08-08lib/replace: Const-qualify sys_errlistJoseph Sutton1-1/+1
Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2023-03-22replace: add ARRAY_INSERT_ELEMENT() helperStefan Metzmacher1-0/+15
Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
2023-01-05libreplace: require TLS support if pthread support is availableRalph Boehme1-0/+12
Signed-off-by: Ralph Boehme <slow@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
2022-10-27lib:replace: Require bool from C99Andreas Schneider1-5/+1
https://fedoraproject.org/wiki/Changes/PortingToModernC We define True to true from stdbool.h and the same for false. So we don't have to do a cleanup now. Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org> Autobuild-User(master): Jeremy Allison <jra@samba.org> Autobuild-Date(master): Thu Oct 27 19:11:30 UTC 2022 on sn-devel-184
2022-08-26lib:replace: Add macro BURN_STR() to zero memory of a stringPavel Filipenský1-0/+11
Signed-off-by: Pavel Filipenský <pfilipensky@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
2022-07-28lib:replace: Add macros to burn data from memoryAndreas Schneider1-0/+18
This will explicitly zero data from memory. This is guaranteed to be not optimized away. Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
2022-03-23replace: add explicit function pointer casting from dlsym() to avoid warningsStefan Metzmacher1-1/+1
This avoids a lot of warnings on AIX. Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org> Autobuild-User(master): Andreas Schneider <asn@cryptomilk.org> Autobuild-Date(master): Wed Mar 23 13:27:45 UTC 2022 on sn-devel-184
2022-03-23lib/replace: Do not typedef int boolAndrew Bartlett1-1/+1
We need a genuine boolean type, as otherwise expressions like bool foo = (4 & 4); if (foo == true) { exit(1); } else { exit(2); } could evaluate differently on non-modern platforms, and that would be a real pain to debug. _Bool and bool are in C99 BUG: https://bugzilla.samba.org/show_bug.cgi?id=15028 Signed-off-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org> Autobuild-User(master): Andreas Schneider <asn@cryptomilk.org> Autobuild-Date(master): Wed Mar 23 12:31:47 UTC 2022 on sn-devel-184
2021-11-30lib/replace: use dlsym(RTLD_DEFAULT,) for ↵Stefan Metzmacher1-4/+53
{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 <metze@samba.org> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
2021-06-30replace: copy_file_range()Ralph Boehme1-0/+10
BUG: https://bugzilla.samba.org/show_bug.cgi?id=12033 Signed-off-by: Ralph Boehme <slow@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
2021-01-08lib: Add "hex_byte()" to replace.hVolker Lendecke1-0/+16
This is required in quite a few places, and replace.h has things like ZERO_STRUCT already, so this is not completely outplaced. Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
2020-10-16replace: also use portable __has_attribute macro to check for "deprecated" ↵Björn Jacke1-1/+1
attribute BUG: https://bugzilla.samba.org/show_bug.cgi?id=14526 Signed-off-by: Bjoern Jacke <bjacke@samba.org> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2020-05-24replace, attr.: use function attributes only if supported by feature macro ↵Björn Jacke1-1/+6
(or old gcc) BUG: https://bugzilla.samba.org/show_bug.cgi?id=12296 Signed-off-by: Bjoern Jacke <bjacke@samba.org> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2020-03-26lib: Add macro ARRAY_DEL_ELEMENT()Volker Lendecke1-0/+6
Every time I have to remove an element from within an array I have to scratch my head about the memmove arguments. Make this easier to use. Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
2020-02-27Undef ARRAY_SIZE, if defined, before define to avoid compilation warningsPeter Eriksson1-0/+3
Signed-off-by: Peter Eriksson <pen@lysator.liu.se> Reviewed-by: Jeremy Allison <jra@samba.org> Reviewed-by: Gary Lockyer <<gary@catalyst.net.nz> Autobuild-User(master): Jeremy Allison <jra@samba.org> Autobuild-Date(master): Thu Feb 27 21:43:29 UTC 2020 on sn-devel-184
2019-09-19replace: Remove crypt() reimplementationAndrew Bartlett1-5/+0
Use of Samba with plaintext authenticaiton is incredibly rare, even more rare is plaintext authentication on systems without a crypt() call and where DES based crypt() would be the right thing to do. Remove this additional cryptographic code per our current efforts to rely entirely on external libraries instead. Similar to the arguments in this thread about zlib discussed on samba-technical here: https://lists.samba.org/archive/samba-technical/2019-May/133476.html Signed-off-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org> Autobuild-User(master): Andreas Schneider <asn@cryptomilk.org> Autobuild-Date(master): Thu Sep 19 09:28:21 UTC 2019 on sn-devel-184
2019-04-30replace: Add ZERO_ARRAY_LEN() macroAndreas Schneider1-0/+5
Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2019-04-26Revert "lib/replace: define NAME_MAX for platforms that don't have it"Günther Deschner1-4/+0
BUG: https://bugzilla.samba.org/show_bug.cgi?id=13872 This reverts commit e3c894fb6b87df8aa56e29ef3b16ae1ef456a875. Signed-off-by: Günther Deschner <gd@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org> Autobuild-User(master): Günther Deschner <gd@samba.org> Autobuild-Date(master): Fri Apr 26 13:03:05 UTC 2019 on sn-devel-184
2019-04-16lib/replace: define NAME_MAX for platforms that don't have itGünther Deschner1-0/+4
This allows the vfs_glusterfs_fuse build to complete on AIX. BUG: https://bugzilla.samba.org/show_bug.cgi?id=13872 Guenther Signed-off-by: Guenther Deschner <gd@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org> Autobuild-User(master): Günther Deschner <gd@samba.org> Autobuild-Date(master): Tue Apr 16 15:14:50 UTC 2019 on sn-devel-144
2019-01-29wafsamba/replace: move __STDC_WANT_LIB_EXT1__ to CFLAGSStefan Metzmacher1-2/+8
This fixes the build of python bindings, which use memset_s() (via ZERO_STRUCT). In python bindings Python.h needs to be the first header, which means is already includes string.h. Defining __STDC_WANT_LIB_EXT1__ in replace.h is too late in that case. This fixes the --check-c-compiler=gcc --picky-developer on FreeBSD 12. Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
2018-12-20replace: Use memset_s for ZERO_* macrosAndreas Schneider1-4/+8
Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2018-12-20replace: Cleanup comments for ZERO_*Andreas Schneider1-11/+13
Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2018-12-16replace: Fix checking for config.h #define in replace.hAndreas Schneider1-1/+1
Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Gary Lockyer <gary@catalyst.net.nz>
2018-11-30replace: Correctly check for 'extern char **environ' in unistd.hAndreas Schneider1-9/+11
Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Martin Schwenke <martin@meltin.net> Autobuild-User(master): Andreas Schneider <asn@cryptomilk.org> Autobuild-Date(master): Fri Nov 30 11:41:44 CET 2018 on sn-devel-144
2018-11-28s3: Remove unsused MMAP_BLACKLIST ifdef checksAndreas Schneider1-4/+0
This doesn't get defined by anything. Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Gary Lockyer <gary@catalyst.net.nz>
2018-11-28lib:replace: Check if HAVE_DECL_ENVIRON is defined firstAndreas Schneider1-0/+2
Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Gary Lockyer <gary@catalyst.net.nz>
2018-11-12lib:replace: Add getprogname()Andreas Schneider1-0/+5
Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
2018-10-16replace: Add memset_s() if not availableAndreas Schneider1-0/+8
See https://en.cppreference.com/w/c/string/byte/memset Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
2018-04-03lib/replace: define __[u]intptr_t_defined if we prove an replacementStefan Metzmacher1-0/+2
BUG: https://bugzilla.samba.org/show_bug.cgi?id=13344 Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Björn Jacke <bjacke@samba.org>
2018-03-01lib:replace: Add FALL_THROUGH supportAndreas Schneider1-0/+9
Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2017-09-26s4:smbd: call setproctitle_initGary Lockyer1-0/+4
Call setproctitle_init() in main which suppresses the "samba: setproctitle not initialized, please either call setproctitle_init() or link against libbsd-ctor." messages, but more importantly it displays meaningful details in ps output. BUG: https://bugzilla.samba.org/show_bug.cgi?id=9816 Signed-off-by: Gary Lockyer <gary@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
2017-06-13strerror_r: provide XSI-compliant strerror_rGary Lockyer1-1/+1
Provide a XSI-compliant strerror_r on GNU based systems. The default GNU strerror_r is not XSI-compliant, this patch wraps the GNU-specific call in an XSI-compliant wrapper. This reverts 18ed32ce0821d11c0c06d82c07ba1c27b0c2b886 which tried to make Heimdal use roken, rather than libreplace for strerror_r. Signed-off-by: Gary Lockyer <gary@catalyst.net.nz> Signed-off-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
2017-01-08replace: Include sysmacros.hAndreas Schneider1-0/+4
In the GNU C Library, "makedev" is defined by <sys/sysmacros.h>. For historical compatibility, it is currently defined by <sys/types.h> as well, but it is planned to remove this soon. Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Volker Lendecke <vl@samba.org> Autobuild-User(master): Volker Lendecke <vl@samba.org> Autobuild-Date(master): Sun Jan 8 22:30:03 CET 2017 on sn-devel-144
2016-06-13libreplace: Add a closefrom() implementationVolker Lendecke1-0/+6
There is closefrom in some BSDs, but Linux ships this only as part of libbsd. Add a new implementation of it in libreplace. The one in libbsd of jessie and upstream differ and it has for example optimizations for FreeBSD, but it gets some of the array calculations slightly wrong from my point of view. If you want those, use libbsd. This replacement is optimized on Linux only looking at /proc/self/fd/, everything else would do the OPEN_MAX brute force fallback. Signed-off-by: Volker Lendecke <vl@samba.org>
2016-03-24libreplace: use HAVE___ATTRIBUTE__ instead of __GNUC__Douglas Bagnall1-2/+2
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Uri Simchoni <uri@samba.org>
2015-07-29lib: replace: Add strsep function (missing on Solaris).Jeremy Allison1-0/+5
BUG: https://bugzilla.samba.org/show_bug.cgi?id=11359 Signed-off-by: Jeremy Allison <jra@samba.org> Reviewed-by: Ira Cooper <ira@wakeful.net> Autobuild-User(master): Jeremy Allison <jra@samba.org> Autobuild-Date(master): Wed Jul 29 02:24:55 CEST 2015 on sn-devel-104
2014-09-17replace: Make EWOULDBLOCK always availableVolker Lendecke1-0/+4
Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
2014-06-07lib: tevent: make TEVENT_SIG_INCREMENT atomic.Jeremy Allison1-0/+5
On arm platforms incrementing a variable is not an atomic operation, so may be interrupted by signal processing (if a signal interrupts another signal handler). Use compiler built-ins to make this atomic. __sync_fetch_and_add() works on gcc, llvm, IBM xlC on AIX, and Intel icc (10.1 and above). atomic_add_32() works on Oracle Solaris. Based on an inital patch from kamei@osstech.co.jp. Bug #10640 - smbd is not responding - tevent_common_signal_handler() increments non-atomic variables https://bugzilla.samba.org/show_bug.cgi?id=10640 Signed-off-by: Jeremy Allison <jra@samba.org> Reviewed-by: Volker Lendecke <Volker.Lendecke@SerNet.DE>
2014-04-17replace: Add socket_wrapper_enabled().Andreas Schneider1-0/+1
Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
2014-04-17replace: Add nss_wrapper_hosts_enabled().Andreas Schneider1-0/+1
Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>