summaryrefslogtreecommitdiff
path: root/lib/util/util.c
AgeCommit message (Collapse)AuthorFilesLines
2025-11-10lib: "boolean == true" looks strange :-)Volker Lendecke1-4/+2
Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Anoop C S <anoopcs@samba.org>
2025-04-29lib/util: let dump_data_diff() pass omit_zero_bytes to dump_data_diff_cb()Stefan Metzmacher1-1/+7
Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Günther Deschner <gd@samba.org> Autobuild-User(master): Stefan Metzmacher <metze@samba.org> Autobuild-Date(master): Tue Apr 29 17:56:37 UTC 2025 on atb-devel-224
2024-06-13lib:util: Fix size of tmp arrayAndreas Schneider1-1/+3
lib/util/util.c: In function ‘dump_data_block16’: lib/util/util.c:503:40: error: ‘%04zX’ directive output may be truncated writing between 4 and 16 bytes into a region of size 15 [-Werror=format-truncation=] 503 | snprintf(tmp, sizeof(tmp), "%s[%04zX]", prefix, idx); | ^~~~~ Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
2024-06-13lib:util: Remove tailing spaces in util.cAndreas Schneider1-12/+12
Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
2023-10-13util: Remove redundant assertion (CID 1497841)Joseph Sutton1-1/+1
Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2023-08-24lib/util: strhex_to_data_blob checks tallocDouglas Bagnall1-1/+4
Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2023-04-14lib:util: Fix code spellingAndreas Schneider1-1/+1
Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Joseph Sutton <josephsutton@catalyst.net.nz>
2023-03-09lib: Add dump_data_addbuf()Volker Lendecke1-0/+11
Helper function to build up debug strings Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
2023-01-27s3:lib: Change file_modtime() to return an error code and a struct timespec.Jeremy Allison1-9/+16
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
2022-07-25lib/util: make use of tevent_cached_getpid() in performance critical codeStefan Metzmacher1-1/+2
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>
2022-06-09lib/util: Delegate constant time memcmp to gnutls_memcmp()Joseph Sutton1-8/+4
gnutls_memcmp() is mostly identical to our own implementation, except that ours will not break if supplied with 4 GiB or more of data. However, using an external function permits us to disclaim responsibility if some CPU/compiler combination happens to invalidate our constant-time guarantee. For reference, gnutls_memcmp() implementation: https://gitlab.com/gnutls/gnutls/-/blob/78d9820de0d2eb2f8088e359779ee7342f5f089e/lib/safe-memfuncs.c#L41-67 Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2022-06-09lib/util: Reduce sum variable to uint8_tJoseph Sutton1-1/+2
Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2022-06-09lib/util: Change function to mem_equal_const_time()Joseph Sutton1-2/+2
Since memcmp_const_time() doesn't act as an exact replacement for memcmp(), and its return value is only ever compared with zero, simplify it and emphasize the intention of checking equality by returning a bool instead. Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2022-06-09lib/util: Move memcmp_const_time() to util.cJoseph Sutton1-0/+12
This allows it to be used in more places without needing to introduce more dependencies. Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2022-01-24lib/util: add dump_data_diff*() helpersStefan Metzmacher1-0/+84
That will make it easy to see the difference between two memory buffers. BUG: https://bugzilla.samba.org/show_bug.cgi?id=14956 Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
2022-01-24lib/util: split out a dump_data_block16() helperStefan Metzmacher1-60/+59
This simplifies the logic a lot for me. It also fixes some corner cases regarding whitespaces in the output, that's why we have to mark a few tests as knownfail, they will be fixed in the next commit. BUG: https://bugzilla.samba.org/show_bug.cgi?id=14956 Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
2021-04-20util: Ensure debugger is not started until it is allowed to attachJoseph Sutton1-10/+39
Use a pipe to ensure that the debugger is not started until after the prctl() call allowing it to attach to the parent, avoiding a potential race condition. Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> 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): Tue Apr 20 12:33:40 UTC 2021 on sn-devel-184
2021-04-20util: Ensure debugger can be attached to processJoseph Sutton1-12/+18
samba_start_debugger() attempts to start a debugger attached to the calling process by calling system() to start a background process. However, if the spawned shell exits before the debugger has had a chance to attach, the debugger process will no longer be a child of the parent process (as it will have been reparented). If the system does not allow tracing by non-child processes, attachment may fail as a result. This commit replaces the system() call and the implicit shell around xterm with an explicit fork()/exec() so that the debugger remains a child of the calling process, ensuring the attachment succeeds unless tracing is disabled completely. Signed-off-by: Joseph Sutton <josephsutton@catalyst.net.nz> Reviewed-by: Andrew Bartlet <abartlet@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
2021-03-11util: don't mark impure functions as pureDouglas Bagnall1-2/+2
nothing that allocates memory can be pure, unless it guarantees to allocate exactly the same pointer very time (which it does not). Signed-off-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz> Reviewed-by: Jeremy Allison <jra@samba.org>
2021-01-22lib: Use hex_byte() in strhex_to_str()Volker Lendecke1-27/+6
I had completely missed that one in the last round... Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
2021-01-06lib:util: Add directory_create_or_exists_recursive()Andreas Schneider1-0/+40
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14601 Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
2020-08-16util: Allow symlinks in directory_create_or_existChristof Schmitt1-2/+16
Commit 9f60a77e0b updated the check to avoid having files or other objects instead of a directory. This missed the valid case that there might be a symlink to a directory. Updated the check accordingly to allow symlinks to directories. BUG: https://bugzilla.samba.org/show_bug.cgi?id=14166 Signed-off-by: Christof Schmitt <cs@samba.org> Reviewed-by: Volker Lendecke <vl@samba.org>
2020-08-03lib: relicense smb_strtoul(l) under LGPLv3Ralph Boehme1-152/+0
Signed-off-by: Ralph Boehme <slow@samba.org> Reviewed-by: Swen Schillig <swen@linux.ibm.com> Reviewed-by: Volker Lendecke <vl@samba.org> Autobuild-User(master): Jeremy Allison <jra@samba.org> Autobuild-Date(master): Mon Aug 3 22:21:04 UTC 2020 on sn-devel-184
2020-05-27lib/util: Allow gdb to be started by samba_start_debugger() under the ↵Andrew Bartlett1-0/+10
default Ubuntu restrictions Ubuntu (in particular) restricts ptrace by default for security reasons but the processe to be traced can allow tracing by a child process using prctl(). This matches what is done for panic action = Signed-off-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Gary Lockyer <gary@catalyst.net.nz>
2020-01-27lib:util: Log mkdir error on correct debug levelsAndreas Schneider1-2/+5
For smbd we want an error and for smbclient we only want it in NOTICE debug level. The default log level of smbclient is log level 1 so we need notice to not spam the user. BUG: https://bugzilla.samba.org/show_bug.cgi?id=14253 Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Guenther Deschner <gd@samba.org> Autobuild-User(master): Günther Deschner <gd@samba.org> Autobuild-Date(master): Mon Jan 27 15:55:24 UTC 2020 on sn-devel-184
2019-06-30lib: Add capability to enable standard glibc behaviour for string to int ↵Swen Schillig1-10/+16
conversion Adding two addtl. flags SAMBA_STR_ALLOW_NO_CONVERSION and SAMBA_STR_GLIBC_STANDARD for the wrappers strtoul_err() and strtoull_err() providing the possibility to get standard glibc behaviour for string to integer conversion. Signed-off-by: Swen Schillig <swen@linux.ibm.com> Reviewed-by: Ralph Boehme <slow@samba.org> Reviewed-by: Christof Schmitt <cs@samba.org>
2019-06-30lib: Add check for full string consumption when converting string to intSwen Schillig1-0/+22
Some callers want to have the entire string being used for a string to integer conversion, otherwise flag an error. This is possible by providing the SAMBA_STR_FULL_STR_CONV flag. Signed-off-by: Swen Schillig <swen@linux.ibm.com> Reviewed-by: Ralph Boehme <slow@samba.org> Reviewed-by: Christof Schmitt <cs@samba.org>
2019-06-30lib: Prepare for strtoul_err(), strtoull_err() API changeSwen Schillig1-10/+24
In order to still be bisectable when changing the API for the wrappers strtoul_err() and strtoull_err() some preparations need to be performed. Signed-off-by: Swen Schillig <swen@linux.ibm.com> Reviewed-by: Ralph Boehme <slow@samba.org> Reviewed-by: Christof Schmitt <cs@samba.org>
2019-04-11lib: modify string conversion wrapper to handle invalid stringsSwen Schillig1-1/+18
The standard string conversion routines convert a "non-number string" to zero and do not flag an error. This is changed now by returning EINVAL if no conversion occured. Signed-off-by: Swen Schillig <swen@linux.ibm.com> Reviewed-by: Ralph Boehme <slow@samba.org> Reviewed-by: Christof Schmitt <cs@samba.org>
2019-03-08lib:util: Move debug message for mkdir failing to log level 1Andreas Schneider1-3/+3
If you connnect to a host with smbclient this gets always printed. BUG: https://bugzilla.samba.org/show_bug.cgi?id=13823 Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Autobuild-User(master): Andrew Bartlett <abartlet@samba.org> Autobuild-Date(master): Fri Mar 8 01:41:27 UTC 2019 on sn-devel-144
2019-03-01lib: modify string conversion wrapper to handle signed inputSwen Schillig1-6/+50
The standard string conversion routines convert a "signed string" into the positive representation of the resulting value. This is not wanted and therefore now detected and flag'ed as an error. Signed-off-by: Swen Schillig <swen@linux.ibm.com> Reviewed-by: Ralph Böhme <slow@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
2019-03-01util: Add two wrapper for string to int conversionSwen Schillig1-0/+50
Adding wrapper strtoull_err and strtoul_err to handle error conditions of the conversion process. Signed-off-by: Swen Schillig <swen@linux.ibm.com> Reviewed-by: Ralph Böhme <slow@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
2018-08-30lib: Fix lstat check in directory_create_or_existChristof Schmitt1-17/+11
The lstat check in directory_create_or_exist did not verify whether an existing object is actually a directory. Also move the check to only apply when mkdir returns EEXIST; this fixes CID 241930 Time of check time of use. Signed-off-by: Christof Schmitt <cs@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
2017-10-27lib: Use all_zero where appropriateVolker Lendecke1-3/+2
Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
2017-03-20lib: Simplify smb_nanosleepVolker Lendecke1-42/+2
We have the recalculation logic also in sys_poll_intr, don't duplicate it. Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org> Autobuild-User(master): Volker Lendecke <vl@samba.org> Autobuild-Date(master): Mon Mar 20 16:11:16 CET 2017 on sn-devel-144
2017-03-16lib/util: Fix initializerAmitay Isaacs1-1/+1
Signed-off-by: Amitay Isaacs <amitay@gmail.com> Reviewed-by: Jeremy Allison <jra@samba.org>
2017-02-14ndrdump: Add the option --hex-input for hexdump parsingCody Harrington1-2/+42
This allows the user to input a hexdump that has been generated by the dump option. Signed-off-by: Cody Harrington <cody@harringtonca.com> Reviewed-by: Garming Sam <garming@catalyst.net.nz> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
2016-11-16lib:util: Don't print lstat warning on ERROR debug levelAndreas Schneider1-2/+2
If we are a client and can't access the lock directory don't confuse a user. Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
2016-06-20lib/util: Optimise trim_string() to use a single memmove(3)Martin Schwenke1-7/+12
Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Ralph Boehme <slow@samba.org> Autobuild-User(master): Martin Schwenke <martins@samba.org> Autobuild-Date(master): Mon Jun 20 04:47:26 CEST 2016 on sn-devel-144
2016-03-01lib/util/util.c: move null-check before useAurelien Aptel1-5/+1
moves a null pointer check *before* the pointer is used in the strlen() call - still allocate the `fname` array on the stack - still compiles under C90 definition/code mixing rules Signed-off-by: Aurelien Aptel <aaptel@suse.com> Reviewed-by: Jeremy Allison <jra@samba.org> Reviewed-by: Ralph Boehme <rb@sernet.de> Autobuild-User(master): Jeremy Allison <jra@samba.org> Autobuild-Date(master): Tue Mar 1 02:25:22 CET 2016 on sn-devel-144
2015-11-19lib: Fix memalign_array overflow protectionVolker Lendecke1-1/+1
Signed-off-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 Nov 19 10:05:08 CET 2015 on sn-devel-104
2015-10-28lib: util: Make non-critical message a warning.Jeremy Allison1-2/+2
Non-root utilities (e.g. bin/net) call this via messaging_init(). BUG: https://bugzilla.samba.org/show_bug.cgi?id=11566 Signed-off-by: Jeremy Allison <jra@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
2015-07-09util.c: fix order of inclusion to correctly consume config.hUri Simchoni1-1/+1
replace.h has to be the first file included in order to correctly act upon the definitions in config.h. Specifically, this change fixes 32-bit i686 builds, which depend upon _FILE_OFFSET_BITS=64 to be set before any standard library file is included. Signed-off-by: Uri Simchoni <urisimchoni@gmail.com> Reviewed-by: "Stefan (metze) Metzmacher" <metze@samba.org> Reviewed-by: Volker Lendecke <vl@samba.org> Autobuild-User(master): Volker Lendecke <vl@samba.org> Autobuild-Date(master): Thu Jul 9 12:32:03 CEST 2015 on sn-devel-104
2015-07-03lib/util: fix output format in dump_data*()Stefan Metzmacher1-1/+1
This changes: [0000] 4E 54 4C 4D 53 53 50 00 01 00 00 00 05 82 08 60 NTLMSSP. .......` [0010] 09 00 09 00 20 00 00 00 00 00 00 00 29 00 00 00 .... ... ....)... [0020] 57 4F 52 4B 47 52 4F 55 50 WORKGROU P into: [0000] 4E 54 4C 4D 53 53 50 00 01 00 00 00 05 82 08 60 NTLMSSP. .......` [0010] 09 00 09 00 20 00 00 00 00 00 00 00 29 00 00 00 .... ... ....)... [0020] 57 4F 52 4B 47 52 4F 55 50 WORKGROU P Note the alignment of 'WORKGROU P'. Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Guenther Deschner <gd@samba.org>
2015-05-13lib: Remove unused hex_encode()Volker Lendecke1-13/+1
Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
2014-12-05lib: Fix signed/unsigned comparisonsVolker Lendecke1-1/+1
Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
2014-10-04lib/util: Clean up includes for util.cMartin Schwenke1-1/+6
Allows standalone compiles without external includes.h. Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Jeremy Allison <jra@samba.org>
2014-09-20lib/util: Drop unnecessary use of talloc_tos()Volker Lendecke1-6/+4
Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Martin Schwenke <martin@meltin.net>
2014-09-19lib/util: Return some functions to util_str.cMartin Schwenke1-55/+0
These were moved in commit 8e704e4107b284bfc1e43f4c698ac0e6c5ae1800 when util_str.c was not shared. Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Volker Lendecke <vl@samba.org> Autobuild-User(master): Volker Lendecke <vl@samba.org> Autobuild-Date(master): Fri Sep 19 20:34:05 CEST 2014 on sn-devel-104
2014-09-19lib/util: Move next_token* functions to util_str.cMartin Schwenke1-146/+0
This is part of an attempt to untangle charset from util.c. Most of this was moved from util_str.c in commit 55903e6f9120f1ec58a8554813229975c3028a09. next_token() was moved from charset to util.c in commit 4be643d4ce33d5ce2bf9deacc3f6d0fde90cf626 so that it would be alongside next_token_talloc(). Now that util_str.c is in shared lib/util it is no longer necessary to have these in util.c. Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Volker Lendecke <vl@samba.org>