From: Ralph Boehme Date: Fri, 15 Jan 2021 09:12:29 +0000 (+0100) Subject: pysmbd: use real dirfsp for SMB_VFS_MKDIRAT() X-Git-Tag: samba-4.14.0rc1~12 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=33e1f3cafebcad1e5d79360bf1fd320fe9cc09bd;p=thirdparty%2Fsamba.git pysmbd: use real dirfsp for SMB_VFS_MKDIRAT() Signed-off-by: Ralph Boehme Reviewed-by: Jeremy Allison --- diff --git a/source3/smbd/pysmbd.c b/source3/smbd/pysmbd.c index 216de7a82fd..042e31b79d6 100644 --- a/source3/smbd/pysmbd.c +++ b/source3/smbd/pysmbd.c @@ -1026,8 +1026,12 @@ static PyObject *py_smbd_mkdir(PyObject *self, PyObject *args, PyObject *kwargs) TALLOC_CTX *frame = talloc_stackframe(); struct connection_struct *conn = NULL; struct smb_filename *smb_fname = NULL; + struct smb_filename *parent_fname = NULL; + struct smb_filename *base_name = NULL; + NTSTATUS status; int ret; mode_t saved_umask; + bool ok; if (!PyArg_ParseTupleAndKeywords(args, kwargs, @@ -1076,13 +1080,33 @@ static PyObject *py_smbd_mkdir(PyObject *self, PyObject *args, PyObject *kwargs) return NULL; } + ok = parent_smb_fname(frame, + smb_fname, + &parent_fname, + &base_name); + if (!ok) { + TALLOC_FREE(frame); + return NULL; + } + + ret = vfs_stat(conn, parent_fname); + if (ret == -1) { + TALLOC_FREE(frame); + return NULL; + } + status = openat_pathref_fsp(conn->cwd_fsp, parent_fname); + if (!NT_STATUS_IS_OK(status)) { + TALLOC_FREE(frame); + return NULL; + } + /* we want total control over the permissions on created files, so set our umask to 0 */ saved_umask = umask(0); ret = SMB_VFS_MKDIRAT(conn, - conn->cwd_fsp, - smb_fname, + parent_fname->fsp, + base_name, 00755); umask(saved_umask);