diff options
author | Tim Potter <tpot@samba.org> | 2002-10-21 09:53:31 +0000 |
---|---|---|
committer | Tim Potter <tpot@samba.org> | 2002-10-21 09:53:31 +0000 |
commit | 91895706b747345698febcb17bd4b9c445b6f15f (patch) | |
tree | 0d370a9ed836d2589f255d7565e505393838ad88 /source3/python | |
parent | 4eb2eab364b327d1498d9eb36c743434b689c1e1 (diff) | |
download | samba-91895706b747345698febcb17bd4b9c445b6f15f.tar.gz samba-91895706b747345698febcb17bd4b9c445b6f15f.tar.xz samba-91895706b747345698febcb17bd4b9c445b6f15f.zip |
Fixed up tconx function. Implemented nt_create_andx, query_secdesc
and set_secdesc functions.
(This used to be commit 3fd568ef5c984f089e7799d9ff55395330716641)
Diffstat (limited to 'source3/python')
-rw-r--r-- | source3/python/py_smb.c | 133 |
1 files changed, 121 insertions, 12 deletions
diff --git a/source3/python/py_smb.c b/source3/python/py_smb.c index 77d7bb32fce..c9ac24659db 100644 --- a/source3/python/py_smb.c +++ b/source3/python/py_smb.c @@ -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 } }; |