[SCM] Samba Shared Repository - branch master updated

Andrew Bartlett abartlet at samba.org
Wed Nov 15 23:12:02 UTC 2023


The branch, master has been updated
       via  7c1e3f0d82a python:tests: Ensure we clean up callbacks in pymessaging tests
       via  beff3e6d776 python:tests: Fix crashing pymessaging tests
       via  ec3e420840e util/charset: Prefer PULL_LE_U16() to older SVAL() macro
       via  99e0a0f21ad util/charset/tests: Add tests for UTF‐16 string length functions
       via  7ebf7f424d0 s4:torture: Remove trailing whitespace
       via  a46746381b2 util/charset: Add utf16_len_n()
       via  74a5a3b74e1 util/charset: Include final UTF‐16 code unit in length calculation loop
       via  516f35b5a11 util/charset: Add utf16_len()
       via  16996d145b1 util/charset: Rename utf16_len() to utf16_null_terminated_len()
       via  542e5a3039a util/charset: Rename utf16_len_n() to utf16_null_terminated_len_n()
       via  c2a743190fc s4:smb_server: Remove trailing whitespace
       via  a63cf19ee43 s4:libcli: Remove trailing whitespace
       via  982238e914a util/charset: Remove trailing whitespace
       via  1e029b2cd75 librpc:ndr: Convert NDR flags types to enumerations
       via  2562f24d112 librpc:ndr: Fix comment
       via  5b693597b0d libndr:ndr: Allow only one string encoding flag
       via  ce2f4ecd596 librpc:ndr: Prohibit STR_NULLTERM|STR_NOTERM flags combination
       via  ef0109d2cd7 librpc:ndr: Check return values of talloc functions
       via  b11978a06cf librpc:ndr: Fix error messages
       via  609965b6ea0 libcli/security:sddl_decode message offset safety latch
       via  1f4e018ef1b libcli/security/test_sddl_conditional_ace: add message tests
       via  2b4f97249f3 libcli/security:sddl_parse: add some top level error messages
       via  15fcf9b769b libcl/security:sddl_decode_acl: expand a comment
       via  01f8b61035a libcli/security:sddl_decode_ace: fix ';' count message
       via  dd41357fcd0 libcl/security:sddl_decode_acl: add a message
       via  206db403b49 libcli/security:sddl_decode_ace: add more messages
       via  f712f8d3710 libcli/security: adjust log verbosity in sddl_decode
       via  74c6cf44b9d libcli/security:sddl_decode_ace: turn DBG_WARNINGs into messages
       via  23a83d37df6 pytest:samba-tool domain auth policy: expect error message detail
       via  b18fe675c0d libcli/security:sddl_decode_err_msg(): don't pretend msg is optional (CID1548624)
      from  12e5c15a97b vfs_zfsacl: Call stat CAP_DAC_OVERRIDE functions

https://git.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit 7c1e3f0d82a08cf0e5fea4fabbc7ad05d0ebbb84
Author: Joseph Sutton <josephsutton at catalyst.net.nz>
Date:   Tue Nov 14 12:45:35 2023 +1300

    python:tests: Ensure we clean up callbacks in pymessaging tests
    
    Not calling ‘deregister()’ results in memory getting leaked.
    
    Signed-off-by: Joseph Sutton <josephsutton at catalyst.net.nz>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>
    
    Autobuild-User(master): Andrew Bartlett <abartlet at samba.org>
    Autobuild-Date(master): Wed Nov 15 23:11:13 UTC 2023 on atb-devel-224

commit beff3e6d7762b423500a7ebf163878ede68b4a2f
Author: Joseph Sutton <josephsutton at catalyst.net.nz>
Date:   Tue Nov 14 12:34:01 2023 +1300

    python:tests: Fix crashing pymessaging tests
    
    Commit 8c75d9fc73614fad29a998d08c4b11034ab2aebb changed
    Messaging.deregister() to take a two‐element tuple containing private
    data as well as a callback, but it did not change the call in
    samba.tests.messaging.MessagingTests.test_register to match.
    
    Since imessaging_deregister() completely ignored the ‘private_data’
    parameter passed to it (assuming the callback was registered with
    msg_type == -1), everything still appeared to work — until commit
    b22c21799527323877b330c16c23057582721abb changed Messaging.deregister()
    to no longer leak memory. Now the wrong variable had its reference count
    decremented, causing the test to crash.
    
    Signed-off-by: Joseph Sutton <josephsutton at catalyst.net.nz>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>

