From 16b454f6c768cea3132d54bb75348ea8c60b5d35 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Wed, 21 Aug 2002 23:28:41 +0000 Subject: Added README written by Jelmer - thanks! (This used to be commit f639eb3817b9edf421dc103394428d607857a0bb) --- source3/python/README | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 source3/python/README (limited to 'source3/python') diff --git a/source3/python/README b/source3/python/README new file mode 100644 index 0000000000..f751046376 --- /dev/null +++ b/source3/python/README @@ -0,0 +1,48 @@ +Quick Install Guide +-- +Lines prepended with a $ indicate shell commands. + +1. Requirements + +In order to be able to compile samba-python you need to have +python and the python-dev packages installed. + +2. Checking out the CVS HEAD branch of Samba and Samba-Python + +In your shell, type: + +$ cvs -d :pserver:cvs@pserver.samba.org:/cvsroot login + +When asked for a password, type 'cvs'. + +Now, type: + +$ cvs -d :pserver:cvs@pserver.samba.org:/cvsroot co samba + +This might probably take a while. When everything is downloaded, +check out the samba-python tree: + +$ cvs -d :pserver:cvs@pserver.samba.org:/cvsroot co samba-python + +Now that you have both cvs modules, move the directory 'samba-python' to +inside the samba source tree, using: + +$ mv samba-python samba/source/python + +Now, go to the samba/source directory and apply the samba-head.patch patch: + +$ cd samba/source && patch -p0 < location/to/samba-python/samba-head.patch + +You can now configure samba as usual and create the python extension: + +$ autoconf +$ ./configure +$ make python_ext + +Now, you can install the modules: + +$ cp build/lib.*/*.so /usr/lib/python2.1/lib-dynload/ + +(the directory /usr/lib/python2.1 may vary, depending on your installation) + +Samba-python should work now! -- cgit From b1037bffcf07ee6d4b978faf6906e276d09c06d2 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Tue, 27 Aug 2002 00:41:06 +0000 Subject: New arguments to cli_spoolss_enum_printers() (This used to be commit 55f891016c005c1552f1c1d95dd067bbf9de8869) --- source3/python/py_spoolss_printers.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/python') diff --git a/source3/python/py_spoolss_printers.c b/source3/python/py_spoolss_printers.c index 8d4cd24778..2a6d056bbf 100644 --- a/source3/python/py_spoolss_printers.c +++ b/source3/python/py_spoolss_printers.c @@ -337,13 +337,13 @@ PyObject *spoolss_enumprinters(PyObject *self, PyObject *args, PyObject *kw) /* Call rpc function */ werror = cli_spoolss_enum_printers( - cli, mem_ctx, 0, &needed, flags, level, + cli, mem_ctx, 0, &needed, name, flags, level, &num_printers, &ctr); if (W_ERROR_V(werror) == ERRinsufficientbuffer) werror = cli_spoolss_enum_printers( - cli, mem_ctx, needed, NULL, flags, level, - &num_printers, &ctr); + cli, mem_ctx, needed, NULL, name, flags, + level, &num_printers, &ctr); if (!W_ERROR_IS_OK(werror)) { PyErr_SetObject(spoolss_werror, py_werror_tuple(werror)); -- cgit From 7488f61d3c7e60cb7607f1b70cacd0635fe95b74 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Tue, 27 Aug 2002 01:49:51 +0000 Subject: Implemented enum_domain_groups function. (This used to be commit 9e36824d47f7d1aac14bb5aeded8da54962c90a8) --- source3/python/py_samr.c | 44 +++++++++++++++++++++++++++++++- source3/python/py_samr_conv.c | 58 +++++++++++++++++++++++++++++++++++++++++++ source3/python/setup.py.in | 1 + 3 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 source3/python/py_samr_conv.c (limited to 'source3/python') diff --git a/source3/python/py_samr.c b/source3/python/py_samr.c index ce6eda99c2..917a90a2fb 100644 --- a/source3/python/py_samr.c +++ b/source3/python/py_samr.c @@ -151,8 +151,50 @@ static void py_samr_domain_hnd_dealloc(PyObject* self) PyObject_Del(self); } +static PyObject *samr_enum_dom_groups(PyObject *self, PyObject *args, + PyObject *kw) +{ + samr_domain_hnd_object *domain_hnd = (samr_domain_hnd_object *)self; + static char *kwlist[] = { NULL }; + TALLOC_CTX *mem_ctx; + uint32 desired_access = MAXIMUM_ALLOWED_ACCESS; + uint32 start_idx, size, num_dom_groups; + struct acct_info *dom_groups; + NTSTATUS result; + PyObject *py_result = NULL; + + if (!PyArg_ParseTupleAndKeywords( + args, kw, "", kwlist)) + return NULL; + + if (!(mem_ctx = talloc_init())) { + PyErr_SetString(samr_error, "unable to init talloc context"); + return NULL; + } + + start_idx = 0; + size = 0xffff; + + do { + result = cli_samr_enum_dom_groups( + domain_hnd->cli, mem_ctx, &domain_hnd->domain_pol, + &start_idx, size, &dom_groups, &num_dom_groups); + + if (NT_STATUS_IS_OK(result) || + NT_STATUS_V(result) == NT_STATUS_V(STATUS_MORE_ENTRIES)) { + py_from_acct_info(&py_result, dom_groups, + num_dom_groups); + } + + } while (NT_STATUS_V(result) == NT_STATUS_V(STATUS_MORE_ENTRIES)); + + return py_result; +} + static PyMethodDef samr_domain_methods[] = { - { NULL } + { "enum_domain_groups", (PyCFunction)samr_enum_dom_groups, + METH_VARARGS | METH_KEYWORDS, "Enumerate domain groups" }, + { NULL } }; static PyObject *py_samr_domain_hnd_getattr(PyObject *self, char *attrname) diff --git a/source3/python/py_samr_conv.c b/source3/python/py_samr_conv.c new file mode 100644 index 0000000000..fdf71641e0 --- /dev/null +++ b/source3/python/py_samr_conv.c @@ -0,0 +1,58 @@ +/* + Python wrappers for DCERPC/SMB client routines. + + Copyright (C) Tim Potter, 2002 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "python/py_samr.h" +#include "python/py_conv.h" + +/* + * Convert between acct_info and Python + */ + +BOOL py_from_acct_info(PyObject **array, struct acct_info *info, int num_accts) +{ + int i; + + *array = PyList_New(num_accts); + + for (i = 0; i < num_accts; i++) { + PyObject *obj; + + obj = PyDict_New(); + + PyDict_SetItemString( + obj, "name", PyString_FromString(info[i].acct_name)); + + PyDict_SetItemString( + obj, "description", + PyString_FromString(info[i].acct_desc)); + + PyDict_SetItemString(obj, "rid", PyInt_FromLong(info[i].rid)); + + PyList_SetItem(*array, i, obj); + } + + return True; +} + +BOOL py_to_acct_info(PRINTER_INFO_3 *info, PyObject *dict, + TALLOC_CTX *mem_ctx) +{ + return False; +} diff --git a/source3/python/setup.py.in b/source3/python/setup.py.in index c61ec2c214..9b6dc1a650 100755 --- a/source3/python/setup.py.in +++ b/source3/python/setup.py.in @@ -118,6 +118,7 @@ setup( Extension(name = "samr", sources = [samba_srcdir + "python/py_samr.c", + samba_srcdir + "python/py_samr_conv.c", samba_srcdir + "python/py_common.c"], libraries = lib_list, library_dirs = ["/usr/kerberos/lib"], -- cgit From 677bae21d1b46a85b5657a514dc938b3590bd2f5 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Fri, 30 Aug 2002 01:35:56 +0000 Subject: Abstract out the functionality of gtdbtool into a dictionary browser class. This should provide a nice framework for browsing any kind of data presented as a python dictionary: - windows registry - printer data - tdb files (This used to be commit 8af86f68354f7c803bb66886560b358d6e48681d) --- source3/python/gtkdictbrowser.py | 188 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 188 insertions(+) create mode 100755 source3/python/gtkdictbrowser.py (limited to 'source3/python') diff --git a/source3/python/gtkdictbrowser.py b/source3/python/gtkdictbrowser.py new file mode 100755 index 0000000000..1609dff9b4 --- /dev/null +++ b/source3/python/gtkdictbrowser.py @@ -0,0 +1,188 @@ +#!/usr/bin/python +# +# Browse a Python dictionary in a two pane graphical interface written +# in GTK. +# +# The GtkDictBrowser class is supposed to be generic enough to allow +# applications to override enough methods and produce a +# domain-specific browser provided the information is presented as a +# Python dictionary. +# +# Possible applications: +# +# - Windows registry browser +# - SPOOLSS printerdata browser +# - tdb file browser +# + +from gtk import * +import string, re + +class GtkDictBrowser: + + def __init__(self, dict): + self.dict = dict + + # This variable stores a list of (regexp, function) used to + # convert the raw value data to a displayable string. + + self.get_value_text_fns = [] + self.get_key_text = lambda x: x + + # We can filter the list of keys displayed using a regex + + self.filter_regex = "" + + # Create and configure user interface widgets. A string argument is + # used to set the window title. + + def build_ui(self, title): + win = GtkWindow() + win.set_title(title) + + win.connect("destroy", mainquit) + + hpaned = GtkHPaned() + win.add(hpaned) + hpaned.set_border_width(5) + hpaned.show() + + vbox = GtkVBox() + hpaned.add1(vbox) + vbox.show() + + scrolled_win = GtkScrolledWindow() + scrolled_win.set_policy(POLICY_AUTOMATIC, POLICY_AUTOMATIC) + vbox.pack_start(scrolled_win) + scrolled_win.show() + + hbox = GtkHBox() + vbox.pack_end(hbox, expand = 0, padding = 5) + hbox.show() + + label = GtkLabel("Filter:") + hbox.pack_start(label, expand = 0, padding = 5) + label.show() + + self.entry = GtkEntry() + hbox.pack_end(self.entry, padding = 5) + self.entry.show() + + self.entry.connect("activate", self.filter_activated) + + self.list = GtkList() + self.list.set_selection_mode(SELECTION_MULTIPLE) + self.list.set_selection_mode(SELECTION_BROWSE) + scrolled_win.add_with_viewport(self.list) + self.list.show() + + self.list.connect("select_child", self.key_selected) + + scrolled_win = GtkScrolledWindow() + scrolled_win.set_policy(POLICY_AUTOMATIC, POLICY_AUTOMATIC) + hpaned.add2(scrolled_win) + scrolled_win.set_usize(500,400) + scrolled_win.show() + + self.text = GtkText() + self.text.set_editable(FALSE) + scrolled_win.add_with_viewport(self.text) + self.text.show() + + self.text.connect("event", self.event_handler) + + self.menu = GtkMenu() + self.menu.show() + + self.font = load_font("fixed") + + self.update_keylist() + + win.show() + + # Add a key to the left hand side of the user interface + + def add_key(self, key): + display_key = self.get_key_text(key) + list_item = GtkListItem(display_key) + list_item.set_data("raw_key", key) # Store raw key in item data + self.list.add(list_item) + list_item.show() + + # Event handler registered by build_ui() + + def event_handler(self, event, menu): + return FALSE + + # Set the text to appear in the right hand side of the user interface + + def set_value_text(self, text): + self.text.delete_text(0, self.text.get_length()) + + # The text widget has trouble inserting text containing NULL + # characters. + + text = string.replace(text, "\x00", ".") + + self.text.insert(self.font, None, None, text) + + # This function is called when a key is selected in the left hand side + # of the user interface. + + def key_selected(self, list, list_item): + key = list_item.children()[0].get() + + # Look for a match in the value display function list + + text = self.dict[list_item.get_data("raw_key")] + + for entry in self.get_value_text_fns: + if re.match(entry[0], key): + text = entry[1](text) + break + + self.set_value_text(text) + + # Refresh the key list by removing all items and re-inserting them. + # Items are only inserted if they pass through the filter regexp. + + def update_keylist(self): + self.list.remove_items(self.list.children()) + self.set_value_text("") + for k in self.dict.keys(): + if re.match(self.filter_regex, k): + self.add_key(k) + + # Invoked when the user hits return in the filter text entry widget. + + def filter_activated(self, entry): + self.filter_regex = entry.get_text() + self.update_keylist() + + # Register a key display function + + def register_get_key_text_fn(self, fn): + self.get_key_text = fn + + # Register a value display function + + def register_get_value_text_fn(self, regexp, fn): + self.get_value_text_fns.append((regexp, fn)) + +# For testing purposes, create a fixed dictionary to browse with + +if __name__ == "__main__": + + dict = {"chicken": "ham", "spam": "fun"} + + db = GtkDictBrowser(dict) + + db.build_ui("GtkDictBrowser") + + # Override Python's handling of ctrl-c so we can break out of the + # gui from the command line. + + import signal + signal.signal(signal.SIGINT, signal.SIG_DFL) + + mainloop() -- cgit From d63a6aba6c4ed198eaafb5c22568565ead007f32 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Fri, 30 Aug 2002 02:43:51 +0000 Subject: Forgot to check in some of the libsmb stuff. (This used to be commit 0a2f6049c0b49810abf1c3e909d712f53c7fc8c1) --- source3/python/py_samba.c | 64 +++++++++++++++++++++++++++++++++++++++++ source3/python/samba-head.patch | 22 +++++++------- source3/python/setup.py.in | 10 +++++++ 3 files changed, 85 insertions(+), 11 deletions(-) create mode 100644 source3/python/py_samba.c (limited to 'source3/python') diff --git a/source3/python/py_samba.c b/source3/python/py_samba.c new file mode 100644 index 0000000000..7c94569787 --- /dev/null +++ b/source3/python/py_samba.c @@ -0,0 +1,64 @@ +/* + Python wrappers for DCERPC/SMB client routines. + + Copyright (C) Tim Potter, 2002 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "Python.h" +#include "python/py_common.h" + +/* + * Module initialisation + */ + +static PyObject *lsa_open_policy(PyObject *self, PyObject *args, + PyObject *kw) +{ + return NULL; +} + +static PyMethodDef samba_methods[] = { + { NULL } +}; + +static PyMethodDef cheepy_methods[] = { + { "open_policy", (PyCFunction)lsa_open_policy, METH_VARARGS|METH_KEYWORDS, + "Foo"}, + { NULL } +}; + +void initsamba(void) +{ + PyObject *module, *new_module, *dict; + + /* Initialise module */ + + module = Py_InitModule("samba", samba_methods); + dict = PyModule_GetDict(module); + + new_module = PyModule_N("cheepy"); + + + + PyDict_SetItemString(dict, "cheepy", new_module); + + + + /* Do samba initialisation */ + + py_samba_init(); +} diff --git a/source3/python/samba-head.patch b/source3/python/samba-head.patch index a739346a5b..ced7da551e 100644 --- a/source3/python/samba-head.patch +++ b/source3/python/samba-head.patch @@ -1,11 +1,11 @@ Index: Makefile.in =================================================================== RCS file: /data/cvs/samba/source/Makefile.in,v -retrieving revision 1.500 -diff -u -r1.500 Makefile.in ---- Makefile.in 2002/07/28 06:04:32 1.500 -+++ Makefile.in 2002/07/29 03:48:03 -@@ -838,6 +838,45 @@ +retrieving revision 1.502 +diff -u -r1.502 Makefile.in +--- Makefile.in 2002/08/02 07:20:56 1.502 ++++ Makefile.in 2002/08/06 00:51:48 +@@ -839,6 +839,45 @@ -$(INSTALLCMD) -d ${prefix}/include -$(INSTALLCMD) include/libsmbclient.h ${prefix}/include @@ -54,16 +54,16 @@ diff -u -r1.500 Makefile.in Index: configure.in =================================================================== RCS file: /data/cvs/samba/source/configure.in,v -retrieving revision 1.324 -diff -u -r1.324 configure.in ---- configure.in 2002/07/27 01:37:32 1.324 -+++ configure.in 2002/07/29 03:48:04 +retrieving revision 1.326 +diff -u -r1.326 configure.in +--- configure.in 2002/07/30 09:59:52 1.326 ++++ configure.in 2002/08/06 00:51:51 @@ -2797,7 +2797,7 @@ builddir=`pwd` AC_SUBST(builddir) --AC_OUTPUT(include/stamp-h Makefile script/findsmb) -+AC_OUTPUT(include/stamp-h Makefile script/findsmb python/setup.py) +-AC_OUTPUT(include/stamp-h Makefile script/findsmb ../examples/VFS/Makefile ../examples/VFS/block/Makefile) ++AC_OUTPUT(include/stamp-h Makefile script/findsmb ../examples/VFS/Makefile ../examples/VFS/block/Makefile python/setup.py) ################################################# # Print very concise instructions on building/use diff --git a/source3/python/setup.py.in b/source3/python/setup.py.in index 9b6dc1a650..5896301245 100755 --- a/source3/python/setup.py.in +++ b/source3/python/setup.py.in @@ -160,5 +160,15 @@ setup( library_dirs = ["/usr/kerberos/lib"], extra_objects = obj_list), + # Moving to merge all individual extensions in to one big + # extension. This is to avoid the fact that each extension is 3MB + # in size due to the lack of proper depedency management in Samba. + + Extension(name = "samba", + sources = [samba_srcdir + "python/py_samba.c", + samba_srcdir + "python/py_common.c"], + libraries = lib_list, + library_dirs = ["/usr/kerberos/lib"], + extra_objects = obj_list), ], ) -- cgit From d75fc27fa1b68762317999d65a232284abf72ef6 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 2 Sep 2002 07:42:39 +0000 Subject: Fix transposed args in open_pipe_creds() function. (This used to be commit 63e59b0b737a1cd4ccc588b27e86be8262296052) --- 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 a65206e022..6247bf6371 100644 --- a/source3/python/py_common.c +++ b/source3/python/py_common.c @@ -211,7 +211,7 @@ struct cli_state *open_pipe_creds(char *server, PyObject *creds, /* Extract credentials from the python dictionary */ - if (!py_parse_creds(creds, &username, &password, &domain, errstr)) + if (!py_parse_creds(creds, &username, &domain, &password, errstr)) return NULL; /* Now try to connect */ -- cgit From fc8c6e7cf08d4570514bdae6d6b37a5e3112c924 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 2 Sep 2002 07:44:00 +0000 Subject: Added methods for getprinterdataex, setprinterdataex and enumprinterdataex. (This used to be commit ac84b220aa2910abec309f2dc048adb84f609786) --- source3/python/py_spoolss.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'source3/python') diff --git a/source3/python/py_spoolss.c b/source3/python/py_spoolss.c index 95be77de55..4451cd87b2 100644 --- a/source3/python/py_spoolss.c +++ b/source3/python/py_spoolss.c @@ -281,6 +281,18 @@ Set the form given by the dictionary argument."}, METH_VARARGS | METH_KEYWORDS, "Delete printer data." }, + { "getprinterdataex", (PyCFunction)spoolss_hnd_getprinterdataex, + METH_VARARGS | METH_KEYWORDS, + "Get printer data." }, + + { "setprinterdataex", (PyCFunction)spoolss_hnd_setprinterdataex, + METH_VARARGS | METH_KEYWORDS, + "Set printer data." }, + + { "enumprinterdataex", (PyCFunction)spoolss_hnd_enumprinterdataex, + METH_VARARGS | METH_KEYWORDS, + "Enumerate printer data." }, + { "deleteprinterdataex", (PyCFunction)spoolss_hnd_deleteprinterdataex, METH_VARARGS | METH_KEYWORDS, "Delete printer data." }, -- cgit From 7ee13d88a18cd99c6d92f400af988961a9ac15d4 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 2 Sep 2002 07:44:48 +0000 Subject: make proto (This used to be commit 88a97d2174eee884de52e848d30bc2c459bf28bb) --- source3/python/py_spoolss_proto.h | 3 +++ 1 file changed, 3 insertions(+) (limited to 'source3/python') diff --git a/source3/python/py_spoolss_proto.h b/source3/python/py_spoolss_proto.h index 5b68ef815a..b5c6a3239e 100644 --- a/source3/python/py_spoolss_proto.h +++ b/source3/python/py_spoolss_proto.h @@ -91,6 +91,9 @@ PyObject *spoolss_hnd_getprinterdata(PyObject *self, PyObject *args, PyObject *k PyObject *spoolss_hnd_setprinterdata(PyObject *self, PyObject *args, PyObject *kw); PyObject *spoolss_hnd_enumprinterdata(PyObject *self, PyObject *args, PyObject *kw); PyObject *spoolss_hnd_deleteprinterdata(PyObject *self, PyObject *args, PyObject *kw); +PyObject *spoolss_hnd_getprinterdataex(PyObject *self, PyObject *args, PyObject *kw); +PyObject *spoolss_hnd_setprinterdataex(PyObject *self, PyObject *args, PyObject *kw); +PyObject *spoolss_hnd_enumprinterdataex(PyObject *self, PyObject *args, PyObject *kw); PyObject *spoolss_hnd_deleteprinterdataex(PyObject *self, PyObject *args, PyObject *kw); /* The following definitions come from python/py_spoolss_printers.c */ -- cgit From 1f914af0ecd688e12c533c9eac6a1eadd2675022 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 2 Sep 2002 07:47:42 +0000 Subject: Add a 'key' field to printer data dictionary. Implemented getprinterdataex, setprinterdataex and enumprinterdataex (doesn't quite work yet). (This used to be commit fb0f4f7bfe81923adfe71549973da2be57f0e71f) --- source3/python/py_spoolss_printerdata.c | 152 ++++++++++++++++++++++++++++---- 1 file changed, 134 insertions(+), 18 deletions(-) (limited to 'source3/python') diff --git a/source3/python/py_spoolss_printerdata.c b/source3/python/py_spoolss_printerdata.c index e1e43fa736..ff8b935679 100644 --- a/source3/python/py_spoolss_printerdata.c +++ b/source3/python/py_spoolss_printerdata.c @@ -20,14 +20,15 @@ #include "python/py_spoolss.h" -static BOOL py_from_printerdata(PyObject **dict, char *value, +static BOOL py_from_printerdata(PyObject **dict, char *key, char *value, uint32 data_type, char *data, uint32 data_size) { *dict = PyDict_New(); - PyDict_SetItemString(*dict, "type", Py_BuildValue("i", data_type)); + PyDict_SetItemString(*dict, "key", Py_BuildValue("s", key ? key : "")); PyDict_SetItemString(*dict, "value", Py_BuildValue("s", value)); + PyDict_SetItemString(*dict, "type", Py_BuildValue("i", data_type)); PyDict_SetItemString(*dict, "data", Py_BuildValue("s#", data, data_size)); @@ -35,25 +36,26 @@ static BOOL py_from_printerdata(PyObject **dict, char *value, return True; } -static BOOL py_to_printerdata(char **value, uint32 *data_type, +static BOOL py_to_printerdata(char **key, char **value, uint32 *data_type, char **data, uint32 *data_size, PyObject *dict) { PyObject *obj; - if ((obj = PyDict_GetItemString(dict, "type"))) { + if ((obj = PyDict_GetItemString(dict, "key"))) { - if (!PyInt_Check(obj)) { + if (!PyString_Check(obj)) { PyErr_SetString(spoolss_error, - "type not an integer"); + "key not a string"); return False; } - *data_type = PyInt_AsLong(obj); - } else { - PyErr_SetString(spoolss_error, "no type present"); - return False; - } + *key = PyString_AsString(obj); + + if (!key[0]) + *key = NULL; + } else + *key = NULL; if ((obj = PyDict_GetItemString(dict, "value"))) { @@ -69,6 +71,20 @@ static BOOL py_to_printerdata(char **value, uint32 *data_type, return False; } + if ((obj = PyDict_GetItemString(dict, "type"))) { + + if (!PyInt_Check(obj)) { + PyErr_SetString(spoolss_error, + "type not an integer"); + return False; + } + + *data_type = PyInt_AsLong(obj); + } else { + PyErr_SetString(spoolss_error, "no type present"); + return False; + } + if ((obj = PyDict_GetItemString(dict, "data"))) { if (!PyString_Check(obj)) { @@ -118,7 +134,7 @@ PyObject *spoolss_hnd_getprinterdata(PyObject *self, PyObject *args, PyObject *k return NULL; } - py_from_printerdata(&result, value, data_type, data, needed); + py_from_printerdata(&result, NULL, value, data_type, data, needed); return result; } @@ -128,7 +144,7 @@ PyObject *spoolss_hnd_setprinterdata(PyObject *self, PyObject *args, PyObject *k spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self; static char *kwlist[] = { "data", NULL }; PyObject *py_data; - char *value, *data; + char *key, *value, *data; uint32 data_size, data_type; WERROR werror; @@ -136,7 +152,7 @@ PyObject *spoolss_hnd_setprinterdata(PyObject *self, PyObject *args, PyObject *k args, kw, "O!", kwlist, &PyDict_Type, &py_data)) return NULL; - if (!py_to_printerdata(&value, &data_type, &data, &data_size, py_data)) + if (!py_to_printerdata(&key, &value, &data_type, &data, &data_size, py_data)) return NULL; /* Call rpc function */ @@ -189,8 +205,8 @@ PyObject *spoolss_hnd_enumprinterdata(PyObject *self, PyObject *args, PyObject * value_needed, data_needed, NULL, NULL, &value, &data_type, &data, &data_size); - if (py_from_printerdata(&obj, value, data_type, data, - data_size)) + if (py_from_printerdata( + &obj, NULL, value, data_type, data, data_size)) PyDict_SetItemString(result, value, obj); ndx++; @@ -225,10 +241,110 @@ PyObject *spoolss_hnd_deleteprinterdata(PyObject *self, PyObject *args, PyObject return Py_None; } -PyObject *spoolss_hnd_deleteprinterdataex(PyObject *self, PyObject *args, PyObject *kw) +PyObject *spoolss_hnd_getprinterdataex(PyObject *self, PyObject *args, PyObject *kw) +{ + spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self; + static char *kwlist[] = { "key", "value", NULL }; + char *key, *value; + WERROR werror; + uint32 needed, data_type, data_size; + char *data; + PyObject *result; + + /* Parse parameters */ + + if (!PyArg_ParseTupleAndKeywords(args, kw, "ss", kwlist, &key, &value)) + return NULL; + + /* Call rpc function */ + + werror = cli_spoolss_getprinterdataex( + hnd->cli, hnd->mem_ctx, 0, &needed, &hnd->pol, key, + value, &data_type, &data, &data_size); + + if (W_ERROR_V(werror) == ERRmoredata) + werror = cli_spoolss_getprinterdataex( + hnd->cli, hnd->mem_ctx, needed, NULL, &hnd->pol, key, + value, &data_type, &data, &data_size); + + if (!W_ERROR_IS_OK(werror)) { + PyErr_SetObject(spoolss_werror, py_werror_tuple(werror)); + return NULL; + } + + py_from_printerdata(&result, key, value, data_type, data, needed); + + return result; +} + +PyObject *spoolss_hnd_setprinterdataex(PyObject *self, PyObject *args, PyObject *kw) { - /* Not supported by Samba server */ + spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self; + static char *kwlist[] = { "data", NULL }; + PyObject *py_data; + char *key, *value, *data; + uint32 data_size, data_type; + WERROR werror; + + if (!PyArg_ParseTupleAndKeywords( + args, kw, "O!", kwlist, &PyDict_Type, &py_data)) + return NULL; + + if (!py_to_printerdata(&key, &value, &data_type, &data, &data_size, py_data)) + return NULL; + /* Call rpc function */ + + werror = cli_spoolss_setprinterdataex( + hnd->cli, hnd->mem_ctx, &hnd->pol, key, value, data_type, + data, data_size); + + if (!W_ERROR_IS_OK(werror)) { + PyErr_SetObject(spoolss_werror, py_werror_tuple(werror)); + return NULL; + } + + Py_INCREF(Py_None); + return Py_None; +} + +PyObject *spoolss_hnd_enumprinterdataex(PyObject *self, PyObject *args, PyObject *kw) +{ + spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self; + static char *kwlist[] = { NULL }; + uint32 needed; + char *key, *value, *data; + WERROR werror; + PyObject *result; + + if (!PyArg_ParseTupleAndKeywords(args, kw, "s", kwlist, &key)) + return NULL; + + /* Get max buffer sizes for value and data */ + + werror = cli_spoolss_enumprinterdataex( + hnd->cli, hnd->mem_ctx, 0, &needed, &hnd->pol, key); + + if (W_ERROR_V(werror) == ERRmoredata) + werror = cli_spoolss_enumprinterdataex( + hnd->cli, hnd->mem_ctx, needed, NULL, &hnd->pol, key); + + if (!W_ERROR_IS_OK(werror)) { + PyErr_SetObject(spoolss_werror, py_werror_tuple(werror)); + return NULL; + } + + /* Iterate over all printerdata */ + + result = PyDict_New(); + + + + return result; +} + +PyObject *spoolss_hnd_deleteprinterdataex(PyObject *self, PyObject *args, PyObject *kw) +{ PyErr_SetString(spoolss_error, "Not implemented"); return NULL; } -- cgit From 611f9c899dceb912a27a20e74a5bb22809999286 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Tue, 3 Sep 2002 00:40:06 +0000 Subject: Return dictionary of printerdata in enumprinterdataex. (This used to be commit 348b6778d8b9e42f27da51652c7198cc42048059) --- source3/python/py_spoolss_printerdata.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'source3/python') diff --git a/source3/python/py_spoolss_printerdata.c b/source3/python/py_spoolss_printerdata.c index ff8b935679..7f2c0bfe88 100644 --- a/source3/python/py_spoolss_printerdata.c +++ b/source3/python/py_spoolss_printerdata.c @@ -312,10 +312,11 @@ PyObject *spoolss_hnd_enumprinterdataex(PyObject *self, PyObject *args, PyObject { spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self; static char *kwlist[] = { NULL }; - uint32 needed; - char *key, *value, *data; + uint32 needed, returned, i; + char *key; WERROR werror; PyObject *result; + PRINTER_ENUM_VALUES *values; if (!PyArg_ParseTupleAndKeywords(args, kw, "s", kwlist, &key)) return NULL; @@ -323,11 +324,13 @@ PyObject *spoolss_hnd_enumprinterdataex(PyObject *self, PyObject *args, PyObject /* Get max buffer sizes for value and data */ werror = cli_spoolss_enumprinterdataex( - hnd->cli, hnd->mem_ctx, 0, &needed, &hnd->pol, key); + hnd->cli, hnd->mem_ctx, 0, &needed, &hnd->pol, key, + &returned, &values); if (W_ERROR_V(werror) == ERRmoredata) werror = cli_spoolss_enumprinterdataex( - hnd->cli, hnd->mem_ctx, needed, NULL, &hnd->pol, key); + hnd->cli, hnd->mem_ctx, needed, NULL, &hnd->pol, key, + &returned, &values); if (!W_ERROR_IS_OK(werror)) { PyErr_SetObject(spoolss_werror, py_werror_tuple(werror)); @@ -338,8 +341,18 @@ PyObject *spoolss_hnd_enumprinterdataex(PyObject *self, PyObject *args, PyObject result = PyDict_New(); - + for (i = 0; i < returned; i++) { + PyObject *item; + fstring value = ""; + rpcstr_pull(value, values[i].valuename.buffer, sizeof(value), -1, STR_TERMINATE); + item = PyDict_New(); + py_from_printerdata(&item, key, value, values[i].type, values[i].data, + values[i].data_len); + + PyDict_SetItemString(result, value, item); + } + return result; } -- cgit From 2a18e89da74c9b4e352e41ca5fe261f332018f85 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Tue, 3 Sep 2002 01:10:21 +0000 Subject: Implement deleteprinterdataex (This used to be commit a89fe79e222b36eda123ccdbca96badb7714776e) --- source3/python/py_spoolss_printerdata.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'source3/python') diff --git a/source3/python/py_spoolss_printerdata.c b/source3/python/py_spoolss_printerdata.c index 7f2c0bfe88..0c62baab72 100644 --- a/source3/python/py_spoolss_printerdata.c +++ b/source3/python/py_spoolss_printerdata.c @@ -358,6 +358,26 @@ PyObject *spoolss_hnd_enumprinterdataex(PyObject *self, PyObject *args, PyObject PyObject *spoolss_hnd_deleteprinterdataex(PyObject *self, PyObject *args, PyObject *kw) { - PyErr_SetString(spoolss_error, "Not implemented"); - return NULL; + spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self; + static char *kwlist[] = { "key", "value", NULL }; + char *key, *value; + WERROR werror; + + /* Parse parameters */ + + if (!PyArg_ParseTupleAndKeywords(args, kw, "ss", kwlist, &key, &value)) + return NULL; + + /* Call rpc function */ + + werror = cli_spoolss_deleteprinterdataex( + hnd->cli, hnd->mem_ctx, &hnd->pol, key, value); + + if (!W_ERROR_IS_OK(werror)) { + PyErr_SetObject(spoolss_werror, py_werror_tuple(werror)); + return NULL; + } + + Py_INCREF(Py_None); + return Py_None; } -- cgit From 86d9d827ce2000a604eeb9af9c3c617bf0c2d9eb Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Tue, 3 Sep 2002 01:30:26 +0000 Subject: Ignore *.pyc files. (This used to be commit 519d1589a9358d8c2de01bd23159e3d552554131) --- source3/python/.cvsignore | 1 + 1 file changed, 1 insertion(+) (limited to 'source3/python') diff --git a/source3/python/.cvsignore b/source3/python/.cvsignore index 659ddbfdf9..8ce381cd39 100644 --- a/source3/python/.cvsignore +++ b/source3/python/.cvsignore @@ -1 +1,2 @@ setup.py +*.pyc \ No newline at end of file -- cgit From 8e56ded996d3b083a1a12ce81dbf0ace4bbc6381 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Tue, 3 Sep 2002 01:32:05 +0000 Subject: Rewrote to use gtkdictbrowser. (This used to be commit 6f78c4181449a995b9d5b2955981a20e4fdcc829) --- source3/python/gtdbtool | 263 ++---------------------------------------------- 1 file changed, 10 insertions(+), 253 deletions(-) (limited to 'source3/python') diff --git a/source3/python/gtdbtool b/source3/python/gtdbtool index 792cdeecc0..d5c76fa318 100755 --- a/source3/python/gtdbtool +++ b/source3/python/gtdbtool @@ -1,242 +1,10 @@ #!/usr/bin/env python -from gtk import * import sys +from gtkdictbrowser import GtkDictBrowser +import gtk import tdb import string -import re - -# -# The gdbtool user interface. The design here is to keep all the gtk stuff -# separate from the tdb stuff so all the user interface magic is stored -# here. -# - -class gtdbtool: - - # Initialise the user interface. A dictionary argument is passed - # in which is the dictionary to display keys and values on the left - # hand and right hand side of the user interface respectively.""" - - def __init__(self, dict): - self.dict = dict - self.value_display_fns = [] - self.filter_regex = "" - - # Create and configure user interface widgets. A string argument is - # used to set the window title. - - def build_ui(self, title): - win = GtkWindow() - win.set_title(title) - - win.connect("destroy", mainquit) - - hpaned = GtkHPaned() - win.add(hpaned) - hpaned.set_border_width(5) - hpaned.show() - - vbox = GtkVBox() - hpaned.add1(vbox) - vbox.show() - - scrolled_win = GtkScrolledWindow() - scrolled_win.set_policy(POLICY_AUTOMATIC, POLICY_AUTOMATIC) - vbox.pack_start(scrolled_win) - scrolled_win.show() - - hbox = GtkHBox() - vbox.pack_end(hbox, expand = 0, padding = 5) - hbox.show() - - label = GtkLabel("Filter:") - hbox.pack_start(label, expand = 0, padding = 5) - label.show() - - self.entry = GtkEntry() - hbox.pack_end(self.entry, padding = 5) - self.entry.show() - - self.entry.connect("activate", self.filter_activated) - - self.list = GtkList() - self.list.set_selection_mode(SELECTION_MULTIPLE) - self.list.set_selection_mode(SELECTION_BROWSE) - scrolled_win.add_with_viewport(self.list) - self.list.show() - - self.list.connect("select_child", self.key_selected) - - scrolled_win = GtkScrolledWindow() - scrolled_win.set_policy(POLICY_AUTOMATIC, POLICY_AUTOMATIC) - hpaned.add2(scrolled_win) - scrolled_win.set_usize(500,400) - scrolled_win.show() - - self.text = GtkText() - self.text.set_editable(FALSE) - scrolled_win.add_with_viewport(self.text) - self.text.show() - - self.text.connect("event", self.event_handler) - - self.menu = GtkMenu() - self.menu.show() - - self.font = load_font("fixed") - - self.update_keylist() - - win.show() - - # Add a key to the left hand side of the user interface - - def add_key(self, key): - display_key = self.display_key(key) - list_item = GtkListItem(display_key) - list_item.set_data("raw_key", key) # Store raw key in item data - self.list.add(list_item) - list_item.show() - - # Event handler registered by build_ui() - - def event_handler(self, event, menu): - return FALSE - - # Set the text to appear in the right hand side of the user interface - - def set_value_text(self, text): - self.text.delete_text(0, self.text.get_length()) - - # The text widget has trouble inserting text containing NULL - # characters. - - text = string.replace(text, "\x00", ".") - - self.text.insert(self.font, None, None, text) - - # This function is called when a key is selected in the left hand side - # of the user interface. - - def key_selected(self, list, list_item): - key = list_item.children()[0].get() - - # Look for a match in the value display function list - - text = t[list_item.get_data("raw_key")] - - for entry in self.value_display_fns: - if re.match(entry[0], key): - text = entry[1](text) - break - - self.set_value_text(text) - - # Refresh the key list by removing all items and re-inserting them. - # Items are only inserted if they pass through the filter regexp. - - def update_keylist(self): - self.list.remove_items(self.list.children()) - self.set_value_text("") - for k in self.dict.keys(): - if re.match(self.filter_regex, k): - self.add_key(k) - - # Invoked when the user hits return in the filter text entry widget. - - def filter_activated(self, entry): - self.filter_regex = entry.get_text() - self.update_keylist() - - # - # Public methods - # - - # Set a function that translates between how keys look in the user - # interface (displayed keys) versus how they are represented in the tdb - # (raw keys). - - def set_display_key_fn(self, fn): - self.display_key = fn - - # Register a value display function for a key. The first argument is a - # regex that matches key values, and the second argument is a function - # to call to convert the raw value data to a string to display in the - # right hand side of the UI. - - def register_display_value_fn(self, key_regexp, fn): - self.value_display_fns.append((key_regexp, fn)) - - def display_value_hex(self, value): - return "foo" - -def convert_to_hex(data): - """Return a hex dump of a string as a string. - - The output produced is in the standard 16 characters per line hex + - ascii format: - - 00000000: 40 00 00 00 00 00 00 00 40 00 00 00 01 00 04 80 @....... @....... - 00000010: 01 01 00 00 00 00 00 01 00 00 00 00 ........ .... - """ - - pos = 0 # Position in data - line = 0 # Line of data - - hex = "" # Hex display - ascii = "" # ASCII display - - result = "" - - while pos < len(data): - - # Start with header - - if pos % 16 == 0: - hex = "%08x: " % (line * 16) - ascii = "" - - # Add character - - hex = hex + "%02x " % (ord(data[pos])) - - if ord(data[pos]) < 32 or ord(data[pos]) > 176: - ascii = ascii + '.' - else: - ascii = ascii + data[pos] - - pos = pos + 1 - - # Add separator if half way - - if pos % 16 == 8: - hex = hex + " " - ascii = ascii + " " - - # End of line - - if pos % 16 == 0: - result = result + "%s %s\n" % (hex, ascii) - line = line + 1 - - # Leftover bits - - if pos % 16 != 0: - - # Pad hex string - - for i in range(0, (16 - (pos % 16))): - hex = hex + " " - - # Half way separator - - if (pos % 16) < 8: - hex = hex + " " - - result = result + "%s %s\n" % (hex, ascii) - - return result # Open handle on tdb @@ -250,33 +18,22 @@ except tdb.error, t: print "gtdbtool: error opening %s: %s" % (sys.argv[1], t) sys.exit(1) -# Create user interface +# Create interface -w = gtdbtool(t) - -# Set up a key display function. A lot of keys have \x00 appended to the -# end which mucks up gtk. +db = GtkDictBrowser(t) def display_key_x00(key): + """Remove \x00 from all keys as they mucks up GTK.""" return string.replace(key, "\x00", "") -w.set_display_key_fn(display_key_x00) - -def display_value_hex(value): - return value; - -w.register_display_value_fn("DRIVERS/", convert_to_hex) -w.register_display_value_fn("SECDESC/", convert_to_hex) -w.register_display_value_fn("PRINTERS/", convert_to_hex) - -# Show user interface +db.register_get_key_text_fn(display_key_x00) -w.build_ui("gtdbtool: %s" % sys.argv[1]) +db.build_ui('gtdbtool') -# Override Python's handling of ctrl-c so we can break out of the gui -# from the command line. +# Override Python's handling of ctrl-c so we can break out of the +# gui from the command line. import signal signal.signal(signal.SIGINT, signal.SIG_DFL) -mainloop() +gtk.mainloop() -- cgit From 53495225a5e5392a98f1fbc252f0fddf48f0dd77 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Tue, 3 Sep 2002 01:48:24 +0000 Subject: A printerdata browser I whipped up in about 5 minutes. (-: Usage: gprinterdata //win2kdc1/fooprinter (This used to be commit a3e52367c961070ce80ac3d4bba763ad9ec1007c) --- source3/python/gprinterdata | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100755 source3/python/gprinterdata (limited to 'source3/python') diff --git a/source3/python/gprinterdata b/source3/python/gprinterdata new file mode 100755 index 0000000000..cd04e6f5a1 --- /dev/null +++ b/source3/python/gprinterdata @@ -0,0 +1,44 @@ +#!/usr/bin/env python + +import sys +from gtkdictbrowser import GtkDictBrowser +import gtk +import spoolss +import string + +class printerdata: + def __init__(self, host): + host = string.replace(host, "/", "\\") + self.hnd = spoolss.openprinter(host) + + def keys(self): + return self.hnd.enumprinterdata().keys() + + def __getitem__(self, key): + return self.hnd.getprinterdata(key)['data'] + +# Initialise printerdata dictionary + +if len(sys.argv) != 2: + print "Usage: gprinterdata " + print "where is a UNC printer name." + sys.exit(1) + +try: + t = printerdata(sys.argv[1]) +except: + print "gprinterdata: error opening %s" % sys.argv[1] + sys.exit(1) + +# Create interface + +db = GtkDictBrowser(t) +db.build_ui('gprinterdata') + +# Override Python's handling of ctrl-c so we can break out of the +# gui from the command line. + +import signal +signal.signal(signal.SIGINT, signal.SIG_DFL) + +gtk.mainloop() -- cgit From 2e93f20c1b10f98de79f76a18e5d34b1465edfbf Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Tue, 3 Sep 2002 01:55:21 +0000 Subject: Added utility function to convert python strings to hex dump + ascii. (This used to be commit 7a6b6a8b4871065e3178223a7da5fafd8792b0bc) --- source3/python/gtkdictbrowser.py | 73 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) (limited to 'source3/python') diff --git a/source3/python/gtkdictbrowser.py b/source3/python/gtkdictbrowser.py index 1609dff9b4..6d6cdb3c8a 100755 --- a/source3/python/gtkdictbrowser.py +++ b/source3/python/gtkdictbrowser.py @@ -169,6 +169,79 @@ class GtkDictBrowser: def register_get_value_text_fn(self, regexp, fn): self.get_value_text_fns.append((regexp, fn)) +# +# A utility function to convert a string to the standard hex + ascii format. +# To display all values in hex do: +# register_get_value_text_fn("", gtkdictbrowser.hex_string) +# + +def hex_string(data): + """Return a hex dump of a string as a string. + + The output produced is in the standard 16 characters per line hex + + ascii format: + + 00000000: 40 00 00 00 00 00 00 00 40 00 00 00 01 00 04 80 @....... @....... + 00000010: 01 01 00 00 00 00 00 01 00 00 00 00 ........ .... + """ + + pos = 0 # Position in data + line = 0 # Line of data + + hex = "" # Hex display + ascii = "" # ASCII display + + result = "" + + while pos < len(data): + + # Start with header + + if pos % 16 == 0: + hex = "%08x: " % (line * 16) + ascii = "" + + # Add character + + hex = hex + "%02x " % (ord(data[pos])) + + if ord(data[pos]) < 32 or ord(data[pos]) > 176: + ascii = ascii + '.' + else: + ascii = ascii + data[pos] + + pos = pos + 1 + + # Add separator if half way + + if pos % 16 == 8: + hex = hex + " " + ascii = ascii + " " + + # End of line + + if pos % 16 == 0: + result = result + "%s %s\n" % (hex, ascii) + line = line + 1 + + # Leftover bits + + if pos % 16 != 0: + + # Pad hex string + + for i in range(0, (16 - (pos % 16))): + hex = hex + " " + + # Half way separator + + if (pos % 16) < 8: + hex = hex + " " + + result = result + "%s %s\n" % (hex, ascii) + + return result + # For testing purposes, create a fixed dictionary to browse with if __name__ == "__main__": -- cgit From 62d6c7f8f836d46e423e4150b7fab1cd7bd61d63 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Tue, 3 Sep 2002 01:56:05 +0000 Subject: Display printerdata values in hex. (This used to be commit cdd64e0860bf05b115e0d107f6cb2b9e1f6d0e9b) --- source3/python/gprinterdata | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source3/python') diff --git a/source3/python/gprinterdata b/source3/python/gprinterdata index cd04e6f5a1..52c6e42719 100755 --- a/source3/python/gprinterdata +++ b/source3/python/gprinterdata @@ -1,7 +1,7 @@ #!/usr/bin/env python import sys -from gtkdictbrowser import GtkDictBrowser +from gtkdictbrowser import GtkDictBrowser, hex_string import gtk import spoolss import string @@ -33,6 +33,7 @@ except: # Create interface db = GtkDictBrowser(t) +db.register_get_value_text_fn("", hex_string) db.build_ui('gprinterdata') # Override Python's handling of ctrl-c so we can break out of the -- cgit From 45664627c78e118c65f4d34a44eac3485b97f99e Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Tue, 3 Sep 2002 04:58:36 +0000 Subject: Fixed enumjobs command to use new JOB_INFO_CTR structure. (This used to be commit 9db5be03617740e705bce51784fdb80784779acb) --- source3/python/py_spoolss_jobs.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/python') diff --git a/source3/python/py_spoolss_jobs.c b/source3/python/py_spoolss_jobs.c index cc5d42e0ee..59754bd36d 100644 --- a/source3/python/py_spoolss_jobs.c +++ b/source3/python/py_spoolss_jobs.c @@ -150,10 +150,10 @@ PyObject *spoolss_hnd_getjob(PyObject *self, PyObject *args, PyObject *kw) switch(level) { case 1: - py_from_JOB_INFO_1(&result, ctr.job.job_info_1); + py_from_JOB_INFO_1(&result, &ctr.job.job_info_1[0]); break; case 2: - py_from_JOB_INFO_2(&result, ctr.job.job_info_2); + py_from_JOB_INFO_2(&result, &ctr.job.job_info_2[0]); break; } -- cgit From b2e4d8e5f9c208ad5edf5fb2e01c8f1f14fb96a9 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Tue, 3 Sep 2002 05:00:17 +0000 Subject: Convert to new REGISTRY_VALUE cli_spoolss routines. (This used to be commit 100aa8c893464d65f1b2225dab9dc5b58bbcff91) --- source3/python/py_spoolss_printerdata.c | 112 +++++++++++++++++--------------- 1 file changed, 61 insertions(+), 51 deletions(-) (limited to 'source3/python') diff --git a/source3/python/py_spoolss_printerdata.c b/source3/python/py_spoolss_printerdata.c index 0c62baab72..ffff2b3a67 100644 --- a/source3/python/py_spoolss_printerdata.c +++ b/source3/python/py_spoolss_printerdata.c @@ -21,7 +21,7 @@ #include "python/py_spoolss.h" static BOOL py_from_printerdata(PyObject **dict, char *key, char *value, - uint32 data_type, char *data, + uint16 data_type, uint8 *data, uint32 data_size) { *dict = PyDict_New(); @@ -36,8 +36,8 @@ static BOOL py_from_printerdata(PyObject **dict, char *key, char *value, return True; } -static BOOL py_to_printerdata(char **key, char **value, uint32 *data_type, - char **data, uint32 *data_size, +static BOOL py_to_printerdata(char **key, char **value, uint16 *data_type, + uint8 **data, uint32 *data_size, PyObject *dict) { PyObject *obj; @@ -50,10 +50,12 @@ static BOOL py_to_printerdata(char **key, char **value, uint32 *data_type, return False; } - *key = PyString_AsString(obj); + if (key) { + *key = PyString_AsString(obj); - if (!key[0]) - *key = NULL; + if (!key[0]) + *key = NULL; + } } else *key = NULL; @@ -107,34 +109,36 @@ PyObject *spoolss_hnd_getprinterdata(PyObject *self, PyObject *args, PyObject *k { spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self; static char *kwlist[] = { "value", NULL }; - char *value; + char *valuename; WERROR werror; - uint32 needed, data_type, data_size; - char *data; + uint32 needed; PyObject *result; + REGISTRY_VALUE value; /* Parse parameters */ - if (!PyArg_ParseTupleAndKeywords(args, kw, "s", kwlist, &value)) + if (!PyArg_ParseTupleAndKeywords(args, kw, "s", kwlist, &valuename)) return NULL; /* Call rpc function */ werror = cli_spoolss_getprinterdata( - hnd->cli, hnd->mem_ctx, 0, &needed, &hnd->pol, value, - &data_type, &data, &data_size); + hnd->cli, hnd->mem_ctx, 0, &needed, &hnd->pol, valuename, + &value); if (W_ERROR_V(werror) == ERRmoredata) werror = cli_spoolss_getprinterdata( - hnd->cli, hnd->mem_ctx, needed, NULL, &hnd->pol, value, - &data_type, &data, &data_size); + hnd->cli, hnd->mem_ctx, needed, NULL, &hnd->pol, + valuename, &value); if (!W_ERROR_IS_OK(werror)) { PyErr_SetObject(spoolss_werror, py_werror_tuple(werror)); return NULL; } - py_from_printerdata(&result, NULL, value, data_type, data, needed); + py_from_printerdata( + &result, NULL, valuename, value.type, value.data_p, + value.size); return result; } @@ -144,22 +148,25 @@ PyObject *spoolss_hnd_setprinterdata(PyObject *self, PyObject *args, PyObject *k spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self; static char *kwlist[] = { "data", NULL }; PyObject *py_data; - char *key, *value, *data; - uint32 data_size, data_type; + char *valuename; WERROR werror; + REGISTRY_VALUE value; if (!PyArg_ParseTupleAndKeywords( args, kw, "O!", kwlist, &PyDict_Type, &py_data)) return NULL; - if (!py_to_printerdata(&key, &value, &data_type, &data, &data_size, py_data)) + if (!py_to_printerdata( + NULL, &valuename, &value.type, &value.data_p, + &value.size, py_data)) return NULL; + fstrcpy(value.valuename, valuename); + /* Call rpc function */ werror = cli_spoolss_setprinterdata( - hnd->cli, hnd->mem_ctx, &hnd->pol, value, data_type, - data, data_size); + hnd->cli, hnd->mem_ctx, &hnd->pol, &value); if (!W_ERROR_IS_OK(werror)) { PyErr_SetObject(spoolss_werror, py_werror_tuple(werror)); @@ -174,10 +181,10 @@ PyObject *spoolss_hnd_enumprinterdata(PyObject *self, PyObject *args, PyObject * { spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self; static char *kwlist[] = { NULL }; - uint32 data_needed, value_needed, ndx = 0, data_size, data_type; - char *value, *data; + uint32 data_needed, value_needed, ndx = 0; WERROR werror; PyObject *result; + REGISTRY_VALUE value; if (!PyArg_ParseTupleAndKeywords(args, kw, "", kwlist)) return NULL; @@ -186,7 +193,7 @@ PyObject *spoolss_hnd_enumprinterdata(PyObject *self, PyObject *args, PyObject * werror = cli_spoolss_enumprinterdata( hnd->cli, hnd->mem_ctx, &hnd->pol, ndx, 0, 0, - &value_needed, &data_needed, NULL, NULL, NULL, NULL); + &value_needed, &data_needed, NULL); if (!W_ERROR_IS_OK(werror)) { PyErr_SetObject(spoolss_werror, py_werror_tuple(werror)); @@ -202,12 +209,12 @@ PyObject *spoolss_hnd_enumprinterdata(PyObject *self, PyObject *args, PyObject * werror = cli_spoolss_enumprinterdata( hnd->cli, hnd->mem_ctx, &hnd->pol, ndx, - value_needed, data_needed, NULL, NULL, - &value, &data_type, &data, &data_size); + value_needed, data_needed, NULL, NULL, &value); if (py_from_printerdata( - &obj, NULL, value, data_type, data, data_size)) - PyDict_SetItemString(result, value, obj); + &obj, NULL, value.valuename, value.type, + value.data_p, value.size)) + PyDict_SetItemString(result, value.valuename, obj); ndx++; } @@ -245,34 +252,35 @@ PyObject *spoolss_hnd_getprinterdataex(PyObject *self, PyObject *args, PyObject { spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self; static char *kwlist[] = { "key", "value", NULL }; - char *key, *value; + char *key, *valuename; WERROR werror; - uint32 needed, data_type, data_size; - char *data; + uint32 needed; PyObject *result; + REGISTRY_VALUE value; /* Parse parameters */ - if (!PyArg_ParseTupleAndKeywords(args, kw, "ss", kwlist, &key, &value)) + if (!PyArg_ParseTupleAndKeywords(args, kw, "ss", kwlist, &key, &valuename)) return NULL; /* Call rpc function */ werror = cli_spoolss_getprinterdataex( hnd->cli, hnd->mem_ctx, 0, &needed, &hnd->pol, key, - value, &data_type, &data, &data_size); + valuename, &value); if (W_ERROR_V(werror) == ERRmoredata) werror = cli_spoolss_getprinterdataex( hnd->cli, hnd->mem_ctx, needed, NULL, &hnd->pol, key, - value, &data_type, &data, &data_size); + valuename, &value); if (!W_ERROR_IS_OK(werror)) { PyErr_SetObject(spoolss_werror, py_werror_tuple(werror)); return NULL; } - py_from_printerdata(&result, key, value, data_type, data, needed); + py_from_printerdata( + &result, key, valuename, value.type, value.data_p, value.size); return result; } @@ -282,22 +290,24 @@ PyObject *spoolss_hnd_setprinterdataex(PyObject *self, PyObject *args, PyObject spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self; static char *kwlist[] = { "data", NULL }; PyObject *py_data; - char *key, *value, *data; - uint32 data_size, data_type; + char *keyname, *valuename; WERROR werror; + REGISTRY_VALUE value; if (!PyArg_ParseTupleAndKeywords( args, kw, "O!", kwlist, &PyDict_Type, &py_data)) return NULL; - if (!py_to_printerdata(&key, &value, &data_type, &data, &data_size, py_data)) + if (!py_to_printerdata( + &keyname, &valuename, &value.type, &value.data_p, &value.size, py_data)) return NULL; + fstrcpy(value.valuename, valuename); + /* Call rpc function */ werror = cli_spoolss_setprinterdataex( - hnd->cli, hnd->mem_ctx, &hnd->pol, key, value, data_type, - data, data_size); + hnd->cli, hnd->mem_ctx, &hnd->pol, keyname, &value); if (!W_ERROR_IS_OK(werror)) { PyErr_SetObject(spoolss_werror, py_werror_tuple(werror)); @@ -312,11 +322,11 @@ PyObject *spoolss_hnd_enumprinterdataex(PyObject *self, PyObject *args, PyObject { spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self; static char *kwlist[] = { NULL }; - uint32 needed, returned, i; + uint32 needed, i; char *key; WERROR werror; PyObject *result; - PRINTER_ENUM_VALUES *values; + REGVAL_CTR ctr; if (!PyArg_ParseTupleAndKeywords(args, kw, "s", kwlist, &key)) return NULL; @@ -324,13 +334,12 @@ PyObject *spoolss_hnd_enumprinterdataex(PyObject *self, PyObject *args, PyObject /* Get max buffer sizes for value and data */ werror = cli_spoolss_enumprinterdataex( - hnd->cli, hnd->mem_ctx, 0, &needed, &hnd->pol, key, - &returned, &values); + hnd->cli, hnd->mem_ctx, 0, &needed, &hnd->pol, key, &ctr); if (W_ERROR_V(werror) == ERRmoredata) werror = cli_spoolss_enumprinterdataex( - hnd->cli, hnd->mem_ctx, needed, NULL, &hnd->pol, key, - &returned, &values); + hnd->cli, hnd->mem_ctx, needed, NULL, &hnd->pol, key, + &ctr); if (!W_ERROR_IS_OK(werror)) { PyErr_SetObject(spoolss_werror, py_werror_tuple(werror)); @@ -341,16 +350,17 @@ PyObject *spoolss_hnd_enumprinterdataex(PyObject *self, PyObject *args, PyObject result = PyDict_New(); - for (i = 0; i < returned; i++) { + for (i = 0; i < regval_ctr_numvals(&ctr); i++) { + REGISTRY_VALUE *value; PyObject *item; - fstring value = ""; - rpcstr_pull(value, values[i].valuename.buffer, sizeof(value), -1, STR_TERMINATE); item = PyDict_New(); - py_from_printerdata(&item, key, value, values[i].type, values[i].data, - values[i].data_len); + value = regval_ctr_specific_value(&ctr, i); - PyDict_SetItemString(result, value, item); + if (py_from_printerdata( + &item, key, value->valuename, value->type, + value->data_p, value->size)) + PyDict_SetItemString(result, value->valuename, item); } return result; -- cgit From 22b75d5c81b7e7ca99e11a304053dac618f7a14e Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Fri, 6 Sep 2002 06:59:40 +0000 Subject: level keys are inserted by conv routines. (This used to be commit b5068bb9fe28cfdd7a00dbc50196eb60e3a46af1) --- source3/python/py_spoolss_drivers.c | 14 -------------- 1 file changed, 14 deletions(-) (limited to 'source3/python') diff --git a/source3/python/py_spoolss_drivers.c b/source3/python/py_spoolss_drivers.c index b5357a78ad..2e8fac4a4e 100644 --- a/source3/python/py_spoolss_drivers.c +++ b/source3/python/py_spoolss_drivers.c @@ -98,9 +98,6 @@ PyObject *spoolss_enumprinterdrivers(PyObject *self, PyObject *args, py_from_DRIVER_INFO_1(&value, &ctr.info1[i]); - PyDict_SetItemString( - value, "level", PyInt_FromLong(1)); - PyDict_SetItemString(result, name, value); } @@ -117,9 +114,6 @@ PyObject *spoolss_enumprinterdrivers(PyObject *self, PyObject *args, py_from_DRIVER_INFO_2(&value, &ctr.info2[i]); - PyDict_SetItemString( - value, "level", PyInt_FromLong(2)); - PyDict_SetItemString(result, name, value); } @@ -136,9 +130,6 @@ PyObject *spoolss_enumprinterdrivers(PyObject *self, PyObject *args, py_from_DRIVER_INFO_3(&value, &ctr.info3[i]); - PyDict_SetItemString( - value, "level", PyInt_FromLong(3)); - PyDict_SetItemString(result, name, value); } @@ -155,9 +146,6 @@ PyObject *spoolss_enumprinterdrivers(PyObject *self, PyObject *args, py_from_DRIVER_INFO_6(&value, &ctr.info6[i]); - PyDict_SetItemString( - value, "level", PyInt_FromLong(6)); - PyList_SetItem(result, i, value); } @@ -302,8 +290,6 @@ PyObject *spoolss_getprinterdriverdir(PyObject *self, PyObject *args, switch (level) { case 1: py_from_DRIVER_DIRECTORY_1(&result, ctr.info1); - PyDict_SetItemString( - result, "level", PyInt_FromLong(1)); break; default: PyErr_SetString(spoolss_error, "unknown info level"); -- cgit From e411dc9687d84dae9e01c57a37ce1bc4b8c71a10 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Fri, 6 Sep 2002 07:01:40 +0000 Subject: Decode list of dependent files in printer driver info3 and info6. It's a null terminated list of null terminated unicode strings. What a mess! (This used to be commit aae48211ff4f22e0c2e2fe57c370f465df4332bc) --- source3/python/py_spoolss_drivers_conv.c | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'source3/python') diff --git a/source3/python/py_spoolss_drivers_conv.c b/source3/python/py_spoolss_drivers_conv.c index dbf33905ae..5d181f9cd9 100644 --- a/source3/python/py_spoolss_drivers_conv.c +++ b/source3/python/py_spoolss_drivers_conv.c @@ -46,7 +46,6 @@ struct pyconv py_DRIVER_INFO_3[] = { { "data_file", PY_UNISTR, offsetof(DRIVER_INFO_3, datafile) }, { "config_file", PY_UNISTR, offsetof(DRIVER_INFO_3, configfile) }, { "help_file", PY_UNISTR, offsetof(DRIVER_INFO_3, helpfile) }, - /* dependentfiles */ { "monitor_name", PY_UNISTR, offsetof(DRIVER_INFO_3, monitorname) }, { "default_datatype", PY_UNISTR, offsetof(DRIVER_INFO_3, defaultdatatype) }, { NULL } @@ -80,6 +79,30 @@ struct pyconv py_DRIVER_DIRECTORY_1[] = { { NULL } }; +/* Convert a NULL terminated list of NULL terminated unicode strings + to a list of (char *) strings */ + +static PyObject *from_dependentfiles(uint16 *dependentfiles) +{ + PyObject *list; + int offset = 0; + + list = PyList_New(0); + + while (*(dependentfiles + offset) != 0) { + fstring name; + int len; + + len = rpcstr_pull(name, dependentfiles + offset, + sizeof(fstring), -1, STR_TERMINATE); + + offset += len / 2; + PyList_Append(list, PyString_FromString(name)); + } + + return list; +} + BOOL py_from_DRIVER_INFO_1(PyObject **dict, DRIVER_INFO_1 *info) { *dict = from_struct(info, py_DRIVER_INFO_1); @@ -108,6 +131,10 @@ 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)); + return True; } @@ -127,6 +154,9 @@ BOOL py_from_DRIVER_INFO_6(PyObject **dict, DRIVER_INFO_6 *info) { *dict = from_struct(info, py_DRIVER_INFO_6); PyDict_SetItemString(*dict, "level", PyInt_FromLong(6)); + PyDict_SetItemString( + *dict, "dependent_files", + from_dependentfiles (info->dependentfiles)); return True; } -- cgit From a2327b84858453ff250b7635f423ae94edf2740b Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Fri, 6 Sep 2002 07:34:57 +0000 Subject: Move printerdata dictionary object into it's own file. (This used to be commit c211d2deca1019d3ef9bd08f5a01e76ede2d0191) --- source3/python/gprinterdata | 15 +++------------ source3/python/printerdata.py | 23 +++++++++++++++++++++++ source3/python/samba/printerdata.py | 23 +++++++++++++++++++++++ 3 files changed, 49 insertions(+), 12 deletions(-) create mode 100644 source3/python/printerdata.py create mode 100644 source3/python/samba/printerdata.py (limited to 'source3/python') diff --git a/source3/python/gprinterdata b/source3/python/gprinterdata index 52c6e42719..f1992db5a5 100755 --- a/source3/python/gprinterdata +++ b/source3/python/gprinterdata @@ -5,18 +5,8 @@ from gtkdictbrowser import GtkDictBrowser, hex_string import gtk import spoolss import string +import printerdata -class printerdata: - def __init__(self, host): - host = string.replace(host, "/", "\\") - self.hnd = spoolss.openprinter(host) - - def keys(self): - return self.hnd.enumprinterdata().keys() - - def __getitem__(self, key): - return self.hnd.getprinterdata(key)['data'] - # Initialise printerdata dictionary if len(sys.argv) != 2: @@ -25,7 +15,8 @@ if len(sys.argv) != 2: sys.exit(1) try: - t = printerdata(sys.argv[1]) + host = string.replace(sys.argv[1], "/", "\\") + t = printerdata.printerdata(host) except: print "gprinterdata: error opening %s" % sys.argv[1] sys.exit(1) diff --git a/source3/python/printerdata.py b/source3/python/printerdata.py new file mode 100644 index 0000000000..55b5fdf6ae --- /dev/null +++ b/source3/python/printerdata.py @@ -0,0 +1,23 @@ +# +# A python module that maps printerdata to a dictionary. We define +# two classes. The printerdata class maps to Get/Set/Enum/DeletePrinterData +# and the printerdata_ex class maps to Get/Set/Enum/DeletePrinterDataEx +# + +import spoolss + +class printerdata: + def __init__(self, host, creds = {}): + self.hnd = spoolss.openprinter(host, creds = creds) + + def keys(self): + return self.hnd.enumprinterdata().keys() + + def __getitem__(self, key): + return self.hnd.getprinterdata(key)['data'] + + def __setitem__(self, key, value): + # Store as REG_BINARY for now + self.hnd.setprinterdata({"key": "", "value": key, "type": 3, + "data": value}) + diff --git a/source3/python/samba/printerdata.py b/source3/python/samba/printerdata.py new file mode 100644 index 0000000000..55b5fdf6ae --- /dev/null +++ b/source3/python/samba/printerdata.py @@ -0,0 +1,23 @@ +# +# A python module that maps printerdata to a dictionary. We define +# two classes. The printerdata class maps to Get/Set/Enum/DeletePrinterData +# and the printerdata_ex class maps to Get/Set/Enum/DeletePrinterDataEx +# + +import spoolss + +class printerdata: + def __init__(self, host, creds = {}): + self.hnd = spoolss.openprinter(host, creds = creds) + + def keys(self): + return self.hnd.enumprinterdata().keys() + + def __getitem__(self, key): + return self.hnd.getprinterdata(key)['data'] + + def __setitem__(self, key, value): + # Store as REG_BINARY for now + self.hnd.setprinterdata({"key": "", "value": key, "type": 3, + "data": value}) + -- cgit From c9101c3b01b7a493944b1fec8612289d8dc531e7 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Fri, 6 Sep 2002 07:44:21 +0000 Subject: Initial version of printerdata_ex browsing. (This used to be commit c201a61a52ffbaf1b1b70e25e0ef2b29a89f921c) --- source3/python/gprinterdata | 13 ++++++++----- source3/python/printerdata.py | 15 +++++++++++++++ source3/python/samba/printerdata.py | 15 +++++++++++++++ 3 files changed, 38 insertions(+), 5 deletions(-) (limited to 'source3/python') diff --git a/source3/python/gprinterdata b/source3/python/gprinterdata index f1992db5a5..59c5f3c315 100755 --- a/source3/python/gprinterdata +++ b/source3/python/gprinterdata @@ -9,16 +9,19 @@ import printerdata # Initialise printerdata dictionary -if len(sys.argv) != 2: - print "Usage: gprinterdata " +if len(sys.argv) < 2 or len(sys.argv) > 3: + print "Usage: gprinterdata [--ex] " print "where is a UNC printer name." sys.exit(1) try: - host = string.replace(sys.argv[1], "/", "\\") - t = printerdata.printerdata(host) + host = string.replace(sys.argv[len(sys.argv) - 1], "/", "\\") + if sys.argv[1] == "--ex": + t = printerdata.printerdata_ex(host) + else: + t = printerdata.printerdata(host) except: - print "gprinterdata: error opening %s" % sys.argv[1] + print "gprinterdata: error opening %s" % sys.argv[len(sys.argv) - 1] sys.exit(1) # Create interface diff --git a/source3/python/printerdata.py b/source3/python/printerdata.py index 55b5fdf6ae..3384de4f30 100644 --- a/source3/python/printerdata.py +++ b/source3/python/printerdata.py @@ -21,3 +21,18 @@ class printerdata: self.hnd.setprinterdata({"key": "", "value": key, "type": 3, "data": value}) +class printerdata_ex: + def __init__(self, host, creds = {}): + self.hnd = spoolss.openprinter(host, creds = creds) + + def keys(self): + return self.hnd.enumprinterdataex("PrinterDriverData").keys() + + def __getitem__(self, key): + return self.hnd.getprinterdataex("PrinterDriverData", key)['data'] + + def __setitem__(self, key, value): + # Store as REG_BINARY for now + self.hnd.setprinterdataex({"key": "PrinterDriverData", "value": key, "type": 3, + "data": value}) + diff --git a/source3/python/samba/printerdata.py b/source3/python/samba/printerdata.py index 55b5fdf6ae..3384de4f30 100644 --- a/source3/python/samba/printerdata.py +++ b/source3/python/samba/printerdata.py @@ -21,3 +21,18 @@ class printerdata: self.hnd.setprinterdata({"key": "", "value": key, "type": 3, "data": value}) +class printerdata_ex: + def __init__(self, host, creds = {}): + self.hnd = spoolss.openprinter(host, creds = creds) + + def keys(self): + return self.hnd.enumprinterdataex("PrinterDriverData").keys() + + def __getitem__(self, key): + return self.hnd.getprinterdataex("PrinterDriverData", key)['data'] + + def __setitem__(self, key, value): + # Store as REG_BINARY for now + self.hnd.setprinterdataex({"key": "PrinterDriverData", "value": key, "type": 3, + "data": value}) + -- cgit From e7561581ffe1c2df591b28820e8815d3c6dd2c42 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Sun, 8 Sep 2002 23:57:40 +0000 Subject: Update patch. (This used to be commit 31feae9e8f0c9831284cfa85f9b771113549ed2f) --- source3/python/samba-head.patch | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'source3/python') diff --git a/source3/python/samba-head.patch b/source3/python/samba-head.patch index ced7da551e..c48dd8a30a 100644 --- a/source3/python/samba-head.patch +++ b/source3/python/samba-head.patch @@ -1,11 +1,11 @@ Index: Makefile.in =================================================================== RCS file: /data/cvs/samba/source/Makefile.in,v -retrieving revision 1.502 -diff -u -r1.502 Makefile.in ---- Makefile.in 2002/08/02 07:20:56 1.502 -+++ Makefile.in 2002/08/06 00:51:48 -@@ -839,6 +839,45 @@ +retrieving revision 1.530 +diff -u -r1.530 Makefile.in +--- Makefile.in 8 Sep 2002 14:58:22 -0000 1.530 ++++ Makefile.in 8 Sep 2002 23:56:36 -0000 +@@ -846,6 +846,45 @@ -$(INSTALLCMD) -d ${prefix}/include -$(INSTALLCMD) include/libsmbclient.h ${prefix}/include @@ -54,16 +54,16 @@ diff -u -r1.502 Makefile.in Index: configure.in =================================================================== RCS file: /data/cvs/samba/source/configure.in,v -retrieving revision 1.326 -diff -u -r1.326 configure.in ---- configure.in 2002/07/30 09:59:52 1.326 -+++ configure.in 2002/08/06 00:51:51 -@@ -2797,7 +2797,7 @@ - builddir=`pwd` - AC_SUBST(builddir) - --AC_OUTPUT(include/stamp-h Makefile script/findsmb ../examples/VFS/Makefile ../examples/VFS/block/Makefile) -+AC_OUTPUT(include/stamp-h Makefile script/findsmb ../examples/VFS/Makefile ../examples/VFS/block/Makefile python/setup.py) +retrieving revision 1.336 +diff -u -r1.336 configure.in +--- configure.in 7 Sep 2002 04:08:02 -0000 1.336 ++++ configure.in 8 Sep 2002 23:56:37 -0000 +@@ -2828,7 +2828,7 @@ + # I added make files that are outside /source directory. + # I know this is not a good solution, will work out a better + # solution soon. --simo +-AC_OUTPUT(include/stamp-h Makefile script/findsmb ../examples/VFS/Makefile ../examples/pdb/mysql/Makefile ../examples/pdb/xml/Makefile ../examples/sam/Makefile) ++AC_OUTPUT(include/stamp-h Makefile script/findsmb ../examples/VFS/Makefile ../examples/pdb/mysql/Makefile ../examples/pdb/xml/Makefile ../examples/sam/Makefile python/setup.py) ################################################# # Print very concise instructions on building/use -- cgit From bffdffcbb10db9a510c8713158cb3e4044b23c2c Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 9 Sep 2002 01:06:20 +0000 Subject: Check no extra fields are present when parsing credentials. (This used to be commit fff081d3440373071d8859b7a7d71cf6489126a4) --- source3/python/py_common.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'source3/python') diff --git a/source3/python/py_common.c b/source3/python/py_common.c index 6247bf6371..e21858e072 100644 --- a/source3/python/py_common.c +++ b/source3/python/py_common.c @@ -144,6 +144,8 @@ BOOL py_parse_creds(PyObject *creds, char **username, char **domain, if (creds && PyDict_Size(creds) > 0) { PyObject *username_obj, *password_obj, *domain_obj; + PyObject *key, *value; + int i; /* Check for presence of required fields */ @@ -166,8 +168,6 @@ BOOL py_parse_creds(PyObject *creds, char **username, char **domain, return False; } - /* Look for any other fields */ - /* Check type of required fields */ if (!PyString_Check(username_obj)) { @@ -185,6 +185,21 @@ BOOL py_parse_creds(PyObject *creds, char **username, char **domain, return False; } + /* Look for any extra fields */ + + i = 0; + + while (PyDict_Next(creds, &i, &key, &value)) { + if (strcmp(PyString_AsString(key), "domain") != 0 && + strcmp(PyString_AsString(key), "username") != 0 && + strcmp(PyString_AsString(key), "password") != 0) { + asprintf(errstr, + "creds contain extra field '%s'", + PyString_AsString(key)); + return False; + } + } + /* Assign values */ *username = PyString_AsString(username_obj); -- cgit From 35d9e886fba9e95b7df1abc4f25b22251b95ac82 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 9 Sep 2002 01:09:23 +0000 Subject: Remove todo comment. (This used to be commit 95831c8266119284264f7f42b08fb4d8e21e9deb) --- source3/python/py_spoolss_drivers_conv.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source3/python') diff --git a/source3/python/py_spoolss_drivers_conv.c b/source3/python/py_spoolss_drivers_conv.c index 5d181f9cd9..41ff38327e 100644 --- a/source3/python/py_spoolss_drivers_conv.c +++ b/source3/python/py_spoolss_drivers_conv.c @@ -59,7 +59,6 @@ struct pyconv py_DRIVER_INFO_6[] = { { "data_file", PY_UNISTR, offsetof(DRIVER_INFO_6, datafile) }, { "config_file", PY_UNISTR, offsetof(DRIVER_INFO_6, configfile) }, { "help_file", PY_UNISTR, offsetof(DRIVER_INFO_6, helpfile) }, - /* dependentfiles */ { "monitor_name", PY_UNISTR, offsetof(DRIVER_INFO_6, monitorname) }, { "default_datatype", PY_UNISTR, offsetof(DRIVER_INFO_6, defaultdatatype) }, /* driver_date */ -- cgit From 317ce5fc06db976e6a7f96e2070e92b65be6349e Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 9 Sep 2002 04:38:12 +0000 Subject: Formatting tidyup. (This used to be commit 4132d9680a0b6ed829663399bba209a49ca41d56) --- source3/python/py_spoolss_drivers.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/python') diff --git a/source3/python/py_spoolss_drivers.c b/source3/python/py_spoolss_drivers.c index 2e8fac4a4e..0c242d9181 100644 --- a/source3/python/py_spoolss_drivers.c +++ b/source3/python/py_spoolss_drivers.c @@ -214,7 +214,7 @@ PyObject *spoolss_hnd_getprinterdriver(PyObject *self, PyObject *args, py_from_DRIVER_INFO_3(&result, ctr.info3); break; case 6: - py_from_DRIVER_INFO_6(&result, ctr.info6); + py_from_DRIVER_INFO_6(&result, ctr.info6); break; default: PyErr_SetString(spoolss_error, "unsupported info level"); -- cgit From b32f4ccf5b2cf74c98f4755856d81e217ab458ef Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 9 Sep 2002 04:42:01 +0000 Subject: Pass level keyword down to cli_spoolss_getform() (This used to be commit 69bb58b92e92113b3ce2c72a3bfa46ed3056c261) --- source3/python/py_spoolss_forms.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/python') diff --git a/source3/python/py_spoolss_forms.c b/source3/python/py_spoolss_forms.c index c216e00afe..ef9ed94533 100644 --- a/source3/python/py_spoolss_forms.c +++ b/source3/python/py_spoolss_forms.c @@ -102,7 +102,7 @@ PyObject *spoolss_hnd_getform(PyObject *self, PyObject *args, PyObject *kw) /* Call rpc function */ werror = cli_spoolss_getform(hnd->cli, hnd->mem_ctx, 0, &needed, - &hnd->pol, form_name, 1, &form); + &hnd->pol, form_name, level, &form); if (W_ERROR_V(werror) == ERRinsufficientbuffer) werror = cli_spoolss_getform( -- cgit From 8a362924714c53b5a5c02b7969a91b4240db57d2 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 9 Sep 2002 04:43:38 +0000 Subject: Fix crash bugs in getprinter info level code (yay unit tests). Let the cli_spoolss function return invalid info level error rather than checking for it ourselves. (This used to be commit fc5e186821abc429ea8314d0785b76cbe1ec5f74) --- source3/python/py_spoolss_printers.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) (limited to 'source3/python') diff --git a/source3/python/py_spoolss_printers.c b/source3/python/py_spoolss_printers.c index 2a6d056bbf..a300eada86 100644 --- a/source3/python/py_spoolss_printers.c +++ b/source3/python/py_spoolss_printers.c @@ -135,11 +135,6 @@ PyObject *spoolss_hnd_getprinter(PyObject *self, PyObject *args, PyObject *kw) if (!PyArg_ParseTupleAndKeywords(args, kw, "|i", kwlist, &level)) return NULL; - if (level < 0 || level > 3) { - PyErr_SetString(spoolss_error, "Invalid info level"); - return NULL; - } - ZERO_STRUCT(ctr); /* Call rpc function */ @@ -224,7 +219,7 @@ PyObject *spoolss_hnd_setprinter(PyObject *self, PyObject *args, PyObject *kw) case 1: ctr.printers_1 = &pinfo.printers_1; - if (!py_to_PRINTER_INFO_1(&pinfo.printers_1, info)){ + if (!py_to_PRINTER_INFO_1(ctr.printers_1, info)){ PyErr_SetString(spoolss_error, "error converting printer to info 1"); return NULL; @@ -234,7 +229,7 @@ PyObject *spoolss_hnd_setprinter(PyObject *self, PyObject *args, PyObject *kw) case 2: ctr.printers_2 = &pinfo.printers_2; - if (!py_to_PRINTER_INFO_2(&pinfo.printers_2, info, + if (!py_to_PRINTER_INFO_2(ctr.printers_2, info, hnd->mem_ctx)){ PyErr_SetString(spoolss_error, "error converting printer to info 2"); @@ -245,7 +240,7 @@ PyObject *spoolss_hnd_setprinter(PyObject *self, PyObject *args, PyObject *kw) case 3: ctr.printers_3 = &pinfo.printers_3; - if (!py_to_PRINTER_INFO_3(&pinfo.printers_3, info, + if (!py_to_PRINTER_INFO_3(ctr.printers_3, info, hnd->mem_ctx)) { PyErr_SetString(spoolss_error, "error converting to printer info 3"); -- cgit From 0b819e864a62941f53f5a30dd4060f2935d64a03 Mon Sep 17 00:00:00 2001 From: Martin Pool Date: Mon, 9 Sep 2002 05:22:13 +0000 Subject: Add little meta note (This used to be commit c651720633e3affb192eef9e676fad37a0ad4fae) --- source3/python/README | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'source3/python') diff --git a/source3/python/README b/source3/python/README index f751046376..6d42897bad 100644 --- a/source3/python/README +++ b/source3/python/README @@ -1,3 +1,9 @@ +This directory contains Python bindings to allow you to access various +aspects of Samba. At the moment their status is "experimental" and +they are not built by default. + + +---- Quick Install Guide -- Lines prepended with a $ indicate shell commands. -- cgit From f099013fcbab03ec2a6a106ac59eff4e6742b2ae Mon Sep 17 00:00:00 2001 From: Martin Pool Date: Mon, 9 Sep 2002 06:23:43 +0000 Subject: This patch has now been applied and no longer needs to exist separately (This used to be commit 5b2fa5260e22c0d8bc9fb0973a6247ad99d2ed4b) --- source3/python/samba-head.patch | 69 ----------------------------------------- 1 file changed, 69 deletions(-) delete mode 100644 source3/python/samba-head.patch (limited to 'source3/python') diff --git a/source3/python/samba-head.patch b/source3/python/samba-head.patch deleted file mode 100644 index c48dd8a30a..0000000000 --- a/source3/python/samba-head.patch +++ /dev/null @@ -1,69 +0,0 @@ -Index: Makefile.in -=================================================================== -RCS file: /data/cvs/samba/source/Makefile.in,v -retrieving revision 1.530 -diff -u -r1.530 Makefile.in ---- Makefile.in 8 Sep 2002 14:58:22 -0000 1.530 -+++ Makefile.in 8 Sep 2002 23:56:36 -0000 -@@ -846,6 +846,45 @@ - -$(INSTALLCMD) -d ${prefix}/include - -$(INSTALLCMD) include/libsmbclient.h ${prefix}/include - -+# Python extensions -+ -+PYTHON_OBJS = $(LIB_OBJ) $(LIBSMB_OBJ) $(RPC_PARSE_OBJ) $(UBIQX_OBJ) \ -+ $(PARAM_OBJ) $(LIBMSRPC_OBJ) $(PASSDB_OBJ) $(GROUPDB_OBJ) $(SECRETS_OBJ) -+ -+PY_SPOOLSS_PROTO_OBJ = python/py_spoolss.o \ -+ python/py_spoolss_printers.o python/py_spoolss_printers_conv.o\ -+ python/py_spoolss_forms.o python/py_spoolss_forms_conv.o \ -+ python/py_spoolss_ports.o python/py_spoolss_ports_conv.o \ -+ python/py_spoolss_drivers.o python/py_spoolss_drivers_conv.o \ -+ python/py_spoolss_jobs.o python/py_spoolss_jobs_conv.o \ -+ python/py_spoolss_printerdata.o -+ -+PY_LSA_PROTO_OBJ = python/py_lsa.o -+ -+PY_COMMON_PROTO_OBJ = python/py_common.c python/py_ntsec.c -+ -+python_proto: python_spoolss_proto python_lsa_proto python_common_proto -+ -+python_spoolss_proto: -+ @cd $(srcdir) && $(SHELL) script/mkproto.sh $(AWK) \ -+ -h _PY_SPOOLSS_PROTO_H python/py_spoolss_proto.h \ -+ $(PY_SPOOLSS_PROTO_OBJ) -+ -+python_lsa_proto: -+ @cd $(srcdir) && $(SHELL) script/mkproto.sh $(AWK) \ -+ -h _PY_LSA_PROTO_H python/py_lsa_proto.h \ -+ $(PY_LSA_PROTO_OBJ) -+ -+python_common_proto: -+ @cd $(srcdir) && $(SHELL) script/mkproto.sh $(AWK) \ -+ -h _PY_COMMON_PROTO_H python/py_common_proto.h \ -+ $(PY_COMMON_PROTO_OBJ) -+ -+python_ext: $(PYTHON_OBJS) -+ @echo python python/setup.py build -+ @PYTHON_OBJS="$(PYTHON_OBJS)" PYTHON_CFLAGS="$(CFLAGS) $(CPPFLAGS)" \ -+ python python/setup.py build -+ - # revert to the previously installed version - revert: - @$(SHELL) $(srcdir)/script/revert.sh $(SBINDIR) $(SPROGS) -Index: configure.in -=================================================================== -RCS file: /data/cvs/samba/source/configure.in,v -retrieving revision 1.336 -diff -u -r1.336 configure.in ---- configure.in 7 Sep 2002 04:08:02 -0000 1.336 -+++ configure.in 8 Sep 2002 23:56:37 -0000 -@@ -2828,7 +2828,7 @@ - # I added make files that are outside /source directory. - # I know this is not a good solution, will work out a better - # solution soon. --simo --AC_OUTPUT(include/stamp-h Makefile script/findsmb ../examples/VFS/Makefile ../examples/pdb/mysql/Makefile ../examples/pdb/xml/Makefile ../examples/sam/Makefile) -+AC_OUTPUT(include/stamp-h Makefile script/findsmb ../examples/VFS/Makefile ../examples/pdb/mysql/Makefile ../examples/pdb/xml/Makefile ../examples/sam/Makefile python/setup.py) - - ################################################# - # Print very concise instructions on building/use -- cgit From 3245349610a999a2eb0b4e388ad16775d7b54e83 Mon Sep 17 00:00:00 2001 From: Martin Pool Date: Mon, 9 Sep 2002 06:26:41 +0000 Subject: Update documentation for newly merged modules (This used to be commit a0e58fd2cef5891e874a08f71d5d7a3f10ec6454) --- source3/python/README | 44 +++++++++----------------------------------- 1 file changed, 9 insertions(+), 35 deletions(-) (limited to 'source3/python') diff --git a/source3/python/README b/source3/python/README index 6d42897bad..04f794215a 100644 --- a/source3/python/README +++ b/source3/python/README @@ -2,44 +2,18 @@ This directory contains Python bindings to allow you to access various aspects of Samba. At the moment their status is "experimental" and they are not built by default. +In order to be able to compile samba-python you need to have python +and the python-dev packages installed. ----- -Quick Install Guide --- -Lines prepended with a $ indicate shell commands. +Python libraries are always built for a particular version of Python +(2.2, 2.1, etc), and libraries built for one version will not be seen +by another. By default Samba's libraries are built for whatever is +installed as "python" on your $PATH, but you can override this using +the --with-python option. For example -1. Requirements + $ ./configure --with-python=python2.2 -In order to be able to compile samba-python you need to have -python and the python-dev packages installed. - -2. Checking out the CVS HEAD branch of Samba and Samba-Python - -In your shell, type: - -$ cvs -d :pserver:cvs@pserver.samba.org:/cvsroot login - -When asked for a password, type 'cvs'. - -Now, type: - -$ cvs -d :pserver:cvs@pserver.samba.org:/cvsroot co samba - -This might probably take a while. When everything is downloaded, -check out the samba-python tree: - -$ cvs -d :pserver:cvs@pserver.samba.org:/cvsroot co samba-python - -Now that you have both cvs modules, move the directory 'samba-python' to -inside the samba source tree, using: - -$ mv samba-python samba/source/python - -Now, go to the samba/source directory and apply the samba-head.patch patch: - -$ cd samba/source && patch -p0 < location/to/samba-python/samba-head.patch - -You can now configure samba as usual and create the python extension: +To build: $ autoconf $ ./configure -- cgit From 63f411a3f90be3d2b1c0d8cf5af394f1163319c5 Mon Sep 17 00:00:00 2001 From: Martin Pool Date: Mon, 9 Sep 2002 06:30:48 +0000 Subject: Import my code to do reasonably fast tdbpack/unpack from Python (This used to be commit 1f7ed8bb863fdacd0b9f3bc2e1e5d72ec7051feb) --- source3/python/py_tdbpack.c | 662 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 662 insertions(+) create mode 100644 source3/python/py_tdbpack.c (limited to 'source3/python') diff --git a/source3/python/py_tdbpack.c b/source3/python/py_tdbpack.c new file mode 100644 index 0000000000..e5044943be --- /dev/null +++ b/source3/python/py_tdbpack.c @@ -0,0 +1,662 @@ +/* -*- c-file-style: "python"; indent-tabs-mode: nil; -*- + + Python wrapper for Samba tdb pack/unpack functions + Copyright (C) Martin Pool 2002 + + + NOTE PYTHON STYLE GUIDE + http://www.python.org/peps/pep-0007.html + + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + + + +#include "Python.h" + +static int pytdbpack_calc_reqd_len(char *format_str, + PyObject *val_seq); + +static PyObject *pytdbpack_unpack_item(char, + char **pbuf, + int *plen); +static int +pytdbpack_calc_item_len(char format_ch, + PyObject *val_obj); + +static PyObject *pytdbpack_pack_data(const char *format_str, + PyObject *val_seq, + unsigned char *buf); + + + +static const char * pytdbpack_docstring = +"Convert between Python values and Samba binary encodings. + +This module is conceptually similar to the standard 'struct' module, but it +uses both a different binary format and a different description string. + +Samba's encoding is based on that used inside DCE-RPC and SMB: a +little-endian, unpadded, non-self-describing binary format. It is intended +that these functions be as similar as possible to the routines in Samba's +tdb/tdbutil module, with appropriate adjustments for Python datatypes. + +Python strings are used to specify the format of data to be packed or +unpacked. + +Strings in TDBs are typically stored in DOS codepages. The caller of this +module must make appropriate translations if necessary, typically to and from +Unicode objects. + +tdbpack format strings: + + 'f': NULL-terminated string in DOS codepage + + 'P': same as 'f' + + 'd': 4 byte little-endian number + + 'w': 2 byte little-endian number + + 'P': \"Pointer\" value -- in the subset of DCERPC used by Samba, this is + really just an \"exists\" or \"does not exist\" flag. The boolean + value of the Python object is used. + + 'B': 4-byte LE length, followed by that many bytes of binary data. + Corresponds to a Python byte string of the appropriate length. + + '$': Special flag indicating that the preceding format code should be + repeated while data remains. This is only supported for unpacking. + + Every code corresponds to a single Python object, except 'B' which + corresponds to two values (length and contents), and '$', which produces + however many make sense. +"; + + +static char const pytdbpack_pack_doc[] = +"pack(format, values) -> buffer +Pack Python objects into Samba binary format according to format string. + +arguments: + format -- string of tdbpack format characters + values -- sequence of value objects corresponding 1:1 to format characters + +returns: + buffer -- string containing packed data + +raises: + IndexError -- if there are not the same number of format codes as of + values + ValueError -- if any of the format characters is illegal + TypeError -- if the format is not a string, or values is not a sequence, + or any of the values is of the wrong type for the corresponding + format character +"; + + +static char const pytdbpack_unpack_doc[] = +"unpack(format, buffer) -> (values, rest) +Unpack Samba binary data according to format string. + +arguments: + format -- string of tdbpack characters + buffer -- string of packed binary data + +returns: + 2-tuple of: + values -- sequence of values corresponding 1:1 to format characters + rest -- string containing data that was not decoded, or '' if the + whole string was consumed + +raises: + IndexError -- if there is insufficient data in the buffer for the + format (or if the data is corrupt and contains a variable-length + field extending past the end) + ValueError -- if any of the format characters is illegal + +notes: + Because unconsumed data is returned, you can feed it back in to the + unpacker to extract further fields. Alternatively, if you wish to modify + some fields near the start of the data, you may be able to save time by + only unpacking and repacking the necessary part. +"; + + + +/* + Game plan is to first of all walk through the arguments and calculate the + total length that will be required. We allocate a Python string of that + size, then walk through again and fill it in. + + We just borrow references to all the passed arguments, since none of them + need to be permanently stored. We transfer ownership to the returned + object. + */ +static PyObject * +pytdbpack_pack(PyObject *self, + PyObject *args) +{ + char *format_str; + PyObject *val_seq, *fast_seq, *buf_str; + int reqd_len; + char *packed_buf; + + /* TODO: Test passing wrong types or too many arguments */ + if (!PyArg_ParseTuple(args, "sO", &format_str, &val_seq)) + return NULL; + + /* Convert into a list or tuple (if not already one), so that we can + * index more easily. */ + fast_seq = PySequence_Fast(val_seq, + __FUNCTION__ ": argument 2 must be sequence"); + if (!fast_seq) + return NULL; + + reqd_len = pytdbpack_calc_reqd_len(format_str, fast_seq); + if (reqd_len == -1) /* exception was thrown */ + return NULL; + + /* Allocate space. + + This design causes an unnecessary copying of the data when Python + constructs an object, and that might possibly be avoided by using a + Buffer object of some kind instead. I'm not doing that for now + though. */ + packed_buf = malloc(reqd_len); + if (!packed_buf) { + PyErr_Format(PyExc_MemoryError, + "%s: couldn't allocate %d bytes for packed buffer", + __FUNCTION__, reqd_len); + return NULL; + } + + if (!pytdbpack_pack_data(format_str, fast_seq, packed_buf)) { + free(packed_buf); + return NULL; + } + + buf_str = PyString_FromStringAndSize(packed_buf, reqd_len); + free(packed_buf); /* get rid of tmp buf */ + + return buf_str; +} + + + +static PyObject * +pytdbpack_unpack(PyObject *self, + PyObject *args) +{ + char *format_str, *packed_str, *ppacked; + PyObject *val_list = NULL, *ret_tuple = NULL; + PyObject *rest_string = NULL; + int format_len, packed_len; + int i; + char last_format = '#'; + + /* get arguments */ + if (!PyArg_ParseTuple(args, "ss#", &format_str, &packed_str, &packed_len)) + return NULL; + + format_len = strlen(format_str); + + /* allocate list to hold results */ + val_list = PyList_New(format_len); + if (!val_list) + goto failed; + ret_tuple = PyTuple_New(2); + if (!ret_tuple) + goto failed; + + /* For every object, unpack. */ + for (ppacked = packed_str, i = 0; i < format_len; i++) { + PyObject *val_obj; + char format; + + format = format_str[i]; + if (format == '$') { + if (i == 0) { + PyErr_Format(PyExc_ValueError, + "%s: '$' may not be first character in format", + __FUNCTION__); + goto failed; + } + else { + format = last_format; /* repeat */ + } + } + + val_obj = pytdbpack_unpack_item(format, + &ppacked, + &packed_len); + if (!val_obj) + goto failed; + + PyList_SET_ITEM(val_list, i, val_obj); + last_format = format; + } + + /* put leftovers in box for lunch tomorrow */ + rest_string = PyString_FromStringAndSize(ppacked, packed_len); + if (!rest_string) + goto failed; + + /* return (values, rest) tuple; give up references to them */ + PyTuple_SET_ITEM(ret_tuple, 0, val_list); + val_list = NULL; + PyTuple_SET_ITEM(ret_tuple, 1, rest_string); + val_list = NULL; + return ret_tuple; + + failed: + /* handle failure: deallocate anything */ + Py_XDECREF(val_list); + Py_XDECREF(ret_tuple); + Py_XDECREF(rest_string); + return NULL; +} + + +/* + Internal routine that calculates how many bytes will be required to + encode the values in the format. + + Also checks that the value list is the right size for the format list. + + Returns number of bytes (may be 0), or -1 if there's something wrong, in + which case a Python exception has been raised. + + Arguments: + + val_seq: a Fast Sequence (list or tuple), being all the values +*/ +static int +pytdbpack_calc_reqd_len(char *format_str, + PyObject *val_seq) +{ + int len = 0; + char *p; + int val_i; + int val_len; + + val_len = PySequence_Fast_GET_SIZE(val_seq); + + for (p = format_str, val_i = 0; *p; p++, val_i++) { + char ch = *p; + PyObject *val_obj; + int item_len; + + if (val_i >= val_len) { + PyErr_Format(PyExc_IndexError, + "samba.tdbpack.pack: value list is too short for format string"); + return -1; + } + + /* borrow a reference to the item */ + val_obj = PySequence_Fast_GET_ITEM(val_seq, val_i); + if (!val_obj) + return -1; + + item_len = pytdbpack_calc_item_len(ch, val_obj); + if (item_len == -1) + return -1; + else + len += item_len; + } + + if (val_i != val_len) { + PyErr_Format(PyExc_IndexError, + "%s: value list is wrong length for format string", + __FUNCTION__); + return -1; + } + + return len; +} + + +/* + 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)) { + PyErr_Format(PyExc_TypeError, + "tdbpack: format '%c' requires an Int", + ch); + return -1; + } + if (ch == 'w') + return 2; + else + return 4; + } else if (ch == 'p') { + return 4; + } + 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; + } + + if (ch == 'B') { + /* byte buffer; just use Python string's length, plus + a preceding word */ + return 4 + PyString_GET_SIZE(val_obj); + } + else { + /* one nul character */ + return 1 + PyString_GET_SIZE(val_obj); + } + } + else { + PyErr_Format(PyExc_ValueError, + __FUNCTION__ ": format character '%c' is not supported", + ch); + + return -1; + } +} + + +/* + XXX: glib and Samba have quicker macro for doing the endianness conversions, + but I don't know of one in plain libc, and it's probably not a big deal. I + realize this is kind of dumb because we'll almost always be on x86, but + being safe is important. +*/ +static void pack_int32(unsigned long val_long, unsigned char **pbuf) +{ + (*pbuf)[0] = val_long & 0xff; + (*pbuf)[1] = (val_long >> 8) & 0xff; + (*pbuf)[2] = (val_long >> 16) & 0xff; + (*pbuf)[3] = (val_long >> 24) & 0xff; + (*pbuf) += 4; +} + + +static void pack_bytes(long len, const char *from, + unsigned char **pbuf) +{ + memcpy(*pbuf, from, len); + (*pbuf) += len; +} + + +static void +unpack_err_too_short(void) +{ + PyErr_Format(PyExc_IndexError, + __FUNCTION__ ": data too short for unpack format"); +} + + +static PyObject * +unpack_int32(char **pbuf, int *plen) +{ + long v; + unsigned char *b; + + if (*plen < 4) { + unpack_err_too_short(); + return NULL; + } + + b = *pbuf; + v = b[0] | b[1]<<8 | b[2]<<16 | b[3]<<24; + + (*pbuf) += 4; + (*plen) -= 4; + + return PyInt_FromLong(v); +} + + +static PyObject *unpack_int16(char **pbuf, int *plen) +{ + long v; + unsigned char *b; + + if (*plen < 2) { + unpack_err_too_short(); + return NULL; + } + + b = *pbuf; + v = b[0] | b[1]<<8; + + (*pbuf) += 2; + (*plen) -= 2; + + return PyInt_FromLong(v); +} + + +static PyObject * +unpack_string(char **pbuf, int *plen) +{ + int len; + char *nul_ptr, *start; + + start = *pbuf; + + nul_ptr = memchr(start, '\0', *plen); + if (!nul_ptr) { + unpack_err_too_short(); + return NULL; + } + + len = nul_ptr - start; + + *pbuf += len + 1; /* skip \0 */ + *plen -= len + 1; + + return PyString_FromStringAndSize(start, len); +} + + +static PyObject * +unpack_buffer(char **pbuf, int *plen) +{ + /* first get 32-bit len */ + long slen; + unsigned char *b; + unsigned char *start; + + if (*plen < 4) { + unpack_err_too_short(); + return NULL; + } + + b = *pbuf; + slen = b[0] | b[1]<<8 | b[2]<<16 | b[3]<<24; + + if (slen < 0) { /* surely you jest */ + PyErr_Format(PyExc_ValueError, + __FUNCTION__ ": buffer seems to have negative length"); + return NULL; + } + + (*pbuf) += 4; + (*plen) -= 4; + start = *pbuf; + + if (*plen < slen) { + PyErr_Format(PyExc_IndexError, + __FUNCTION__ ": not enough data to unpack buffer: " + "need %d bytes, have %d", + (int) slen, *plen); + return NULL; + } + + (*pbuf) += slen; + (*plen) -= slen; + + return PyString_FromStringAndSize(start, slen); +} + + +/* Unpack a single field from packed data, according to format character CH. + Remaining data is at *PBUF, of *PLEN. + + *PBUF is advanced, and *PLEN reduced to reflect the amount of data that has + been consumed. + + Returns a reference to the unpacked Python object, or NULL for failure. +*/ +static PyObject *pytdbpack_unpack_item(char ch, + char **pbuf, + int *plen) +{ + if (ch == 'w') { /* 16-bit int */ + return unpack_int16(pbuf, plen); + } + else if (ch == 'd' || ch == 'p') { /* 32-bit int */ + /* pointers can just come through as integers */ + return unpack_int32(pbuf, plen); + } + else if (ch == 'f' || ch == 'P') { /* nul-term string */ + return unpack_string(pbuf, plen); + } + else if (ch == 'B') { /* length, buffer */ + return unpack_buffer(pbuf, plen); + } + else { + PyErr_Format(PyExc_ValueError, + __FUNCTION__ ": format character '%c' is not supported", + ch); + + return NULL; + } +} + + + +/* + Pack a single item VAL_OBJ, encoded using format CH, into a buffer at *PBUF, + and advance the pointer. Buffer length has been pre-calculated so we are + sure that there is enough space. + +*/ +static PyObject * +pytdbpack_pack_item(char ch, + PyObject *val_obj, + unsigned char **pbuf) +{ + if (ch == 'w') { + unsigned long val_long = PyInt_AsLong(val_obj); + (*pbuf)[0] = val_long & 0xff; + (*pbuf)[1] = (val_long >> 8) & 0xff; + (*pbuf) += 2; + } + else if (ch == 'd') { + /* 4-byte LE number */ + pack_int32(PyInt_AsLong(val_obj), pbuf); + } + else if (ch == 'p') { + /* "Pointer" value -- in the subset of DCERPC used by Samba, + this is really just an "exists" or "does not exist" + flag. */ + pack_int32(PyObject_IsTrue(val_obj), pbuf); + } + else if (ch == 'f' || ch == 'P') { + int size; + char *sval; + + size = PyString_GET_SIZE(val_obj); + sval = PyString_AS_STRING(val_obj); + pack_bytes(size+1, sval, pbuf); /* include nul */ + } + else if (ch == 'B') { + int size; + char *sval; + + size = PyString_GET_SIZE(val_obj); + pack_int32(size, pbuf); + sval = PyString_AS_STRING(val_obj); + pack_bytes(size, sval, pbuf); /* do not include nul */ + } + else { + /* this ought to be caught while calculating the length, but + just in case. */ + PyErr_Format(PyExc_ValueError, + "%s: format character '%c' is not supported", + __FUNCTION__, ch); + + return NULL; + } + + return Py_None; +} + + +/* + Pack data according to FORMAT_STR from the elements of VAL_SEQ into + PACKED_BUF. + + The string has already been checked out, so we know that VAL_SEQ is large + enough to hold the packed data, and that there are enough value items. + (However, their types may not have been thoroughly checked yet.) + + In addition, val_seq is a Python Fast sequence. + + Returns NULL for error (with exception set), or None. +*/ +PyObject * +pytdbpack_pack_data(const char *format_str, + PyObject *val_seq, + unsigned char *packed_buf) +{ + int i; + + for (i = 0; format_str[i]; i++) { + char ch = format_str[i]; + PyObject *val_obj; + + /* borrow a reference to the item */ + val_obj = PySequence_Fast_GET_ITEM(val_seq, i); + if (!val_obj) + return NULL; + + if (!pytdbpack_pack_item(ch, val_obj, &packed_buf)) + return NULL; + } + + return Py_None; +} + + + + + +static PyMethodDef pytdbpack_methods[] = { + { "pack", pytdbpack_pack, METH_VARARGS, (char *) pytdbpack_pack_doc }, + { "unpack", pytdbpack_unpack, METH_VARARGS, (char *) pytdbpack_unpack_doc }, +}; + +DL_EXPORT(void) +inittdbpack(void) +{ + Py_InitModule3("tdbpack", pytdbpack_methods, + (char *) pytdbpack_docstring); +} -- cgit From b2536ccfdde333633f1d208a6113182aee260aab Mon Sep 17 00:00:00 2001 From: Martin Pool Date: Mon, 9 Sep 2002 07:49:25 +0000 Subject: Python's setup.py does not need to be munged by configure.in -- it is sufficient to just pass the relevant variables to Python from the Makefile. Therefore, remove setup.py.in. (This used to be commit 8bebe9ee2b6bd56c297acc6b01cb0856aad1c4f3) --- source3/python/.cvsignore | 1 - source3/python/setup.py | 168 +++++++++++++++++++++++++++++++++++++++++++ source3/python/setup.py.in | 174 --------------------------------------------- 3 files changed, 168 insertions(+), 175 deletions(-) create mode 100755 source3/python/setup.py delete mode 100755 source3/python/setup.py.in (limited to 'source3/python') diff --git a/source3/python/.cvsignore b/source3/python/.cvsignore index 8ce381cd39..7e99e367f8 100644 --- a/source3/python/.cvsignore +++ b/source3/python/.cvsignore @@ -1,2 +1 @@ -setup.py *.pyc \ No newline at end of file diff --git a/source3/python/setup.py b/source3/python/setup.py new file mode 100755 index 0000000000..b39ef448c1 --- /dev/null +++ b/source3/python/setup.py @@ -0,0 +1,168 @@ +# -*- mode: python -*- +# +# Unix SMB/CIFS implementation. +# Module packaging setup for Samba python extensions +# +# Copyright (C) Tim Potter, 2002 +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# + +from distutils.core import setup +from distutils.extension import Extension + +import sys, string, os + +# The Makefile passes in environment variable $PYTHON_OBJ as being the +# list of Samba objects. This kind of goes against the distutils.cmd +# method of adding setup commands and will also confuse people who are +# familiar with the python Distutils module. + +samba_objs = os.environ.get("PYTHON_OBJS", "") + +samba_cflags = os.environ.get("PYTHON_CFLAGS", "") + +samba_srcdir = os.environ.get("SRCDIR", "") + +# These variables are filled in by configure + +samba_libs = os.environ.get("LIBS", "") + +# Convert libs and objs from space separated strings to lists of strings +# for distutils to digest. Split "-l" prefix off library list. + +obj_list = string.split(samba_objs) + +lib_list = [] + +for lib in string.split(samba_libs): + lib_list.append(string.replace(lib, "-l", "")) + +flags_list = string.split(samba_cflags) + +# Invoke distutils.setup + +setup( + + # Overview information + + name = "Samba Python Extensions", + version = "0.1", + author = "Tim Potter", + author_email = "tpot@samba.org", + license = "GPL", + + # Build info + + include_dirs = [samba_srcdir + '.', samba_srcdir + "include", + samba_srcdir + "ubiqx", samba_srcdir + "smbwrapper", + samba_srcdir + "popt", "/usr/kerberos/include", + "/usr/local/include"], + + # Module list + + ext_modules = [ + + # SPOOLSS pipe module + + Extension(name = "spoolss", + sources = [samba_srcdir + "python/py_spoolss.c", + samba_srcdir + "python/py_common.c", + samba_srcdir + "python/py_conv.c", + samba_srcdir + "python/py_ntsec.c", + samba_srcdir + "python/py_spoolss_forms.c", + samba_srcdir + "python/py_spoolss_forms_conv.c", + samba_srcdir + "python/py_spoolss_drivers.c", + samba_srcdir + "python/py_spoolss_drivers_conv.c", + samba_srcdir + "python/py_spoolss_printers.c", + samba_srcdir + "python/py_spoolss_printers_conv.c", + samba_srcdir + "python/py_spoolss_printerdata.c", + samba_srcdir + "python/py_spoolss_ports.c", + samba_srcdir + "python/py_spoolss_ports_conv.c", + samba_srcdir + "python/py_spoolss_jobs.c", + samba_srcdir + "python/py_spoolss_jobs_conv.c", + ], + libraries = lib_list, + library_dirs = ["/usr/kerberos/lib"], + extra_objects = obj_list), + + # LSA pipe module + + Extension(name = "lsa", + sources = [samba_srcdir + "python/py_lsa.c", + samba_srcdir + "python/py_common.c", + samba_srcdir + "python/py_ntsec.c"], + libraries = lib_list, + library_dirs = ["/usr/kerberos/lib"], + extra_objects = obj_list), + + # SAMR pipe module + + Extension(name = "samr", + sources = [samba_srcdir + "python/py_samr.c", + samba_srcdir + "python/py_samr_conv.c", + samba_srcdir + "python/py_common.c"], + libraries = lib_list, + library_dirs = ["/usr/kerberos/lib"], + extra_objects = obj_list), + + # winbind client module + + Extension(name = "winbind", + sources = [samba_srcdir + "python/py_winbind.c", + samba_srcdir + "python/py_common.c"], + libraries = lib_list, + library_dirs = ["/usr/kerberos/lib"], + extra_objects = obj_list, + extra_compile_args = flags_list), + + # WINREG pipe module + + Extension(name = "winreg", + sources = [samba_srcdir + "python/py_winreg.c", + samba_srcdir + "python/py_common.c"], + libraries = lib_list, + library_dirs = ["/usr/kerberos/lib"], + extra_objects = obj_list), + + # tdb module + + Extension(name = "tdb", + sources = [samba_srcdir + "python/py_tdb.c"], + libraries = lib_list, + library_dirs = ["/usr/kerberos/lib"], + extra_objects = obj_list), + + # libsmb module + + Extension(name = "smb", + sources = [samba_srcdir + "python/py_smb.c", + samba_srcdir + "python/py_common.c"], + libraries = lib_list, + library_dirs = ["/usr/kerberos/lib"], + extra_objects = obj_list), + + # Moving to merge all individual extensions in to one big + # extension. This is to avoid the fact that each extension is 3MB + # in size due to the lack of proper depedency management in Samba. + + Extension(name = "samba", + sources = [samba_srcdir + "python/py_samba.c", + samba_srcdir + "python/py_common.c"], + libraries = lib_list, + library_dirs = ["/usr/kerberos/lib"], + extra_objects = obj_list), + ], +) diff --git a/source3/python/setup.py.in b/source3/python/setup.py.in deleted file mode 100755 index 5896301245..0000000000 --- a/source3/python/setup.py.in +++ /dev/null @@ -1,174 +0,0 @@ -# -*- mode: python -*- -# -# Unix SMB/CIFS implementation. -# Module packaging setup for Samba python extensions -# -# Copyright (C) Tim Potter, 2002 -# -# This program is free software; you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation; either version 2 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -# - -from distutils.core import setup -from distutils.extension import Extension - -import sys, string, os - -# The Makefile passes in environment variable $PYTHON_OBJ as being the -# list of Samba objects. This kind of goes against the distutils.cmd -# method of adding setup commands and will also confuse people who are -# familiar with the python Distutils module. - -samba_objs = "" -if os.environ.has_key("PYTHON_OBJS"): - samba_objs = os.environ.get("PYTHON_OBJS") - -samba_cflags = "" -if os.environ.has_key("PYTHON_CFLAGS"): - samba_cflags = os.environ.get("PYTHON_CFLAGS") - -samba_srcdir = "" -if os.environ.has_key("SRCDIR"): - samba_srcdir = os.environ.get("SRCDIR") - -# These variables are filled in by configure - -samba_libs = "@LIBS@" - -# Convert libs and objs from space separated strings to lists of strings -# for distutils to digest. Split "-l" prefix off library list. - -obj_list = string.split(samba_objs) - -lib_list = [] - -for lib in string.split(samba_libs): - lib_list.append(string.replace(lib, "-l", "")) - -flags_list = string.split(samba_cflags) - -# Invoke distutils.setup - -setup( - - # Overview information - - name = "Samba Python Extensions", - version = "0.1", - author = "Tim Potter", - author_email = "tpot@samba.org", - license = "GPL", - - # Build info - - include_dirs = [samba_srcdir + '.', samba_srcdir + "include", - samba_srcdir + "ubiqx", samba_srcdir + "smbwrapper", - samba_srcdir + "popt", "/usr/kerberos/include", - "/usr/local/include"], - - # Module list - - ext_modules = [ - - # SPOOLSS pipe module - - Extension(name = "spoolss", - sources = [samba_srcdir + "python/py_spoolss.c", - samba_srcdir + "python/py_common.c", - samba_srcdir + "python/py_conv.c", - samba_srcdir + "python/py_ntsec.c", - samba_srcdir + "python/py_spoolss_forms.c", - samba_srcdir + "python/py_spoolss_forms_conv.c", - samba_srcdir + "python/py_spoolss_drivers.c", - samba_srcdir + "python/py_spoolss_drivers_conv.c", - samba_srcdir + "python/py_spoolss_printers.c", - samba_srcdir + "python/py_spoolss_printers_conv.c", - samba_srcdir + "python/py_spoolss_printerdata.c", - samba_srcdir + "python/py_spoolss_ports.c", - samba_srcdir + "python/py_spoolss_ports_conv.c", - samba_srcdir + "python/py_spoolss_jobs.c", - samba_srcdir + "python/py_spoolss_jobs_conv.c", - ], - libraries = lib_list, - library_dirs = ["/usr/kerberos/lib"], - extra_objects = obj_list), - - # LSA pipe module - - Extension(name = "lsa", - sources = [samba_srcdir + "python/py_lsa.c", - samba_srcdir + "python/py_common.c", - samba_srcdir + "python/py_ntsec.c"], - libraries = lib_list, - library_dirs = ["/usr/kerberos/lib"], - extra_objects = obj_list), - - # SAMR pipe module - - Extension(name = "samr", - sources = [samba_srcdir + "python/py_samr.c", - samba_srcdir + "python/py_samr_conv.c", - samba_srcdir + "python/py_common.c"], - libraries = lib_list, - library_dirs = ["/usr/kerberos/lib"], - extra_objects = obj_list), - - # winbind client module - - Extension(name = "winbind", - sources = [samba_srcdir + "python/py_winbind.c", - samba_srcdir + "python/py_common.c"], - libraries = lib_list, - library_dirs = ["/usr/kerberos/lib"], - extra_objects = obj_list, - extra_compile_args = flags_list), - - # WINREG pipe module - - Extension(name = "winreg", - sources = [samba_srcdir + "python/py_winreg.c", - samba_srcdir + "python/py_common.c"], - libraries = lib_list, - library_dirs = ["/usr/kerberos/lib"], - extra_objects = obj_list), - - # tdb module - - Extension(name = "tdb", - sources = [samba_srcdir + "python/py_tdb.c"], - libraries = lib_list, - library_dirs = ["/usr/kerberos/lib"], - extra_objects = obj_list), - - # libsmb module - - Extension(name = "smb", - sources = [samba_srcdir + "python/py_smb.c", - samba_srcdir + "python/py_common.c"], - libraries = lib_list, - library_dirs = ["/usr/kerberos/lib"], - extra_objects = obj_list), - - # Moving to merge all individual extensions in to one big - # extension. This is to avoid the fact that each extension is 3MB - # in size due to the lack of proper depedency management in Samba. - - Extension(name = "samba", - sources = [samba_srcdir + "python/py_samba.c", - samba_srcdir + "python/py_common.c"], - libraries = lib_list, - library_dirs = ["/usr/kerberos/lib"], - extra_objects = obj_list), - ], -) -- cgit From 462818caba9e68f092fdedb3cbcf7155161dffeb Mon Sep 17 00:00:00 2001 From: Martin Pool Date: Mon, 9 Sep 2002 08:06:17 +0000 Subject: Build py_tdbpack as well. (This used to be commit fc5e8b8f672d461809f113fe14435841608b046f) --- source3/python/setup.py | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'source3/python') diff --git a/source3/python/setup.py b/source3/python/setup.py index b39ef448c1..38bc841d98 100755 --- a/source3/python/setup.py +++ b/source3/python/setup.py @@ -164,5 +164,10 @@ setup( libraries = lib_list, library_dirs = ["/usr/kerberos/lib"], extra_objects = obj_list), + + # tdbpack/unpack extensions. Does not actually link to any Samba + # code, although it implements a compatible data format. + Extension(name = "tdbpack", + sources = [os.path.join(samba_srcdir, "python", "py_tdbpack.c")]), ], ) -- cgit From 0ad8d0c768b2c961a1b93662d7050216edc2d3c0 Mon Sep 17 00:00:00 2001 From: Martin Pool Date: Mon, 9 Sep 2002 08:34:35 +0000 Subject: Put all Python modules into the 'samba' subpackage. Now you need to write import samba.tdbutil samba.tdbutil.pack('f', ['hello']) You need 'cvs update -d' to get the new subdirectory for this to build properly. (This used to be commit 0d3276355e0511d6aff110a3943199629b3c00fd) --- source3/python/samba/__init__.py | 7 +++++++ source3/python/setup.py | 10 +++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 source3/python/samba/__init__.py (limited to 'source3/python') diff --git a/source3/python/samba/__init__.py b/source3/python/samba/__init__.py new file mode 100644 index 0000000000..c818ca3e04 --- /dev/null +++ b/source3/python/samba/__init__.py @@ -0,0 +1,7 @@ +"""samba + +Various Python modules for interfacing to Samba. + +Try using help() to examine their documentation. +""" + diff --git a/source3/python/setup.py b/source3/python/setup.py index 38bc841d98..a5d7879371 100755 --- a/source3/python/setup.py +++ b/source3/python/setup.py @@ -4,6 +4,7 @@ # Module packaging setup for Samba python extensions # # Copyright (C) Tim Potter, 2002 +# Copyright (C) Martin Pool, 2002 # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -70,9 +71,16 @@ setup( samba_srcdir + "ubiqx", samba_srcdir + "smbwrapper", samba_srcdir + "popt", "/usr/kerberos/include", "/usr/local/include"], + + # Get the "samba" directory of Python source. At the moment this + # just contains the __init__ file that makes it work as a + # subpackage. This is needed even though everything else is an + # extension module. + package_dir = {"samba": os.path.join(samba_srcdir, "python", "samba")}, + packages = ["samba"], # Module list - + ext_package = "samba", ext_modules = [ # SPOOLSS pipe module -- cgit From d4b6d5db9145ae62c99e2432cf524f83fdc72277 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Tue, 10 Sep 2002 06:41:27 +0000 Subject: Updated examples for new top level module layout. Fixed some bugs also. (This used to be commit 3e19e3afdb6fd1f63dee9ca52a5d33090670832e) --- source3/python/examples/spoolss/changeid.py | 7 ++++++- source3/python/examples/spoolss/enumprinters.py | 23 +++++++++++++++++------ source3/python/examples/spoolss/psec.py | 3 ++- 3 files changed, 25 insertions(+), 8 deletions(-) (limited to 'source3/python') diff --git a/source3/python/examples/spoolss/changeid.py b/source3/python/examples/spoolss/changeid.py index b2345094ed..85fe0efe8a 100755 --- a/source3/python/examples/spoolss/changeid.py +++ b/source3/python/examples/spoolss/changeid.py @@ -2,8 +2,13 @@ # # Display the changeid for a list of printers given on the command line # +# Sample usage: +# +# changeid.py '\\win2kdc1\magpie' +# -import sys, spoolss +import sys +from samba import spoolss if len(sys.argv) == 1: print "Usage: changeid.py " diff --git a/source3/python/examples/spoolss/enumprinters.py b/source3/python/examples/spoolss/enumprinters.py index bf08b95bb9..478c46bc24 100755 --- a/source3/python/examples/spoolss/enumprinters.py +++ b/source3/python/examples/spoolss/enumprinters.py @@ -1,20 +1,28 @@ #!/usr/bin/env python # -# Display information on all printers on a print server +# Display information on all printers on a print server. Defaults to +# printer info level 1. +# +# Example: enumprinters.py win2kdc1 # -import sys, spoolss +import sys +from samba import spoolss -if len(sys.argv) != 2: - print "Usage: changeid.py " +if len(sys.argv) < 2 or len(sys.argv) > 3: + print "Usage: enumprinters.py [infolevel]" sys.exit(1) printserver = sys.argv[1] +level = 1 +if len(sys.argv) == 3: + level = int(sys.argv[2]) + # Get list of printers try: - printer_list = spoolss.enumprinters(printserver) + printer_list = spoolss.enumprinters("\\\\%s" % printserver) except: print "error enumerating printers on %s" % printserver sys.exit(1) @@ -22,4 +30,7 @@ except: # Display basic info for printer in printer_list: - print "%s: %s" % (printer["printer_name"], printer["comment"]) + h = spoolss.openprinter("\\\\%s\\%s" % (printserver, printer)) + info = h.getprinter(level = level) + print "Printer info %d for %s: %s" % (level, printer, info) + print diff --git a/source3/python/examples/spoolss/psec.py b/source3/python/examples/spoolss/psec.py index f3fdb7bccd..498a0ef174 100755 --- a/source3/python/examples/spoolss/psec.py +++ b/source3/python/examples/spoolss/psec.py @@ -3,7 +3,8 @@ # Get or set the security descriptor on a printer # -import sys, spoolss, re, string +import sys, re, string +from samba import spoolss if len(sys.argv) != 3: print "Usage: psec.py getsec|setsec printername" -- cgit From 31737ace97c3b614adb66a228157e20a43e31054 Mon Sep 17 00:00:00 2001 From: Martin Pool Date: Tue, 10 Sep 2002 08:36:55 +0000 Subject: Check in examples for tdb packer (This used to be commit e8f9fbd32b73f60db3683d23a979dc09e7204258) --- source3/python/examples/tdbpack/tdbtimetrial.py | 12 ++ source3/python/examples/tdbpack/test_tdbpack.py | 195 ++++++++++++++++++++++++ 2 files changed, 207 insertions(+) create mode 100755 source3/python/examples/tdbpack/tdbtimetrial.py create mode 100755 source3/python/examples/tdbpack/test_tdbpack.py (limited to 'source3/python') diff --git a/source3/python/examples/tdbpack/tdbtimetrial.py b/source3/python/examples/tdbpack/tdbtimetrial.py new file mode 100755 index 0000000000..be6404899d --- /dev/null +++ b/source3/python/examples/tdbpack/tdbtimetrial.py @@ -0,0 +1,12 @@ +#! /usr/bin/python2.2 + +def run_trial(): + # import tdbutil + from samba.tdbpack import pack + + for i in xrange(500000): + pack("ddffd", (10, 2, "mbp", "martin", 0)) + #s = "\n\0\0\0" + "\x02\0\0\0" + "mbp\0" + "martin\0" + "\0\0\0\0" + +if __name__ == '__main__': + run_trial() diff --git a/source3/python/examples/tdbpack/test_tdbpack.py b/source3/python/examples/tdbpack/test_tdbpack.py new file mode 100755 index 0000000000..36fed881e3 --- /dev/null +++ b/source3/python/examples/tdbpack/test_tdbpack.py @@ -0,0 +1,195 @@ +#! /usr/bin/env python2.2 + +__doc__ = """test case for samba.tdbkpack functions + +tdbpack provides a means of pickling values into binary formats +compatible with that used by the samba tdbpack()/tdbunpack() +functions. + +Numbers are always stored in little-endian format; strings are stored +in either DOS or Unix codepage as appropriate. + +The format for any particular element is encoded as a short ASCII +string, with one character per field.""" + +# Copyright (C) 2002 Hewlett-Packard. + +__author__ = 'Martin Pool ' + +import unittest +# import tdbutil +import samba.tdbpack + +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'), + ('www', [42, 2, 69], '\x2a\0\x02\0\x45\0'), + ('wd', [42, 256], '\x2a\0\0\x01\0\0'), + ('w', [0], '\0\0'), + ('w', [255], '\xff\0'), + ('w', [256], '\0\x01'), + ('w', [0xdead], '\xad\xde'), + ('w', [0xffff], '\xff\xff'), + ('p', [0], '\0\0\0\0'), + ('p', [1], '\x01\0\0\0'), + ('d', [0x01020304], '\x04\x03\x02\x01'), + ('d', [0x7fffffff], '\xff\xff\xff\x7f'), + ('d', [0x80000000], '\x00\x00\x00\x80'), + ('d', [-1], '\xff\xff\xff\xff'), + ('d', [-255], '\x01\xff\xff\xff'), + ('d', [-256], '\x00\xff\xff\xff'), + ('ddd', [1, 10, 50], '\x01\0\0\0\x0a\0\0\0\x32\0\0\0'), + ('ff', ['hello', 'world'], 'hello\0world\0'), + ('fP', ['hello', 'world'], 'hello\0world\0'), + ('PP', ['hello', 'world'], 'hello\0world\0'), + ('B', [''], '\0\0\0\0'), + ('B', ['hello'], '\x05\0\0\0hello'), + ('BB', ['hello\0world', 'now'], + '\x0b\0\0\0hello\0world\x03\0\0\0now'), + ('pd', [1, 10], '\x01\0\0\0\x0a\0\0\0'), + ('BBB', ['hello', '', 'world'], + '\x05\0\0\0hello\0\0\0\0\x05\0\0\0world'), + + # strings are sequences in Python, there's no getting away + # from it + ('ffff', 'evil', 'e\0v\0i\0l\0'), + ('BBBB', 'evil', + '\x01\0\0\0e' + '\x01\0\0\0v' + '\x01\0\0\0i' + '\x01\0\0\0l'), + + ('', [], ''), + + # exercise some long strings + ('PP', ['hello' * 255, 'world' * 255], + 'hello' * 255 + '\0' + 'world' * 255 + '\0'), + ('PP', ['hello' * 40000, 'world' * 50000], + 'hello' * 40000 + '\0' + 'world' * 50000 + '\0'), + ('B', ['hello' * 51], '\xff\0\0\0' + 'hello' * 51), + ('BB', ['hello' * 40000, 'world' * 50000], + '\x40\x0d\x03\0' + 'hello' * 40000 + '\x90\xd0\x03\x00' + 'world' * 50000), + ] + + 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)) + + + def test_pack(self): + """Cookbook of expected pack values + + These can't be used for the symmetric test because the unpacked value is + not "canonical". + """ + cases = [('w', (42,), '\x2a\0'), + ('p', [None], '\0\0\0\0'), + ('p', ['true'], '\x01\0\0\0'), + + ('w', {1: 'fruit'}, '\x01\0'), + # passing a dictionary is dodgy, but it gets coerced to keys + # as if you called list() + ] + + 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)) + + + def test_unpack(self): + """Cookbook of tricky unpack tests""" + cases = [ + ] + 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): + """Expected errors for incorrect packing""" + cases = [('w', [], IndexError), + ('w', (), IndexError), + ('w', {}, IndexError), + ('ww', [2], IndexError), + ('w', 2, TypeError), + ('', [1, 2, 3], IndexError), + ('w', None, TypeError), + ('wwwwwwwwwwww', [], IndexError), + ('w', [2, 3], IndexError), + ('w', [0x60A15EC5L], TypeError), + ('w', [None], TypeError), + ('w', xrange(10000), IndexError), + ('d', [], IndexError), + ('d', [0L], TypeError), + ('p', [], IndexError), + ('f', [2], TypeError), + ('P', [None], TypeError), + ('P', (), IndexError), + ('f', [packer], TypeError), + ('fw', ['hello'], IndexError), + ('f', [u'hello'], TypeError), + ('B', [2], TypeError), + (None, [2, 3, 4], TypeError), + (ord('f'), [20], TypeError), + (['w', 'w'], [2, 2], TypeError), + ('Q', [2], ValueError), + ('fQ', ['2', 3], ValueError), + ('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) + + + def test_unpack_failures(self): + """Expected errors for incorrect unpacking""" + cases = [('$', '', ValueError), + ('Q', '', ValueError), + ('Q$', '', ValueError), + ('f', '', IndexError), + ('d', '', IndexError), + ('d', '2', IndexError), + ('d', '22', IndexError), + ('d', '222', IndexError), + ('w', '', IndexError), + ('w', '2', IndexError), + ('f', 'hello', IndexError), + ('f', '', IndexError), + ('p', '\x01\0', IndexError), + ('B', '\xff\0\0\0hello', IndexError), + ('B', '\xff\0', IndexError), + ('B', '\x01\0\0\0', IndexError), + ('B', '\x05\0\0\0hell', IndexError), + ('B', '\xff\xff\xff\xff', ValueError), + ('B', 'foobar', IndexError), + ('BB', '\x01\0\0\0a\x01', IndexError), + ] + + for format, values, throwable_class in cases: + def do_unpack(): + unpacker(format, values) + self.assertRaises(throwable_class, do_unpack) + + + +if __name__ == '__main__': + unittest.main() + -- cgit From 324846f08d51ff33b9fae96992e9888392bd2111 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Wed, 11 Sep 2002 01:20:49 +0000 Subject: Change 'import spoolss' to 'from samba import spoolss'. (This used to be commit 06f6e7110029d5d60c4f34123f470bfb4c96364a) --- source3/python/gtdbtool | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/python') diff --git a/source3/python/gtdbtool b/source3/python/gtdbtool index d5c76fa318..129f4fe0e2 100755 --- a/source3/python/gtdbtool +++ b/source3/python/gtdbtool @@ -3,7 +3,7 @@ import sys from gtkdictbrowser import GtkDictBrowser import gtk -import tdb +from samba import tdb import string # Open handle on tdb -- cgit From 1d3bef09b664a992ffbe2307045757115f3d00c9 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Wed, 11 Sep 2002 02:26:47 +0000 Subject: Ignore *.pyc (This used to be commit 9d639cd4156e6b8fcb84e20e0b8adaa3fc5dc5ba) --- source3/python/samba/.cvsignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 source3/python/samba/.cvsignore (limited to 'source3/python') diff --git a/source3/python/samba/.cvsignore b/source3/python/samba/.cvsignore new file mode 100644 index 0000000000..0d20b6487c --- /dev/null +++ b/source3/python/samba/.cvsignore @@ -0,0 +1 @@ +*.pyc -- cgit From 18e72f5facd1f87193b5295cc4d081d1d04374f5 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Wed, 11 Sep 2002 04:50:18 +0000 Subject: Fix imports for printerdata browser. (This used to be commit d36fd6651726ffee059f4b39211da66b5b6d7ec1) --- source3/python/gprinterdata | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/python') diff --git a/source3/python/gprinterdata b/source3/python/gprinterdata index 59c5f3c315..cd062076c0 100755 --- a/source3/python/gprinterdata +++ b/source3/python/gprinterdata @@ -3,7 +3,7 @@ import sys from gtkdictbrowser import GtkDictBrowser, hex_string import gtk -import spoolss +from samba import spoolss import string import printerdata -- cgit From 3600395b373acb48379d8500eaf2aaa11805ab08 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Wed, 11 Sep 2002 04:53:16 +0000 Subject: Fix some dodgy stuff that accidentally was committed. (This used to be commit d6d0f121d95b79d4acc68354b35fb0fb3e42e1c0) --- source3/python/py_samba.c | 8 -------- 1 file changed, 8 deletions(-) (limited to 'source3/python') diff --git a/source3/python/py_samba.c b/source3/python/py_samba.c index 7c94569787..c0ade12f65 100644 --- a/source3/python/py_samba.c +++ b/source3/python/py_samba.c @@ -50,14 +50,6 @@ void initsamba(void) module = Py_InitModule("samba", samba_methods); dict = PyModule_GetDict(module); - new_module = PyModule_N("cheepy"); - - - - PyDict_SetItemString(dict, "cheepy", new_module); - - - /* Do samba initialisation */ py_samba_init(); -- cgit From 735eb8fdd26f23e585f575d3a67787e33117db5a Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Wed, 11 Sep 2002 04:54:20 +0000 Subject: Added char *, uid_t and gid_t types to generic conversion routines. (This used to be commit a938863914cbfec247586c92fd06203fec7febde) --- source3/python/py_conv.c | 25 +++++++++++++++++++++++++ source3/python/py_conv.h | 2 +- 2 files changed, 26 insertions(+), 1 deletion(-) (limited to 'source3/python') diff --git a/source3/python/py_conv.c b/source3/python/py_conv.c index 39b20ace86..20302c83e8 100644 --- a/source3/python/py_conv.c +++ b/source3/python/py_conv.c @@ -68,7 +68,32 @@ PyObject *from_struct(void *s, struct pyconv *conv) break; } + case PY_STRING: { + char *str = (char *)s + conv[i].offset; + + item = PyString_FromString(str); + PyDict_SetItemString(obj, conv[i].name, item); + + break; + } + case PY_UID: { + uid_t *uid = (uid_t *)((char *)s + conv[i].offset); + + item = PyInt_FromLong(*uid); + PyDict_SetItemString(obj, conv[i].name, item); + + break; + } + case PY_GID: { + gid_t *gid = (gid_t *)((char *)s + conv[i].offset); + + item = PyInt_FromLong(*gid); + PyDict_SetItemString(obj, conv[i].name, item); + + break; + } default: + break; } } diff --git a/source3/python/py_conv.h b/source3/python/py_conv.h index ed06b9a852..24f5a66287 100644 --- a/source3/python/py_conv.h +++ b/source3/python/py_conv.h @@ -21,7 +21,7 @@ #ifndef _PY_CONV_H #define _PY_CONV_H -enum pyconv_types { PY_UNISTR, PY_UINT32, PY_UINT16 }; +enum pyconv_types { PY_UNISTR, PY_UINT32, PY_UINT16, PY_STRING, PY_UID, PY_GID }; struct pyconv { char *name; /* Name of member */ -- cgit From b3bcdccb1c3670495248469170b7b86c16312f99 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Wed, 11 Sep 2002 04:55:45 +0000 Subject: Implemented getpw{nam,uid} functions. (This used to be commit 19adbf1faed3d076207ec55e398f15f87d48c9f7) --- source3/python/py_winbind.c | 65 ++++++++++++++++++++++++++++++++++++++++ source3/python/py_winbind_conv.c | 42 ++++++++++++++++++++++++++ source3/python/setup.py | 2 ++ 3 files changed, 109 insertions(+) create mode 100644 source3/python/py_winbind_conv.c (limited to 'source3/python') diff --git a/source3/python/py_winbind.c b/source3/python/py_winbind.c index 49c7f8e924..ef6bc06233 100644 --- a/source3/python/py_winbind.c +++ b/source3/python/py_winbind.c @@ -445,12 +445,77 @@ static PyObject *py_auth_crap(PyObject *self, PyObject *args) return PyInt_FromLong(response.data.auth.nt_status); } +/* Get user info from name */ + +static PyObject *py_getpwnam(PyObject *self, PyObject *args) +{ + struct winbindd_request request; + struct winbindd_response response; + char *username; + PyObject *result; + + if (!PyArg_ParseTuple(args, "s", &username)) + return NULL; + + ZERO_STRUCT(request); + ZERO_STRUCT(response); + + fstrcpy(request.data.username, username); + + if (winbindd_request(WINBINDD_GETPWNAM, &request, &response) + != NSS_STATUS_SUCCESS) { + PyErr_SetString(winbind_error, "lookup failed"); + return NULL; + } + + if (!py_from_winbind_passwd(&result, &response)) { + result = Py_None; + Py_INCREF(result); + } + + return result; +} + +/* Get user info from uid */ + +static PyObject *py_getpwuid(PyObject *self, PyObject *args) +{ + struct winbindd_request request; + struct winbindd_response response; + uid_t uid; + PyObject *result; + + if (!PyArg_ParseTuple(args, "i", &uid)) + return NULL; + + ZERO_STRUCT(request); + ZERO_STRUCT(response); + + request.data.uid = uid; + + if (winbindd_request(WINBINDD_GETPWUID, &request, &response) + != NSS_STATUS_SUCCESS) { + PyErr_SetString(winbind_error, "lookup failed"); + return NULL; + } + + if (!py_from_winbind_passwd(&result, &response)) { + result = Py_None; + Py_INCREF(result); + } + + return result; +} + /* * Method dispatch table */ static PyMethodDef winbind_methods[] = { + { "getpwnam", py_getpwnam, METH_VARARGS, "getpwnam(3)" }, + { "getpwuid", py_getpwuid, METH_VARARGS, "getpwuid(3)" }, + /* Name <-> SID conversion */ { "name_to_sid", py_name_to_sid, METH_VARARGS, diff --git a/source3/python/py_winbind_conv.c b/source3/python/py_winbind_conv.c new file mode 100644 index 0000000000..c3e416171e --- /dev/null +++ b/source3/python/py_winbind_conv.c @@ -0,0 +1,42 @@ +/* + Python wrappers for DCERPC/SMB client routines. + + Copyright (C) Tim Potter, 2002 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" +#include "Python.h" +#include "python/py_conv.h" + +/* Convert a struct passwd to a dictionary */ + +static struct pyconv py_passwd[] = { + { "pw_name", PY_STRING, offsetof(struct winbindd_response, data.pw.pw_name) }, + { "pw_passwd", PY_STRING, offsetof(struct winbindd_response, data.pw.pw_passwd) }, + { "pw_uid", PY_UID, offsetof(struct winbindd_response, data.pw.pw_uid) }, + { "pw_guid", PY_GID, offsetof(struct winbindd_response, data.pw.pw_gid) }, + { "pw_gecos", PY_STRING, offsetof(struct winbindd_response, data.pw.pw_gecos) }, + { "pw_dir", PY_STRING, offsetof(struct winbindd_response, data.pw.pw_dir) }, + { "pw_shell", PY_STRING, offsetof(struct winbindd_response, data.pw.pw_shell) }, + { NULL} +}; + +BOOL py_from_winbind_passwd(PyObject **dict, struct winbindd_response *response) +{ + *dict = from_struct(response, py_passwd); + return True; +} diff --git a/source3/python/setup.py b/source3/python/setup.py index a5d7879371..d3c420834a 100755 --- a/source3/python/setup.py +++ b/source3/python/setup.py @@ -130,6 +130,8 @@ setup( Extension(name = "winbind", sources = [samba_srcdir + "python/py_winbind.c", + samba_srcdir + "python/py_winbind_conv.c", + samba_srcdir + "python/py_conv.c", samba_srcdir + "python/py_common.c"], libraries = lib_list, library_dirs = ["/usr/kerberos/lib"], -- cgit From e7ff6ab84058a7823b047b99bafd87274d72fa3b Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Wed, 18 Sep 2002 08:16:22 +0000 Subject: Display the repr() of non-string dictionary values. (This used to be commit 3c6975c711d87755f0532147f9aaecb224159f43) --- source3/python/gtkdictbrowser.py | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) (limited to 'source3/python') diff --git a/source3/python/gtkdictbrowser.py b/source3/python/gtkdictbrowser.py index 6d6cdb3c8a..dd8bed8f47 100755 --- a/source3/python/gtkdictbrowser.py +++ b/source3/python/gtkdictbrowser.py @@ -116,16 +116,27 @@ class GtkDictBrowser: # Set the text to appear in the right hand side of the user interface - def set_value_text(self, text): - self.text.delete_text(0, self.text.get_length()) + def set_value_text(self, item): - # The text widget has trouble inserting text containing NULL - # characters. + # Clear old old value in text window - text = string.replace(text, "\x00", ".") + self.text.delete_text(0, self.text.get_length()) + + if type(item) == str: - self.text.insert(self.font, None, None, text) + # The text widget has trouble inserting text containing NULL + # characters. + + item = string.replace(item, "\x00", ".") + + self.text.insert(self.font, None, None, item) + else: + + # A non-text item + + self.text.insert(self.font, None, None, repr(item)) + # This function is called when a key is selected in the left hand side # of the user interface. @@ -246,7 +257,7 @@ def hex_string(data): if __name__ == "__main__": - dict = {"chicken": "ham", "spam": "fun"} + dict = {"chicken": "ham", "spam": "fun", "subdict": {"a": "b", "c": "d"}} db = GtkDictBrowser(dict) -- cgit From 15fdb18dd7f7169be9f22b639a6e1e9bcab833b9 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Thu, 19 Sep 2002 00:14:01 +0000 Subject: Implement printerdata_ex as Python dictionary. Read only at the moment. (This used to be commit 739ea89eb3ab49e5dccddfa767812811b413e67d) --- source3/python/printerdata.py | 43 +++++++++++++++++++++++++++---------- source3/python/samba/printerdata.py | 43 +++++++++++++++++++++++++++---------- 2 files changed, 64 insertions(+), 22 deletions(-) (limited to 'source3/python') diff --git a/source3/python/printerdata.py b/source3/python/printerdata.py index 3384de4f30..33251f6a00 100644 --- a/source3/python/printerdata.py +++ b/source3/python/printerdata.py @@ -1,10 +1,18 @@ +#!/usr/bin/env python + # # A python module that maps printerdata to a dictionary. We define # two classes. The printerdata class maps to Get/Set/Enum/DeletePrinterData # and the printerdata_ex class maps to Get/Set/Enum/DeletePrinterDataEx # -import spoolss +# +# TODO: +# +# - Implement __delitem__ +# + +from samba import spoolss class printerdata: def __init__(self, host, creds = {}): @@ -22,17 +30,30 @@ class printerdata: "data": value}) class printerdata_ex: - def __init__(self, host, creds = {}): - self.hnd = spoolss.openprinter(host, creds = creds) + def __init__(self, host): + self.host = host + self.top_level_keys = ["PrinterDriverData", "DsSpooler", "DsDriver", + "DsUser"] def keys(self): - return self.hnd.enumprinterdataex("PrinterDriverData").keys() + return self.top_level_keys - def __getitem__(self, key): - return self.hnd.getprinterdataex("PrinterDriverData", key)['data'] + def has_key(self, key): + for k in self.top_level_keys: + if k == key: + return 1 + return 0 - def __setitem__(self, key, value): - # Store as REG_BINARY for now - self.hnd.setprinterdataex({"key": "PrinterDriverData", "value": key, "type": 3, - "data": value}) - + class printerdata_ex_subkey: + def __init__(self, host, key): + self.hnd = spoolss.openprinter(host) + self.key = key + + def keys(self): + return self.hnd.enumprinterdataex(self.key).keys() + + def __getitem__(self, key): + return self.hnd.getprinterdataex(self.key, key)['data'] + + def __getitem__(self, key): + return self.printerdata_ex_subkey(self.host, key) diff --git a/source3/python/samba/printerdata.py b/source3/python/samba/printerdata.py index 3384de4f30..33251f6a00 100644 --- a/source3/python/samba/printerdata.py +++ b/source3/python/samba/printerdata.py @@ -1,10 +1,18 @@ +#!/usr/bin/env python + # # A python module that maps printerdata to a dictionary. We define # two classes. The printerdata class maps to Get/Set/Enum/DeletePrinterData # and the printerdata_ex class maps to Get/Set/Enum/DeletePrinterDataEx # -import spoolss +# +# TODO: +# +# - Implement __delitem__ +# + +from samba import spoolss class printerdata: def __init__(self, host, creds = {}): @@ -22,17 +30,30 @@ class printerdata: "data": value}) class printerdata_ex: - def __init__(self, host, creds = {}): - self.hnd = spoolss.openprinter(host, creds = creds) + def __init__(self, host): + self.host = host + self.top_level_keys = ["PrinterDriverData", "DsSpooler", "DsDriver", + "DsUser"] def keys(self): - return self.hnd.enumprinterdataex("PrinterDriverData").keys() + return self.top_level_keys - def __getitem__(self, key): - return self.hnd.getprinterdataex("PrinterDriverData", key)['data'] + def has_key(self, key): + for k in self.top_level_keys: + if k == key: + return 1 + return 0 - def __setitem__(self, key, value): - # Store as REG_BINARY for now - self.hnd.setprinterdataex({"key": "PrinterDriverData", "value": key, "type": 3, - "data": value}) - + class printerdata_ex_subkey: + def __init__(self, host, key): + self.hnd = spoolss.openprinter(host) + self.key = key + + def keys(self): + return self.hnd.enumprinterdataex(self.key).keys() + + def __getitem__(self, key): + return self.hnd.getprinterdataex(self.key, key)['data'] + + def __getitem__(self, key): + return self.printerdata_ex_subkey(self.host, key) -- cgit From d3a661453e5e16cf0bd3bdcdb9b07d9f29ae0044 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Thu, 19 Sep 2002 00:26:07 +0000 Subject: Moving to subdirectory. (This used to be commit 154c59c8f92b9f735f4e1e7c8c42692c959996f1) --- source3/python/printerdata.py | 59 ------------------------------------------- 1 file changed, 59 deletions(-) delete mode 100644 source3/python/printerdata.py (limited to 'source3/python') diff --git a/source3/python/printerdata.py b/source3/python/printerdata.py deleted file mode 100644 index 33251f6a00..0000000000 --- a/source3/python/printerdata.py +++ /dev/null @@ -1,59 +0,0 @@ -#!/usr/bin/env python - -# -# A python module that maps printerdata to a dictionary. We define -# two classes. The printerdata class maps to Get/Set/Enum/DeletePrinterData -# and the printerdata_ex class maps to Get/Set/Enum/DeletePrinterDataEx -# - -# -# TODO: -# -# - Implement __delitem__ -# - -from samba import spoolss - -class printerdata: - def __init__(self, host, creds = {}): - self.hnd = spoolss.openprinter(host, creds = creds) - - def keys(self): - return self.hnd.enumprinterdata().keys() - - def __getitem__(self, key): - return self.hnd.getprinterdata(key)['data'] - - def __setitem__(self, key, value): - # Store as REG_BINARY for now - self.hnd.setprinterdata({"key": "", "value": key, "type": 3, - "data": value}) - -class printerdata_ex: - def __init__(self, host): - self.host = host - self.top_level_keys = ["PrinterDriverData", "DsSpooler", "DsDriver", - "DsUser"] - - def keys(self): - return self.top_level_keys - - def has_key(self, key): - for k in self.top_level_keys: - if k == key: - return 1 - return 0 - - class printerdata_ex_subkey: - def __init__(self, host, key): - self.hnd = spoolss.openprinter(host) - self.key = key - - def keys(self): - return self.hnd.enumprinterdataex(self.key).keys() - - def __getitem__(self, key): - return self.hnd.getprinterdataex(self.key, key)['data'] - - def __getitem__(self, key): - return self.printerdata_ex_subkey(self.host, key) -- cgit From a39dcb606dff72c2b851e692224b8ec1140e093c Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Thu, 19 Sep 2002 05:29:14 +0000 Subject: Fixed bug in keyword args for enumprinterdataex (This used to be commit c7845b3c43f7167f2c695722bc9923ff666ade76) --- source3/python/py_spoolss_printerdata.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/python') diff --git a/source3/python/py_spoolss_printerdata.c b/source3/python/py_spoolss_printerdata.c index ffff2b3a67..bacc870d9d 100644 --- a/source3/python/py_spoolss_printerdata.c +++ b/source3/python/py_spoolss_printerdata.c @@ -321,7 +321,7 @@ PyObject *spoolss_hnd_setprinterdataex(PyObject *self, PyObject *args, PyObject PyObject *spoolss_hnd_enumprinterdataex(PyObject *self, PyObject *args, PyObject *kw) { spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self; - static char *kwlist[] = { NULL }; + static char *kwlist[] = { "key", NULL }; uint32 needed, i; char *key; WERROR werror; -- cgit From 86c7c460ca6c099f3593a092581ee5364179e481 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Thu, 19 Sep 2002 05:39:03 +0000 Subject: Bong! The devmode could be NULL. Don't crash if this is the case. (This used to be commit 3ce8f8c50c0adcedc38bf2812b7e9fae78942458) --- source3/python/py_spoolss_printers_conv.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'source3/python') diff --git a/source3/python/py_spoolss_printers_conv.c b/source3/python/py_spoolss_printers_conv.c index 247db65b1e..760896fcde 100644 --- a/source3/python/py_spoolss_printers_conv.c +++ b/source3/python/py_spoolss_printers_conv.c @@ -227,8 +227,14 @@ BOOL py_from_PRINTER_INFO_2(PyObject **dict, PRINTER_INFO_2 *info) if (py_from_SECDESC(&obj, info->secdesc)) PyDict_SetItemString(*dict, "security_descriptor", obj); - if (py_from_DEVICEMODE(&obj, info->devmode)) - PyDict_SetItemString(*dict, "device_mode", obj); + /* Bong! The devmode could be NULL */ + + if (info->devmode) + py_from_DEVICEMODE(&obj, info->devmode); + else + obj = PyDict_New(); + + PyDict_SetItemString(*dict, "device_mode", obj); PyDict_SetItemString(*dict, "level", PyInt_FromLong(2)); -- cgit From 8eda50793ea5edaddb5224496a42f677328d4af2 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Thu, 19 Sep 2002 05:49:14 +0000 Subject: Remove hardcoded -I stuff. Hooray! (This used to be commit 105ff7c5400a6b79613b6a3b72808124b17ddc60) --- source3/python/setup.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'source3/python') diff --git a/source3/python/setup.py b/source3/python/setup.py index d3c420834a..6d03ca633a 100755 --- a/source3/python/setup.py +++ b/source3/python/setup.py @@ -65,13 +65,6 @@ setup( author_email = "tpot@samba.org", license = "GPL", - # Build info - - include_dirs = [samba_srcdir + '.', samba_srcdir + "include", - samba_srcdir + "ubiqx", samba_srcdir + "smbwrapper", - samba_srcdir + "popt", "/usr/kerberos/include", - "/usr/local/include"], - # Get the "samba" directory of Python source. At the moment this # just contains the __init__ file that makes it work as a # subpackage. This is needed even though everything else is an @@ -104,6 +97,7 @@ setup( ], libraries = lib_list, library_dirs = ["/usr/kerberos/lib"], + extra_compile_args = flags_list, extra_objects = obj_list), # LSA pipe module @@ -114,6 +108,7 @@ setup( samba_srcdir + "python/py_ntsec.c"], libraries = lib_list, library_dirs = ["/usr/kerberos/lib"], + extra_compile_args = flags_list, extra_objects = obj_list), # SAMR pipe module @@ -124,6 +119,7 @@ setup( samba_srcdir + "python/py_common.c"], libraries = lib_list, library_dirs = ["/usr/kerberos/lib"], + extra_compile_args = flags_list, extra_objects = obj_list), # winbind client module @@ -135,8 +131,8 @@ setup( samba_srcdir + "python/py_common.c"], libraries = lib_list, library_dirs = ["/usr/kerberos/lib"], - extra_objects = obj_list, - extra_compile_args = flags_list), + extra_compile_args = flags_list, + extra_objects = obj_list), # WINREG pipe module @@ -145,6 +141,7 @@ setup( samba_srcdir + "python/py_common.c"], libraries = lib_list, library_dirs = ["/usr/kerberos/lib"], + extra_compile_args = flags_list, extra_objects = obj_list), # tdb module @@ -153,6 +150,7 @@ setup( sources = [samba_srcdir + "python/py_tdb.c"], libraries = lib_list, library_dirs = ["/usr/kerberos/lib"], + extra_compile_args = flags_list, extra_objects = obj_list), # libsmb module @@ -162,6 +160,7 @@ setup( samba_srcdir + "python/py_common.c"], libraries = lib_list, library_dirs = ["/usr/kerberos/lib"], + extra_compile_args = flags_list, extra_objects = obj_list), # Moving to merge all individual extensions in to one big @@ -173,6 +172,7 @@ setup( samba_srcdir + "python/py_common.c"], libraries = lib_list, library_dirs = ["/usr/kerberos/lib"], + extra_compile_args = flags_list, extra_objects = obj_list), # tdbpack/unpack extensions. Does not actually link to any Samba -- cgit From 5b71a0055ffe619d7b2aaef453c39fcbc2b3f4e4 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Wed, 25 Sep 2002 06:25:02 +0000 Subject: The security descriptor in a PRINTER_INFO_2 could be NULL. (Bong?) (This used to be commit 7ce782c20c6b9e515a2fa831315ae14c66d322ee) --- source3/python/py_spoolss_printers_conv.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'source3/python') diff --git a/source3/python/py_spoolss_printers_conv.c b/source3/python/py_spoolss_printers_conv.c index 760896fcde..9bef118f2b 100644 --- a/source3/python/py_spoolss_printers_conv.c +++ b/source3/python/py_spoolss_printers_conv.c @@ -224,8 +224,12 @@ BOOL py_from_PRINTER_INFO_2(PyObject **dict, PRINTER_INFO_2 *info) *dict = from_struct(info, py_PRINTER_INFO_2); - if (py_from_SECDESC(&obj, info->secdesc)) - PyDict_SetItemString(*dict, "security_descriptor", obj); + /* The security descriptor could be NULL */ + + if (info->secdesc) { + if (py_from_SECDESC(&obj, info->secdesc)) + PyDict_SetItemString(*dict, "security_descriptor", obj); + } /* Bong! The devmode could be NULL */ -- cgit