summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorAndrew Bartlett <abartlet@samba.org>2012-10-26 17:25:53 +1100
committerAndrew Bartlett <abartlet@samba.org>2012-10-26 17:26:20 +1100
commite107c6ace73ac40894fdd66860cfeae9115d5cd9 (patch)
tree93876bded1ad18df85c4ca32fd76d7079e81d192 /source3
parent52ace6767fddb389e3393c4b19685e59782c6a90 (diff)
downloadsamba-e107c6ace73ac40894fdd66860cfeae9115d5cd9.tar.gz
samba-e107c6ace73ac40894fdd66860cfeae9115d5cd9.tar.bz2
samba-e107c6ace73ac40894fdd66860cfeae9115d5cd9.zip
pysmbd: Add hook for unlink() so python scripts can remove xattr.tdb entries
If we do not provide a way to remove files from xattr.tdb, we can re-use the inode. Andrew Bartlett
Diffstat (limited to 'source3')
-rw-r--r--source3/smbd/pysmbd.c68
1 files changed, 68 insertions, 0 deletions
diff --git a/source3/smbd/pysmbd.c b/source3/smbd/pysmbd.c
index 5e2daa1f71..cfc4012630 100644
--- a/source3/smbd/pysmbd.c
+++ b/source3/smbd/pysmbd.c
@@ -331,6 +331,71 @@ static PyObject *py_smbd_chown(PyObject *self, PyObject *args)
}
/*
+ chown a file
+ */
+static PyObject *py_smbd_unlink(PyObject *self, PyObject *args)
+{
+ connection_struct *conn;
+ NTSTATUS status = NT_STATUS_OK;
+ int ret;
+ struct smb_filename *smb_fname = NULL;
+ char *fname;
+ int uid, gid;
+ TALLOC_CTX *frame;
+ mode_t saved_umask;
+
+ if (!PyArg_ParseTuple(args, "s", &fname))
+ return NULL;
+
+ frame = talloc_stackframe();
+
+ conn = talloc_zero(frame, connection_struct);
+ if (conn == NULL) {
+ PyErr_NoMemory();
+ return NULL;
+ }
+
+ if (!(conn->params = talloc(conn, struct share_params))) {
+ PyErr_NoMemory();
+ return NULL;
+ }
+
+ /* we want total control over the permissions on created files,
+ so set our umask to 0 */
+ saved_umask = umask(0);
+
+ conn->params->service = -1;
+
+ set_conn_connectpath(conn, "/");
+
+ smbd_vfs_init(conn);
+
+ status = create_synthetic_smb_fname_split(frame, fname, NULL,
+ &smb_fname);
+ if (!NT_STATUS_IS_OK(status)) {
+ TALLOC_FREE(frame);
+ umask(saved_umask);
+ PyErr_NTSTATUS_IS_ERR_RAISE(status);
+ }
+
+ ret = SMB_VFS_UNLINK(conn, smb_fname);
+ if (ret != 0) {
+ status = map_nt_error_from_unix_common(errno);
+ DEBUG(0,("unlink returned failure: %s\n", strerror(errno)));
+ }
+
+ umask(saved_umask);
+
+ conn_free(conn);
+
+ TALLOC_FREE(frame);
+
+ PyErr_NTSTATUS_IS_ERR_RAISE(status);
+
+ Py_RETURN_NONE;
+}
+
+/*
check if we have ACL support
*/
static PyObject *py_smbd_have_posix_acls(PyObject *self, PyObject *args)
@@ -495,6 +560,9 @@ static PyMethodDef py_smbd_methods[] = {
{ "chown",
(PyCFunction)py_smbd_chown, METH_VARARGS,
NULL },
+ { "unlink",
+ (PyCFunction)py_smbd_unlink, METH_VARARGS,
+ NULL },
{ NULL }
};