diff options
Diffstat (limited to 'source3/python')
-rwxr-xr-x | source3/python/examples/tdbpack/test_tdbpack.py | 66 | ||||
-rw-r--r-- | source3/python/py_common.c | 7 | ||||
-rw-r--r-- | source3/python/py_common_proto.h | 2 | ||||
-rw-r--r-- | source3/python/py_lsa.c | 2 | ||||
-rw-r--r-- | source3/python/py_samr.c | 3 | ||||
-rw-r--r-- | source3/python/py_smb.c | 133 | ||||
-rw-r--r-- | source3/python/py_spoolss_drivers.c | 6 | ||||
-rw-r--r-- | source3/python/py_spoolss_ports.c | 2 | ||||
-rw-r--r-- | source3/python/py_spoolss_printers.c | 6 | ||||
-rw-r--r-- | source3/python/py_tdbpack.c | 34 | ||||
-rwxr-xr-x | source3/python/setup.py | 3 |
11 files changed, 67 insertions, 197 deletions
diff --git a/source3/python/examples/tdbpack/test_tdbpack.py b/source3/python/examples/tdbpack/test_tdbpack.py index 659dc0efed..36fed881e3 100755 --- a/source3/python/examples/tdbpack/test_tdbpack.py +++ b/source3/python/examples/tdbpack/test_tdbpack.py @@ -17,12 +17,13 @@ string, with one character per field.""" __author__ = 'Martin Pool <mbp@sourcefrog.net>' import unittest -import oldtdbutil +# import tdbutil import samba.tdbpack -both_unpackers = (samba.tdbpack.unpack, oldtdbutil.unpack) -both_packers = (samba.tdbpack.pack, oldtdbutil.pack) - +packer = samba.tdbpack.pack +unpacker = samba.tdbpack.unpack + + class PackTests(unittest.TestCase): symm_cases = [('B', ['hello' * 51], '\xff\0\0\0' + 'hello' * 51), ('w', [42], '\x2a\0'), @@ -77,13 +78,11 @@ class PackTests(unittest.TestCase): def test_symmetric(self): """Cookbook of symmetric pack/unpack tests """ - for packer in both_packers: - for unpacker in both_unpackers: - for format, values, expected in self.symm_cases: - self.assertEquals(packer(format, values), expected) - out, rest = unpacker(format, expected) - self.assertEquals(rest, '') - self.assertEquals(list(values), list(out)) + for format, values, expected in self.symm_cases: + self.assertEquals(packer(format, values), expected) + out, rest = unpacker(format, expected) + self.assertEquals(rest, '') + self.assertEquals(list(values), list(out)) def test_pack(self): @@ -101,30 +100,25 @@ class PackTests(unittest.TestCase): # as if you called list() ] - for packer in both_packers: - for format, values, expected in cases: - self.assertEquals(packer(format, values), expected) + for format, values, expected in cases: + self.assertEquals(packer(format, values), expected) def test_unpack_extra(self): # Test leftover data - for unpacker in both_unpackers: - for format, values, packed in self.symm_cases: - out, rest = unpacker(format, packed + 'hello sailor!') - self.assertEquals(rest, 'hello sailor!') - self.assertEquals(list(values), list(out)) + for format, values, packed in self.symm_cases: + out, rest = unpacker(format, packed + 'hello sailor!') + self.assertEquals(rest, 'hello sailor!') + self.assertEquals(list(values), list(out)) def test_unpack(self): """Cookbook of tricky unpack tests""" cases = [ - # Apparently I couldn't think of any tests that weren't - # symmetric :-/ ] - for unpacker in both_unpackers: - for format, values, expected in cases: - out, rest = unpacker(format, expected) - self.assertEquals(rest, '') - self.assertEquals(list(values), list(out)) + for format, values, expected in cases: + out, rest = unpacker(format, expected) + self.assertEquals(rest, '') + self.assertEquals(list(values), list(out)) def test_pack_failures(self): @@ -147,7 +141,7 @@ class PackTests(unittest.TestCase): ('f', [2], TypeError), ('P', [None], TypeError), ('P', (), IndexError), - ('f', [hex], TypeError), + ('f', [packer], TypeError), ('fw', ['hello'], IndexError), ('f', [u'hello'], TypeError), ('B', [2], TypeError), @@ -159,11 +153,10 @@ class PackTests(unittest.TestCase): ('fQ', ['2'], IndexError), (2, [2], TypeError), ({}, {}, TypeError)] - for packer in both_packers: - for format, values, throwable_class in cases: - def do_pack(): - packer(format, values) - self.assertRaises(throwable_class, do_pack) + for format, values, throwable_class in cases: + def do_pack(): + packer(format, values) + self.assertRaises(throwable_class, do_pack) def test_unpack_failures(self): @@ -189,11 +182,10 @@ class PackTests(unittest.TestCase): ('B', 'foobar', IndexError), ('BB', '\x01\0\0\0a\x01', IndexError), ] - - for unpacker in both_unpackers: - for format, values, throwable_class in cases: - def do_unpack(): - unpacker(format, values) + + for format, values, throwable_class in cases: + def do_unpack(): + unpacker(format, values) self.assertRaises(throwable_class, do_unpack) diff --git a/source3/python/py_common.c b/source3/python/py_common.c index 364271d57c..d15df234d1 100644 --- a/source3/python/py_common.c +++ b/source3/python/py_common.c @@ -218,7 +218,7 @@ BOOL py_parse_creds(PyObject *creds, char **username, char **domain, be freed by calling free(). */ struct cli_state *open_pipe_creds(char *server, PyObject *creds, - int pipe_idx, char **errstr) + char *pipe_name, char **errstr) { char *username, *password, *domain; struct cli_state *cli; @@ -240,9 +240,10 @@ struct cli_state *open_pipe_creds(char *server, PyObject *creds, return NULL; } - if (!cli_nt_session_open(cli, pipe_idx)) { + if (!cli_nt_session_open(cli, pipe_name)) { cli_shutdown(cli); - asprintf(errstr, "error opening pipe index %d", pipe_idx); + free(cli); + asprintf(errstr, "error opening %s", pipe_name); return NULL; } diff --git a/source3/python/py_common_proto.h b/source3/python/py_common_proto.h index b012c17e15..89f0f35fc9 100644 --- a/source3/python/py_common_proto.h +++ b/source3/python/py_common_proto.h @@ -15,7 +15,7 @@ PyObject *py_setup_logging(PyObject *self, PyObject *args, PyObject *kw); BOOL py_parse_creds(PyObject *creds, char **username, char **domain, char **password, char **errstr); struct cli_state *open_pipe_creds(char *server, PyObject *creds, - int pipe_idx, char **errstr); + char *pipe_name, char **errstr); BOOL get_level_value(PyObject *dict, uint32 *level); /* The following definitions come from python/py_ntsec.c */ diff --git a/source3/python/py_lsa.c b/source3/python/py_lsa.c index d54a2289ef..0584cf716b 100644 --- a/source3/python/py_lsa.c +++ b/source3/python/py_lsa.c @@ -78,7 +78,7 @@ static PyObject *lsa_open_policy(PyObject *self, PyObject *args, server += 2; - if (!(cli = open_pipe_creds(server, creds, PI_LSARPC, &errstr))) { + if (!(cli = open_pipe_creds(server, creds, PIPE_LSARPC, &errstr))) { PyErr_SetString(lsa_error, errstr); free(errstr); return NULL; diff --git a/source3/python/py_samr.c b/source3/python/py_samr.c index 92a2eaf063..917a90a2fb 100644 --- a/source3/python/py_samr.c +++ b/source3/python/py_samr.c @@ -393,7 +393,7 @@ static PyObject *samr_connect(PyObject *self, PyObject *args, PyObject *kw) return NULL; } - if (!(cli = open_pipe_creds(server, creds, PI_SAMR, &errstr))) { + if (!(cli = open_pipe_creds(server, creds, PIPE_SAMR, &errstr))) { PyErr_SetString(samr_error, errstr); free(errstr); return NULL; @@ -409,6 +409,7 @@ static PyObject *samr_connect(PyObject *self, PyObject *args, PyObject *kw) if (!NT_STATUS_IS_OK(ntstatus)) { cli_shutdown(cli); + SAFE_FREE(cli); PyErr_SetObject(samr_ntstatus, py_ntstatus_tuple(ntstatus)); goto done; } diff --git a/source3/python/py_smb.c b/source3/python/py_smb.c index c9ac24659d..77d7bb32fc 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,125 +120,29 @@ 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", NULL }; - char *service; - BOOL result; - - if (!PyArg_ParseTupleAndKeywords(args, kw, "s", kwlist, &service)) - return NULL; - - 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; + static char *kwlist[] = { "service", "creds" }; + PyObject *creds; + char *service, *username, *domain, *password, *errstr; BOOL result; - /* Parse parameters */ - - if (!PyArg_ParseTupleAndKeywords( - args, kw, "iO", kwlist, &fnum, &py_secdesc)) + if (!PyArg_ParseTupleAndKeywords(args, kw, "sO", kwlist, &service, + &creds)) return NULL; - if (!py_to_SECDESC(&secdesc, py_secdesc, mem_ctx)) { - PyErr_SetString(PyExc_TypeError, - "Invalid security descriptor"); + if (!py_parse_creds(creds, &username, &domain, &password, &errstr)) { + free(errstr); return NULL; } - result = cli_set_secdesc(cli->cli, fnum, secdesc); + result = cli_send_tconX( + cli->cli, service, strequal(service, "IPC$") ? "IPC" : "?????", + password, strlen(password) + 1); - return PyInt_FromLong(result); + return Py_BuildValue("i", result); } static PyMethodDef smb_hnd_methods[] = { - /* Session and connection handling */ - { "session_request", (PyCFunction)py_smb_session_request, METH_VARARGS | METH_KEYWORDS, "Request a session" }, @@ -251,19 +155,6 @@ 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 } }; diff --git a/source3/python/py_spoolss_drivers.c b/source3/python/py_spoolss_drivers.c index 6daa32d0f4..f1cf6aca99 100644 --- a/source3/python/py_spoolss_drivers.c +++ b/source3/python/py_spoolss_drivers.c @@ -57,7 +57,7 @@ PyObject *spoolss_enumprinterdrivers(PyObject *self, PyObject *args, /* Call rpc function */ - if (!(cli = open_pipe_creds(server, creds, PI_SPOOLSS, &errstr))) { + if (!(cli = open_pipe_creds(server, creds, PIPE_SPOOLSS, &errstr))) { PyErr_SetString(spoolss_error, errstr); free(errstr); goto done; @@ -261,7 +261,7 @@ PyObject *spoolss_getprinterdriverdir(PyObject *self, PyObject *args, /* Call rpc function */ - if (!(cli = open_pipe_creds(server, creds, PI_SPOOLSS, &errstr))) { + if (!(cli = open_pipe_creds(server, creds, PIPE_SPOOLSS, &errstr))) { PyErr_SetString(spoolss_error, errstr); free(errstr); goto done; @@ -341,7 +341,7 @@ PyObject *spoolss_addprinterdriver(PyObject *self, PyObject *args, return NULL; } - if (!(cli = open_pipe_creds(server, creds, PI_SPOOLSS, &errstr))) { + if (!(cli = open_pipe_creds(server, creds, PIPE_SPOOLSS, &errstr))) { PyErr_SetString(spoolss_error, errstr); free(errstr); goto done; diff --git a/source3/python/py_spoolss_ports.c b/source3/python/py_spoolss_ports.c index 55716aca6e..fe6d7536d3 100644 --- a/source3/python/py_spoolss_ports.c +++ b/source3/python/py_spoolss_ports.c @@ -53,7 +53,7 @@ PyObject *spoolss_enumports(PyObject *self, PyObject *args, PyObject *kw) return NULL; } - if (!(cli = open_pipe_creds(server, creds, PI_SPOOLSS, &errstr))) { + if (!(cli = open_pipe_creds(server, creds, PIPE_SPOOLSS, &errstr))) { PyErr_SetString(spoolss_error, errstr); free(errstr); goto done; diff --git a/source3/python/py_spoolss_printers.c b/source3/python/py_spoolss_printers.c index a96498dddc..a300eada86 100644 --- a/source3/python/py_spoolss_printers.c +++ b/source3/python/py_spoolss_printers.c @@ -56,7 +56,7 @@ PyObject *spoolss_openprinter(PyObject *self, PyObject *args, PyObject *kw) return NULL; } - if (!(cli = open_pipe_creds(server, creds, PI_SPOOLSS, &errstr))) { + if (!(cli = open_pipe_creds(server, creds, PIPE_SPOOLSS, &errstr))) { PyErr_SetString(spoolss_error, errstr); free(errstr); goto done; @@ -304,7 +304,7 @@ PyObject *spoolss_enumprinters(PyObject *self, PyObject *args, PyObject *kw) return NULL; } - if (!(cli = open_pipe_creds(server, creds, PI_SPOOLSS, &errstr))) { + if (!(cli = open_pipe_creds(server, creds, PIPE_SPOOLSS, &errstr))) { PyErr_SetString(spoolss_error, errstr); free(errstr); goto done; @@ -439,7 +439,7 @@ PyObject *spoolss_addprinterex(PyObject *self, PyObject *args, PyObject *kw) &PyDict_Type, &info, &PyDict_Type, &creds)) return NULL; - if (!(cli = open_pipe_creds(server, creds, PI_SPOOLSS, &errstr))) { + if (!(cli = open_pipe_creds(server, creds, PIPE_SPOOLSS, &errstr))) { PyErr_SetString(spoolss_error, errstr); free(errstr); goto done; diff --git a/source3/python/py_tdbpack.c b/source3/python/py_tdbpack.c index 06aebe61eb..e5044943be 100644 --- a/source3/python/py_tdbpack.c +++ b/source3/python/py_tdbpack.c @@ -329,35 +329,18 @@ pytdbpack_calc_reqd_len(char *format_str, } -static PyObject *pytdbpack_bad_type(char ch, - const char *expected, - PyObject *val_obj) -{ - PyObject *r = PyObject_Repr(val_obj); - if (!r) - return NULL; - PyErr_Format(PyExc_TypeError, - "tdbpack: format '%c' requires %s, not %s", - ch, expected, PyString_AS_STRING(r)); - Py_DECREF(r); - return val_obj; -} - - /* - * Calculate the number of bytes required to pack a single value. While doing - * this, also conduct some initial checks that the argument types are - * reasonable. - * - * Returns -1 on exception. - */ + Calculate the number of bytes required to pack a single value. +*/ static int pytdbpack_calc_item_len(char ch, PyObject *val_obj) { if (ch == 'd' || ch == 'w') { if (!PyInt_Check(val_obj)) { - pytdbpack_bad_type(ch, "Int", val_obj); + PyErr_Format(PyExc_TypeError, + "tdbpack: format '%c' requires an Int", + ch); return -1; } if (ch == 'w') @@ -370,7 +353,10 @@ pytdbpack_calc_item_len(char ch, else if (ch == 'f' || ch == 'P' || ch == 'B') { /* nul-terminated 8-bit string */ if (!PyString_Check(val_obj)) { - pytdbpack_bad_type(ch, "String", val_obj); + PyErr_Format(PyExc_TypeError, + "tdbpack: format '%c' requires a String", + ch); + return -1; } if (ch == 'B') { @@ -385,7 +371,7 @@ pytdbpack_calc_item_len(char ch, } else { PyErr_Format(PyExc_ValueError, - "tdbpack: format character '%c' is not supported", + __FUNCTION__ ": format character '%c' is not supported", ch); return -1; diff --git a/source3/python/setup.py b/source3/python/setup.py index bf62f3b877..6d03ca633a 100755 --- a/source3/python/setup.py +++ b/source3/python/setup.py @@ -157,8 +157,7 @@ setup( Extension(name = "smb", sources = [samba_srcdir + "python/py_smb.c", - samba_srcdir + "python/py_common.c", - samba_srcdir + "python/py_ntsec.c"], + samba_srcdir + "python/py_common.c"], libraries = lib_list, library_dirs = ["/usr/kerberos/lib"], extra_compile_args = flags_list, |