diff options
Diffstat (limited to 'source3/python')
-rw-r--r-- | source3/python/.cvsignore | 1 | ||||
-rwxr-xr-x | source3/python/examples/spoolss/changeid.py | 29 | ||||
-rwxr-xr-x | source3/python/examples/spoolss/enumprinters.py | 25 | ||||
-rwxr-xr-x | source3/python/examples/spoolss/psec.py | 87 | ||||
-rwxr-xr-x | source3/python/gtdbtool | 282 | ||||
-rw-r--r-- | source3/python/py_common.c | 255 | ||||
-rw-r--r-- | source3/python/py_conv.c | 159 | ||||
-rw-r--r-- | source3/python/py_conv.h | 40 | ||||
-rw-r--r-- | source3/python/py_samr.c | 456 | ||||
-rw-r--r-- | source3/python/py_spoolss.c | 478 | ||||
-rw-r--r-- | source3/python/py_spoolss_drivers.c | 434 | ||||
-rw-r--r-- | source3/python/py_spoolss_drivers_conv.c | 148 | ||||
-rw-r--r-- | source3/python/py_spoolss_forms.c | 266 | ||||
-rw-r--r-- | source3/python/py_spoolss_jobs.c | 377 | ||||
-rw-r--r-- | source3/python/py_spoolss_printerdata.c | 234 | ||||
-rw-r--r-- | source3/python/py_spoolss_printers.c | 480 | ||||
-rw-r--r-- | source3/python/py_spoolss_printers_conv.c | 296 | ||||
-rw-r--r-- | source3/python/py_spoolss_proto.h | 120 | ||||
-rw-r--r-- | source3/python/py_winbind.c | 651 | ||||
-rw-r--r-- | source3/python/samba-head.patch | 69 | ||||
-rwxr-xr-x | source3/python/setup.py.in | 163 |
21 files changed, 0 insertions, 5050 deletions
diff --git a/source3/python/.cvsignore b/source3/python/.cvsignore deleted file mode 100644 index 659ddbfdf9..0000000000 --- a/source3/python/.cvsignore +++ /dev/null @@ -1 +0,0 @@ -setup.py diff --git a/source3/python/examples/spoolss/changeid.py b/source3/python/examples/spoolss/changeid.py deleted file mode 100755 index b2345094ed..0000000000 --- a/source3/python/examples/spoolss/changeid.py +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/python -# -# Display the changeid for a list of printers given on the command line -# - -import sys, spoolss - -if len(sys.argv) == 1: - print "Usage: changeid.py <printername>" - sys.exit(1) - -for printer in sys.argv[1:]: - - # Open printer handle - - try: - hnd = spoolss.openprinter(printer) - except: - print "error opening printer %s" % printer - sys.exit(1) - - # Fetch and display changeid - - info = hnd.getprinter(level = 0) - print info["change_id"] - - # Clean up - - spoolss.closeprinter(hnd) diff --git a/source3/python/examples/spoolss/enumprinters.py b/source3/python/examples/spoolss/enumprinters.py deleted file mode 100755 index bf08b95bb9..0000000000 --- a/source3/python/examples/spoolss/enumprinters.py +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/env python -# -# Display information on all printers on a print server -# - -import sys, spoolss - -if len(sys.argv) != 2: - print "Usage: changeid.py <printername>" - sys.exit(1) - -printserver = sys.argv[1] - -# Get list of printers - -try: - printer_list = spoolss.enumprinters(printserver) -except: - print "error enumerating printers on %s" % printserver - sys.exit(1) - -# Display basic info - -for printer in printer_list: - print "%s: %s" % (printer["printer_name"], printer["comment"]) diff --git a/source3/python/examples/spoolss/psec.py b/source3/python/examples/spoolss/psec.py deleted file mode 100755 index f3fdb7bccd..0000000000 --- a/source3/python/examples/spoolss/psec.py +++ /dev/null @@ -1,87 +0,0 @@ -#!/usr/bin/env python -# -# Get or set the security descriptor on a printer -# - -import sys, spoolss, re, string - -if len(sys.argv) != 3: - print "Usage: psec.py getsec|setsec printername" - sys.exit(1) - -op = sys.argv[1] -printername = sys.argv[2] - -# Display security descriptor - -if op == "getsec": - - try: - hnd = spoolss.openprinter(printername) - except: - print "error opening printer %s" % printername - sys.exit(1) - - secdesc = hnd.getprinter(level = 3)["security_descriptor"] - - print secdesc["owner_sid"] - print secdesc["group_sid"] - - for acl in secdesc["dacl"]["ace_list"]: - print "%d %d 0x%08x %s" % (acl["type"], acl["flags"], - acl["mask"], acl["trustee"]) - - spoolss.closeprinter(hnd) - - sys.exit(0) - -# Set security descriptor - -if op == "setsec": - - # Open printer - - try: - hnd = spoolss.openprinter(printername, - creds = {"domain": "NPSD-TEST2", - "username": "Administrator", - "password": "penguin"}) - except: - print "error opening printer %s" % printername - sys.exit(1) - - # Read lines from standard input and build security descriptor - - lines = sys.stdin.readlines() - - secdesc = {} - - secdesc["owner_sid"] = lines[0] - secdesc["group_sid"] = lines[1] - - secdesc["revision"] = 1 - secdesc["dacl"] = {} - secdesc["dacl"]["revision"] = 2 - secdesc["dacl"]["ace_list"] = [] - - for acl in lines[2:]: - match = re.match("(\d+) (\d+) (0[xX][\dA-Fa-f]+) (\S+)", acl) - secdesc["dacl"]["ace_list"].append( - {"type": int(match.group(1)), "flags": int(match.group(2)), - "mask": string.atoi(match.group(3), 0), "trustee": match.group(4)}) - - # Build info3 structure - - info3 = {} - - info3["flags"] = 0x8004 # self-relative, dacl present - info3["level"] = 3 - info3["security_descriptor"] = secdesc - - hnd.setprinter(info3) - - spoolss.closeprinter(hnd) - sys.exit(0) - -print "invalid operation %s" % op -sys.exit(1) diff --git a/source3/python/gtdbtool b/source3/python/gtdbtool deleted file mode 100755 index 792cdeecc0..0000000000 --- a/source3/python/gtdbtool +++ /dev/null @@ -1,282 +0,0 @@ -#!/usr/bin/env python - -from gtk import * -import sys -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 - -if len(sys.argv) != 2: - print "Usage: gdbtool <tdbfile>" - sys.exit(1) - -try: - t = tdb.open(sys.argv[1]) -except tdb.error, t: - print "gtdbtool: error opening %s: %s" % (sys.argv[1], t) - sys.exit(1) - -# Create user interface - -w = gtdbtool(t) - -# Set up a key display function. A lot of keys have \x00 appended to the -# end which mucks up gtk. - -def display_key_x00(key): - 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 - -w.build_ui("gtdbtool: %s" % sys.argv[1]) - -# 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() diff --git a/source3/python/py_common.c b/source3/python/py_common.c deleted file mode 100644 index a65206e022..0000000000 --- a/source3/python/py_common.c +++ /dev/null @@ -1,255 +0,0 @@ -/* - 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_proto.h" - -/* Return a tuple of (error code, error string) from a WERROR */ - -PyObject *py_werror_tuple(WERROR werror) -{ - return Py_BuildValue("[is]", W_ERROR_V(werror), - dos_errstr(werror)); -} - -/* Return a tuple of (error code, error string) from a WERROR */ - -PyObject *py_ntstatus_tuple(NTSTATUS ntstatus) -{ - return Py_BuildValue("[is]", NT_STATUS_V(ntstatus), - nt_errstr(ntstatus)); -} - -/* Initialise samba client routines */ - -static BOOL initialised; - -void py_samba_init(void) -{ - extern pstring global_myname; - char *p; - - if (initialised) - return; - - /* 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(); - - fstrcpy(global_myname, myhostname()); - p = strchr(global_myname, '.'); - if (p) - *p = 0; - - initialised = True; -} - -/* Debuglevel routines */ - -PyObject *get_debuglevel(PyObject *self, PyObject *args) -{ - PyObject *debuglevel; - - if (!PyArg_ParseTuple(args, "")) - return NULL; - - debuglevel = PyInt_FromLong(DEBUGLEVEL); - - return debuglevel; -} - -PyObject *set_debuglevel(PyObject *self, PyObject *args) -{ - int debuglevel; - - if (!PyArg_ParseTuple(args, "i", &debuglevel)) - return NULL; - - DEBUGLEVEL = debuglevel; - - Py_INCREF(Py_None); - return Py_None; -} - -/* Initialise logging */ - -PyObject *py_setup_logging(PyObject *self, PyObject *args, PyObject *kw) -{ - BOOL interactive = False; - char *logfilename = NULL; - static char *kwlist[] = {"interactive", "logfilename", NULL}; - - if (!PyArg_ParseTupleAndKeywords( - args, kw, "|is", kwlist, &interactive, &logfilename)) - return NULL; - - if (interactive && logfilename) { - PyErr_SetString(PyExc_RuntimeError, - "can't be interactive and set log file name"); - return NULL; - } - - if (interactive) - setup_logging("spoolss", True); - - if (logfilename) { - lp_set_logfile(logfilename); - setup_logging(logfilename, False); - reopen_logs(); - } - - Py_INCREF(Py_None); - return Py_None; -} - -/* Parse credentials from a python dictionary. The dictionary can - only have the keys "username", "domain" and "password". Return - True for valid credentials in which case the username, domain and - password are set to pointers to their values from the dicationary. - If returns False, the errstr is set to point at some mallocated - memory describing the error. */ - -BOOL py_parse_creds(PyObject *creds, char **username, char **domain, - char **password, char **errstr) -{ - /* Initialise anonymous credentials */ - - *username = ""; - *domain = ""; - *password = ""; - - if (creds && PyDict_Size(creds) > 0) { - PyObject *username_obj, *password_obj, *domain_obj; - - /* Check for presence of required fields */ - - username_obj = PyDict_GetItemString(creds, "username"); - domain_obj = PyDict_GetItemString(creds, "domain"); - password_obj = PyDict_GetItemString(creds, "password"); - - if (!username_obj) { - *errstr = strdup("no username field in credential"); - return False; - } - - if (!domain_obj) { - *errstr = strdup("no domain field in credential"); - return False; - } - - if (!password_obj) { - *errstr = strdup("no password field in credential"); - return False; - } - - /* Look for any other fields */ - - /* Check type of required fields */ - - if (!PyString_Check(username_obj)) { - *errstr = strdup("username field is not string type"); - return False; - } - - if (!PyString_Check(domain_obj)) { - *errstr = strdup("domain field is not string type"); - return False; - } - - if (!PyString_Check(password_obj)) { - *errstr = strdup("password field is not string type"); - return False; - } - - /* Assign values */ - - *username = PyString_AsString(username_obj); - *domain = PyString_AsString(domain_obj); - *password = PyString_AsString(password_obj); - } - - *errstr = NULL; - - return True; -} - -/* Return a cli_state to a RPC pipe on the given server. Use the - credentials passed if not NULL. If an error occurs errstr is set to a - string describing the error and NULL is returned. If set, errstr must - be freed by calling free(). */ - -struct cli_state *open_pipe_creds(char *server, PyObject *creds, - char *pipe_name, char **errstr) -{ - char *username, *password, *domain; - struct cli_state *cli; - NTSTATUS result; - - /* Extract credentials from the python dictionary */ - - if (!py_parse_creds(creds, &username, &password, &domain, errstr)) - return NULL; - - /* Now try to connect */ - - result = cli_full_connection( - &cli, NULL, server, NULL, 0, "IPC$", "IPC", - username, domain, password, 0); - - if (!NT_STATUS_IS_OK(result)) { - *errstr = strdup("error connecting to IPC$ pipe"); - return NULL; - } - - if (!cli_nt_session_open(cli, pipe_name)) { - cli_shutdown(cli); - free(cli); - asprintf(errstr, "error opening %s", pipe_name); - return NULL; - } - - *errstr = NULL; - - return cli; -} - -/* Return true if a dictionary contains a "level" key with an integer - value. Set the value if so. */ - -BOOL get_level_value(PyObject *dict, uint32 *level) -{ - PyObject *obj; - - if (!(obj = PyDict_GetItemString(dict, "level")) || - !PyInt_Check(obj)) - return False; - - if (level) - *level = PyInt_AsLong(obj); - - return True; -} diff --git a/source3/python/py_conv.c b/source3/python/py_conv.c deleted file mode 100644 index 39b20ace86..0000000000 --- a/source3/python/py_conv.c +++ /dev/null @@ -1,159 +0,0 @@ -/* - 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 "py_conv.h" - -/* Helper for rpcstr_pull() function */ - -static void fstr_pull(fstring str, UNISTR *uni) -{ - rpcstr_pull(str, uni->buffer, sizeof(fstring), -1, 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 */ - -BOOL to_struct(void *s, PyObject *dict, struct pyconv *conv) -{ - PyObject *visited, *key, *value; - BOOL result = False; - int i; - - visited = PyDict_New(); - - for (i = 0; conv[i].name; i++) { - PyObject *obj; - - obj = PyDict_GetItemString(dict, conv[i].name); - - if (!obj) - goto done; - - switch (conv[i].type) { - case PY_UNISTR: { - UNISTR *u = (UNISTR *)((char *)s + conv[i].offset); - char *s = ""; - - if (!PyString_Check(obj)) - goto done; - - s = PyString_AsString(obj); - init_unistr(u, s); - - break; - } - case PY_UINT32: { - uint32 *u = (uint32 *)((char *)s + conv[i].offset); - - if (!PyInt_Check(obj)) - goto done; - - *u = PyInt_AsLong(obj); - - break; - } - case PY_UINT16: { - uint16 *u = (uint16 *)((char *)s + conv[i].offset); - - if (!PyInt_Check(obj)) - goto done; - - *u = PyInt_AsLong(obj); - break; - } - default: - break; - } - - /* Mark as visited */ - - PyDict_SetItemString(visited, conv[i].name, - PyInt_FromLong(1)); - } - - /* Iterate over each item in the input dictionary and see if it was - visited. If it wasn't then the user has added some extra crap - to the dictionary. */ - - i = 0; - - while (PyDict_Next(dict, &i, &key, &value)) { - if (!PyDict_GetItem(visited, key)) - goto done; - } - - result = True; - -done: - /* We must decrement the reference count here or the visited - dictionary will not be freed. */ - - Py_DECREF(visited); - - return result; -} diff --git a/source3/python/py_conv.h b/source3/python/py_conv.h deleted file mode 100644 index ed06b9a852..0000000000 --- a/source3/python/py_conv.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - 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_CONV_H -#define _PY_CONV_H - -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 */ -}; - -PyObject *from_struct(void *s, struct pyconv *conv); -BOOL to_struct(void *s, PyObject *dict, struct pyconv *conv); - -/* Another version of offsetof (-: */ - -#undef offsetof -#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER) - -#endif /* _PY_CONV_H */ diff --git a/source3/python/py_samr.c b/source3/python/py_samr.c deleted file mode 100644 index ce6eda99c2..0000000000 --- a/source3/python/py_samr.c +++ /dev/null @@ -1,456 +0,0 @@ -/* - 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" - -/* - * Exceptions raised by this module - */ - -PyObject *samr_error; /* This indicates a non-RPC related error - such as name lookup failure */ - -PyObject *samr_ntstatus; /* This exception is raised when a RPC call - returns a status code other than - NT_STATUS_OK */ - -/* SAMR connect handle object */ - -static void py_samr_connect_hnd_dealloc(PyObject* self) -{ - PyObject_Del(self); -} - -PyObject *new_samr_domain_hnd_object(struct cli_state *cli, TALLOC_CTX *mem_ctx, - POLICY_HND *pol) -{ - samr_domain_hnd_object *o; - - o = PyObject_New(samr_domain_hnd_object, &samr_domain_hnd_type); - - o->cli = cli; - o->mem_ctx = mem_ctx; - memcpy(&o->domain_pol, pol, sizeof(POLICY_HND)); - - return (PyObject*)o; -} - -static PyObject *samr_open_domain(PyObject *self, PyObject *args, PyObject *kw) -{ - samr_connect_hnd_object *connect_hnd = (samr_connect_hnd_object *)self; - static char *kwlist[] = { "sid", "access", NULL }; - uint32 desired_access = MAXIMUM_ALLOWED_ACCESS; - char *sid_str; - DOM_SID sid; - TALLOC_CTX *mem_ctx = NULL; - POLICY_HND domain_pol; - NTSTATUS ntstatus; - PyObject *result = NULL; - - if (!PyArg_ParseTupleAndKeywords( - args, kw, "s|i", kwlist, &sid_str, &desired_access)) - return NULL; - - if (!string_to_sid(&sid, sid_str)) { - PyErr_SetString(PyExc_TypeError, "string is not a sid"); - return NULL; - } - - if (!(mem_ctx = talloc_init())) { - PyErr_SetString(samr_error, "unable to init talloc context"); - return NULL; - } - - ntstatus = cli_samr_open_domain( - connect_hnd->cli, mem_ctx, &connect_hnd->connect_pol, - desired_access, &sid, &domain_pol); - - if (!NT_STATUS_IS_OK(ntstatus)) { - PyErr_SetObject(samr_ntstatus, py_ntstatus_tuple(ntstatus)); - goto done; - } - - result = new_samr_domain_hnd_object( - connect_hnd->cli, mem_ctx, &domain_pol); - -done: - if (!result) { - if (mem_ctx) - talloc_destroy(mem_ctx); - } - - return result; -} - -static PyMethodDef samr_connect_methods[] = { - { "open_domain", (PyCFunction)samr_open_domain, - METH_VARARGS | METH_KEYWORDS, - "Open a handle on a domain" }, - - { NULL } -}; - -static PyObject *py_samr_connect_hnd_getattr(PyObject *self, char *attrname) -{ - return Py_FindMethod(samr_connect_methods, self, attrname); -} - -PyTypeObject samr_connect_hnd_type = { - PyObject_HEAD_INIT(NULL) - 0, - "SAMR Connect Handle", - sizeof(samr_connect_hnd_object), - 0, - py_samr_connect_hnd_dealloc, /*tp_dealloc*/ - 0, /*tp_print*/ - py_samr_connect_hnd_getattr, /*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 */ -}; - -PyObject *new_samr_connect_hnd_object(struct cli_state *cli, TALLOC_CTX *mem_ctx, - POLICY_HND *pol) -{ - samr_connect_hnd_object *o; - - o = PyObject_New(samr_connect_hnd_object, &samr_connect_hnd_type); - - o->cli = cli; - o->mem_ctx = mem_ctx; - memcpy(&o->connect_pol, pol, sizeof(POLICY_HND)); - - return (PyObject*)o; -} - -/* SAMR domain handle object */ - -static void py_samr_domain_hnd_dealloc(PyObject* self) -{ - PyObject_Del(self); -} - -static PyMethodDef samr_domain_methods[] = { - { NULL } -}; - -static PyObject *py_samr_domain_hnd_getattr(PyObject *self, char *attrname) -{ - return Py_FindMethod(samr_domain_methods, self, attrname); -} - -PyTypeObject samr_domain_hnd_type = { - PyObject_HEAD_INIT(NULL) - 0, - "SAMR Domain Handle", - sizeof(samr_domain_hnd_object), - 0, - py_samr_domain_hnd_dealloc, /*tp_dealloc*/ - 0, /*tp_print*/ - py_samr_domain_hnd_getattr, /*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 */ -}; - -/* SAMR user handle object */ - -static void py_samr_user_hnd_dealloc(PyObject* self) -{ - PyObject_Del(self); -} - -static PyMethodDef samr_user_methods[] = { - { NULL } -}; - -static PyObject *py_samr_user_hnd_getattr(PyObject *self, char *attrname) -{ - return Py_FindMethod(samr_user_methods, self, attrname); -} - -PyTypeObject samr_user_hnd_type = { - PyObject_HEAD_INIT(NULL) - 0, - "SAMR User Handle", - sizeof(samr_user_hnd_object), - 0, - py_samr_user_hnd_dealloc, /*tp_dealloc*/ - 0, /*tp_print*/ - py_samr_user_hnd_getattr, /*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 */ -}; - -PyObject *new_samr_user_hnd_object(struct cli_state *cli, TALLOC_CTX *mem_ctx, - POLICY_HND *pol) -{ - samr_user_hnd_object *o; - - o = PyObject_New(samr_user_hnd_object, &samr_user_hnd_type); - - o->cli = cli; - o->mem_ctx = mem_ctx; - memcpy(&o->user_pol, pol, sizeof(POLICY_HND)); - - return (PyObject*)o; -} - -/* SAMR group handle object */ - -static void py_samr_group_hnd_dealloc(PyObject* self) -{ - PyObject_Del(self); -} - -static PyMethodDef samr_group_methods[] = { - { NULL } -}; - -static PyObject *py_samr_group_hnd_getattr(PyObject *self, char *attrname) -{ - return Py_FindMethod(samr_group_methods, self, attrname); -} - -PyTypeObject samr_group_hnd_type = { - PyObject_HEAD_INIT(NULL) - 0, - "SAMR Group Handle", - sizeof(samr_group_hnd_object), - 0, - py_samr_group_hnd_dealloc, /*tp_dealloc*/ - 0, /*tp_print*/ - py_samr_group_hnd_getattr, /*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 */ -}; - -PyObject *new_samr_group_hnd_object(struct cli_state *cli, TALLOC_CTX *mem_ctx, - POLICY_HND *pol) -{ - samr_group_hnd_object *o; - - o = PyObject_New(samr_group_hnd_object, &samr_group_hnd_type); - - o->cli = cli; - o->mem_ctx = mem_ctx; - memcpy(&o->group_pol, pol, sizeof(POLICY_HND)); - - return (PyObject*)o; -} - -/* Alias handle object */ - -static void py_samr_alias_hnd_dealloc(PyObject* self) -{ - PyObject_Del(self); -} - -static PyMethodDef samr_alias_methods[] = { - { NULL } -}; - -static PyObject *py_samr_alias_hnd_getattr(PyObject *self, char *attrname) -{ - return Py_FindMethod(samr_alias_methods, self, attrname); -} - -PyTypeObject samr_alias_hnd_type = { - PyObject_HEAD_INIT(NULL) - 0, - "SAMR Alias Handle", - sizeof(samr_alias_hnd_object), - 0, - py_samr_alias_hnd_dealloc, /*tp_dealloc*/ - 0, /*tp_print*/ - py_samr_alias_hnd_getattr, /*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 */ -}; - -PyObject *new_samr_alias_hnd_object(struct cli_state *cli, TALLOC_CTX *mem_ctx, - POLICY_HND *pol) -{ - samr_alias_hnd_object *o; - - o = PyObject_New(samr_alias_hnd_object, &samr_alias_hnd_type); - - o->cli = cli; - o->mem_ctx = mem_ctx; - memcpy(&o->alias_pol, pol, sizeof(POLICY_HND)); - - return (PyObject*)o; -} - -static PyObject *samr_connect(PyObject *self, PyObject *args, PyObject *kw) -{ - static char *kwlist[] = { "server", "creds", "access", NULL }; - uint32 desired_access = MAXIMUM_ALLOWED_ACCESS; - char *server, *errstr; - struct cli_state *cli = NULL; - POLICY_HND hnd; - TALLOC_CTX *mem_ctx = NULL; - PyObject *result = NULL, *creds = NULL; - NTSTATUS ntstatus; - - if (!PyArg_ParseTupleAndKeywords( - args, kw, "s|Oi", kwlist, &server, &creds, - &desired_access)) - return NULL; - - if (server[0] != '\\' || server[1] != '\\') { - PyErr_SetString(PyExc_ValueError, "UNC name required"); - return NULL; - } - - server += 2; - - if (creds && creds != Py_None && !PyDict_Check(creds)) { - PyErr_SetString(PyExc_TypeError, - "credentials must be dictionary or None"); - return NULL; - } - - if (!(cli = open_pipe_creds(server, creds, PIPE_SAMR, &errstr))) { - PyErr_SetString(samr_error, errstr); - free(errstr); - return NULL; - } - - if (!(mem_ctx = talloc_init())) { - PyErr_SetString(samr_ntstatus, - "unable to init talloc context\n"); - goto done; - } - - ntstatus = cli_samr_connect(cli, mem_ctx, desired_access, &hnd); - - if (!NT_STATUS_IS_OK(ntstatus)) { - cli_shutdown(cli); - SAFE_FREE(cli); - PyErr_SetObject(samr_ntstatus, py_ntstatus_tuple(ntstatus)); - goto done; - } - - result = new_samr_connect_hnd_object(cli, mem_ctx, &hnd); - -done: - if (!result) { - if (cli) - cli_shutdown(cli); - - if (mem_ctx) - talloc_destroy(mem_ctx); - } - - return result; -} - -/* - * Module initialisation - */ - -static PyMethodDef samr_methods[] = { - - /* Open/close samr connect handles */ - - { "connect", (PyCFunction)samr_connect, - METH_VARARGS | METH_KEYWORDS, - "Open a connect handle" }, - - { NULL } -}; - -static struct const_vals { - char *name; - uint32 value; -} module_const_vals[] = { - { NULL } -}; - -static void const_init(PyObject *dict) -{ - struct const_vals *tmp; - PyObject *obj; - - for (tmp = module_const_vals; tmp->name; tmp++) { - obj = PyInt_FromLong(tmp->value); - PyDict_SetItemString(dict, tmp->name, obj); - Py_DECREF(obj); - } -} - -void initsamr(void) -{ - PyObject *module, *dict; - - /* Initialise module */ - - module = Py_InitModule("samr", samr_methods); - dict = PyModule_GetDict(module); - - samr_error = PyErr_NewException("samr.error", NULL, NULL); - PyDict_SetItemString(dict, "error", samr_error); - - samr_ntstatus = PyErr_NewException("samr.ntstatus", NULL, NULL); - PyDict_SetItemString(dict, "ntstatus", samr_ntstatus); - - /* Initialise policy handle object */ - - samr_connect_hnd_type.ob_type = &PyType_Type; - samr_domain_hnd_type.ob_type = &PyType_Type; - samr_user_hnd_type.ob_type = &PyType_Type; - samr_group_hnd_type.ob_type = &PyType_Type; - samr_alias_hnd_type.ob_type = &PyType_Type; - - /* Initialise constants */ - - const_init(dict); - - /* Do samba initialisation */ - - py_samba_init(); - - setup_logging("samr", True); - DEBUGLEVEL = 10; -} diff --git a/source3/python/py_spoolss.c b/source3/python/py_spoolss.c deleted file mode 100644 index 95be77de55..0000000000 --- a/source3/python/py_spoolss.c +++ /dev/null @@ -1,478 +0,0 @@ -/* - 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_spoolss.h" - -/* Exceptions this module can raise */ - -PyObject *spoolss_error, *spoolss_werror; - -/* - * Routines to convert from python hashes to Samba structures - */ - -PyObject *new_spoolss_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; -} - -/* - * Method dispatch table - */ - -static PyMethodDef spoolss_methods[] = { - - /* Open/close printer handles */ - - { "openprinter", (PyCFunction)spoolss_openprinter, METH_VARARGS | METH_KEYWORDS, - "Open a printer by name in UNC format. - -Optionally a dictionary of (domain, username, password) may be given in -which case they are used when opening the RPC pipe. An access mask may -also be given which defaults to MAXIMUM_ALLOWED_ACCESS. - -Example: - ->>> hnd = spoolss.openprinter(\"\\\\\\\\NPSD-PDC2\\\\meanie\")"}, - - { "closeprinter", spoolss_closeprinter, METH_VARARGS, - "Close a printer handle opened with openprinter or addprinter. - -Example: - ->>> spoolss.closeprinter(hnd)"}, - - { "addprinterex", (PyCFunction)spoolss_addprinterex, METH_VARARGS, - "addprinterex()"}, - - /* Server enumeratation functions */ - - { "enumprinters", (PyCFunction)spoolss_enumprinters, - METH_VARARGS | METH_KEYWORDS, - "Enumerate printers on a print server. - -Return a list of printers on a print server. The credentials, info level -and flags may be specified as keyword arguments. - -Example: - ->>> print spoolss.enumprinters(\"\\\\\\\\npsd-pdc2\") -[{'comment': 'i am a comment', 'printer_name': 'meanie', 'flags': 8388608, - 'description': 'meanie,Generic / Text Only,i am a location'}, - {'comment': '', 'printer_name': 'fileprint', 'flags': 8388608, - 'description': 'fileprint,Generic / Text Only,'}]"}, - - { "enumports", (PyCFunction)spoolss_enumports, - METH_VARARGS | METH_KEYWORDS, - "Enumerate ports on a print server. - -Return a list of ports on a print server. - -Example: - ->>> print spoolss.enumports(\"\\\\\\\\npsd-pdc2\") -[{'name': 'LPT1:'}, {'name': 'LPT2:'}, {'name': 'COM1:'}, {'name': 'COM2:'}, - {'name': 'FILE:'}, {'name': '\\\\nautilus1\\zpekt3r'}]"}, - - { "enumprinterdrivers", (PyCFunction)spoolss_enumprinterdrivers, - METH_VARARGS | METH_KEYWORDS, - "Enumerate printer drivers on a print server. - -Return a list of printer drivers."}, - /* Miscellaneous other commands */ - - { "getprinterdriverdir", (PyCFunction)spoolss_getprinterdriverdir, - METH_VARARGS | METH_KEYWORDS, - "Return printer driver directory. - -Return the printer driver directory for a given architecture. The -architecture defaults to \"Windows NT x86\"."}, - - /* Other stuff - this should really go into a samba config module - but for the moment let's leave it here. */ - - { "setup_logging", (PyCFunction)py_setup_logging, - METH_VARARGS | METH_KEYWORDS, - "Set up debug logging. - -Initialises Samba's debug logging system. One argument is expected which -is a boolean specifying whether debugging is interactive and sent to stdout -or logged to a file. - -Example: - ->>> spoolss.setup_logging(interactive = 1)" }, - - { "get_debuglevel", (PyCFunction)get_debuglevel, - METH_VARARGS, - "Set the current debug level. - -Example: - ->>> spoolss.get_debuglevel() -0" }, - - { "set_debuglevel", (PyCFunction)set_debuglevel, - METH_VARARGS, - "Get the current debug level. - -Example: - ->>> spoolss.set_debuglevel(10)" }, - - /* Printer driver routines */ - - { "addprinterdriver", (PyCFunction)spoolss_addprinterdriver, - METH_VARARGS | METH_KEYWORDS, - "Add a printer driver." }, - - { "addprinterdriverex", (PyCFunction)spoolss_addprinterdriverex, - METH_VARARGS | METH_KEYWORDS, - "Add a printer driver." }, - - { "deleteprinterdriver", (PyCFunction)spoolss_deleteprinterdriver, - METH_VARARGS | METH_KEYWORDS, - "Delete a printer driver." }, - - { "deleteprinterdriverex", (PyCFunction)spoolss_deleteprinterdriverex, - METH_VARARGS | METH_KEYWORDS, - "Delete a printer driver." }, - - { NULL } -}; - -/* Methods attached to a spoolss handle object */ - -static PyMethodDef spoolss_hnd_methods[] = { - - /* Printer info */ - - { "getprinter", (PyCFunction)spoolss_hnd_getprinter, - METH_VARARGS | METH_KEYWORDS, - "Get printer information. - -Return a dictionary of print information. The info level defaults to 1. - -Example: - ->>> hnd.getprinter() -{'comment': 'i am a comment', 'printer_name': '\\\\NPSD-PDC2\\meanie', - 'description': '\\\\NPSD-PDC2\\meanie,Generic / Text Only,i am a location', - 'flags': 8388608}"}, - - { "setprinter", (PyCFunction)spoolss_hnd_setprinter, - METH_VARARGS | METH_KEYWORDS, - "Set printer information."}, - - /* Printer drivers */ - - { "getprinterdriver", (PyCFunction)spoolss_hnd_getprinterdriver, - METH_VARARGS | METH_KEYWORDS, - "Return printer driver information. - -Return a dictionary of printer driver information for the printer driver -bound to this printer."}, - - /* Forms */ - - { "enumforms", (PyCFunction)spoolss_hnd_enumforms, - METH_VARARGS | METH_KEYWORDS, - "Enumerate supported forms. - -Return a list of forms supported by this printer or print server."}, - - { "setform", (PyCFunction)spoolss_hnd_setform, - METH_VARARGS | METH_KEYWORDS, - "Set form data. - -Set the form given by the dictionary argument."}, - - { "addform", (PyCFunction)spoolss_hnd_addform, - METH_VARARGS | METH_KEYWORDS, - "Add a new form." }, - - { "getform", (PyCFunction)spoolss_hnd_getform, - METH_VARARGS | METH_KEYWORDS, - "Get form properties." }, - - { "deleteform", (PyCFunction)spoolss_hnd_deleteform, - METH_VARARGS | METH_KEYWORDS, - "Delete a form." }, - - /* Job related methods */ - - { "enumjobs", (PyCFunction)spoolss_hnd_enumjobs, - METH_VARARGS | METH_KEYWORDS, - "Enumerate jobs." }, - - { "setjob", (PyCFunction)spoolss_hnd_setjob, - METH_VARARGS | METH_KEYWORDS, - "Set job information." }, - - { "getjob", (PyCFunction)spoolss_hnd_getjob, - METH_VARARGS | METH_KEYWORDS, - "Get job information." }, - - { "startpageprinter", (PyCFunction)spoolss_hnd_startpageprinter, - METH_VARARGS | METH_KEYWORDS, - "Notify spooler that a page is about to be printed." }, - - { "endpageprinter", (PyCFunction)spoolss_hnd_endpageprinter, - METH_VARARGS | METH_KEYWORDS, - "Notify spooler that a page is about to be printed." }, - - { "startdocprinter", (PyCFunction)spoolss_hnd_startdocprinter, - METH_VARARGS | METH_KEYWORDS, - "Notify spooler that a document is about to be printed." }, - - { "enddocprinter", (PyCFunction)spoolss_hnd_enddocprinter, - METH_VARARGS | METH_KEYWORDS, - "Notify spooler that a document is about to be printed." }, - - { "writeprinter", (PyCFunction)spoolss_hnd_writeprinter, - METH_VARARGS | METH_KEYWORDS, - "Write job data to a printer." }, - - { "addjob", (PyCFunction)spoolss_hnd_addjob, - METH_VARARGS | METH_KEYWORDS, - "Add a job to the list of print jobs." }, - - /* Printer data */ - - { "getprinterdata", (PyCFunction)spoolss_hnd_getprinterdata, - METH_VARARGS | METH_KEYWORDS, - "Get printer data." }, - - { "setprinterdata", (PyCFunction)spoolss_hnd_setprinterdata, - METH_VARARGS | METH_KEYWORDS, - "Set printer data." }, - - { "enumprinterdata", (PyCFunction)spoolss_hnd_enumprinterdata, - METH_VARARGS | METH_KEYWORDS, - "Enumerate printer data." }, - - { "deleteprinterdata", (PyCFunction)spoolss_hnd_deleteprinterdata, - METH_VARARGS | METH_KEYWORDS, - "Delete printer data." }, - - { "deleteprinterdataex", (PyCFunction)spoolss_hnd_deleteprinterdataex, - METH_VARARGS | METH_KEYWORDS, - "Delete printer data." }, - - { NULL } - -}; - -static void py_policy_hnd_dealloc(PyObject* self) -{ - spoolss_policy_hnd_object *hnd; - - /* Close down policy handle and free talloc context */ - - hnd = (spoolss_policy_hnd_object*)self; - - cli_shutdown(hnd->cli); - talloc_destroy(hnd->mem_ctx); - - PyObject_Del(self); -} - -static PyObject *py_policy_hnd_getattr(PyObject *self, char *attrname) -{ - return Py_FindMethod(spoolss_hnd_methods, self, attrname); -} - -static char spoolss_type_doc[] = -"Python wrapper for Windows NT SPOOLSS rpc pipe."; - -PyTypeObject spoolss_policy_hnd_type = { - PyObject_HEAD_INIT(NULL) - 0, - "spoolss.hnd", - sizeof(spoolss_policy_hnd_object), - 0, - py_policy_hnd_dealloc, /* tp_dealloc*/ - 0, /* tp_print*/ - py_policy_hnd_getattr, /* 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 */ - 0, /* tp_call */ - 0, /* tp_str */ - 0, /* tp_getattro */ - 0, /* tp_setattro */ - 0, /* tp_as_buffer*/ - Py_TPFLAGS_DEFAULT, /* tp_flags */ - spoolss_type_doc, /* tp_doc */ -}; - -/* Initialise constants */ - -static struct const_vals { - char *name; - uint32 value; -} module_const_vals[] = { - - /* Access permissions */ - - { "MAXIMUM_ALLOWED_ACCESS", MAXIMUM_ALLOWED_ACCESS }, - { "SERVER_ALL_ACCESS", SERVER_ALL_ACCESS }, - { "SERVER_READ", SERVER_READ }, - { "SERVER_WRITE", SERVER_WRITE }, - { "SERVER_EXECUTE", SERVER_EXECUTE }, - { "SERVER_ACCESS_ADMINISTER", SERVER_ACCESS_ADMINISTER }, - { "SERVER_ACCESS_ENUMERATE", SERVER_ACCESS_ENUMERATE }, - { "PRINTER_ALL_ACCESS", PRINTER_ALL_ACCESS }, - { "PRINTER_READ", PRINTER_READ }, - { "PRINTER_WRITE", PRINTER_WRITE }, - { "PRINTER_EXECUTE", PRINTER_EXECUTE }, - { "PRINTER_ACCESS_ADMINISTER", PRINTER_ACCESS_ADMINISTER }, - { "PRINTER_ACCESS_USE", PRINTER_ACCESS_USE }, - { "JOB_ACCESS_ADMINISTER", JOB_ACCESS_ADMINISTER }, - { "JOB_ALL_ACCESS", JOB_ALL_ACCESS }, - { "JOB_READ", JOB_READ }, - { "JOB_WRITE", JOB_WRITE }, - { "JOB_EXECUTE", JOB_EXECUTE }, - { "STANDARD_RIGHTS_ALL_ACCESS", STANDARD_RIGHTS_ALL_ACCESS }, - { "STANDARD_RIGHTS_EXECUTE_ACCESS", STANDARD_RIGHTS_EXECUTE_ACCESS }, - { "STANDARD_RIGHTS_READ_ACCESS", STANDARD_RIGHTS_READ_ACCESS }, - { "STANDARD_RIGHTS_REQUIRED_ACCESS", STANDARD_RIGHTS_REQUIRED_ACCESS }, - { "STANDARD_RIGHTS_WRITE_ACCESS", STANDARD_RIGHTS_WRITE_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 }, - - /* Form types */ - - { "FORM_USER", FORM_USER }, - { "FORM_BUILTIN", FORM_BUILTIN }, - { "FORM_PRINTER", FORM_PRINTER }, - - /* WERRORs */ - - { "WERR_OK", 0 }, - { "WERR_BADFILE", 2 }, - { "WERR_ACCESS_DENIED", 5 }, - { "WERR_BADFID", 6 }, - { "WERR_BADFUNC", 1 }, - { "WERR_INSUFFICIENT_BUFFER", 122 }, - { "WERR_NO_SUCH_SHARE", 67 }, - { "WERR_ALREADY_EXISTS", 80 }, - { "WERR_INVALID_PARAM", 87 }, - { "WERR_NOT_SUPPORTED", 50 }, - { "WERR_BAD_PASSWORD", 86 }, - { "WERR_NOMEM", 8 }, - { "WERR_INVALID_NAME", 123 }, - { "WERR_UNKNOWN_LEVEL", 124 }, - { "WERR_OBJECT_PATH_INVALID", 161 }, - { "WERR_NO_MORE_ITEMS", 259 }, - { "WERR_MORE_DATA", 234 }, - { "WERR_UNKNOWN_PRINTER_DRIVER", 1797 }, - { "WERR_INVALID_PRINTER_NAME", 1801 }, - { "WERR_PRINTER_ALREADY_EXISTS", 1802 }, - { "WERR_INVALID_DATATYPE", 1804 }, - { "WERR_INVALID_ENVIRONMENT", 1805 }, - { "WERR_INVALID_FORM_NAME", 1902 }, - { "WERR_INVALID_FORM_SIZE", 1903 }, - { "WERR_BUF_TOO_SMALL", 2123 }, - { "WERR_JOB_NOT_FOUND", 2151 }, - { "WERR_DEST_NOT_FOUND", 2152 }, - { "WERR_NOT_LOCAL_DOMAIN", 2320 }, - { "WERR_PRINTER_DRIVER_IN_USE", 3001 }, - { "WERR_STATUS_MORE_ENTRIES ", 0x0105 }, - - /* Job control constants */ - - { "JOB_CONTROL_PAUSE", JOB_CONTROL_PAUSE }, - { "JOB_CONTROL_RESUME", JOB_CONTROL_RESUME }, - { "JOB_CONTROL_CANCEL", JOB_CONTROL_CANCEL }, - { "JOB_CONTROL_RESTART", JOB_CONTROL_RESTART }, - { "JOB_CONTROL_DELETE", JOB_CONTROL_DELETE }, - - { NULL }, -}; - -static void const_init(PyObject *dict) -{ - struct const_vals *tmp; - PyObject *obj; - - for (tmp = module_const_vals; tmp->name; tmp++) { - obj = PyInt_FromLong(tmp->value); - PyDict_SetItemString(dict, tmp->name, obj); - Py_DECREF(obj); - } -} - -/* Module initialisation */ - -void initspoolss(void) -{ - PyObject *module, *dict; - - /* Initialise module */ - - module = Py_InitModule("spoolss", spoolss_methods); - dict = PyModule_GetDict(module); - - /* Exceptions we can raise */ - - 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; - - PyDict_SetItemString(dict, "spoolss.hnd", - (PyObject *)&spoolss_policy_hnd_type); - - /* Initialise constants */ - - const_init(dict); - - /* Do samba initialisation */ - - py_samba_init(); -} diff --git a/source3/python/py_spoolss_drivers.c b/source3/python/py_spoolss_drivers.c deleted file mode 100644 index b5357a78ad..0000000000 --- a/source3/python/py_spoolss_drivers.c +++ /dev/null @@ -1,434 +0,0 @@ -/* - 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_spoolss.h" - -/* Enumerate printer drivers */ - -PyObject *spoolss_enumprinterdrivers(PyObject *self, PyObject *args, - PyObject *kw) -{ - WERROR werror; - PyObject *result = NULL, *creds = NULL; - PRINTER_DRIVER_CTR ctr; - int level = 1, i; - uint32 needed, num_drivers; - char *arch = "Windows NT x86", *server, *errstr; - static char *kwlist[] = {"server", "level", "creds", "arch", NULL}; - struct cli_state *cli = NULL; - TALLOC_CTX *mem_ctx = NULL; - - /* Parse parameters */ - - if (!PyArg_ParseTupleAndKeywords( - args, kw, "s|iOs", kwlist, &server, &level, &creds, - &arch)) - return NULL; - - if (server[0] != '\\' || server[1] != '\\') { - PyErr_SetString(PyExc_ValueError, "UNC name required"); - return NULL; - } - - server += 2; - - if (creds && creds != Py_None && !PyDict_Check(creds)) { - PyErr_SetString(PyExc_TypeError, - "credentials must be dictionary or None"); - return NULL; - } - - /* Call rpc function */ - - if (!(cli = open_pipe_creds(server, creds, PIPE_SPOOLSS, &errstr))) { - PyErr_SetString(spoolss_error, errstr); - free(errstr); - goto done; - } - - if (!(mem_ctx = talloc_init())) { - PyErr_SetString( - spoolss_error, "unable to init talloc context\n"); - goto done; - } - - werror = cli_spoolss_enumprinterdrivers( - cli, mem_ctx, 0, &needed, level, arch, - &num_drivers, &ctr); - - if (W_ERROR_V(werror) == ERRinsufficientbuffer) - werror = cli_spoolss_enumprinterdrivers( - cli, mem_ctx, needed, NULL, level, arch, - &num_drivers, &ctr); - - if (!W_ERROR_IS_OK(werror)) { - PyErr_SetObject(spoolss_werror, py_werror_tuple(werror)); - goto done; - } - - /* Return value */ - - switch (level) { - case 1: - result = PyDict_New(); - - for (i = 0; i < num_drivers; i++) { - PyObject *value; - fstring name; - - rpcstr_pull(name, ctr.info1[i].name.buffer, - sizeof(fstring), -1, STR_TERMINATE); - - py_from_DRIVER_INFO_1(&value, &ctr.info1[i]); - - PyDict_SetItemString( - value, "level", PyInt_FromLong(1)); - - PyDict_SetItemString(result, name, value); - } - - break; - case 2: - result = PyDict_New(); - - for(i = 0; i < num_drivers; i++) { - PyObject *value; - fstring name; - - rpcstr_pull(name, ctr.info2[i].name.buffer, - sizeof(fstring), -1, STR_TERMINATE); - - py_from_DRIVER_INFO_2(&value, &ctr.info2[i]); - - PyDict_SetItemString( - value, "level", PyInt_FromLong(2)); - - PyDict_SetItemString(result, name, value); - } - - break; - case 3: - result = PyDict_New(); - - for(i = 0; i < num_drivers; i++) { - PyObject *value; - fstring name; - - rpcstr_pull(name, ctr.info3[i].name.buffer, - sizeof(fstring), -1, STR_TERMINATE); - - py_from_DRIVER_INFO_3(&value, &ctr.info3[i]); - - PyDict_SetItemString( - value, "level", PyInt_FromLong(3)); - - PyDict_SetItemString(result, name, value); - } - - break; - case 6: - result = PyDict_New(); - - for(i = 0; i < num_drivers; i++) { - PyObject *value; - fstring name; - - rpcstr_pull(name, ctr.info6[i].name.buffer, - sizeof(fstring), -1, STR_TERMINATE); - - py_from_DRIVER_INFO_6(&value, &ctr.info6[i]); - - PyDict_SetItemString( - value, "level", PyInt_FromLong(6)); - - PyList_SetItem(result, i, value); - } - - break; - default: - PyErr_SetString(spoolss_error, "unknown info level"); - goto done; - } - - done: - if (cli) - cli_shutdown(cli); - - if (mem_ctx) - talloc_destroy(mem_ctx); - - return result; -} - -/* Fetch printer driver */ - -PyObject *spoolss_hnd_getprinterdriver(PyObject *self, PyObject *args, - PyObject *kw) -{ - spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self; - WERROR werror; - PyObject *result = Py_None; - 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); - - if (!W_ERROR_IS_OK(werror)) { - PyErr_SetObject(spoolss_werror, py_werror_tuple(werror)); - return NULL; - } - - /* Return value */ - - switch (level) { - case 1: - py_from_DRIVER_INFO_1(&result, ctr.info1); - break; - case 2: - py_from_DRIVER_INFO_2(&result, ctr.info2); - break; - case 3: - py_from_DRIVER_INFO_3(&result, ctr.info3); - break; - case 6: - py_from_DRIVER_INFO_6(&result, ctr.info6); - break; - default: - PyErr_SetString(spoolss_error, "unsupported info level"); - return NULL; - } - - Py_INCREF(result); - return result; -} - -/* Fetch printer driver directory */ - -PyObject *spoolss_getprinterdriverdir(PyObject *self, PyObject *args, - PyObject *kw) -{ - WERROR werror; - PyObject *result = NULL, *creds = NULL; - DRIVER_DIRECTORY_CTR ctr; - uint32 needed, level = 1; - char *arch = "Windows NT x86", *server, *errstr; - static char *kwlist[] = {"server", "level", "arch", "creds", NULL}; - struct cli_state *cli = NULL; - TALLOC_CTX *mem_ctx = NULL; - - /* Parse parameters */ - - if (!PyArg_ParseTupleAndKeywords( - args, kw, "s|isO", kwlist, &server, &level, - &arch, &creds)) - return NULL; - - if (server[0] != '\\' || server[1] != '\\') { - PyErr_SetString(PyExc_ValueError, "UNC name required"); - return NULL; - } - - server += 2; - - if (creds && creds != Py_None && !PyDict_Check(creds)) { - PyErr_SetString(PyExc_TypeError, - "credentials must be dictionary or None"); - return NULL; - } - - /* Call rpc function */ - - if (!(cli = open_pipe_creds(server, creds, PIPE_SPOOLSS, &errstr))) { - PyErr_SetString(spoolss_error, errstr); - free(errstr); - goto done; - } - - if (!(mem_ctx = talloc_init())) { - PyErr_SetString( - spoolss_error, "unable to init talloc context\n"); - goto done; - } - - werror = cli_spoolss_getprinterdriverdir( - cli, mem_ctx, 0, &needed, level, arch, &ctr); - - if (W_ERROR_V(werror) == ERRinsufficientbuffer) - werror = cli_spoolss_getprinterdriverdir( - cli, mem_ctx, needed, NULL, level, arch, &ctr); - - if (!W_ERROR_IS_OK(werror)) { - PyErr_SetObject(spoolss_werror, py_werror_tuple(werror)); - goto done; - } - - /* Return value */ - - 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"); - goto done; - } - - done: - if (cli) - cli_shutdown(cli); - - if (mem_ctx) - talloc_destroy(mem_ctx); - - return result; -} - -PyObject *spoolss_addprinterdriver(PyObject *self, PyObject *args, - PyObject *kw) -{ - static char *kwlist[] = { "server", "info", "creds", NULL }; - char *server, *errstr; - uint32 level; - PyObject *info, *result = NULL, *creds = NULL; - WERROR werror; - TALLOC_CTX *mem_ctx = NULL; - struct cli_state *cli = NULL; - PRINTER_DRIVER_CTR ctr; - union { - DRIVER_INFO_3 driver_3; - } dinfo; - - if (!PyArg_ParseTupleAndKeywords( - args, kw, "sO!|O", kwlist, &server, &PyDict_Type, - &info, &creds)) - return NULL; - - if (server[0] == '\\' || server[1] == '\\') - server += 2; - - if (creds && creds != Py_None && !PyDict_Check(creds)) { - PyErr_SetString(PyExc_TypeError, - "credentials must be dictionary or None"); - return NULL; - } - - if (!(mem_ctx = talloc_init())) { - PyErr_SetString( - spoolss_error, "unable to init talloc context\n"); - return NULL; - } - - if (!(cli = open_pipe_creds(server, creds, PIPE_SPOOLSS, &errstr))) { - PyErr_SetString(spoolss_error, errstr); - free(errstr); - goto done; - } - - if (!get_level_value(info, &level)) { - PyErr_SetString(spoolss_error, "invalid info level"); - goto done; - } - - if (level != 3) { - PyErr_SetString(spoolss_error, "unsupported info level"); - goto done; - } - - ZERO_STRUCT(ctr); - - switch(level) { - case 3: - ctr.info3 = &dinfo.driver_3; - - if (!py_to_DRIVER_INFO_3(&dinfo.driver_3, info)) { - PyErr_SetString(spoolss_error, - "error converting to driver info 3"); - goto done; - } - - break; - default: - PyErr_SetString(spoolss_error, "unsupported info level"); - goto done; - } - - werror = cli_spoolss_addprinterdriver(cli, mem_ctx, level, &ctr); - - if (!W_ERROR_IS_OK(werror)) { - PyErr_SetObject(spoolss_werror, py_werror_tuple(werror)); - goto done; - } - - Py_INCREF(Py_None); - result = Py_None; - -done: - if (cli) - cli_shutdown(cli); - - if (mem_ctx) - talloc_destroy(mem_ctx); - - return result; - -} - -PyObject *spoolss_addprinterdriverex(PyObject *self, PyObject *args, - PyObject *kw) -{ - /* Not supported by Samba server */ - - PyErr_SetString(spoolss_error, "Not implemented"); - return NULL; -} - -PyObject *spoolss_deleteprinterdriver(PyObject *self, PyObject *args, - PyObject *kw) -{ - PyErr_SetString(spoolss_error, "Not implemented"); - return NULL; -} - -PyObject *spoolss_deleteprinterdriverex(PyObject *self, PyObject *args, - PyObject *kw) -{ - PyErr_SetString(spoolss_error, "Not implemented"); - return NULL; -} diff --git a/source3/python/py_spoolss_drivers_conv.c b/source3/python/py_spoolss_drivers_conv.c deleted file mode 100644 index dbf33905ae..0000000000 --- a/source3/python/py_spoolss_drivers_conv.c +++ /dev/null @@ -1,148 +0,0 @@ -/* - 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_spoolss.h" -#include "python/py_conv.h" - -/* Structure/hash conversions */ - -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 } -}; - -struct pyconv py_DRIVER_DIRECTORY_1[] = { - { "name", PY_UNISTR, offsetof(DRIVER_DIRECTORY_1, name) }, - { NULL } -}; - -BOOL py_from_DRIVER_INFO_1(PyObject **dict, DRIVER_INFO_1 *info) -{ - *dict = from_struct(info, py_DRIVER_INFO_1); - PyDict_SetItemString(*dict, "level", PyInt_FromLong(1)); - return True; -} - -BOOL py_to_DRIVER_INFO_1(DRIVER_INFO_1 *info, PyObject *dict) -{ - return False; -} - -BOOL py_from_DRIVER_INFO_2(PyObject **dict, DRIVER_INFO_2 *info) -{ - *dict = from_struct(info, py_DRIVER_INFO_2); - PyDict_SetItemString(*dict, "level", PyInt_FromLong(2)); - return True; -} - -BOOL py_to_DRIVER_INFO_2(DRIVER_INFO_2 *info, PyObject *dict) -{ - return False; -} - -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)); - return True; -} - -BOOL py_to_DRIVER_INFO_3(DRIVER_INFO_3 *info, PyObject *dict) -{ - PyObject *dict_copy = PyDict_Copy(dict); - BOOL result; - - PyDict_DelItemString(dict_copy, "level"); - result = to_struct(info, dict_copy, py_DRIVER_INFO_3); - - Py_DECREF(dict_copy); - return result; -} - -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)); - return True; -} - -BOOL py_to_DRIVER_INFO_6(DRIVER_INFO_6 *info, PyObject *dict) -{ - return False; -} - -BOOL py_from_DRIVER_DIRECTORY_1(PyObject **dict, DRIVER_DIRECTORY_1 *info) -{ - *dict = from_struct(info, py_DRIVER_DIRECTORY_1); - PyDict_SetItemString(*dict, "level", PyInt_FromLong(1)); - return True; -} - -BOOL py_to_DRIVER_DIRECTORY_1(DRIVER_DIRECTORY_1 *info, PyObject *dict) -{ - return False; -} diff --git a/source3/python/py_spoolss_forms.c b/source3/python/py_spoolss_forms.c deleted file mode 100644 index c216e00afe..0000000000 --- a/source3/python/py_spoolss_forms.c +++ /dev/null @@ -1,266 +0,0 @@ -/* - 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_spoolss.h" - -/* Add a form */ - -PyObject *spoolss_hnd_addform(PyObject *self, PyObject *args, PyObject *kw) -{ - spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self; - WERROR werror; - PyObject *info; - FORM form; - int level; - static char *kwlist[] = {"form", NULL}; - - /* Parse parameters */ - - if (!PyArg_ParseTupleAndKeywords( - args, kw, "O!", kwlist, &PyDict_Type, &info)) - return NULL; - - /* Call rpc function */ - - if (!py_to_FORM(&form, info)) { - PyErr_SetString(spoolss_error, "invalid form"); - return NULL; - } - - if (!get_level_value(info, &level)) { - PyErr_SetString(spoolss_error, "invalid info level"); - return NULL; - } - - if (level != 1) { - PyErr_SetString(spoolss_error, "unsupported info level"); - return NULL; - } - - switch (level) { - case 1: { - PyObject *obj = PyDict_GetItemString(info, "name"); - char *form_name = PyString_AsString(obj); - - 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, py_werror_tuple(werror)); - return NULL; - } - - Py_INCREF(Py_None); - return Py_None; -} - -/* Get form properties */ - -PyObject *spoolss_hnd_getform(PyObject *self, PyObject *args, PyObject *kw) -{ - spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self; - WERROR werror; - PyObject *result; - char *form_name; - int level = 1; - static char *kwlist[] = {"form_name", "level", NULL}; - uint32 needed; - FORM_1 form; - - /* Parse parameters */ - - if (!PyArg_ParseTupleAndKeywords( - args, kw, "s|i", kwlist, &form_name, &level)) - return NULL; - - /* 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, py_werror_tuple(werror)); - return NULL; - } - - result = Py_None; - - switch(level) { - case 1: - py_from_FORM_1(&result, &form); - break; - } - - Py_INCREF(result); - return result; -} - -/* Set form properties */ - -PyObject *spoolss_hnd_setform(PyObject *self, PyObject *args, PyObject *kw) -{ - spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self; - WERROR werror; - PyObject *info, *form_name; - int level; - static char *kwlist[] = { "form", NULL}; - FORM form; - - /* Parse parameters */ - - if (!PyArg_ParseTupleAndKeywords( - args, kw, "O!", kwlist, &PyDict_Type, &info)) - return NULL; - - if (!get_level_value(info, &level)) { - PyErr_SetString(spoolss_error, "invalid info level"); - return NULL; - } - - if (level != 1) { - PyErr_SetString(spoolss_error, "unsupported info level"); - return NULL; - } - - /* Call rpc function */ - - if (!py_to_FORM(&form, info)) { - PyErr_SetString(spoolss_error, "invalid form"); - return NULL; - } - - form_name = PyDict_GetItemString(info, "name"); - - werror = cli_spoolss_setform( - hnd->cli, hnd->mem_ctx, &hnd->pol, level, - PyString_AsString(form_name), &form); - - if (!W_ERROR_IS_OK(werror)) { - PyErr_SetObject(spoolss_werror, py_werror_tuple(werror)); - return NULL; - } - - Py_INCREF(Py_None); - return Py_None; -} - -/* Delete a form */ - -PyObject *spoolss_hnd_deleteform(PyObject *self, PyObject *args, PyObject *kw) -{ - spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self; - WERROR werror; - static char *kwlist[] = {"form_name", NULL}; - char *form_name; - - /* Parse parameters */ - - if (!PyArg_ParseTupleAndKeywords( - args, kw, "s", kwlist, &form_name)) - return NULL; - - /* 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, py_werror_tuple(werror)); - return NULL; - } - - Py_INCREF(Py_None); - return Py_None; -} - -/* Enumerate forms */ - -PyObject *spoolss_hnd_enumforms(PyObject *self, PyObject *args, PyObject *kw) -{ - PyObject *result; - spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self; - WERROR werror; - uint32 level = 1, num_forms, needed, i; - static char *kwlist[] = {"level", NULL}; - FORM_1 *forms; - - /* Parse parameters */ - - if (!PyArg_ParseTupleAndKeywords( - args, kw, "|i", kwlist, &level)) - return NULL; - - /* 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, py_werror_tuple(werror)); - return NULL; - } - - switch(level) { - case 1: - result = PyDict_New(); - - for (i = 0; i < num_forms; i++) { - PyObject *value; - fstring name; - - rpcstr_pull(name, forms[i].name.buffer, - sizeof(fstring), -1, STR_TERMINATE); - - py_from_FORM_1(&value, &forms[i]); - - PyDict_SetItemString( - value, "level", PyInt_FromLong(1)); - - PyDict_SetItemString(result, name, value); - } - - break; - default: - PyErr_SetString(spoolss_error, "unknown info level"); - return NULL; - } - - return result; -} diff --git a/source3/python/py_spoolss_jobs.c b/source3/python/py_spoolss_jobs.c deleted file mode 100644 index cc5d42e0ee..0000000000 --- a/source3/python/py_spoolss_jobs.c +++ /dev/null @@ -1,377 +0,0 @@ -/* - 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_spoolss.h" - -/* Enumerate jobs */ - -PyObject *spoolss_hnd_enumjobs(PyObject *self, PyObject *args, PyObject *kw) -{ - spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self; - WERROR werror; - PyObject *result; - int level = 1; - uint32 i, needed, num_jobs; - static char *kwlist[] = {"level", NULL}; - JOB_INFO_CTR ctr; - - /* Parse parameters */ - - if (!PyArg_ParseTupleAndKeywords(args, kw, "|i", kwlist, &level)) - return NULL; - - /* Call rpc function */ - - werror = cli_spoolss_enumjobs( - hnd->cli, hnd->mem_ctx, 0, &needed, &hnd->pol, level, 0, - 1000, &num_jobs, &ctr); - - if (W_ERROR_V(werror) == ERRinsufficientbuffer) - werror = cli_spoolss_enumjobs( - hnd->cli, hnd->mem_ctx, needed, NULL, &hnd->pol, - level, 0, 1000, &num_jobs, &ctr); - - /* Return value */ - - result = Py_None; - - if (!W_ERROR_IS_OK(werror)) { - PyErr_SetObject(spoolss_werror, py_werror_tuple(werror)); - goto done; - } - - result = PyList_New(num_jobs); - - switch (level) { - case 1: - for (i = 0; i < num_jobs; i++) { - PyObject *value; - - py_from_JOB_INFO_1(&value, &ctr.job.job_info_1[i]); - - PyList_SetItem(result, i, value); - } - - break; - case 2: - for(i = 0; i < num_jobs; i++) { - PyObject *value; - - py_from_JOB_INFO_2(&value, &ctr.job.job_info_2[i]); - - PyList_SetItem(result, i, value); - } - - break; - } - - done: - Py_INCREF(result); - return result; -} - -/* Set job command */ - -PyObject *spoolss_hnd_setjob(PyObject *self, PyObject *args, PyObject *kw) -{ - spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self; - WERROR werror; - uint32 level = 0, command, jobid; - static char *kwlist[] = {"jobid", "command", "level", NULL}; - - /* Parse parameters */ - - if (!PyArg_ParseTupleAndKeywords( - args, kw, "ii|i", kwlist, &jobid, &command, &level)) - return NULL; - - /* Call rpc function */ - - werror = cli_spoolss_setjob(hnd->cli, hnd->mem_ctx, &hnd->pol, - jobid, level, command); - - if (!W_ERROR_IS_OK(werror)) { - PyErr_SetObject(spoolss_werror, py_werror_tuple(werror)); - return NULL; - } - - Py_INCREF(Py_None); - return Py_None; -} - -/* Get job */ - -PyObject *spoolss_hnd_getjob(PyObject *self, PyObject *args, PyObject *kw) -{ - spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self; - WERROR werror; - PyObject *result; - uint32 level = 1, jobid, needed; - static char *kwlist[] = {"jobid", "level", NULL}; - JOB_INFO_CTR ctr; - - /* Parse parameters */ - - if (!PyArg_ParseTupleAndKeywords( - args, kw, "i|i", kwlist, &jobid, &level)) - return NULL; - - /* Call rpc function */ - - werror = cli_spoolss_getjob(hnd->cli, hnd->mem_ctx, 0, &needed, - &hnd->pol, jobid, level, &ctr); - - if (W_ERROR_V(werror) == ERRinsufficientbuffer) - werror = cli_spoolss_getjob( - hnd->cli, hnd->mem_ctx, needed, NULL, &hnd->pol, - jobid, level, &ctr); - - if (!W_ERROR_IS_OK(werror)) { - PyErr_SetObject(spoolss_werror, py_werror_tuple(werror)); - return NULL; - } - - switch(level) { - case 1: - py_from_JOB_INFO_1(&result, ctr.job.job_info_1); - break; - case 2: - py_from_JOB_INFO_2(&result, ctr.job.job_info_2); - break; - } - - return result; -} - -/* Start page printer. This notifies the spooler that a page is about to be - printed on the specified printer. */ - -PyObject *spoolss_hnd_startpageprinter(PyObject *self, PyObject *args, PyObject *kw) -{ - spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self; - WERROR werror; - static char *kwlist[] = { NULL }; - - /* Parse parameters */ - - if (!PyArg_ParseTupleAndKeywords(args, kw, "", kwlist)) - return NULL; - - /* Call rpc function */ - - werror = cli_spoolss_startpageprinter( - hnd->cli, hnd->mem_ctx, &hnd->pol); - - if (!W_ERROR_IS_OK(werror)) { - PyErr_SetObject(spoolss_werror, py_werror_tuple(werror)); - return NULL; - } - - Py_INCREF(Py_None); - return Py_None; -} - -/* End page printer. This notifies the spooler that a page has finished - being printed on the specified printer. */ - -PyObject *spoolss_hnd_endpageprinter(PyObject *self, PyObject *args, PyObject *kw) -{ - spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self; - WERROR werror; - static char *kwlist[] = { NULL }; - - /* Parse parameters */ - - if (!PyArg_ParseTupleAndKeywords(args, kw, "", kwlist)) - return NULL; - - /* Call rpc function */ - - werror = cli_spoolss_endpageprinter( - hnd->cli, hnd->mem_ctx, &hnd->pol); - - if (!W_ERROR_IS_OK(werror)) { - PyErr_SetObject(spoolss_werror, py_werror_tuple(werror)); - return NULL; - } - - Py_INCREF(Py_None); - return Py_None; -} - -/* Start doc printer. This notifies the spooler that a document is about to be - printed on the specified printer. */ - -PyObject *spoolss_hnd_startdocprinter(PyObject *self, PyObject *args, PyObject *kw) -{ - spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self; - WERROR werror; - static char *kwlist[] = { "document_info", NULL }; - PyObject *info, *obj; - uint32 level, jobid; - char *document_name = NULL, *output_file = NULL, *data_type = NULL; - - /* Parse parameters */ - - if (!PyArg_ParseTupleAndKeywords( - args, kw, "O!", kwlist, &PyDict_Type, &info)) - return NULL; - - /* Check document_info parameter */ - - if (!get_level_value(info, &level)) { - PyErr_SetString(spoolss_error, "invalid info level"); - return NULL; - } - - if (level != 1) { - PyErr_SetString(spoolss_error, "unsupported info level"); - return NULL; - } - - if ((obj = PyDict_GetItemString(info, "document_name"))) { - - if (!PyString_Check(obj) && obj != Py_None) { - PyErr_SetString(spoolss_error, - "document_name not a string"); - return NULL; - } - - if (PyString_Check(obj)) - document_name = PyString_AsString(obj); - - } else { - PyErr_SetString(spoolss_error, "no document_name present"); - return NULL; - } - - if ((obj = PyDict_GetItemString(info, "output_file"))) { - - if (!PyString_Check(obj) && obj != Py_None) { - PyErr_SetString(spoolss_error, - "output_file not a string"); - return NULL; - } - - if (PyString_Check(obj)) - output_file = PyString_AsString(obj); - - } else { - PyErr_SetString(spoolss_error, "no output_file present"); - return NULL; - } - - if ((obj = PyDict_GetItemString(info, "data_type"))) { - - if (!PyString_Check(obj) && obj != Py_None) { - PyErr_SetString(spoolss_error, - "data_type not a string"); - return NULL; - } - - if (PyString_Check(obj)) - data_type = PyString_AsString(obj); - - } else { - PyErr_SetString(spoolss_error, "no data_type present"); - return NULL; - } - - /* Call rpc function */ - - werror = cli_spoolss_startdocprinter( - hnd->cli, hnd->mem_ctx, &hnd->pol, document_name, - output_file, data_type, &jobid); - - if (!W_ERROR_IS_OK(werror)) { - PyErr_SetObject(spoolss_werror, py_werror_tuple(werror)); - return NULL; - } - - /* The return value is zero for an error (where does the status - code come from now??) and the return value is the jobid - allocated for the new job. */ - - return Py_BuildValue("i", jobid); -} - -/* End doc printer. This notifies the spooler that a document has finished - being printed on the specified printer. */ - -PyObject *spoolss_hnd_enddocprinter(PyObject *self, PyObject *args, PyObject *kw) -{ - spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self; - WERROR werror; - static char *kwlist[] = { NULL }; - - /* Parse parameters */ - - if (!PyArg_ParseTupleAndKeywords(args, kw, "", kwlist)) - return NULL; - - /* Call rpc function */ - - werror = cli_spoolss_enddocprinter(hnd->cli, hnd->mem_ctx, &hnd->pol); - - if (!W_ERROR_IS_OK(werror)) { - PyErr_SetObject(spoolss_werror, py_werror_tuple(werror)); - return NULL; - } - - Py_INCREF(Py_None); - return Py_None; -} - -/* Write data to a printer */ - -PyObject *spoolss_hnd_writeprinter(PyObject *self, PyObject *args, PyObject *kw) -{ - spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self; - WERROR werror; - static char *kwlist[] = { "data", NULL }; - PyObject *data; - uint32 num_written; - - /* Parse parameters */ - - if (!PyArg_ParseTupleAndKeywords( - args, kw, "O!", kwlist, &PyString_Type, &data)) - return NULL; - - /* Call rpc function */ - - werror = cli_spoolss_writeprinter( - hnd->cli, hnd->mem_ctx, &hnd->pol, PyString_Size(data), - PyString_AsString(data), &num_written); - - 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_addjob(PyObject *self, PyObject *args, PyObject *kw) -{ - PyErr_SetString(spoolss_error, "Not implemented"); - return NULL; -} diff --git a/source3/python/py_spoolss_printerdata.c b/source3/python/py_spoolss_printerdata.c deleted file mode 100644 index e1e43fa736..0000000000 --- a/source3/python/py_spoolss_printerdata.c +++ /dev/null @@ -1,234 +0,0 @@ -/* - 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_spoolss.h" - -static BOOL py_from_printerdata(PyObject **dict, 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, "value", Py_BuildValue("s", value)); - - PyDict_SetItemString(*dict, "data", - Py_BuildValue("s#", data, data_size)); - - return True; -} - -static BOOL py_to_printerdata(char **value, uint32 *data_type, - char **data, uint32 *data_size, - PyObject *dict) -{ - PyObject *obj; - - 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, "value"))) { - - if (!PyString_Check(obj)) { - PyErr_SetString(spoolss_error, - "value not a string"); - return False; - } - - *value = PyString_AsString(obj); - } else { - PyErr_SetString(spoolss_error, "no value present"); - return False; - } - - if ((obj = PyDict_GetItemString(dict, "data"))) { - - if (!PyString_Check(obj)) { - PyErr_SetString(spoolss_error, - "data not a string"); - return False; - } - - *data = PyString_AsString(obj); - *data_size = PyString_Size(obj); - } else { - PyErr_SetString(spoolss_error, "no data present"); - return False; - } - - return True; -} - -PyObject *spoolss_hnd_getprinterdata(PyObject *self, PyObject *args, PyObject *kw) -{ - spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self; - static char *kwlist[] = { "value", NULL }; - char *value; - WERROR werror; - uint32 needed, data_type, data_size; - char *data; - PyObject *result; - - /* Parse parameters */ - - if (!PyArg_ParseTupleAndKeywords(args, kw, "s", kwlist, &value)) - return NULL; - - /* Call rpc function */ - - werror = cli_spoolss_getprinterdata( - hnd->cli, hnd->mem_ctx, 0, &needed, &hnd->pol, value, - &data_type, &data, &data_size); - - 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); - - if (!W_ERROR_IS_OK(werror)) { - PyErr_SetObject(spoolss_werror, py_werror_tuple(werror)); - return NULL; - } - - py_from_printerdata(&result, value, data_type, data, needed); - - return result; -} - -PyObject *spoolss_hnd_setprinterdata(PyObject *self, PyObject *args, PyObject *kw) -{ - spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self; - static char *kwlist[] = { "data", NULL }; - PyObject *py_data; - char *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(&value, &data_type, &data, &data_size, py_data)) - return NULL; - - /* Call rpc function */ - - werror = cli_spoolss_setprinterdata( - hnd->cli, hnd->mem_ctx, &hnd->pol, 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_enumprinterdata(PyObject *self, PyObject *args, PyObject *kw) -{ - 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; - WERROR werror; - PyObject *result; - - if (!PyArg_ParseTupleAndKeywords(args, kw, "", kwlist)) - return NULL; - - /* Get max buffer sizes for value and data */ - - werror = cli_spoolss_enumprinterdata( - hnd->cli, hnd->mem_ctx, &hnd->pol, ndx, 0, 0, - &value_needed, &data_needed, NULL, NULL, NULL, NULL); - - if (!W_ERROR_IS_OK(werror)) { - PyErr_SetObject(spoolss_werror, py_werror_tuple(werror)); - return NULL; - } - - /* Iterate over all printerdata */ - - result = PyDict_New(); - - while (W_ERROR_IS_OK(werror)) { - PyObject *obj; - - werror = cli_spoolss_enumprinterdata( - hnd->cli, hnd->mem_ctx, &hnd->pol, ndx, - value_needed, data_needed, NULL, NULL, - &value, &data_type, &data, &data_size); - - if (py_from_printerdata(&obj, value, data_type, data, - data_size)) - PyDict_SetItemString(result, value, obj); - - ndx++; - } - - return result; -} - -PyObject *spoolss_hnd_deleteprinterdata(PyObject *self, PyObject *args, PyObject *kw) -{ - spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self; - static char *kwlist[] = { "value", NULL }; - char *value; - WERROR werror; - - /* Parse parameters */ - - if (!PyArg_ParseTupleAndKeywords(args, kw, "s", kwlist, &value)) - return NULL; - - /* Call rpc function */ - - werror = cli_spoolss_deleteprinterdata( - hnd->cli, hnd->mem_ctx, &hnd->pol, value); - - 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_deleteprinterdataex(PyObject *self, PyObject *args, PyObject *kw) -{ - /* Not supported by Samba server */ - - PyErr_SetString(spoolss_error, "Not implemented"); - return NULL; -} diff --git a/source3/python/py_spoolss_printers.c b/source3/python/py_spoolss_printers.c deleted file mode 100644 index 8d4cd24778..0000000000 --- a/source3/python/py_spoolss_printers.c +++ /dev/null @@ -1,480 +0,0 @@ -/* - 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_spoolss.h" - -/* Open a printer */ - -PyObject *spoolss_openprinter(PyObject *self, PyObject *args, PyObject *kw) -{ - char *unc_name, *server, *errstr; - TALLOC_CTX *mem_ctx = NULL; - 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|Oi", kwlist, &unc_name, &creds, - &desired_access)) - return NULL; - - if (unc_name[0] != '\\' || unc_name[1] != '\\') { - PyErr_SetString(PyExc_ValueError, "UNC name required"); - return NULL; - } - - server = strdup(unc_name + 2); - - if (strchr(server, '\\')) { - char *c = strchr(server, '\\'); - *c = 0; - } - - if (creds && creds != Py_None && !PyDict_Check(creds)) { - PyErr_SetString(PyExc_TypeError, - "credentials must be dictionary or None"); - return NULL; - } - - if (!(cli = open_pipe_creds(server, creds, PIPE_SPOOLSS, &errstr))) { - PyErr_SetString(spoolss_error, errstr); - free(errstr); - goto done; - } - - if (!(mem_ctx = talloc_init())) { - PyErr_SetString(spoolss_error, - "unable to init talloc context\n"); - goto done; - } - - werror = cli_spoolss_open_printer_ex( - cli, mem_ctx, unc_name, "", desired_access, server, - "", &hnd); - - if (!W_ERROR_IS_OK(werror)) { - PyErr_SetObject(spoolss_werror, py_werror_tuple(werror)); - goto done; - } - - result = new_spoolss_policy_hnd_object(cli, mem_ctx, &hnd); - - done: - if (!result) { - if (cli) - cli_shutdown(cli); - - if (mem_ctx) - talloc_destroy(mem_ctx); - } - - SAFE_FREE(server); - - return result; -} - -/* Close a printer */ - -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); - - /* Return value */ - - Py_INCREF(Py_None); - return Py_None; -} - -/* Fetch printer information */ - -PyObject *spoolss_hnd_getprinter(PyObject *self, PyObject *args, PyObject *kw) -{ - spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self; - WERROR werror; - PyObject *result = NULL; - 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; - - if (level < 0 || level > 3) { - PyErr_SetString(spoolss_error, "Invalid info level"); - return NULL; - } - - ZERO_STRUCT(ctr); - - /* 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 */ - - if (!W_ERROR_IS_OK(werror)) { - PyErr_SetObject(spoolss_werror, py_werror_tuple(werror)); - return NULL; - } - - result = Py_None; - - switch (level) { - - case 0: - py_from_PRINTER_INFO_0(&result, ctr.printers_0); - break; - - case 1: - py_from_PRINTER_INFO_1(&result, ctr.printers_1); - break; - - case 2: - py_from_PRINTER_INFO_2(&result, ctr.printers_2); - break; - - case 3: - py_from_PRINTER_INFO_3(&result, ctr.printers_3); - break; - } - - Py_INCREF(result); - return result; -} - -/* Set printer information */ - -PyObject *spoolss_hnd_setprinter(PyObject *self, PyObject *args, PyObject *kw) -{ - spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self; - WERROR werror; - PyObject *info; - PRINTER_INFO_CTR ctr; - uint32 level; - static char *kwlist[] = {"dict", NULL}; - union { - PRINTER_INFO_1 printers_1; - PRINTER_INFO_2 printers_2; - PRINTER_INFO_3 printers_3; - } pinfo; - - /* Parse parameters */ - - if (!PyArg_ParseTupleAndKeywords( - args, kw, "O!", kwlist, &PyDict_Type, &info)) - return NULL; - - if (!get_level_value(info, &level)) { - PyErr_SetString(spoolss_error, "invalid info level"); - return NULL; - } - - if (level < 1 && level > 3) { - PyErr_SetString(spoolss_error, "unsupported info level"); - return NULL; - } - - /* Fill in printer info */ - - ZERO_STRUCT(ctr); - - switch (level) { - case 1: - ctr.printers_1 = &pinfo.printers_1; - - if (!py_to_PRINTER_INFO_1(&pinfo.printers_1, info)){ - PyErr_SetString(spoolss_error, - "error converting printer to info 1"); - return NULL; - } - - break; - case 2: - ctr.printers_2 = &pinfo.printers_2; - - if (!py_to_PRINTER_INFO_2(&pinfo.printers_2, info, - hnd->mem_ctx)){ - PyErr_SetString(spoolss_error, - "error converting printer to info 2"); - return NULL; - } - - break; - case 3: - ctr.printers_3 = &pinfo.printers_3; - - if (!py_to_PRINTER_INFO_3(&pinfo.printers_3, info, - hnd->mem_ctx)) { - PyErr_SetString(spoolss_error, - "error converting to printer info 3"); - return NULL; - } - - break; - default: - PyErr_SetString(spoolss_error, "unsupported info level"); - return NULL; - } - - /* Call rpc function */ - - werror = cli_spoolss_setprinter(hnd->cli, hnd->mem_ctx, &hnd->pol, - level, &ctr, 0); - - /* Return value */ - - if (!W_ERROR_IS_OK(werror)) { - PyErr_SetObject(spoolss_werror, py_werror_tuple(werror)); - return NULL; - } - - Py_INCREF(Py_None); - return Py_None; -} - -/* Enumerate printers */ - -PyObject *spoolss_enumprinters(PyObject *self, PyObject *args, PyObject *kw) -{ - WERROR werror; - PyObject *result = NULL, *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, *errstr, *name = NULL; - - /* Parse parameters */ - - if (!PyArg_ParseTupleAndKeywords( - args, kw, "s|siiO", kwlist, &server, &name, &level, - &flags, &creds)) - return NULL; - - if (server[0] != '\\' || server[1] != '\\') { - PyErr_SetString(PyExc_ValueError, "UNC name required"); - return NULL; - } - - server += 2; - - if (creds && creds != Py_None && !PyDict_Check(creds)) { - PyErr_SetString(PyExc_TypeError, - "credentials must be dictionary or None"); - return NULL; - } - - if (!(cli = open_pipe_creds(server, creds, PIPE_SPOOLSS, &errstr))) { - PyErr_SetString(spoolss_error, errstr); - free(errstr); - goto done; - } - - if (!(mem_ctx = talloc_init())) { - PyErr_SetString( - spoolss_error, "unable to init talloc context\n"); - goto done; - } - - /* This RPC is weird. By setting the server name to different - values we can get different behaviour. If however the server - name is not specified, we default it to being the full server - name as this is probably what the caller intended. To pass a - NULL name, pass a value of "" */ - - if (!name) - name = server; - else { - if (!name[0]) - name = 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); - - if (!W_ERROR_IS_OK(werror)) { - PyErr_SetObject(spoolss_werror, py_werror_tuple(werror)); - goto done; - } - - /* Return value */ - - switch (level) { - case 0: - result = PyDict_New(); - - for (i = 0; i < num_printers; i++) { - PyObject *value; - fstring name; - - rpcstr_pull(name, ctr.printers_0[i].printername.buffer, - sizeof(fstring), -1, STR_TERMINATE); - - py_from_PRINTER_INFO_0(&value, &ctr.printers_0[i]); - - PyDict_SetItemString( - value, "level", PyInt_FromLong(0)); - - PyDict_SetItemString(result, name, value); - } - - break; - case 1: - result = PyDict_New(); - - for(i = 0; i < num_printers; i++) { - PyObject *value; - fstring name; - - rpcstr_pull(name, ctr.printers_1[i].name.buffer, - sizeof(fstring), -1, STR_TERMINATE); - - py_from_PRINTER_INFO_1(&value, &ctr.printers_1[i]); - - PyDict_SetItemString( - value, "level", PyInt_FromLong(1)); - - PyDict_SetItemString(result, name, value); - } - - break; - case 2: - result = PyDict_New(); - - for(i = 0; i < num_printers; i++) { - PyObject *value; - fstring name; - - rpcstr_pull(name, ctr.printers_2[i].printername.buffer, - sizeof(fstring), -1, STR_TERMINATE); - - py_from_PRINTER_INFO_2(&value, &ctr.printers_2[i]); - - PyDict_SetItemString( - value, "level", PyInt_FromLong(2)); - - PyDict_SetItemString(result, name, value); - } - - break; - default: - PyErr_SetString(spoolss_error, "unknown info level"); - goto done; - } - -done: - if (cli) - cli_shutdown(cli); - - if (mem_ctx) - talloc_destroy(mem_ctx); - - return result; -} - -/* Add a printer */ - -PyObject *spoolss_addprinterex(PyObject *self, PyObject *args, PyObject *kw) -{ - static char *kwlist[] = { "server", "printername", "info", "creds", - NULL}; - char *printername, *server, *errstr; - PyObject *info, *result = NULL, *creds = NULL; - struct cli_state *cli = NULL; - TALLOC_CTX *mem_ctx = NULL; - PRINTER_INFO_CTR ctr; - PRINTER_INFO_2 info2; - WERROR werror; - - if (!PyArg_ParseTupleAndKeywords( - args, kw, "ssO!|O!", kwlist, &server, &printername, - &PyDict_Type, &info, &PyDict_Type, &creds)) - return NULL; - - if (!(cli = open_pipe_creds(server, creds, PIPE_SPOOLSS, &errstr))) { - PyErr_SetString(spoolss_error, errstr); - free(errstr); - goto done; - } - - if (!(mem_ctx = talloc_init())) { - PyErr_SetString( - spoolss_error, "unable to init talloc context\n"); - goto done; - } - - if (!py_to_PRINTER_INFO_2(&info2, info, mem_ctx)) { - PyErr_SetString(spoolss_error, - "error converting to printer info 2"); - goto done; - } - - ctr.printers_2 = &info2; - - werror = cli_spoolss_addprinterex(cli, mem_ctx, 2, &ctr); - - Py_INCREF(Py_None); - result = Py_None; - -done: - if (cli) - cli_shutdown(cli); - - if (mem_ctx) - talloc_destroy(mem_ctx); - - return result; -} diff --git a/source3/python/py_spoolss_printers_conv.c b/source3/python/py_spoolss_printers_conv.c deleted file mode 100644 index 247db65b1e..0000000000 --- a/source3/python/py_spoolss_printers_conv.c +++ /dev/null @@ -1,296 +0,0 @@ -/* - 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_spoolss.h" -#include "python/py_conv.h" - -struct pyconv py_PRINTER_INFO_0[] = { - { "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[] = { - { "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) }, - { "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 } -}; - -/* - * Convert between DEVICEMODE and Python - */ - -BOOL py_from_DEVICEMODE(PyObject **dict, DEVICEMODE *devmode) -{ - *dict = from_struct(devmode, py_DEVICEMODE); - - PyDict_SetItemString(*dict, "private", - PyString_FromStringAndSize( - devmode->private, devmode->driverextra)); - - return True; -} - -BOOL py_to_DEVICEMODE(DEVICEMODE *devmode, PyObject *dict) -{ - PyObject *obj; - - if (!to_struct(devmode, dict, py_DEVICEMODE)) - return False; - - if (!(obj = PyDict_GetItemString(dict, "private"))) - return False; - - devmode->private = PyString_AsString(obj); - devmode->driverextra = PyString_Size(obj); - - return True; -} - -/* - * Convert between PRINTER_INFO_0 and Python - */ - -BOOL py_from_PRINTER_INFO_0(PyObject **dict, PRINTER_INFO_0 *info) -{ - *dict = from_struct(info, py_PRINTER_INFO_0); - PyDict_SetItemString(*dict, "level", PyInt_FromLong(0)); - return True; -} - -BOOL py_to_PRINTER_INFO_0(PRINTER_INFO_0 *info, PyObject *dict) -{ - return False; -} - -/* - * Convert between PRINTER_INFO_1 and Python - */ - -BOOL py_from_PRINTER_INFO_1(PyObject **dict, PRINTER_INFO_1 *info) -{ - *dict = from_struct(info, py_PRINTER_INFO_1); - PyDict_SetItemString(*dict, "level", PyInt_FromLong(1)); - return True; -} - -BOOL py_to_PRINTER_INFO_1(PRINTER_INFO_1 *info, PyObject *dict) -{ - PyObject *dict_copy = PyDict_Copy(dict); - BOOL result; - - PyDict_DelItemString(dict_copy, "level"); - result = to_struct(info, dict_copy, py_PRINTER_INFO_1); - - Py_DECREF(dict_copy); - return result; -} - -/* - * Convert between PRINTER_INFO_2 and Python - */ - -BOOL py_from_PRINTER_INFO_2(PyObject **dict, PRINTER_INFO_2 *info) -{ - PyObject *obj; - - *dict = from_struct(info, py_PRINTER_INFO_2); - - 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); - - PyDict_SetItemString(*dict, "level", PyInt_FromLong(2)); - - return True; -} - -BOOL py_to_PRINTER_INFO_2(PRINTER_INFO_2 *info, PyObject *dict, - TALLOC_CTX *mem_ctx) -{ - PyObject *obj; - - if (!to_struct(info, dict, py_PRINTER_INFO_2)) - return False; - - if (!(obj = PyDict_GetItemString(dict, "security_descriptor"))) - return False; - - if (!py_to_SECDESC(&info->secdesc, obj, mem_ctx)) - return False; - - if (!(obj = PyDict_GetItemString(dict, "device_mode"))) - return False; - - info->devmode = talloc(mem_ctx, sizeof(DEVICEMODE)); - - if (!py_to_DEVICEMODE(info->devmode, obj)) - return False; - - return True; -} - -/* - * Convert between PRINTER_INFO_1 and Python - */ - -BOOL py_from_PRINTER_INFO_3(PyObject **dict, PRINTER_INFO_3 *info) -{ - PyObject *obj; - - *dict = from_struct(info, py_PRINTER_INFO_3); - - if (py_from_SECDESC(&obj, info->secdesc)) - PyDict_SetItemString(*dict, "security_descriptor", obj); - - PyDict_SetItemString(*dict, "level", PyInt_FromLong(3)); - - return True; -} - -BOOL py_to_PRINTER_INFO_3(PRINTER_INFO_3 *info, PyObject *dict, - TALLOC_CTX *mem_ctx) -{ - PyObject *obj; - - if (!to_struct(info, dict, py_PRINTER_INFO_3)) - return False; - - if (!(obj = PyDict_GetItemString(dict, "security_descriptor"))) - return False; - - if (!py_to_SECDESC(&info->secdesc, obj, mem_ctx)) - return False; - - return True; -} diff --git a/source3/python/py_spoolss_proto.h b/source3/python/py_spoolss_proto.h deleted file mode 100644 index 5b68ef815a..0000000000 --- a/source3/python/py_spoolss_proto.h +++ /dev/null @@ -1,120 +0,0 @@ -#ifndef _PY_SPOOLSS_PROTO_H -#define _PY_SPOOLSS_PROTO_H - -/* This file is automatically generated with "make proto". DO NOT EDIT */ - - -/* The following definitions come from python/py_spoolss.c */ - -PyObject *new_spoolss_policy_hnd_object(struct cli_state *cli, - TALLOC_CTX *mem_ctx, POLICY_HND *pol); -void initspoolss(void); - -/* The following definitions come from python/py_spoolss_drivers.c */ - -PyObject *spoolss_enumprinterdrivers(PyObject *self, PyObject *args, - PyObject *kw); -PyObject *spoolss_hnd_getprinterdriver(PyObject *self, PyObject *args, - PyObject *kw); -PyObject *spoolss_getprinterdriverdir(PyObject *self, PyObject *args, - PyObject *kw); -PyObject *spoolss_addprinterdriver(PyObject *self, PyObject *args, - PyObject *kw); -PyObject *spoolss_addprinterdriverex(PyObject *self, PyObject *args, - PyObject *kw); -PyObject *spoolss_deleteprinterdriver(PyObject *self, PyObject *args, - PyObject *kw); -PyObject *spoolss_deleteprinterdriverex(PyObject *self, PyObject *args, - PyObject *kw); - -/* The following definitions come from python/py_spoolss_drivers_conv.c */ - -BOOL py_from_DRIVER_INFO_1(PyObject **dict, DRIVER_INFO_1 *info); -BOOL py_to_DRIVER_INFO_1(DRIVER_INFO_1 *info, PyObject *dict); -BOOL py_from_DRIVER_INFO_2(PyObject **dict, DRIVER_INFO_2 *info); -BOOL py_to_DRIVER_INFO_2(DRIVER_INFO_2 *info, PyObject *dict); -BOOL py_from_DRIVER_INFO_3(PyObject **dict, DRIVER_INFO_3 *info); -BOOL py_to_DRIVER_INFO_3(DRIVER_INFO_3 *info, PyObject *dict); -BOOL py_from_DRIVER_INFO_6(PyObject **dict, DRIVER_INFO_6 *info); -BOOL py_to_DRIVER_INFO_6(DRIVER_INFO_6 *info, PyObject *dict); -BOOL py_from_DRIVER_DIRECTORY_1(PyObject **dict, DRIVER_DIRECTORY_1 *info); -BOOL py_to_DRIVER_DIRECTORY_1(DRIVER_DIRECTORY_1 *info, PyObject *dict); - -/* The following definitions come from python/py_spoolss_forms.c */ - -PyObject *spoolss_hnd_addform(PyObject *self, PyObject *args, PyObject *kw); -PyObject *spoolss_hnd_getform(PyObject *self, PyObject *args, PyObject *kw); -PyObject *spoolss_hnd_setform(PyObject *self, PyObject *args, PyObject *kw); -PyObject *spoolss_hnd_deleteform(PyObject *self, PyObject *args, PyObject *kw); -PyObject *spoolss_hnd_enumforms(PyObject *self, PyObject *args, PyObject *kw); - -/* The following definitions come from python/py_spoolss_forms_conv.c */ - -BOOL py_from_FORM_1(PyObject **dict, FORM_1 *form); -BOOL py_to_FORM(FORM *form, PyObject *dict); - -/* The following definitions come from python/py_spoolss_jobs.c */ - -PyObject *spoolss_hnd_enumjobs(PyObject *self, PyObject *args, PyObject *kw); -PyObject *spoolss_hnd_setjob(PyObject *self, PyObject *args, PyObject *kw); -PyObject *spoolss_hnd_getjob(PyObject *self, PyObject *args, PyObject *kw); -PyObject *spoolss_hnd_startpageprinter(PyObject *self, PyObject *args, PyObject *kw); -PyObject *spoolss_hnd_endpageprinter(PyObject *self, PyObject *args, PyObject *kw); -PyObject *spoolss_hnd_startdocprinter(PyObject *self, PyObject *args, PyObject *kw); -PyObject *spoolss_hnd_enddocprinter(PyObject *self, PyObject *args, PyObject *kw); -PyObject *spoolss_hnd_writeprinter(PyObject *self, PyObject *args, PyObject *kw); -PyObject *spoolss_hnd_addjob(PyObject *self, PyObject *args, PyObject *kw); - -/* The following definitions come from python/py_spoolss_jobs_conv.c */ - -BOOL py_from_JOB_INFO_1(PyObject **dict, JOB_INFO_1 *info); -BOOL py_to_JOB_INFO_1(JOB_INFO_1 *info, PyObject *dict); -BOOL py_from_JOB_INFO_2(PyObject **dict, JOB_INFO_2 *info); -BOOL py_to_JOB_INFO_2(JOB_INFO_2 *info, PyObject *dict); -BOOL py_from_DOC_INFO_1(PyObject **dict, DOC_INFO_1 *info); -BOOL py_to_DOC_INFO_1(DOC_INFO_1 *info, PyObject *dict); - -/* The following definitions come from python/py_spoolss_ports.c */ - -PyObject *spoolss_enumports(PyObject *self, PyObject *args, PyObject *kw); - -/* The following definitions come from python/py_spoolss_ports_conv.c */ - -BOOL py_from_PORT_INFO_1(PyObject **dict, PORT_INFO_1 *info); -BOOL py_to_PORT_INFO_1(PORT_INFO_1 *info, PyObject *dict); -BOOL py_from_PORT_INFO_2(PyObject **dict, PORT_INFO_2 *info); -BOOL py_to_PORT_INFO_2(PORT_INFO_2 *info, PyObject *dict); - -/* The following definitions come from python/py_spoolss_printerdata.c */ - -PyObject *spoolss_hnd_getprinterdata(PyObject *self, PyObject *args, PyObject *kw); -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_deleteprinterdataex(PyObject *self, PyObject *args, PyObject *kw); - -/* The following definitions come from python/py_spoolss_printers.c */ - -PyObject *spoolss_openprinter(PyObject *self, PyObject *args, PyObject *kw); -PyObject *spoolss_closeprinter(PyObject *self, PyObject *args); -PyObject *spoolss_hnd_getprinter(PyObject *self, PyObject *args, PyObject *kw); -PyObject *spoolss_hnd_setprinter(PyObject *self, PyObject *args, PyObject *kw); -PyObject *spoolss_enumprinters(PyObject *self, PyObject *args, PyObject *kw); -PyObject *spoolss_addprinterex(PyObject *self, PyObject *args, PyObject *kw); - -/* The following definitions come from python/py_spoolss_printers_conv.c */ - -BOOL py_from_DEVICEMODE(PyObject **dict, DEVICEMODE *devmode); -BOOL py_to_DEVICEMODE(DEVICEMODE *devmode, PyObject *dict); -BOOL py_from_PRINTER_INFO_0(PyObject **dict, PRINTER_INFO_0 *info); -BOOL py_to_PRINTER_INFO_0(PRINTER_INFO_0 *info, PyObject *dict); -BOOL py_from_PRINTER_INFO_1(PyObject **dict, PRINTER_INFO_1 *info); -BOOL py_to_PRINTER_INFO_1(PRINTER_INFO_1 *info, PyObject *dict); -BOOL py_from_PRINTER_INFO_2(PyObject **dict, PRINTER_INFO_2 *info); -BOOL py_to_PRINTER_INFO_2(PRINTER_INFO_2 *info, PyObject *dict, - TALLOC_CTX *mem_ctx); -BOOL py_from_PRINTER_INFO_3(PyObject **dict, PRINTER_INFO_3 *info); -BOOL py_to_PRINTER_INFO_3(PRINTER_INFO_3 *info, PyObject *dict, - TALLOC_CTX *mem_ctx); - -#endif /* _PY_SPOOLSS_PROTO_H */ diff --git a/source3/python/py_winbind.c b/source3/python/py_winbind.c deleted file mode 100644 index 49c7f8e924..0000000000 --- a/source3/python/py_winbind.c +++ /dev/null @@ -1,651 +0,0 @@ -/* - Unix SMB/CIFS implementation. - - Python wrapper for winbind client functions. - - 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 "py_common_proto.h" - -/* - * Exceptions raised by this module - */ - -PyObject *winbind_error; /* A winbind call returned WINBINDD_ERROR */ - -/* Prototypes from common.h */ - -NSS_STATUS winbindd_request(int req_type, - struct winbindd_request *request, - struct winbindd_response *response); - -/* - * Name <-> SID conversion - */ - -/* Convert a name to a sid */ - -static PyObject *py_name_to_sid(PyObject *self, PyObject *args) - -{ - struct winbindd_request request; - struct winbindd_response response; - PyObject *result; - char *name, *p, *sep; - - if (!PyArg_ParseTuple(args, "s", &name)) - return NULL; - - ZERO_STRUCT(request); - ZERO_STRUCT(response); - - sep = lp_winbind_separator(); - - if ((p = strchr(name, sep[0]))) { - *p = 0; - fstrcpy(request.data.name.dom_name, name); - fstrcpy(request.data.name.name, p + 1); - } else { - fstrcpy(request.data.name.dom_name, lp_workgroup()); - fstrcpy(request.data.name.name, name); - } - - if (winbindd_request(WINBINDD_LOOKUPNAME, &request, &response) - != NSS_STATUS_SUCCESS) { - PyErr_SetString(winbind_error, "lookup failed"); - return NULL; - } - - result = PyString_FromString(response.data.sid.sid); - - return result; -} - -/* Convert a sid to a name */ - -static PyObject *py_sid_to_name(PyObject *self, PyObject *args) -{ - struct winbindd_request request; - struct winbindd_response response; - PyObject *result; - char *sid, *name; - - if (!PyArg_ParseTuple(args, "s", &sid)) - return NULL; - - ZERO_STRUCT(request); - ZERO_STRUCT(response); - - fstrcpy(request.data.sid, sid); - - if (winbindd_request(WINBINDD_LOOKUPSID, &request, &response) - != NSS_STATUS_SUCCESS) { - PyErr_SetString(winbind_error, "lookup failed"); - return NULL; - } - - asprintf(&name, "%s%s%s", response.data.name.dom_name, - lp_winbind_separator(), response.data.name.name); - - result = PyString_FromString(name); - - free(name); - - return result; -} - -/* - * Enumerate users/groups - */ - -/* Enumerate domain users */ - -static PyObject *py_enum_domain_users(PyObject *self, PyObject *args) -{ - struct winbindd_response response; - PyObject *result; - - if (!PyArg_ParseTuple(args, "")) - return NULL; - - ZERO_STRUCT(response); - - if (winbindd_request(WINBINDD_LIST_USERS, NULL, &response) - != NSS_STATUS_SUCCESS) { - PyErr_SetString(winbind_error, "lookup failed"); - return NULL; - } - - result = PyList_New(0); - - if (response.extra_data) { - char *extra_data = response.extra_data; - fstring name; - - while (next_token(&extra_data, name, ",", sizeof(fstring))) - PyList_Append(result, PyString_FromString(name)); - } - - return result; -} - -/* Enumerate domain groups */ - -static PyObject *py_enum_domain_groups(PyObject *self, PyObject *args) -{ - struct winbindd_response response; - PyObject *result = NULL; - - if (!PyArg_ParseTuple(args, "")) - return NULL; - - ZERO_STRUCT(response); - - if (winbindd_request(WINBINDD_LIST_GROUPS, NULL, &response) - != NSS_STATUS_SUCCESS) { - PyErr_SetString(winbind_error, "lookup failed"); - return NULL; - } - - result = PyList_New(0); - - if (response.extra_data) { - char *extra_data = response.extra_data; - fstring name; - - while (next_token(&extra_data, name, ",", sizeof(fstring))) - PyList_Append(result, PyString_FromString(name)); - } - - return result; -} - -/* - * Miscellaneous domain related - */ - -/* Enumerate domain groups */ - -static PyObject *py_enum_trust_dom(PyObject *self, PyObject *args) -{ - struct winbindd_response response; - PyObject *result = NULL; - - if (!PyArg_ParseTuple(args, "")) - return NULL; - - ZERO_STRUCT(response); - - if (winbindd_request(WINBINDD_LIST_TRUSTDOM, NULL, &response) - != NSS_STATUS_SUCCESS) { - PyErr_SetString(winbind_error, "lookup failed"); - return NULL; - } - - result = PyList_New(0); - - if (response.extra_data) { - char *extra_data = response.extra_data; - fstring name; - - while (next_token(&extra_data, name, ",", sizeof(fstring))) - PyList_Append(result, PyString_FromString(name)); - } - - return result; -} - -/* Check machine account password */ - -static PyObject *py_check_secret(PyObject *self, PyObject *args) -{ - struct winbindd_response response; - - if (!PyArg_ParseTuple(args, "")) - return NULL; - - ZERO_STRUCT(response); - - if (winbindd_request(WINBINDD_CHECK_MACHACC, NULL, &response) - != NSS_STATUS_SUCCESS) { - PyErr_SetString(winbind_error, "lookup failed"); - return NULL; - } - - return PyInt_FromLong(response.data.num_entries); -} - -/* - * Return a dictionary consisting of all the winbind related smb.conf - * parameters. This is stored in the module object. - */ - -static PyObject *py_config_dict(void) -{ - PyObject *result; - uid_t ulow, uhi; - gid_t glow, ghi; - - if (!(result = PyDict_New())) - return NULL; - - /* Various string parameters */ - - PyDict_SetItemString(result, "workgroup", - PyString_FromString(lp_workgroup())); - - PyDict_SetItemString(result, "separator", - PyString_FromString(lp_winbind_separator())); - - PyDict_SetItemString(result, "template_homedir", - PyString_FromString(lp_template_homedir())); - - PyDict_SetItemString(result, "template_shell", - PyString_FromString(lp_template_shell())); - - /* Winbind uid/gid range */ - - if (lp_winbind_uid(&ulow, &uhi)) { - PyDict_SetItemString(result, "uid_low", PyInt_FromLong(ulow)); - PyDict_SetItemString(result, "uid_high", PyInt_FromLong(uhi)); - } - - if (lp_winbind_gid(&glow, &ghi)) { - PyDict_SetItemString(result, "gid_low", PyInt_FromLong(glow)); - PyDict_SetItemString(result, "gid_high", PyInt_FromLong(ghi)); - } - - return result; -} - -/* - * ID mapping - */ - -/* Convert a uid to a SID */ - -static PyObject *py_uid_to_sid(PyObject *self, PyObject *args) -{ - struct winbindd_request request; - struct winbindd_response response; - int id; - - if (!PyArg_ParseTuple(args, "i", &id)) - return NULL; - - ZERO_STRUCT(request); - ZERO_STRUCT(response); - - request.data.uid = id; - - if (winbindd_request(WINBINDD_UID_TO_SID, &request, &response) - != NSS_STATUS_SUCCESS) { - PyErr_SetString(winbind_error, "lookup failed"); - return NULL; - } - - return PyString_FromString(response.data.sid.sid); -} - -/* Convert a gid to a SID */ - -static PyObject *py_gid_to_sid(PyObject *self, PyObject *args) -{ - struct winbindd_request request; - struct winbindd_response response; - int id; - - if (!PyArg_ParseTuple(args, "i", &id)) - return NULL; - - ZERO_STRUCT(request); - ZERO_STRUCT(response); - - request.data.gid = id; - - if (winbindd_request(WINBINDD_GID_TO_SID, &request, &response) - != NSS_STATUS_SUCCESS) { - PyErr_SetString(winbind_error, "lookup failed"); - return NULL; - } - - return PyString_FromString(response.data.sid.sid); -} - -/* Convert a sid to a uid */ - -static PyObject *py_sid_to_uid(PyObject *self, PyObject *args) -{ - struct winbindd_request request; - struct winbindd_response response; - char *sid; - - if (!PyArg_ParseTuple(args, "s", &sid)) - return NULL; - - ZERO_STRUCT(request); - ZERO_STRUCT(response); - - fstrcpy(request.data.sid, sid); - - if (winbindd_request(WINBINDD_SID_TO_UID, &request, &response) - != NSS_STATUS_SUCCESS) { - PyErr_SetString(winbind_error, "lookup failed"); - return NULL; - } - - return PyInt_FromLong(response.data.uid); -} - -/* Convert a sid to a gid */ - -static PyObject *py_sid_to_gid(PyObject *self, PyObject *args) -{ - struct winbindd_request request; - struct winbindd_response response; - char *sid; - - if (!PyArg_ParseTuple(args, "s", &sid)) - return NULL; - - ZERO_STRUCT(request); - ZERO_STRUCT(response); - - fstrcpy(request.data.sid, sid); - - if (winbindd_request(WINBINDD_SID_TO_GID, &request, &response) - != NSS_STATUS_SUCCESS) { - PyErr_SetString(winbind_error, "lookup failed"); - return NULL; - } - - return PyInt_FromLong(response.data.gid); -} - -/* - * PAM authentication functions - */ - -/* Plaintext authentication */ - -static PyObject *py_auth_plaintext(PyObject *self, PyObject *args) -{ - struct winbindd_request request; - struct winbindd_response response; - char *username, *password; - - if (!PyArg_ParseTuple(args, "ss", &username, &password)) - return NULL; - - ZERO_STRUCT(request); - ZERO_STRUCT(response); - - fstrcpy(request.data.auth.user, username); - fstrcpy(request.data.auth.pass, password); - - if (winbindd_request(WINBINDD_PAM_AUTH, &request, &response) - != NSS_STATUS_SUCCESS) { - PyErr_SetString(winbind_error, "lookup failed"); - return NULL; - } - - return PyInt_FromLong(response.data.auth.nt_status); -} - -/* Challenge/response authentication */ - -static PyObject *py_auth_crap(PyObject *self, PyObject *args) -{ - struct winbindd_request request; - struct winbindd_response response; - char *username, *password; - - if (!PyArg_ParseTuple(args, "ss", &username, &password)) - return NULL; - - ZERO_STRUCT(request); - ZERO_STRUCT(response); - - fstrcpy(request.data.auth_crap.user, username); - - generate_random_buffer(request.data.auth_crap.chal, 8, False); - - SMBencrypt((uchar *)password, request.data.auth_crap.chal, - (uchar *)request.data.auth_crap.lm_resp); - SMBNTencrypt((uchar *)password, request.data.auth_crap.chal, - (uchar *)request.data.auth_crap.nt_resp); - - request.data.auth_crap.lm_resp_len = 24; - request.data.auth_crap.nt_resp_len = 24; - - if (winbindd_request(WINBINDD_PAM_AUTH_CRAP, &request, &response) - != NSS_STATUS_SUCCESS) { - PyErr_SetString(winbind_error, "lookup failed"); - return NULL; - } - - return PyInt_FromLong(response.data.auth.nt_status); -} - -/* - * Method dispatch table - */ - -static PyMethodDef winbind_methods[] = { - - /* Name <-> SID conversion */ - - { "name_to_sid", py_name_to_sid, METH_VARARGS, - "name_to_sid(s) -> string - -Return the SID for a name. - -Example: - ->>> winbind.name_to_sid('FOO/Administrator') -'S-1-5-21-406022937-1377575209-526660263-500' " }, - - { "sid_to_name", py_sid_to_name, METH_VARARGS, - "sid_to_name(s) -> string - -Return the name for a SID. - -Example: - ->>> import winbind ->>> winbind.sid_to_name('S-1-5-21-406022937-1377575209-526660263-500') -'FOO/Administrator' " }, - - /* Enumerate users/groups */ - - { "enum_domain_users", py_enum_domain_users, METH_VARARGS, - "enum_domain_users() -> list of strings - -Return a list of domain users. - -Example: - ->>> winbind.enum_domain_users() -['FOO/Administrator', 'FOO/anna', 'FOO/Anne Elk', 'FOO/build', -'FOO/foo', 'FOO/foo2', 'FOO/foo3', 'FOO/Guest', 'FOO/user1', -'FOO/whoops-ptang'] " }, - - { "enum_domain_groups", py_enum_domain_groups, METH_VARARGS, - "enum_domain_groups() -> list of strings - -Return a list of domain groups. - -Example: - ->>> winbind.enum_domain_groups() -['FOO/cows', 'FOO/Domain Admins', 'FOO/Domain Guests', -'FOO/Domain Users'] " }, - - /* ID mapping */ - - { "uid_to_sid", py_uid_to_sid, METH_VARARGS, - "uid_to_sid(int) -> string - -Return the SID for a UNIX uid. - -Example: - ->>> winbind.uid_to_sid(10000) -'S-1-5-21-406022937-1377575209-526660263-500' " }, - - { "gid_to_sid", py_gid_to_sid, METH_VARARGS, - "gid_to_sid(int) -> string - -Return the UNIX gid for a SID. - -Example: - ->>> winbind.gid_to_sid(10001) -'S-1-5-21-406022937-1377575209-526660263-512' " }, - - { "sid_to_uid", py_sid_to_uid, METH_VARARGS, - "sid_to_uid(string) -> int - -Return the UNIX uid for a SID. - -Example: - ->>> winbind.sid_to_uid('S-1-5-21-406022937-1377575209-526660263-500') -10000 " }, - - { "sid_to_gid", py_sid_to_gid, METH_VARARGS, - "sid_to_gid(string) -> int - -Return the UNIX gid corresponding to a SID. - -Example: - ->>> winbind.sid_to_gid('S-1-5-21-406022937-1377575209-526660263-512') -10001 " }, - - /* Miscellaneous */ - - { "check_secret", py_check_secret, METH_VARARGS, - "check_secret() -> int - -Check the machine trust account password. The NT status is returned -with zero indicating success. " }, - - { "enum_trust_dom", py_enum_trust_dom, METH_VARARGS, - "enum_trust_dom() -> list of strings - -Return a list of trusted domains. The domain the server is a member -of is not included. - -Example: - ->>> winbind.enum_trust_dom() -['NPSD-TEST2', 'SP2NDOM'] " }, - - /* PAM authorisation functions */ - - { "auth_plaintext", py_auth_plaintext, METH_VARARGS, - "auth_plaintext(s, s) -> int - -Authenticate a username and password using plaintext authentication. -The NT status code is returned with zero indicating success." }, - - { "auth_crap", py_auth_crap, METH_VARARGS, - "auth_crap(s, s) -> int - -Authenticate a username and password using the challenge/response -protocol. The NT status code is returned with zero indicating -success." }, - - { NULL } -}; - -static struct const_vals { - char *name; - uint32 value; - char *docstring; -} module_const_vals[] = { - - /* Well known RIDs */ - - { "DOMAIN_USER_RID_ADMIN", DOMAIN_USER_RID_ADMIN, - "Well-known RID for Administrator user" }, - - { "DOMAIN_USER_RID_GUEST", DOMAIN_USER_RID_GUEST, - "Well-known RID for Guest user" }, - - { "DOMAIN_GROUP_RID_ADMINS", DOMAIN_GROUP_RID_ADMINS, - "Well-known RID for Domain Admins group" }, - - { "DOMAIN_GROUP_RID_USERS", DOMAIN_GROUP_RID_USERS, - "Well-known RID for Domain Users group" }, - - { "DOMAIN_GROUP_RID_GUESTS", DOMAIN_GROUP_RID_GUESTS, - "Well-known RID for Domain Guests group" }, - - { NULL } -}; - -static void const_init(PyObject *dict) -{ - struct const_vals *tmp; - PyObject *obj; - - for (tmp = module_const_vals; tmp->name; tmp++) { - obj = PyInt_FromLong(tmp->value); - PyDict_SetItemString(dict, tmp->name, obj); - Py_DECREF(obj); - } -} - -/* - * Module initialisation - */ - -static char winbind_module__doc__[] = -"A python extension to winbind client functions."; - -void initwinbind(void) -{ - PyObject *module, *dict; - - /* Initialise module */ - - module = Py_InitModule3("winbind", winbind_methods, - winbind_module__doc__); - - dict = PyModule_GetDict(module); - - winbind_error = PyErr_NewException("winbind.error", NULL, NULL); - PyDict_SetItemString(dict, "error", winbind_error); - - /* Do samba initialisation */ - - py_samba_init(); - - /* Initialise constants */ - - const_init(dict); - - /* Insert configuration dictionary */ - - PyDict_SetItemString(dict, "config", py_config_dict()); -} diff --git a/source3/python/samba-head.patch b/source3/python/samba-head.patch deleted file mode 100644 index a739346a5b..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.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 @@ - -$(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.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 -@@ -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) - - ################################################# - # Print very concise instructions on building/use diff --git a/source3/python/setup.py.in b/source3/python/setup.py.in deleted file mode 100755 index c61ec2c214..0000000000 --- a/source3/python/setup.py.in +++ /dev/null @@ -1,163 +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_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), - - ], -) |