commit ec3e420840eded527a2a7bb1177b5daa79ee8448
Author: Joseph Sutton <josephsutton at catalyst.net.nz>
Date:   Thu Nov 9 12:46:17 2023 +1300

    util/charset: Prefer PULL_LE_U16() to older SVAL() macro
    
    Signed-off-by: Joseph Sutton <josephsutton at catalyst.net.nz>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>

commit 99e0a0f21adc36e42ecce56c88e584e38e6fb23d
Author: Joseph Sutton <josephsutton at catalyst.net.nz>
Date:   Tue Nov 14 12:31:07 2023 +1300

    util/charset/tests: Add tests for UTF‐16 string length functions
    
    Signed-off-by: Joseph Sutton <josephsutton at catalyst.net.nz>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>

commit 7ebf7f424d0b5d6872ee6a74e369ccd96de4b9f3
Author: Joseph Sutton <josephsutton at catalyst.net.nz>
Date:   Tue Nov 14 13:07:19 2023 +1300

    s4:torture: Remove trailing whitespace
    
    Signed-off-by: Joseph Sutton <josephsutton at catalyst.net.nz>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>

commit a46746381b2bf7c336e4411430ecfc5fbb3cbb2a
Author: Joseph Sutton <josephsutton at catalyst.net.nz>
Date:   Thu Nov 9 12:43:07 2023 +1300

    util/charset: Add utf16_len_n()
    
    This function returns the length in bytes — at most ‘n’ — of a UTF‐16
    string excluding the null terminator.
    
    Signed-off-by: Joseph Sutton <josephsutton at catalyst.net.nz>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>

commit 74a5a3b74e1388936307da9d06f4d1a816d7613f
Author: Joseph Sutton <josephsutton at catalyst.net.nz>
Date:   Tue Nov 14 14:38:48 2023 +1300

    util/charset: Include final UTF‐16 code unit in length calculation loop
    
    Change ‘<’ to ‘<=’ so that we check the final UTF‐16 code unit in our
    search for the null terminator. This makes no difference to the result:
    if we’ve reached the final code unit without finding a terminator, the
    final code unit will be included in the length whether it is a null
    terminator or not.
    
    Why make this change? We’re about to factor out this loop into a new
    function, utf16_len_n(), where including the final code unit *will*
    matter.
    
    Signed-off-by: Joseph Sutton <josephsutton at catalyst.net.nz>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>

commit 516f35b5a114136eaae283a53a6281b9895e29ed
Author: Joseph Sutton <josephsutton at catalyst.net.nz>
Date:   Thu Nov 9 12:39:02 2023 +1300

    util/charset: Add utf16_len()
    
    This function returns the length in bytes of a UTF‐16 string excluding
    the null terminator.
    
    Signed-off-by: Joseph Sutton <josephsutton at catalyst.net.nz>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>

commit 16996d145b15ad5f41b1ffd73434d7c984645d7e
Author: Joseph Sutton <josephsutton at catalyst.net.nz>
Date:   Thu Nov 9 12:36:21 2023 +1300

    util/charset: Rename utf16_len() to utf16_null_terminated_len()
    
    The new name indicates that — contrary to functions such as strnlen() —
    the length may include the terminator.
    
    Signed-off-by: Joseph Sutton <josephsutton at catalyst.net.nz>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>

commit 542e5a3039a0121646f2e4f108854e1ca4136a56
Author: Joseph Sutton <josephsutton at catalyst.net.nz>
Date:   Thu Nov 9 12:33:43 2023 +1300

    util/charset: Rename utf16_len_n() to utf16_null_terminated_len_n()
    
    The new name indicates that — contrary to functions such as strnlen() —
    the length may include the terminator.
    
    Signed-off-by: Joseph Sutton <josephsutton at catalyst.net.nz>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>

commit c2a743190fc0fb9bac87329cf1da4b715e59d5be
Author: Joseph Sutton <josephsutton at catalyst.net.nz>
Date:   Thu Nov 9 12:33:16 2023 +1300

    s4:smb_server: Remove trailing whitespace
    
    Signed-off-by: Joseph Sutton <josephsutton at catalyst.net.nz>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>

commit a63cf19ee43a2f3db071db846f9294176154368d
Author: Joseph Sutton <josephsutton at catalyst.net.nz>
Date:   Thu Nov 9 12:32:20 2023 +1300

    s4:libcli: Remove trailing whitespace
    
    Signed-off-by: Joseph Sutton <josephsutton at catalyst.net.nz>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>

