summaryrefslogtreecommitdiff
path: root/source3/python
diff options
context:
space:
mode:
authorTim Potter <tpot@samba.org>2002-03-20 03:29:03 +0000
committerTim Potter <tpot@samba.org>2002-03-20 03:29:03 +0000
commitd07cc9d8a1b34429f3c96abde7449ee0b7487ac3 (patch)
treee0b6da3f20671e26c49581349b984d77b4f42a1e /source3/python
parenta1249aca906e9624edada1b4e9c654b568897dce (diff)
downloadsamba-d07cc9d8a1b34429f3c96abde7449ee0b7487ac3.tar.gz
samba-d07cc9d8a1b34429f3c96abde7449ee0b7487ac3.tar.bz2
samba-d07cc9d8a1b34429f3c96abde7449ee0b7487ac3.zip
Initial version.
(This used to be commit d35770d06f7bc396cf32337a4e1104b5fe8a3ca8)
Diffstat (limited to 'source3/python')
-rw-r--r--source3/python/py_common.c47
-rw-r--r--source3/python/py_common.h28
-rw-r--r--source3/python/py_lsa.c141
-rw-r--r--source3/python/py_spoolss.c1118
-rw-r--r--source3/python/py_spoolss.h51
-rw-r--r--source3/python/py_spoolss_forms.c283
-rw-r--r--source3/python/py_spoolss_forms.h32
-rw-r--r--source3/python/py_winbind.c34
8 files changed, 1734 insertions, 0 deletions
diff --git a/source3/python/py_common.c b/source3/python/py_common.c
new file mode 100644
index 0000000000..a24a6009d3
--- /dev/null
+++ b/source3/python/py_common.c
@@ -0,0 +1,47 @@
+/*
+ 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"
+
+/* Initialise samba client routines */
+
+static BOOL initialised;
+
+void py_samba_init(void)
+{
+ if (initialised)
+ return;
+
+ /* FIXME: logging doesn't work very well */
+
+ setup_logging("python", True);
+
+ /* Load configuration file */
+
+ if (!lp_load(dyn_CONFIGFILE, True, False, False))
+ fprintf(stderr, "Can't load %s\n", dyn_CONFIGFILE);
+
+ /* Misc other stuff */
+
+ load_interfaces();
+ DEBUGLEVEL = 10;
+
+ initialised = True;
+}
diff --git a/source3/python/py_common.h b/source3/python/py_common.h
new file mode 100644
index 0000000000..1d2d4d6cd0
--- /dev/null
+++ b/source3/python/py_common.h
@@ -0,0 +1,28 @@
+/*
+ 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.
+*/
+
+#ifndef _PY_COMMON_H
+#define _PY_COMMON_H
+
+/* Function prototypes */
+
+void py_samba_init(void);
+
+#endif /* _PY_COMMON_H */
diff --git a/source3/python/py_lsa.c b/source3/python/py_lsa.c
new file mode 100644
index 0000000000..dfb9b642ed
--- /dev/null
+++ b/source3/python/py_lsa.c
@@ -0,0 +1,141 @@
+#include "includes.h"
+#include "Python.h"
+#include "python/py_common.h"
+
+static void py_policy_hnd_dealloc(PyObject* self)
+{
+ PyObject_Del(self);
+}
+
+typedef struct {
+ PyObject_HEAD
+ struct cli_state *cli;
+ TALLOC_CTX *mem_ctx;
+ POLICY_HND pol;
+} lsa_policy_hnd_object;
+
+PyTypeObject lsa_policy_hnd_type = {
+ PyObject_HEAD_INIT(NULL)
+ 0,
+ "LSA Policy Handle",
+ sizeof(lsa_policy_hnd_object),
+ 0,
+ py_policy_hnd_dealloc, /*tp_dealloc*/
+ 0, /*tp_print*/
+ 0, /*tp_getattr*/
+ 0, /*tp_setattr*/
+ 0, /*tp_compare*/
+ 0, /*tp_repr*/
+ 0, /*tp_as_number*/
+ 0, /*tp_as_sequence*/
+ 0, /*tp_as_mapping*/
+ 0, /*tp_hash */
+};
+
+/*
+ * Exceptions raised by this module
+ */
+
+PyObject *lsa_error; /* This indicates a non-RPC related error
+ such as name lookup failure */
+
+PyObject *lsa_ntstatus; /* This exception is raised when a RPC call
+ returns a status code other than
+ NT_STATUS_OK */
+
+/*
+ * Open/close lsa handles
+ */
+
+static PyObject *lsa_openpolicy(PyObject *self, PyObject *args,
+ PyObject *kw)
+{
+ static char *kwlist[] = { "servername", "creds", "access", NULL };
+ char *server_name;
+ PyObject *creds = NULL;
+ uint32 desired_access = MAXIMUM_ALLOWED_ACCESS;
+
+ if (!PyArg_ParseTupleAndKeywords(
+ args, kw, "s|O!i", kwlist, &server_name, &PyDict_Type,
+ &creds, &desired_access)) {
+
+ goto done;
+ }
+
+ done:
+ return NULL;
+}
+
+static PyObject *lsa_close(PyObject *self, PyObject *args, PyObject *kw)
+{
+ return NULL;
+}
+
+static PyObject *lsa_lookupnames(PyObject *self, PyObject *args,
+ PyObject *kw)
+{
+ return NULL;
+}
+
+static PyObject *lsa_lookupsids(PyObject *self, PyObject *args,
+ PyObject *kw)
+{
+ return NULL;
+}
+
+/*
+ * Method dispatch table
+ */
+
+static PyMethodDef lsa_methods[] = {
+
+ /* Open/close lsa handles */
+
+ { "openpolicy", lsa_openpolicy, METH_VARARGS | METH_KEYWORDS,
+ "Open a policy handle" },
+
+ { "close", lsa_close, METH_VARARGS,
+ "Close a policy handle" },
+
+ /* Name <-> SID resolution */
+
+ { "lookupnames", lsa_lookupnames, METH_VARARGS | METH_KEYWORDS,
+ "Look up SIDS from a list of names" },
+
+ { "lookupsids", lsa_lookupsids, METH_VARARGS | METH_KEYWORDS,
+ "Look up names from a list of SIDS" },
+
+ { NULL }
+};
+
+/*
+ * Module initialisation
+*/
+
+void initlsa(void)
+{
+ PyObject *module, *dict;
+
+ /* Initialise module */
+
+ module = Py_InitModule("lsa", lsa_methods);
+ dict = PyModule_GetDict(module);
+
+ lsa_error = PyErr_NewException("lsa.error", NULL, NULL);
+ PyDict_SetItemString(dict, "error", lsa_error);
+
+ lsa_ntstatus = PyErr_NewException("lsa.ntstatus", NULL, NULL);
+ PyDict_SetItemString(dict, "ntstatus", lsa_ntstatus);
+
+ /* Initialise policy handle object */
+
+ lsa_policy_hnd_type.ob_type = &PyType_Type;
+
+ /* Initialise constants */
+
+// const_init(dict);
+
+ /* Do samba initialisation */
+
+ py_samba_init();
+}
diff --git a/source3/python/py_spoolss.c b/source3/python/py_spoolss.c
new file mode 100644
index 0000000000..37074baca1
--- /dev/null
+++ b/source3/python/py_spoolss.c
@@ -0,0 +1,1118 @@
+/*
+ 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_common.h"
+#include "python/py_spoolss.h"
+
+/* Exceptions this module can raise */
+
+PyObject *spoolss_error, *spoolss_werror;
+
+static void py_policy_hnd_dealloc(PyObject* self)
+{
+ PyObject_Del(self);
+}
+
+static PyObject *new_policy_hnd_object(struct cli_state *cli,
+ TALLOC_CTX *mem_ctx, POLICY_HND *pol)
+{
+ spoolss_policy_hnd_object *o;
+
+ o = PyObject_New(spoolss_policy_hnd_object, &spoolss_policy_hnd_type);
+
+ o->cli = cli;
+ o->mem_ctx = mem_ctx;
+ memcpy(&o->pol, pol, sizeof(POLICY_HND));
+
+ return (PyObject*)o;
+}
+
+PyTypeObject spoolss_policy_hnd_type = {
+ PyObject_HEAD_INIT(NULL)
+ 0,
+ "Policy Handle",
+ sizeof(spoolss_policy_hnd_object),
+ 0,
+ py_policy_hnd_dealloc, /*tp_dealloc*/
+ 0, /*tp_print*/
+ 0, /*tp_getattr*/
+ 0, /*tp_setattr*/
+ 0, /*tp_compare*/
+ 0, /*tp_repr*/
+ 0, /*tp_as_number*/
+ 0, /*tp_as_sequence*/
+ 0, /*tp_as_mapping*/
+ 0, /*tp_hash */
+};
+
+/*
+ * Routines to convert from python hashes to Samba structures
+ */
+
+struct pyconv py_PRINTER_INFO_0[] = {
+ { "printer_name", PY_UNISTR, offsetof(PRINTER_INFO_0, printername) },
+ { "server_name", PY_UNISTR, offsetof(PRINTER_INFO_0, servername) },
+
+ { "cjobs", PY_UINT32, offsetof(PRINTER_INFO_0, cjobs) },
+ { "total_jobs", PY_UINT32, offsetof(PRINTER_INFO_0, total_jobs) },
+ { "total_bytes", PY_UINT32, offsetof(PRINTER_INFO_0, total_bytes) },
+
+ { "year", PY_UINT16, offsetof(PRINTER_INFO_0, year) },
+ { "month", PY_UINT16, offsetof(PRINTER_INFO_0, month) },
+ { "day_of_week", PY_UINT16, offsetof(PRINTER_INFO_0, dayofweek) },
+ { "day", PY_UINT16, offsetof(PRINTER_INFO_0, day) },
+ { "hour", PY_UINT16, offsetof(PRINTER_INFO_0, hour) },
+ { "minute", PY_UINT16, offsetof(PRINTER_INFO_0, minute) },
+ { "second", PY_UINT16, offsetof(PRINTER_INFO_0, second) },
+ { "milliseconds", PY_UINT16, offsetof(PRINTER_INFO_0, milliseconds) },
+
+ { "global_counter", PY_UINT32, offsetof(PRINTER_INFO_0, global_counter) },
+ { "total_pages", PY_UINT32, offsetof(PRINTER_INFO_0, total_pages) },
+
+ { "major_version", PY_UINT16, offsetof(PRINTER_INFO_0, major_version) },
+ { "build_version", PY_UINT16, offsetof(PRINTER_INFO_0, build_version) },
+
+ { "unknown7", PY_UINT32, offsetof(PRINTER_INFO_0, unknown7) },
+ { "unknown8", PY_UINT32, offsetof(PRINTER_INFO_0, unknown8) },
+ { "unknown9", PY_UINT32, offsetof(PRINTER_INFO_0, unknown9) },
+ { "session_counter", PY_UINT32, offsetof(PRINTER_INFO_0, session_counter)},
+ { "unknown11", PY_UINT32, offsetof(PRINTER_INFO_0, unknown11) },
+ { "printer_errors", PY_UINT32, offsetof(PRINTER_INFO_0, printer_errors) },
+ { "unknown13", PY_UINT32, offsetof(PRINTER_INFO_0, unknown13) },
+ { "unknown14", PY_UINT32, offsetof(PRINTER_INFO_0, unknown14) },
+ { "unknown15", PY_UINT32, offsetof(PRINTER_INFO_0, unknown15) },
+ { "unknown16", PY_UINT32, offsetof(PRINTER_INFO_0, unknown16) },
+ { "change_id", PY_UINT32, offsetof(PRINTER_INFO_0, change_id) },
+ { "unknown18", PY_UINT32, offsetof(PRINTER_INFO_0, unknown18) },
+ { "status", PY_UINT32, offsetof(PRINTER_INFO_0, status) },
+ { "unknown20", PY_UINT32, offsetof(PRINTER_INFO_0, unknown20) },
+ { "c_setprinter", PY_UINT32, offsetof(PRINTER_INFO_0, c_setprinter) },
+ { "unknown22", PY_UINT32, offsetof(PRINTER_INFO_0, unknown22) },
+ { "unknown23", PY_UINT32, offsetof(PRINTER_INFO_0, unknown23) },
+ { "unknown24", PY_UINT32, offsetof(PRINTER_INFO_0, unknown24) },
+ { "unknown25", PY_UINT32, offsetof(PRINTER_INFO_0, unknown25) },
+ { "unknown26", PY_UINT32, offsetof(PRINTER_INFO_0, unknown26) },
+ { "unknown27", PY_UINT32, offsetof(PRINTER_INFO_0, unknown27) },
+ { "unknown28", PY_UINT32, offsetof(PRINTER_INFO_0, unknown28) },
+ { "unknown29", PY_UINT32, offsetof(PRINTER_INFO_0, unknown29) },
+
+ { NULL }
+};
+
+struct pyconv py_PRINTER_INFO_1[] = {
+ { "printer_name", PY_UNISTR, offsetof(PRINTER_INFO_1, name) },
+ { "description", PY_UNISTR, offsetof(PRINTER_INFO_1, description) },
+ { "comment", PY_UNISTR, offsetof(PRINTER_INFO_1, comment) },
+ { "flags", PY_UINT32, offsetof(PRINTER_INFO_1, flags) },
+ { NULL }
+};
+
+struct pyconv py_PRINTER_INFO_2[] = {
+ { "server_name", PY_UNISTR, offsetof(PRINTER_INFO_2, servername) },
+ { "printer_name", PY_UNISTR, offsetof(PRINTER_INFO_2, printername) },
+ { "share_name", PY_UNISTR, offsetof(PRINTER_INFO_2, sharename) },
+ { "port_name", PY_UNISTR, offsetof(PRINTER_INFO_2, portname) },
+ { "driver_name", PY_UNISTR, offsetof(PRINTER_INFO_2, drivername) },
+ { "comment", PY_UNISTR, offsetof(PRINTER_INFO_2, comment) },
+ { "location", PY_UNISTR, offsetof(PRINTER_INFO_2, location) },
+ { "datatype", PY_UNISTR, offsetof(PRINTER_INFO_2, datatype) },
+ { "sepfile", PY_UNISTR, offsetof(PRINTER_INFO_2, sepfile) },
+ { "print_processor", PY_UNISTR, offsetof(PRINTER_INFO_2, printprocessor) },
+ { "parameters", PY_UNISTR, offsetof(PRINTER_INFO_2, parameters) },
+ { "attributes", PY_UINT32, offsetof(PRINTER_INFO_2, attributes) },
+ { "default_priority", PY_UINT32, offsetof(PRINTER_INFO_2, defaultpriority) },
+ { "priority", PY_UINT32, offsetof(PRINTER_INFO_2, priority) },
+ { "start_time", PY_UINT32, offsetof(PRINTER_INFO_2, starttime) },
+ { "until_time", PY_UINT32, offsetof(PRINTER_INFO_2, untiltime) },
+ { "status", PY_UINT32, offsetof(PRINTER_INFO_2, status) },
+ { "cjobs", PY_UINT32, offsetof(PRINTER_INFO_2, cjobs) },
+ { "average_ppm", PY_UINT32, offsetof(PRINTER_INFO_2, averageppm) },
+ { NULL }
+};
+
+struct pyconv py_PRINTER_INFO_3[] = {
+ { "flags", PY_UINT32, offsetof(PRINTER_INFO_3, flags) },
+ { NULL }
+};
+
+struct pyconv py_DEVICEMODE[] = {
+ { "device_name", PY_UNISTR, offsetof(DEVICEMODE, devicename) },
+ { "spec_version", PY_UINT16, offsetof(DEVICEMODE, specversion) },
+ { "driver_version", PY_UINT16, offsetof(DEVICEMODE, driverversion) },
+ { "size", PY_UINT16, offsetof(DEVICEMODE, size) },
+ { "fields", PY_UINT16, offsetof(DEVICEMODE, fields) },
+ { "orientation", PY_UINT16, offsetof(DEVICEMODE, orientation) },
+ { "paper_size", PY_UINT16, offsetof(DEVICEMODE, papersize) },
+ { "paper_width", PY_UINT16, offsetof(DEVICEMODE, paperwidth) },
+ { "paper_length", PY_UINT16, offsetof(DEVICEMODE, paperlength) },
+ { "scale", PY_UINT16, offsetof(DEVICEMODE, scale) },
+ { "copies", PY_UINT16, offsetof(DEVICEMODE, copies) },
+ { "default_source", PY_UINT16, offsetof(DEVICEMODE, defaultsource) },
+ { "print_quality", PY_UINT16, offsetof(DEVICEMODE, printquality) },
+ { "color", PY_UINT16, offsetof(DEVICEMODE, color) },
+ { "duplex", PY_UINT16, offsetof(DEVICEMODE, duplex) },
+ { "y_resolution", PY_UINT16, offsetof(DEVICEMODE, yresolution) },
+ { "tt_option", PY_UINT16, offsetof(DEVICEMODE, ttoption) },
+ { "collate", PY_UINT16, offsetof(DEVICEMODE, collate) },
+ { "form_name", PY_UNISTR, offsetof(DEVICEMODE, formname) },
+ { "log_pixels", PY_UINT16, offsetof(DEVICEMODE, logpixels) },
+ { "bits_per_pel", PY_UINT32, offsetof(DEVICEMODE, bitsperpel) },
+ { "pels_width", PY_UINT32, offsetof(DEVICEMODE, pelswidth) },
+ { "pels_height", PY_UINT32, offsetof(DEVICEMODE, pelsheight) },
+ { "display_flags", PY_UINT32, offsetof(DEVICEMODE, displayflags) },
+ { "display_frequency", PY_UINT32, offsetof(DEVICEMODE, displayfrequency) },
+ { "icm_method", PY_UINT32, offsetof(DEVICEMODE, icmmethod) },
+ { "icm_intent", PY_UINT32, offsetof(DEVICEMODE, icmintent) },
+ { "media_type", PY_UINT32, offsetof(DEVICEMODE, mediatype) },
+ { "dither_type", PY_UINT32, offsetof(DEVICEMODE, dithertype) },
+ { "reserved1", PY_UINT32, offsetof(DEVICEMODE, reserved1) },
+ { "reserved2", PY_UINT32, offsetof(DEVICEMODE, reserved2) },
+ { "panning_width", PY_UINT32, offsetof(DEVICEMODE, panningwidth) },
+ { "panning_height", PY_UINT32, offsetof(DEVICEMODE, panningheight) },
+ { NULL }
+};
+
+struct pyconv py_DRIVER_INFO_1[] = {
+ { "name", PY_UNISTR, offsetof(DRIVER_INFO_1, name) },
+ { NULL }
+};
+
+struct pyconv py_DRIVER_INFO_2[] = {
+ { "version", PY_UINT32, offsetof(DRIVER_INFO_2, version) },
+ { "name", PY_UNISTR, offsetof(DRIVER_INFO_2, name) },
+ { "architecture", PY_UNISTR, offsetof(DRIVER_INFO_2, architecture) },
+ { "driver_path", PY_UNISTR, offsetof(DRIVER_INFO_2, driverpath) },
+ { "data_file", PY_UNISTR, offsetof(DRIVER_INFO_2, datafile) },
+ { "config_file", PY_UNISTR, offsetof(DRIVER_INFO_2, configfile) },
+ { NULL }
+};
+
+struct pyconv py_DRIVER_INFO_3[] = {
+ { "version", PY_UINT32, offsetof(DRIVER_INFO_3, version) },
+ { "name", PY_UNISTR, offsetof(DRIVER_INFO_3, name) },
+ { "architecture", PY_UNISTR, offsetof(DRIVER_INFO_3, architecture) },
+ { "driver_path", PY_UNISTR, offsetof(DRIVER_INFO_3, driverpath) },
+ { "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 }
+};
+
+struct pyconv py_DRIVER_INFO_6[] = {
+ { "version", PY_UINT32, offsetof(DRIVER_INFO_6, version) },
+ { "name", PY_UNISTR, offsetof(DRIVER_INFO_6, name) },
+ { "architecture", PY_UNISTR, offsetof(DRIVER_INFO_6, architecture) },
+ { "driver_path", PY_UNISTR, offsetof(DRIVER_INFO_6, driverpath) },
+ { "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 */
+
+ { "padding", PY_UINT32, offsetof(DRIVER_INFO_6, padding) },
+ { "driver_version_low", PY_UINT32, offsetof(DRIVER_INFO_6, driver_version_low) },
+ { "driver_version_high", PY_UINT32, offsetof(DRIVER_INFO_6, driver_version_high) },
+ { "mfg_name", PY_UNISTR, offsetof(DRIVER_INFO_6, mfgname) },
+ { "oem_url", PY_UNISTR, offsetof(DRIVER_INFO_6, oem_url) },
+ { "hardware_id", PY_UNISTR, offsetof(DRIVER_INFO_6, hardware_id) },
+ { "provider", PY_UNISTR, offsetof(DRIVER_INFO_6, provider) },
+
+ { NULL }
+};
+
+static void fstr_pull(fstring str, UNISTR *uni)
+{
+ rpcstr_pull(str, uni->buffer, sizeof(fstring), 0, STR_TERMINATE);
+}
+
+/* Convert a structure to a Python dict */
+
+PyObject *from_struct(void *s, struct pyconv *conv)
+{
+ PyObject *obj, *item;
+ int i;
+
+ obj = PyDict_New();
+
+ for (i = 0; conv[i].name; i++) {
+ switch (conv[i].type) {
+ case PY_UNISTR: {
+ UNISTR *u = (UNISTR *)((char *)s + conv[i].offset);
+ fstring s = "";
+
+ if (u->buffer)
+ fstr_pull(s, u);
+
+ item = PyString_FromString(s);
+ PyDict_SetItemString(obj, conv[i].name, item);
+
+ break;
+ }
+ case PY_UINT32: {
+ uint32 *u = (uint32 *)((char *)s + conv[i].offset);
+
+ item = PyInt_FromLong(*u);
+ PyDict_SetItemString(obj, conv[i].name, item);
+
+ break;
+ }
+ case PY_UINT16: {
+ uint16 *u = (uint16 *)((char *)s + conv[i].offset);
+
+ item = PyInt_FromLong(*u);
+ PyDict_SetItemString(obj, conv[i].name, item);
+
+ break;
+ }
+ default:
+ break;
+ }
+ }
+
+ return obj;
+}
+
+/* Convert a Python dict to a structure */
+
+void to_struct(void *s, PyObject *dict, struct pyconv *conv)
+{
+ int i;
+
+ for (i = 0; conv[i].name; i++) {
+ PyObject *obj;
+
+ obj = PyDict_GetItemString(dict, conv[i].name);
+
+ switch (conv[i].type) {
+ case PY_UNISTR: {
+ UNISTR *u = (UNISTR *)((char *)s + conv[i].offset);
+ char *s = "";
+
+ if (obj && PyString_Check(obj))
+ s = PyString_AsString(obj);
+
+ init_unistr(u, s);
+
+ break;
+ }
+ case PY_UINT32: {
+ uint32 *u = (uint32 *)((char *)s + conv[i].offset);
+
+ if (obj && PyInt_Check(obj))
+ *u = PyInt_AsLong(obj);
+ else
+ *u = 0;
+
+ break;
+ }
+ case PY_UINT16: {
+ uint16 *u = (uint16 *)((char *)s + conv[i].offset);
+
+ if (obj && PyInt_Check(obj))
+ *u = PyInt_AsLong(obj);
+ else
+ *u = 0;
+
+ break;
+ }
+ default:
+ break;
+ }
+ }
+}
+
+/* Return a cli_state struct opened on the SPOOLSS pipe. If credentials
+ are passed use them. */
+
+typedef struct cli_state *(cli_pipe_fn)(
+ struct cli_state *cli, char *system_name,
+ struct ntuser_creds *creds);
+
+static struct cli_state *open_pipe_creds(char *system_name, PyObject *creds,
+ cli_pipe_fn *connect_fn,
+ struct cli_state *cli)
+{
+ struct ntuser_creds nt_creds;
+
+ if (!cli) {
+ cli = (struct cli_state *)malloc(sizeof(struct cli_state));
+ if (!cli)
+ return NULL;
+ }
+
+ ZERO_STRUCTP(cli);
+
+ /* Extract credentials from the python dictionary and initialise
+ the ntuser_creds struct from them. */
+
+ ZERO_STRUCT(nt_creds);
+ nt_creds.pwd.null_pwd = True;
+
+ if (creds) {
+ char *username, *password, *domain;
+ PyObject *username_obj, *password_obj, *domain_obj;
+
+ /* Check credentials passed are valid. This means the
+ username, domain and password keys must exist and be
+ string objects. */
+
+ username_obj = PyDict_GetItemString(creds, "username");
+ domain_obj = PyDict_GetItemString(creds, "domain");
+ password_obj = PyDict_GetItemString(creds, "password");
+
+ if (!username_obj || !domain_obj || !password_obj) {
+ error:
+ PyErr_SetString(spoolss_error, "invalid credentials");
+ return NULL;
+ }
+
+ if (!PyString_Check(username_obj) ||
+ !PyString_Check(domain_obj) ||
+ !PyString_Check(password_obj))
+ goto error;
+
+ username = PyString_AsString(username_obj);
+ domain = PyString_AsString(domain_obj);
+ password = PyString_AsString(password_obj);
+
+ if (!username || !domain || !password)
+ goto error;
+
+ /* Initialise nt_creds structure with passed creds */
+
+ fstrcpy(nt_creds.user_name, username);
+ fstrcpy(nt_creds.domain, domain);
+
+ if (lp_encrypted_passwords())
+ pwd_make_lm_nt_16(&nt_creds.pwd, password);
+ else
+ pwd_set_cleartext(&nt_creds.pwd, password);
+
+ nt_creds.pwd.null_pwd = False;
+ }
+
+ /* Now try to connect */
+
+ connect_fn(cli, system_name, &nt_creds);
+
+ return cli;
+}
+
+/* Open a printer */
+
+static PyObject *spoolss_openprinter(PyObject *self, PyObject *args,
+ PyObject *kw)
+{
+ char *full_name, *computer_name = NULL;
+ TALLOC_CTX *mem_ctx;
+ POLICY_HND hnd;
+ WERROR werror;
+ PyObject *result = NULL, *creds = NULL;
+ static char *kwlist[] = { "printername", "creds", "access", NULL };
+ uint32 desired_access = MAXIMUM_ALLOWED_ACCESS;
+ struct cli_state *cli;
+
+ if (!PyArg_ParseTupleAndKeywords(
+ args, kw, "s|O!i", kwlist, &full_name, &PyDict_Type, &creds,
+ &desired_access)) {
+
+ goto done;
+ }
+
+ /* FIXME: Return name format exception for names without a UNC
+ prefix */
+
+ computer_name = strdup(full_name + 2);
+
+ if (strchr(computer_name, '\\')) {
+ char *c = strchr(computer_name, '\\');
+ *c = 0;
+ }
+
+ if (!(cli = open_pipe_creds(computer_name, creds,
+ cli_spoolss_initialise, NULL))) {
+ fprintf(stderr, "could not initialise cli state\n");
+ goto done;
+ }
+
+ if (!(mem_ctx = talloc_init())) {
+ fprintf(stderr, "unable to initialise talloc context\n");
+ goto done;
+ }
+
+ werror = cli_spoolss_open_printer_ex(
+ cli, mem_ctx, full_name, "", desired_access, computer_name,
+ "", &hnd);
+
+ if (!W_ERROR_IS_OK(werror)) {
+ cli_shutdown(cli);
+ SAFE_FREE(cli);
+ PyErr_SetObject(spoolss_werror,
+ PyInt_FromLong(W_ERROR_V(werror)));
+ goto done;
+ }
+
+ result = new_policy_hnd_object(cli, mem_ctx, &hnd);
+
+ done:
+ SAFE_FREE(computer_name);
+
+ return result;
+}
+
+/* Close a printer */
+
+static PyObject *spoolss_closeprinter(PyObject *self, PyObject *args)
+{
+ PyObject *po;
+ spoolss_policy_hnd_object *hnd;
+ WERROR result;
+
+ /* Parse parameters */
+
+ if (!PyArg_ParseTuple(args, "O!", &spoolss_policy_hnd_type, &po))
+ return NULL;
+
+ hnd = (spoolss_policy_hnd_object *)po;
+
+ /* Call rpc function */
+
+ result = cli_spoolss_close_printer(hnd->cli, hnd->mem_ctx, &hnd->pol);
+
+ /* Cleanup samba stuf */
+
+ cli_shutdown(hnd->cli);
+ talloc_destroy(hnd->mem_ctx);
+
+ /* Return value */
+
+ Py_INCREF(Py_None);
+ return Py_None;
+}
+
+/* Fetch printer driver */
+
+static PyObject *spoolss_getprinterdriver(PyObject *self, PyObject *args,
+ PyObject *kw)
+{
+ PyObject *po;
+ spoolss_policy_hnd_object *hnd;
+ WERROR werror;
+ PyObject *result;
+ PRINTER_DRIVER_CTR ctr;
+ int level = 1;
+ uint32 needed;
+ char *arch = "Windows NT x86";
+ static char *kwlist[] = {"hnd", "level", "arch", NULL};
+
+ /* Parse parameters */
+
+ if (!PyArg_ParseTupleAndKeywords(args, kw, "O!|is", kwlist,
+ &spoolss_policy_hnd_type, &po, &level, &arch))
+ return NULL;
+
+ hnd = (spoolss_policy_hnd_object *)po;
+
+ /* Call rpc function */
+
+ werror = cli_spoolss_getprinterdriver(
+ hnd->cli, hnd->mem_ctx, 0, &needed, &hnd->pol, level,
+ arch, &ctr);
+
+ if (W_ERROR_V(werror) == ERRinsufficientbuffer)
+ werror = cli_spoolss_getprinterdriver(
+ hnd->cli, hnd->mem_ctx, needed, NULL, &hnd->pol,
+ level, arch, &ctr);
+
+ /* Return value */
+
+ result = Py_None;
+
+ if (W_ERROR_IS_OK(werror)) {
+ switch (level) {
+ case 1:
+ result = from_struct(&ctr.info1, py_DRIVER_INFO_1);
+ break;
+ case 2:
+ result = from_struct(&ctr.info2, py_DRIVER_INFO_2);
+ break;
+ case 6:
+ result = from_struct(&ctr.info6, py_DRIVER_INFO_6);
+ break;
+ default:
+ result = Py_None;
+ break;
+ }
+ }
+
+ Py_INCREF(result);
+ return result;
+}
+
+/* Enumerate printer drivers */
+
+static PyObject *spoolss_enumprinterdrivers(PyObject *self, PyObject *args,
+ PyObject *kw)
+{
+ PyObject *po;
+ spoolss_policy_hnd_object *hnd;
+ WERROR werror;
+ PyObject *result;
+ PRINTER_DRIVER_CTR ctr;
+ int level = 1, i;
+ uint32 needed, num_drivers;
+ char *arch = "Windows NT x86";
+ static char *kwlist[] = {"hnd", "level", "arch", NULL};
+
+ /* Parse parameters */
+
+ if (!PyArg_ParseTupleAndKeywords(args, kw, "O!|is", kwlist,
+ &spoolss_policy_hnd_type, &po, &level, &arch))
+ return NULL;
+
+ hnd = (spoolss_policy_hnd_object *)po;
+
+ /* Call rpc function */
+
+ werror = cli_spoolss_enumprinterdrivers(
+ hnd->cli, hnd->mem_ctx, 0, &needed, level, arch,
+ &num_drivers, &ctr);
+
+ if (W_ERROR_V(werror) == ERRinsufficientbuffer)
+ werror = cli_spoolss_enumprinterdrivers(
+ hnd->cli, hnd->mem_ctx, needed, NULL, level, arch,
+ &num_drivers, &ctr);
+
+ /* Return value */
+
+ result = Py_None;
+
+ if (!W_ERROR_IS_OK(werror))
+ goto done;
+
+ switch (level) {
+ case 1:
+ result = PyList_New(num_drivers);
+
+ for (i = 0; i < num_drivers; i++) {
+ PyObject *value;
+
+ value = from_struct(&ctr.info1, py_DRIVER_INFO_1);
+ PyList_SetItem(result, i, value);
+ }
+
+ break;
+ case 2:
+ result = PyList_New(num_drivers);
+
+ for(i = 0; i < num_drivers; i++) {
+ PyObject *value;
+
+ value = from_struct(&ctr.info2, py_DRIVER_INFO_2);
+ PyList_SetItem(result, i, value);
+ }
+
+ break;
+ case 6:
+ result = PyList_New(num_drivers);
+
+ for(i = 0; i < num_drivers; i++) {
+ PyObject *value;
+
+ value = from_struct(&ctr.info2, py_DRIVER_INFO_6);
+ PyList_SetItem(result, i, value);
+ }
+
+ break;
+ default:
+ result = Py_None;
+ break;
+ }
+
+ done:
+ Py_INCREF(result);
+ return result;
+}
+
+/* Convert a security descriptor to a Python dict */
+
+static PyObject *PySID_FromSID(DOM_SID *sid)
+{
+ fstring sidstr;
+
+ if (!sid) {
+ Py_INCREF(Py_None);
+ return Py_None;
+ }
+
+ if (sid_to_string(sidstr, sid))
+ return PyString_FromString(sidstr);
+
+ Py_INCREF(Py_None);
+ return Py_None;
+}
+
+static PyObject *PyACE_FromACE(SEC_ACE *ace)
+{
+ PyObject *obj;
+
+ if (!ace) {
+ Py_INCREF(Py_None);
+ return Py_None;
+ }
+
+ obj = PyDict_New();
+
+ PyDict_SetItemString(obj, "type", PyInt_FromLong(ace->type));
+ PyDict_SetItemString(obj, "flags", PyInt_FromLong(ace->flags));
+ PyDict_SetItemString(obj, "mask", PyInt_FromLong(ace->info.mask));
+
+ PyDict_SetItemString(obj, "trustee", PySID_FromSID(&ace->trustee));
+
+ return obj;
+}
+
+static PyObject *PyACL_FromACL(SEC_ACL *acl)
+{
+ PyObject *obj, *ace_list;
+ int i;
+
+ if (!acl) {
+ Py_INCREF(Py_None);
+ return Py_None;
+ }
+
+ obj = PyDict_New();
+
+ PyDict_SetItemString(obj, "revision", PyInt_FromLong(acl->revision));
+
+ ace_list = PyList_New(acl->num_aces);
+
+ for (i = 0; i < acl->num_aces; i++)
+ PyList_SetItem(ace_list, i, PyACE_FromACE(&acl->ace[i]));
+
+ PyDict_SetItemString(obj, "ace_list", ace_list);
+
+ return obj;
+}
+
+static PyObject *PySECDESC_FromSECDESC(SEC_DESC *sd)
+{
+ PyObject *obj = PyDict_New();
+
+ PyDict_SetItemString(obj, "revision", PyInt_FromLong(sd->revision));
+ PyDict_SetItemString(obj, "type", PyInt_FromLong(sd->type));
+
+ PyDict_SetItemString(obj, "owner_sid", PySID_FromSID(sd->owner_sid));
+ PyDict_SetItemString(obj, "group_sid", PySID_FromSID(sd->grp_sid));
+
+ PyDict_SetItemString(obj, "dacl", PyACL_FromACL(sd->dacl));
+ PyDict_SetItemString(obj, "sacl", PyACL_FromACL(sd->sacl));
+
+ return obj;
+}
+
+PyObject *PyDEVICEMODE_FromDEVICEMODE(DEVICEMODE *devmode)
+{
+ PyObject *obj;
+
+ obj = from_struct(devmode, py_DEVICEMODE);
+
+ PyDict_SetItemString(obj, "private",
+ PyString_FromStringAndSize(devmode->private,
+ devmode->driverextra));
+
+ return obj;
+}
+
+/* Fetch printer information */
+
+static PyObject *spoolss_getprinter(PyObject *self, PyObject *args,
+ PyObject *kw)
+{
+ PyObject *po;
+ spoolss_policy_hnd_object *hnd;
+ WERROR werror;
+ PyObject *result;
+ PRINTER_INFO_CTR ctr;
+ int level = 1;
+ uint32 needed;
+ static char *kwlist[] = {"hnd", "level", NULL};
+
+ /* Parse parameters */
+
+ if (!PyArg_ParseTupleAndKeywords(args, kw, "O!|i", kwlist,
+ &spoolss_policy_hnd_type, &po, &level))
+ return NULL;
+
+ hnd = (spoolss_policy_hnd_object *)po;
+
+ /* Call rpc function */
+
+ werror = cli_spoolss_getprinter(
+ hnd->cli, hnd->mem_ctx, 0, &needed, &hnd->pol, level, &ctr);
+
+ if (W_ERROR_V(werror) == ERRinsufficientbuffer)
+ werror = cli_spoolss_getprinter(
+ hnd->cli, hnd->mem_ctx, needed, NULL, &hnd->pol,
+ level, &ctr);
+
+ /* Return value */
+
+ result = Py_None;
+
+ if (!W_ERROR_IS_OK(werror))
+ goto done;
+
+ switch (level) {
+
+ case 0:
+ result = from_struct(ctr.printers_0, py_PRINTER_INFO_0);
+
+ break;
+
+ case 1:
+ result = from_struct(ctr.printers_1, py_PRINTER_INFO_1);
+
+ break;
+
+ case 2:
+ result = from_struct(ctr.printers_2, py_PRINTER_INFO_2);
+
+ PyDict_SetItemString(result, "security_descriptor",
+ PySECDESC_FromSECDESC(
+ ctr.printers_2->secdesc));
+
+ PyDict_SetItemString(result, "device_mode",
+ PyDEVICEMODE_FromDEVICEMODE(
+ ctr.printers_2->devmode));
+
+ break;
+
+ case 3:
+ result = from_struct(ctr.printers_3, py_PRINTER_INFO_3);
+
+ PyDict_SetItemString(result, "security_descriptor",
+ PySECDESC_FromSECDESC(
+ ctr.printers_3->secdesc));
+ break;
+
+ default:
+ result = Py_None;
+ break;
+ }
+ done:
+ Py_INCREF(result);
+ return result;
+}
+
+/* Set printer information */
+
+static PyObject *spoolss_setprinter(PyObject *self, PyObject *args,
+ PyObject *kw)
+{
+ PyObject *po;
+ spoolss_policy_hnd_object *hnd;
+ WERROR werror;
+ PyObject *result, *info;
+ PRINTER_INFO_CTR ctr;
+ int level = 1;
+ static char *kwlist[] = { "hnd", "dict", "level", NULL };
+ union {
+ PRINTER_INFO_0 printers_0;
+ PRINTER_INFO_1 printers_1;
+ PRINTER_INFO_2 printers_2;
+ PRINTER_INFO_3 printers_3;
+ PRINTER_INFO_4 printers_4;
+ PRINTER_INFO_5 printers_5;
+ } pinfo;
+
+ /* Parse parameters */
+
+ if (!PyArg_ParseTupleAndKeywords(args, kw, "O!O!|i", kwlist,
+ &spoolss_policy_hnd_type, &po,
+ &PyDict_Type, &info, &level))
+ return NULL;
+
+ hnd = (spoolss_policy_hnd_object *)po;
+
+ /* Fill in printer info */
+
+ ZERO_STRUCT(ctr);
+
+ switch (level) {
+ case 1:
+ ctr.printers_1 = &pinfo.printers_1;
+ to_struct(&pinfo.printers_1, info, py_PRINTER_INFO_1);
+ break;
+ default:
+ }
+
+ /* Call rpc function */
+
+ werror = cli_spoolss_setprinter(hnd->cli, hnd->mem_ctx, &hnd->pol,
+ level, &ctr, 0);
+
+ /* Return value */
+
+ result = Py_None;
+
+ if (!W_ERROR_IS_OK(werror))
+ goto done;
+
+ done:
+ Py_INCREF(result);
+ return result;
+}
+
+/* Enumerate printers */
+
+static PyObject *spoolss_enumprinters(PyObject *self, PyObject *args,
+ PyObject *kw)
+{
+ WERROR werror;
+ PyObject *result, *creds = NULL;
+ PRINTER_INFO_CTR ctr;
+ int level = 1, flags = PRINTER_ENUM_LOCAL, i;
+ uint32 needed, num_printers;
+ static char *kwlist[] = {"server", "name", "level", "flags",
+ "creds", NULL};
+ TALLOC_CTX *mem_ctx = NULL;
+ struct cli_state *cli = NULL;
+ char *server, *name = NULL;
+
+ /* Parse parameters */
+
+ if (!PyArg_ParseTupleAndKeywords(args, kw, "s|siiO!", kwlist,
+ &server, &name, &level, &flags,
+ &PyDict_Type, &creds))
+ return NULL;
+
+ if (server[0] == '\\' && server[1] == '\\')
+ server += 2;
+
+ mem_ctx = talloc_init();
+ cli = open_pipe_creds(server, creds, cli_spoolss_initialise, NULL);
+
+ /* Call rpc function */
+
+ werror = cli_spoolss_enum_printers(
+ cli, mem_ctx, 0, &needed, 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);
+
+ /* Return value */
+
+ result = Py_None;
+
+ if (!W_ERROR_IS_OK(werror))
+ goto done;
+
+ result = PyList_New(num_printers);
+
+ switch (level) {
+ case 0:
+ for (i = 0; i < num_printers; i++) {
+ PyObject *value;
+
+ value = from_struct (
+ &ctr.printers_0[i], py_PRINTER_INFO_0);
+
+ PyList_SetItem(result, i, value);
+ }
+
+ break;
+ case 1:
+ for(i = 0; i < num_printers; i++) {
+ PyObject *value;
+
+ value = from_struct(
+ &ctr.printers_1[i], py_PRINTER_INFO_1);
+
+ PyList_SetItem(result, i, value);
+ }
+
+ break;
+ case 2:
+ for(i = 0; i < num_printers; i++) {
+ PyObject *value;
+
+ value = from_struct(
+ &ctr.printers_2[i], py_PRINTER_INFO_2);
+
+ PyList_SetItem(result, i, value);
+ }
+
+ break;
+ case 3:
+ for(i = 0; i < num_printers; i++) {
+ PyObject *value;
+
+ value = from_struct(
+ &ctr.printers_3[i], py_PRINTER_INFO_3);
+
+ PyList_SetItem(result, i, value);
+ }
+
+ break;
+ }
+
+ done:
+ Py_INCREF(result);
+ return result;
+}
+
+/*
+ * Method dispatch table
+ */
+
+#include "python/py_spoolss_forms.h"
+
+static PyMethodDef spoolss_methods[] = {
+
+ /* Open/close printer handles */
+
+ { "openprinter", spoolss_openprinter, METH_VARARGS | METH_KEYWORDS,
+ "Open printer" },
+
+ { "closeprinter", spoolss_closeprinter, METH_VARARGS,
+ "Close printer" },
+
+ /* Printer drivers */
+
+ { "getprinterdriver", spoolss_getprinterdriver,
+ METH_VARARGS | METH_KEYWORDS, "Fetch printer driver" },
+
+ { "enumprinterdrivers", spoolss_enumprinterdrivers,
+ METH_VARARGS | METH_KEYWORDS, "Enumerate printer drivers" },
+
+ { "getprinter", spoolss_getprinter, METH_VARARGS | METH_KEYWORDS,
+ "Fetch printer information" },
+
+ { "setprinter", spoolss_setprinter, METH_VARARGS | METH_KEYWORDS,
+ "Set printer information" },
+
+ { "enumprinters", spoolss_enumprinters, METH_VARARGS | METH_KEYWORDS,
+ "Enumerate printers" },
+
+ /* Forms */
+
+ { "enumforms", spoolss_enumforms, METH_VARARGS | METH_KEYWORDS,
+ "Enumerate forms" },
+
+ { "setform", spoolss_setform, METH_VARARGS | METH_KEYWORDS,
+ "Modify properties of a form" },
+
+ { "addform", spoolss_addform, METH_VARARGS | METH_KEYWORDS,
+ "Insert a form" },
+
+ { "getform", spoolss_getform, METH_VARARGS | METH_KEYWORDS,
+ "Fetch form properties" },
+
+ { "deleteform", spoolss_deleteform, METH_VARARGS | METH_KEYWORDS,
+ "Delete a form" },
+
+ { "enumforms", spoolss_enumforms, METH_VARARGS | METH_KEYWORDS,
+ "Delete a form" },
+
+ { NULL }
+};
+
+/* Initialise constants */
+
+struct spoolss_const {
+ char *name;
+ uint32 value;
+} spoolss_const_vals[] = {
+
+ /* Access permissions */
+
+ { "MAXIMUM_ALLOWED_ACCESS", MAXIMUM_ALLOWED_ACCESS },
+ { "SERVER_ALL_ACCESS", SERVER_ALL_ACCESS },
+ { "PRINTER_ALL_ACCESS", PRINTER_ALL_ACCESS },
+
+ /* Printer enumeration flags */
+
+ { "PRINTER_ENUM_DEFAULT", PRINTER_ENUM_DEFAULT },
+ { "PRINTER_ENUM_LOCAL", PRINTER_ENUM_LOCAL },
+ { "PRINTER_ENUM_CONNECTIONS", PRINTER_ENUM_CONNECTIONS },
+ { "PRINTER_ENUM_FAVORITE", PRINTER_ENUM_FAVORITE },
+ { "PRINTER_ENUM_NAME", PRINTER_ENUM_NAME },
+ { "PRINTER_ENUM_REMOTE", PRINTER_ENUM_REMOTE },
+ { "PRINTER_ENUM_SHARED", PRINTER_ENUM_SHARED },
+ { "PRINTER_ENUM_NETWORK", PRINTER_ENUM_NETWORK },
+
+ { NULL },
+};
+
+static void const_init(PyObject *dict)
+{
+ struct spoolss_const *tmp;
+ PyObject *obj;
+
+ for (tmp = spoolss_const_vals; tmp->name; tmp++) {
+ obj = PyInt_FromLong(tmp->value);
+ PyDict_SetItemString(dict, tmp->name, obj);
+ }
+}
+
+/* Module initialisation */
+
+void initspoolss(void)
+{
+ PyObject *module, *dict;
+
+ /* Initialise module */
+
+ module = Py_InitModule("spoolss", spoolss_methods);
+ dict = PyModule_GetDict(module);
+
+ /* Make spools_error global an exception we can raise when an error
+ occurs. */
+
+ spoolss_error = PyErr_NewException("spoolss.error", NULL, NULL);
+ PyDict_SetItemString(dict, "error", spoolss_error);
+
+ spoolss_werror = PyErr_NewException("spoolss.werror", NULL, NULL);
+ PyDict_SetItemString(dict, "werror", spoolss_werror);
+
+ /* Initialise policy handle object */
+
+ spoolss_policy_hnd_type.ob_type = &PyType_Type;
+
+ /* Initialise constants */
+
+ const_init(dict);
+
+ /* Do samba initialisation */
+
+ py_samba_init();
+}
diff --git a/source3/python/py_spoolss.h b/source3/python/py_spoolss.h
new file mode 100644
index 0000000000..ebe6daa5cc
--- /dev/null
+++ b/source3/python/py_spoolss.h
@@ -0,0 +1,51 @@
+/*
+ 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.
+*/
+
+#ifndef _PY_SPOOLSS_H
+#define _PY_SPOOLSS_H
+
+/* Another version of offsetof (-: */
+
+#undef offsetof
+#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
+
+enum pyconv_types { PY_UNISTR, PY_UINT32, PY_UINT16 };
+
+struct pyconv {
+ char *name; /* Name of member */
+ enum pyconv_types type; /* Type */
+ size_t offset; /* Offset into structure */
+};
+
+typedef struct {
+ PyObject_HEAD
+ struct cli_state *cli;
+ TALLOC_CTX *mem_ctx;
+ POLICY_HND pol;
+} spoolss_policy_hnd_object;
+
+extern PyTypeObject spoolss_policy_hnd_type;
+
+extern PyObject *spoolss_error, *spoolss_werror;
+
+void to_struct(void *s, PyObject *dict, struct pyconv *conv);
+PyObject *from_struct(void *s, struct pyconv *conv);
+
+#endif /* _PY_SPOOLSS_H */
diff --git a/source3/python/py_spoolss_forms.c b/source3/python/py_spoolss_forms.c
new file mode 100644
index 0000000000..fc7db6ac93
--- /dev/null
+++ b/source3/python/py_spoolss_forms.c
@@ -0,0 +1,283 @@
+/*
+ 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_spoolss.h"
+
+struct pyconv py_FORM[] = {
+ { "flags", PY_UINT32, offsetof(FORM, flags) },
+ { "width", PY_UINT32, offsetof(FORM, size_x) },
+ { "length", PY_UINT32, offsetof(FORM, size_y) },
+ { "top", PY_UINT32, offsetof(FORM, top) },
+ { "left", PY_UINT32, offsetof(FORM, left) },
+ { "right", PY_UINT32, offsetof(FORM, right) },
+ { "bottom", PY_UINT32, offsetof(FORM, bottom) },
+ { NULL }
+};
+
+struct pyconv py_FORM_1[] = {
+ { "flags", PY_UINT32, offsetof(FORM_1, flag) },
+ { "width", PY_UINT32, offsetof(FORM_1, width) },
+ { "length", PY_UINT32, offsetof(FORM_1, length) },
+ { "top", PY_UINT32, offsetof(FORM_1, top) },
+ { "left", PY_UINT32, offsetof(FORM_1, left) },
+ { "right", PY_UINT32, offsetof(FORM_1, right) },
+ { "bottom", PY_UINT32, offsetof(FORM_1, bottom) },
+ { "name", PY_UNISTR, offsetof(FORM_1, name) },
+ { NULL }
+};
+
+/* Add a form */
+
+PyObject *spoolss_addform(PyObject *self, PyObject *args, PyObject *kw)
+{
+ PyObject *po;
+ spoolss_policy_hnd_object *hnd;
+ WERROR werror;
+ PyObject *py_form;
+ FORM form;
+ int level = 1;
+ static char *kwlist[] = {"hnd", "form", "level", NULL};
+
+ /* Parse parameters */
+
+ if (!PyArg_ParseTupleAndKeywords(
+ args, kw, "O!O!|i", kwlist, &spoolss_policy_hnd_type, &po,
+ &PyDict_Type, &py_form, &level))
+ return NULL;
+
+ hnd = (spoolss_policy_hnd_object *)po;
+
+ /* Call rpc function */
+
+ switch (level) {
+ case 1: {
+ PyObject *py_form_name;
+ char *form_name;
+
+ to_struct(&form, py_form, py_FORM);
+
+ py_form_name = PyDict_GetItemString(py_form, "name");
+ form_name = PyString_AsString(py_form_name);
+
+ init_unistr2(&form.name, form_name, strlen(form_name) + 1);
+
+ break;
+ }
+ default:
+ PyErr_SetString(spoolss_error, "unsupported info level");
+ return NULL;
+ }
+
+ werror = cli_spoolss_addform(hnd->cli, hnd->mem_ctx, &hnd->pol,
+ level, &form);
+
+
+ if (!W_ERROR_IS_OK(werror)) {
+ PyErr_SetObject(spoolss_werror,
+ PyInt_FromLong(W_ERROR_V(werror)));
+ return NULL;
+ }
+
+ Py_INCREF(Py_None);
+ return Py_None;
+}
+
+/* Get form properties */
+
+PyObject *spoolss_getform(PyObject *self, PyObject *args, PyObject *kw)
+{
+ PyObject *po;
+ spoolss_policy_hnd_object *hnd;
+ WERROR werror;
+ PyObject *result;
+ char *form_name;
+ int level = 1;
+ static char *kwlist[] = {"hnd", "form_name", "level", NULL};
+ uint32 needed;
+ FORM_1 form;
+
+ /* Parse parameters */
+
+ if (!PyArg_ParseTupleAndKeywords(args, kw, "O!s|i", kwlist,
+ &spoolss_policy_hnd_type, &po, &form_name,
+ &level))
+ return NULL;
+
+ hnd = (spoolss_policy_hnd_object *)po;
+
+ /* Call rpc function */
+
+ werror = cli_spoolss_getform(hnd->cli, hnd->mem_ctx, 0, &needed,
+ &hnd->pol, form_name, 1, &form);
+
+ if (W_ERROR_V(werror) == ERRinsufficientbuffer)
+ werror = cli_spoolss_getform(
+ hnd->cli, hnd->mem_ctx, needed, NULL, &hnd->pol,
+ form_name, 1, &form);
+
+ if (!W_ERROR_IS_OK(werror)) {
+ PyErr_SetObject(spoolss_werror,
+ PyInt_FromLong(W_ERROR_V(werror)));
+ return NULL;
+ }
+
+ result = Py_None;
+
+ switch(level) {
+ case 1:
+ result = from_struct(&form, py_FORM_1);
+ break;
+ }
+
+ Py_INCREF(result);
+ return result;
+}
+
+/* Set form properties */
+
+PyObject *spoolss_setform(PyObject *self, PyObject *args, PyObject *kw)
+{
+ PyObject *po;
+ spoolss_policy_hnd_object *hnd;
+ WERROR werror;
+ PyObject *py_form;
+ int level = 1;
+ static char *kwlist[] = {"hnd", "form_name", "form", "level", NULL};
+ char *form_name;
+ FORM form;
+
+ /* Parse parameters */
+
+ if (!PyArg_ParseTupleAndKeywords(args, kw, "O!sO!|i", kwlist,
+ &spoolss_policy_hnd_type, &po, &form_name,
+ &PyDict_Type, &py_form, &level))
+ return NULL;
+
+ hnd = (spoolss_policy_hnd_object *)po;
+
+ /* Call rpc function */
+
+ to_struct(&form, py_form, py_FORM);
+ init_unistr2(&form.name, form_name, strlen(form_name) + 1);
+
+ werror = cli_spoolss_setform(hnd->cli, hnd->mem_ctx, &hnd->pol,
+ level, form_name, &form);
+
+ if (!W_ERROR_IS_OK(werror)) {
+ PyErr_SetObject(spoolss_werror,
+ PyInt_FromLong(W_ERROR_V(werror)));
+
+ return NULL;
+ }
+
+ Py_INCREF(Py_None);
+ return Py_None;
+}
+
+/* Delete a form */
+
+PyObject *spoolss_deleteform(PyObject *self, PyObject *args, PyObject *kw)
+{
+ PyObject *po;
+ spoolss_policy_hnd_object *hnd;
+ WERROR werror;
+ int level = 1;
+ static char *kwlist[] = {"hnd", "form_name", "level", NULL};
+ char *form_name;
+
+ /* Parse parameters */
+
+ if (!PyArg_ParseTupleAndKeywords(
+ args, kw, "O!s|i", kwlist, &spoolss_policy_hnd_type, &po,
+ &form_name, &level))
+ return NULL;
+
+ hnd = (spoolss_policy_hnd_object *)po;
+
+ /* Call rpc function */
+
+ werror = cli_spoolss_deleteform(
+ hnd->cli, hnd->mem_ctx, &hnd->pol, form_name);
+
+ if (!W_ERROR_IS_OK(werror)) {
+ PyErr_SetObject(spoolss_werror,
+ PyInt_FromLong(W_ERROR_V(werror)));
+ return NULL;
+ }
+
+ Py_INCREF(Py_None);
+ return Py_None;
+}
+
+/* Enumerate forms */
+
+PyObject *spoolss_enumforms(PyObject *self, PyObject *args, PyObject *kw)
+{
+ PyObject *po, *result;
+ spoolss_policy_hnd_object *hnd;
+ WERROR werror;
+ uint32 level = 1, num_forms, needed, i;
+ static char *kwlist[] = {"hnd", "level", NULL};
+ FORM_1 *forms;
+
+ /* Parse parameters */
+
+ if (!PyArg_ParseTupleAndKeywords(
+ args, kw, "O!|i", kwlist, &spoolss_policy_hnd_type,
+ &po, &level))
+ return NULL;
+
+ hnd = (spoolss_policy_hnd_object *)po;
+
+ /* Call rpc function */
+
+ werror = cli_spoolss_enumforms(
+ hnd->cli, hnd->mem_ctx, 0, &needed, &hnd->pol, level,
+ &num_forms, &forms);
+
+ if (W_ERROR_V(werror) == ERRinsufficientbuffer)
+ werror = cli_spoolss_enumforms(
+ hnd->cli, hnd->mem_ctx, needed, NULL, &hnd->pol, level,
+ &num_forms, &forms);
+
+ if (!W_ERROR_IS_OK(werror)) {
+ PyErr_SetObject(spoolss_werror,
+ PyInt_FromLong(W_ERROR_V(werror)));
+ return NULL;
+ }
+
+ result = PyList_New(num_forms);
+
+ for (i = 0; i < num_forms; i++) {
+ PyObject *obj = NULL;
+
+ switch(level) {
+ case 1:
+ obj = from_struct(&forms[i], py_FORM_1);
+ break;
+ }
+
+ PyList_SetItem(result, i, obj);
+ }
+
+ return result;
+}
diff --git a/source3/python/py_spoolss_forms.h b/source3/python/py_spoolss_forms.h
new file mode 100644
index 0000000000..336666f1b0
--- /dev/null
+++ b/source3/python/py_spoolss_forms.h
@@ -0,0 +1,32 @@
+/*
+ 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.
+*/
+
+#ifndef _PY_SPOOLSS_FORMS_H
+#define _PY_SPOOLSS_FORMS_H
+
+/* Function prototypes */
+
+PyObject *spoolss_addform(PyObject *self, PyObject *args, PyObject *kw);
+PyObject *spoolss_getform(PyObject *self, PyObject *args, PyObject *kw);
+PyObject *spoolss_setform(PyObject *self, PyObject *args, PyObject *kw);
+PyObject *spoolss_deleteform(PyObject *self, PyObject *args, PyObject *kw);
+PyObject *spoolss_enumforms(PyObject *self, PyObject *args, PyObject *kw);
+
+#endif /* _PY_SPOOLSS_FORMS_H */
diff --git a/source3/python/py_winbind.c b/source3/python/py_winbind.c
new file mode 100644
index 0000000000..eed9b235e0
--- /dev/null
+++ b/source3/python/py_winbind.c
@@ -0,0 +1,34 @@
+#include "includes.h"
+#include "Python.h"
+#include "python/py_common.h"
+
+/*
+ * Exceptions raised by this module
+ */
+
+PyObject *winbind_error; /* A winbind call returned WINBINDD_ERROR */
+
+/*
+ * Method dispatch table
+ */
+
+static PyMethodDef winbind_methods[] = {
+ { NULL }
+};
+
+/*
+ * Module initialisation
+ */
+
+void initwinbind(void)
+{
+ PyObject *module, *dict;
+
+ /* Initialise module */
+
+ module = Py_InitModule("winbind", winbind_methods);
+ dict = PyModule_GetDict(module);
+
+ winbind_error = PyErr_NewException("winbind.error", NULL, NULL);
+ PyDict_SetItemString(dict, "error", winbind_error);
+}