1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-22 13:34:15 +03:00

vfs_recycle: remember resolved config->repository in vfs_recycle_connect()

This should not change during the lifetime of the tcon.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=15659

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Noel Power <noel.power@suse.com>
Reviewed-by: Volker Lendecke <vl@samba.org>
This commit is contained in:
Stefan Metzmacher 2024-06-14 10:07:02 +02:00
parent c229a84b44
commit 53b72ea4d2

View File

@ -55,11 +55,14 @@ static int vfs_recycle_connect(struct vfs_handle_struct *handle,
const char *service, const char *service,
const char *user) const char *user)
{ {
const struct loadparm_substitution *lp_sub =
loadparm_s3_global_substitution();
struct recycle_config_data *config = NULL; struct recycle_config_data *config = NULL;
int ret; int ret;
int t; int t;
const char *buff = NULL; const char *buff = NULL;
const char **tmplist = NULL; const char **tmplist = NULL;
char *repository = NULL;
ret = SMB_VFS_NEXT_CONNECT(handle, service, user); ret = SMB_VFS_NEXT_CONNECT(handle, service, user);
if (ret < 0) { if (ret < 0) {
@ -80,13 +83,26 @@ static int vfs_recycle_connect(struct vfs_handle_struct *handle,
"recycle", "recycle",
"repository", "repository",
".recycle"); ".recycle");
config->repository = talloc_strdup(config, buff); repository = talloc_sub_full(
if (config->repository == NULL) { config,
DBG_ERR("talloc_strdup(%s) failed\n", buff); lp_servicename(talloc_tos(), lp_sub, SNUM(handle->conn)),
handle->conn->session_info->unix_info->unix_name,
handle->conn->connectpath,
handle->conn->session_info->unix_token->gid,
handle->conn->session_info->unix_info->sanitized_username,
handle->conn->session_info->info->domain_name,
buff);
if (repository == NULL) {
DBG_ERR("talloc_sub_full() failed\n");
TALLOC_FREE(config); TALLOC_FREE(config);
errno = ENOMEM; errno = ENOMEM;
return -1; return -1;
} }
/* shouldn't we allow absolute path names here? --metze */
/* Yes :-). JRA. */
trim_char(repository, '\0', '/');
config->repository = repository;
config->keeptree = lp_parm_bool(SNUM(handle->conn), config->keeptree = lp_parm_bool(SNUM(handle->conn),
"recycle", "recycle",
"keeptree", "keeptree",
@ -460,16 +476,12 @@ static int recycle_unlink_internal(vfs_handle_struct *handle,
int flags) int flags)
{ {
TALLOC_CTX *frame = NULL; TALLOC_CTX *frame = NULL;
const struct loadparm_substitution *lp_sub =
loadparm_s3_global_substitution();
connection_struct *conn = handle->conn;
struct smb_filename *full_fname = NULL; struct smb_filename *full_fname = NULL;
char *path_name = NULL; char *path_name = NULL;
const char *temp_name = NULL; const char *temp_name = NULL;
const char *final_name = NULL; const char *final_name = NULL;
struct smb_filename *smb_fname_final = NULL; struct smb_filename *smb_fname_final = NULL;
const char *base = NULL; const char *base = NULL;
char *repository = NULL;
int i = 1; int i = 1;
off_t file_size; /* space_avail; */ off_t file_size; /* space_avail; */
bool exist; bool exist;
@ -483,21 +495,7 @@ static int recycle_unlink_internal(vfs_handle_struct *handle,
frame = talloc_stackframe(); frame = talloc_stackframe();
repository = talloc_sub_full( if (config->repository[0] == '\0') {
frame,
lp_servicename(frame, lp_sub, SNUM(conn)),
conn->session_info->unix_info->unix_name,
conn->connectpath,
conn->session_info->unix_token->gid,
conn->session_info->unix_info->sanitized_username,
conn->session_info->info->domain_name,
config->repository);
ALLOC_CHECK(repository, done);
/* shouldn't we allow absolute path names here? --metze */
/* Yes :-). JRA. */
trim_char(repository, '\0', '/');
if(!repository || *(repository) == '\0') {
DEBUG(3, ("recycle: repository path not set, purging %s...\n", DEBUG(3, ("recycle: repository path not set, purging %s...\n",
smb_fname_str_dbg(smb_fname))); smb_fname_str_dbg(smb_fname)));
rc = SMB_VFS_NEXT_UNLINKAT(handle, rc = SMB_VFS_NEXT_UNLINKAT(handle,
@ -517,8 +515,8 @@ static int recycle_unlink_internal(vfs_handle_struct *handle,
} }
/* we don't recycle the recycle bin... */ /* we don't recycle the recycle bin... */
if (strncmp(full_fname->base_name, repository, if (strncmp(full_fname->base_name, config->repository,
strlen(repository)) == 0) { strlen(config->repository)) == 0) {
DEBUG(3, ("recycle: File is within recycling bin, unlinking ...\n")); DEBUG(3, ("recycle: File is within recycling bin, unlinking ...\n"));
rc = SMB_VFS_NEXT_UNLINKAT(handle, rc = SMB_VFS_NEXT_UNLINKAT(handle,
dirfsp, dirfsp,