commit 982238e914a3f8da8cc8c2290dd5d1359c01aab9
Author: Joseph Sutton <josephsutton at catalyst.net.nz>
Date:   Thu Nov 9 12:31:22 2023 +1300

    util/charset: Remove trailing whitespace
    
    Signed-off-by: Joseph Sutton <josephsutton at catalyst.net.nz>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>

commit 1e029b2cd754007cb4abac5c405ca37eb51c8a44
Author: Joseph Sutton <josephsutton at catalyst.net.nz>
Date:   Wed Nov 8 17:09:04 2023 +1300

    librpc:ndr: Convert NDR flags types to enumerations
    
    Using an enumeration rather than ‘uint32_t’ or ‘uint64_t’ means that
    debuggers such as gdb can now associate the flag constants with their
    respective types. This means that if you have an instance of these flags
    types, the debugger will show you the individual flags that make up the
    value rather than an inscrutable integer value.
    
    Signed-off-by: Joseph Sutton <josephsutton at catalyst.net.nz>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>

commit 2562f24d112775236a44d86404e634b1db6c992c
Author: Joseph Sutton <josephsutton at catalyst.net.nz>
Date:   Mon Nov 13 13:48:22 2023 +1300

    librpc:ndr: Fix comment
    
    Signed-off-by: Joseph Sutton <josephsutton at catalyst.net.nz>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>

commit 5b693597b0db6425e5d11b067f5b8aea301dca76
Author: Joseph Sutton <josephsutton at catalyst.net.nz>
Date:   Thu Jul 13 14:59:52 2023 +1200

    libndr:ndr: Allow only one string encoding flag
    
    Signed-off-by: Joseph Sutton <josephsutton at catalyst.net.nz>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>

commit ce2f4ecd5960b6e262f24fe739bb7a8bf0632866
Author: Joseph Sutton <josephsutton at catalyst.net.nz>
Date:   Thu Jul 13 14:44:40 2023 +1200

    librpc:ndr: Prohibit STR_NULLTERM|STR_NOTERM flags combination
    
    ndr_pull_string() prohibited this, but ndr_push_string() always masked
    STR_NOTERM out. Now the set of allowed flags should be consistent
    between the two functions.
    
    Signed-off-by: Joseph Sutton <josephsutton at catalyst.net.nz>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>

commit ef0109d2cd723d92b01888ea257dc3b8d1d9ac86
Author: Joseph Sutton <josephsutton at catalyst.net.nz>
Date:   Wed Nov 8 16:18:54 2023 +1300

    librpc:ndr: Check return values of talloc functions
    
    Signed-off-by: Joseph Sutton <josephsutton at catalyst.net.nz>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>

commit b11978a06cf6204b954ccd23b9818dbb93ddadca
Author: Joseph Sutton <josephsutton at catalyst.net.nz>
Date:   Thu Jul 13 14:37:27 2023 +1200

    librpc:ndr: Fix error messages
    
    Signed-off-by: Joseph Sutton <josephsutton at catalyst.net.nz>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>

commit 609965b6ea0f33016c13e431fe658c07983b4d9f
Author: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
Date:   Fri Nov 10 12:11:24 2023 +1300

    libcli/security:sddl_decode message offset safety latch
    
    the message offset is largely calculated using the differences
    between pointers in many places scattered throughout the code.
    
    If we got one of these wrong, we could easily have a SIZE_MAX-ish
    offset, which would be unfortunate if we came decided to display
    the offset using spaces.
    
    We can sanely limit the offset to the length of the SDDL.
    
    Signed-off-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>

commit 1f4e018ef1be97a5f5c32dcdc307a42b81054e40
Author: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
Date:   Fri Nov 10 11:44:56 2023 +1300

    libcli/security/test_sddl_conditional_ace: add message tests
    
    Signed-off-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>

commit 2b4f97249f35a2c4e1f0ece052afff443f9f1b60
Author: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
Date:   Fri Nov 10 11:33:56 2023 +1300

    libcli/security:sddl_parse: add some top level error messages
    
    the way we parse things, we can't really distinguish between complete
    nonsense and an ACL that seems to end early because of bad flags. That
    is, "D:ZZ(A;;;;;WD)" looks the same as "ZZ" to the parser. But at least
    we can point to the right place in the string.
    
    Signed-off-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>

commit 15fcf9b769bf0f7ab17804fc83020b4f1b2fb4f3
Author: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
Date:   Fri Nov 10 11:28:57 2023 +1300

    libcl/security:sddl_decode_acl: expand a comment
    
    Signed-off-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>

