s3-pysmbd: Add hook for a VFS chown()
authorAndrew Bartlett <abartlet@samba.org>
Tue, 21 Aug 2012 04:23:35 +0000 (14:23 +1000)
committerAndrew Bartlett <abartlet@samba.org>
Tue, 21 Aug 2012 05:25:49 +0000 (15:25 +1000)
source3/smbd/pysmbd.c

index 0004887720d78f30b3878a4d950702f0a8a2a15b..0e8ecaacf14609cc78189000a9434163fc885438 100644 (file)
@@ -273,6 +273,56 @@ static PyObject *py_smbd_set_simple_acl(PyObject *self, PyObject *args)
        Py_RETURN_NONE;
 }
 
+/*
+  chown a file
+ */
+static PyObject *py_smbd_chown(PyObject *self, PyObject *args)
+{
+       connection_struct *conn;
+       NTSTATUS status = NT_STATUS_OK;
+       int ret;
+
+       char *fname;
+       int uid, gid;
+       TALLOC_CTX *frame;
+
+       if (!PyArg_ParseTuple(args, "sii", &fname, &uid, &gid))
+               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;
+       }
+
+       conn->params->service = -1;
+
+       set_conn_connectpath(conn, "/");
+
+       smbd_vfs_init(conn);
+
+       ret = SMB_VFS_CHOWN( conn, fname, uid, gid);
+       if (ret != 0) {
+               status = map_nt_error_from_unix_common(ret);
+               DEBUG(0,("chwon returned failure: %s\n", strerror(ret)));
+       }
+
+       conn_free(conn);
+
+       TALLOC_FREE(frame);
+
+       PyErr_NTSTATUS_IS_ERR_RAISE(status);
+
+       Py_RETURN_NONE;
+}
+
 /*
   check if we have ACL support
  */
@@ -347,6 +397,9 @@ static PyMethodDef py_smbd_methods[] = {
        { "get_nt_acl",
                (PyCFunction)py_smbd_get_nt_acl, METH_VARARGS,
                NULL },
+       { "chown",
+               (PyCFunction)py_smbd_chown, METH_VARARGS,
+               NULL },
        { NULL }
 };