diff options
author | Jeremy Allison <jra@samba.org> | 2019-10-10 14:14:13 -0700 |
---|---|---|
committer | Jeremy Allison <jra@samba.org> | 2019-10-15 18:46:37 +0000 |
commit | 634a4d13e197e01ae509c88bd6c6487008a86f71 (patch) | |
tree | 27635cfe6c00d46613aa8dd573bef00ce8b29ea4 /source3/smbd | |
parent | 99bfdb6e81925760af2a6e89fc6ac55768c88b78 (diff) | |
download | samba-634a4d13e197e01ae509c88bd6c6487008a86f71.tar.gz |
s3: pysmbd: Change py_smbd_chown() to use SMB_VFS_FCHOWN() internally.
Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Ralph Böhme <slow@samba.org>
Diffstat (limited to 'source3/smbd')
-rw-r--r-- | source3/smbd/pysmbd.c | 46 |
1 files changed, 33 insertions, 13 deletions
diff --git a/source3/smbd/pysmbd.c b/source3/smbd/pysmbd.c index 69cc96b34a4..e5836b49f54 100644 --- a/source3/smbd/pysmbd.c +++ b/source3/smbd/pysmbd.c @@ -472,11 +472,11 @@ static PyObject *py_smbd_chown(PyObject *self, PyObject *args, PyObject *kwargs) const char * const kwnames[] = { "fname", "uid", "gid", "service", NULL }; connection_struct *conn; int ret; - + NTSTATUS status; char *fname, *service = NULL; int uid, gid; TALLOC_CTX *frame; - struct smb_filename *smb_fname = NULL; + struct files_struct *fsp = NULL; if (!PyArg_ParseTupleAndKeywords(args, kwargs, "sii|z", discard_const_p(char *, kwnames), @@ -491,25 +491,45 @@ static PyObject *py_smbd_chown(PyObject *self, PyObject *args, PyObject *kwargs) return NULL; } - smb_fname = synthetic_smb_fname(talloc_tos(), - fname, - NULL, - NULL, - lp_posix_pathnames() ? - SMB_FILENAME_POSIX_PATH : 0); - if (smb_fname == NULL) { + /* first, try to open it as a file with flag O_RDWR */ + status = init_files_struct(frame, + fname, + conn, + O_RDWR, + &fsp); + if (!NT_STATUS_IS_OK(status) && errno == EISDIR) { + /* if fail, try to open as dir */ + status = init_files_struct(frame, + fname, + conn, + DIRECTORY_FLAGS, + &fsp); + } + + if (!NT_STATUS_IS_OK(status)) { + DBG_ERR("init_files_struct failed: %s\n", + nt_errstr(status)); + if (fsp != NULL) { + SMB_VFS_CLOSE(fsp); + } TALLOC_FREE(frame); - errno = ENOMEM; - return PyErr_SetFromErrno(PyExc_OSError); + /* + * The following macro raises a python + * error then returns NULL. + */ + PyErr_NTSTATUS_IS_ERR_RAISE(status); } - ret = SMB_VFS_CHOWN(conn, smb_fname, uid, gid); + ret = SMB_VFS_FCHOWN(fsp, uid, gid); if (ret != 0) { + int saved_errno = errno; + SMB_VFS_CLOSE(fsp); TALLOC_FREE(frame); - errno = ret; + errno = saved_errno; return PyErr_SetFromErrno(PyExc_OSError); } + SMB_VFS_CLOSE(fsp); TALLOC_FREE(frame); Py_RETURN_NONE; |