commit 01f8b61035afbcaf14997ce1e590451be4c754ca
Author: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
Date:   Fri Nov 10 11:28:35 2023 +1300

    libcli/security:sddl_decode_ace: fix ';' count message
    
    The wrong number of semicolons is usually one less than count (which
    counts sections separated by semicolons), except when count is zero.
    
    Signed-off-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>

commit dd41357fcd057a5ec347f7ec0bf2ea7d4271be5e
Author: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
Date:   Thu Nov 9 18:45:57 2023 +1300

    libcl/security:sddl_decode_acl: add a message
    
    Signed-off-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>

commit 206db403b4942334dba071107518b2b6a4c042d6
Author: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
Date:   Thu Nov 9 18:45:19 2023 +1300

    libcli/security:sddl_decode_ace: add more messages
    
    Signed-off-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>

commit f712f8d3710c1d4e65e5f4c9509e4039ca87d125
Author: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
Date:   Fri Nov 10 12:51:36 2023 +1300

    libcli/security: adjust log verbosity in sddl_decode
    
    Signed-off-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>

commit 74c6cf44b9d138f5a6ba878cfac55ddc5fbd9399
Author: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
Date:   Thu Nov 9 18:43:33 2023 +1300

    libcli/security:sddl_decode_ace: turn DBG_WARNINGs into messages
    
    This allows the messages to be more reliably presented by client tools
    in a useful way.
    
    The messages lose the trailing \n, and some were slightly tweaked (e.g.
    s/Resource ACE/Resource Attribute ACE/).
    
    They will still show up in logs for callers of sddl_decode(), but at
    NOTICE level rather than WARNING.
    
    Signed-off-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>

commit 23a83d37df6c23212f512a7786f2224b2764b324
Author: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
Date:   Fri Nov 10 11:47:07 2023 +1300

    pytest:samba-tool domain auth policy: expect error message detail
    
    The knownfail will stay around for a few commits, because the message
    we get is slightly wrong.
    
    Signed-off-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>

commit b18fe675c0d015b70cd6a1a6b8237438b345cc8a
Author: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
Date:   Thu Nov 9 17:56:48 2023 +1300

    libcli/security:sddl_decode_err_msg(): don't pretend msg is optional (CID1548624)
    
    Having it optionally NULL just complicates the code, and Coverity
    rightly complained.
    
    Signed-off-by: Douglas Bagnall <douglas.bagnall at catalyst.net.nz>
    Reviewed-by: Andrew Bartlett <abartlet at samba.org>

-----------------------------------------------------------------------

Summary of changes:
 lib/tdr/tdr.c                                      |   2 +-
 lib/util/charset/charset.h                         |  47 +++--
 lib/util/charset/tests/util_unistr.c               | 166 ++++++++++++++++++
 lib/util/charset/util_unistr.c                     |  43 +++--
 libcli/security/sddl.c                             | 139 +++++++++++----
 libcli/security/tests/test_sddl_conditional_ace.c  |  87 ++++++++++
 libcli/smb/smbXcli_base.c                          |   8 +-
 libcli/smb/util.c                                  |   2 +-
 librpc/ndr/libndr.h                                | 193 +++++++++++----------
 librpc/ndr/ndr_string.c                            |  90 +++++++---
 python/samba/tests/messaging.py                    |  29 +++-
 .../samba/tests/samba_tool/domain_auth_policy.py   |   6 +-
 source4/libcli/ldap/ldap_controls.c                |  55 +++---
 source4/libcli/raw/rawrequest.c                    |   4 +-
 source4/smb_server/smb/request.c                   |  64 +++----
 source4/torture/local/local.c                      |  55 +++---
 source4/torture/local/wscript_build                |   1 +
 17 files changed, 708 insertions(+), 283 deletions(-)
 create mode 100644 lib/util/charset/tests/util_unistr.c


Changeset truncated at 500 lines:

