summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim Potter <tpot@samba.org>2002-03-27 05:33:19 +0000
committerTim Potter <tpot@samba.org>2002-03-27 05:33:19 +0000
commit6deca76e4c5228589ddbf9ad036768ca5423b115 (patch)
treebb6b006a390a60bbd0e97e38abfc3579626c241a
parentb66111f9ba0c1286725a591e7584acc9805b5081 (diff)
downloadsamba-6deca76e4c5228589ddbf9ad036768ca5423b115.tar.gz
samba-6deca76e4c5228589ddbf9ad036768ca5423b115.tar.bz2
samba-6deca76e4c5228589ddbf9ad036768ca5423b115.zip
Broke out stuff into other files.
(This used to be commit 9eb3eb8513e82ec11cb8db671cfb5be45619d3fd)
-rw-r--r--source3/python/py_spoolss.c762
1 files changed, 19 insertions, 743 deletions
diff --git a/source3/python/py_spoolss.c b/source3/python/py_spoolss.c
index 4d64ab0a76..fd05c7e302 100644
--- a/source3/python/py_spoolss.c
+++ b/source3/python/py_spoolss.c
@@ -24,8 +24,6 @@
#include "python/py_common.h"
#include "python/py_conv.h"
#include "python/py_spoolss.h"
-#include "python/py_spoolss_forms.h"
-#include "python/py_spoolss_ports.h"
/* Exceptions this module can raise */
@@ -35,182 +33,6 @@ PyObject *spoolss_error, *spoolss_werror;
* 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 }
-};
-
/* Return a cli_state struct opened on the SPOOLSS pipe. If credentials
are passed use them. */
@@ -218,9 +40,9 @@ 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 cli_state *open_pipe_creds(char *system_name, PyObject *creds,
+ cli_pipe_fn *connect_fn,
+ struct cli_state *cli)
{
struct ntuser_creds nt_creds;
@@ -302,564 +124,15 @@ static PyObject *new_policy_hnd_object(struct cli_state *cli,
return (PyObject*)o;
}
-/* 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)
-{
- spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
- WERROR werror;
- PyObject *result;
- PRINTER_DRIVER_CTR ctr;
- int level = 1;
- uint32 needed;
- char *arch = "Windows NT x86";
- static char *kwlist[] = {"level", "arch", NULL};
-
- /* Parse parameters */
-
- if (!PyArg_ParseTupleAndKeywords(args, kw, "|is", kwlist,
- &level, &arch))
- return NULL;
-
- /* 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)
-{
- spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
- WERROR werror;
- PyObject *result;
- PRINTER_DRIVER_CTR ctr;
- int level = 1, i;
- uint32 needed, num_drivers;
- char *arch = "Windows NT x86";
- static char *kwlist[] = {"level", "arch", NULL};
-
- /* Parse parameters */
-
- if (!PyArg_ParseTupleAndKeywords(args, kw, "|is", kwlist,
- &level, &arch))
- return NULL;
-
- /* 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)
-{
- spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
- WERROR werror;
- PyObject *result;
- PRINTER_INFO_CTR ctr;
- int level = 1;
- uint32 needed;
- static char *kwlist[] = {"level", NULL};
-
- /* Parse parameters */
-
- if (!PyArg_ParseTupleAndKeywords(args, kw, "|i", kwlist, &level))
- return NULL;
-
- /* 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)
-{
- spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self;
- WERROR werror;
- PyObject *result, *info;
- PRINTER_INFO_CTR ctr;
- int level = 1;
- static char *kwlist[] = {"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!|i", kwlist,
- &PyDict_Type, &info, &level))
- return NULL;
-
- /* 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 "py_spoolss_printers.c"
+#include "py_spoolss_drivers.c"
+#include "py_spoolss_ports.c"
+#include "py_spoolss_forms.c"
+
static PyMethodDef spoolss_methods[] = {
/* Open/close printer handles */
@@ -870,16 +143,22 @@ static PyMethodDef spoolss_methods[] = {
{ "closeprinter", spoolss_closeprinter, METH_VARARGS,
"Close printer" },
- /* Enumerate printers */
+ /* Server enumeratation functions */
{ "enumprinters", spoolss_enumprinters, METH_VARARGS | METH_KEYWORDS,
"Enumerate printers" },
- /* Ports */
-
- { "enumports", spoolss_enumports, METH_VARARGS,
+ { "enumports", spoolss_enumports, METH_VARARGS | METH_KEYWORDS,
"Enumerate ports" },
+ { "enumprinterdrivers", spoolss_enumprinterdrivers, METH_VARARGS |
+ METH_KEYWORDS, "Enumerate printer drivers" },
+
+ /* Miscellaneous other commands */
+
+ { "getprinterdriverdir", spoolss_getprinterdriverdir, METH_VARARGS |
+ METH_KEYWORDS, "Get printer driver directory" },
+
{ NULL }
};
@@ -900,9 +179,6 @@ static PyMethodDef spoolss_hnd_methods[] = {
{ "getprinterdriver", spoolss_getprinterdriver,
METH_VARARGS | METH_KEYWORDS, "Fetch printer driver" },
- { "enumprinterdrivers", spoolss_enumprinterdrivers,
- METH_VARARGS | METH_KEYWORDS, "Enumerate printer drivers" },
-
/* Forms */
{ "enumforms", spoolss_enumforms, METH_VARARGS | METH_KEYWORDS,
@@ -937,7 +213,7 @@ static PyObject *py_policy_hnd_getattr(PyObject *self, char *attrname)
PyTypeObject spoolss_policy_hnd_type = {
PyObject_HEAD_INIT(NULL)
0,
- "Policy Handle",
+ "Spoolss Policy Handle",
sizeof(spoolss_policy_hnd_object),
0,
py_policy_hnd_dealloc, /*tp_dealloc*/