summaryrefslogtreecommitdiff
path: root/lib/util
Commit message (Collapse)AuthorAgeFilesLines
* lib:util: prefer size_t for random data generation functionsDmitry Antipov2023-05-162-7/+7
| | | | | | | | | | Prefer 'size_t' over 'int' in generate_random_buffer(), generate_secret_buffer() and generate_nonce_buffer() to match an underlying gnutls_rnd() calls. Signed-off-by: Dmitry Antipov <dantipov@cloudlinux.com> Reviewed-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
* lib:util: Fix undefined bitshiftJoseph Sutton2023-05-051-1/+1
| | | | | | | runtime error: left shift of 65535 by 16 places cannot be represented in type 'int' Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
* debug: Only initialize gpfs wrapper when gpfs logging is enabledChristof Schmitt2023-04-141-1/+3
| | | | | | | | | | | | This avoids unnecessary attempts to load libgpfs.so when it is not needed. Signed-off-by: Christof Schmitt <cs@samba.org> Reviewed-by: Michael Tokarev <mjt@tls.msk.ru> Reviewed-by: Volker Lendecke <vl@samba.org> Autobuild-User(master): Volker Lendecke <vl@samba.org> Autobuild-Date(master): Fri Apr 14 12:28:23 UTC 2023 on atb-devel-224
* lib:util: Fix code spellingAndreas Schneider2023-04-1423-230/+230
| | | | Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Joseph Sutton <josephsutton@catalyst.net.nz>
* lib:util: Remove trailing white spaces in byteorder.hAndreas Schneider2023-04-141-6/+6
| | | | Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Joseph Sutton <josephsutton@catalyst.net.nz>
* lib/util: Add "debug syslog format = always", which logs to stdout in syslog ↵Andrew Bartlett2023-04-062-9/+38
| | | | | | | style Signed-off-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
* lib:util: prefer mallinfo2() over mallinfo() if availableDmitry Antipov2023-03-092-4/+41
| | | | | | | | | | | | | Prefer mallinfo2() with 'size_t' fields over deprecated mallinfo() (with 'int' fields which may wrap around zero and so be inaccurate on a 64-bit system) and move relevant checks to lib/util/wscript_configure because mallinfo() is not used beyond 'samba-util'. Suggested-by: Andreas Schneider <asn@samba.org> Signed-off-by: Dmitry Antipov <dantipov@cloudlinux.com> Reviewed-by: Volker Lendecke <vl@samba.org> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
* lib: Add dump_data_addbuf()Volker Lendecke2023-03-092-0/+15
| | | | | | | Helper function to build up debug strings Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
* lib: Move the dump_data_pw() prototype to the other dump_data_* onesVolker Lendecke2023-03-092-8/+8
| | | | | Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
* lib: Fix whitespaceVolker Lendecke2023-03-091-7/+7
| | | | | Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
* lib: add NTTIME_[U|m]SEC macrosAmir Goldstein2023-03-011-0/+3
| | | | | | Signed-off-by: Amir Goldstein <amir@ctera.com> Reviewed-by: Ralph Boehme <slow@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
* lib:util: File descriptor being closed repeatedly.baixiangcpp2023-02-161-1/+8
| | | | | | | | | | | | | | | In file_load()/file_lines_load(), the file's fd is obtained using open(), and in fd_load() the fd is converted to a FILE* using fdopen(). However, after fclose(), the fd is closed again using close(). Bug: https://bugzilla.samba.org/show_bug.cgi?id=15311 Signed-off-by: baixiangcpp baixiangcpp@gmail.com Reviewed-by: Volker Lendecke <vl@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org> Autobuild-User(master): Volker Lendecke <vl@samba.org> Autobuild-Date(master): Thu Feb 16 12:13:05 UTC 2023 on atb-devel-224
* s3:lib: Change file_modtime() to return an error code and a struct timespec.Jeremy Allison2023-01-272-12/+25
| | | | | | | | | | Removes need for external stat() code when checking for timechange. Signed-off-by: Jeremy Allison <jra@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org> Autobuild-User(master): Andreas Schneider <asn@cryptomilk.org> Autobuild-Date(master): Fri Jan 27 08:30:35 UTC 2023 on atb-devel-224
* spelling fixes for 4.18 (errror implemenation proces Controler)Michael Tokarev2023-01-261-1/+1
| | | | | | | | | | | | | | One of changes is somewhat interesting, it is "tfork waiter proces" process title in tfork.c. I wonder why no one noticed this before. There's another similar process title in there, "tfork waiter process(%d)". Hopefully no one does grep for "proces$" (and there's no reason to). Signed-off-by: Michael Tokarev <mjt@tls.msk.ru> Reviewed-by: Volker Lendecke <vl@samba.org> Reviewed-by: Rowland Penny <rpenny@samba.org> Autobuild-User(master): Jeremy Allison <jra@samba.org> Autobuild-Date(master): Thu Jan 26 20:46:11 UTC 2023 on atb-devel-224
* debug: Call depth: Indent the debug textPavel Filipenský2023-01-261-0/+13
| | | | | | | BUG: https://bugzilla.samba.org/show_bug.cgi?id=15287 Signed-off-by: Pavel Filipenský <pfilipensky@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
* debug: Call depth: Print ", depth=..." in the debug headerPavel Filipenský2023-01-261-0/+10
| | | | | | | BUG: https://bugzilla.samba.org/show_bug.cgi?id=15287 Signed-off-by: Pavel Filipenský <pfilipensky@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
* debug: Call depth: InterfacePavel Filipenský2023-01-262-0/+13
| | | | | | | BUG: https://bugzilla.samba.org/show_bug.cgi?id=15287 Signed-off-by: Pavel Filipenský <pfilipensky@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
* debug: Fix whitespaces in debug.cPavel Filipenský2023-01-261-4/+4
| | | | | | | BUG: https://bugzilla.samba.org/show_bug.cgi?id=15287 Signed-off-by: Pavel Filipenský <pfilipensky@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
* lib:util: Print data in ISO 8601 formatAndreas Schneider2023-01-261-2/+2
| | | | Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
* lib:util: Remove trailing whitespaces from time.cAndreas Schneider2023-01-261-19/+19
| | | | Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
* lib/util: install a tevent_abort callback using smb_panic()Stefan Metzmacher2023-01-181-0/+18
| | | | | | Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Pavel Filipenský <pfilipen@redhat.com> Reviewed-by: Volker Lendecke <vl@samba.org>
* lib/tfork: Don't overwrite 'ret' in cleanup phaseJoseph Sutton2023-01-101-5/+6
| | | | | | | | | | | | | The cleanup phase of tfork_create() saves errno prior to calling functions that might modify it, with the intention of restoring it afterwards. However, the value of 'ret' is accidentally overwritten. It will always be equal to 0, and hence errno will not be restored. Fix this by introducing a new variable, ret2, for calling functions in the cleanup phase. Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Jeremy Allison <jra@samba.org>
* lib: Remove idtree from samba_util.hVolker Lendecke2023-01-102-3/+1
| | | | | | | No need to recompile the world when only a few files need this. Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
* lib: Add "starting_id" to idr_get_new_random()Volker Lendecke2023-01-102-5/+16
| | | | | | | To be used in smbXsrv_open.c, for this we need a lower bound. Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
* lib: Use talloc_asprintf_addbuf() in print_socket_options()Volker Lendecke2022-12-141-13/+6
| | | | | | | | With the proper NULL checks we don't need the stackframe, use a passed in context instead. Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
* lib: Use talloc_asprintf_addbuf() in str_list_join_shell()Volker Lendecke2022-12-141-4/+5
| | | | | | | This adds proper NULL checks via talloc_asprintf_addbuf() Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
* lib: Use talloc_asprintf_addbuf() in str_list_join()Volker Lendecke2022-12-141-1/+1
| | | | | | | This adds intermediate NULL checks via talloc_asprintf_addbuf() Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
* lib: Use talloc_asprintf_addbuf() in debug.cVolker Lendecke2022-12-141-9/+6
| | | | | | | Slightly simplify debug_list_class_names_and_levels() Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
* lib: Move talloc_asprintf_addbuf() to tallocVolker Lendecke2022-12-142-37/+0
| | | | | | | | | | | I wanted to use this in debug.c, but this would have meant to pollute debug's deps with a lot of stuff. Also, looking through uses of talloc_asprint_append(), very many of those don't do NULL checks properly and could benefit from the _addbuf() flavor. We can add a vasprintf variant later if the need shows up. Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
* lib: Fix whitespaceVolker Lendecke2022-12-141-24/+24
| | | | | Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
* lib/util: use process_set_title() in tfork()Ralph Boehme2022-12-141-4/+3
| | | | | Signed-off-by: Ralph Boehme <slow@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
* lib/util: add process_set_title()Ralph Boehme2022-12-142-3/+42
| | | | | Signed-off-by: Ralph Boehme <slow@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
* util: add stable sort functionsDouglas Bagnall2022-12-014-0/+626
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Sometimes (e.g. in lzxpress Huffman encoding, and in some of our tests: c.f. https://lists.samba.org/archive/samba-technical/2018-March/126010.html) we want a stable sort algorithm (meaning one that retains the previous order of items that compare equal). The GNU libc qsort() is *usually* stable, in that it first tries to use a mergesort but reverts to quicksort if the necessary allocations fail. That has led Samba developers to unthinkingly assume qsort() is stable which is not the case on many platforms, and might not always be on GNU/Linuxes either. This adds four functions. stable_sort() sorts an array, and requires an auxiliary working array of the same size. stable_sort_talloc() takes a talloc context so it ca create a working array and call stable_sort(). stable_sort_r() takes an opaque context blob that gets passed to the compare function, like qsort_r() and ldb_qsort(). And stable_sort_talloc_r() rounds out the quadrant. These are LGPL so that the can be used in ldb, which has problems with unstable sort. The tests are borrowed and extended from test_ldb_qsort.c. When sorting non-trivial structs this is roughly as fast as GNU qsort, but GNU qsort has optimisations for small items, using direct assignments of rather than memcpy where the size allows the item to be cast as some kind of int. Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Joseph Sutton <josephsutton@catalyst.net.nz>
* lib: Whitespace fixesVolker Lendecke2022-11-221-11/+11
| | | | | Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
* lib: Make lib/util/iov_buf.h self-containedVolker Lendecke2022-11-221-0/+1
| | | | | | | | We need "struct iovec", which comes in via sys/uio.h, incuded by system/filesys.h Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
* lib:util: Check memset_s() error code in talloc_keep_secret_destructor()Joseph Sutton2022-09-121-1/+14
| | | | | | | | Panic if memset_s() fails. Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andreas Schneider <asn@samba.org> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
* lib: Fix a typoVolker Lendecke2022-08-261-4/+5
| | | | | Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
* lib:util: Zero memory in generate_random_machine_password()Pavel Filipenský2022-08-261-0/+8
| | | | Signed-off-by: Pavel Filipenský <pfilipensky@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
* lib:util: Add BURN_FREE() and BURN_FREE_STR()Pavel Filipenský2022-08-261-0/+27
| | | | Signed-off-by: Pavel Filipenský <pfilipensky@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
* lib/util: add unlikely() to SMB_ASSERT()Stefan Metzmacher2022-08-191-1/+1
| | | | | | | BUG: https://bugzilla.samba.org/show_bug.cgi?id=15125 Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
* lib/util/access: source3/auth/user_util: Check for INNETGRlistout2022-08-081-1/+1
| | | | | | | | | | | | Checking for presence of both netgroup and innetgr. INNETGR is not defined on libc's such as musl so not checking results in a build error. Signed-off-by: listout <brahmajit.xyz@gmail.com> Reviewed-by: Andreas Schneider <asn@samba.org> Reviewed-by: Volker Lendecke <vl@samba.org> Autobuild-User(master): Volker Lendecke <vl@samba.org> Autobuild-Date(master): Mon Aug 8 07:28:31 UTC 2022 on sn-devel-184
* lib:util: Add generate_random_u64_range()Andreas Schneider2022-07-282-0/+16
| | | | Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
* lib:util: Remove trailing whitespaces in samba_util.hAndreas Schneider2022-07-281-17/+17
| | | | Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
* util/genrand: don't ignore errors in random number generationDouglas Bagnall2022-07-282-4/+27
| | | | | | | | In this case it is probably better to crash out. BUG: https://bugzilla.samba.org/show_bug.cgi?id=15103 Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andreas Schneider <asn@samba.org>
* lib/util: make use of tevent_cached_getpid() in performance critical codeStefan Metzmacher2022-07-252-2/+4
| | | | | | | This avoids wasting getpid() calls in a lot of places... Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
* lib: Remove a few #include "includes.h"Volker Lendecke2022-07-259-9/+19
| | | | | Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
* lib: On FreeBSD util_paths.c does not find struct statVolker Lendecke2022-07-241-0/+1
| | | | | | | | Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org> Autobuild-User(master): Jeremy Allison <jra@samba.org> Autobuild-Date(master): Sun Jul 24 00:25:49 UTC 2022 on sn-devel-184
* lib: Fix the FreeBSD buildVolker Lendecke2022-07-231-0/+1
| | | | | | | "time_t" only comes in via a proper include of <time.h> Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
* waf: Check for -Wno-error=array-bounds flagsAndreas Schneider2022-07-191-3/+19
| | | | | | | | | | BUG: https://bugzilla.samba.org/show_bug.cgi?id=15073 Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org> Autobuild-User(master): Andreas Schneider <asn@cryptomilk.org> Autobuild-Date(master): Tue Jul 19 12:17:35 UTC 2022 on sn-devel-184
* debug: Add DEBUGLF macro with explicit location and function parameters.Pavel Filipenský2022-07-151-0/+19
| | | | Signed-off-by: Pavel Filipenský <pfilipen@redhat.com> Reviewed-by: Andreas Schneider <asn@samba.org>