From 0e3a46fc0be02bdac08c5cbcca8dad98b39496b8 Mon Sep 17 00:00:00 2001 From: David Mulder Date: Tue, 15 Mar 2022 16:32:34 -0600 Subject: [PATCH] smbd: Move srvstr_get_path* to smb2_reply.c Signed-off-by: David Mulder Reviewed-by: Jeremy Allison --- source3/smbd/proto.h | 38 +++++------ source3/smbd/reply.c | 129 -------------------------------------- source3/smbd/smb2_reply.c | 129 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 148 insertions(+), 148 deletions(-) diff --git a/source3/smbd/proto.h b/source3/smbd/proto.h index 6cc980eab6f..978e98eb1ea 100644 --- a/source3/smbd/proto.h +++ b/source3/smbd/proto.h @@ -912,25 +912,6 @@ bool disk_quotas(connection_struct *conn, struct smb_filename *fname, /* The following definitions come from smbd/reply.c */ -size_t srvstr_get_path(TALLOC_CTX *ctx, - const char *inbuf, - uint16_t smb_flags2, - char **pp_dest, - const char *src, - size_t src_len, - int flags, - NTSTATUS *err); -size_t srvstr_get_path_posix(TALLOC_CTX *ctx, - const char *inbuf, - uint16_t smb_flags2, - char **pp_dest, - const char *src, - size_t src_len, - int flags, - NTSTATUS *err); -size_t srvstr_get_path_req(TALLOC_CTX *mem_ctx, struct smb_request *req, - char **pp_dest, const char *src, int flags, - NTSTATUS *err); size_t srvstr_pull_req_talloc(TALLOC_CTX *ctx, struct smb_request *req, char **dest, const uint8_t *src, int flags); bool check_fsp_open(connection_struct *conn, struct smb_request *req, @@ -1036,6 +1017,25 @@ void reply_getattrE(struct smb_request *req); NTSTATUS check_path_syntax(char *path); NTSTATUS check_path_syntax_posix(char *path); +size_t srvstr_get_path(TALLOC_CTX *ctx, + const char *inbuf, + uint16_t smb_flags2, + char **pp_dest, + const char *src, + size_t src_len, + int flags, + NTSTATUS *err); +size_t srvstr_get_path_posix(TALLOC_CTX *ctx, + const char *inbuf, + uint16_t smb_flags2, + char **pp_dest, + const char *src, + size_t src_len, + int flags, + NTSTATUS *err); +size_t srvstr_get_path_req(TALLOC_CTX *mem_ctx, struct smb_request *req, + char **pp_dest, const char *src, int flags, + NTSTATUS *err); /* The following definitions come from smbd/seal.c */ diff --git a/source3/smbd/reply.c b/source3/smbd/reply.c index 8b216681e2f..2ec4149c2f8 100644 --- a/source3/smbd/reply.c +++ b/source3/smbd/reply.c @@ -53,135 +53,6 @@ #include "source3/printing/rap_jobid.h" #include "source3/lib/substitute.h" -/**************************************************************************** - Pull a string and check the path allowing a wildcard - provide for error return. - Passes in posix flag. -****************************************************************************/ - -static size_t srvstr_get_path_internal(TALLOC_CTX *ctx, - const char *base_ptr, - uint16_t smb_flags2, - char **pp_dest, - const char *src, - size_t src_len, - int flags, - bool posix_pathnames, - NTSTATUS *err) -{ - size_t ret; - - *pp_dest = NULL; - - ret = srvstr_pull_talloc(ctx, base_ptr, smb_flags2, pp_dest, src, - src_len, flags); - - if (!*pp_dest) { - *err = NT_STATUS_INVALID_PARAMETER; - return ret; - } - - if (smb_flags2 & FLAGS2_DFS_PATHNAMES) { - /* - * For a DFS path the function parse_dfs_path() - * will do the path processing, just make a copy. - */ - *err = NT_STATUS_OK; - return ret; - } - - if (posix_pathnames) { - *err = check_path_syntax_posix(*pp_dest); - } else { - *err = check_path_syntax(*pp_dest); - } - - return ret; -} - -/**************************************************************************** - Pull a string and check the path - provide for error return. -****************************************************************************/ - -size_t srvstr_get_path(TALLOC_CTX *ctx, - const char *base_ptr, - uint16_t smb_flags2, - char **pp_dest, - const char *src, - size_t src_len, - int flags, - NTSTATUS *err) -{ - return srvstr_get_path_internal(ctx, - base_ptr, - smb_flags2, - pp_dest, - src, - src_len, - flags, - false, - err); -} - -/**************************************************************************** - Pull a string and check the path - provide for error return. - posix_pathnames version. -****************************************************************************/ - -size_t srvstr_get_path_posix(TALLOC_CTX *ctx, - const char *base_ptr, - uint16_t smb_flags2, - char **pp_dest, - const char *src, - size_t src_len, - int flags, - NTSTATUS *err) -{ - return srvstr_get_path_internal(ctx, - base_ptr, - smb_flags2, - pp_dest, - src, - src_len, - flags, - true, - err); -} - - -size_t srvstr_get_path_req(TALLOC_CTX *mem_ctx, struct smb_request *req, - char **pp_dest, const char *src, int flags, - NTSTATUS *err) -{ - ssize_t bufrem = smbreq_bufrem(req, src); - - if (bufrem < 0) { - *err = NT_STATUS_INVALID_PARAMETER; - return 0; - } - - if (req->posix_pathnames) { - return srvstr_get_path_internal(mem_ctx, - (const char *)req->inbuf, - req->flags2, - pp_dest, - src, - bufrem, - flags, - true, - err); - } else { - return srvstr_get_path_internal(mem_ctx, - (const char *)req->inbuf, - req->flags2, - pp_dest, - src, - bufrem, - flags, - false, - err); - } -} - /** * pull a string from the smb_buf part of a packet. In this case the * string can either be null terminated or it can be terminated by the diff --git a/source3/smbd/smb2_reply.c b/source3/smbd/smb2_reply.c index ba5ad648fea..4048284990e 100644 --- a/source3/smbd/smb2_reply.c +++ b/source3/smbd/smb2_reply.c @@ -243,3 +243,132 @@ NTSTATUS check_path_syntax_posix(char *path) { return check_path_syntax_internal(path, true); } + +/**************************************************************************** + Pull a string and check the path allowing a wildcard - provide for error return. + Passes in posix flag. +****************************************************************************/ + +static size_t srvstr_get_path_internal(TALLOC_CTX *ctx, + const char *base_ptr, + uint16_t smb_flags2, + char **pp_dest, + const char *src, + size_t src_len, + int flags, + bool posix_pathnames, + NTSTATUS *err) +{ + size_t ret; + + *pp_dest = NULL; + + ret = srvstr_pull_talloc(ctx, base_ptr, smb_flags2, pp_dest, src, + src_len, flags); + + if (!*pp_dest) { + *err = NT_STATUS_INVALID_PARAMETER; + return ret; + } + + if (smb_flags2 & FLAGS2_DFS_PATHNAMES) { + /* + * For a DFS path the function parse_dfs_path() + * will do the path processing, just make a copy. + */ + *err = NT_STATUS_OK; + return ret; + } + + if (posix_pathnames) { + *err = check_path_syntax_posix(*pp_dest); + } else { + *err = check_path_syntax(*pp_dest); + } + + return ret; +} + +/**************************************************************************** + Pull a string and check the path - provide for error return. +****************************************************************************/ + +size_t srvstr_get_path(TALLOC_CTX *ctx, + const char *base_ptr, + uint16_t smb_flags2, + char **pp_dest, + const char *src, + size_t src_len, + int flags, + NTSTATUS *err) +{ + return srvstr_get_path_internal(ctx, + base_ptr, + smb_flags2, + pp_dest, + src, + src_len, + flags, + false, + err); +} + +/**************************************************************************** + Pull a string and check the path - provide for error return. + posix_pathnames version. +****************************************************************************/ + +size_t srvstr_get_path_posix(TALLOC_CTX *ctx, + const char *base_ptr, + uint16_t smb_flags2, + char **pp_dest, + const char *src, + size_t src_len, + int flags, + NTSTATUS *err) +{ + return srvstr_get_path_internal(ctx, + base_ptr, + smb_flags2, + pp_dest, + src, + src_len, + flags, + true, + err); +} + + +size_t srvstr_get_path_req(TALLOC_CTX *mem_ctx, struct smb_request *req, + char **pp_dest, const char *src, int flags, + NTSTATUS *err) +{ + ssize_t bufrem = smbreq_bufrem(req, src); + + if (bufrem < 0) { + *err = NT_STATUS_INVALID_PARAMETER; + return 0; + } + + if (req->posix_pathnames) { + return srvstr_get_path_internal(mem_ctx, + (const char *)req->inbuf, + req->flags2, + pp_dest, + src, + bufrem, + flags, + true, + err); + } else { + return srvstr_get_path_internal(mem_ctx, + (const char *)req->inbuf, + req->flags2, + pp_dest, + src, + bufrem, + flags, + false, + err); + } +}