diff --git a/lib/tdr/tdr.c b/lib/tdr/tdr.c
index 6c87aa0b89d..cff1fc67d5e 100644
--- a/lib/tdr/tdr.c
+++ b/lib/tdr/tdr.c
@@ -148,7 +148,7 @@ NTSTATUS tdr_pull_charset(struct tdr_pull *tdr, TALLOC_CTX *ctx, const char **v,
 				length = ascii_len_n((const char*)tdr->data.data+tdr->offset, tdr->data.length-tdr->offset);
 				break;
 			case CH_UTF16:
-				length = utf16_len_n(tdr->data.data+tdr->offset, tdr->data.length-tdr->offset);
+				length = utf16_null_terminated_len_n(tdr->data.data+tdr->offset, tdr->data.length-tdr->offset);
 				break;
 
 			default:
diff --git a/lib/util/charset/charset.h b/lib/util/charset/charset.h
index 391430b0cf5..195655ba1e5 100644
--- a/lib/util/charset/charset.h
+++ b/lib/util/charset/charset.h
@@ -1,25 +1,25 @@
-/* 
+/*
    Unix SMB/CIFS implementation.
    charset defines
    Copyright (C) Andrew Tridgell 2001
    Copyright (C) Jelmer Vernooij 2002
-   
+
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
-   
+
    This program 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 General Public License for more details.
-   
+
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
-/* This is a public header file that is installed as part of Samba. 
- * If you remove any functions or change their signature, update 
+/* This is a public header file that is installed as part of Samba.
+ * If you remove any functions or change their signature, update
  * the so version number. */
 
 #ifndef __CHARSET_H__
@@ -105,17 +105,28 @@ size_t ucs2_align(const void *base_ptr, const void *p, int flags);
 
 /**
 return the number of bytes occupied by a buffer in CH_UTF16 format
-the result includes the null termination
 **/
 size_t utf16_len(const void *buf);
 
 /**
 return the number of bytes occupied by a buffer in CH_UTF16 format
 the result includes the null termination
+**/
+size_t utf16_null_terminated_len(const void *buf);
+
+/**
+return the number of bytes occupied by a buffer in CH_UTF16 format
 limited by 'n' bytes
 **/
 size_t utf16_len_n(const void *src, size_t n);
 
+/**
+return the number of bytes occupied by a buffer in CH_UTF16 format
+the result includes the null termination
+limited by 'n' bytes
+**/
+size_t utf16_null_terminated_len_n(const void *src, size_t n);
+
 char *strchr_m(const char *s, char c);
 /**
  * Calculate the number of units (8 or 16-bit, depending on the
@@ -181,13 +192,13 @@ bool pull_utf8_talloc(TALLOC_CTX *ctx, char **dest, const char *src, size_t *con
 ssize_t push_string(void *dest, const char *src, size_t dest_len, int flags);
 ssize_t pull_string(char *dest, const void *src, size_t dest_len, size_t src_len, int flags);
 
-bool convert_string_talloc(TALLOC_CTX *ctx, 
-			   charset_t from, charset_t to, 
-			   void const *src, size_t srclen, 
+bool convert_string_talloc(TALLOC_CTX *ctx,
+			   charset_t from, charset_t to,
+			   void const *src, size_t srclen,
 			   void *dest, size_t *converted_size);
 
 bool convert_string(charset_t from, charset_t to,
-		      void const *src, size_t srclen, 
+		      void const *src, size_t srclen,
 		      void *dest, size_t destlen,
 		      size_t *converted_size);
 bool convert_string_error(charset_t from, charset_t to,
@@ -196,8 +207,8 @@ bool convert_string_error(charset_t from, charset_t to,
 			  size_t *converted_size);
 
 struct smb_iconv_handle *get_iconv_handle(void);
-struct smb_iconv_handle *get_iconv_testing_handle(TALLOC_CTX *mem_ctx, 
-						  const char *dos_charset, 
+struct smb_iconv_handle *get_iconv_testing_handle(TALLOC_CTX *mem_ctx,
+						  const char *dos_charset,
 						  const char *unix_charset,
 						  bool use_builtin_handlers);
 struct smb_iconv_handle *reinit_iconv_handle(TALLOC_CTX *mem_ctx,
@@ -239,7 +250,7 @@ struct smb_iconv_handle *smb_iconv_handle_reinit(TALLOC_CTX *mem_ctx,
 
 bool convert_string_handle(struct smb_iconv_handle *ic,
 				charset_t from, charset_t to,
-				void const *src, size_t srclen, 
+				void const *src, size_t srclen,
 				void *dest, size_t destlen, size_t *converted_size);
 bool convert_string_error_handle(struct smb_iconv_handle *ic,
 				 charset_t from, charset_t to,
@@ -249,16 +260,16 @@ bool convert_string_error_handle(struct smb_iconv_handle *ic,
 
 bool convert_string_talloc_handle(TALLOC_CTX *ctx,
 				       struct smb_iconv_handle *ic,
-				       charset_t from, charset_t to, 
-				       void const *src, size_t srclen, 
+				       charset_t from, charset_t to,
+				       void const *src, size_t srclen,
 				       void *dest, size_t *converted_size);
 /* iconv */
 smb_iconv_t smb_iconv_open(const char *tocode, const char *fromcode);
 int smb_iconv_close(smb_iconv_t cd);
-size_t smb_iconv(smb_iconv_t cd, 
+size_t smb_iconv(smb_iconv_t cd,
 		 const char **inbuf, size_t *inbytesleft,
 		 char **outbuf, size_t *outbytesleft);
-smb_iconv_t smb_iconv_open_ex(TALLOC_CTX *mem_ctx, const char *tocode, 
+smb_iconv_t smb_iconv_open_ex(TALLOC_CTX *mem_ctx, const char *tocode,
 			      const char *fromcode, bool use_builtin_handlers);
 
 void smb_init_locale(void);
diff --git a/lib/util/charset/tests/util_unistr.c b/lib/util/charset/tests/util_unistr.c
new file mode 100644
index 00000000000..1a9fcaafdf5
--- /dev/null
+++ b/lib/util/charset/tests/util_unistr.c
@@ -0,0 +1,166 @@
+/*
+   Unix SMB/CIFS implementation.
+   test suite for the util_unistr utility functions
+
+   Copyright (C) Catalyst.Net Ltd. 2023
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+
+   This program 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 General Public License for more details.
+
+   You should have received a copy of the GNU General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include "includes.h"
+#include "torture/torture.h"
+
+#undef strcasecmp
+#undef strncasecmp
+
+struct torture_suite *torture_local_util_unistr(TALLOC_CTX *mem_ctx);
+
+static bool test_utf16_len(struct torture_context *tctx)
+{
+	static const uint16_t empty_string[] = {'\0'};
+	static const uint16_t foo_bar[] = {
+		'f', 'o', 'o', ' ', 'b', 'a', 'r', '\0'};
+	static const uint16_t foo_bar_alternative[] = {0xd83c,
+						       0xdd75,
+						       0xd83c,
+						       0xdd7e,
+						       0xd83c,
+						       0xdd7e,
+						       ' ',
+						       0xd83c,
+						       0xdd31,
+						       0xd83c,
+						       0xdd30,
+						       0xd83c,
+						       0xdd41,
+						       '\0'};
+
+	torture_assert_size_equal(tctx,
+				  utf16_len(empty_string),
+				  0,
+				  "length of empty string");
+	torture_assert_size_equal(tctx,
+				  utf16_null_terminated_len(empty_string),
+				  2,
+				  "null‐terminated length of empty string");
+	torture_assert_size_equal(tctx,
+				  utf16_len(foo_bar),
+				  14,
+				  "length of “foo bar”");
+	torture_assert_size_equal(tctx,
+				  utf16_null_terminated_len(foo_bar),
+				  16,
+				  "null‐terminated length of “foo bar”");
+	torture_assert_size_equal(tctx,
+				  utf16_len(foo_bar_alternative),
+				  26,
+				  "length of “🅵🅾🅾 🄱🄰🅁”");
+	torture_assert_size_equal(tctx,
+				  utf16_null_terminated_len(
+					  foo_bar_alternative),
+				  28,
+				  "null‐terminated length of “🅵🅾🅾 🄱🄰🅁”");
+
+	return true;
+}
+
+static bool test_utf16_len_n(struct torture_context *tctx)
+{
+	static const uint16_t empty_string[] = {'\0'};
+	static const uint16_t foo_bar[] = {'f', 'o', 'o', ' ', 'b', 'a', 'r'};
+	static const uint16_t null_terminated_foo_bar[] = {
+		'f', 'o', 'o', ' ', 'b', 'a', 'r', '\0'};
+	static const uint16_t twice_null_terminated_abc[] = {
+		'a', 'b', 'c', '\0', '\0'};
+
+	torture_assert_size_equal(tctx,
+				  utf16_len_n(empty_string, 0),
+				  0,
+				  "length of empty string");
+	torture_assert_size_equal(tctx,
+				  utf16_null_terminated_len_n(empty_string, 0),
+				  0,
+				  "null‐terminated length of empty string");
+
+	torture_assert_size_equal(tctx,
+				  utf16_len_n(empty_string,
+					      sizeof empty_string),
+				  0,
+				  "length of null‐terminated empty string");
+	torture_assert_size_equal(
+		tctx,
+		utf16_null_terminated_len_n(empty_string, sizeof empty_string),
+		2,
+		"null‐terminated length of null‐terminated empty string");
+
+	torture_assert_size_equal(tctx,
+				  utf16_len_n(foo_bar, sizeof foo_bar),
+				  14,
+				  "length of “foo bar”");
+	torture_assert_size_equal(tctx,
+				  utf16_null_terminated_len_n(foo_bar,
+							      sizeof foo_bar),
+				  14,
+				  "null‐terminated length of “foo bar”");
+
+	torture_assert_size_equal(tctx,
+				  utf16_len_n(null_terminated_foo_bar,
+					      sizeof null_terminated_foo_bar),
+				  14,
+				  "length of null‐terminated “foo bar”");
+	torture_assert_size_equal(
+		tctx,
+		utf16_null_terminated_len_n(null_terminated_foo_bar,
+					    sizeof null_terminated_foo_bar),
+		16,
+		"null‐terminated length of null‐terminated “foo bar”");
+
+	torture_assert_size_equal(tctx,
+				  utf16_len_n(null_terminated_foo_bar,
+					      sizeof null_terminated_foo_bar -
+						      1),
+				  14,
+				  "length of “foo bar” minus one byte");
+	torture_assert_size_equal(
+		tctx,
+		utf16_null_terminated_len_n(null_terminated_foo_bar,
+					    sizeof null_terminated_foo_bar - 1),
+		14,
+		"null‐terminated length of “foo bar” minus one byte");
+
+	torture_assert_size_equal(tctx,
+				  utf16_len_n(twice_null_terminated_abc,
+					      sizeof twice_null_terminated_abc),
+				  6,
+				  "length of twice–null‐terminated “abc”");
+	torture_assert_size_equal(
+		tctx,
+		utf16_null_terminated_len_n(twice_null_terminated_abc,
+					    sizeof twice_null_terminated_abc),
+		8,
+		"null‐terminated length of twice–null‐terminated “abc”");
+
+	return true;
+}
+
+struct torture_suite *torture_local_util_unistr(TALLOC_CTX *mem_ctx)
+{
+	struct torture_suite *suite = torture_suite_create(mem_ctx,
+							   "util_unistr");
+
+	torture_suite_add_simple_test(suite, "utf16_len", test_utf16_len);
+	torture_suite_add_simple_test(suite, "utf16_len_n", test_utf16_len_n);
+
+	return suite;
+}
diff --git a/lib/util/charset/util_unistr.c b/lib/util/charset/util_unistr.c
index ac80f902362..7d8ff68074b 100644
--- a/lib/util/charset/util_unistr.c
+++ b/lib/util/charset/util_unistr.c
@@ -1,19 +1,19 @@
-/* 
+/*
    Unix SMB/CIFS implementation.
    Samba utility functions
    Copyright (C) Andrew Tridgell 1992-2001
    Copyright (C) Simo Sorce 2001
-   
+
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
-   
+
    This program 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 General Public License for more details.
-   
+
    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
@@ -193,27 +193,48 @@ size_t ucs2_align(const void *base_ptr, const void *p, int flags)
 
 /**
 return the number of bytes occupied by a buffer in CH_UTF16 format
-the result includes the null termination
 **/
 size_t utf16_len(const void *buf)
 {
 	size_t len;
 
-	for (len = 0; SVAL(buf,len); len += 2) ;
+	for (len = 0; PULL_LE_U16(buf,len); len += 2) ;
 
-	return len + 2;
+	return len;
 }
 
 /**
 return the number of bytes occupied by a buffer in CH_UTF16 format
 the result includes the null termination
+**/
+size_t utf16_null_terminated_len(const void *buf)
+{
+	return utf16_len(buf) + 2;
+}
+
+/**
+return the number of bytes occupied by a buffer in CH_UTF16 format
 limited by 'n' bytes
 **/
 size_t utf16_len_n(const void *src, size_t n)
 {
 	size_t len;
 
-	for (len = 0; (len+2 < n) && SVAL(src, len); len += 2) ;
+	for (len = 0; (len+2 <= n) && PULL_LE_U16(src, len); len += 2) ;
+
+	return len;
+}
+
+/**
+return the number of bytes occupied by a buffer in CH_UTF16 format
+the result includes the null termination
+limited by 'n' bytes
+**/
+size_t utf16_null_terminated_len_n(const void *src, size_t n)
+{
+	size_t len;
+
+	len = utf16_len_n(src, n);
 
 	if (len+2 <= n) {
 		len += 2;
@@ -501,9 +522,9 @@ static size_t pull_ucs2(char *dest, const void *src, size_t dest_len, size_t src
 
 	if (flags & STR_TERMINATE) {
 		if (src_len == (size_t)-1) {
-			src_len = utf16_len(src);
+			src_len = utf16_null_terminated_len(src);
 		} else {
-			src_len = utf16_len_n(src, src_len);
+			src_len = utf16_null_terminated_len_n(src, src_len);
 		}
 	}
 
@@ -521,7 +542,7 @@ static size_t pull_ucs2(char *dest, const void *src, size_t dest_len, size_t src
 
 /**
  Copy a string from a char* src to a unicode or ascii
- dos codepage destination choosing unicode or ascii based on the 
+ dos codepage destination choosing unicode or ascii based on the
  flags in the SMB buffer starting at base_ptr.
  Return the number of bytes occupied by the string in the destination.
  flags can have:
diff --git a/libcli/security/sddl.c b/libcli/security/sddl.c
index 97e579cfe32..2cad84a937a 100644
--- a/libcli/security/sddl.c
+++ b/libcli/security/sddl.c
@@ -536,7 +536,9 @@ static bool sddl_decode_ace(TALLOC_CTX *mem_ctx,
 	bool has_extra_data = false;
 	ZERO_STRUCTP(ace);
 
+	*msg_offset = 1;
 	if (*str != '(') {
+		*msg = talloc_strdup(mem_ctx, "Not an ACE");
 		return false;
 	}
 	str++;
@@ -585,18 +587,22 @@ static bool sddl_decode_ace(TALLOC_CTX *mem_ctx,
 	}
 	if (count != 6) {
 		/* we hit the '\0' or ')' before all of ';;;;;)' */
-		DBG_WARNING("malformed ACE with only %zu ';'\n", count);
+		*msg = talloc_asprintf(mem_ctx,
+				       "malformed ACE with only %zu ';'",
+				       MIN(count - 1, count));
 		return false;
 	}
 
 	/* parse ace type */
 	ok = sddl_map_flag(ace_types, tok[0], &len, &v);
 	if (!ok) {
-		DBG_WARNING("Unknown ACE type - %s\n", tok[0]);
+		*msg = talloc_asprintf(mem_ctx,
+				       "Unknown ACE type - %s", tok[0]);
 		return false;
 	}
 	if (tok[0][len] != '\0') {
-		DBG_WARNING("Garbage after ACE type - %s\n", tok[0]);
+		*msg = talloc_asprintf(mem_ctx,
+				       "Garbage after ACE type - %s", tok[0]);
 		return false;
 	}
 
@@ -607,22 +613,34 @@ static bool sddl_decode_ace(TALLOC_CTX *mem_ctx,
 	 */
 	if (sec_ace_callback(ace->type)) {
 		if (! has_extra_data) {
-			DBG_WARNING("callback ACE has no trailing data\n");
+			*msg = talloc_strdup(
+				mem_ctx,
+				"callback ACE has no trailing data");
+			*msg_offset = str - *sddl_copy;
 			return false;
 		}
 	} else if (sec_ace_resource(ace->type)) {
 		if (! has_extra_data) {
-			DBG_WARNING("resource ACE has no trailing data\n");
+			*msg = talloc_strdup(
+				mem_ctx,
+				"resource attribute ACE has no trailing data");
+			*msg_offset = str - *sddl_copy;
 			return false;
 		}
 	} else if (has_extra_data) {
-		DBG_WARNING("ACE has trailing section but is not a "
-			    "callback or resource ACE\n");
+		*msg = talloc_strdup(
+			mem_ctx,
+			"ACE has trailing section but is not a "
+			"callback or resource ACE");
+		*msg_offset = str - *sddl_copy;
 		return false;
 	}
 
 	/* ace flags */
 	if (!sddl_map_flags(ace_flags, tok[1], &v, NULL, false)) {
+		*msg = talloc_strdup(mem_ctx,
+				     "could not parse flags");
+		*msg_offset = tok[1] - *sddl_copy;
 		return false;
 	}
 	ace->flags = v;
@@ -630,6 +648,9 @@ static bool sddl_decode_ace(TALLOC_CTX *mem_ctx,
 	/* access mask */
 	ok = sddl_decode_access(tok[2], &ace->access_mask);
 	if (!ok) {
+		*msg = talloc_strdup(mem_ctx,
+				     "could not parse access string");
+		*msg_offset = tok[2] - *sddl_copy;
 		return false;
 	}


-- 
Samba Shared Repository



More information about the samba-cvs mailing list