From dae2b02f781267d2a00bc627a053abef39299831 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Thu, 17 Oct 2002 04:40:53 +0000 Subject: Fix for new arguments of cli_nt_session_open() (This used to be commit cfb0c12eb6412c2cc84785c17ab2f6c89916aa56) --- source3/python/py_common.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'source3/python') diff --git a/source3/python/py_common.c b/source3/python/py_common.c index e21858e072..8742cfa363 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, - char *pipe_name, char **errstr) + int pipe_idx, char **errstr) { char *username, *password, *domain; struct cli_state *cli; @@ -240,10 +240,9 @@ struct cli_state *open_pipe_creds(char *server, PyObject *creds, return NULL; } - if (!cli_nt_session_open(cli, pipe_name)) { + if (!cli_nt_session_open(cli, pipe_idx)) { cli_shutdown(cli); - free(cli); - asprintf(errstr, "error opening %s", pipe_name); + asprintf(errstr, "error opening pipe index %d", pipe_idx); return NULL; } -- cgit From 14df81590cd7f2b26053803de924c8604aad3c3b Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Thu, 17 Oct 2002 04:45:25 +0000 Subject: open_pipe_creds() now takes a pipe index instead of a pipe name. (This used to be commit 3a0a30beda4b8be0038c98ccc6f8f01c6dae386a) --- source3/python/py_lsa.c | 2 +- source3/python/py_samr.c | 3 +-- source3/python/py_spoolss_drivers.c | 6 +++--- source3/python/py_spoolss_ports.c | 2 +- source3/python/py_spoolss_printers.c | 6 +++--- 5 files changed, 9 insertions(+), 10 deletions(-) (limited to 'source3/python') diff --git a/source3/python/py_lsa.c b/source3/python/py_lsa.c index 0584cf716b..d54a2289ef 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, PIPE_LSARPC, &errstr))) { + if (!(cli = open_pipe_creds(server, creds, PI_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 917a90a2fb..92a2eaf063 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, PIPE_SAMR, &errstr))) { + if (!(cli = open_pipe_creds(server, creds, PI_SAMR, &errstr))) { PyErr_SetString(samr_error, errstr); free(errstr); return NULL; @@ -409,7 +409,6 @@ 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_spoolss_drivers.c b/source3/python/py_spoolss_drivers.c index 0c242d9181..644280fea2 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, PIPE_SPOOLSS, &errstr))) { + if (!(cli = open_pipe_creds(server, creds, PI_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, PIPE_SPOOLSS, &errstr))) { + if (!(cli = open_pipe_creds(server, creds, PI_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, PIPE_SPOOLSS, &errstr))) { + if (!(cli = open_pipe_creds(server, creds, PI_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 b5f2102e5e..75c8c4aa28 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, PIPE_SPOOLSS, &errstr))) { + if (!(cli = open_pipe_creds(server, creds, PI_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 a300eada86..a96498dddc 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, PIPE_SPOOLSS, &errstr))) { + if (!(cli = open_pipe_creds(server, creds, PI_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, PIPE_SPOOLSS, &errstr))) { + if (!(cli = open_pipe_creds(server, creds, PI_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, PIPE_SPOOLSS, &errstr))) { + if (!(cli = open_pipe_creds(server, creds, PI_SPOOLSS, &errstr))) { PyErr_SetString(spoolss_error, errstr); free(errstr); goto done; -- cgit From 4af2e30ecf31da6dd9ac2763c0743f2f5548d443 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Thu, 17 Oct 2002 04:48:08 +0000 Subject: make proto (This used to be commit 86c884c3a129d12dc77332c38484bef78c66440e) --- source3/python/py_common_proto.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/python') diff --git a/source3/python/py_common_proto.h b/source3/python/py_common_proto.h index 89f0f35fc9..b012c17e15 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, - char *pipe_name, char **errstr); + int pipe_idx, char **errstr); BOOL get_level_value(PyObject *dict, uint32 *level); /* The following definitions come from python/py_ntsec.c */ -- cgit From fb3d215b396d9c3a1aecf9335a5520bdd604117f Mon Sep 17 00:00:00 2001 From: Jim McDonough Date: Fri, 18 Oct 2002 17:29:20 +0000 Subject: Add extra parm to cli_full_connection call. Tim, you should probably look at this. (This used to be commit a9f632ed5d3d033849c25efac419b21e830c5069) --- source3/python/py_common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/python') diff --git a/source3/python/py_common.c b/source3/python/py_common.c index 8742cfa363..364271d57c 100644 --- a/source3/python/py_common.c +++ b/source3/python/py_common.c @@ -233,7 +233,7 @@ struct cli_state *open_pipe_creds(char *server, PyObject *creds, result = cli_full_connection( &cli, NULL, server, NULL, 0, "IPC$", "IPC", - username, domain, password, 0); + username, domain, password, 0, NULL); if (!NT_STATUS_IS_OK(result)) { *errstr = strdup("error connecting to IPC$ pipe"); -- cgit From 7c6400a78f8939d673f5df4f0e2c73f859f4ff23 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Sun, 20 Oct 2002 20:43:26 +0000 Subject: Added stubs for query/set security descriptors on files. Not even close to working yet. (This used to be commit b7ef2e8b41bd6a7225b9f21c65c42b8ef0f82a32) --- source3/python/py_samba.c | 52 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) (limited to 'source3/python') diff --git a/source3/python/py_samba.c b/source3/python/py_samba.c index c0ade12f65..32b99ca7e9 100644 --- a/source3/python/py_samba.c +++ b/source3/python/py_samba.c @@ -31,6 +31,58 @@ static PyObject *lsa_open_policy(PyObject *self, PyObject *args, return NULL; } +static PyObject *samba_query_secdesc(PyObject *self, PyObject *args, + PyObject *kw) +{ + static char *kwlist[] = { NULL }; + PyObject *py_secdesc; + SEC_DESC *secdesc = NULL; + + /* Parse parameters */ + + if (!PyArg_ParseTupleAndKeywords( + args, kw, "", kwlist)) + return NULL; + + /* FIXME: Fetch security descriptor with cli_query_secdesc*/ + + if (!py_from_SECDESC(&py_secdesc, secdesc)) { + PyErr_SetString( + PyExc_TypeError, + "Invalid security descriptor returned"); + return NULL; + } + + return py_secdesc; + +} + +static PyObject *samba_set_secdesc(PyObject *self, PyObject *args, + PyObject *kw) +{ + static char *kwlist[] = { "security_descriptor", NULL }; + PyObject *py_secdesc; + SEC_DESC *secdesc; + TALLOC_CTX *mem_ctx = talloc_init(); + + /* Parse parameters */ + + if (!PyArg_ParseTupleAndKeywords( + args, kw, "O", kwlist, &py_secdesc)) + return NULL; + + if (!py_to_SECDESC(&secdesc, py_secdesc, mem_ctx)) { + PyErr_SetString(PyExc_TypeError, + "Invalid security descriptor"); + return NULL; + } + + /* FIXME: call cli_set_secdesc() to set security descriptor */ + + Py_INCREF(Py_None); + return Py_None; +} + static PyMethodDef samba_methods[] = { { NULL } }; -- cgit From 7f62309268bf28dfd44eea23ca4d911742f25e5b Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 21 Oct 2002 04:12:47 +0000 Subject: Fixed DRIVER_INFO_3 conversion function to check for dependent_files key. (This used to be commit 35413be0ac39ce52f009f7750f23b41728d8a35c) --- source3/python/py_spoolss_drivers_conv.c | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) (limited to 'source3/python') diff --git a/source3/python/py_spoolss_drivers_conv.c b/source3/python/py_spoolss_drivers_conv.c index 41ff38327e..fd47c0e84d 100644 --- a/source3/python/py_spoolss_drivers_conv.c +++ b/source3/python/py_spoolss_drivers_conv.c @@ -102,10 +102,16 @@ static PyObject *from_dependentfiles(uint16 *dependentfiles) return list; } +static uint16 *to_dependentfiles(PyObject *dict) +{ + return (uint16 *)"abcd\0"; +} + BOOL py_from_DRIVER_INFO_1(PyObject **dict, DRIVER_INFO_1 *info) { *dict = from_struct(info, py_DRIVER_INFO_1); PyDict_SetItemString(*dict, "level", PyInt_FromLong(1)); + return True; } @@ -118,6 +124,7 @@ BOOL py_from_DRIVER_INFO_2(PyObject **dict, DRIVER_INFO_2 *info) { *dict = from_struct(info, py_DRIVER_INFO_2); PyDict_SetItemString(*dict, "level", PyInt_FromLong(2)); + return True; } @@ -129,7 +136,9 @@ BOOL py_to_DRIVER_INFO_2(DRIVER_INFO_2 *info, PyObject *dict) BOOL py_from_DRIVER_INFO_3(PyObject **dict, DRIVER_INFO_3 *info) { *dict = from_struct(info, py_DRIVER_INFO_3); + PyDict_SetItemString(*dict, "level", PyInt_FromLong(3)); + PyDict_SetItemString( *dict, "dependent_files", from_dependentfiles(info->dependentfiles)); @@ -139,12 +148,29 @@ BOOL py_from_DRIVER_INFO_3(PyObject **dict, DRIVER_INFO_3 *info) BOOL py_to_DRIVER_INFO_3(DRIVER_INFO_3 *info, PyObject *dict) { - PyObject *dict_copy = PyDict_Copy(dict); - BOOL result; + PyObject *obj, *dict_copy = PyDict_Copy(dict); + BOOL result = False; + + if (!(obj = PyDict_GetItemString(dict_copy, "dependent_files")) || + !PyList_Check(obj)) + goto done; + + info->dependentfiles = to_dependentfiles(obj); + + PyDict_DelItemString(dict_copy, "dependent_files"); + + if (!(obj = PyDict_GetItemString(dict_copy, "level")) || + !PyInt_Check(obj)) + goto done; PyDict_DelItemString(dict_copy, "level"); - result = to_struct(info, dict_copy, py_DRIVER_INFO_3); + if (!to_struct(info, dict_copy, py_DRIVER_INFO_3)) + goto done; + + result = True; + +done: Py_DECREF(dict_copy); return result; } -- cgit From 69e2a9d7fa689012848b50b40b7b49eeec536d0a Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 21 Oct 2002 04:16:12 +0000 Subject: Stricter validation in python->C conversion functions. (This used to be commit 672c07e2432299e3b1015af524dc5c124f61f904) --- source3/python/py_spoolss_forms_conv.c | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) (limited to 'source3/python') diff --git a/source3/python/py_spoolss_forms_conv.c b/source3/python/py_spoolss_forms_conv.c index 6ef953cbc9..cfeb475b1e 100644 --- a/source3/python/py_spoolss_forms_conv.c +++ b/source3/python/py_spoolss_forms_conv.c @@ -57,23 +57,30 @@ BOOL py_to_FORM(FORM *form, PyObject *dict) { PyObject *obj, *dict_copy = PyDict_Copy(dict); char *name; + BOOL result = False; - obj = PyDict_GetItemString(dict, "name"); + if (!(obj = PyDict_GetItemString(dict_copy, "name")) || + !PyString_Check(obj)) + goto done; - if (!obj || !PyString_Check(obj)) - return False; + PyDict_DelItemString(dict_copy, "name"); + + if (!(obj = PyDict_GetItemString(dict_copy, "level")) || + !PyInt_Check(obj)) + goto done; PyDict_DelItemString(dict_copy, "level"); - PyDict_DelItemString(dict_copy, "name"); - if (!to_struct(form, dict_copy, py_FORM)) { - Py_DECREF(dict_copy); - return False; - } + if (!to_struct(form, dict_copy, py_FORM)) + goto done; name = PyString_AsString(obj); init_unistr2(&form->name, name, strlen(name) + 1); - return True; + result = True; + +done: + Py_DECREF(dict_copy); + return result; } -- cgit From 354878f76fb6689e26a62ef988564c099991edc0 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 21 Oct 2002 04:17:43 +0000 Subject: level should be a uint32 in enum_ports function. (This used to be commit 121db5b6821df9c6ec05adb2d35c2dde930736f2) --- source3/python/py_spoolss_ports.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/python') diff --git a/source3/python/py_spoolss_ports.c b/source3/python/py_spoolss_ports.c index 75c8c4aa28..55716aca6e 100644 --- a/source3/python/py_spoolss_ports.c +++ b/source3/python/py_spoolss_ports.c @@ -26,7 +26,7 @@ PyObject *spoolss_enumports(PyObject *self, PyObject *args, PyObject *kw) { WERROR werror; PyObject *result = NULL, *creds = NULL; - int level = 1; + uint32 level = 1; uint32 i, needed, num_ports; static char *kwlist[] = {"server", "level", "creds", NULL}; TALLOC_CTX *mem_ctx = NULL; -- cgit From d897c63fb596ba9a5a1c6a25f80bdc37b654c611 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 21 Oct 2002 04:44:44 +0000 Subject: Zero some more return values. (This used to be commit 7f45bad319ace07a5bfc21465a0db919131dd608) --- source3/python/py_spoolss_drivers.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source3/python') diff --git a/source3/python/py_spoolss_drivers.c b/source3/python/py_spoolss_drivers.c index 644280fea2..6daa32d0f4 100644 --- a/source3/python/py_spoolss_drivers.c +++ b/source3/python/py_spoolss_drivers.c @@ -358,7 +358,8 @@ PyObject *spoolss_addprinterdriver(PyObject *self, PyObject *args, } ZERO_STRUCT(ctr); - + ZERO_STRUCT(dinfo); + switch(level) { case 3: ctr.info3 = &dinfo.driver_3; -- cgit From 771fc528ebf3ea6d8580b76449df974c4492aae5 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 21 Oct 2002 04:47:29 +0000 Subject: More cleanups of validation functions. (This used to be commit a4790ba42cc6ee4086dafbc64b1dba790a6c3583) --- source3/python/py_spoolss_forms_conv.c | 5 ++ source3/python/py_spoolss_printers_conv.c | 80 +++++++++++++++++++++++-------- 2 files changed, 66 insertions(+), 19 deletions(-) (limited to 'source3/python') diff --git a/source3/python/py_spoolss_forms_conv.c b/source3/python/py_spoolss_forms_conv.c index cfeb475b1e..095a318fd2 100644 --- a/source3/python/py_spoolss_forms_conv.c +++ b/source3/python/py_spoolss_forms_conv.c @@ -74,6 +74,11 @@ BOOL py_to_FORM(FORM *form, PyObject *dict) if (!to_struct(form, dict_copy, py_FORM)) goto done; + /* Careful! We can't call PyString_AsString(obj) then delete + obj and still expect to have our pointer pointing somewhere + useful. */ + + obj = PyDict_GetItemString(dict, "name"); name = PyString_AsString(obj); init_unistr2(&form->name, name, strlen(name) + 1); diff --git a/source3/python/py_spoolss_printers_conv.c b/source3/python/py_spoolss_printers_conv.c index 9bef118f2b..3e3ef95b12 100644 --- a/source3/python/py_spoolss_printers_conv.c +++ b/source3/python/py_spoolss_printers_conv.c @@ -161,18 +161,28 @@ BOOL py_from_DEVICEMODE(PyObject **dict, DEVICEMODE *devmode) BOOL py_to_DEVICEMODE(DEVICEMODE *devmode, PyObject *dict) { - PyObject *obj; + PyObject *obj, *dict_copy = PyDict_Copy(dict); + BOOL result = False; - if (!to_struct(devmode, dict, py_DEVICEMODE)) - return False; + if (!(obj = PyDict_GetItemString(dict_copy, "private"))) + goto done; - if (!(obj = PyDict_GetItemString(dict, "private"))) - return False; + if (!PyString_Check(obj)) + goto done; devmode->private = PyString_AsString(obj); devmode->driverextra = PyString_Size(obj); - return True; + PyDict_DelItemString(dict_copy, "private"); + + if (!to_struct(devmode, dict_copy, py_DEVICEMODE)) + goto done; + + result = True; + +done: + Py_DECREF(dict_copy); + return result; } /* @@ -204,12 +214,23 @@ BOOL py_from_PRINTER_INFO_1(PyObject **dict, PRINTER_INFO_1 *info) BOOL py_to_PRINTER_INFO_1(PRINTER_INFO_1 *info, PyObject *dict) { - PyObject *dict_copy = PyDict_Copy(dict); - BOOL result; + PyObject *obj, *dict_copy = PyDict_Copy(dict); + BOOL result = False; + + if (!(obj = PyDict_GetItemString(dict_copy, "level"))) + goto done; + + if (!PyInt_Check(obj)) + goto done; PyDict_DelItemString(dict_copy, "level"); - result = to_struct(info, dict_copy, py_PRINTER_INFO_1); + if (!to_struct(info, dict_copy, py_PRINTER_INFO_1)) + goto done; + + result = True; + +done: Py_DECREF(dict_copy); return result; } @@ -248,26 +269,47 @@ BOOL py_from_PRINTER_INFO_2(PyObject **dict, PRINTER_INFO_2 *info) BOOL py_to_PRINTER_INFO_2(PRINTER_INFO_2 *info, PyObject *dict, TALLOC_CTX *mem_ctx) { - PyObject *obj; + PyObject *obj, *dict_copy = PyDict_Copy(dict); + BOOL result = False; - if (!to_struct(info, dict, py_PRINTER_INFO_2)) - return False; + /* Convert security descriptor */ - if (!(obj = PyDict_GetItemString(dict, "security_descriptor"))) - return False; + if (!(obj = PyDict_GetItemString(dict_copy, "security_descriptor"))) + goto done; + + if (!PyDict_Check(obj)) + goto done; if (!py_to_SECDESC(&info->secdesc, obj, mem_ctx)) - return False; + goto done; - if (!(obj = PyDict_GetItemString(dict, "device_mode"))) - return False; + PyDict_DelItemString(dict_copy, "security_descriptor"); + + /* Convert device mode */ + + if (!(obj = PyDict_GetItemString(dict_copy, "device_mode"))) + goto done; + + if (!PyDict_Check(obj)) + goto done; info->devmode = talloc(mem_ctx, sizeof(DEVICEMODE)); if (!py_to_DEVICEMODE(info->devmode, obj)) - return False; + goto done; - return True; + PyDict_DelItemString(dict_copy, "device_mode"); + + /* Convert remaining elements of dictionary */ + + if (!to_struct(info, dict_copy, py_PRINTER_INFO_2)) + goto done; + + result = True; + +done: + Py_DECREF(dict_copy); + return result; } /* -- cgit From 3b8d11fe503a1e53d7f6a7f1714014253f2b90e3 Mon Sep 17 00:00:00 2001 From: Martin Pool Date: Mon, 21 Oct 2002 07:41:08 +0000 Subject: Give better error messages for TypeError, which will arise if e.g. you try to pack an Int using a string tdbpack format. (This used to be commit 6139ab3cbca3fc2969d1e578b38394b1f6aeb9c3) --- source3/python/py_tdbpack.c | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) (limited to 'source3/python') diff --git a/source3/python/py_tdbpack.c b/source3/python/py_tdbpack.c index e5044943be..06aebe61eb 100644 --- a/source3/python/py_tdbpack.c +++ b/source3/python/py_tdbpack.c @@ -329,18 +329,35 @@ 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. -*/ + * 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. + */ static int pytdbpack_calc_item_len(char ch, PyObject *val_obj) { if (ch == 'd' || ch == 'w') { if (!PyInt_Check(val_obj)) { - PyErr_Format(PyExc_TypeError, - "tdbpack: format '%c' requires an Int", - ch); + pytdbpack_bad_type(ch, "Int", val_obj); return -1; } if (ch == 'w') @@ -353,10 +370,7 @@ pytdbpack_calc_item_len(char ch, else if (ch == 'f' || ch == 'P' || ch == 'B') { /* nul-terminated 8-bit string */ if (!PyString_Check(val_obj)) { - PyErr_Format(PyExc_TypeError, - "tdbpack: format '%c' requires a String", - ch); - return -1; + pytdbpack_bad_type(ch, "String", val_obj); } if (ch == 'B') { @@ -371,7 +385,7 @@ pytdbpack_calc_item_len(char ch, } else { PyErr_Format(PyExc_ValueError, - __FUNCTION__ ": format character '%c' is not supported", + "tdbpack: format character '%c' is not supported", ch); return -1; -- cgit From 4eb2eab364b327d1498d9eb36c743434b689c1e1 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 21 Oct 2002 08:23:20 +0000 Subject: Whoops - this should be in py_smb.c (This used to be commit b740c7e5050b18bc06865451bed3daf3ae09c609) --- source3/python/py_samba.c | 52 ----------------------------------------------- 1 file changed, 52 deletions(-) (limited to 'source3/python') diff --git a/source3/python/py_samba.c b/source3/python/py_samba.c index 32b99ca7e9..c0ade12f65 100644 --- a/source3/python/py_samba.c +++ b/source3/python/py_samba.c @@ -31,58 +31,6 @@ static PyObject *lsa_open_policy(PyObject *self, PyObject *args, return NULL; } -static PyObject *samba_query_secdesc(PyObject *self, PyObject *args, - PyObject *kw) -{ - static char *kwlist[] = { NULL }; - PyObject *py_secdesc; - SEC_DESC *secdesc = NULL; - - /* Parse parameters */ - - if (!PyArg_ParseTupleAndKeywords( - args, kw, "", kwlist)) - return NULL; - - /* FIXME: Fetch security descriptor with cli_query_secdesc*/ - - if (!py_from_SECDESC(&py_secdesc, secdesc)) { - PyErr_SetString( - PyExc_TypeError, - "Invalid security descriptor returned"); - return NULL; - } - - return py_secdesc; - -} - -static PyObject *samba_set_secdesc(PyObject *self, PyObject *args, - PyObject *kw) -{ - static char *kwlist[] = { "security_descriptor", NULL }; - PyObject *py_secdesc; - SEC_DESC *secdesc; - TALLOC_CTX *mem_ctx = talloc_init(); - - /* Parse parameters */ - - if (!PyArg_ParseTupleAndKeywords( - args, kw, "O", kwlist, &py_secdesc)) - return NULL; - - if (!py_to_SECDESC(&secdesc, py_secdesc, mem_ctx)) { - PyErr_SetString(PyExc_TypeError, - "Invalid security descriptor"); - return NULL; - } - - /* FIXME: call cli_set_secdesc() to set security descriptor */ - - Py_INCREF(Py_None); - return Py_None; -} - static PyMethodDef samba_methods[] = { { NULL } }; -- cgit From 91895706b747345698febcb17bd4b9c445b6f15f Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 21 Oct 2002 09:53:31 +0000 Subject: Fixed up tconx function. Implemented nt_create_andx, query_secdesc and set_secdesc functions. (This used to be commit 3fd568ef5c984f089e7799d9ff55395330716641) --- source3/python/py_smb.c | 133 +++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 121 insertions(+), 12 deletions(-) (limited to 'source3/python') diff --git a/source3/python/py_smb.c b/source3/python/py_smb.c index 77d7bb32fc..c9ac24659d 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 } }; -- cgit From e0d317dd16f130a4290107f9ab1dce20d417d6ad Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 21 Oct 2002 09:54:41 +0000 Subject: The libsmb module uses py_ntsec.o (This used to be commit e27d3d20e3c51fc04f37d92c24f38f91b2d1e1e4) --- source3/python/setup.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source3/python') diff --git a/source3/python/setup.py b/source3/python/setup.py index 6d03ca633a..bf62f3b877 100755 --- a/source3/python/setup.py +++ b/source3/python/setup.py @@ -157,7 +157,8 @@ setup( Extension(name = "smb", sources = [samba_srcdir + "python/py_smb.c", - samba_srcdir + "python/py_common.c"], + samba_srcdir + "python/py_common.c", + samba_srcdir + "python/py_ntsec.c"], libraries = lib_list, library_dirs = ["/usr/kerberos/lib"], extra_compile_args = flags_list, -- cgit From d70d4ef34b21d86ede25f00ed1b9726c9e9444be Mon Sep 17 00:00:00 2001 From: Martin Pool Date: Mon, 21 Oct 2002 11:13:53 +0000 Subject: Import old pure Python version of tdbpack/unpack, so that we can do compatibility testing against the shiny new C version. This version is slightly modified to not call codepage conversion routines, and renamed tdbutil->oldtdbutil. (This used to be commit 2dc4373727f73a46cd6135413e50917fb7fa538b) --- source3/python/examples/tdbpack/oldtdbutil.py | 144 ++++++++++++++++++++++++++ 1 file changed, 144 insertions(+) create mode 100644 source3/python/examples/tdbpack/oldtdbutil.py (limited to 'source3/python') diff --git a/source3/python/examples/tdbpack/oldtdbutil.py b/source3/python/examples/tdbpack/oldtdbutil.py new file mode 100644 index 0000000000..ac435b8bac --- /dev/null +++ b/source3/python/examples/tdbpack/oldtdbutil.py @@ -0,0 +1,144 @@ +#!/usr/bin/python +############################################################# +# tdbutil +# +# Purpose: +# Contains functions that are used to pack and unpack data +# from Samba's tdb databases. Samba sometimes represents complex +# data structures as a single value in a database. These functions +# allow other python scripts to package data types into a single python +# string and unpackage them. +# +# +# XXXXX: This code is no longer used; it's just here for testing +# compatibility with the new (much faster) C implementation. +# +############################################################## +import string + +def pack(format,list): + retstring = '' + listind = 0 + + # Cycle through format entries + for type in format: + # Null Terminated String + if (type == 'f' or type == 'P'): + retstring = retstring + list[listind] + "\000" + # 4 Byte Number + if (type == 'd'): + retstring = retstring + PackNum(list[listind],4) + # 2 Byte Number + if (type == 'w'): + retstring = retstring + PackNum(list[listind],2) + # Pointer Value + if (type == 'p'): + if (list[listind]): + retstring = retstring + PackNum(1,4) + else: + retstring = retstring + PackNum(0,4) + # Buffer and Length + if (type == 'B'): + # length + length = list[listind] + retstring = retstring + PackNum(length,4) + length = int(length) + listind = listind + 1 + # buffer + retstring = retstring + list[listind][:length] + + listind = listind + 1 + + return retstring + +def unpack(format,buffer): + retlist = [] + bufind = 0 + + lasttype = "" + for type in format: + # Pointer Value + if (type == 'p'): + newvalue = UnpackNum(buffer[bufind:bufind+4]) + bufind = bufind + 4 + if (newvalue): + newvalue = 1L + else: + newvalue = 0L + retlist.append(newvalue) + # Previous character till end of data + elif (type == '$'): + if (lasttype == 'f'): + while (bufind < len(buffer)): + newstring = '' + while (buffer[bufind] != '\000'): + newstring = newstring + buffer[bufind] + bufind = bufind + 1 + bufind = bufind + 1 + retlist.append(newstring) + # Null Terminated String + elif (type == 'f' or type == 'P'): + newstring = '' + while (buffer[bufind] != '\000'): + newstring = newstring + buffer[bufind] + bufind = bufind + 1 + bufind = bufind + 1 + retlist.append(newstring) + # 4 Byte Number + elif (type == 'd'): + newvalue = UnpackNum(buffer[bufind:bufind+4]) + bufind = bufind + 4 + retlist.append(newvalue) + # 2 Byte Number + elif (type == 'w'): + newvalue = UnpackNum(buffer[bufind:bufind+2]) + bufind = bufind + 2 + retlist.append(newvalue) + # Length and Buffer + elif (type == 'B'): + # Length + length = UnpackNum(buffer[bufind:bufind+4]) + bufind = bufind + 4 + retlist.append(length) + length = int(length) + # Buffer + retlist.append(buffer[bufind:bufind+length]) + bufind = bufind + length + + lasttype = type + + return ((retlist,buffer[bufind:])) + +def PackNum(myint,size): + retstring = '' + size = size * 2 + hint = hex(myint)[2:] + + # Check for long notation + if (hint[-1:] == 'L'): + hint = hint[:-1] + + addon = size - len(hint) + for i in range(0,addon): + hint = '0' + hint + + while (size > 0): + val = string.atoi(hint[size-2:size],16) + retstring = retstring + chr(val) + size = size - 2 + + return retstring + +def UnpackNum(buffer): + size = len(buffer) + mystring = '' + + for i in range(size-1,-1,-1): + val = hex(ord(buffer[i]))[2:] + if (len(val) == 1): + val = '0' + val + mystring = mystring + val + if (len(mystring) > 4): + return string.atol(mystring,16) + else: + return string.atoi(mystring,16) -- cgit From 23e608435895a39a4da52c3f649b130140f09662 Mon Sep 17 00:00:00 2001 From: Martin Pool Date: Mon, 21 Oct 2002 11:44:26 +0000 Subject: Test both new samba.tdbpack and oldtdbutil pack/unpack routines. This makes the test suite fail because at the moment they are in fact not behaving the same way. (This used to be commit 44dd7746ede7f7f9efcf7dabcd351b1d800e535c) --- source3/python/examples/tdbpack/test_tdbpack.py | 66 ++++++++++++++----------- 1 file changed, 37 insertions(+), 29 deletions(-) (limited to 'source3/python') diff --git a/source3/python/examples/tdbpack/test_tdbpack.py b/source3/python/examples/tdbpack/test_tdbpack.py index 36fed881e3..659dc0efed 100755 --- a/source3/python/examples/tdbpack/test_tdbpack.py +++ b/source3/python/examples/tdbpack/test_tdbpack.py @@ -17,13 +17,12 @@ string, with one character per field.""" __author__ = 'Martin Pool ' import unittest -# import tdbutil +import oldtdbutil import samba.tdbpack -packer = samba.tdbpack.pack -unpacker = samba.tdbpack.unpack - - +both_unpackers = (samba.tdbpack.unpack, oldtdbutil.unpack) +both_packers = (samba.tdbpack.pack, oldtdbutil.pack) + class PackTests(unittest.TestCase): symm_cases = [('B', ['hello' * 51], '\xff\0\0\0' + 'hello' * 51), ('w', [42], '\x2a\0'), @@ -78,11 +77,13 @@ class PackTests(unittest.TestCase): def test_symmetric(self): """Cookbook of symmetric pack/unpack tests """ - 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 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)) def test_pack(self): @@ -100,25 +101,30 @@ class PackTests(unittest.TestCase): # as if you called list() ] - for format, values, expected in cases: - self.assertEquals(packer(format, values), expected) + for packer in both_packers: + for format, values, expected in cases: + self.assertEquals(packer(format, values), expected) def test_unpack_extra(self): # Test leftover data - 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 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)) def test_unpack(self): """Cookbook of tricky unpack tests""" cases = [ + # Apparently I couldn't think of any tests that weren't + # symmetric :-/ ] - for format, values, expected in cases: - out, rest = unpacker(format, expected) - self.assertEquals(rest, '') - self.assertEquals(list(values), list(out)) + 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)) def test_pack_failures(self): @@ -141,7 +147,7 @@ class PackTests(unittest.TestCase): ('f', [2], TypeError), ('P', [None], TypeError), ('P', (), IndexError), - ('f', [packer], TypeError), + ('f', [hex], TypeError), ('fw', ['hello'], IndexError), ('f', [u'hello'], TypeError), ('B', [2], TypeError), @@ -153,10 +159,11 @@ class PackTests(unittest.TestCase): ('fQ', ['2'], IndexError), (2, [2], TypeError), ({}, {}, TypeError)] - for format, values, throwable_class in cases: - def do_pack(): - packer(format, values) - self.assertRaises(throwable_class, do_pack) + for packer in both_packers: + for format, values, throwable_class in cases: + def do_pack(): + packer(format, values) + self.assertRaises(throwable_class, do_pack) def test_unpack_failures(self): @@ -182,10 +189,11 @@ class PackTests(unittest.TestCase): ('B', 'foobar', IndexError), ('BB', '\x01\0\0\0a\x01', IndexError), ] - - for format, values, throwable_class in cases: - def do_unpack(): - unpacker(format, values) + + for unpacker in both_unpackers: + for format, values, throwable_class in cases: + def do_unpack(): + unpacker(format, values) self.assertRaises(throwable_class, do_unpack) -- cgit