Fixed up tconx function. Implemented nt_create_andx, query_secdesc
authorTim Potter <tpot@samba.org>
Mon, 21 Oct 2002 09:53:31 +0000 (09:53 +0000)
committerTim Potter <tpot@samba.org>
Mon, 21 Oct 2002 09:53:31 +0000 (09:53 +0000)
and set_secdesc functions.
(This used to be commit 3fd568ef5c984f089e7799d9ff55395330716641)

source3/python/py_smb.c

index 77d7bb32fce6c019cac268462267579f48a6607d..c9ac24659db6fc0bdb2fe927b3afaee1c9ba5bdc 100644 (file)
@@ -102,7 +102,7 @@ static PyObject *py_smb_session_setup(PyObject *self, PyObject *args,
        char *username, *domain, *password, *errstr;
        BOOL result;
 
-       if (!PyArg_ParseTupleAndKeywords(args, kw, "O", kwlist, &creds))
+       if (!PyArg_ParseTupleAndKeywords(args, kw, "|O", kwlist, &creds))
                return NULL;
 
        if (!py_parse_creds(creds, &username, &domain, &password, &errstr)) {
@@ -120,29 +120,125 @@ static PyObject *py_smb_session_setup(PyObject *self, PyObject *args,
 static PyObject *py_smb_tconx(PyObject *self, PyObject *args, PyObject *kw)
 {
        cli_state_object *cli = (cli_state_object *)self;
-       static char *kwlist[] = { "service", "creds" };
-       PyObject *creds;
-       char *service, *username, *domain, *password, *errstr;
+       static char *kwlist[] = { "service", NULL };
+       char *service;
        BOOL result;
 
-       if (!PyArg_ParseTupleAndKeywords(args, kw, "sO", kwlist, &service, 
-                                        &creds))
+       if (!PyArg_ParseTupleAndKeywords(args, kw, "s", kwlist, &service))
                return NULL;
 
-       if (!py_parse_creds(creds, &username, &domain, &password, &errstr)) {
-               free(errstr);
+       result = cli_send_tconX(
+               cli->cli, service, strequal(service, "IPC$") ? "IPC" : 
+               "?????", "", 1);
+
+       return Py_BuildValue("i", result);
+}
+
+static PyObject *py_smb_nt_create_andx(PyObject *self, PyObject *args,
+                                      PyObject *kw)
+{
+       cli_state_object *cli = (cli_state_object *)self;
+       static char *kwlist[] = { "filename", "desired_access", 
+                                 "file_attributes", "share_access",
+                                 "create_disposition", NULL };
+       char *filename;
+       uint32 desired_access, file_attributes = 0, 
+               share_access = FILE_SHARE_READ | FILE_SHARE_WRITE,
+               create_disposition = FILE_EXISTS_OPEN, create_options = 0;
+       int result;
+
+       /* Parse parameters */
+
+       if (!PyArg_ParseTupleAndKeywords(
+                   args, kw, "si|iiii", kwlist, &filename, &desired_access,
+                   &file_attributes, &share_access, &create_disposition,
+                   &create_options))
+               return NULL;
+
+       result = cli_nt_create_full(
+               cli->cli, filename, desired_access, file_attributes,
+               share_access, create_disposition, create_options);
+
+       /* Return FID */
+
+       return PyInt_FromLong(result);
+}
+
+static PyObject *py_smb_query_secdesc(PyObject *self, PyObject *args,
+                                     PyObject *kw)
+{
+       cli_state_object *cli = (cli_state_object *)self;
+       static char *kwlist[] = { "fnum", NULL };
+       PyObject *result;
+       SEC_DESC *secdesc = NULL;
+       int fnum;
+       TALLOC_CTX *mem_ctx;
+
+       /* Parse parameters */
+
+       if (!PyArg_ParseTupleAndKeywords(
+                   args, kw, "i", kwlist, &fnum))
+               return NULL;
+
+       mem_ctx = talloc_init();
+
+       secdesc = cli_query_secdesc(cli->cli, fnum, mem_ctx);
+
+       /* FIXME: we should raise an exception here */
+
+       if (!secdesc) {
+               Py_INCREF(Py_None);
+               result = Py_None;
+               goto done;
+       }
+
+       if (!py_from_SECDESC(&result, secdesc)) {
+               PyErr_SetString(
+                       PyExc_TypeError,
+                       "Invalid security descriptor returned");
+               result = NULL;
+               goto done;
+       }
+
+ done:
+       talloc_destroy(mem_ctx);
+
+       return result;
+       
+}
+
+static PyObject *py_smb_set_secdesc(PyObject *self, PyObject *args,
+                                   PyObject *kw)
+{
+       cli_state_object *cli = (cli_state_object *)self;
+       static char *kwlist[] = { "fnum", "security_descriptor", NULL };
+       PyObject *py_secdesc;
+       SEC_DESC *secdesc;
+       TALLOC_CTX *mem_ctx = talloc_init();
+       int fnum;
+       BOOL result;
+
+       /* Parse parameters */
+
+       if (!PyArg_ParseTupleAndKeywords(
+                   args, kw, "iO", kwlist, &fnum, &py_secdesc))
+               return NULL;
+
+       if (!py_to_SECDESC(&secdesc, py_secdesc, mem_ctx)) {
+               PyErr_SetString(PyExc_TypeError, 
+                               "Invalid security descriptor");
                return NULL;
        }
 
-       result = cli_send_tconX(
-               cli->cli, service, strequal(service, "IPC$") ? "IPC" : "?????", 
-               password, strlen(password) + 1);
+       result = cli_set_secdesc(cli->cli, fnum, secdesc);
 
-       return Py_BuildValue("i", result);
+       return PyInt_FromLong(result);
 }
 
 static PyMethodDef smb_hnd_methods[] = {
 
+       /* Session and connection handling */
+
        { "session_request", (PyCFunction)py_smb_session_request, 
          METH_VARARGS | METH_KEYWORDS, "Request a session" },
 
@@ -155,6 +251,19 @@ static PyMethodDef smb_hnd_methods[] = {
        { "tconx", (PyCFunction)py_smb_tconx,
          METH_VARARGS | METH_KEYWORDS, "Tree connect" },
 
+       /* File operations */
+
+       { "nt_create_andx", (PyCFunction)py_smb_nt_create_andx,
+         METH_VARARGS | METH_KEYWORDS, "NT Create&X" },
+
+       /* Security descriptors */
+
+       { "query_secdesc", (PyCFunction)py_smb_query_secdesc,
+         METH_VARARGS | METH_KEYWORDS, "Query security descriptor" },
+
+       { "set_secdesc", (PyCFunction)py_smb_set_secdesc,
+         METH_VARARGS | METH_KEYWORDS, "Set security descriptor" },
+
        { NULL }
 };