pysmbd: add py_smbd_create_file
authorJoe Guo <joeg@catalyst.net.nz>
Fri, 1 Jun 2018 01:48:31 +0000 (13:48 +1200)
committerAndrew Bartlett <abartlet@samba.org>
Thu, 28 Jun 2018 07:25:09 +0000 (09:25 +0200)
Add create_file function to smbd API.

Signed-off-by: Joe Guo <joeg@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
source3/smbd/pysmbd.c

index cd6ff1f53c5f5c09345890a0e264b99c37592168..b220fbe691f800882e91aa0d1d1aa7c1f3ceabcc 100644 (file)
@@ -768,6 +768,51 @@ static PyObject *py_smbd_mkdir(PyObject *self, PyObject *args, PyObject *kwargs)
        Py_RETURN_NONE;
 }
 
+
+/*
+  Create an empty file
+ */
+static PyObject *py_smbd_create_file(PyObject *self, PyObject *args, PyObject *kwargs)
+{
+       const char * const kwnames[] = { "fname", "service", NULL };
+       char *fname, *service = NULL;
+       TALLOC_CTX *frame = talloc_stackframe();
+       struct connection_struct *conn = NULL;
+       struct files_struct *fsp = NULL;
+       NTSTATUS status;
+
+       if (!PyArg_ParseTupleAndKeywords(args,
+                                        kwargs,
+                                        "s|z",
+                                        discard_const_p(char *,
+                                                        kwnames),
+                                        &fname,
+                                        &service)) {
+               TALLOC_FREE(frame);
+               return NULL;
+       }
+
+       conn = get_conn_tos(service);
+       if (!conn) {
+               TALLOC_FREE(frame);
+               return NULL;
+       }
+
+       status = init_files_struct(frame,
+                                  fname,
+                                  conn,
+                                  O_CREAT|O_EXCL|O_RDWR,
+                                  &fsp);
+       if (!NT_STATUS_IS_OK(status)) {
+               DBG_ERR("init_files_struct failed: %s\n",
+                       nt_errstr(status));
+       }
+
+       TALLOC_FREE(frame);
+       Py_RETURN_NONE;
+}
+
+
 static PyMethodDef py_smbd_methods[] = {
        { "have_posix_acls",
                (PyCFunction)py_smbd_have_posix_acls, METH_NOARGS,
@@ -796,6 +841,9 @@ static PyMethodDef py_smbd_methods[] = {
        { "mkdir",
                (PyCFunction)py_smbd_mkdir, METH_VARARGS|METH_KEYWORDS,
                NULL },
+       { "create_file",
+               (PyCFunction)py_smbd_create_file, METH_VARARGS|METH_KEYWORDS,
+               NULL },
        { NULL }
 };