The branch, master has been updated via a3126ebfe57 lib: Use struct initialization in imessaging_client_init() via 2d4aa599943 lib: Fix whitespace via ff747f691ec lib: Fix dbwrap_tdb.h prerequisites via b1b5d32c540 lib: Give tallocmsg.c its own header via b8e409e755b lib: Fix whitespace via 00141ca4704 smbd: Remove an outdated comment via 18d9b1b17cf smbd: Remove struct open_symlink_err via adca0ffd712 smbd: Remove "unparsed" from struct open_symlink_err via 8ca649025ae smbd: Remove "st" from struct open_symlink_err via 331a49ca394 smbd: Fix returning symlink stat info in the NO_OPATH case via a2a77842a13 smbd: Make read_symlink_reparse() return a reparse_data_buffer via 57e548841f9 smbd: Simplify users of fsp_fullbasepath() from 06c589aaa1a python/samba/tests/krb5: Extend PKINIT tests to cover UF_SMARTCARD_REQUIRED
https://git.samba.org/?p=samba.git;a=shortlog;h=master - Log ----------------------------------------------------------------- commit a3126ebfe5736f5e8af9bff3a6e8d7db1929e377 Author: Volker Lendecke <v...@samba.org> Date: Tue Feb 27 15:39:30 2024 +0100 lib: Use struct initialization in imessaging_client_init() Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Andreas Schneider <a...@samba.org> Autobuild-User(master): Andreas Schneider <a...@cryptomilk.org> Autobuild-Date(master): Thu Mar 28 09:13:43 UTC 2024 on atb-devel-224 commit 2d4aa599943a5860ebc0cc54d85012b360453bdc Author: Volker Lendecke <v...@samba.org> Date: Tue Feb 27 15:39:16 2024 +0100 lib: Fix whitespace Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Andreas Schneider <a...@samba.org> commit ff747f691ec30c964094550e6a9a0fc1f19fb0ff Author: Volker Lendecke <v...@samba.org> Date: Wed Feb 21 10:55:55 2024 +0100 lib: Fix dbwrap_tdb.h prerequisites It uses enum dbwrap_lock_order, so include dbwrap.h Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Andreas Schneider <a...@samba.org> commit b1b5d32c54099e4a1c61d0a81ceaab986b62ce52 Author: Volker Lendecke <v...@samba.org> Date: Tue Feb 20 13:04:28 2024 +0100 lib: Give tallocmsg.c its own header Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Andreas Schneider <a...@samba.org> commit b8e409e755baf77184995f72d640f0de7ed6808e Author: Volker Lendecke <v...@samba.org> Date: Wed Feb 28 16:45:57 2024 +0100 lib: Fix whitespace Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Andreas Schneider <a...@samba.org> commit 00141ca4704698028fa0137d4eecb37ba2385e8b Author: Volker Lendecke <v...@samba.org> Date: Sat Feb 10 14:27:38 2024 +0100 smbd: Remove an outdated comment Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Andreas Schneider <a...@samba.org> commit 18d9b1b17cfee79b8d2b78ac99ca31600b002a6e Author: Volker Lendecke <v...@samba.org> Date: Sun Feb 4 18:07:19 2024 +0100 smbd: Remove struct open_symlink_err This was just a wrapper for a single pointer, remove it Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Andreas Schneider <a...@samba.org> commit adca0ffd712ecfa26f2255f86e3882a9c124c429 Author: Volker Lendecke <v...@samba.org> Date: Sun Feb 4 17:42:28 2024 +0100 smbd: Remove "unparsed" from struct open_symlink_err We have the reserved field unparsed_path_length as part of struct symlink_reparse_struct. Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Andreas Schneider <a...@samba.org> commit 8ca649025aee31b4a3a0f5f8fb62861d4a41b864 Author: Volker Lendecke <v...@samba.org> Date: Sun Feb 4 17:27:50 2024 +0100 smbd: Remove "st" from struct open_symlink_err Since c96010a2a9f nobody reads it anymore Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Andreas Schneider <a...@samba.org> commit 331a49ca394f185473d0b5ba1c566a32ab01b6ff Author: Volker Lendecke <v...@samba.org> Date: Sun Feb 4 18:50:47 2024 +0100 smbd: Fix returning symlink stat info in the NO_OPATH case Our callers don't look at symlink_err's struct stat anymore, they look at the fname's one since we return them properly even for symlinks. So don't bother filling in symlink_err->st, nobody reads it anyways. Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Andreas Schneider <a...@samba.org> commit a2a77842a13c3c4a561ec8d5d298bbab60fafd1a Author: Volker Lendecke <v...@samba.org> Date: Sun Feb 4 16:07:22 2024 +0100 smbd: Make read_symlink_reparse() return a reparse_data_buffer Will make generalized handling of reparse point error returns easier once we will also allow creating symlink reparse point files over smb. Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Andreas Schneider <a...@samba.org> commit 57e548841f9b560e7caf84965e3ca4d36997bf17 Author: Volker Lendecke <v...@samba.org> Date: Sun Feb 4 11:10:18 2024 +0100 smbd: Simplify users of fsp_fullbasepath() All three users had to strip a trailing "/.". Centralize this. Signed-off-by: Volker Lendecke <v...@samba.org> Reviewed-by: Andreas Schneider <a...@samba.org> ----------------------------------------------------------------------- Summary of changes: lib/dbwrap/dbwrap_tdb.h | 2 +- source3/include/proto.h | 5 - source3/lib/ctdbd_conn.c | 2 +- source3/lib/messages.c | 1 + source3/lib/tallocmsg.c | 6 +- .../lib/tallocmsg.h | 14 +- source3/smbd/filename.c | 38 +++-- source3/smbd/files.c | 166 ++++++++++----------- source3/smbd/notify.c | 11 -- source3/smbd/proto.h | 41 ++--- source3/smbd/smb1_trans2.c | 5 - source4/lib/messaging/irpc.h | 11 +- source4/lib/messaging/messaging.c | 16 +- source4/lib/messaging/messaging.h | 8 +- 14 files changed, 149 insertions(+), 177 deletions(-) copy lib/util/talloc_report_printf.h => source3/lib/tallocmsg.h (72%) Changeset truncated at 500 lines: diff --git a/lib/dbwrap/dbwrap_tdb.h b/lib/dbwrap/dbwrap_tdb.h index d5f49c7d574..9251538705c 100644 --- a/lib/dbwrap/dbwrap_tdb.h +++ b/lib/dbwrap/dbwrap_tdb.h @@ -20,7 +20,7 @@ #ifndef __DBWRAP_TDB_H__ #define __DBWRAP_TDB_H__ -#include <talloc.h> +#include "lib/dbwrap/dbwrap.h" struct db_context; diff --git a/source3/include/proto.h b/source3/include/proto.h index ed45485e654..389bb2fc935 100644 --- a/source3/include/proto.h +++ b/source3/include/proto.h @@ -222,11 +222,6 @@ bool getgroups_unix_user(TALLOC_CTX *mem_ctx, const char *user, gid_t primary_gid, gid_t **ret_groups, uint32_t *p_ngroups); -/* The following definitions come from lib/tallocmsg.c */ - -void register_msg_pool_usage(TALLOC_CTX *mem_ctx, - struct messaging_context *msg_ctx); - /* The following definitions come from lib/time.c */ uint32_t convert_time_t_to_uint32_t(time_t t); diff --git a/source3/lib/ctdbd_conn.c b/source3/lib/ctdbd_conn.c index f32397d9353..abee0eb87b1 100644 --- a/source3/lib/ctdbd_conn.c +++ b/source3/lib/ctdbd_conn.c @@ -1,4 +1,4 @@ -/* +/* Unix SMB/CIFS implementation. Samba internal messaging functions Copyright (C) 2007 by Volker Lendecke diff --git a/source3/lib/messages.c b/source3/lib/messages.c index 7d3d46960a9..b856a2889b1 100644 --- a/source3/lib/messages.c +++ b/source3/lib/messages.c @@ -62,6 +62,7 @@ #include "cluster_support.h" #include "ctdbd_conn.h" #include "ctdb_srvids.h" +#include "source3/lib/tallocmsg.h" #ifdef CLUSTER_SUPPORT #include "ctdb_protocol.h" diff --git a/source3/lib/tallocmsg.c b/source3/lib/tallocmsg.c index af5a90bb434..da05357a4df 100644 --- a/source3/lib/tallocmsg.c +++ b/source3/lib/tallocmsg.c @@ -16,9 +16,11 @@ along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#include "includes.h" -#include "messages.h" +#include "replace.h" +#include "source3/include/messages.h" +#include "source3/lib/tallocmsg.h" #include "lib/util/talloc_report_printf.h" +#include "lib/util/debug.h" static bool pool_usage_filter(struct messaging_rec *rec, void *private_data) { diff --git a/lib/util/talloc_report_printf.h b/source3/lib/tallocmsg.h similarity index 72% copy from lib/util/talloc_report_printf.h copy to source3/lib/tallocmsg.h index 7881e655243..9dd31a7c4b3 100644 --- a/lib/util/talloc_report_printf.h +++ b/source3/lib/tallocmsg.h @@ -1,7 +1,6 @@ /* - * talloc_report into a FILE - * - * Copyright Volker Lendecke <v...@samba.org> 2019 + * samba -- Unix SMB/CIFS implementation. + * Copyright (C) 2001, 2002 by Martin Pool * * 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 @@ -17,13 +16,14 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef _TALLOC_REPORT_PRINTF_H_ -#define _TALLOC_REPORT_PRINTF_H_ +#ifndef __SOURCE3_LIB_TALLOCMSG_H__ +#define __SOURCE3_LIB_TALLOCMSG_H__ #include "replace.h" -#include "system/filesys.h" #include <talloc.h> +struct messaging_context; -void talloc_full_report_printf(TALLOC_CTX *root, FILE *f); +void register_msg_pool_usage( + TALLOC_CTX *mem_ctx, struct messaging_context *msg_ctx); #endif diff --git a/source3/smbd/filename.c b/source3/smbd/filename.c index f80f67c1291..4370d733048 100644 --- a/source3/smbd/filename.c +++ b/source3/smbd/filename.c @@ -737,12 +737,12 @@ static NTSTATUS filename_convert_dirfsp_nosymlink( NTTIME twrp, struct files_struct **_dirfsp, struct smb_filename **_smb_fname, - struct open_symlink_err **_symlink_err) + struct reparse_data_buffer **_symlink_err) { struct smb_filename *smb_dirname = NULL; struct smb_filename *smb_fname_rel = NULL; struct smb_filename *smb_fname = NULL; - struct open_symlink_err *symlink_err = NULL; + struct reparse_data_buffer *symlink_err = NULL; const bool posix = (ucf_flags & UCF_POSIX_PATHNAMES); char *dirname = NULL; const char *fname_rel = NULL; @@ -846,6 +846,9 @@ static NTSTATUS filename_convert_dirfsp_nosymlink( &symlink_err); if (NT_STATUS_EQUAL(status, NT_STATUS_STOPPED_ON_SYMLINK)) { + struct symlink_reparse_struct + *lnk = &symlink_err->parsed.lnk; + size_t unparsed = lnk->unparsed_path_length; size_t name_in_len, dirname_len; name_in_len = strlen(name_in); @@ -853,7 +856,14 @@ static NTSTATUS filename_convert_dirfsp_nosymlink( SMB_ASSERT(name_in_len >= dirname_len); - symlink_err->unparsed += (name_in_len - dirname_len); + unparsed += (name_in_len - dirname_len); + + if (unparsed > UINT16_MAX) { + status = NT_STATUS_BUFFER_OVERFLOW; + goto fail; + } + + lnk->unparsed_path_length = unparsed; *_symlink_err = symlink_err; goto fail; @@ -950,10 +960,10 @@ static NTSTATUS filename_convert_dirfsp_nosymlink( * Upper layers might need the link target. Here we * still have the relname around, get the symlink err. */ - status = create_open_symlink_err(mem_ctx, - smb_dirname->fsp, - smb_fname_rel, - &symlink_err); + status = read_symlink_reparse(mem_ctx, + smb_dirname->fsp, + smb_fname_rel, + &symlink_err); if (!NT_STATUS_IS_OK(status)) { DBG_DEBUG("Could not read symlink for %s: %s\n", smb_fname_str_dbg( @@ -1126,7 +1136,8 @@ NTSTATUS filename_convert_dirfsp( struct files_struct **_dirfsp, struct smb_filename **_smb_fname) { - struct open_symlink_err *symlink_err = NULL; + struct reparse_data_buffer *symlink_err = NULL; + struct symlink_reparse_struct *lnk = NULL; NTSTATUS status; char *target = NULL; char *safe_target = NULL; @@ -1161,13 +1172,14 @@ next: if (!NT_STATUS_EQUAL(status, NT_STATUS_STOPPED_ON_SYMLINK)) { return status; } + lnk = &symlink_err->parsed.lnk; /* * If we're on an MSDFS share, see if this is * an MSDFS link. */ if (lp_host_msdfs() && lp_msdfs_root(SNUM(conn)) && - strnequal(symlink_err->reparse->substitute_name, "msdfs:", 6)) + strnequal(lnk->substitute_name, "msdfs:", 6)) { TALLOC_FREE(*_smb_fname); TALLOC_FREE(symlink_err); @@ -1175,7 +1187,7 @@ next: } if (!lp_follow_symlinks(SNUM(conn))) { - status = (symlink_err->unparsed == 0) + status = (lnk->unparsed_path_length == 0) ? NT_STATUS_OBJECT_NAME_NOT_FOUND : NT_STATUS_OBJECT_PATH_NOT_FOUND; TALLOC_FREE(symlink_err); @@ -1196,8 +1208,8 @@ next: target = symlink_target_path(mem_ctx, name_in, - symlink_err->reparse->substitute_name, - symlink_err->unparsed); + lnk->substitute_name, + lnk->unparsed_path_length); if (target == NULL) { return NT_STATUS_NO_MEMORY; } @@ -1206,7 +1218,7 @@ next: conn->connectpath, NULL, target, - symlink_err->unparsed, + lnk->unparsed_path_length, &safe_target); TALLOC_FREE(symlink_err); if (!NT_STATUS_IS_OK(status)) { diff --git a/source3/smbd/files.c b/source3/smbd/files.c index ef1eb1a78a8..046b58023bd 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -733,28 +733,34 @@ NTSTATUS readlink_talloc( return NT_STATUS_OK; } -NTSTATUS read_symlink_reparse( - TALLOC_CTX *mem_ctx, - struct files_struct *dirfsp, - struct smb_filename *smb_relname, - struct symlink_reparse_struct **_symlink) +NTSTATUS read_symlink_reparse(TALLOC_CTX *mem_ctx, + struct files_struct *dirfsp, + struct smb_filename *smb_relname, + struct reparse_data_buffer **_reparse) { - struct symlink_reparse_struct *symlink = NULL; + struct reparse_data_buffer *reparse = NULL; + struct symlink_reparse_struct *lnk = NULL; NTSTATUS status; - symlink = talloc_zero(mem_ctx, struct symlink_reparse_struct); - if (symlink == NULL) { + reparse = talloc_zero(mem_ctx, struct reparse_data_buffer); + if (reparse == NULL) { goto nomem; } + *reparse = (struct reparse_data_buffer){ + .tag = IO_REPARSE_TAG_SYMLINK, + }; + lnk = &reparse->parsed.lnk; - status = readlink_talloc( - symlink, dirfsp, smb_relname, &symlink->substitute_name); + status = readlink_talloc(reparse, + dirfsp, + smb_relname, + &lnk->substitute_name); if (!NT_STATUS_IS_OK(status)) { DBG_DEBUG("readlink_talloc failed: %s\n", nt_errstr(status)); goto fail; } - if (symlink->substitute_name[0] == '/') { + if (lnk->substitute_name[0] == '/') { char *subdir_path = NULL; char *abs_target_canon = NULL; const char *relative = NULL; @@ -768,9 +774,8 @@ NTSTATUS read_symlink_reparse( goto nomem; } - abs_target_canon = - canonicalize_absolute_path(talloc_tos(), - symlink->substitute_name); + abs_target_canon = canonicalize_absolute_path( + talloc_tos(), lnk->substitute_name); if (abs_target_canon == NULL) { goto nomem; } @@ -780,25 +785,25 @@ NTSTATUS read_symlink_reparse( abs_target_canon, &relative); if (in_share) { - TALLOC_FREE(symlink->substitute_name); - symlink->substitute_name = - talloc_strdup(symlink, relative); - if (symlink->substitute_name == NULL) { + TALLOC_FREE(lnk->substitute_name); + lnk->substitute_name = talloc_strdup(reparse, + relative); + if (lnk->substitute_name == NULL) { goto nomem; } } } - if (!IS_DIRECTORY_SEP(symlink->substitute_name[0])) { - symlink->flags |= SYMLINK_FLAG_RELATIVE; + if (!IS_DIRECTORY_SEP(lnk->substitute_name[0])) { + lnk->flags |= SYMLINK_FLAG_RELATIVE; } - *_symlink = symlink; + *_reparse = reparse; return NT_STATUS_OK; nomem: status = NT_STATUS_NO_MEMORY; fail: - TALLOC_FREE(symlink); + TALLOC_FREE(reparse); return status; } @@ -811,29 +816,6 @@ static bool full_path_extend(char **dir, const char *atname) return (*dir) != NULL; } -NTSTATUS create_open_symlink_err(TALLOC_CTX *mem_ctx, - files_struct *dirfsp, - struct smb_filename *smb_relname, - struct open_symlink_err **_err) -{ - struct open_symlink_err *err = NULL; - NTSTATUS status; - - err = talloc_zero(mem_ctx, struct open_symlink_err); - if (err == NULL) { - return NT_STATUS_NO_MEMORY; - } - - status = read_symlink_reparse(err, dirfsp, smb_relname, &err->reparse); - if (!NT_STATUS_IS_OK(status)) { - TALLOC_FREE(err); - return status; - } - - *_err = err; - return NT_STATUS_OK; -} - /* * Create the memcache-key for GETREALFILENAME_CACHE: This supplements * the stat cache for the last component to be looked up. Cache @@ -1012,14 +994,15 @@ lookup: return fd; } -NTSTATUS openat_pathref_fsp_nosymlink(TALLOC_CTX *mem_ctx, - struct connection_struct *conn, - struct files_struct *in_dirfsp, - const char *path_in, - NTTIME twrp, - bool posix, - struct smb_filename **_smb_fname, - struct open_symlink_err **_symlink_err) +NTSTATUS openat_pathref_fsp_nosymlink( + TALLOC_CTX *mem_ctx, + struct connection_struct *conn, + struct files_struct *in_dirfsp, + const char *path_in, + NTTIME twrp, + bool posix, + struct smb_filename **_smb_fname, + struct reparse_data_buffer **_symlink_err) { struct files_struct *dirfsp = in_dirfsp; struct smb_filename full_fname = { @@ -1033,7 +1016,7 @@ NTSTATUS openat_pathref_fsp_nosymlink(TALLOC_CTX *mem_ctx, .flags = full_fname.flags, }; struct smb_filename *result = NULL; - struct open_symlink_err *symlink_err = NULL; + struct reparse_data_buffer *symlink_err = NULL; struct files_struct *fsp = NULL; char *path = NULL, *next = NULL; bool ok, is_toplevel; @@ -1229,12 +1212,12 @@ next: * below. */ - status = create_open_symlink_err(mem_ctx, - dirfsp, - &rel_fname, - &symlink_err); + status = read_symlink_reparse(mem_ctx, + dirfsp, + &rel_fname, + &symlink_err); if (!NT_STATUS_IS_OK(status)) { - DBG_DEBUG("create_open_symlink_err failed: %s\n", + DBG_DEBUG("read_symlink_reparse failed: %s\n", nt_errstr(status)); goto fail; } @@ -1242,7 +1225,14 @@ next: if (next != NULL) { size_t parsed = next - path; size_t len = talloc_get_size(path); - symlink_err->unparsed = len - parsed; + size_t unparsed = len - parsed; + + if (unparsed > UINT16_MAX) { + status = NT_STATUS_BUFFER_OVERFLOW; + goto fail; + } + symlink_err->parsed.lnk + .unparsed_path_length = unparsed; } /* @@ -1253,7 +1243,7 @@ next: ret = SMB_VFS_FSTATAT(conn, dirfsp, &rel_fname, - &symlink_err->st, + &full_fname.st, AT_SYMLINK_NOFOLLOW); if (ret == -1) { status = map_nt_error_from_unix(errno); @@ -1265,7 +1255,7 @@ next: goto fail; } - if (!S_ISLNK(symlink_err->st.st_ex_mode)) { + if (!S_ISLNK(full_fname.st.st_ex_mode)) { /* * Hit a race: readlink_talloc() worked before * the fstatat(), but rel_fname changed to @@ -1282,20 +1272,20 @@ next: #endif if ((fd == -1) && (errno == ENOTDIR)) { - size_t parsed, len; + size_t parsed, len, unparsed; /* * dirfsp does not point at a directory, try a * freadlink. */ - status = create_open_symlink_err(mem_ctx, - dirfsp, - NULL, - &symlink_err); + status = read_symlink_reparse(mem_ctx, + dirfsp, + NULL, + &symlink_err); if (!NT_STATUS_IS_OK(status)) { - DBG_DEBUG("create_open_symlink_err failed: %s\n", + DBG_DEBUG("read_symlink_reparse failed: %s\n", nt_errstr(status)); status = NT_STATUS_NOT_A_DIRECTORY; goto fail; @@ -1303,9 +1293,14 @@ next: parsed = rel_fname.base_name - path; len = talloc_get_size(path); - symlink_err->unparsed = len - parsed; + unparsed = len - parsed; - symlink_err->st = dirfsp->fsp_name->st; + if (unparsed > UINT16_MAX) { + status = NT_STATUS_BUFFER_OVERFLOW; + goto fail; + } + + symlink_err->parsed.lnk.unparsed_path_length = unparsed; status = NT_STATUS_STOPPED_ON_SYMLINK; goto fail; @@ -1383,14 +1378,13 @@ done: * Last component was a symlink we opened with O_PATH, fail it * here. */ - status = create_open_symlink_err(mem_ctx, - fsp, - NULL, - &symlink_err); + status = read_symlink_reparse(mem_ctx, + fsp, + NULL, + &symlink_err); if (!NT_STATUS_IS_OK(status)) { return status; } - symlink_err->st = fsp->fsp_name->st; status = NT_STATUS_STOPPED_ON_SYMLINK; goto fail; @@ -2238,15 +2232,6 @@ void fsp_unbind_smb(struct smb_request *req, files_struct *fsp) fsp_fullbasepath(fsp, fullpath, sizeof(fullpath)); - /* - * Avoid /. at the end of the path name. notify can't -- Samba Shared Repository