From: Jeremy Allison Date: Thu, 3 Jun 2021 00:30:26 +0000 (-0700) Subject: s3: smbd: Add is_visible_fsp(). X-Git-Tag: tevent-0.11.0~581 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b25109d4f4ea56917f4f7d2b17a1b6709c8d4511;p=thirdparty%2Fsamba.git s3: smbd: Add is_visible_fsp(). Not yet used. Signed-off-by: Jeremy Allison Reviewed-by: Ralph Boehme --- diff --git a/source3/smbd/dir.c b/source3/smbd/dir.c index d20bfa142ab..75e1c2e4ef9 100644 --- a/source3/smbd/dir.c +++ b/source3/smbd/dir.c @@ -1449,6 +1449,100 @@ bool is_visible_file(connection_struct *conn, return ret; } +/******************************************************************* + Should the file be seen by the client? +********************************************************************/ + +bool is_visible_fsp(struct files_struct *fsp, bool use_veto) +{ + bool hide_unreadable = false; + bool hide_unwriteable = false; + bool hide_special = false; + int hide_new_files_timeout = 0; + const char *last_component = NULL; + + /* + * If the file does not exist, there's no point checking + * the configuration options. We succeed, on the basis that the + * checks *might* have passed if the file was present. + */ + if (fsp == NULL) { + return true; + } + + hide_unreadable = lp_hide_unreadable(SNUM(fsp->conn)); + hide_unwriteable = lp_hide_unwriteable_files(SNUM(fsp->conn)); + hide_special = lp_hide_special_files(SNUM(fsp->conn)); + hide_new_files_timeout = lp_hide_new_files_timeout(SNUM(fsp->conn)); + + if (fsp->base_fsp != NULL) { + /* Only operate on non-stream files. */ + fsp = fsp->base_fsp; + } + + /* Get the last component of the base name. */ + last_component = strrchr_m(fsp->fsp_name->base_name, '/'); + if (!last_component) { + last_component = fsp->fsp_name->base_name; + } else { + last_component++; /* Go past '/' */ + } + + if (ISDOT(last_component) || ISDOTDOT(last_component)) { + return true; /* . and .. are always visible. */ + } + + /* If it's a vetoed file, pretend it doesn't even exist */ + if (use_veto && IS_VETO_PATH(fsp->conn, last_component)) { + DBG_ERR("file %s is vetoed.\n", fsp_str_dbg(fsp)); + return false; + } + + if (hide_unreadable || + hide_unwriteable || + hide_special || + (hide_new_files_timeout != 0)) + { + /* Honour _hide unreadable_ option */ + if (hide_unreadable && + !user_can_read_file(fsp->conn, + fsp->conn->cwd_fsp, + fsp->fsp_name)) + { + DBG_DEBUG("file %s is unreadable.\n", + fsp_str_dbg(fsp)); + return false; + } + /* Honour _hide unwriteable_ option */ + if (hide_unwriteable && + !user_can_write_file(fsp->conn, + fsp->conn->cwd_fsp, + fsp->fsp_name)) + { + DBG_DEBUG("file %s is unwritable.\n", + fsp_str_dbg(fsp)); + return false; + } + /* Honour _hide_special_ option */ + if (hide_special && file_is_special(fsp->conn, fsp->fsp_name)) { + DBG_DEBUG("file %s is special.\n", + fsp_str_dbg(fsp)); + return false; + } + + if (hide_new_files_timeout != 0) { + double age = timespec_elapsed( + &fsp->fsp_name->st.st_ex_mtime); + + if (age < (double)hide_new_files_timeout) { + return false; + } + } + } + + return true; +} + static int smb_Dir_destructor(struct smb_Dir *dir_hnd) { files_struct *fsp = dir_hnd->fsp; diff --git a/source3/smbd/proto.h b/source3/smbd/proto.h index f9691656ea2..9b521dc3a6e 100644 --- a/source3/smbd/proto.h +++ b/source3/smbd/proto.h @@ -233,6 +233,7 @@ bool is_visible_file(connection_struct *conn, const char *name, SMB_STRUCT_STAT *pst, bool use_veto); +bool is_visible_fsp(files_struct *fsp, bool use_veto); struct smb_Dir *OpenDir(TALLOC_CTX *mem_ctx, connection_struct *conn, const struct smb_filename *smb_fname,