From 8d994f432d34a7e81335c3be05aa40f1e227636c Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Sun, 14 Apr 2002 00:58:16 +0000 Subject: Moved open_pipe_creds() function to common file. (This used to be commit 14e4d889a236dd9c2ba6db68b3133e44195b8a47) --- source3/python/py_common.c | 78 ++++++++++++++++++++++++++++++++++++++++++++++ source3/python/py_common.h | 13 +++++++- 2 files changed, 90 insertions(+), 1 deletion(-) (limited to 'source3/python') diff --git a/source3/python/py_common.c b/source3/python/py_common.c index bc3153c26c..019bcca07c 100644 --- a/source3/python/py_common.c +++ b/source3/python/py_common.c @@ -21,6 +21,8 @@ #include "includes.h" #include "Python.h" +#include "python/py_common.h" + /* Return a tuple of (error code, error string) from a WERROR */ PyObject *py_werror_tuple(WERROR werror) @@ -115,3 +117,79 @@ PyObject *py_setup_logging(PyObject *self, PyObject *args, PyObject *kw) Py_INCREF(Py_None); return Py_None; } + +struct cli_state *open_pipe_creds(char *system_name, PyObject *creds, + cli_pipe_fn *connect_fn, + struct cli_state *cli) +{ + struct ntuser_creds nt_creds; + + if (!cli) { + cli = (struct cli_state *)malloc(sizeof(struct cli_state)); + if (!cli) + return NULL; + } + + ZERO_STRUCTP(cli); + + /* Extract credentials from the python dictionary and initialise + the ntuser_creds struct from them. */ + + ZERO_STRUCT(nt_creds); + nt_creds.pwd.null_pwd = True; + + if (creds && PyDict_Size(creds) > 0) { + char *username, *password, *domain; + PyObject *username_obj, *password_obj, *domain_obj; + + /* Check credentials passed are valid. This means the + username, domain and password keys must exist and be + string objects. */ + + username_obj = PyDict_GetItemString(creds, "username"); + domain_obj = PyDict_GetItemString(creds, "domain"); + password_obj = PyDict_GetItemString(creds, "password"); + + if (!username_obj || !domain_obj || !password_obj) { + error: + + /* TODO: Either pass in the exception for the + module calling open_pipe_creds() or have a + global samba python module exception. */ + + PyErr_SetString(PyExc_RuntimeError, + "invalid credentials"); + return NULL; + } + + if (!PyString_Check(username_obj) || + !PyString_Check(domain_obj) || + !PyString_Check(password_obj)) + goto error; + + username = PyString_AsString(username_obj); + domain = PyString_AsString(domain_obj); + password = PyString_AsString(password_obj); + + if (!username || !domain || !password) + goto error; + + /* Initialise nt_creds structure with passed creds */ + + fstrcpy(nt_creds.user_name, username); + fstrcpy(nt_creds.domain, domain); + + if (lp_encrypted_passwords()) + pwd_make_lm_nt_16(&nt_creds.pwd, password); + else + pwd_set_cleartext(&nt_creds.pwd, password); + + nt_creds.pwd.null_pwd = False; + } + + /* Now try to connect */ + + connect_fn(cli, system_name, &nt_creds); + + return cli; +} diff --git a/source3/python/py_common.h b/source3/python/py_common.h index 4a5c92ca8c..45ad5c422d 100644 --- a/source3/python/py_common.h +++ b/source3/python/py_common.h @@ -27,8 +27,19 @@ void py_samba_init(void); PyObject *py_werror_tuple(WERROR werror); PyObject *py_ntstatus_tuple(NTSTATUS ntstatus); -PyObject *py_setup_logging(PyObject *self, PyObject *args); +PyObject *py_setup_logging(PyObject *self, PyObject *args, PyObject *kw); PyObject *get_debuglevel(PyObject *self, PyObject *args); PyObject *set_debuglevel(PyObject *self, PyObject *args); +/* Return a cli_state struct opened on the SPOOLSS pipe. If credentials + are passed use them. */ + +typedef struct cli_state *(cli_pipe_fn)( + struct cli_state *cli, char *system_name, + struct ntuser_creds *creds); + +struct cli_state *open_pipe_creds(char *system_name, PyObject *creds, + cli_pipe_fn *connect_fn, + struct cli_state *cli); + #endif /* _PY_COMMON_H */ -- cgit From 54bda76922cb14579bb363135da8862982d22925 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Sun, 14 Apr 2002 00:59:50 +0000 Subject: More open_pipe_creds() refactoring. (This used to be commit 7f2c814237f1df7008c9a91b7cf3b1de01e6ed87) --- source3/python/py_lsa.c | 82 ++++++++++++++++++++++++++++++++------- source3/python/py_spoolss.c | 70 --------------------------------- source3/python/py_spoolss.h | 7 ---- source3/python/py_spoolss_proto.h | 3 -- 4 files changed, 68 insertions(+), 94 deletions(-) (limited to 'source3/python') diff --git a/source3/python/py_lsa.c b/source3/python/py_lsa.c index dfb9b642ed..5e805a91ad 100644 --- a/source3/python/py_lsa.c +++ b/source3/python/py_lsa.c @@ -1,19 +1,12 @@ #include "includes.h" #include "Python.h" -#include "python/py_common.h" +#include "python/py_lsa.h" static void py_policy_hnd_dealloc(PyObject* self) { PyObject_Del(self); } -typedef struct { - PyObject_HEAD - struct cli_state *cli; - TALLOC_CTX *mem_ctx; - POLICY_HND pol; -} lsa_policy_hnd_object; - PyTypeObject lsa_policy_hnd_type = { PyObject_HEAD_INIT(NULL) 0, @@ -32,6 +25,20 @@ PyTypeObject lsa_policy_hnd_type = { 0, /*tp_hash */ }; +PyObject *new_lsa_policy_hnd_object(struct cli_state *cli, TALLOC_CTX *mem_ctx, + POLICY_HND *pol) +{ + lsa_policy_hnd_object *o; + + o = PyObject_New(lsa_policy_hnd_object, &lsa_policy_hnd_type); + + o->cli = cli; + o->mem_ctx = mem_ctx; + memcpy(&o->pol, pol, sizeof(POLICY_HND)); + + return (PyObject*)o; +} + /* * Exceptions raised by this module */ @@ -52,23 +59,70 @@ static PyObject *lsa_openpolicy(PyObject *self, PyObject *args, { static char *kwlist[] = { "servername", "creds", "access", NULL }; char *server_name; - PyObject *creds = NULL; + PyObject *creds = NULL, *result; uint32 desired_access = MAXIMUM_ALLOWED_ACCESS; + struct cli_state *cli; + NTSTATUS ntstatus; + TALLOC_CTX *mem_ctx; + POLICY_HND hnd; if (!PyArg_ParseTupleAndKeywords( args, kw, "s|O!i", kwlist, &server_name, &PyDict_Type, - &creds, &desired_access)) { + &creds, &desired_access)) + return NULL; - goto done; + if (!(cli = open_pipe_creds(server_name, creds, cli_lsa_initialise, + NULL))) { + fprintf(stderr, "could not initialise cli state\n"); + return NULL; } - done: - return NULL; + if (!(mem_ctx = talloc_init())) { + fprintf(stderr, "unable to initialise talloc context\n"); + return NULL; + } + + ntstatus = cli_lsa_open_policy(cli, mem_ctx, True, + SEC_RIGHTS_MAXIMUM_ALLOWED, &hnd); + + if (!NT_STATUS_IS_OK(ntstatus)) { + cli_shutdown(cli); + SAFE_FREE(cli); + PyErr_SetObject(lsa_ntstatus, py_ntstatus_tuple(ntstatus)); + return NULL; + } + + result = new_lsa_policy_hnd_object(cli, mem_ctx, &hnd); + + return result; } static PyObject *lsa_close(PyObject *self, PyObject *args, PyObject *kw) { - return NULL; + PyObject *po; + lsa_policy_hnd_object *hnd; + NTSTATUS result; + + /* Parse parameters */ + + if (!PyArg_ParseTuple(args, "O!", &lsa_policy_hnd_type, &po)) + return NULL; + + hnd = (lsa_policy_hnd_object *)po; + + /* Call rpc function */ + + result = cli_lsa_close(hnd->cli, hnd->mem_ctx, &hnd->pol); + + /* Cleanup samba stuf */ + + cli_shutdown(hnd->cli); + talloc_destroy(hnd->mem_ctx); + + /* Return value */ + + Py_INCREF(Py_None); + return Py_None; } static PyObject *lsa_lookupnames(PyObject *self, PyObject *args, diff --git a/source3/python/py_spoolss.c b/source3/python/py_spoolss.c index ead54febda..450abbd6dc 100644 --- a/source3/python/py_spoolss.c +++ b/source3/python/py_spoolss.c @@ -28,76 +28,6 @@ PyObject *spoolss_error, *spoolss_werror; * Routines to convert from python hashes to Samba structures */ -struct cli_state *open_pipe_creds(char *system_name, PyObject *creds, - cli_pipe_fn *connect_fn, - struct cli_state *cli) -{ - struct ntuser_creds nt_creds; - - if (!cli) { - cli = (struct cli_state *)malloc(sizeof(struct cli_state)); - if (!cli) - return NULL; - } - - ZERO_STRUCTP(cli); - - /* Extract credentials from the python dictionary and initialise - the ntuser_creds struct from them. */ - - ZERO_STRUCT(nt_creds); - nt_creds.pwd.null_pwd = True; - - if (creds && PyDict_Size(creds) > 0) { - char *username, *password, *domain; - PyObject *username_obj, *password_obj, *domain_obj; - - /* Check credentials passed are valid. This means the - username, domain and password keys must exist and be - string objects. */ - - username_obj = PyDict_GetItemString(creds, "username"); - domain_obj = PyDict_GetItemString(creds, "domain"); - password_obj = PyDict_GetItemString(creds, "password"); - - if (!username_obj || !domain_obj || !password_obj) { - error: - PyErr_SetString(spoolss_error, "invalid credentials"); - return NULL; - } - - if (!PyString_Check(username_obj) || - !PyString_Check(domain_obj) || - !PyString_Check(password_obj)) - goto error; - - username = PyString_AsString(username_obj); - domain = PyString_AsString(domain_obj); - password = PyString_AsString(password_obj); - - if (!username || !domain || !password) - goto error; - - /* Initialise nt_creds structure with passed creds */ - - fstrcpy(nt_creds.user_name, username); - fstrcpy(nt_creds.domain, domain); - - if (lp_encrypted_passwords()) - pwd_make_lm_nt_16(&nt_creds.pwd, password); - else - pwd_set_cleartext(&nt_creds.pwd, password); - - nt_creds.pwd.null_pwd = False; - } - - /* Now try to connect */ - - connect_fn(cli, system_name, &nt_creds); - - return cli; -} - PyObject *new_policy_hnd_object(struct cli_state *cli, TALLOC_CTX *mem_ctx, POLICY_HND *pol) { diff --git a/source3/python/py_spoolss.h b/source3/python/py_spoolss.h index 7c7669c752..777a2b5991 100644 --- a/source3/python/py_spoolss.h +++ b/source3/python/py_spoolss.h @@ -41,13 +41,6 @@ extern PyTypeObject spoolss_policy_hnd_type; extern PyObject *spoolss_error, *spoolss_werror; -/* Return a cli_state struct opened on the SPOOLSS pipe. If credentials - are passed use them. */ - -typedef struct cli_state *(cli_pipe_fn)( - struct cli_state *cli, char *system_name, - struct ntuser_creds *creds); - #include "python/py_spoolss_proto.h" #endif /* _PY_SPOOLSS_H */ diff --git a/source3/python/py_spoolss_proto.h b/source3/python/py_spoolss_proto.h index 6788dcccd1..3e3e5ef6ee 100644 --- a/source3/python/py_spoolss_proto.h +++ b/source3/python/py_spoolss_proto.h @@ -6,9 +6,6 @@ /* The following definitions come from python/py_spoolss.c */ -struct cli_state *open_pipe_creds(char *system_name, PyObject *creds, - cli_pipe_fn *connect_fn, - struct cli_state *cli); PyObject *new_policy_hnd_object(struct cli_state *cli, TALLOC_CTX *mem_ctx, POLICY_HND *pol); void initspoolss(void); -- cgit From a160d7bbb1cde89923d8e50117a164d9ed0184ec Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Sun, 14 Apr 2002 01:00:49 +0000 Subject: Starting work on lsa module. (This used to be commit 5c44397803622400390b13f1998b49f5da83d2a1) --- source3/python/py_lsa.h | 46 +++++++++++++++++++++++++++++++++++++++++++ source3/python/py_lsa_proto.h | 13 ++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 source3/python/py_lsa.h create mode 100644 source3/python/py_lsa_proto.h (limited to 'source3/python') diff --git a/source3/python/py_lsa.h b/source3/python/py_lsa.h new file mode 100644 index 0000000000..a963fcac98 --- /dev/null +++ b/source3/python/py_lsa.h @@ -0,0 +1,46 @@ +/* + 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_LSA_H +#define _PY_LSA_H + +#include "includes.h" +#include "Python.h" + +#include "python/py_common.h" + +/* LSA policy handle object */ + +typedef struct { + PyObject_HEAD + struct cli_state *cli; + TALLOC_CTX *mem_ctx; + POLICY_HND pol; +} lsa_policy_hnd_object; + +/* Exceptions raised by this module */ + +extern PyTypeObject lsa_policy_hnd_type; + +extern PyObject *lsa_error; + +#include "python/py_lsa_proto.h" + +#endif /* _PY_LSA_H */ diff --git a/source3/python/py_lsa_proto.h b/source3/python/py_lsa_proto.h new file mode 100644 index 0000000000..066a0aad53 --- /dev/null +++ b/source3/python/py_lsa_proto.h @@ -0,0 +1,13 @@ +#ifndef _PY_LSA_PROTO_H +#define _PY_LSA_PROTO_H + +/* This file is automatically generated with "make proto". DO NOT EDIT */ + + +/* The following definitions come from python/py_lsa.c */ + +PyObject *new_policy_hnd_object(struct cli_state *cli, TALLOC_CTX *mem_ctx, + POLICY_HND *pol); +void initlsa(void); + +#endif /* _PY_LSA_PROTO_H */ -- cgit From d837a511e8057b23e493a078d18a1b96fa69d69c Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Sun, 14 Apr 2002 01:01:39 +0000 Subject: Generate proto for lsa. Updated patch. (This used to be commit 5dbd716b99c522eac89d9216eb4293084958b966) --- source3/python/samba-head.patch | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) (limited to 'source3/python') diff --git a/source3/python/samba-head.patch b/source3/python/samba-head.patch index 2e0863e31e..223e0179fb 100644 --- a/source3/python/samba-head.patch +++ b/source3/python/samba-head.patch @@ -1,11 +1,11 @@ Index: Makefile.in =================================================================== RCS file: /data/cvs/samba/source/Makefile.in,v -retrieving revision 1.465 -diff -u -r1.465 Makefile.in ---- Makefile.in 2002/04/04 22:58:56 1.465 -+++ Makefile.in 2002/04/05 05:48:51 -@@ -785,6 +785,29 @@ +retrieving revision 1.470 +diff -u -r1.470 Makefile.in +--- Makefile.in 2002/04/13 11:45:33 1.470 ++++ Makefile.in 2002/04/14 01:01:05 +@@ -787,6 +787,36 @@ -$(INSTALLCMD) -d ${prefix}/include -$(INSTALLCMD) include/libsmbclient.h ${prefix}/include @@ -20,13 +20,20 @@ diff -u -r1.465 Makefile.in + python/py_spoolss_ports.o python/py_spoolss_ports_conv.o \ + python/py_spoolss_drivers.o python/py_spoolss_drivers_conv.o \ + -+python_proto: python_spoolss_proto ++PY_LSA_PROTO_OBJ = python/py_lsa.o ++ ++python_proto: python_spoolss_proto python_lsa_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_ext: $(PYTHON_OBJS) + @echo python python/setup.py build + @PYTHON_OBJS="$(PYTHON_OBJS)" PYTHON_CFLAGS="$(CFLAGS) $(CPPFLAGS)" \ @@ -38,11 +45,11 @@ diff -u -r1.465 Makefile.in Index: configure.in =================================================================== RCS file: /data/cvs/samba/source/configure.in,v -retrieving revision 1.298 -diff -u -r1.298 configure.in ---- configure.in 2002/04/04 05:47:41 1.298 -+++ configure.in 2002/04/05 05:48:52 -@@ -2695,7 +2695,7 @@ +retrieving revision 1.300 +diff -u -r1.300 configure.in +--- configure.in 2002/04/11 15:26:58 1.300 ++++ configure.in 2002/04/14 01:01:08 +@@ -2716,7 +2716,7 @@ builddir=`pwd` AC_SUBST(builddir) -- cgit From db32b9ceb726ad24fe022eae71b315683f840508 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Sun, 14 Apr 2002 04:55:18 +0000 Subject: Made a comment clearer. (This used to be commit 703e0a6ce2d283349f64cba72b36c1bef6a0d806) --- source3/python/py_spoolss_printers_conv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/python') diff --git a/source3/python/py_spoolss_printers_conv.c b/source3/python/py_spoolss_printers_conv.c index 84a068181f..c583792c0a 100644 --- a/source3/python/py_spoolss_printers_conv.c +++ b/source3/python/py_spoolss_printers_conv.c @@ -144,7 +144,7 @@ struct pyconv py_DEVICEMODE[] = { { NULL } }; -/* Convert a security descriptor to a Python dict */ +/* Convert a SID to a Python dict */ BOOL py_from_SID(PyObject **obj, DOM_SID *sid) { -- cgit From f143cb6144a564f0248770cd552e440dbcddb056 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Sun, 14 Apr 2002 09:00:13 +0000 Subject: Added copyright. Added lookup_names() and lookup_sids() functions. (This used to be commit 2d2c925014374605b29e052729e959c0fd690586) --- source3/python/py_lsa.c | 202 ++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 160 insertions(+), 42 deletions(-) (limited to 'source3/python') diff --git a/source3/python/py_lsa.c b/source3/python/py_lsa.c index 5e805a91ad..1c84af5ea0 100644 --- a/source3/python/py_lsa.c +++ b/source3/python/py_lsa.c @@ -1,29 +1,27 @@ +/* + 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_lsa.h" -static void py_policy_hnd_dealloc(PyObject* self) -{ - PyObject_Del(self); -} - -PyTypeObject lsa_policy_hnd_type = { - PyObject_HEAD_INIT(NULL) - 0, - "LSA Policy Handle", - sizeof(lsa_policy_hnd_object), - 0, - py_policy_hnd_dealloc, /*tp_dealloc*/ - 0, /*tp_print*/ - 0, /*tp_getattr*/ - 0, /*tp_setattr*/ - 0, /*tp_compare*/ - 0, /*tp_repr*/ - 0, /*tp_as_number*/ - 0, /*tp_as_sequence*/ - 0, /*tp_as_mapping*/ - 0, /*tp_hash */ -}; PyObject *new_lsa_policy_hnd_object(struct cli_state *cli, TALLOC_CTX *mem_ctx, POLICY_HND *pol) @@ -54,7 +52,7 @@ PyObject *lsa_ntstatus; /* This exception is raised when a RPC call * Open/close lsa handles */ -static PyObject *lsa_openpolicy(PyObject *self, PyObject *args, +static PyObject *lsa_open_policy(PyObject *self, PyObject *args, PyObject *kw) { static char *kwlist[] = { "servername", "creds", "access", NULL }; @@ -114,7 +112,7 @@ static PyObject *lsa_close(PyObject *self, PyObject *args, PyObject *kw) result = cli_lsa_close(hnd->cli, hnd->mem_ctx, &hnd->pol); - /* Cleanup samba stuf */ + /* Cleanup samba stuff */ cli_shutdown(hnd->cli); talloc_destroy(hnd->mem_ctx); @@ -125,39 +123,156 @@ static PyObject *lsa_close(PyObject *self, PyObject *args, PyObject *kw) return Py_None; } -static PyObject *lsa_lookupnames(PyObject *self, PyObject *args, - PyObject *kw) +static PyObject *lsa_lookup_names(PyObject *self, PyObject *args) { - return NULL; + PyObject *py_names, *result; + NTSTATUS ntstatus; + lsa_policy_hnd_object *hnd = (lsa_policy_hnd_object *)self; + int num_names, i; + const char **names; + DOM_SID *sids; + uint32 *name_types; + + if (!PyArg_ParseTuple(args, "O!", &PyList_Type, &py_names)) + return NULL; + + /* Convert dictionary to char ** array */ + + num_names = PyList_Size(py_names); + names = (const char **)talloc( + hnd->mem_ctx, num_names * sizeof(char *)); + + for (i = 0; i < num_names; i++) { + PyObject *obj = PyList_GetItem(py_names, i); + + names[i] = talloc_strdup(hnd->mem_ctx, PyString_AsString(obj)); + } + + ntstatus = cli_lsa_lookup_names(hnd->cli, hnd->mem_ctx, &hnd->pol, + num_names, names, &sids, &name_types); + + if (!NT_STATUS_IS_OK(ntstatus) && NT_STATUS_V(ntstatus) != 0x107) { + PyErr_SetObject(lsa_ntstatus, py_ntstatus_tuple(ntstatus)); + return NULL; + } + + result = PyList_New(num_names); + + for (i = 0; i < num_names; i++) { + PyObject *sid_obj, *obj; + + py_from_SID(&sid_obj, &sids[i]); + + obj = Py_BuildValue("(Oi)", sid_obj, name_types[i]); + + PyList_SetItem(result, i, obj); + } + + return result; } -static PyObject *lsa_lookupsids(PyObject *self, PyObject *args, - PyObject *kw) +static PyObject *lsa_lookup_sids(PyObject *self, PyObject *args, + PyObject *kw) { - return NULL; + PyObject *py_sids, *result; + NTSTATUS ntstatus; + int num_sids, i; + char **domains, **names; + uint32 *types; + lsa_policy_hnd_object *hnd = (lsa_policy_hnd_object *)self; + DOM_SID *sids; + + if (!PyArg_ParseTuple(args, "O!", &PyList_Type, &py_sids)) + return NULL; + + /* Convert dictionary to char ** array */ + + num_sids = PyList_Size(py_sids); + sids = (DOM_SID *)talloc(hnd->mem_ctx, num_sids * sizeof(DOM_SID)); + + memset(sids, 0, num_sids * sizeof(DOM_SID)); + + for (i = 0; i < num_sids; i++) { + PyObject *obj = PyList_GetItem(py_sids, i); + + string_to_sid(&sids[i], PyString_AsString(obj)); + } + + ntstatus = cli_lsa_lookup_sids(hnd->cli, hnd->mem_ctx, &hnd->pol, + num_sids, sids, &domains, &names, + &types); + + if (!NT_STATUS_IS_OK(ntstatus)) { + PyErr_SetObject(lsa_ntstatus, py_ntstatus_tuple(ntstatus)); + return NULL; + } + + result = PyList_New(num_sids); + + for (i = 0; i < num_sids; i++) { + PyObject *name_obj, *obj; + + obj = Py_BuildValue("{sssssi}", "username", names[i], + "domain", domains[i], "name_type", + types[i]); + + PyList_SetItem(result, i, obj); + } + + return result; } /* - * Method dispatch table + * Method dispatch tables */ +static PyMethodDef lsa_hnd_methods[] = { + + { "lookup_sids", lsa_lookup_sids, METH_VARARGS | METH_KEYWORDS, + "Convert sids to names." }, + + { "lookup_names", lsa_lookup_names, METH_VARARGS | METH_KEYWORDS, + "Convert names to sids." }, + + { NULL } +}; + +static void py_lsa_policy_hnd_dealloc(PyObject* self) +{ + PyObject_Del(self); +} + +static PyObject *py_lsa_policy_hnd_getattr(PyObject *self, char *attrname) +{ + return Py_FindMethod(lsa_hnd_methods, self, attrname); +} + +PyTypeObject lsa_policy_hnd_type = { + PyObject_HEAD_INIT(NULL) + 0, + "LSA Policy Handle", + sizeof(lsa_policy_hnd_object), + 0, + py_lsa_policy_hnd_dealloc, /*tp_dealloc*/ + 0, /*tp_print*/ + py_lsa_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 */ +}; + static PyMethodDef lsa_methods[] = { /* Open/close lsa handles */ - { "openpolicy", lsa_openpolicy, METH_VARARGS | METH_KEYWORDS, + { "open_policy", lsa_open_policy, METH_VARARGS | METH_KEYWORDS, "Open a policy handle" }, - { "close", lsa_close, METH_VARARGS, - "Close a policy handle" }, - - /* Name <-> SID resolution */ - - { "lookupnames", lsa_lookupnames, METH_VARARGS | METH_KEYWORDS, - "Look up SIDS from a list of names" }, - - { "lookupsids", lsa_lookupsids, METH_VARARGS | METH_KEYWORDS, - "Look up names from a list of SIDS" }, + { "close", lsa_close, METH_VARARGS, "Close a policy handle" }, { NULL } }; @@ -192,4 +307,7 @@ void initlsa(void) /* Do samba initialisation */ py_samba_init(); + + setup_logging("lsa", True); + DEBUGLEVEL = 10; } -- cgit From cc8dce0debe4dc81bdb94fc4593eda22e5b8200a Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Sun, 14 Apr 2002 09:03:05 +0000 Subject: Moved function prototypes to py_common_proto.h (This used to be commit f006bcf8e50e44b955678356039a6d6a7e16ab20) --- source3/python/py_common.h | 14 +------------- 1 file changed, 1 insertion(+), 13 deletions(-) (limited to 'source3/python') diff --git a/source3/python/py_common.h b/source3/python/py_common.h index 45ad5c422d..6661d87fe0 100644 --- a/source3/python/py_common.h +++ b/source3/python/py_common.h @@ -21,16 +21,6 @@ #ifndef _PY_COMMON_H #define _PY_COMMON_H -/* Function prototypes */ - -void py_samba_init(void); -PyObject *py_werror_tuple(WERROR werror); -PyObject *py_ntstatus_tuple(NTSTATUS ntstatus); - -PyObject *py_setup_logging(PyObject *self, PyObject *args, PyObject *kw); -PyObject *get_debuglevel(PyObject *self, PyObject *args); -PyObject *set_debuglevel(PyObject *self, PyObject *args); - /* Return a cli_state struct opened on the SPOOLSS pipe. If credentials are passed use them. */ @@ -38,8 +28,6 @@ typedef struct cli_state *(cli_pipe_fn)( struct cli_state *cli, char *system_name, struct ntuser_creds *creds); -struct cli_state *open_pipe_creds(char *system_name, PyObject *creds, - cli_pipe_fn *connect_fn, - struct cli_state *cli); +#include "python/py_common_proto.h" #endif /* _PY_COMMON_H */ -- cgit From 562393fc85b977fa55134e0767d9ddf0569c0100 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Sun, 14 Apr 2002 09:04:12 +0000 Subject: Moved security descriptor routines into their own file. (This used to be commit 8e0457f8aa7b5ecababcdec4dfbc328d11513192) --- source3/python/py_ntsec.c | 139 ++++++++++++++++++++++++++++++ source3/python/py_spoolss_printers_conv.c | 115 ------------------------ source3/python/setup.py.in | 4 +- 3 files changed, 142 insertions(+), 116 deletions(-) create mode 100644 source3/python/py_ntsec.c (limited to 'source3/python') diff --git a/source3/python/py_ntsec.c b/source3/python/py_ntsec.c new file mode 100644 index 0000000000..d97bbb6f8c --- /dev/null +++ b/source3/python/py_ntsec.c @@ -0,0 +1,139 @@ +/* + Python wrappers for DCERPC/SMB client routines. + + Copyright (C) Tim Potter, 2002 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" +#include "Python.h" + +#include "python/py_common.h" + +/* Convert a SID to a Python dict */ + +BOOL py_from_SID(PyObject **obj, DOM_SID *sid) +{ + fstring sidstr; + + if (!sid) { + Py_INCREF(Py_None); + *obj = Py_None; + return True; + } + + if (!sid_to_string(sidstr, sid)) + return False; + + *obj = PyString_FromString(sidstr); + + return True; +} + +BOOL py_to_SID(DOM_SID *sid, PyObject *dict) +{ + return False; +} + +BOOL py_from_ACE(PyObject **dict, SEC_ACE *ace) +{ + PyObject *obj; + + if (!ace) { + Py_INCREF(Py_None); + *dict = Py_None; + return True; + } + + *dict = PyDict_New(); + + PyDict_SetItemString(*dict, "type", PyInt_FromLong(ace->type)); + PyDict_SetItemString(*dict, "flags", PyInt_FromLong(ace->flags)); + PyDict_SetItemString(*dict, "mask", PyInt_FromLong(ace->info.mask)); + + if (py_from_SID(&obj, &ace->trustee)) + PyDict_SetItemString(*dict, "trustee", obj); + + return True; +} + +BOOL py_to_ACE(SEC_ACE *ace, PyObject *dict) +{ + return False; +} + +BOOL py_from_ACL(PyObject **dict, SEC_ACL *acl) +{ + PyObject *ace_list; + int i; + + if (!acl) { + Py_INCREF(Py_None); + *dict = Py_None; + return True; + } + + *dict = PyDict_New(); + + PyDict_SetItemString(*dict, "revision", PyInt_FromLong(acl->revision)); + + ace_list = PyList_New(acl->num_aces); + + for (i = 0; i < acl->num_aces; i++) { + PyObject *obj; + + if (py_from_ACE(&obj, &acl->ace[i])) + PyList_SetItem(ace_list, i, obj); + } + + PyDict_SetItemString(*dict, "ace_list", ace_list); + + return True; +} + +BOOL py_to_ACL(SEC_ACL *acl, PyObject *dict) +{ + return False; +} + +BOOL py_from_SECDESC(PyObject **dict, SEC_DESC *sd) +{ + PyObject *obj; + + *dict = PyDict_New(); + + PyDict_SetItemString(*dict, "revision", PyInt_FromLong(sd->revision)); + PyDict_SetItemString(*dict, "type", PyInt_FromLong(sd->type)); + + if (py_from_SID(&obj, sd->owner_sid)) + PyDict_SetItemString(*dict, "owner_sid", obj); + + if (py_from_SID(&obj, sd->grp_sid)) + PyDict_SetItemString(*dict, "group_sid", obj); + + if (py_from_ACL(&obj, sd->dacl)) + PyDict_SetItemString(*dict, "dacl", obj); + + if (py_from_ACL(&obj, sd->sacl)) + PyDict_SetItemString(*dict, "sacl", obj); + + return True; +} + +BOOL py_to_SECDESC(SEC_DESC *sd, PyObject *dict) +{ + return False; +} diff --git a/source3/python/py_spoolss_printers_conv.c b/source3/python/py_spoolss_printers_conv.c index c583792c0a..84b36ddbb2 100644 --- a/source3/python/py_spoolss_printers_conv.c +++ b/source3/python/py_spoolss_printers_conv.c @@ -144,121 +144,6 @@ struct pyconv py_DEVICEMODE[] = { { NULL } }; -/* Convert a SID to a Python dict */ - -BOOL py_from_SID(PyObject **obj, DOM_SID *sid) -{ - fstring sidstr; - - if (!sid) { - Py_INCREF(Py_None); - *obj = Py_None; - return True; - } - - if (!sid_to_string(sidstr, sid)) - return False; - - *obj = PyString_FromString(sidstr); - - return True; -} - -BOOL py_to_SID(DOM_SID *sid, PyObject *dict) -{ - return False; -} - -BOOL py_from_ACE(PyObject **dict, SEC_ACE *ace) -{ - PyObject *obj; - - if (!ace) { - Py_INCREF(Py_None); - *dict = Py_None; - return True; - } - - *dict = PyDict_New(); - - PyDict_SetItemString(*dict, "type", PyInt_FromLong(ace->type)); - PyDict_SetItemString(*dict, "flags", PyInt_FromLong(ace->flags)); - PyDict_SetItemString(*dict, "mask", PyInt_FromLong(ace->info.mask)); - - if (py_from_SID(&obj, &ace->trustee)) - PyDict_SetItemString(*dict, "trustee", obj); - - return True; -} - -BOOL py_to_ACE(SEC_ACE *ace, PyObject *dict) -{ - return False; -} - -BOOL py_from_ACL(PyObject **dict, SEC_ACL *acl) -{ - PyObject *ace_list; - int i; - - if (!acl) { - Py_INCREF(Py_None); - *dict = Py_None; - return True; - } - - *dict = PyDict_New(); - - PyDict_SetItemString(*dict, "revision", PyInt_FromLong(acl->revision)); - - ace_list = PyList_New(acl->num_aces); - - for (i = 0; i < acl->num_aces; i++) { - PyObject *obj; - - if (py_from_ACE(&obj, &acl->ace[i])) - PyList_SetItem(ace_list, i, obj); - } - - PyDict_SetItemString(*dict, "ace_list", ace_list); - - return True; -} - -BOOL py_to_ACL(SEC_ACL *acl, PyObject *dict) -{ - return False; -} - -BOOL py_from_SECDESC(PyObject **dict, SEC_DESC *sd) -{ - PyObject *obj; - - *dict = PyDict_New(); - - PyDict_SetItemString(*dict, "revision", PyInt_FromLong(sd->revision)); - PyDict_SetItemString(*dict, "type", PyInt_FromLong(sd->type)); - - if (py_from_SID(&obj, sd->owner_sid)) - PyDict_SetItemString(*dict, "owner_sid", obj); - - if (py_from_SID(&obj, sd->grp_sid)) - PyDict_SetItemString(*dict, "group_sid", obj); - - if (py_from_ACL(&obj, sd->dacl)) - PyDict_SetItemString(*dict, "dacl", obj); - - if (py_from_ACL(&obj, sd->sacl)) - PyDict_SetItemString(*dict, "sacl", obj); - - return True; -} - -BOOL py_to_SECDESC(SEC_DESC *sd, PyObject *dict) -{ - return False; -} - /* * Convert between DEVICEMODE and Python */ diff --git a/source3/python/setup.py.in b/source3/python/setup.py.in index 37bcd84772..59182f5def 100755 --- a/source3/python/setup.py.in +++ b/source3/python/setup.py.in @@ -87,6 +87,7 @@ setup( 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", @@ -104,7 +105,8 @@ setup( Extension(name = "lsa", sources = [samba_srcdir + "python/py_lsa.c", - samba_srcdir + "python/py_common.c"], + samba_srcdir + "python/py_common.c", + samba_srcdir + "python/py_ntsec.c"], libraries = lib_list, library_dirs = ["/usr/kerberos/lib"], extra_objects = obj_list), -- cgit From 06f15779303dc540ee7801fe843023970454166b Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Sun, 14 Apr 2002 09:04:45 +0000 Subject: New file to hold common prototypes. (This used to be commit d5862891979678c4defb3e33791edca1f1f8c3e4) --- source3/python/py_common_proto.h | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 source3/python/py_common_proto.h (limited to 'source3/python') diff --git a/source3/python/py_common_proto.h b/source3/python/py_common_proto.h new file mode 100644 index 0000000000..0c227ffef8 --- /dev/null +++ b/source3/python/py_common_proto.h @@ -0,0 +1,30 @@ +#ifndef _PY_COMMON_PROTO_H +#define _PY_COMMON_PROTO_H + +/* This file is automatically generated with "make proto". DO NOT EDIT */ + + +/* The following definitions come from python/py_common.c */ + +PyObject *py_werror_tuple(WERROR werror); +PyObject *py_ntstatus_tuple(NTSTATUS ntstatus); +void py_samba_init(void); +PyObject *get_debuglevel(PyObject *self, PyObject *args); +PyObject *set_debuglevel(PyObject *self, PyObject *args); +PyObject *py_setup_logging(PyObject *self, PyObject *args, PyObject *kw); +struct cli_state *open_pipe_creds(char *system_name, PyObject *creds, + cli_pipe_fn *connect_fn, + struct cli_state *cli); + +/* The following definitions come from python/py_ntsec.c */ + +BOOL py_from_SID(PyObject **obj, DOM_SID *sid); +BOOL py_to_SID(DOM_SID *sid, PyObject *dict); +BOOL py_from_ACE(PyObject **dict, SEC_ACE *ace); +BOOL py_to_ACE(SEC_ACE *ace, PyObject *dict); +BOOL py_from_ACL(PyObject **dict, SEC_ACL *acl); +BOOL py_to_ACL(SEC_ACL *acl, PyObject *dict); +BOOL py_from_SECDESC(PyObject **dict, SEC_DESC *sd); +BOOL py_to_SECDESC(SEC_DESC *sd, PyObject *dict); + +#endif /* _PY_COMMON_PROTO_H */ -- cgit From 8d680f879605b8e40fe2b4a16db5d860226e17a5 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Sun, 14 Apr 2002 12:26:09 +0000 Subject: Added enumerate trusted domains. (This used to be commit 3a11ce31ca3eed23f3bf82c46b2ebd2423be737d) --- source3/python/py_lsa.c | 45 ++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 44 insertions(+), 1 deletion(-) (limited to 'source3/python') diff --git a/source3/python/py_lsa.c b/source3/python/py_lsa.c index 1c84af5ea0..fecbf535aa 100644 --- a/source3/python/py_lsa.c +++ b/source3/python/py_lsa.c @@ -210,7 +210,7 @@ static PyObject *lsa_lookup_sids(PyObject *self, PyObject *args, result = PyList_New(num_sids); for (i = 0; i < num_sids; i++) { - PyObject *name_obj, *obj; + PyObject *obj; obj = Py_BuildValue("{sssssi}", "username", names[i], "domain", domains[i], "name_type", @@ -222,18 +222,61 @@ static PyObject *lsa_lookup_sids(PyObject *self, PyObject *args, return result; } +static PyObject *lsa_enum_trust_dom(PyObject *self, PyObject *args) +{ + lsa_policy_hnd_object *hnd = (lsa_policy_hnd_object *)self; + NTSTATUS ntstatus; + uint32 enum_ctx = 0, num_domains, i; + char **domain_names; + DOM_SID *domain_sids; + PyObject *result; + + if (!PyArg_ParseTuple(args, "")) + return NULL; + + ntstatus = cli_lsa_enum_trust_dom(hnd->cli, hnd->mem_ctx, + &hnd->pol, &enum_ctx, + &num_domains, &domain_names, + &domain_sids); + + if (!NT_STATUS_IS_OK(ntstatus)) { + PyErr_SetObject(lsa_ntstatus, py_ntstatus_tuple(ntstatus)); + return NULL; + } + + result = PyList_New(num_domains); + + for (i = 0; i < num_domains; i++) { + fstring sid_str; + + sid_to_string(sid_str, &domain_sids[i]); + PyList_SetItem( + result, i, + Py_BuildValue("(ss)", domain_names[i], sid_str)); + } + + return result; +} + /* * Method dispatch tables */ static PyMethodDef lsa_hnd_methods[] = { + /* SIDs<->names */ + { "lookup_sids", lsa_lookup_sids, METH_VARARGS | METH_KEYWORDS, "Convert sids to names." }, { "lookup_names", lsa_lookup_names, METH_VARARGS | METH_KEYWORDS, "Convert names to sids." }, + /* Trusted domains */ + + { "enum_trusted_domains", lsa_enum_trust_dom, METH_VARARGS, + "Enumerate trusted domains." }, + { NULL } }; -- cgit From 3540c42bf4ac403b4a82e970b0e3566ffdc48407 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Sun, 14 Apr 2002 23:33:31 +0000 Subject: Shutdown cli_state in the dealloc function. This happens automatically when a handle object falls out of scope. (This used to be commit 39546dd241b36d5e7b8e239525a13b91e4e9db80) --- source3/python/py_spoolss.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'source3/python') diff --git a/source3/python/py_spoolss.c b/source3/python/py_spoolss.c index 450abbd6dc..b92e3c1758 100644 --- a/source3/python/py_spoolss.c +++ b/source3/python/py_spoolss.c @@ -192,6 +192,15 @@ Set the form given by the dictionary argument. 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); } @@ -337,8 +346,7 @@ void initspoolss(void) module = Py_InitModule("spoolss", spoolss_methods); dict = PyModule_GetDict(module); - /* Make spools_error global an exception we can raise when an error - occurs. */ + /* Exceptions we can raise */ spoolss_error = PyErr_NewException("spoolss.error", NULL, NULL); PyDict_SetItemString(dict, "error", spoolss_error); -- cgit From f6da697708576f4ff3be0b3da5b7271754cbc1ef Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Sun, 14 Apr 2002 23:36:01 +0000 Subject: Call PyErr_SetString instead of fprintf to stderr. Don't clean up talloc and cli_state on close printer. They will be destroyed in the handle dealloc function. (This used to be commit 4114fe5996f84dfd14855ffdf666e065446607b4) --- source3/python/py_spoolss_printers.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'source3/python') diff --git a/source3/python/py_spoolss_printers.c b/source3/python/py_spoolss_printers.c index b0033405ad..decc52e080 100644 --- a/source3/python/py_spoolss_printers.c +++ b/source3/python/py_spoolss_printers.c @@ -52,12 +52,15 @@ PyObject *spoolss_openprinter(PyObject *self, PyObject *args, PyObject *kw) if (!(cli = open_pipe_creds(computer_name, creds, cli_spoolss_initialise, NULL))) { - fprintf(stderr, "could not initialise cli state\n"); + + /* Error state set in open_pipe_creds() */ + goto done; } if (!(mem_ctx = talloc_init())) { - fprintf(stderr, "unable to initialise talloc context\n"); + PyErr_SetString(spoolss_error, + "unable to initialise talloc context\n"); goto done; } @@ -99,11 +102,6 @@ PyObject *spoolss_closeprinter(PyObject *self, PyObject *args) result = cli_spoolss_close_printer(hnd->cli, hnd->mem_ctx, &hnd->pol); - /* Cleanup samba stuf */ - - cli_shutdown(hnd->cli); - talloc_destroy(hnd->mem_ctx); - /* Return value */ Py_INCREF(Py_None); -- cgit From 0c01601d31c401bc17747f91e72db82cd7454266 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Sun, 14 Apr 2002 23:39:02 +0000 Subject: Explicitly return a list in py_ntstatus_tuple() and py_werror_typle(). Not sure whether these should really be tuples or lists. In open_pipe_creds() raise PyExc_RuntimeError exceptions if the pipe connect function returns an error. (This used to be commit 45cb1fed490d1fdafc5b63f2f5a33dfe5b334972) --- source3/python/py_common.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) (limited to 'source3/python') diff --git a/source3/python/py_common.c b/source3/python/py_common.c index 019bcca07c..5b80f09498 100644 --- a/source3/python/py_common.c +++ b/source3/python/py_common.c @@ -27,7 +27,7 @@ PyObject *py_werror_tuple(WERROR werror) { - return Py_BuildValue("is", W_ERROR_V(werror), + return Py_BuildValue("[is]", W_ERROR_V(werror), dos_errstr(werror)); } @@ -35,7 +35,7 @@ PyObject *py_werror_tuple(WERROR werror) PyObject *py_ntstatus_tuple(NTSTATUS ntstatus) { - return Py_BuildValue("is", NT_STATUS_V(ntstatus), + return Py_BuildValue("[is]", NT_STATUS_V(ntstatus), nt_errstr(ntstatus)); } @@ -189,7 +189,24 @@ struct cli_state *open_pipe_creds(char *system_name, PyObject *creds, /* Now try to connect */ - connect_fn(cli, system_name, &nt_creds); + if (!connect_fn(cli, system_name, &nt_creds)) { + if (cli) { + NTSTATUS error = cli_nt_error(cli); + + /* Raise an exception if something went wrong. + FIXME: This should be a more appropriate + exception than PyExc_RuntimeError */ + + if (!NT_STATUS_IS_OK(error)) + PyErr_SetObject(PyExc_RuntimeError, + py_ntstatus_tuple(error)); + else + PyErr_SetString(PyExc_RuntimeError, + "error connecting to pipe"); + } + + return NULL; + } return cli; } -- cgit From 9aabbc564f3d8b9080b9047665a7212c29e9c1f0 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Sun, 14 Apr 2002 23:42:54 +0000 Subject: Rename new_policy_hnd_object() to new_spoolss_policy_hnd_object() (This used to be commit 4bf6a9830acde47994975dffd578454ebb75e45a) --- source3/python/py_spoolss.c | 4 ++-- source3/python/py_spoolss_printers.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/python') diff --git a/source3/python/py_spoolss.c b/source3/python/py_spoolss.c index b92e3c1758..c87b6626fe 100644 --- a/source3/python/py_spoolss.c +++ b/source3/python/py_spoolss.c @@ -28,8 +28,8 @@ PyObject *spoolss_error, *spoolss_werror; * Routines to convert from python hashes to Samba structures */ -PyObject *new_policy_hnd_object(struct cli_state *cli, TALLOC_CTX *mem_ctx, - POLICY_HND *pol) +PyObject *new_spoolss_policy_hnd_object(struct cli_state *cli, + TALLOC_CTX *mem_ctx, POLICY_HND *pol) { spoolss_policy_hnd_object *o; diff --git a/source3/python/py_spoolss_printers.c b/source3/python/py_spoolss_printers.c index decc52e080..69b2733cfb 100644 --- a/source3/python/py_spoolss_printers.c +++ b/source3/python/py_spoolss_printers.c @@ -75,7 +75,7 @@ PyObject *spoolss_openprinter(PyObject *self, PyObject *args, PyObject *kw) goto done; } - result = new_policy_hnd_object(cli, mem_ctx, &hnd); + result = new_spoolss_policy_hnd_object(cli, mem_ctx, &hnd); done: SAFE_FREE(computer_name); -- cgit From b84cce809baceeb7a24b3a98e9bef47279aad3ca Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 15 Apr 2002 07:29:47 +0000 Subject: Skeleton for SAMR module. (This used to be commit 70bd1a0f94412236bf6603f16947336cb75c6415) --- source3/python/py_samr.c | 206 +++++++++++++++++++++++++++++++++++++++++++++ source3/python/py_samr.h | 83 ++++++++++++++++++ source3/python/setup.py.in | 9 ++ 3 files changed, 298 insertions(+) create mode 100644 source3/python/py_samr.c create mode 100644 source3/python/py_samr.h (limited to 'source3/python') diff --git a/source3/python/py_samr.c b/source3/python/py_samr.c new file mode 100644 index 0000000000..2271cb4464 --- /dev/null +++ b/source3/python/py_samr.c @@ -0,0 +1,206 @@ +/* + 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_samr.h" + +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->pol, pol, sizeof(POLICY_HND)); + + return (PyObject*)o; +} + +/* + * 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 */ + +static void py_samr_connect_hnd_dealloc(PyObject* self) +{ + PyObject_Del(self); +} + +#if 0 + +static PyObject *py_samr_connect_hnd_getattr(PyObject *self, char *attrname) +{ + return Py_FindMethod(samr_connect_methods, self, attrname); +} + +#endif + +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 */ +}; + +PyTypeObject samr_domain_hnd_type = { + PyObject_HEAD_INIT(NULL) + 0, + "SAMR Domain 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 */ +}; + +PyTypeObject samr_user_hnd_type = { + PyObject_HEAD_INIT(NULL) + 0, + "SAMR User 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 */ +}; + +PyTypeObject samr_group_hnd_type = { + PyObject_HEAD_INIT(NULL) + 0, + "SAMR Group 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 */ +}; + +PyTypeObject samr_alias_hnd_type = { + PyObject_HEAD_INIT(NULL) + 0, + "SAMR Alias 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 */ +}; + +static PyMethodDef samr_methods[] = { + + /* Open/close samr connect handles */ + +#if 0 + { "connect", lsa_open_policy, METH_VARARGS | METH_KEYWORDS, + "Open a connect handle" }, + + { "close", lsa_close, METH_VARARGS, "Close a policy handle" }, +#endif + + { NULL } +}; + +/* + * Module initialisation +*/ + +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_samr.h b/source3/python/py_samr.h new file mode 100644 index 0000000000..52352cc64d --- /dev/null +++ b/source3/python/py_samr.h @@ -0,0 +1,83 @@ +/* + 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_SAMR_H +#define _PY_SAMR_H + +#include "includes.h" +#include "Python.h" + +#include "python/py_common.h" + +/* SAMR connect policy handle object */ + +typedef struct { + PyObject_HEAD + struct cli_state *cli; + TALLOC_CTX *mem_ctx; + POLICY_HND pol; +} samr_connect_hnd_object; + +/* SAMR domain policy handle object */ + +typedef struct { + PyObject_HEAD + struct cli_state *cli; + TALLOC_CTX *mem_ctx; + POLICY_HND pol; +} samr_domain_hnd_object; + +/* SAMR user policy handle object */ + +typedef struct { + PyObject_HEAD + struct cli_state *cli; + TALLOC_CTX *mem_ctx; + POLICY_HND pol; +} samr_user_hnd_object; + +/* SAMR group policy handle object */ + +typedef struct { + PyObject_HEAD + struct cli_state *cli; + TALLOC_CTX *mem_ctx; + POLICY_HND pol; +} samr_group_hnd_object; + +/* SAMR alias policy handle object */ + +typedef struct { + PyObject_HEAD + struct cli_state *cli; + TALLOC_CTX *mem_ctx; + POLICY_HND pol; +} samr_alias_hnd_object; + +extern PyTypeObject samr_connect_hnd_type, samr_domain_hnd_type, + samr_user_hnd_type, samr_group_hnd_type, samr_alias_hnd_type; + +/* Exceptions raised by this module */ + +extern PyObject *samr_error; + +// #include "python/py_samr_proto.h" + +#endif /* _PY_SAMR_H */ diff --git a/source3/python/setup.py.in b/source3/python/setup.py.in index 59182f5def..6bc568fa1d 100755 --- a/source3/python/setup.py.in +++ b/source3/python/setup.py.in @@ -111,6 +111,15 @@ setup( 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", -- cgit From 37e4471dea4e3140270d90f3f685ad4fb15fb036 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 15 Apr 2002 23:33:09 +0000 Subject: Stubs for connect, domain, user, group and alias policy objects. Wrote samr connect fn. (This used to be commit f2155aa3f4608b14777092002c39358b816dbea5) --- source3/python/py_samr.c | 241 +++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 202 insertions(+), 39 deletions(-) (limited to 'source3/python') diff --git a/source3/python/py_samr.c b/source3/python/py_samr.c index 2271cb4464..9a19f9abd5 100644 --- a/source3/python/py_samr.c +++ b/source3/python/py_samr.c @@ -23,20 +23,6 @@ #include "python/py_samr.h" -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->pol, pol, sizeof(POLICY_HND)); - - return (PyObject*)o; -} - /* * Exceptions raised by this module */ @@ -48,20 +34,22 @@ 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); } -#if 0 +static PyMethodDef samr_connect_methods[] = { + { NULL } +}; static PyObject *py_samr_connect_hnd_getattr(PyObject *self, char *attrname) { return Py_FindMethod(samr_connect_methods, self, attrname); } -#endif - PyTypeObject samr_connect_hnd_type = { PyObject_HEAD_INIT(NULL) 0, @@ -70,7 +58,7 @@ PyTypeObject samr_connect_hnd_type = { 0, py_samr_connect_hnd_dealloc, /*tp_dealloc*/ 0, /*tp_print*/ -// py_samr_connect_hnd_getattr, /*tp_getattr*/ + py_samr_connect_hnd_getattr, /*tp_getattr*/ 0, /*tp_setattr*/ 0, /*tp_compare*/ 0, /*tp_repr*/ @@ -80,15 +68,45 @@ PyTypeObject samr_connect_hnd_type = { 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->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_connect_hnd_object), + sizeof(samr_domain_hnd_object), 0, - py_samr_connect_hnd_dealloc, /*tp_dealloc*/ + py_samr_domain_hnd_dealloc, /*tp_dealloc*/ 0, /*tp_print*/ -// py_samr_connect_hnd_getattr, /*tp_getattr*/ + py_samr_domain_hnd_getattr, /*tp_getattr*/ 0, /*tp_setattr*/ 0, /*tp_compare*/ 0, /*tp_repr*/ @@ -98,15 +116,45 @@ PyTypeObject samr_domain_hnd_type = { 0, /*tp_hash */ }; +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->pol, pol, sizeof(POLICY_HND)); + + return (PyObject*)o; +} + +/* 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_connect_hnd_object), + sizeof(samr_user_hnd_object), 0, - py_samr_connect_hnd_dealloc, /*tp_dealloc*/ + py_samr_user_hnd_dealloc, /*tp_dealloc*/ 0, /*tp_print*/ -// py_samr_connect_hnd_getattr, /*tp_getattr*/ + py_samr_user_hnd_getattr, /*tp_getattr*/ 0, /*tp_setattr*/ 0, /*tp_compare*/ 0, /*tp_repr*/ @@ -116,15 +164,45 @@ PyTypeObject samr_user_hnd_type = { 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->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_connect_hnd_object), + sizeof(samr_group_hnd_object), 0, - py_samr_connect_hnd_dealloc, /*tp_dealloc*/ + py_samr_group_hnd_dealloc, /*tp_dealloc*/ 0, /*tp_print*/ -// py_samr_connect_hnd_getattr, /*tp_getattr*/ + py_samr_group_hnd_getattr, /*tp_getattr*/ 0, /*tp_setattr*/ 0, /*tp_compare*/ 0, /*tp_repr*/ @@ -134,15 +212,45 @@ PyTypeObject samr_group_hnd_type = { 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->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_connect_hnd_object), + sizeof(samr_alias_hnd_object), 0, - py_samr_connect_hnd_dealloc, /*tp_dealloc*/ + py_samr_alias_hnd_dealloc, /*tp_dealloc*/ 0, /*tp_print*/ -// py_samr_connect_hnd_getattr, /*tp_getattr*/ + py_samr_alias_hnd_getattr, /*tp_getattr*/ 0, /*tp_setattr*/ 0, /*tp_compare*/ 0, /*tp_repr*/ @@ -152,24 +260,79 @@ PyTypeObject samr_alias_hnd_type = { 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->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_name; + struct cli_state *cli; + POLICY_HND hnd; + TALLOC_CTX *mem_ctx; + PyObject *result = NULL, *creds = NULL; + NTSTATUS ntstatus; + + if (!PyArg_ParseTupleAndKeywords( + args, kw, "s|O!i", kwlist, &server_name, &PyDict_Type, + &creds, &desired_access)) + return NULL; + + if (!(cli = open_pipe_creds(server_name, creds, cli_samr_initialise, + NULL))) { + + /* Error state set in open_pipe_creds() */ + + goto done; + } + + if (!(mem_ctx = talloc_init())) { + PyErr_SetString(samr_ntstatus, + "unable to initialise 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: + return result; +} + +/* + * Module initialisation + */ + static PyMethodDef samr_methods[] = { /* Open/close samr connect handles */ -#if 0 - { "connect", lsa_open_policy, METH_VARARGS | METH_KEYWORDS, + { "connect", samr_connect, METH_VARARGS | METH_KEYWORDS, "Open a connect handle" }, - { "close", lsa_close, METH_VARARGS, "Close a policy handle" }, -#endif - { NULL } }; -/* - * Module initialisation -*/ - void initsamr(void) { PyObject *module, *dict; -- cgit From eaf7e2b374d6a77e573195da1d7617bea97b1a94 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Thu, 18 Apr 2002 03:24:02 +0000 Subject: make proto (This used to be commit a721843197d39c0edc6c464214123be3300d0b91) --- source3/python/py_lsa_proto.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/python') diff --git a/source3/python/py_lsa_proto.h b/source3/python/py_lsa_proto.h index 066a0aad53..1c6f6ab1d1 100644 --- a/source3/python/py_lsa_proto.h +++ b/source3/python/py_lsa_proto.h @@ -6,8 +6,8 @@ /* The following definitions come from python/py_lsa.c */ -PyObject *new_policy_hnd_object(struct cli_state *cli, TALLOC_CTX *mem_ctx, - POLICY_HND *pol); +PyObject *new_lsa_policy_hnd_object(struct cli_state *cli, TALLOC_CTX *mem_ctx, + POLICY_HND *pol); void initlsa(void); #endif /* _PY_LSA_PROTO_H */ -- cgit From b0fbd72b41dda039d4fd1036998721ee7387cd45 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Thu, 18 Apr 2002 03:35:05 +0000 Subject: Started working on setprinter code. (This used to be commit 38d2b1794a0942ac4c2787f06bc5e546508c2515) --- source3/python/py_common_proto.h | 6 +- source3/python/py_ntsec.c | 151 ++++++++++++++++++++++++++++-- source3/python/py_spoolss_printers.c | 42 +++------ source3/python/py_spoolss_printers_conv.c | 27 +++++- source3/python/py_spoolss_proto.h | 15 +-- source3/python/samba-head.patch | 15 ++- 6 files changed, 197 insertions(+), 59 deletions(-) (limited to 'source3/python') diff --git a/source3/python/py_common_proto.h b/source3/python/py_common_proto.h index 0c227ffef8..bca59689a4 100644 --- a/source3/python/py_common_proto.h +++ b/source3/python/py_common_proto.h @@ -19,12 +19,12 @@ struct cli_state *open_pipe_creds(char *system_name, PyObject *creds, /* The following definitions come from python/py_ntsec.c */ BOOL py_from_SID(PyObject **obj, DOM_SID *sid); -BOOL py_to_SID(DOM_SID *sid, PyObject *dict); +BOOL py_to_SID(DOM_SID *sid, PyObject *obj); BOOL py_from_ACE(PyObject **dict, SEC_ACE *ace); BOOL py_to_ACE(SEC_ACE *ace, PyObject *dict); BOOL py_from_ACL(PyObject **dict, SEC_ACL *acl); -BOOL py_to_ACL(SEC_ACL *acl, PyObject *dict); +BOOL py_to_ACL(SEC_ACL *acl, PyObject *dict, TALLOC_CTX *mem_ctx); BOOL py_from_SECDESC(PyObject **dict, SEC_DESC *sd); -BOOL py_to_SECDESC(SEC_DESC *sd, PyObject *dict); +BOOL py_to_SECDESC(SEC_DESC **sd, PyObject *dict, TALLOC_CTX *mem_ctx); #endif /* _PY_COMMON_PROTO_H */ diff --git a/source3/python/py_ntsec.c b/source3/python/py_ntsec.c index d97bbb6f8c..d8ed50379f 100644 --- a/source3/python/py_ntsec.c +++ b/source3/python/py_ntsec.c @@ -43,9 +43,19 @@ BOOL py_from_SID(PyObject **obj, DOM_SID *sid) return True; } -BOOL py_to_SID(DOM_SID *sid, PyObject *dict) +BOOL py_to_SID(DOM_SID *sid, PyObject *obj) { - return False; + BOOL result; + + if (!PyString_Check(obj)) + return False; + + result = string_to_sid(sid, PyString_AsString(obj)); + + if (result) + DEBUG(0, ("py: got sid %s\n", PyString_AsString(obj))); + + return result; } BOOL py_from_ACE(PyObject **dict, SEC_ACE *ace) @@ -72,7 +82,50 @@ BOOL py_from_ACE(PyObject **dict, SEC_ACE *ace) BOOL py_to_ACE(SEC_ACE *ace, PyObject *dict) { - return False; + PyObject *obj; + uint8 ace_type, ace_flags; + DOM_SID trustee; + SEC_ACCESS sec_access; + + if (!PyDict_Check(dict)) + return False; + + if (!(obj = PyDict_GetItemString(dict, "type")) || + !PyInt_Check(obj)) + return False; + + ace_type = PyInt_AsLong(obj); + + DEBUG(0, ("py: got ace_type %d\n", ace_type)); + + if (!(obj = PyDict_GetItemString(dict, "flags")) || + !PyInt_Check(obj)) + return False; + + ace_flags = PyInt_AsLong(obj); + + DEBUG(0, ("py: got ace_flags %d\n", ace_flags)); + + if (!(obj = PyDict_GetItemString(dict, "trustee")) || + !PyString_Check(obj)) + return False; + + if (!py_to_SID(&trustee, obj)) + return False; + + DEBUG(0, ("py: got trustee\n")); + + if (!(obj = PyDict_GetItemString(dict, "mask")) || + !PyInt_Check(obj)) + return False; + + sec_access.mask = PyInt_AsLong(obj); + + DEBUG(0, ("py: got mask 0x%08x\n", sec_access.mask)); + + init_sec_ace(ace, &trustee, ace_type, sec_access, ace_flags); + + return True; } BOOL py_from_ACL(PyObject **dict, SEC_ACL *acl) @@ -104,9 +157,39 @@ BOOL py_from_ACL(PyObject **dict, SEC_ACL *acl) return True; } -BOOL py_to_ACL(SEC_ACL *acl, PyObject *dict) +BOOL py_to_ACL(SEC_ACL *acl, PyObject *dict, TALLOC_CTX *mem_ctx) { - return False; + PyObject *obj; + uint32 i; + + if (!(obj = PyDict_GetItemString(dict, "revision")) || + !PyInt_Check(obj)) + return False; + + acl->revision = PyInt_AsLong(obj); + + DEBUG(0, ("py: got revision %d\n", acl->revision)); + + if (!(obj = PyDict_GetItemString(dict, "ace_list")) || + !PyList_Check(obj)) + return False; + + acl->num_aces = PyList_Size(obj); + + DEBUG(0, ("py: got num_aces %d\n", acl->num_aces)); + + acl->ace = talloc(mem_ctx, acl->num_aces * sizeof(SEC_ACE)); + + for (i = 0; i < acl->num_aces; i++) { + PyObject *py_ace = PyList_GetItem(obj, i); + + if (!py_to_ACE(acl->ace, py_ace)) + return False; + + DEBUG(0, ("py: got ace %d\n", i)); + } + + return True; } BOOL py_from_SECDESC(PyObject **dict, SEC_DESC *sd) @@ -116,7 +199,6 @@ BOOL py_from_SECDESC(PyObject **dict, SEC_DESC *sd) *dict = PyDict_New(); PyDict_SetItemString(*dict, "revision", PyInt_FromLong(sd->revision)); - PyDict_SetItemString(*dict, "type", PyInt_FromLong(sd->type)); if (py_from_SID(&obj, sd->owner_sid)) PyDict_SetItemString(*dict, "owner_sid", obj); @@ -133,7 +215,60 @@ BOOL py_from_SECDESC(PyObject **dict, SEC_DESC *sd) return True; } -BOOL py_to_SECDESC(SEC_DESC *sd, PyObject *dict) +BOOL py_to_SECDESC(SEC_DESC **sd, PyObject *dict, TALLOC_CTX *mem_ctx) { - return False; + PyObject *obj; + uint16 revision; + DOM_SID owner_sid, group_sid; + SEC_ACL sacl, dacl; + size_t sd_size; + BOOL got_dacl = False, got_sacl = False; + + ZERO_STRUCT(dacl); ZERO_STRUCT(sacl); + ZERO_STRUCT(owner_sid); ZERO_STRUCT(group_sid); + + if (!(obj = PyDict_GetItemString(dict, "revision"))) + return False; + + revision = PyInt_AsLong(obj); + + if (!(obj = PyDict_GetItemString(dict, "owner_sid"))) + return False; + + if (!py_to_SID(&owner_sid, obj)) + return False; + + if (!(obj = PyDict_GetItemString(dict, "group_sid"))) + return False; + + if (!py_to_SID(&group_sid, obj)) + return False; + + if ((obj = PyDict_GetItemString(dict, "dacl"))) { + + if (!py_to_ACL(&dacl, obj, mem_ctx)) + return False; + + got_dacl = True; + } + + DEBUG(0, ("py: got dacl\n")); + + if ((obj = PyDict_GetItemString(dict, "sacl"))) { + if (obj != Py_None) { + + if (!py_to_ACL(&sacl, obj, mem_ctx)) + return False; + + got_sacl = True; + } + } + + DEBUG(0, ("py: got sacl\n")); + + *sd = make_sec_desc(mem_ctx, revision, &owner_sid, &group_sid, + got_sacl ? &sacl : NULL, + got_dacl ? &dacl : NULL, &sd_size); + + return True; } diff --git a/source3/python/py_spoolss_printers.c b/source3/python/py_spoolss_printers.c index 69b2733cfb..48321500e7 100644 --- a/source3/python/py_spoolss_printers.c +++ b/source3/python/py_spoolss_printers.c @@ -181,12 +181,8 @@ PyObject *spoolss_setprinter(PyObject *self, PyObject *args, PyObject *kw) uint32 level; static char *kwlist[] = {"dict", NULL}; union { - PRINTER_INFO_0 printers_0; - PRINTER_INFO_1 printers_1; PRINTER_INFO_2 printers_2; PRINTER_INFO_3 printers_3; - PRINTER_INFO_4 printers_4; - PRINTER_INFO_5 printers_5; } pinfo; /* Parse parameters */ @@ -199,12 +195,22 @@ PyObject *spoolss_setprinter(PyObject *self, PyObject *args, PyObject *kw) if ((level_obj = PyDict_GetItemString(info, "level"))) { - if (!PyInt_Check(level_obj)) + if (!PyInt_Check(level_obj)) { + DEBUG(0, ("** level not an integer\n")); goto error; + } level = PyInt_AsLong(level_obj); + /* Only level 2, 3 supported by NT */ + + if (level != 2 && level != 3) { + DEBUG(0, ("** unsupported info level\n")); + goto error; + } + } else { + DEBUG(0, ("** no level info\n")); error: PyErr_SetString(spoolss_error, "invalid info"); return NULL; @@ -215,34 +221,14 @@ PyObject *spoolss_setprinter(PyObject *self, PyObject *args, PyObject *kw) ZERO_STRUCT(ctr); switch (level) { - case 2: { - PyObject *devmode_obj; - + case 2: ctr.printers_2 = &pinfo.printers_2; - if (!py_to_PRINTER_INFO_2(&pinfo.printers_2, info)) + if (!py_to_PRINTER_INFO_2(&pinfo.printers_2, info, + hnd->mem_ctx)) goto error; -#if 0 - devmode_obj = PyDict_GetItemString(info, "device_mode"); - - pinfo.printers_2.devmode = talloc( - hnd->mem_ctx, sizeof(DEVICEMODE)); - - PyDEVICEMODE_AsDEVICEMODE(pinfo.printers_2.devmode, - devmode_obj); - -#else - - /* FIXME: can we actually set the security descriptor using - a setprinter level 2? */ - - pinfo.printers_2.secdesc = NULL; - pinfo.printers_2.secdesc = NULL; - -#endif break; - } default: PyErr_SetString(spoolss_error, "unsupported info level"); return NULL; diff --git a/source3/python/py_spoolss_printers_conv.c b/source3/python/py_spoolss_printers_conv.c index 84b36ddbb2..4b78f087e6 100644 --- a/source3/python/py_spoolss_printers_conv.c +++ b/source3/python/py_spoolss_printers_conv.c @@ -165,9 +165,7 @@ BOOL py_to_DEVICEMODE(DEVICEMODE *devmode, PyObject *dict) to_struct(devmode, dict, py_DEVICEMODE); - obj = PyDict_GetItemString(dict, "private"); - - if (!obj) + if (!(obj = PyDict_GetItemString(dict, "private"))) return False; devmode->private = PyString_AsString(obj); @@ -225,9 +223,28 @@ BOOL py_from_PRINTER_INFO_2(PyObject **dict, PRINTER_INFO_2 *info) return True; } -BOOL py_to_PRINTER_INFO_2(PRINTER_INFO_2 *info, PyObject *dict) +BOOL py_to_PRINTER_INFO_2(PRINTER_INFO_2 *info, PyObject *dict, + TALLOC_CTX *mem_ctx) { - return False; + PyObject *obj; + + to_struct(info, dict, py_PRINTER_INFO_2); + + 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; } /* diff --git a/source3/python/py_spoolss_proto.h b/source3/python/py_spoolss_proto.h index 3e3e5ef6ee..47602d175d 100644 --- a/source3/python/py_spoolss_proto.h +++ b/source3/python/py_spoolss_proto.h @@ -6,8 +6,8 @@ /* The following definitions come from python/py_spoolss.c */ -PyObject *new_policy_hnd_object(struct cli_state *cli, TALLOC_CTX *mem_ctx, - POLICY_HND *pol); +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 */ @@ -66,14 +66,6 @@ PyObject *spoolss_enumprinters(PyObject *self, PyObject *args, PyObject *kw); /* The following definitions come from python/py_spoolss_printers_conv.c */ -BOOL py_from_SID(PyObject **obj, DOM_SID *sid); -BOOL py_to_SID(DOM_SID *sid, PyObject *dict); -BOOL py_from_ACE(PyObject **dict, SEC_ACE *ace); -BOOL py_to_ACE(SEC_ACE *ace, PyObject *dict); -BOOL py_from_ACL(PyObject **dict, SEC_ACL *acl); -BOOL py_to_ACL(SEC_ACL *acl, PyObject *dict); -BOOL py_from_SECDESC(PyObject **dict, SEC_DESC *sd); -BOOL py_to_SECDESC(SEC_DESC *sd, PyObject *dict); 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); @@ -81,7 +73,8 @@ 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); +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); diff --git a/source3/python/samba-head.patch b/source3/python/samba-head.patch index 223e0179fb..c8089934b8 100644 --- a/source3/python/samba-head.patch +++ b/source3/python/samba-head.patch @@ -4,8 +4,8 @@ RCS file: /data/cvs/samba/source/Makefile.in,v retrieving revision 1.470 diff -u -r1.470 Makefile.in --- Makefile.in 2002/04/13 11:45:33 1.470 -+++ Makefile.in 2002/04/14 01:01:05 -@@ -787,6 +787,36 @@ ++++ Makefile.in 2002/04/18 03:34:05 +@@ -787,6 +787,43 @@ -$(INSTALLCMD) -d ${prefix}/include -$(INSTALLCMD) include/libsmbclient.h ${prefix}/include @@ -22,7 +22,9 @@ diff -u -r1.470 Makefile.in + +PY_LSA_PROTO_OBJ = python/py_lsa.o + -+python_proto: python_spoolss_proto python_lsa_proto ++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) \ @@ -34,6 +36,11 @@ diff -u -r1.470 Makefile.in + -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)" \ @@ -48,7 +55,7 @@ RCS file: /data/cvs/samba/source/configure.in,v retrieving revision 1.300 diff -u -r1.300 configure.in --- configure.in 2002/04/11 15:26:58 1.300 -+++ configure.in 2002/04/14 01:01:08 ++++ configure.in 2002/04/18 03:34:05 @@ -2716,7 +2716,7 @@ builddir=`pwd` AC_SUBST(builddir) -- cgit From 5c261ce93d369d8c3901117777c3bb421178a186 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Sat, 20 Apr 2002 07:17:36 +0000 Subject: Return exception text if getprinter level not [0..3] (This used to be commit c02a7a71d6ddae711c84094e410d1117efc031f0) --- source3/python/py_spoolss_printers.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'source3/python') diff --git a/source3/python/py_spoolss_printers.c b/source3/python/py_spoolss_printers.c index 48321500e7..623e693124 100644 --- a/source3/python/py_spoolss_printers.c +++ b/source3/python/py_spoolss_printers.c @@ -119,12 +119,19 @@ PyObject *spoolss_getprinter(PyObject *self, PyObject *args, PyObject *kw) 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( -- cgit From f530f9c25df2d880fd08fe43b51a2a36d53eb88b Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Wed, 1 May 2002 04:19:22 +0000 Subject: Implemented routines to convert from a Python dictionary to a SEC_DESC structure. Cleaned up debugging stuff. (This used to be commit f3f4f0d3978f90c589894234bbcc63728940a246) --- source3/python/py_ntsec.c | 76 +++++++++++++++++++++++------------------------ 1 file changed, 38 insertions(+), 38 deletions(-) (limited to 'source3/python') diff --git a/source3/python/py_ntsec.c b/source3/python/py_ntsec.c index d8ed50379f..f9881f5a55 100644 --- a/source3/python/py_ntsec.c +++ b/source3/python/py_ntsec.c @@ -50,12 +50,7 @@ BOOL py_to_SID(DOM_SID *sid, PyObject *obj) if (!PyString_Check(obj)) return False; - result = string_to_sid(sid, PyString_AsString(obj)); - - if (result) - DEBUG(0, ("py: got sid %s\n", PyString_AsString(obj))); - - return result; + return string_to_sid(sid, PyString_AsString(obj)); } BOOL py_from_ACE(PyObject **dict, SEC_ACE *ace) @@ -96,16 +91,12 @@ BOOL py_to_ACE(SEC_ACE *ace, PyObject *dict) ace_type = PyInt_AsLong(obj); - DEBUG(0, ("py: got ace_type %d\n", ace_type)); - if (!(obj = PyDict_GetItemString(dict, "flags")) || !PyInt_Check(obj)) return False; ace_flags = PyInt_AsLong(obj); - DEBUG(0, ("py: got ace_flags %d\n", ace_flags)); - if (!(obj = PyDict_GetItemString(dict, "trustee")) || !PyString_Check(obj)) return False; @@ -113,18 +104,18 @@ BOOL py_to_ACE(SEC_ACE *ace, PyObject *dict) if (!py_to_SID(&trustee, obj)) return False; - DEBUG(0, ("py: got trustee\n")); - if (!(obj = PyDict_GetItemString(dict, "mask")) || !PyInt_Check(obj)) return False; sec_access.mask = PyInt_AsLong(obj); - DEBUG(0, ("py: got mask 0x%08x\n", sec_access.mask)); - init_sec_ace(ace, &trustee, ace_type, sec_access, ace_flags); + /* Fill in size field */ + + ace->size = SEC_ACE_HEADER_SIZE + sid_size(&trustee); + return True; } @@ -168,25 +159,22 @@ BOOL py_to_ACL(SEC_ACL *acl, PyObject *dict, TALLOC_CTX *mem_ctx) acl->revision = PyInt_AsLong(obj); - DEBUG(0, ("py: got revision %d\n", acl->revision)); - if (!(obj = PyDict_GetItemString(dict, "ace_list")) || !PyList_Check(obj)) return False; acl->num_aces = PyList_Size(obj); - DEBUG(0, ("py: got num_aces %d\n", acl->num_aces)); - acl->ace = talloc(mem_ctx, acl->num_aces * sizeof(SEC_ACE)); + acl->size = SEC_ACL_HEADER_SIZE; for (i = 0; i < acl->num_aces; i++) { PyObject *py_ace = PyList_GetItem(obj, i); - if (!py_to_ACE(acl->ace, py_ace)) + if (!py_to_ACE(&acl->ace[i], py_ace)) return False; - DEBUG(0, ("py: got ace %d\n", i)); + acl->size += acl->ace[i].size; } return True; @@ -221,8 +209,8 @@ BOOL py_to_SECDESC(SEC_DESC **sd, PyObject *dict, TALLOC_CTX *mem_ctx) uint16 revision; DOM_SID owner_sid, group_sid; SEC_ACL sacl, dacl; - size_t sd_size; BOOL got_dacl = False, got_sacl = False; + BOOL got_owner_sid = False, got_group_sid = False; ZERO_STRUCT(dacl); ZERO_STRUCT(sacl); ZERO_STRUCT(owner_sid); ZERO_STRUCT(group_sid); @@ -232,29 +220,41 @@ BOOL py_to_SECDESC(SEC_DESC **sd, PyObject *dict, TALLOC_CTX *mem_ctx) revision = PyInt_AsLong(obj); - if (!(obj = PyDict_GetItemString(dict, "owner_sid"))) - return False; + if ((obj = PyDict_GetItemString(dict, "owner_sid"))) { - if (!py_to_SID(&owner_sid, obj)) - return False; + if (obj != Py_None) { - if (!(obj = PyDict_GetItemString(dict, "group_sid"))) - return False; + if (!py_to_SID(&owner_sid, obj)) + return False; - if (!py_to_SID(&group_sid, obj)) - return False; + got_owner_sid = True; + } + } - if ((obj = PyDict_GetItemString(dict, "dacl"))) { + if ((obj = PyDict_GetItemString(dict, "group_sid"))) { - if (!py_to_ACL(&dacl, obj, mem_ctx)) - return False; + if (obj != Py_None) { - got_dacl = True; + if (!py_to_SID(&group_sid, obj)) + return False; + + got_group_sid = True; + } } - DEBUG(0, ("py: got dacl\n")); + if ((obj = PyDict_GetItemString(dict, "dacl"))) { + + if (obj != Py_None) { + + if (!py_to_ACL(&dacl, obj, mem_ctx)) + return False; + + got_dacl = True; + } + } if ((obj = PyDict_GetItemString(dict, "sacl"))) { + if (obj != Py_None) { if (!py_to_ACL(&sacl, obj, mem_ctx)) @@ -264,11 +264,11 @@ BOOL py_to_SECDESC(SEC_DESC **sd, PyObject *dict, TALLOC_CTX *mem_ctx) } } - DEBUG(0, ("py: got sacl\n")); - - *sd = make_sec_desc(mem_ctx, revision, &owner_sid, &group_sid, + *sd = make_sec_desc(mem_ctx, revision, + got_owner_sid ? &owner_sid : NULL, + got_group_sid ? &group_sid : NULL, got_sacl ? &sacl : NULL, - got_dacl ? &dacl : NULL, &sd_size); + got_dacl ? &dacl : NULL); return True; } -- cgit From 77922d18a85c85a7fd0b38e04bc210ee351d1ee8 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Wed, 1 May 2002 04:22:20 +0000 Subject: Implemented py_to_PRINTER_INFO_3() helper function. (This used to be commit d125f9f7dff357bf9eeffc430b5876080f3debeb) --- source3/python/py_spoolss_printers_conv.c | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) (limited to 'source3/python') diff --git a/source3/python/py_spoolss_printers_conv.c b/source3/python/py_spoolss_printers_conv.c index 4b78f087e6..89980ef25a 100644 --- a/source3/python/py_spoolss_printers_conv.c +++ b/source3/python/py_spoolss_printers_conv.c @@ -253,7 +253,7 @@ BOOL py_to_PRINTER_INFO_2(PRINTER_INFO_2 *info, PyObject *dict, BOOL py_from_PRINTER_INFO_3(PyObject **dict, PRINTER_INFO_3 *info) { - PyObject *obj; + PyObject *obj; *dict = from_struct(info, py_PRINTER_INFO_3); @@ -263,7 +263,18 @@ BOOL py_from_PRINTER_INFO_3(PyObject **dict, PRINTER_INFO_3 *info) return True; } -BOOL py_to_PRINTER_INFO_3(PRINTER_INFO_3 *info, PyObject *dict) +BOOL py_to_PRINTER_INFO_3(PRINTER_INFO_3 *info, PyObject *dict, + TALLOC_CTX *mem_ctx) { - return False; + PyObject *obj; + + to_struct(info, dict, py_PRINTER_INFO_3); + + if (!(obj = PyDict_GetItemString(dict, "security_descriptor"))) + return False; + + if (!py_to_SECDESC(&info->secdesc, obj, mem_ctx)) + return False; + + return True; } -- cgit From 451b5feeb72771a64181ad07e08fff865872fd3e Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Wed, 1 May 2002 04:24:01 +0000 Subject: make proto (This used to be commit 99dee7b1018f9abc5374bcf877fea1a5cbde6cae) --- source3/python/py_spoolss_proto.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source3/python') diff --git a/source3/python/py_spoolss_proto.h b/source3/python/py_spoolss_proto.h index 47602d175d..00118aae7d 100644 --- a/source3/python/py_spoolss_proto.h +++ b/source3/python/py_spoolss_proto.h @@ -76,6 +76,7 @@ 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); +BOOL py_to_PRINTER_INFO_3(PRINTER_INFO_3 *info, PyObject *dict, + TALLOC_CTX *mem_ctx); #endif /* _PY_SPOOLSS_PROTO_H */ -- cgit From e8e866867e08c3784e379682325501972795bf4b Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Wed, 1 May 2002 04:25:46 +0000 Subject: Got setprinter level 3 working! Replaced some DEBUG's with PyErr_SetString() calls. (This used to be commit 0f464fc79118161a97f45f428e4da1069a0be23d) --- source3/python/py_spoolss_printers.c | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) (limited to 'source3/python') diff --git a/source3/python/py_spoolss_printers.c b/source3/python/py_spoolss_printers.c index 623e693124..b006e54d81 100644 --- a/source3/python/py_spoolss_printers.c +++ b/source3/python/py_spoolss_printers.c @@ -203,8 +203,9 @@ PyObject *spoolss_setprinter(PyObject *self, PyObject *args, PyObject *kw) if ((level_obj = PyDict_GetItemString(info, "level"))) { if (!PyInt_Check(level_obj)) { - DEBUG(0, ("** level not an integer\n")); - goto error; + PyErr_SetString(spoolss_error, + "level not an integer"); + return NULL; } level = PyInt_AsLong(level_obj); @@ -212,14 +213,13 @@ PyObject *spoolss_setprinter(PyObject *self, PyObject *args, PyObject *kw) /* Only level 2, 3 supported by NT */ if (level != 2 && level != 3) { - DEBUG(0, ("** unsupported info level\n")); - goto error; + PyErr_SetString(spoolss_error, + "unsupported info level"); + return NULL; } } else { - DEBUG(0, ("** no level info\n")); - error: - PyErr_SetString(spoolss_error, "invalid info"); + PyErr_SetString(spoolss_error, "no info level present"); return NULL; } @@ -232,8 +232,22 @@ PyObject *spoolss_setprinter(PyObject *self, PyObject *args, PyObject *kw) ctr.printers_2 = &pinfo.printers_2; if (!py_to_PRINTER_INFO_2(&pinfo.printers_2, info, - hnd->mem_ctx)) - goto error; + 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: -- cgit From aa69c1ee80fbf7f45d61861089daeb5828e91229 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Thu, 2 May 2002 05:23:38 +0000 Subject: Some examples using the spoolss python module. (This used to be commit 68b952561429e1d08a974e633bb9c2870c819c69) --- source3/python/examples/spoolss/changeid.py | 29 +++++++++ source3/python/examples/spoolss/enumprinters.py | 25 +++++++ source3/python/examples/spoolss/psec.py | 87 +++++++++++++++++++++++++ 3 files changed, 141 insertions(+) create mode 100755 source3/python/examples/spoolss/changeid.py create mode 100755 source3/python/examples/spoolss/enumprinters.py create mode 100755 source3/python/examples/spoolss/psec.py (limited to 'source3/python') diff --git a/source3/python/examples/spoolss/changeid.py b/source3/python/examples/spoolss/changeid.py new file mode 100755 index 0000000000..b2345094ed --- /dev/null +++ b/source3/python/examples/spoolss/changeid.py @@ -0,0 +1,29 @@ +#!/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 " + 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 new file mode 100755 index 0000000000..bf08b95bb9 --- /dev/null +++ b/source3/python/examples/spoolss/enumprinters.py @@ -0,0 +1,25 @@ +#!/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 " + 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 new file mode 100755 index 0000000000..f3fdb7bccd --- /dev/null +++ b/source3/python/examples/spoolss/psec.py @@ -0,0 +1,87 @@ +#!/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) -- cgit From fe816061c1543ae8435f6e80801d5c3d5366461e Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Fri, 3 May 2002 06:21:59 +0000 Subject: Re-order args for enumprinterdrivers function. (This used to be commit 5f9f32021300d47dcc068192428ee48b8aa246ea) --- source3/python/py_spoolss.c | 10 +++++----- source3/python/py_spoolss_drivers.c | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) (limited to 'source3/python') diff --git a/source3/python/py_spoolss.c b/source3/python/py_spoolss.c index c87b6626fe..e1d6d47345 100644 --- a/source3/python/py_spoolss.c +++ b/source3/python/py_spoolss.c @@ -53,10 +53,10 @@ static PyMethodDef spoolss_methods[] = { { "openprinter", spoolss_openprinter, METH_VARARGS | METH_KEYWORDS, "openprinter(printername, [creds, access]) -> -Open a printer given by printername in UNC format. Optionally a -dictionary of (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. +Open a printer given by printername 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: @@ -104,7 +104,7 @@ Example: { "enumprinterdrivers", spoolss_enumprinterdrivers, METH_VARARGS | METH_KEYWORDS, -"enumprinterdrivers(server, [level, arch, creds]) -> list +"enumprinterdrivers(server, [creds, level, arch]) -> list Return a list of printer drivers. "}, diff --git a/source3/python/py_spoolss_drivers.c b/source3/python/py_spoolss_drivers.c index 5c0d6174cf..de2fd5626b 100644 --- a/source3/python/py_spoolss_drivers.c +++ b/source3/python/py_spoolss_drivers.c @@ -31,15 +31,15 @@ PyObject *spoolss_enumprinterdrivers(PyObject *self, PyObject *args, int level = 1, i; uint32 needed, num_drivers; char *arch = "Windows NT x86", *server_name; - static char *kwlist[] = {"server", "level", "arch", "creds", NULL}; + static char *kwlist[] = {"server", "creds", "level", "arch", NULL}; struct cli_state *cli = NULL; TALLOC_CTX *mem_ctx = NULL; /* Parse parameters */ - if (!PyArg_ParseTupleAndKeywords(args, kw, "s|isO!", kwlist, - &server_name, &level, &arch, - &PyDict_Type, &creds)) + if (!PyArg_ParseTupleAndKeywords(args, kw, "s|O!is", kwlist, + &server_name, &PyDict_Type, &creds, + &level, &arch)) return NULL; /* Call rpc function */ -- cgit From 0a01e23e2be461fe3d4a8af7344c0a08ed091d96 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 6 May 2002 04:52:45 +0000 Subject: Removed unused arg to deleteform. (This used to be commit 5071fd8fe0ad219f813b490a78c01bb249a3cad6) --- source3/python/py_spoolss_forms.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/python') diff --git a/source3/python/py_spoolss_forms.c b/source3/python/py_spoolss_forms.c index 9f8a49bd52..fbe3240c15 100644 --- a/source3/python/py_spoolss_forms.c +++ b/source3/python/py_spoolss_forms.c @@ -162,14 +162,13 @@ PyObject *spoolss_deleteform(PyObject *self, PyObject *args, PyObject *kw) { spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self; WERROR werror; - int level = 1; static char *kwlist[] = {"form_name", "level", NULL}; char *form_name; /* Parse parameters */ if (!PyArg_ParseTupleAndKeywords( - args, kw, "s|i", kwlist, &form_name, &level)) + args, kw, "s", kwlist, &form_name)) return NULL; /* Call rpc function */ -- cgit From 202341dbce8f53ed71334cc8eb8a9ab0c1873b61 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 6 May 2002 04:53:44 +0000 Subject: Allow lookup_sids() and lookup_names() to take either a list of strings or just a single string. (This used to be commit 775549b70e1d2770619c2fe1ed39418a8788dbfe) --- source3/python/py_lsa.c | 66 +++++++++++++++++++++++++++++++++++++------------ 1 file changed, 50 insertions(+), 16 deletions(-) (limited to 'source3/python') diff --git a/source3/python/py_lsa.c b/source3/python/py_lsa.c index fecbf535aa..82ae99c53e 100644 --- a/source3/python/py_lsa.c +++ b/source3/python/py_lsa.c @@ -133,19 +133,36 @@ static PyObject *lsa_lookup_names(PyObject *self, PyObject *args) DOM_SID *sids; uint32 *name_types; - if (!PyArg_ParseTuple(args, "O!", &PyList_Type, &py_names)) + if (!PyArg_ParseTuple(args, "O", &py_names)) return NULL; - /* Convert dictionary to char ** array */ + if (!PyList_Check(py_names) && !PyString_Check(py_names)) { + PyErr_SetString(PyExc_TypeError, "must be list or string"); + return NULL; + } - num_names = PyList_Size(py_names); - names = (const char **)talloc( - hnd->mem_ctx, num_names * sizeof(char *)); + if (PyList_Check(py_names)) { - for (i = 0; i < num_names; i++) { - PyObject *obj = PyList_GetItem(py_names, i); + /* Convert list to char ** array */ + + num_names = PyList_Size(py_names); + names = (const char **)talloc( + hnd->mem_ctx, num_names * sizeof(char *)); + + for (i = 0; i < num_names; i++) { + PyObject *obj = PyList_GetItem(py_names, i); + + names[i] = talloc_strdup(hnd->mem_ctx, PyString_AsString(obj)); + } + + } else { + + /* Just a single element */ - names[i] = talloc_strdup(hnd->mem_ctx, PyString_AsString(obj)); + num_names = 1; + names = (const char **)talloc(hnd->mem_ctx, sizeof(char *)); + + names[0] = PyString_AsString(py_names); } ntstatus = cli_lsa_lookup_names(hnd->cli, hnd->mem_ctx, &hnd->pol, @@ -182,20 +199,37 @@ static PyObject *lsa_lookup_sids(PyObject *self, PyObject *args, lsa_policy_hnd_object *hnd = (lsa_policy_hnd_object *)self; DOM_SID *sids; - if (!PyArg_ParseTuple(args, "O!", &PyList_Type, &py_sids)) + if (!PyArg_ParseTuple(args, "O", &py_sids)) + return NULL; + + if (!PyList_Check(py_sids) && !PyString_Check(py_sids)) { + PyErr_SetString(PyExc_TypeError, "must be list or string"); return NULL; + } - /* Convert dictionary to char ** array */ + if (PyList_Check(py_sids)) { - num_sids = PyList_Size(py_sids); - sids = (DOM_SID *)talloc(hnd->mem_ctx, num_sids * sizeof(DOM_SID)); + /* Convert dictionary to char ** array */ + + num_sids = PyList_Size(py_sids); + sids = (DOM_SID *)talloc(hnd->mem_ctx, num_sids * sizeof(DOM_SID)); + + memset(sids, 0, num_sids * sizeof(DOM_SID)); + + for (i = 0; i < num_sids; i++) { + PyObject *obj = PyList_GetItem(py_sids, i); + + string_to_sid(&sids[i], PyString_AsString(obj)); + } - memset(sids, 0, num_sids * sizeof(DOM_SID)); + } else { - for (i = 0; i < num_sids; i++) { - PyObject *obj = PyList_GetItem(py_sids, i); + /* Just a single element */ + + num_sids = 1; + sids = (DOM_SID *)talloc(hnd->mem_ctx, sizeof(DOM_SID)); - string_to_sid(&sids[i], PyString_AsString(obj)); + string_to_sid(&sids[0], PyString_AsString(py_sids)); } ntstatus = cli_lsa_lookup_sids(hnd->cli, hnd->mem_ctx, &hnd->pol, -- cgit From 2b34442922eacb0efd9ff339b06f4a1ff73bd1cd Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Tue, 7 May 2002 07:00:14 +0000 Subject: rpcstr_pull() src_len fix. (This used to be commit 7da054d814d16deeea954e2559fdeb97dc323bbb) --- source3/python/py_conv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/python') diff --git a/source3/python/py_conv.c b/source3/python/py_conv.c index 88068898a4..2dc12f348a 100644 --- a/source3/python/py_conv.c +++ b/source3/python/py_conv.c @@ -26,7 +26,7 @@ static void fstr_pull(fstring str, UNISTR *uni) { - rpcstr_pull(str, uni->buffer, sizeof(fstring), 0, STR_TERMINATE); + rpcstr_pull(str, uni->buffer, sizeof(fstring), -1, STR_TERMINATE); } /* Convert a structure to a Python dict */ -- cgit From cd929ae6ce2d408fe3256de4a3e9e71c89986e77 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Tue, 7 May 2002 07:06:10 +0000 Subject: Added enumjobs command. (This used to be commit bc9dd9b45866d269f576a640286a578da921c3fb) --- source3/python/py_spoolss.c | 5 ++ source3/python/py_spoolss_jobs.c | 86 +++++++++++++++++++++++++++++++++++ source3/python/py_spoolss_jobs_conv.c | 84 ++++++++++++++++++++++++++++++++++ source3/python/py_spoolss_proto.h | 11 +++++ source3/python/samba-head.patch | 21 +++++---- source3/python/setup.py.in | 2 + 6 files changed, 199 insertions(+), 10 deletions(-) create mode 100644 source3/python/py_spoolss_jobs.c create mode 100644 source3/python/py_spoolss_jobs_conv.c (limited to 'source3/python') diff --git a/source3/python/py_spoolss.c b/source3/python/py_spoolss.c index e1d6d47345..b1c70f9d4e 100644 --- a/source3/python/py_spoolss.c +++ b/source3/python/py_spoolss.c @@ -186,6 +186,11 @@ Set the form given by the dictionary argument. { "deleteform", spoolss_deleteform, METH_VARARGS | METH_KEYWORDS, "Delete a form" }, + /* Job related methods */ + + { "enumjobs", spoolss_enumjobs, METH_VARARGS | METH_KEYWORDS, + "Enumerate jobs" }, + { NULL } }; diff --git a/source3/python/py_spoolss_jobs.c b/source3/python/py_spoolss_jobs.c new file mode 100644 index 0000000000..e049d82a33 --- /dev/null +++ b/source3/python/py_spoolss_jobs.c @@ -0,0 +1,86 @@ +/* + 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_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)) + 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; +} diff --git a/source3/python/py_spoolss_jobs_conv.c b/source3/python/py_spoolss_jobs_conv.c new file mode 100644 index 0000000000..7db8a5c5af --- /dev/null +++ b/source3/python/py_spoolss_jobs_conv.c @@ -0,0 +1,84 @@ +/* + 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_JOB_INFO_1[] = { + { "jobid", PY_UINT32, offsetof(JOB_INFO_1, jobid) }, + { "printer_name", PY_UNISTR, offsetof(JOB_INFO_1, printername) }, + { "server_name", PY_UNISTR, offsetof(JOB_INFO_1, machinename) }, + { "user_name", PY_UNISTR, offsetof(JOB_INFO_1, username) }, + { "document_name", PY_UNISTR, offsetof(JOB_INFO_1, document) }, + { "data_type", PY_UNISTR, offsetof(JOB_INFO_1, datatype) }, + { "text_status", PY_UNISTR, offsetof(JOB_INFO_1, text_status) }, + { "status", PY_UINT32, offsetof(JOB_INFO_1, status) }, + { "priority", PY_UINT32, offsetof(JOB_INFO_1, priority) }, + { "position", PY_UINT32, offsetof(JOB_INFO_1, position) }, + { "total_pages", PY_UINT32, offsetof(JOB_INFO_1, totalpages) }, + { "pages_printed", PY_UINT32, offsetof(JOB_INFO_1, pagesprinted) }, + { NULL } +}; + +struct pyconv py_JOB_INFO_2[] = { + { "jobid", PY_UINT32, offsetof(JOB_INFO_2, jobid) }, + { "printer_name", PY_UNISTR, offsetof(JOB_INFO_2, printername) }, + { "server_name", PY_UNISTR, offsetof(JOB_INFO_2, machinename) }, + { "user_name", PY_UNISTR, offsetof(JOB_INFO_2, username) }, + { "document_name", PY_UNISTR, offsetof(JOB_INFO_2, document) }, + { "notify_name", PY_UNISTR, offsetof(JOB_INFO_2, notifyname) }, + { "data_type", PY_UNISTR, offsetof(JOB_INFO_2, datatype) }, + { "print_processor", PY_UNISTR, offsetof(JOB_INFO_2, printprocessor) }, + { "parameters", PY_UNISTR, offsetof(JOB_INFO_2, parameters) }, + { "driver_name", PY_UNISTR, offsetof(JOB_INFO_2, drivername) }, + { "text_status", PY_UNISTR, offsetof(JOB_INFO_2, text_status) }, + { "status", PY_UINT32, offsetof(JOB_INFO_2, status) }, + { "priority", PY_UINT32, offsetof(JOB_INFO_2, priority) }, + { "position", PY_UINT32, offsetof(JOB_INFO_2, position) }, + { "start_time", PY_UINT32, offsetof(JOB_INFO_2, starttime) }, + { "until_time", PY_UINT32, offsetof(JOB_INFO_2, untiltime) }, + { "total_pages", PY_UINT32, offsetof(JOB_INFO_2, totalpages) }, + { "size", PY_UINT32, offsetof(JOB_INFO_2, size) }, + { "time_elapsed", PY_UINT32, offsetof(JOB_INFO_2, timeelapsed) }, + { "pages_printed", PY_UINT32, offsetof(JOB_INFO_2, pagesprinted) }, + { NULL } +}; + +BOOL py_from_JOB_INFO_1(PyObject **dict, JOB_INFO_1 *info) +{ + *dict = from_struct(info, py_JOB_INFO_1); + return True; +} + +BOOL py_to_JOB_INFO_1(JOB_INFO_1 *info, PyObject *dict) +{ + return False; +} + +BOOL py_from_JOB_INFO_2(PyObject **dict, JOB_INFO_2 *info) +{ + *dict = from_struct(info, py_JOB_INFO_2); + return True; +} + +BOOL py_to_JOB_INFO_2(JOB_INFO_2 *info, PyObject *dict) +{ + return False; +} diff --git a/source3/python/py_spoolss_proto.h b/source3/python/py_spoolss_proto.h index 00118aae7d..81d34a2c2d 100644 --- a/source3/python/py_spoolss_proto.h +++ b/source3/python/py_spoolss_proto.h @@ -45,6 +45,17 @@ PyObject *spoolss_enumforms(PyObject *self, PyObject *args, PyObject *kw); 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_enumjobs(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); + /* The following definitions come from python/py_spoolss_ports.c */ PyObject *spoolss_enumports(PyObject *self, PyObject *args, PyObject *kw); diff --git a/source3/python/samba-head.patch b/source3/python/samba-head.patch index c8089934b8..59d2a25ae4 100644 --- a/source3/python/samba-head.patch +++ b/source3/python/samba-head.patch @@ -1,11 +1,11 @@ Index: Makefile.in =================================================================== RCS file: /data/cvs/samba/source/Makefile.in,v -retrieving revision 1.470 -diff -u -r1.470 Makefile.in ---- Makefile.in 2002/04/13 11:45:33 1.470 -+++ Makefile.in 2002/04/18 03:34:05 -@@ -787,6 +787,43 @@ +retrieving revision 1.473 +diff -u -r1.473 Makefile.in +--- Makefile.in 2002/04/30 05:44:25 1.473 ++++ Makefile.in 2002/05/07 07:02:43 +@@ -788,6 +788,44 @@ -$(INSTALLCMD) -d ${prefix}/include -$(INSTALLCMD) include/libsmbclient.h ${prefix}/include @@ -19,6 +19,7 @@ diff -u -r1.470 Makefile.in + 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 + +PY_LSA_PROTO_OBJ = python/py_lsa.o + @@ -52,11 +53,11 @@ diff -u -r1.470 Makefile.in Index: configure.in =================================================================== RCS file: /data/cvs/samba/source/configure.in,v -retrieving revision 1.300 -diff -u -r1.300 configure.in ---- configure.in 2002/04/11 15:26:58 1.300 -+++ configure.in 2002/04/18 03:34:05 -@@ -2716,7 +2716,7 @@ +retrieving revision 1.302 +diff -u -r1.302 configure.in +--- configure.in 2002/04/24 11:42:46 1.302 ++++ configure.in 2002/05/07 07:02:44 +@@ -2720,7 +2720,7 @@ builddir=`pwd` AC_SUBST(builddir) diff --git a/source3/python/setup.py.in b/source3/python/setup.py.in index 6bc568fa1d..2e0e5def9d 100755 --- a/source3/python/setup.py.in +++ b/source3/python/setup.py.in @@ -96,6 +96,8 @@ setup( samba_srcdir + "python/py_spoolss_printers_conv.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"], -- cgit From 646183a78d82bf33c0ff051de4a628c367c42784 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Wed, 8 May 2002 04:19:52 +0000 Subject: Remove unused variable. #ifdef out code for new (uncommitted) version of make_sec_desc() (This used to be commit 07d11f5e0938c0e4f895391f6c8e2501069a0ef7) --- source3/python/py_ntsec.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'source3/python') diff --git a/source3/python/py_ntsec.c b/source3/python/py_ntsec.c index f9881f5a55..8981f0c3ac 100644 --- a/source3/python/py_ntsec.c +++ b/source3/python/py_ntsec.c @@ -45,8 +45,6 @@ BOOL py_from_SID(PyObject **obj, DOM_SID *sid) BOOL py_to_SID(DOM_SID *sid, PyObject *obj) { - BOOL result; - if (!PyString_Check(obj)) return False; @@ -264,11 +262,23 @@ BOOL py_to_SECDESC(SEC_DESC **sd, PyObject *dict, TALLOC_CTX *mem_ctx) } } +#if 0 /* For new secdesc code */ *sd = make_sec_desc(mem_ctx, revision, got_owner_sid ? &owner_sid : NULL, got_group_sid ? &group_sid : NULL, got_sacl ? &sacl : NULL, got_dacl ? &dacl : NULL); - +#else + { + size_t sd_size; + + *sd = make_sec_desc(mem_ctx, revision, + got_owner_sid ? &owner_sid : NULL, + got_group_sid ? &group_sid : NULL, + got_sacl ? &sacl : NULL, + got_dacl ? &dacl : NULL, &sd_size); + } +#endif + return True; } -- cgit From 8e917f27f2d54180829696d23073f671df5b9216 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Wed, 8 May 2002 04:22:17 +0000 Subject: Changed some error returns to return a werror tuple (status code and text message) instead of just the status code. (This used to be commit 39f58333fa84dc05cac8d13cabb1f203c5cf2c62) --- source3/python/py_spoolss_printers.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'source3/python') diff --git a/source3/python/py_spoolss_printers.c b/source3/python/py_spoolss_printers.c index b006e54d81..17c8af902a 100644 --- a/source3/python/py_spoolss_printers.c +++ b/source3/python/py_spoolss_printers.c @@ -145,8 +145,7 @@ PyObject *spoolss_getprinter(PyObject *self, PyObject *args, PyObject *kw) /* Return value */ if (!W_ERROR_IS_OK(werror)) { - PyErr_SetObject(spoolss_werror, - PyInt_FromLong(W_ERROR_V(werror))); + PyErr_SetObject(spoolss_werror, py_werror_tuple(werror)); return NULL; } @@ -313,8 +312,7 @@ PyObject *spoolss_enumprinters(PyObject *self, PyObject *args, PyObject *kw) /* Return value */ if (!W_ERROR_IS_OK(werror)) { - PyErr_SetObject(spoolss_werror, - PyInt_FromLong(W_ERROR_V(werror))); + PyErr_SetObject(spoolss_werror, py_werror_tuple(werror)); return NULL; } -- cgit From 1359433ad8c4f66922564a5f9c1bba7a7b2563e5 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Wed, 8 May 2002 04:26:22 +0000 Subject: Added setjob() command. (This used to be commit 02c63de9e58f9806e58d3862391e05e9b9cdb8fc) --- source3/python/py_spoolss.c | 11 +++++++++++ source3/python/py_spoolss_jobs.c | 30 ++++++++++++++++++++++++++++++ source3/python/py_spoolss_proto.h | 1 + 3 files changed, 42 insertions(+) (limited to 'source3/python') diff --git a/source3/python/py_spoolss.c b/source3/python/py_spoolss.c index b1c70f9d4e..51e128ecc0 100644 --- a/source3/python/py_spoolss.c +++ b/source3/python/py_spoolss.c @@ -191,6 +191,9 @@ Set the form given by the dictionary argument. { "enumjobs", spoolss_enumjobs, METH_VARARGS | METH_KEYWORDS, "Enumerate jobs" }, + { "setjob", spoolss_setjob, METH_VARARGS | METH_KEYWORDS, + "Set job command" }, + { NULL } }; @@ -325,6 +328,14 @@ struct spoolss_const { { "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 }, }; diff --git a/source3/python/py_spoolss_jobs.c b/source3/python/py_spoolss_jobs.c index e049d82a33..3e436849b1 100644 --- a/source3/python/py_spoolss_jobs.c +++ b/source3/python/py_spoolss_jobs.c @@ -84,3 +84,33 @@ PyObject *spoolss_enumjobs(PyObject *self, PyObject *args, PyObject *kw) Py_INCREF(result); return result; } + +/* Set job command */ + +PyObject *spoolss_setjob(PyObject *self, PyObject *args, PyObject *kw) +{ + spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self; + WERROR werror; + PyObject *result; + 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; +} diff --git a/source3/python/py_spoolss_proto.h b/source3/python/py_spoolss_proto.h index 81d34a2c2d..913b7822c2 100644 --- a/source3/python/py_spoolss_proto.h +++ b/source3/python/py_spoolss_proto.h @@ -48,6 +48,7 @@ BOOL py_to_FORM(FORM *form, PyObject *dict); /* The following definitions come from python/py_spoolss_jobs.c */ PyObject *spoolss_enumjobs(PyObject *self, PyObject *args, PyObject *kw); +PyObject *spoolss_setjob(PyObject *self, PyObject *args, PyObject *kw); /* The following definitions come from python/py_spoolss_jobs_conv.c */ -- cgit From 5e723ce3c089f118e66f55ef78832421531265f8 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Wed, 8 May 2002 05:50:12 +0000 Subject: Added commands for startpageprinter, endpageprinter, setjob and getjob. (This used to be commit 3da89aa8e45d08444bfcddb145264bfcd6f6d768) --- source3/python/py_spoolss.c | 13 ++++- source3/python/py_spoolss_jobs.c | 101 +++++++++++++++++++++++++++++++++++++- source3/python/py_spoolss_proto.h | 3 ++ 3 files changed, 115 insertions(+), 2 deletions(-) (limited to 'source3/python') diff --git a/source3/python/py_spoolss.c b/source3/python/py_spoolss.c index 51e128ecc0..323b3c3b6f 100644 --- a/source3/python/py_spoolss.c +++ b/source3/python/py_spoolss.c @@ -192,7 +192,18 @@ Set the form given by the dictionary argument. "Enumerate jobs" }, { "setjob", spoolss_setjob, METH_VARARGS | METH_KEYWORDS, - "Set job command" }, + "Set job information" }, + + { "getjob", spoolss_getjob, METH_VARARGS | METH_KEYWORDS, + "Get job information" }, + + { "startpageprinter", spoolss_startpageprinter, + METH_VARARGS | METH_KEYWORDS, + "Notify spooler that a page is about to be printed." }, + + { "endpageprinter", spoolss_endpageprinter, + METH_VARARGS | METH_KEYWORDS, + "Notify spooler that a page is about to be printed." }, { NULL } diff --git a/source3/python/py_spoolss_jobs.c b/source3/python/py_spoolss_jobs.c index 3e436849b1..2cab6c0b28 100644 --- a/source3/python/py_spoolss_jobs.c +++ b/source3/python/py_spoolss_jobs.c @@ -91,7 +91,6 @@ PyObject *spoolss_setjob(PyObject *self, PyObject *args, PyObject *kw) { spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self; WERROR werror; - PyObject *result; uint32 level = 0, command, jobid; static char *kwlist[] = {"jobid", "command", "level", NULL}; @@ -114,3 +113,103 @@ PyObject *spoolss_setjob(PyObject *self, PyObject *args, PyObject *kw) Py_INCREF(Py_None); return Py_None; } + +/* Get job */ + +PyObject *spoolss_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_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_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; +} diff --git a/source3/python/py_spoolss_proto.h b/source3/python/py_spoolss_proto.h index 913b7822c2..bd54030551 100644 --- a/source3/python/py_spoolss_proto.h +++ b/source3/python/py_spoolss_proto.h @@ -49,6 +49,9 @@ BOOL py_to_FORM(FORM *form, PyObject *dict); PyObject *spoolss_enumjobs(PyObject *self, PyObject *args, PyObject *kw); PyObject *spoolss_setjob(PyObject *self, PyObject *args, PyObject *kw); +PyObject *spoolss_getjob(PyObject *self, PyObject *args, PyObject *kw); +PyObject *spoolss_startpageprinter(PyObject *self, PyObject *args, PyObject *kw); +PyObject *spoolss_endpageprinter(PyObject *self, PyObject *args, PyObject *kw); /* The following definitions come from python/py_spoolss_jobs_conv.c */ -- cgit From 950004e125724aa0fea5fe5b74d5e12f48c52017 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 13 May 2002 01:55:04 +0000 Subject: Added startdocprinter and enddocprinter. (This used to be commit 954107a9d314c8d87f65f741804ca3f9ca94432e) --- source3/python/py_spoolss.c | 8 ++ source3/python/py_spoolss_jobs.c | 136 ++++++++++++++++++++++++++++++++++ source3/python/py_spoolss_jobs_conv.c | 20 +++++ source3/python/py_spoolss_proto.h | 4 + 4 files changed, 168 insertions(+) (limited to 'source3/python') diff --git a/source3/python/py_spoolss.c b/source3/python/py_spoolss.c index 323b3c3b6f..a8372fd213 100644 --- a/source3/python/py_spoolss.c +++ b/source3/python/py_spoolss.c @@ -205,6 +205,14 @@ Set the form given by the dictionary argument. METH_VARARGS | METH_KEYWORDS, "Notify spooler that a page is about to be printed." }, + { "startdocprinter", spoolss_startdocprinter, + METH_VARARGS | METH_KEYWORDS, + "Notify spooler that a document is about to be printed." }, + + { "enddocprinter", spoolss_enddocprinter, + METH_VARARGS | METH_KEYWORDS, + "Notify spooler that a document is about to be printed." }, + { NULL } }; diff --git a/source3/python/py_spoolss_jobs.c b/source3/python/py_spoolss_jobs.c index 2cab6c0b28..3d2295b88e 100644 --- a/source3/python/py_spoolss_jobs.c +++ b/source3/python/py_spoolss_jobs.c @@ -213,3 +213,139 @@ PyObject *spoolss_endpageprinter(PyObject *self, PyObject *args, PyObject *kw) 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_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 *doc_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, &doc_info)) + return NULL; + + /* Check document_info parameter */ + + if ((obj = PyDict_GetItemString(doc_info, "level"))) { + + if (!PyInt_Check(obj)) { + PyErr_SetString(spoolss_error, + "level not an integer"); + return NULL; + } + + level = PyInt_AsLong(obj); + + /* Only level 1 supported by Samba! */ + + if (level != 1) { + PyErr_SetString(spoolss_error, + "unsupported info level"); + return NULL; + } + + } else { + PyErr_SetString(spoolss_error, "no info level present"); + return NULL; + } + + if ((obj = PyDict_GetItemString(doc_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(doc_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(doc_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_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; +} diff --git a/source3/python/py_spoolss_jobs_conv.c b/source3/python/py_spoolss_jobs_conv.c index 7db8a5c5af..5ac36379ba 100644 --- a/source3/python/py_spoolss_jobs_conv.c +++ b/source3/python/py_spoolss_jobs_conv.c @@ -61,6 +61,13 @@ struct pyconv py_JOB_INFO_2[] = { { NULL } }; +struct pyconv py_DOC_INFO_1[] = { + { "document_name", PY_UNISTR, offsetof(DOC_INFO_1, docname) }, + { "output_file", PY_UNISTR, offsetof(DOC_INFO_1, outputfile) }, + { "data_type", PY_UNISTR, offsetof(DOC_INFO_1, datatype) }, + { NULL } +}; + BOOL py_from_JOB_INFO_1(PyObject **dict, JOB_INFO_1 *info) { *dict = from_struct(info, py_JOB_INFO_1); @@ -82,3 +89,16 @@ BOOL py_to_JOB_INFO_2(JOB_INFO_2 *info, PyObject *dict) { return False; } + +BOOL py_from_DOC_INFO_1(PyObject **dict, DOC_INFO_1 *info) +{ + *dict = from_struct(info, py_DOC_INFO_1); + return True; +} + +BOOL py_to_DOC_INFO_1(DOC_INFO_1 *info, PyObject *dict) +{ + to_struct(info, dict, py_DOC_INFO_1); + return True; +} + diff --git a/source3/python/py_spoolss_proto.h b/source3/python/py_spoolss_proto.h index bd54030551..ae9abf5351 100644 --- a/source3/python/py_spoolss_proto.h +++ b/source3/python/py_spoolss_proto.h @@ -52,6 +52,8 @@ PyObject *spoolss_setjob(PyObject *self, PyObject *args, PyObject *kw); PyObject *spoolss_getjob(PyObject *self, PyObject *args, PyObject *kw); PyObject *spoolss_startpageprinter(PyObject *self, PyObject *args, PyObject *kw); PyObject *spoolss_endpageprinter(PyObject *self, PyObject *args, PyObject *kw); +PyObject *spoolss_startdocprinter(PyObject *self, PyObject *args, PyObject *kw); +PyObject *spoolss_enddocprinter(PyObject *self, PyObject *args, PyObject *kw); /* The following definitions come from python/py_spoolss_jobs_conv.c */ @@ -59,6 +61,8 @@ 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 */ -- cgit From 5ead26e30b851a544385b3b4d4b3b929b6faf290 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 13 May 2002 06:04:07 +0000 Subject: Registry module. Only contains REG_xxx constants used by the spoolss printerdata routines at the moment. (This used to be commit f2b9447bbdfe025b24a73d1c44885bcadb3f826f) --- source3/python/py_winreg.c | 83 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 source3/python/py_winreg.c (limited to 'source3/python') diff --git a/source3/python/py_winreg.c b/source3/python/py_winreg.c new file mode 100644 index 0000000000..105ad25db2 --- /dev/null +++ b/source3/python/py_winreg.c @@ -0,0 +1,83 @@ +/* + 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" + +struct spoolss_const { + char *name; + uint32 value; +} spoolss_const_vals[] = { + + /* Registry value types */ + + { "REG_NONE", REG_NONE }, + { "REG_SZ", REG_SZ }, + { "REG_EXPAND_SZ", REG_EXPAND_SZ }, + { "REG_BINARY", REG_BINARY }, + { "REG_DWORD", REG_DWORD }, + { "REG_DWORD_LE", REG_DWORD_LE }, + { "REG_DWORD_BE", REG_DWORD_BE }, + { "REG_LINK", REG_LINK }, + { "REG_MULTI_SZ", REG_MULTI_SZ }, + { "REG_RESOURCE_LIST", REG_RESOURCE_LIST }, + { "REG_FULL_RESOURCE_DESCRIPTOR", REG_FULL_RESOURCE_DESCRIPTOR }, + { "REG_RESOURCE_REQUIREMENTS_LIST", REG_RESOURCE_REQUIREMENTS_LIST }, + + { NULL }, +}; + +static void const_init(PyObject *dict) +{ + struct spoolss_const *tmp; + PyObject *obj; + + for (tmp = spoolss_const_vals; tmp->name; tmp++) { + obj = PyInt_FromLong(tmp->value); + PyDict_SetItemString(dict, tmp->name, obj); + Py_DECREF(obj); + } +} + +/* + * Module initialisation + */ + +static PyMethodDef winreg_methods[] = { + { NULL } +}; + +void initwinreg(void) +{ + PyObject *module, *dict; + + /* Initialise module */ + + module = Py_InitModule("winreg", winreg_methods); + dict = PyModule_GetDict(module); + + /* Initialise constants */ + + const_init(dict); + + /* Do samba initialisation */ + + py_samba_init(); +} -- cgit From 62f63f96e1a18bae09c6cdb42f4ab17668fc90ff Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 13 May 2002 07:27:20 +0000 Subject: Added getprinterdata and setprinterdata functions. (This used to be commit 325361e9e6e2b2f852cc8607ad93108b80bcef06) --- source3/python/py_spoolss.c | 14 +++ source3/python/py_spoolss_printerdata.c | 160 ++++++++++++++++++++++++++++++++ source3/python/py_spoolss_proto.h | 6 ++ 3 files changed, 180 insertions(+) create mode 100644 source3/python/py_spoolss_printerdata.c (limited to 'source3/python') diff --git a/source3/python/py_spoolss.c b/source3/python/py_spoolss.c index a8372fd213..d57867dd7c 100644 --- a/source3/python/py_spoolss.c +++ b/source3/python/py_spoolss.c @@ -213,6 +213,20 @@ Set the form given by the dictionary argument. METH_VARARGS | METH_KEYWORDS, "Notify spooler that a document is about to be printed." }, + /* Printer data */ + + { "getprinterdata", spoolss_getprinterdata, + METH_VARARGS | METH_KEYWORDS, + "Get printer data." }, + + { "setprinterdata", spoolss_setprinterdata, + METH_VARARGS | METH_KEYWORDS, + "Set printer data." }, + + { "enumprinterdata", spoolss_enumprinterdata, + METH_VARARGS | METH_KEYWORDS, + "Enumerate printer data." }, + { NULL } }; diff --git a/source3/python/py_spoolss_printerdata.c b/source3/python/py_spoolss_printerdata.c new file mode 100644 index 0000000000..622c487b8c --- /dev/null +++ b/source3/python/py_spoolss_printerdata.c @@ -0,0 +1,160 @@ +/* + 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_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_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_enumprinterdata(PyObject *self, PyObject *args, PyObject *kw) +{ + return NULL; +} diff --git a/source3/python/py_spoolss_proto.h b/source3/python/py_spoolss_proto.h index ae9abf5351..1f08b1b615 100644 --- a/source3/python/py_spoolss_proto.h +++ b/source3/python/py_spoolss_proto.h @@ -75,6 +75,12 @@ 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_getprinterdata(PyObject *self, PyObject *args, PyObject *kw); +PyObject *spoolss_setprinterdata(PyObject *self, PyObject *args, PyObject *kw); +PyObject *spoolss_enumprinterdata(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); -- cgit From 27c0ce7d1178d7f00a97558c8634de884a6afd68 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 13 May 2002 07:28:16 +0000 Subject: Removed irritating CR at end of file. (This used to be commit 2811ac99a1fcc2be02f89a418fe00c99c2bba81c) --- source3/python/py_spoolss_jobs_conv.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source3/python') diff --git a/source3/python/py_spoolss_jobs_conv.c b/source3/python/py_spoolss_jobs_conv.c index 5ac36379ba..3481e96485 100644 --- a/source3/python/py_spoolss_jobs_conv.c +++ b/source3/python/py_spoolss_jobs_conv.c @@ -101,4 +101,3 @@ BOOL py_to_DOC_INFO_1(DOC_INFO_1 *info, PyObject *dict) to_struct(info, dict, py_DOC_INFO_1); return True; } - -- cgit From b2606aaa80a6bb8b2ffe7d268a287a943198e375 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 13 May 2002 07:29:38 +0000 Subject: Updated patch. (This used to be commit 0851f473b7705a3d95dc2727cd7986295d2733ff) --- source3/python/samba-head.patch | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) (limited to 'source3/python') diff --git a/source3/python/samba-head.patch b/source3/python/samba-head.patch index 59d2a25ae4..0894533487 100644 --- a/source3/python/samba-head.patch +++ b/source3/python/samba-head.patch @@ -1,11 +1,11 @@ Index: Makefile.in =================================================================== RCS file: /data/cvs/samba/source/Makefile.in,v -retrieving revision 1.473 -diff -u -r1.473 Makefile.in ---- Makefile.in 2002/04/30 05:44:25 1.473 -+++ Makefile.in 2002/05/07 07:02:43 -@@ -788,6 +788,44 @@ +retrieving revision 1.475 +diff -u -r1.475 Makefile.in +--- Makefile.in 2002/05/09 04:44:00 1.475 ++++ Makefile.in 2002/05/13 07:26:04 +@@ -792,6 +792,45 @@ -$(INSTALLCMD) -d ${prefix}/include -$(INSTALLCMD) include/libsmbclient.h ${prefix}/include @@ -19,7 +19,8 @@ diff -u -r1.473 Makefile.in + 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_jobs.o python/py_spoolss_jobs_conv.o \ ++ python/py_spoolss_printerdata.o + +PY_LSA_PROTO_OBJ = python/py_lsa.o + @@ -53,16 +54,16 @@ diff -u -r1.473 Makefile.in Index: configure.in =================================================================== RCS file: /data/cvs/samba/source/configure.in,v -retrieving revision 1.302 -diff -u -r1.302 configure.in ---- configure.in 2002/04/24 11:42:46 1.302 -+++ configure.in 2002/05/07 07:02:44 -@@ -2720,7 +2720,7 @@ +retrieving revision 1.307 +diff -u -r1.307 configure.in +--- configure.in 2002/05/11 00:36:33 1.307 ++++ configure.in 2002/05/13 07:26:06 +@@ -2892,7 +2892,7 @@ builddir=`pwd` AC_SUBST(builddir) --AC_OUTPUT(include/stamp-h Makefile) -+AC_OUTPUT(include/stamp-h Makefile python/setup.py) +-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 -- cgit From 4662d9b896e806be7035f7dc0fd9b5bc1eaa5f29 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 13 May 2002 07:30:41 +0000 Subject: Added entry for winreg extension. Added extra source file for printerdata routines. (This used to be commit 34a0293a04cecf20c05a2d09d1ecda64538ca529) --- source3/python/setup.py.in | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'source3/python') diff --git a/source3/python/setup.py.in b/source3/python/setup.py.in index 2e0e5def9d..ceb86854c0 100755 --- a/source3/python/setup.py.in +++ b/source3/python/setup.py.in @@ -94,6 +94,7 @@ setup( 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", @@ -131,5 +132,14 @@ setup( 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), + ], ) -- cgit From 520b40e4235f26cf2bc670128ff277141084e53c Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Tue, 14 May 2002 02:37:47 +0000 Subject: General cleanup of compiler warnings etc. (This used to be commit 18aeadc591b69bbbd874b7285ecaed50ff587e68) --- source3/python/py_common.h | 2 ++ source3/python/py_lsa.c | 42 ++++++++++++++++++------ source3/python/py_samr.c | 27 +++++++++++++--- source3/python/py_spoolss.c | 78 ++++++++++++++++++++++++++------------------- source3/python/py_winbind.c | 8 ++--- source3/python/py_winreg.c | 11 +++---- source3/python/py_winreg.h | 29 +++++++++++++++++ 7 files changed, 139 insertions(+), 58 deletions(-) create mode 100644 source3/python/py_winreg.h (limited to 'source3/python') diff --git a/source3/python/py_common.h b/source3/python/py_common.h index 6661d87fe0..f13224a020 100644 --- a/source3/python/py_common.h +++ b/source3/python/py_common.h @@ -21,6 +21,8 @@ #ifndef _PY_COMMON_H #define _PY_COMMON_H +#include "includes.h" + /* Return a cli_state struct opened on the SPOOLSS pipe. If credentials are passed use them. */ diff --git a/source3/python/py_lsa.c b/source3/python/py_lsa.c index 82ae99c53e..23566282f6 100644 --- a/source3/python/py_lsa.c +++ b/source3/python/py_lsa.c @@ -18,9 +18,6 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#include "includes.h" -#include "Python.h" - #include "python/py_lsa.h" PyObject *new_lsa_policy_hnd_object(struct cli_state *cli, TALLOC_CTX *mem_ctx, @@ -300,15 +297,18 @@ static PyMethodDef lsa_hnd_methods[] = { /* SIDs<->names */ - { "lookup_sids", lsa_lookup_sids, METH_VARARGS | METH_KEYWORDS, + { "lookup_sids", (PyCFunction)lsa_lookup_sids, + METH_VARARGS | METH_KEYWORDS, "Convert sids to names." }, - { "lookup_names", lsa_lookup_names, METH_VARARGS | METH_KEYWORDS, + { "lookup_names", (PyCFunction)lsa_lookup_names, + METH_VARARGS | METH_KEYWORDS, "Convert names to sids." }, /* Trusted domains */ - { "enum_trusted_domains", lsa_enum_trust_dom, METH_VARARGS, + { "enum_trusted_domains", (PyCFunction)lsa_enum_trust_dom, + METH_VARARGS, "Enumerate trusted domains." }, { NULL } @@ -346,17 +346,39 @@ static PyMethodDef lsa_methods[] = { /* Open/close lsa handles */ - { "open_policy", lsa_open_policy, METH_VARARGS | METH_KEYWORDS, + { "open_policy", (PyCFunction)lsa_open_policy, + METH_VARARGS | METH_KEYWORDS, "Open a policy handle" }, - { "close", lsa_close, METH_VARARGS, "Close a policy handle" }, + { "close", (PyCFunction)lsa_close, + METH_VARARGS, + "Close a policy 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); + } +} + /* * Module initialisation -*/ + */ void initlsa(void) { @@ -379,7 +401,7 @@ void initlsa(void) /* Initialise constants */ -// const_init(dict); + const_init(dict); /* Do samba initialisation */ diff --git a/source3/python/py_samr.c b/source3/python/py_samr.c index 9a19f9abd5..6c52ebe8cd 100644 --- a/source3/python/py_samr.c +++ b/source3/python/py_samr.c @@ -18,9 +18,6 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#include "includes.h" -#include "Python.h" - #include "python/py_samr.h" /* @@ -327,12 +324,32 @@ static PyMethodDef samr_methods[] = { /* Open/close samr connect handles */ - { "connect", samr_connect, METH_VARARGS | METH_KEYWORDS, + { "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; @@ -358,7 +375,7 @@ void initsamr(void) /* Initialise constants */ -// const_init(dict); + const_init(dict); /* Do samba initialisation */ diff --git a/source3/python/py_spoolss.c b/source3/python/py_spoolss.c index d57867dd7c..b209e6243b 100644 --- a/source3/python/py_spoolss.c +++ b/source3/python/py_spoolss.c @@ -50,7 +50,7 @@ static PyMethodDef spoolss_methods[] = { /* Open/close printer handles */ - { "openprinter", spoolss_openprinter, METH_VARARGS | METH_KEYWORDS, + { "openprinter", (PyCFunction)spoolss_openprinter, METH_VARARGS | METH_KEYWORDS, "openprinter(printername, [creds, access]) -> Open a printer given by printername in UNC format. Optionally a dictionary @@ -75,7 +75,8 @@ Example: /* Server enumeratation functions */ - { "enumprinters", spoolss_enumprinters, METH_VARARGS | METH_KEYWORDS, + { "enumprinters", (PyCFunction)spoolss_enumprinters, + METH_VARARGS | METH_KEYWORDS, "enumprinters(server, [creds, level, flags]) -> list Return a list of printers on a print server. The credentials, info level @@ -90,7 +91,8 @@ Example: 'description': 'fileprint,Generic / Text Only,'}] "}, - { "enumports", spoolss_enumports, METH_VARARGS | METH_KEYWORDS, + { "enumports", (PyCFunction)spoolss_enumports, + METH_VARARGS | METH_KEYWORDS, "enumports(server, [creds, level]) -> list Return a list of ports on a print server. @@ -102,15 +104,15 @@ Example: {'name': 'FILE:'}, {'name': '\\\\nautilus1\\zpekt3r'}] "}, - { "enumprinterdrivers", spoolss_enumprinterdrivers, METH_VARARGS | - METH_KEYWORDS, -"enumprinterdrivers(server, [creds, level, arch]) -> list + { "enumprinterdrivers", (PyCFunction)spoolss_enumprinterdrivers, + METH_VARARGS | METH_KEYWORDS, + "enumprinterdrivers(server, [creds, level, arch]) -> list Return a list of printer drivers. "}, /* Miscellaneous other commands */ - { "getprinterdriverdir", spoolss_getprinterdriverdir, METH_VARARGS | + { "getprinterdriverdir", (PyCFunction)spoolss_getprinterdriverdir, METH_VARARGS | METH_KEYWORDS, "getprinterdriverdir(server, [creds]) -> string Return the printer driver directory for a given architecture. The @@ -120,11 +122,11 @@ 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", py_setup_logging, METH_VARARGS | METH_KEYWORDS, - "" }, + { "setup_logging", (PyCFunction)py_setup_logging, + METH_VARARGS | METH_KEYWORDS, "" }, - { "get_debuglevel", get_debuglevel, METH_VARARGS, "" }, - { "set_debuglevel", set_debuglevel, METH_VARARGS, "" }, + { "get_debuglevel", (PyCFunction)get_debuglevel, METH_VARARGS, "" }, + { "set_debuglevel", (PyCFunction)set_debuglevel, METH_VARARGS, "" }, { NULL } }; @@ -135,7 +137,8 @@ static PyMethodDef spoolss_hnd_methods[] = { /* Printer info */ - { "getprinter", spoolss_getprinter, METH_VARARGS | METH_KEYWORDS, + { "getprinter", (PyCFunction)spoolss_getprinter, + METH_VARARGS | METH_KEYWORDS, "getprinter([level]) -> dict Return a dictionary of print information. The info level defaults to 1. @@ -148,7 +151,8 @@ Example: 'flags': 8388608} "}, - { "setprinter", spoolss_setprinter, METH_VARARGS | METH_KEYWORDS, + { "setprinter", (PyCFunction)spoolss_setprinter, + METH_VARARGS | METH_KEYWORDS, "setprinter(dict) -> None Set printer information. @@ -156,7 +160,7 @@ Set printer information. /* Printer drivers */ - { "getprinterdriver", spoolss_getprinterdriver, + { "getprinterdriver", (PyCFunction)spoolss_getprinterdriver, METH_VARARGS | METH_KEYWORDS, "getprinterdriver([level = 1, arch = \"Windows NT x86\"] -> dict @@ -165,65 +169,73 @@ Return a dictionary of printer driver information. /* Forms */ - { "enumforms", spoolss_enumforms, METH_VARARGS | METH_KEYWORDS, + { "enumforms", (PyCFunction)spoolss_enumforms, + METH_VARARGS | METH_KEYWORDS, "enumforms([level = 1]) -> list Return a list of forms supported by a printer. "}, - { "setform", spoolss_setform, METH_VARARGS | METH_KEYWORDS, + { "setform", (PyCFunction)spoolss_setform, + METH_VARARGS | METH_KEYWORDS, "setform(dict) -> None Set the form given by the dictionary argument. "}, - { "addform", spoolss_addform, METH_VARARGS | METH_KEYWORDS, + { "addform", (PyCFunction)spoolss_addform, + METH_VARARGS | METH_KEYWORDS, "Insert a form" }, - { "getform", spoolss_getform, METH_VARARGS | METH_KEYWORDS, + { "getform", (PyCFunction)spoolss_getform, + METH_VARARGS | METH_KEYWORDS, "Fetch form properties" }, - { "deleteform", spoolss_deleteform, METH_VARARGS | METH_KEYWORDS, + { "deleteform", (PyCFunction)spoolss_deleteform, + METH_VARARGS | METH_KEYWORDS, "Delete a form" }, /* Job related methods */ - { "enumjobs", spoolss_enumjobs, METH_VARARGS | METH_KEYWORDS, + { "enumjobs", (PyCFunction)spoolss_enumjobs, + METH_VARARGS | METH_KEYWORDS, "Enumerate jobs" }, - { "setjob", spoolss_setjob, METH_VARARGS | METH_KEYWORDS, + { "setjob", (PyCFunction)spoolss_setjob, + METH_VARARGS | METH_KEYWORDS, "Set job information" }, - { "getjob", spoolss_getjob, METH_VARARGS | METH_KEYWORDS, + { "getjob", (PyCFunction)spoolss_getjob, + METH_VARARGS | METH_KEYWORDS, "Get job information" }, - { "startpageprinter", spoolss_startpageprinter, + { "startpageprinter", (PyCFunction)spoolss_startpageprinter, METH_VARARGS | METH_KEYWORDS, "Notify spooler that a page is about to be printed." }, - { "endpageprinter", spoolss_endpageprinter, + { "endpageprinter", (PyCFunction)spoolss_endpageprinter, METH_VARARGS | METH_KEYWORDS, "Notify spooler that a page is about to be printed." }, - { "startdocprinter", spoolss_startdocprinter, + { "startdocprinter", (PyCFunction)spoolss_startdocprinter, METH_VARARGS | METH_KEYWORDS, "Notify spooler that a document is about to be printed." }, - { "enddocprinter", spoolss_enddocprinter, + { "enddocprinter", (PyCFunction)spoolss_enddocprinter, METH_VARARGS | METH_KEYWORDS, "Notify spooler that a document is about to be printed." }, /* Printer data */ - { "getprinterdata", spoolss_getprinterdata, + { "getprinterdata", (PyCFunction)spoolss_getprinterdata, METH_VARARGS | METH_KEYWORDS, "Get printer data." }, - { "setprinterdata", spoolss_setprinterdata, + { "setprinterdata", (PyCFunction)spoolss_setprinterdata, METH_VARARGS | METH_KEYWORDS, "Set printer data." }, - { "enumprinterdata", spoolss_enumprinterdata, + { "enumprinterdata", (PyCFunction)spoolss_enumprinterdata, METH_VARARGS | METH_KEYWORDS, "Enumerate printer data." }, @@ -280,10 +292,10 @@ PyTypeObject spoolss_policy_hnd_type = { /* Initialise constants */ -struct spoolss_const { +static struct const_vals { char *name; uint32 value; -} spoolss_const_vals[] = { +} module_const_vals[] = { /* Access permissions */ @@ -374,10 +386,10 @@ struct spoolss_const { static void const_init(PyObject *dict) { - struct spoolss_const *tmp; + struct const_vals *tmp; PyObject *obj; - for (tmp = spoolss_const_vals; tmp->name; tmp++) { + for (tmp = module_const_vals; tmp->name; tmp++) { obj = PyInt_FromLong(tmp->value); PyDict_SetItemString(dict, tmp->name, obj); Py_DECREF(obj); diff --git a/source3/python/py_winbind.c b/source3/python/py_winbind.c index 657e98281d..e55d12afb2 100644 --- a/source3/python/py_winbind.c +++ b/source3/python/py_winbind.c @@ -578,11 +578,11 @@ success." }, { NULL } }; -static struct winbind_const { +static struct const_vals { char *name; uint32 value; char *docstring; -} winbind_const_vals[] = { +} module_const_vals[] = { /* Well known RIDs */ @@ -606,10 +606,10 @@ static struct winbind_const { static void const_init(PyObject *dict) { - struct winbind_const *tmp; + struct const_vals *tmp; PyObject *obj; - for (tmp = winbind_const_vals; tmp->name; tmp++) { + for (tmp = module_const_vals; tmp->name; tmp++) { obj = PyInt_FromLong(tmp->value); PyDict_SetItemString(dict, tmp->name, obj); Py_DECREF(obj); diff --git a/source3/python/py_winreg.c b/source3/python/py_winreg.c index 105ad25db2..ce27f5c533 100644 --- a/source3/python/py_winreg.c +++ b/source3/python/py_winreg.c @@ -18,13 +18,12 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ -#include "includes.h" -#include "Python.h" +#include "python/py_winreg.h" -struct spoolss_const { +static struct const_vals { char *name; uint32 value; -} spoolss_const_vals[] = { +} module_const_vals[] = { /* Registry value types */ @@ -46,10 +45,10 @@ struct spoolss_const { static void const_init(PyObject *dict) { - struct spoolss_const *tmp; + struct const_vals *tmp; PyObject *obj; - for (tmp = spoolss_const_vals; tmp->name; tmp++) { + for (tmp = module_const_vals; tmp->name; tmp++) { obj = PyInt_FromLong(tmp->value); PyDict_SetItemString(dict, tmp->name, obj); Py_DECREF(obj); diff --git a/source3/python/py_winreg.h b/source3/python/py_winreg.h new file mode 100644 index 0000000000..e19674d218 --- /dev/null +++ b/source3/python/py_winreg.h @@ -0,0 +1,29 @@ +/* + 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_WINREG_H +#define _PY_WINREG_H + +#include "includes.h" +#include "Python.h" + +#include "python/py_common.h" + +#endif /* _PY_WINREG_H */ -- cgit From 762d52feba43fa0ae296d7eed6195fbe3ccc0e71 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Tue, 14 May 2002 05:01:04 +0000 Subject: Added enumprinterdata. (This used to be commit 7a15ce7c0c6a6b3a62dd6607fefc32742fa50308) --- source3/python/py_spoolss_printerdata.c | 42 ++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) (limited to 'source3/python') diff --git a/source3/python/py_spoolss_printerdata.c b/source3/python/py_spoolss_printerdata.c index 622c487b8c..352252f2bd 100644 --- a/source3/python/py_spoolss_printerdata.c +++ b/source3/python/py_spoolss_printerdata.c @@ -156,5 +156,45 @@ PyObject *spoolss_setprinterdata(PyObject *self, PyObject *args, PyObject *kw) PyObject *spoolss_enumprinterdata(PyObject *self, PyObject *args, PyObject *kw) { - return NULL; + 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; } -- cgit From 2e6939cf0b16055bae6eba6b3d3404164833c459 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Tue, 14 May 2002 06:09:59 +0000 Subject: Added writeprinter command. (This used to be commit 307788d0b823f228c718b2a186fc66144fd55717) --- source3/python/py_spoolss.c | 4 ++++ source3/python/py_spoolss_jobs.c | 31 +++++++++++++++++++++++++++++++ source3/python/py_spoolss_proto.h | 1 + 3 files changed, 36 insertions(+) (limited to 'source3/python') diff --git a/source3/python/py_spoolss.c b/source3/python/py_spoolss.c index b209e6243b..ef61d02db6 100644 --- a/source3/python/py_spoolss.c +++ b/source3/python/py_spoolss.c @@ -225,6 +225,10 @@ Set the form given by the dictionary argument. METH_VARARGS | METH_KEYWORDS, "Notify spooler that a document is about to be printed." }, + { "writeprinter", (PyCFunction)spoolss_writeprinter, + METH_VARARGS | METH_KEYWORDS, + "Write job data to a printer." }, + /* Printer data */ { "getprinterdata", (PyCFunction)spoolss_getprinterdata, diff --git a/source3/python/py_spoolss_jobs.c b/source3/python/py_spoolss_jobs.c index 3d2295b88e..6951ebab9a 100644 --- a/source3/python/py_spoolss_jobs.c +++ b/source3/python/py_spoolss_jobs.c @@ -349,3 +349,34 @@ PyObject *spoolss_enddocprinter(PyObject *self, PyObject *args, PyObject *kw) Py_INCREF(Py_None); return Py_None; } + +/* Write data to a printer */ + +PyObject *spoolss_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; +} diff --git a/source3/python/py_spoolss_proto.h b/source3/python/py_spoolss_proto.h index 1f08b1b615..c56b8f7095 100644 --- a/source3/python/py_spoolss_proto.h +++ b/source3/python/py_spoolss_proto.h @@ -54,6 +54,7 @@ PyObject *spoolss_startpageprinter(PyObject *self, PyObject *args, PyObject *kw) PyObject *spoolss_endpageprinter(PyObject *self, PyObject *args, PyObject *kw); PyObject *spoolss_startdocprinter(PyObject *self, PyObject *args, PyObject *kw); PyObject *spoolss_enddocprinter(PyObject *self, PyObject *args, PyObject *kw); +PyObject *spoolss_writeprinter(PyObject *self, PyObject *args, PyObject *kw); /* The following definitions come from python/py_spoolss_jobs_conv.c */ -- cgit From ceb338a35c80f1ddd8965b19bdbde5e870107fb7 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Tue, 14 May 2002 07:09:54 +0000 Subject: Moved PyDict_SetItemString for printer info level structures into conv functions. (This used to be commit f7fadfdd73d3ba12dbfc7bf18319ce72f79a0dcc) --- source3/python/py_spoolss_printers.c | 2 -- source3/python/py_spoolss_printers_conv.c | 6 ++++++ 2 files changed, 6 insertions(+), 2 deletions(-) (limited to 'source3/python') diff --git a/source3/python/py_spoolss_printers.c b/source3/python/py_spoolss_printers.c index 17c8af902a..d20b144502 100644 --- a/source3/python/py_spoolss_printers.c +++ b/source3/python/py_spoolss_printers.c @@ -170,8 +170,6 @@ PyObject *spoolss_getprinter(PyObject *self, PyObject *args, PyObject *kw) break; } - PyDict_SetItemString(result, "level", PyInt_FromLong(level)); - Py_INCREF(result); return result; } diff --git a/source3/python/py_spoolss_printers_conv.c b/source3/python/py_spoolss_printers_conv.c index 89980ef25a..b20382922c 100644 --- a/source3/python/py_spoolss_printers_conv.c +++ b/source3/python/py_spoolss_printers_conv.c @@ -181,6 +181,7 @@ BOOL py_to_DEVICEMODE(DEVICEMODE *devmode, PyObject *dict) 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; } @@ -196,6 +197,7 @@ BOOL py_to_PRINTER_INFO_0(PRINTER_INFO_0 *info, PyObject *dict) 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; } @@ -220,6 +222,8 @@ BOOL py_from_PRINTER_INFO_2(PyObject **dict, PRINTER_INFO_2 *info) if (py_from_DEVICEMODE(&obj, info->devmode)) PyDict_SetItemString(*dict, "device_mode", obj); + PyDict_SetItemString(*dict, "level", PyInt_FromLong(2)); + return True; } @@ -260,6 +264,8 @@ BOOL py_from_PRINTER_INFO_3(PyObject **dict, PRINTER_INFO_3 *info) if (py_from_SECDESC(&obj, info->secdesc)) PyDict_SetItemString(*dict, "security_descriptor", obj); + PyDict_SetItemString(*dict, "level", PyInt_FromLong(3)); + return True; } -- cgit From 60f4e9dccc31ff54ca941dc473e3b025b659f8b8 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Tue, 14 May 2002 07:11:31 +0000 Subject: Fixed bug in enumprinterdrivers. Added stubs for addprinterdriver and deleteprinterdriver functions. (This used to be commit ca315ef84ff949edfbf0a8df0ae2128a97fc3ac5) --- source3/python/py_spoolss_drivers.c | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) (limited to 'source3/python') diff --git a/source3/python/py_spoolss_drivers.c b/source3/python/py_spoolss_drivers.c index de2fd5626b..b612e139f3 100644 --- a/source3/python/py_spoolss_drivers.c +++ b/source3/python/py_spoolss_drivers.c @@ -78,7 +78,7 @@ PyObject *spoolss_enumprinterdrivers(PyObject *self, PyObject *args, for (i = 0; i < num_drivers; i++) { PyObject *value; - py_from_DRIVER_INFO_1(&value, ctr.info1); + py_from_DRIVER_INFO_1(&value, &ctr.info1[i]); PyList_SetItem(result, i, value); } @@ -89,7 +89,7 @@ PyObject *spoolss_enumprinterdrivers(PyObject *self, PyObject *args, for(i = 0; i < num_drivers; i++) { PyObject *value; - py_from_DRIVER_INFO_2(&value, ctr.info2); + py_from_DRIVER_INFO_2(&value, &ctr.info2[i]); PyList_SetItem(result, i, value); } @@ -100,7 +100,7 @@ PyObject *spoolss_enumprinterdrivers(PyObject *self, PyObject *args, for(i = 0; i < num_drivers; i++) { PyObject *value; - py_from_DRIVER_INFO_6(&value, ctr.info6); + py_from_DRIVER_INFO_6(&value, &ctr.info6[i]); PyList_SetItem(result, i, value); } @@ -241,3 +241,27 @@ PyObject *spoolss_getprinterdriverdir(PyObject *self, PyObject *args, Py_INCREF(result); return result; } + +PyObject *spoolss_addprinterdriver(PyObject *self, PyObject *args, + PyObject *kw) +{ + return NULL; +} + +PyObject *spoolss_addprinterdriverex(PyObject *self, PyObject *args, + PyObject *kw) +{ + return NULL; +} + +PyObject *spoolss_deleteprinterdriver(PyObject *self, PyObject *args, + PyObject *kw) +{ + return NULL; +} + +PyObject *spoolss_deleteprinterdriverex(PyObject *self, PyObject *args, + PyObject *kw) +{ + return NULL; +} -- cgit From d8b60d56fb961639e0d79c751c619badecadce8e Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Tue, 14 May 2002 07:13:25 +0000 Subject: Added deleteprinterdata function. Stub for deleteprinterdataex. (This used to be commit 14acdbf06dec517a4f2fee5904cae1c0b72a90aa) --- source3/python/py_spoolss_printerdata.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'source3/python') diff --git a/source3/python/py_spoolss_printerdata.c b/source3/python/py_spoolss_printerdata.c index 352252f2bd..c22eaa2239 100644 --- a/source3/python/py_spoolss_printerdata.c +++ b/source3/python/py_spoolss_printerdata.c @@ -198,3 +198,33 @@ PyObject *spoolss_enumprinterdata(PyObject *self, PyObject *args, PyObject *kw) return result; } + +PyObject *spoolss_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_deleteprinterdataex(PyObject *self, PyObject *args, PyObject *kw) +{ +} -- cgit From 034a0b46c7c3cd685de4440d4f489fc590e6ad89 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Tue, 14 May 2002 07:14:15 +0000 Subject: make proto (This used to be commit 0c52191cc5b986fbb50a476442e808d5e161e534) --- source3/python/py_spoolss_proto.h | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'source3/python') diff --git a/source3/python/py_spoolss_proto.h b/source3/python/py_spoolss_proto.h index c56b8f7095..89788faa36 100644 --- a/source3/python/py_spoolss_proto.h +++ b/source3/python/py_spoolss_proto.h @@ -18,6 +18,14 @@ PyObject *spoolss_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 */ @@ -81,6 +89,8 @@ BOOL py_to_PORT_INFO_2(PORT_INFO_2 *info, PyObject *dict); PyObject *spoolss_getprinterdata(PyObject *self, PyObject *args, PyObject *kw); PyObject *spoolss_setprinterdata(PyObject *self, PyObject *args, PyObject *kw); PyObject *spoolss_enumprinterdata(PyObject *self, PyObject *args, PyObject *kw); +PyObject *spoolss_deleteprinterdata(PyObject *self, PyObject *args, PyObject *kw); +PyObject *spoolss_deleteprinterdataex(PyObject *self, PyObject *args, PyObject *kw); /* The following definitions come from python/py_spoolss_printers.c */ -- cgit From 8ca814e5299afccd1e2c5aea222c23d84905fc02 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Tue, 14 May 2002 07:15:43 +0000 Subject: Added lots of new functions to the method tables. (This used to be commit a8f5951becaab82bb1b03e3e04a05901ec3aa8e3) --- source3/python/py_spoolss.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'source3/python') diff --git a/source3/python/py_spoolss.c b/source3/python/py_spoolss.c index ef61d02db6..68d5ded99a 100644 --- a/source3/python/py_spoolss.c +++ b/source3/python/py_spoolss.c @@ -128,6 +128,20 @@ architecture defaults to \"Windows NT x86\". { "get_debuglevel", (PyCFunction)get_debuglevel, METH_VARARGS, "" }, { "set_debuglevel", (PyCFunction)set_debuglevel, METH_VARARGS, "" }, + /* Printer driver routines */ + + { "addprinterdriver", (PyCFunction)spoolss_addprinterdriver, + METH_VARARGS | METH_KEYWORDS, "" }, + + { "addprinterdriverex", (PyCFunction)spoolss_addprinterdriverex, + METH_VARARGS | METH_KEYWORDS, "" }, + + { "deleteprinterdriver", (PyCFunction)spoolss_deleteprinterdriver, + METH_VARARGS | METH_KEYWORDS, "" }, + + { "deleteprinterdriverex", (PyCFunction)spoolss_deleteprinterdriverex, + METH_VARARGS | METH_KEYWORDS, "" }, + { NULL } }; @@ -243,6 +257,14 @@ Set the form given by the dictionary argument. METH_VARARGS | METH_KEYWORDS, "Enumerate printer data." }, + { "deleteprinterdata", (PyCFunction)spoolss_deleteprinterdata, + METH_VARARGS | METH_KEYWORDS, + "Delete printer data." }, + + { "deleteprinterdataex", (PyCFunction)spoolss_deleteprinterdataex, + METH_VARARGS | METH_KEYWORDS, + "Delete printer data." }, + { NULL } }; -- cgit From 130d8ec7b04d067ae6b69e2777463c713474de6e Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Wed, 15 May 2002 05:59:12 +0000 Subject: Implement py_to_DRIVER_INFO_3() (This used to be commit ced14ea913b55c87a8dd177080e711cfc16935c3) --- source3/python/py_spoolss_drivers_conv.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'source3/python') diff --git a/source3/python/py_spoolss_drivers_conv.c b/source3/python/py_spoolss_drivers_conv.c index 70a57a1357..0eaf605cbe 100644 --- a/source3/python/py_spoolss_drivers_conv.c +++ b/source3/python/py_spoolss_drivers_conv.c @@ -111,7 +111,11 @@ BOOL py_from_DRIVER_INFO_3(PyObject **dict, DRIVER_INFO_3 *info) BOOL py_to_DRIVER_INFO_3(DRIVER_INFO_3 *info, PyObject *dict) { - return False; + PyObject *obj; + + to_struct(info, dict, py_DRIVER_INFO_3); + + return True; } BOOL py_from_DRIVER_INFO_6(PyObject **dict, DRIVER_INFO_6 *info) -- cgit From c0c95a271afffd4e9748d618495d45bee413222f Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Wed, 15 May 2002 06:03:09 +0000 Subject: Return a dictionary of printer drivers in enumprinterdrivers() instead of a list. Started addprinterdriver() - doesn't work yet. Added stubs for deleteprinterdriver routines. (This used to be commit e3c27d7d1093743124cad573e781547a9a2f659f) --- source3/python/py_spoolss_drivers.c | 146 ++++++++++++++++++++++++++++++++++-- 1 file changed, 138 insertions(+), 8 deletions(-) (limited to 'source3/python') diff --git a/source3/python/py_spoolss_drivers.c b/source3/python/py_spoolss_drivers.c index b612e139f3..d4855c58a8 100644 --- a/source3/python/py_spoolss_drivers.c +++ b/source3/python/py_spoolss_drivers.c @@ -66,47 +66,91 @@ PyObject *spoolss_enumprinterdrivers(PyObject *self, PyObject *args, if (!W_ERROR_IS_OK(werror)) { PyErr_SetObject(spoolss_werror, py_werror_tuple(werror)); - return NULL; + goto done; } /* Return value */ switch (level) { case 1: - result = PyList_New(num_drivers); + 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]); - PyList_SetItem(result, i, value); + + PyDict_SetItemString( + value, "level", PyInt_FromLong(1)); + + PyDict_SetItemString(result, name, value); } break; case 2: - result = PyList_New(num_drivers); + 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]); - PyList_SetItem(result, i, value); + + 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 = PyList_New(num_drivers); + 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: - result = Py_None; + PyErr_SetString(spoolss_error, "unknown info level returned"); + result = NULL; break; } @@ -245,23 +289,109 @@ PyObject *spoolss_getprinterdriverdir(PyObject *self, PyObject *args, PyObject *spoolss_addprinterdriver(PyObject *self, PyObject *args, PyObject *kw) { - return NULL; + static char *kwlist[] = { "server", "info", "creds", NULL }; + char *server; + uint32 level; + PyObject *info, *result = NULL, *creds = NULL, *level_obj; + WERROR werror; + TALLOC_CTX *mem_ctx; + struct cli_state *cli; + PRINTER_DRIVER_CTR ctr; + union { + DRIVER_INFO_3 driver_3; + } dinfo; + + if (!PyArg_ParseTupleAndKeywords( + args, kw, "sO!|O!", kwlist, &server, &PyDict_Type, + &info, &PyDict_Type, &creds)) + return NULL; + + if (server[0] == '\\' && server[1] == '\\') + server += 2; + + mem_ctx = talloc_init(); + + if (!(cli = open_pipe_creds(server, creds, cli_spoolss_initialise, + NULL))) + goto done; + + if ((level_obj = PyDict_GetItemString(info, "level"))) { + + if (!PyInt_Check(level_obj)) { + PyErr_SetString(spoolss_error, + "level not an integer"); + goto done; + } + + level = PyInt_AsLong(level_obj); + + /* Only level 2, 3 supported by NT */ + + if (level != 3) { + PyErr_SetString(spoolss_error, + "unsupported info level"); + goto done; + } + + } else { + PyErr_SetString(spoolss_error, "no info level present"); + 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: + cli_shutdown(cli); + 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; } -- cgit From fb986ce8ae04f89275b204a40186fccdc8f13869 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Wed, 15 May 2002 06:05:00 +0000 Subject: Comment that deleteprinterdataex isn't supported by a samba server. (This used to be commit c07d583327fa194547d1bd41fdb12b25f24e88f7) --- source3/python/py_spoolss_printerdata.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'source3/python') diff --git a/source3/python/py_spoolss_printerdata.c b/source3/python/py_spoolss_printerdata.c index c22eaa2239..0252b0e3ab 100644 --- a/source3/python/py_spoolss_printerdata.c +++ b/source3/python/py_spoolss_printerdata.c @@ -227,4 +227,8 @@ PyObject *spoolss_deleteprinterdata(PyObject *self, PyObject *args, PyObject *kw PyObject *spoolss_deleteprinterdataex(PyObject *self, PyObject *args, PyObject *kw) { + /* Not supported by Samba server */ + + PyErr_SetString(spoolss_error, "Not implemented"); + return NULL; } -- cgit From 7c0ff78f3ede35823121109110a6dd610680c024 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Wed, 15 May 2002 06:09:47 +0000 Subject: Fixed a memory leak in enumprinters. Started addprinterex() - doesn't work yet. (This used to be commit b56bf8f43efbb356ecacf13b96cee7f07386d83d) --- source3/python/py_spoolss_printers.c | 61 +++++++++++++++++++++++++++++++++--- 1 file changed, 57 insertions(+), 4 deletions(-) (limited to 'source3/python') diff --git a/source3/python/py_spoolss_printers.c b/source3/python/py_spoolss_printers.c index d20b144502..79e4d95fb8 100644 --- a/source3/python/py_spoolss_printers.c +++ b/source3/python/py_spoolss_printers.c @@ -279,8 +279,8 @@ PyObject *spoolss_enumprinters(PyObject *self, PyObject *args, PyObject *kw) uint32 needed, num_printers; static char *kwlist[] = {"server", "name", "level", "flags", "creds", NULL}; - TALLOC_CTX *mem_ctx = NULL; - struct cli_state *cli = NULL; + TALLOC_CTX *mem_ctx; + struct cli_state *cli; char *server, *name = NULL; /* Parse parameters */ @@ -311,7 +311,8 @@ PyObject *spoolss_enumprinters(PyObject *self, PyObject *args, PyObject *kw) if (!W_ERROR_IS_OK(werror)) { PyErr_SetObject(spoolss_werror, py_werror_tuple(werror)); - return NULL; + result = NULL; + goto done; } result = PyList_New(num_printers); @@ -359,6 +360,58 @@ PyObject *spoolss_enumprinters(PyObject *self, PyObject *args, PyObject *kw) break; } - Py_INCREF(result); +done: + cli_shutdown(cli); + 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; + 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, + cli_spoolss_initialise, NULL))) + goto done; + + mem_ctx = talloc_init(); + + if (!(cli = open_pipe_creds(server, creds, cli_spoolss_initialise, + NULL))) + 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: + cli_shutdown(cli); + talloc_destroy(mem_ctx); + return result; } -- cgit From dfd19535421fbcc26c852a54b94b207cfa667441 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Wed, 15 May 2002 06:10:45 +0000 Subject: Method entry for addprinterex() (This used to be commit 1ad82cd0c3f76a629b8fc2e1b02e57b8e97829dd) --- source3/python/py_spoolss.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'source3/python') diff --git a/source3/python/py_spoolss.c b/source3/python/py_spoolss.c index 68d5ded99a..b88c6cdeef 100644 --- a/source3/python/py_spoolss.c +++ b/source3/python/py_spoolss.c @@ -73,6 +73,9 @@ Example: >>> spoolss.closeprinter(hnd) "}, + { "addprinterex", spoolss_addprinterex, METH_VARARGS, + "addprinterex()"}, + /* Server enumeratation functions */ { "enumprinters", (PyCFunction)spoolss_enumprinters, -- cgit From c4d0a4c5f816bc8ac6fa258433400ae23163f4d1 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Wed, 15 May 2002 06:11:52 +0000 Subject: make proto (This used to be commit 4fe9f83998a3b669b2190b0c71908fe2d9f915fd) --- source3/python/py_spoolss_proto.h | 1 + 1 file changed, 1 insertion(+) (limited to 'source3/python') diff --git a/source3/python/py_spoolss_proto.h b/source3/python/py_spoolss_proto.h index 89788faa36..bef9fe350e 100644 --- a/source3/python/py_spoolss_proto.h +++ b/source3/python/py_spoolss_proto.h @@ -99,6 +99,7 @@ PyObject *spoolss_closeprinter(PyObject *self, PyObject *args); PyObject *spoolss_getprinter(PyObject *self, PyObject *args, PyObject *kw); PyObject *spoolss_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 */ -- cgit From 5951e762d564de31938cf9d18dd3a8abff2b5983 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Wed, 15 May 2002 06:22:53 +0000 Subject: Renamed functions that are methods of a printer handle object from spoolss_* to spoolss_hnd_* to make things a bit clearer. (This used to be commit 986d868837350e9b107c147e649f139fd7d881f0) --- source3/python/py_spoolss.c | 44 ++++++++++++++++----------------- source3/python/py_spoolss_drivers.c | 2 +- source3/python/py_spoolss_forms.c | 10 ++++---- source3/python/py_spoolss_jobs.c | 16 ++++++------ source3/python/py_spoolss_printerdata.c | 10 ++++---- source3/python/py_spoolss_printers.c | 4 +-- source3/python/py_spoolss_proto.h | 42 +++++++++++++++---------------- 7 files changed, 64 insertions(+), 64 deletions(-) (limited to 'source3/python') diff --git a/source3/python/py_spoolss.c b/source3/python/py_spoolss.c index b88c6cdeef..72f3329c08 100644 --- a/source3/python/py_spoolss.c +++ b/source3/python/py_spoolss.c @@ -73,7 +73,7 @@ Example: >>> spoolss.closeprinter(hnd) "}, - { "addprinterex", spoolss_addprinterex, METH_VARARGS, + { "addprinterex", (PyCFunction)spoolss_addprinterex, METH_VARARGS, "addprinterex()"}, /* Server enumeratation functions */ @@ -154,7 +154,7 @@ static PyMethodDef spoolss_hnd_methods[] = { /* Printer info */ - { "getprinter", (PyCFunction)spoolss_getprinter, + { "getprinter", (PyCFunction)spoolss_hnd_getprinter, METH_VARARGS | METH_KEYWORDS, "getprinter([level]) -> dict @@ -168,7 +168,7 @@ Example: 'flags': 8388608} "}, - { "setprinter", (PyCFunction)spoolss_setprinter, + { "setprinter", (PyCFunction)spoolss_hnd_setprinter, METH_VARARGS | METH_KEYWORDS, "setprinter(dict) -> None @@ -177,7 +177,7 @@ Set printer information. /* Printer drivers */ - { "getprinterdriver", (PyCFunction)spoolss_getprinterdriver, + { "getprinterdriver", (PyCFunction)spoolss_hnd_getprinterdriver, METH_VARARGS | METH_KEYWORDS, "getprinterdriver([level = 1, arch = \"Windows NT x86\"] -> dict @@ -186,85 +186,85 @@ Return a dictionary of printer driver information. /* Forms */ - { "enumforms", (PyCFunction)spoolss_enumforms, + { "enumforms", (PyCFunction)spoolss_hnd_enumforms, METH_VARARGS | METH_KEYWORDS, "enumforms([level = 1]) -> list Return a list of forms supported by a printer. "}, - { "setform", (PyCFunction)spoolss_setform, + { "setform", (PyCFunction)spoolss_hnd_setform, METH_VARARGS | METH_KEYWORDS, "setform(dict) -> None Set the form given by the dictionary argument. "}, - { "addform", (PyCFunction)spoolss_addform, + { "addform", (PyCFunction)spoolss_hnd_addform, METH_VARARGS | METH_KEYWORDS, "Insert a form" }, - { "getform", (PyCFunction)spoolss_getform, + { "getform", (PyCFunction)spoolss_hnd_getform, METH_VARARGS | METH_KEYWORDS, "Fetch form properties" }, - { "deleteform", (PyCFunction)spoolss_deleteform, + { "deleteform", (PyCFunction)spoolss_hnd_deleteform, METH_VARARGS | METH_KEYWORDS, "Delete a form" }, /* Job related methods */ - { "enumjobs", (PyCFunction)spoolss_enumjobs, + { "enumjobs", (PyCFunction)spoolss_hnd_enumjobs, METH_VARARGS | METH_KEYWORDS, "Enumerate jobs" }, - { "setjob", (PyCFunction)spoolss_setjob, + { "setjob", (PyCFunction)spoolss_hnd_setjob, METH_VARARGS | METH_KEYWORDS, "Set job information" }, - { "getjob", (PyCFunction)spoolss_getjob, + { "getjob", (PyCFunction)spoolss_hnd_getjob, METH_VARARGS | METH_KEYWORDS, "Get job information" }, - { "startpageprinter", (PyCFunction)spoolss_startpageprinter, + { "startpageprinter", (PyCFunction)spoolss_hnd_startpageprinter, METH_VARARGS | METH_KEYWORDS, "Notify spooler that a page is about to be printed." }, - { "endpageprinter", (PyCFunction)spoolss_endpageprinter, + { "endpageprinter", (PyCFunction)spoolss_hnd_endpageprinter, METH_VARARGS | METH_KEYWORDS, "Notify spooler that a page is about to be printed." }, - { "startdocprinter", (PyCFunction)spoolss_startdocprinter, + { "startdocprinter", (PyCFunction)spoolss_hnd_startdocprinter, METH_VARARGS | METH_KEYWORDS, "Notify spooler that a document is about to be printed." }, - { "enddocprinter", (PyCFunction)spoolss_enddocprinter, + { "enddocprinter", (PyCFunction)spoolss_hnd_enddocprinter, METH_VARARGS | METH_KEYWORDS, "Notify spooler that a document is about to be printed." }, - { "writeprinter", (PyCFunction)spoolss_writeprinter, + { "writeprinter", (PyCFunction)spoolss_hnd_writeprinter, METH_VARARGS | METH_KEYWORDS, "Write job data to a printer." }, /* Printer data */ - { "getprinterdata", (PyCFunction)spoolss_getprinterdata, + { "getprinterdata", (PyCFunction)spoolss_hnd_getprinterdata, METH_VARARGS | METH_KEYWORDS, "Get printer data." }, - { "setprinterdata", (PyCFunction)spoolss_setprinterdata, + { "setprinterdata", (PyCFunction)spoolss_hnd_setprinterdata, METH_VARARGS | METH_KEYWORDS, "Set printer data." }, - { "enumprinterdata", (PyCFunction)spoolss_enumprinterdata, + { "enumprinterdata", (PyCFunction)spoolss_hnd_enumprinterdata, METH_VARARGS | METH_KEYWORDS, "Enumerate printer data." }, - { "deleteprinterdata", (PyCFunction)spoolss_deleteprinterdata, + { "deleteprinterdata", (PyCFunction)spoolss_hnd_deleteprinterdata, METH_VARARGS | METH_KEYWORDS, "Delete printer data." }, - { "deleteprinterdataex", (PyCFunction)spoolss_deleteprinterdataex, + { "deleteprinterdataex", (PyCFunction)spoolss_hnd_deleteprinterdataex, METH_VARARGS | METH_KEYWORDS, "Delete printer data." }, diff --git a/source3/python/py_spoolss_drivers.c b/source3/python/py_spoolss_drivers.c index d4855c58a8..088dc54576 100644 --- a/source3/python/py_spoolss_drivers.c +++ b/source3/python/py_spoolss_drivers.c @@ -167,7 +167,7 @@ PyObject *spoolss_enumprinterdrivers(PyObject *self, PyObject *args, /* Fetch printer driver */ -PyObject *spoolss_getprinterdriver(PyObject *self, PyObject *args, +PyObject *spoolss_hnd_getprinterdriver(PyObject *self, PyObject *args, PyObject *kw) { spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self; diff --git a/source3/python/py_spoolss_forms.c b/source3/python/py_spoolss_forms.c index fbe3240c15..83cdf9badd 100644 --- a/source3/python/py_spoolss_forms.c +++ b/source3/python/py_spoolss_forms.c @@ -22,7 +22,7 @@ /* Add a form */ -PyObject *spoolss_addform(PyObject *self, PyObject *args, PyObject *kw) +PyObject *spoolss_hnd_addform(PyObject *self, PyObject *args, PyObject *kw) { spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self; WERROR werror; @@ -71,7 +71,7 @@ PyObject *spoolss_addform(PyObject *self, PyObject *args, PyObject *kw) /* Get form properties */ -PyObject *spoolss_getform(PyObject *self, PyObject *args, PyObject *kw) +PyObject *spoolss_hnd_getform(PyObject *self, PyObject *args, PyObject *kw) { spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self; WERROR werror; @@ -117,7 +117,7 @@ PyObject *spoolss_getform(PyObject *self, PyObject *args, PyObject *kw) /* Set form properties */ -PyObject *spoolss_setform(PyObject *self, PyObject *args, PyObject *kw) +PyObject *spoolss_hnd_setform(PyObject *self, PyObject *args, PyObject *kw) { spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self; WERROR werror; @@ -158,7 +158,7 @@ PyObject *spoolss_setform(PyObject *self, PyObject *args, PyObject *kw) /* Delete a form */ -PyObject *spoolss_deleteform(PyObject *self, PyObject *args, PyObject *kw) +PyObject *spoolss_hnd_deleteform(PyObject *self, PyObject *args, PyObject *kw) { spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self; WERROR werror; @@ -187,7 +187,7 @@ PyObject *spoolss_deleteform(PyObject *self, PyObject *args, PyObject *kw) /* Enumerate forms */ -PyObject *spoolss_enumforms(PyObject *self, PyObject *args, PyObject *kw) +PyObject *spoolss_hnd_enumforms(PyObject *self, PyObject *args, PyObject *kw) { PyObject *result; spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self; diff --git a/source3/python/py_spoolss_jobs.c b/source3/python/py_spoolss_jobs.c index 6951ebab9a..3a02cdac68 100644 --- a/source3/python/py_spoolss_jobs.c +++ b/source3/python/py_spoolss_jobs.c @@ -22,7 +22,7 @@ /* Enumerate jobs */ -PyObject *spoolss_enumjobs(PyObject *self, PyObject *args, PyObject *kw) +PyObject *spoolss_hnd_enumjobs(PyObject *self, PyObject *args, PyObject *kw) { spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self; WERROR werror; @@ -87,7 +87,7 @@ PyObject *spoolss_enumjobs(PyObject *self, PyObject *args, PyObject *kw) /* Set job command */ -PyObject *spoolss_setjob(PyObject *self, PyObject *args, PyObject *kw) +PyObject *spoolss_hnd_setjob(PyObject *self, PyObject *args, PyObject *kw) { spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self; WERROR werror; @@ -116,7 +116,7 @@ PyObject *spoolss_setjob(PyObject *self, PyObject *args, PyObject *kw) /* Get job */ -PyObject *spoolss_getjob(PyObject *self, PyObject *args, PyObject *kw) +PyObject *spoolss_hnd_getjob(PyObject *self, PyObject *args, PyObject *kw) { spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self; WERROR werror; @@ -161,7 +161,7 @@ PyObject *spoolss_getjob(PyObject *self, PyObject *args, PyObject *kw) /* Start page printer. This notifies the spooler that a page is about to be printed on the specified printer. */ -PyObject *spoolss_startpageprinter(PyObject *self, PyObject *args, PyObject *kw) +PyObject *spoolss_hnd_startpageprinter(PyObject *self, PyObject *args, PyObject *kw) { spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self; WERROR werror; @@ -189,7 +189,7 @@ PyObject *spoolss_startpageprinter(PyObject *self, PyObject *args, PyObject *kw) /* End page printer. This notifies the spooler that a page has finished being printed on the specified printer. */ -PyObject *spoolss_endpageprinter(PyObject *self, PyObject *args, PyObject *kw) +PyObject *spoolss_hnd_endpageprinter(PyObject *self, PyObject *args, PyObject *kw) { spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self; WERROR werror; @@ -217,7 +217,7 @@ PyObject *spoolss_endpageprinter(PyObject *self, PyObject *args, PyObject *kw) /* Start doc printer. This notifies the spooler that a document is about to be printed on the specified printer. */ -PyObject *spoolss_startdocprinter(PyObject *self, PyObject *args, PyObject *kw) +PyObject *spoolss_hnd_startdocprinter(PyObject *self, PyObject *args, PyObject *kw) { spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self; WERROR werror; @@ -326,7 +326,7 @@ PyObject *spoolss_startdocprinter(PyObject *self, PyObject *args, PyObject *kw) /* End doc printer. This notifies the spooler that a document has finished being printed on the specified printer. */ -PyObject *spoolss_enddocprinter(PyObject *self, PyObject *args, PyObject *kw) +PyObject *spoolss_hnd_enddocprinter(PyObject *self, PyObject *args, PyObject *kw) { spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self; WERROR werror; @@ -352,7 +352,7 @@ PyObject *spoolss_enddocprinter(PyObject *self, PyObject *args, PyObject *kw) /* Write data to a printer */ -PyObject *spoolss_writeprinter(PyObject *self, PyObject *args, PyObject *kw) +PyObject *spoolss_hnd_writeprinter(PyObject *self, PyObject *args, PyObject *kw) { spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self; WERROR werror; diff --git a/source3/python/py_spoolss_printerdata.c b/source3/python/py_spoolss_printerdata.c index 0252b0e3ab..24e2340059 100644 --- a/source3/python/py_spoolss_printerdata.c +++ b/source3/python/py_spoolss_printerdata.c @@ -87,7 +87,7 @@ static BOOL py_to_printerdata(char **value, uint32 *data_type, return True; } -PyObject *spoolss_getprinterdata(PyObject *self, PyObject *args, PyObject *kw) +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 }; @@ -123,7 +123,7 @@ PyObject *spoolss_getprinterdata(PyObject *self, PyObject *args, PyObject *kw) return result; } -PyObject *spoolss_setprinterdata(PyObject *self, PyObject *args, PyObject *kw) +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 }; @@ -154,7 +154,7 @@ PyObject *spoolss_setprinterdata(PyObject *self, PyObject *args, PyObject *kw) return Py_None; } -PyObject *spoolss_enumprinterdata(PyObject *self, PyObject *args, PyObject *kw) +PyObject *spoolss_hnd_enumprinterdata(PyObject *self, PyObject *args, PyObject *kw) { spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self; static char *kwlist[] = { NULL }; @@ -199,7 +199,7 @@ PyObject *spoolss_enumprinterdata(PyObject *self, PyObject *args, PyObject *kw) return result; } -PyObject *spoolss_deleteprinterdata(PyObject *self, PyObject *args, PyObject *kw) +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 }; @@ -225,7 +225,7 @@ PyObject *spoolss_deleteprinterdata(PyObject *self, PyObject *args, PyObject *kw return Py_None; } -PyObject *spoolss_deleteprinterdataex(PyObject *self, PyObject *args, PyObject *kw) +PyObject *spoolss_hnd_deleteprinterdataex(PyObject *self, PyObject *args, PyObject *kw) { /* Not supported by Samba server */ diff --git a/source3/python/py_spoolss_printers.c b/source3/python/py_spoolss_printers.c index 79e4d95fb8..164ba974b9 100644 --- a/source3/python/py_spoolss_printers.c +++ b/source3/python/py_spoolss_printers.c @@ -110,7 +110,7 @@ PyObject *spoolss_closeprinter(PyObject *self, PyObject *args) /* Fetch printer information */ -PyObject *spoolss_getprinter(PyObject *self, PyObject *args, PyObject *kw) +PyObject *spoolss_hnd_getprinter(PyObject *self, PyObject *args, PyObject *kw) { spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self; WERROR werror; @@ -176,7 +176,7 @@ PyObject *spoolss_getprinter(PyObject *self, PyObject *args, PyObject *kw) /* Set printer information */ -PyObject *spoolss_setprinter(PyObject *self, PyObject *args, PyObject *kw) +PyObject *spoolss_hnd_setprinter(PyObject *self, PyObject *args, PyObject *kw) { spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self; WERROR werror; diff --git a/source3/python/py_spoolss_proto.h b/source3/python/py_spoolss_proto.h index bef9fe350e..ae990433d6 100644 --- a/source3/python/py_spoolss_proto.h +++ b/source3/python/py_spoolss_proto.h @@ -14,7 +14,7 @@ void initspoolss(void); PyObject *spoolss_enumprinterdrivers(PyObject *self, PyObject *args, PyObject *kw); -PyObject *spoolss_getprinterdriver(PyObject *self, PyObject *args, +PyObject *spoolss_hnd_getprinterdriver(PyObject *self, PyObject *args, PyObject *kw); PyObject *spoolss_getprinterdriverdir(PyObject *self, PyObject *args, PyObject *kw); @@ -42,11 +42,11 @@ BOOL py_to_DRIVER_DIRECTORY_1(DRIVER_DIRECTORY_1 *info, PyObject *dict); /* The following definitions come from python/py_spoolss_forms.c */ -PyObject *spoolss_addform(PyObject *self, PyObject *args, PyObject *kw); -PyObject *spoolss_getform(PyObject *self, PyObject *args, PyObject *kw); -PyObject *spoolss_setform(PyObject *self, PyObject *args, PyObject *kw); -PyObject *spoolss_deleteform(PyObject *self, PyObject *args, PyObject *kw); -PyObject *spoolss_enumforms(PyObject *self, PyObject *args, PyObject *kw); +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 */ @@ -55,14 +55,14 @@ BOOL py_to_FORM(FORM *form, PyObject *dict); /* The following definitions come from python/py_spoolss_jobs.c */ -PyObject *spoolss_enumjobs(PyObject *self, PyObject *args, PyObject *kw); -PyObject *spoolss_setjob(PyObject *self, PyObject *args, PyObject *kw); -PyObject *spoolss_getjob(PyObject *self, PyObject *args, PyObject *kw); -PyObject *spoolss_startpageprinter(PyObject *self, PyObject *args, PyObject *kw); -PyObject *spoolss_endpageprinter(PyObject *self, PyObject *args, PyObject *kw); -PyObject *spoolss_startdocprinter(PyObject *self, PyObject *args, PyObject *kw); -PyObject *spoolss_enddocprinter(PyObject *self, PyObject *args, PyObject *kw); -PyObject *spoolss_writeprinter(PyObject *self, PyObject *args, PyObject *kw); +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); /* The following definitions come from python/py_spoolss_jobs_conv.c */ @@ -86,18 +86,18 @@ BOOL py_to_PORT_INFO_2(PORT_INFO_2 *info, PyObject *dict); /* The following definitions come from python/py_spoolss_printerdata.c */ -PyObject *spoolss_getprinterdata(PyObject *self, PyObject *args, PyObject *kw); -PyObject *spoolss_setprinterdata(PyObject *self, PyObject *args, PyObject *kw); -PyObject *spoolss_enumprinterdata(PyObject *self, PyObject *args, PyObject *kw); -PyObject *spoolss_deleteprinterdata(PyObject *self, PyObject *args, PyObject *kw); -PyObject *spoolss_deleteprinterdataex(PyObject *self, PyObject *args, PyObject *kw); +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_getprinter(PyObject *self, PyObject *args, PyObject *kw); -PyObject *spoolss_setprinter(PyObject *self, PyObject *args, PyObject *kw); +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); -- cgit From 932b8e9d40e620c166da907d48ae571e5d73db6a Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Thu, 16 May 2002 01:33:38 +0000 Subject: Cleaned up help docstrings. (This used to be commit a8fcb151f8ff601774c302b61e694b4522461068) --- source3/python/py_spoolss.c | 121 ++++++++++++++++++++++++-------------------- 1 file changed, 67 insertions(+), 54 deletions(-) (limited to 'source3/python') diff --git a/source3/python/py_spoolss.c b/source3/python/py_spoolss.c index 72f3329c08..fde8b1efbd 100644 --- a/source3/python/py_spoolss.c +++ b/source3/python/py_spoolss.c @@ -51,27 +51,22 @@ static PyMethodDef spoolss_methods[] = { /* Open/close printer handles */ { "openprinter", (PyCFunction)spoolss_openprinter, METH_VARARGS | METH_KEYWORDS, - "openprinter(printername, [creds, access]) -> + "Open a printer by name in UNC format. -Open a printer given by printername 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. +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\") -"}, +>>> hnd = spoolss.openprinter(\"\\\\\\\\NPSD-PDC2\\\\meanie\")"}, { "closeprinter", spoolss_closeprinter, METH_VARARGS, - "closeprinter() - -Close a printer handle opened with openprinter or addprinter. + "Close a printer handle opened with openprinter or addprinter. Example: ->>> spoolss.closeprinter(hnd) -"}, +>>> spoolss.closeprinter(hnd)"}, { "addprinterex", (PyCFunction)spoolss_addprinterex, METH_VARARGS, "addprinterex()"}, @@ -80,7 +75,7 @@ Example: { "enumprinters", (PyCFunction)spoolss_enumprinters, METH_VARARGS | METH_KEYWORDS, - "enumprinters(server, [creds, level, flags]) -> list + "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. @@ -91,12 +86,11 @@ Example: [{'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,'}] -"}, + 'description': 'fileprint,Generic / Text Only,'}]"}, { "enumports", (PyCFunction)spoolss_enumports, METH_VARARGS | METH_KEYWORDS, - "enumports(server, [creds, level]) -> list + "Enumerate ports on a print server. Return a list of ports on a print server. @@ -104,46 +98,71 @@ Example: >>> print spoolss.enumports(\"\\\\\\\\npsd-pdc2\") [{'name': 'LPT1:'}, {'name': 'LPT2:'}, {'name': 'COM1:'}, {'name': 'COM2:'}, - {'name': 'FILE:'}, {'name': '\\\\nautilus1\\zpekt3r'}] -"}, + {'name': 'FILE:'}, {'name': '\\\\nautilus1\\zpekt3r'}]"}, { "enumprinterdrivers", (PyCFunction)spoolss_enumprinterdrivers, METH_VARARGS | METH_KEYWORDS, - "enumprinterdrivers(server, [creds, level, arch]) -> list + "Enumerate printer drivers on a print server. -Return a list of printer drivers. -"}, +Return a list of printer drivers."}, /* Miscellaneous other commands */ - { "getprinterdriverdir", (PyCFunction)spoolss_getprinterdriverdir, METH_VARARGS | - METH_KEYWORDS, "getprinterdriverdir(server, [creds]) -> string + { "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\". -"}, +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, "" }, + 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: - { "get_debuglevel", (PyCFunction)get_debuglevel, METH_VARARGS, "" }, - { "set_debuglevel", (PyCFunction)set_debuglevel, METH_VARARGS, "" }, +>>> 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, "" }, + METH_VARARGS | METH_KEYWORDS, + "Add a printer driver." }, { "addprinterdriverex", (PyCFunction)spoolss_addprinterdriverex, - METH_VARARGS | METH_KEYWORDS, "" }, + METH_VARARGS | METH_KEYWORDS, + "Add a printer driver." }, { "deleteprinterdriver", (PyCFunction)spoolss_deleteprinterdriver, - METH_VARARGS | METH_KEYWORDS, "" }, + METH_VARARGS | METH_KEYWORDS, + "Delete a printer driver." }, { "deleteprinterdriverex", (PyCFunction)spoolss_deleteprinterdriverex, - METH_VARARGS | METH_KEYWORDS, "" }, + METH_VARARGS | METH_KEYWORDS, + "Delete a printer driver." }, { NULL } }; @@ -156,7 +175,7 @@ static PyMethodDef spoolss_hnd_methods[] = { { "getprinter", (PyCFunction)spoolss_hnd_getprinter, METH_VARARGS | METH_KEYWORDS, - "getprinter([level]) -> dict + "Get printer information. Return a dictionary of print information. The info level defaults to 1. @@ -165,66 +184,60 @@ 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} -"}, + 'flags': 8388608}"}, { "setprinter", (PyCFunction)spoolss_hnd_setprinter, METH_VARARGS | METH_KEYWORDS, - "setprinter(dict) -> None - -Set printer information. -"}, + "Set printer information."}, /* Printer drivers */ { "getprinterdriver", (PyCFunction)spoolss_hnd_getprinterdriver, METH_VARARGS | METH_KEYWORDS, - "getprinterdriver([level = 1, arch = \"Windows NT x86\"] -> dict + "Return printer driver information. -Return a dictionary of 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, - "enumforms([level = 1]) -> list + "Enumerate supported forms. -Return a list of forms supported by a printer. -"}, +Return a list of forms supported by this printer or print server."}, { "setform", (PyCFunction)spoolss_hnd_setform, METH_VARARGS | METH_KEYWORDS, - "setform(dict) -> None + "Set form data. -Set the form given by the dictionary argument. -"}, +Set the form given by the dictionary argument."}, { "addform", (PyCFunction)spoolss_hnd_addform, METH_VARARGS | METH_KEYWORDS, - "Insert a form" }, + "Add a new form." }, { "getform", (PyCFunction)spoolss_hnd_getform, METH_VARARGS | METH_KEYWORDS, - "Fetch form properties" }, + "Get form properties." }, { "deleteform", (PyCFunction)spoolss_hnd_deleteform, METH_VARARGS | METH_KEYWORDS, - "Delete a form" }, + "Delete a form." }, /* Job related methods */ { "enumjobs", (PyCFunction)spoolss_hnd_enumjobs, METH_VARARGS | METH_KEYWORDS, - "Enumerate jobs" }, + "Enumerate jobs." }, { "setjob", (PyCFunction)spoolss_hnd_setjob, METH_VARARGS | METH_KEYWORDS, - "Set job information" }, + "Set job information." }, { "getjob", (PyCFunction)spoolss_hnd_getjob, METH_VARARGS | METH_KEYWORDS, - "Get job information" }, + "Get job information." }, { "startpageprinter", (PyCFunction)spoolss_hnd_startpageprinter, METH_VARARGS | METH_KEYWORDS, -- cgit From ea8c45bbfd31151e91c1c57a162f255e706ca859 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Thu, 16 May 2002 02:01:23 +0000 Subject: Added addjob command. (This used to be commit e4cc7e2d521cb2777c15c00ec222342e2a0b02ca) --- source3/python/py_spoolss.c | 8 ++++++-- source3/python/py_spoolss_jobs.c | 6 ++++++ source3/python/py_spoolss_proto.h | 1 + 3 files changed, 13 insertions(+), 2 deletions(-) (limited to 'source3/python') diff --git a/source3/python/py_spoolss.c b/source3/python/py_spoolss.c index fde8b1efbd..95be77de55 100644 --- a/source3/python/py_spoolss.c +++ b/source3/python/py_spoolss.c @@ -144,10 +144,10 @@ Example: Example: ->>> spoolss.set_debuglevel(10)" +>>> spoolss.set_debuglevel(10)" }, /* Printer driver routines */ - + { "addprinterdriver", (PyCFunction)spoolss_addprinterdriver, METH_VARARGS | METH_KEYWORDS, "Add a printer driver." }, @@ -259,6 +259,10 @@ Set the form given by the dictionary argument."}, 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, diff --git a/source3/python/py_spoolss_jobs.c b/source3/python/py_spoolss_jobs.c index 3a02cdac68..d98fdba137 100644 --- a/source3/python/py_spoolss_jobs.c +++ b/source3/python/py_spoolss_jobs.c @@ -380,3 +380,9 @@ PyObject *spoolss_hnd_writeprinter(PyObject *self, PyObject *args, PyObject *kw) 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_proto.h b/source3/python/py_spoolss_proto.h index ae990433d6..b197003c79 100644 --- a/source3/python/py_spoolss_proto.h +++ b/source3/python/py_spoolss_proto.h @@ -63,6 +63,7 @@ PyObject *spoolss_hnd_endpageprinter(PyObject *self, PyObject *args, PyObject *k 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 */ -- cgit From ce03ce2e5629930e582f9fd17445e52ce1b08907 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Thu, 16 May 2002 02:24:22 +0000 Subject: Refactored open_pipe_creds() function to remove unused parameter. (This used to be commit 36ed06cb5078429445f3bbb0f69baa2e0f8356a4) --- source3/python/py_common.c | 22 +++++++++++++--------- source3/python/py_common.h | 2 +- source3/python/py_common_proto.h | 3 +-- source3/python/py_lsa.c | 3 +-- source3/python/py_samr.c | 7 +------ source3/python/py_spoolss_drivers.c | 28 ++++++++++++++-------------- source3/python/py_spoolss_ports.c | 2 +- source3/python/py_spoolss_printers.c | 17 ++++++----------- 8 files changed, 38 insertions(+), 46 deletions(-) (limited to 'source3/python') diff --git a/source3/python/py_common.c b/source3/python/py_common.c index 5b80f09498..d286ed68f0 100644 --- a/source3/python/py_common.c +++ b/source3/python/py_common.c @@ -118,16 +118,20 @@ PyObject *py_setup_logging(PyObject *self, PyObject *args, PyObject *kw) return Py_None; } +/* Return a cli_state to a RPC pipe on the given server. Use the + credentials passed if not NULL. Set an exception and return NULL if + there was an error creating the connection. */ + struct cli_state *open_pipe_creds(char *system_name, PyObject *creds, - cli_pipe_fn *connect_fn, - struct cli_state *cli) + cli_pipe_fn *connect_fn) { struct ntuser_creds nt_creds; - + struct cli_state *cli; + + cli = (struct cli_state *)malloc(sizeof(struct cli_state)); if (!cli) { - cli = (struct cli_state *)malloc(sizeof(struct cli_state)); - if (!cli) - return NULL; + PyErr_SetString(PyExc_RuntimeError, "out of memory"); + return NULL; } ZERO_STRUCTP(cli); @@ -151,7 +155,7 @@ struct cli_state *open_pipe_creds(char *system_name, PyObject *creds, password_obj = PyDict_GetItemString(creds, "password"); if (!username_obj || !domain_obj || !password_obj) { - error: + creds_error: /* TODO: Either pass in the exception for the module calling open_pipe_creds() or have a @@ -165,14 +169,14 @@ struct cli_state *open_pipe_creds(char *system_name, PyObject *creds, if (!PyString_Check(username_obj) || !PyString_Check(domain_obj) || !PyString_Check(password_obj)) - goto error; + goto creds_error; username = PyString_AsString(username_obj); domain = PyString_AsString(domain_obj); password = PyString_AsString(password_obj); if (!username || !domain || !password) - goto error; + goto creds_error; /* Initialise nt_creds structure with passed creds */ diff --git a/source3/python/py_common.h b/source3/python/py_common.h index f13224a020..1f5188971d 100644 --- a/source3/python/py_common.h +++ b/source3/python/py_common.h @@ -23,7 +23,7 @@ #include "includes.h" -/* Return a cli_state struct opened on the SPOOLSS pipe. If credentials +/* Return a cli_state struct opened on the specified pipe. If credentials are passed use them. */ typedef struct cli_state *(cli_pipe_fn)( diff --git a/source3/python/py_common_proto.h b/source3/python/py_common_proto.h index bca59689a4..98d970d7bc 100644 --- a/source3/python/py_common_proto.h +++ b/source3/python/py_common_proto.h @@ -13,8 +13,7 @@ PyObject *get_debuglevel(PyObject *self, PyObject *args); PyObject *set_debuglevel(PyObject *self, PyObject *args); PyObject *py_setup_logging(PyObject *self, PyObject *args, PyObject *kw); struct cli_state *open_pipe_creds(char *system_name, PyObject *creds, - cli_pipe_fn *connect_fn, - struct cli_state *cli); + cli_pipe_fn *connect_fn); /* The following definitions come from python/py_ntsec.c */ diff --git a/source3/python/py_lsa.c b/source3/python/py_lsa.c index 23566282f6..cf96928790 100644 --- a/source3/python/py_lsa.c +++ b/source3/python/py_lsa.c @@ -66,8 +66,7 @@ static PyObject *lsa_open_policy(PyObject *self, PyObject *args, &creds, &desired_access)) return NULL; - if (!(cli = open_pipe_creds(server_name, creds, cli_lsa_initialise, - NULL))) { + if (!(cli = open_pipe_creds(server_name, creds, cli_lsa_initialise))) { fprintf(stderr, "could not initialise cli state\n"); return NULL; } diff --git a/source3/python/py_samr.c b/source3/python/py_samr.c index 6c52ebe8cd..66d6266d10 100644 --- a/source3/python/py_samr.c +++ b/source3/python/py_samr.c @@ -287,13 +287,8 @@ static PyObject *samr_connect(PyObject *self, PyObject *args, PyObject *kw) &creds, &desired_access)) return NULL; - if (!(cli = open_pipe_creds(server_name, creds, cli_samr_initialise, - NULL))) { - - /* Error state set in open_pipe_creds() */ - + if (!(cli = open_pipe_creds(server_name, creds, cli_samr_initialise))) goto done; - } if (!(mem_ctx = talloc_init())) { PyErr_SetString(samr_ntstatus, diff --git a/source3/python/py_spoolss_drivers.c b/source3/python/py_spoolss_drivers.c index 088dc54576..416d46f1d2 100644 --- a/source3/python/py_spoolss_drivers.c +++ b/source3/python/py_spoolss_drivers.c @@ -34,7 +34,7 @@ PyObject *spoolss_enumprinterdrivers(PyObject *self, PyObject *args, static char *kwlist[] = {"server", "creds", "level", "arch", NULL}; struct cli_state *cli = NULL; TALLOC_CTX *mem_ctx = NULL; - + /* Parse parameters */ if (!PyArg_ParseTupleAndKeywords(args, kw, "s|O!is", kwlist, @@ -44,8 +44,8 @@ PyObject *spoolss_enumprinterdrivers(PyObject *self, PyObject *args, /* Call rpc function */ - if (!(cli = open_pipe_creds(server_name, creds, - cli_spoolss_initialise, NULL))) { + if (!(cli = open_pipe_creds( + server_name, creds, cli_spoolss_initialise))) { fprintf(stderr, "could not initialise cli state\n"); goto done; } @@ -244,12 +244,12 @@ PyObject *spoolss_getprinterdriverdir(PyObject *self, PyObject *args, /* Call rpc function */ - if (!(cli = open_pipe_creds(server_name, creds, - cli_spoolss_initialise, NULL))) { + if (!(cli = open_pipe_creds( + server_name, creds, cli_spoolss_initialise))) { fprintf(stderr, "could not initialise cli state\n"); goto done; } - + if (!(mem_ctx = talloc_init())) { fprintf(stderr, "unable to initialise talloc context\n"); goto done; @@ -311,8 +311,7 @@ PyObject *spoolss_addprinterdriver(PyObject *self, PyObject *args, mem_ctx = talloc_init(); - if (!(cli = open_pipe_creds(server, creds, cli_spoolss_initialise, - NULL))) + if (!(cli = open_pipe_creds(server, creds, cli_spoolss_initialise))) goto done; if ((level_obj = PyDict_GetItemString(info, "level"))) { @@ -337,9 +336,9 @@ PyObject *spoolss_addprinterdriver(PyObject *self, PyObject *args, PyErr_SetString(spoolss_error, "no info level present"); goto done; } - + ZERO_STRUCT(ctr); - + switch(level) { case 3: ctr.info3 = &dinfo.driver_3; @@ -369,19 +368,20 @@ PyObject *spoolss_addprinterdriver(PyObject *self, PyObject *args, done: cli_shutdown(cli); talloc_destroy(mem_ctx); - + return result; + } PyObject *spoolss_addprinterdriverex(PyObject *self, PyObject *args, - PyObject *kw) + PyObject *kw) { /* Not supported by Samba server */ - + PyErr_SetString(spoolss_error, "Not implemented"); return NULL; } - + PyObject *spoolss_deleteprinterdriver(PyObject *self, PyObject *args, PyObject *kw) { diff --git a/source3/python/py_spoolss_ports.c b/source3/python/py_spoolss_ports.c index 2d73a6e033..8e74017f4a 100644 --- a/source3/python/py_spoolss_ports.c +++ b/source3/python/py_spoolss_ports.c @@ -45,7 +45,7 @@ PyObject *spoolss_enumports(PyObject *self, PyObject *args, PyObject *kw) server += 2; mem_ctx = talloc_init(); - cli = open_pipe_creds(server, creds, cli_spoolss_initialise, NULL); + cli = open_pipe_creds(server, creds, cli_spoolss_initialise); /* Call rpc function */ diff --git a/source3/python/py_spoolss_printers.c b/source3/python/py_spoolss_printers.c index 164ba974b9..36ba22a7c4 100644 --- a/source3/python/py_spoolss_printers.c +++ b/source3/python/py_spoolss_printers.c @@ -50,13 +50,9 @@ PyObject *spoolss_openprinter(PyObject *self, PyObject *args, PyObject *kw) *c = 0; } - if (!(cli = open_pipe_creds(computer_name, creds, - cli_spoolss_initialise, NULL))) { - - /* Error state set in open_pipe_creds() */ - + if (!(cli = open_pipe_creds( + computer_name, creds, cli_spoolss_initialise))) goto done; - } if (!(mem_ctx = talloc_init())) { PyErr_SetString(spoolss_error, @@ -294,7 +290,7 @@ PyObject *spoolss_enumprinters(PyObject *self, PyObject *args, PyObject *kw) server += 2; mem_ctx = talloc_init(); - cli = open_pipe_creds(server, creds, cli_spoolss_initialise, NULL); + cli = open_pipe_creds(server, creds, cli_spoolss_initialise); /* Call rpc function */ @@ -386,14 +382,13 @@ PyObject *spoolss_addprinterex(PyObject *self, PyObject *args, PyObject *kw) &PyDict_Type, &info, &PyDict_Type, &creds)) return NULL; - if (!(cli = open_pipe_creds(server, creds, - cli_spoolss_initialise, NULL))) + if (!(cli = open_pipe_creds( + server, creds, cli_spoolss_initialise))) goto done; mem_ctx = talloc_init(); - if (!(cli = open_pipe_creds(server, creds, cli_spoolss_initialise, - NULL))) + if (!(cli = open_pipe_creds(server, creds, cli_spoolss_initialise))) goto done; if (!py_to_PRINTER_INFO_2(&info2, info, mem_ctx)) { -- cgit From 286d3a80fdcd316ebbf63b007a24e787143313a4 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Thu, 16 May 2002 04:00:31 +0000 Subject: More cleanups. - removed dodgy fprintf() error handling - return an error string from open_pipe_creds() so the appropriate exception can be raised by the caller - reformatting (This used to be commit d35cad359df3bd53e6bb49f6655d4c7b9993abb0) --- source3/python/py_common.c | 43 +++++++--------------- source3/python/py_common_proto.h | 4 +- source3/python/py_lsa.c | 15 +++++--- source3/python/py_samr.c | 12 ++++-- source3/python/py_spoolss_drivers.c | 50 +++++++++++++++---------- source3/python/py_spoolss_forms.c | 9 +++-- source3/python/py_spoolss_jobs.c | 16 ++++---- source3/python/py_spoolss_ports.c | 22 ++++++++--- source3/python/py_spoolss_printerdata.c | 8 ++-- source3/python/py_spoolss_printers.c | 65 ++++++++++++++++++++------------- source3/python/py_spoolss_proto.h | 2 +- 11 files changed, 137 insertions(+), 109 deletions(-) (limited to 'source3/python') diff --git a/source3/python/py_common.c b/source3/python/py_common.c index d286ed68f0..61eacced27 100644 --- a/source3/python/py_common.c +++ b/source3/python/py_common.c @@ -95,8 +95,8 @@ PyObject *py_setup_logging(PyObject *self, PyObject *args, PyObject *kw) char *logfilename = NULL; static char *kwlist[] = {"interactive", "logfilename", NULL}; - if (!PyArg_ParseTupleAndKeywords(args, kw, "|is", kwlist, - &interactive, &logfilename)) + if (!PyArg_ParseTupleAndKeywords( + args, kw, "|is", kwlist, &interactive, &logfilename)) return NULL; if (interactive && logfilename) { @@ -119,18 +119,19 @@ PyObject *py_setup_logging(PyObject *self, PyObject *args, PyObject *kw) } /* Return a cli_state to a RPC pipe on the given server. Use the - credentials passed if not NULL. Set an exception and return NULL if - there was an error creating the connection. */ + 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 *system_name, PyObject *creds, - cli_pipe_fn *connect_fn) +struct cli_state *open_pipe_creds(char *server, PyObject *creds, + cli_pipe_fn *connect_fn, char **errstr) { struct ntuser_creds nt_creds; struct cli_state *cli; cli = (struct cli_state *)malloc(sizeof(struct cli_state)); if (!cli) { - PyErr_SetString(PyExc_RuntimeError, "out of memory"); + *errstr = strdup("out of memory"); return NULL; } @@ -156,13 +157,7 @@ struct cli_state *open_pipe_creds(char *system_name, PyObject *creds, if (!username_obj || !domain_obj || !password_obj) { creds_error: - - /* TODO: Either pass in the exception for the - module calling open_pipe_creds() or have a - global samba python module exception. */ - - PyErr_SetString(PyExc_RuntimeError, - "invalid credentials"); + *errstr = strdup("invalid credentials"); return NULL; } @@ -193,24 +188,12 @@ struct cli_state *open_pipe_creds(char *system_name, PyObject *creds, /* Now try to connect */ - if (!connect_fn(cli, system_name, &nt_creds)) { - if (cli) { - NTSTATUS error = cli_nt_error(cli); - - /* Raise an exception if something went wrong. - FIXME: This should be a more appropriate - exception than PyExc_RuntimeError */ - - if (!NT_STATUS_IS_OK(error)) - PyErr_SetObject(PyExc_RuntimeError, - py_ntstatus_tuple(error)); - else - PyErr_SetString(PyExc_RuntimeError, - "error connecting to pipe"); - } - + if (!connect_fn(cli, server, &nt_creds)) { + *errstr = strdup("error connecting to RPC pipe"); return NULL; } + *errstr = NULL; + return cli; } diff --git a/source3/python/py_common_proto.h b/source3/python/py_common_proto.h index 98d970d7bc..dd823dd4c0 100644 --- a/source3/python/py_common_proto.h +++ b/source3/python/py_common_proto.h @@ -12,8 +12,8 @@ void py_samba_init(void); PyObject *get_debuglevel(PyObject *self, PyObject *args); PyObject *set_debuglevel(PyObject *self, PyObject *args); PyObject *py_setup_logging(PyObject *self, PyObject *args, PyObject *kw); -struct cli_state *open_pipe_creds(char *system_name, PyObject *creds, - cli_pipe_fn *connect_fn); +struct cli_state *open_pipe_creds(char *server, PyObject *creds, + cli_pipe_fn *connect_fn, char **errstr); /* The following definitions come from python/py_ntsec.c */ diff --git a/source3/python/py_lsa.c b/source3/python/py_lsa.c index cf96928790..82055181cc 100644 --- a/source3/python/py_lsa.c +++ b/source3/python/py_lsa.c @@ -53,7 +53,7 @@ static PyObject *lsa_open_policy(PyObject *self, PyObject *args, PyObject *kw) { static char *kwlist[] = { "servername", "creds", "access", NULL }; - char *server_name; + char *server, *errstr; PyObject *creds = NULL, *result; uint32 desired_access = MAXIMUM_ALLOWED_ACCESS; struct cli_state *cli; @@ -62,17 +62,20 @@ static PyObject *lsa_open_policy(PyObject *self, PyObject *args, POLICY_HND hnd; if (!PyArg_ParseTupleAndKeywords( - args, kw, "s|O!i", kwlist, &server_name, &PyDict_Type, - &creds, &desired_access)) + args, kw, "s|O!i", kwlist, &server, &PyDict_Type, + &creds, &desired_access)) return NULL; - if (!(cli = open_pipe_creds(server_name, creds, cli_lsa_initialise))) { - fprintf(stderr, "could not initialise cli state\n"); + if (!(cli = open_pipe_creds( + server, creds, cli_lsa_initialise, &errstr))) { + PyErr_SetString(lsa_error, errstr); + free(errstr); return NULL; } if (!(mem_ctx = talloc_init())) { - fprintf(stderr, "unable to initialise talloc context\n"); + PyErr_SetString( + lsa_error, "unable to initialise talloc context\n"); return NULL; } diff --git a/source3/python/py_samr.c b/source3/python/py_samr.c index 66d6266d10..d0573171f3 100644 --- a/source3/python/py_samr.c +++ b/source3/python/py_samr.c @@ -275,7 +275,7 @@ 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_name; + char *server, *errstr; struct cli_state *cli; POLICY_HND hnd; TALLOC_CTX *mem_ctx; @@ -283,12 +283,16 @@ static PyObject *samr_connect(PyObject *self, PyObject *args, PyObject *kw) NTSTATUS ntstatus; if (!PyArg_ParseTupleAndKeywords( - args, kw, "s|O!i", kwlist, &server_name, &PyDict_Type, + args, kw, "s|O!i", kwlist, &server, &PyDict_Type, &creds, &desired_access)) return NULL; - if (!(cli = open_pipe_creds(server_name, creds, cli_samr_initialise))) - goto done; + if (!(cli = open_pipe_creds( + server, creds, cli_lsa_initialise, &errstr))) { + PyErr_SetString(samr_error, errstr); + free(errstr); + return NULL; + } if (!(mem_ctx = talloc_init())) { PyErr_SetString(samr_ntstatus, diff --git a/source3/python/py_spoolss_drivers.c b/source3/python/py_spoolss_drivers.c index 416d46f1d2..64d3a37afa 100644 --- a/source3/python/py_spoolss_drivers.c +++ b/source3/python/py_spoolss_drivers.c @@ -30,28 +30,30 @@ PyObject *spoolss_enumprinterdrivers(PyObject *self, PyObject *args, PRINTER_DRIVER_CTR ctr; int level = 1, i; uint32 needed, num_drivers; - char *arch = "Windows NT x86", *server_name; + char *arch = "Windows NT x86", *server, *errstr; static char *kwlist[] = {"server", "creds", "level", "arch", NULL}; struct cli_state *cli = NULL; TALLOC_CTX *mem_ctx = NULL; /* Parse parameters */ - if (!PyArg_ParseTupleAndKeywords(args, kw, "s|O!is", kwlist, - &server_name, &PyDict_Type, &creds, - &level, &arch)) + if (!PyArg_ParseTupleAndKeywords( + args, kw, "s|O!is", kwlist, &server, &PyDict_Type, + &creds, &level, &arch)) return NULL; /* Call rpc function */ if (!(cli = open_pipe_creds( - server_name, creds, cli_spoolss_initialise))) { - fprintf(stderr, "could not initialise cli state\n"); + server, creds, cli_spoolss_initialise, &errstr))) { + PyErr_SetString(spoolss_error, errstr); + free(errstr); goto done; } if (!(mem_ctx = talloc_init())) { - fprintf(stderr, "unable to initialise talloc context\n"); + PyErr_SetString( + spoolss_error, "unable to initialise talloc context\n"); goto done; } @@ -181,8 +183,8 @@ PyObject *spoolss_hnd_getprinterdriver(PyObject *self, PyObject *args, /* Parse parameters */ - if (!PyArg_ParseTupleAndKeywords(args, kw, "|is", kwlist, - &level, &arch)) + if (!PyArg_ParseTupleAndKeywords( + args, kw, "|is", kwlist, &level, &arch)) return NULL; /* Call rpc function */ @@ -230,28 +232,30 @@ PyObject *spoolss_getprinterdriverdir(PyObject *self, PyObject *args, PyObject *result = Py_None, *creds = NULL; DRIVER_DIRECTORY_CTR ctr; uint32 needed, level; - char *arch = "Windows NT x86", *server_name; + 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_name, &level, &arch, - &PyDict_Type, &creds)) + if (!PyArg_ParseTupleAndKeywords( + args, kw, "s|isO!", kwlist, &server, &level, + &arch, &PyDict_Type, &creds)) return NULL; /* Call rpc function */ if (!(cli = open_pipe_creds( - server_name, creds, cli_spoolss_initialise))) { - fprintf(stderr, "could not initialise cli state\n"); + server, creds, cli_spoolss_initialise, &errstr))) { + PyErr_SetString(spoolss_error, errstr); + free(errstr); goto done; } if (!(mem_ctx = talloc_init())) { - fprintf(stderr, "unable to initialise talloc context\n"); + PyErr_SetString( + spoolss_error, "unable to initialise talloc context\n"); goto done; } @@ -290,7 +294,7 @@ PyObject *spoolss_addprinterdriver(PyObject *self, PyObject *args, PyObject *kw) { static char *kwlist[] = { "server", "info", "creds", NULL }; - char *server; + char *server, *errstr; uint32 level; PyObject *info, *result = NULL, *creds = NULL, *level_obj; WERROR werror; @@ -309,10 +313,18 @@ PyObject *spoolss_addprinterdriver(PyObject *self, PyObject *args, if (server[0] == '\\' && server[1] == '\\') server += 2; - mem_ctx = talloc_init(); + if (!(mem_ctx = talloc_init())) { + PyErr_SetString( + spoolss_error, "unable to initialise talloc context\n"); + return NULL; + } - if (!(cli = open_pipe_creds(server, creds, cli_spoolss_initialise))) + if (!(cli = open_pipe_creds( + server, creds, cli_spoolss_initialise, &errstr))) { + PyErr_SetString(spoolss_error, errstr); + free(errstr); goto done; + } if ((level_obj = PyDict_GetItemString(info, "level"))) { diff --git a/source3/python/py_spoolss_forms.c b/source3/python/py_spoolss_forms.c index 83cdf9badd..762b13f73b 100644 --- a/source3/python/py_spoolss_forms.c +++ b/source3/python/py_spoolss_forms.c @@ -84,8 +84,8 @@ PyObject *spoolss_hnd_getform(PyObject *self, PyObject *args, PyObject *kw) /* Parse parameters */ - if (!PyArg_ParseTupleAndKeywords(args, kw, "s|i", kwlist, - &form_name, &level)) + if (!PyArg_ParseTupleAndKeywords( + args, kw, "s|i", kwlist, &form_name, &level)) return NULL; /* Call rpc function */ @@ -129,8 +129,9 @@ PyObject *spoolss_hnd_setform(PyObject *self, PyObject *args, PyObject *kw) /* Parse parameters */ - if (!PyArg_ParseTupleAndKeywords(args, kw, "O!|i", kwlist, - &PyDict_Type, &py_form, &level)) + if (!PyArg_ParseTupleAndKeywords( + args, kw, "O!|i", kwlist, &PyDict_Type, &py_form, + &level)) return NULL; /* Call rpc function */ diff --git a/source3/python/py_spoolss_jobs.c b/source3/python/py_spoolss_jobs.c index d98fdba137..29475f9e3b 100644 --- a/source3/python/py_spoolss_jobs.c +++ b/source3/python/py_spoolss_jobs.c @@ -96,8 +96,8 @@ PyObject *spoolss_hnd_setjob(PyObject *self, PyObject *args, PyObject *kw) /* Parse parameters */ - if (!PyArg_ParseTupleAndKeywords(args, kw, "ii|i", kwlist, &jobid, - &command, &level)) + if (!PyArg_ParseTupleAndKeywords( + args, kw, "ii|i", kwlist, &jobid, &command, &level)) return NULL; /* Call rpc function */ @@ -127,8 +127,8 @@ PyObject *spoolss_hnd_getjob(PyObject *self, PyObject *args, PyObject *kw) /* Parse parameters */ - if (!PyArg_ParseTupleAndKeywords(args, kw, "i|i", kwlist, &jobid, - &level)) + if (!PyArg_ParseTupleAndKeywords( + args, kw, "i|i", kwlist, &jobid, &level)) return NULL; /* Call rpc function */ @@ -228,8 +228,8 @@ PyObject *spoolss_hnd_startdocprinter(PyObject *self, PyObject *args, PyObject * /* Parse parameters */ - if (!PyArg_ParseTupleAndKeywords(args, kw, "O!", kwlist, - &PyDict_Type, &doc_info)) + if (!PyArg_ParseTupleAndKeywords( + args, kw, "O!", kwlist, &PyDict_Type, &doc_info)) return NULL; /* Check document_info parameter */ @@ -362,8 +362,8 @@ PyObject *spoolss_hnd_writeprinter(PyObject *self, PyObject *args, PyObject *kw) /* Parse parameters */ - if (!PyArg_ParseTupleAndKeywords(args, kw, "O!", kwlist, - &PyString_Type, &data)) + if (!PyArg_ParseTupleAndKeywords( + args, kw, "O!", kwlist, &PyString_Type, &data)) return NULL; /* Call rpc function */ diff --git a/source3/python/py_spoolss_ports.c b/source3/python/py_spoolss_ports.c index 8e74017f4a..fb3f47c746 100644 --- a/source3/python/py_spoolss_ports.c +++ b/source3/python/py_spoolss_ports.c @@ -31,21 +31,31 @@ PyObject *spoolss_enumports(PyObject *self, PyObject *args, PyObject *kw) static char *kwlist[] = {"server", "level", "creds", NULL}; TALLOC_CTX *mem_ctx = NULL; struct cli_state *cli = NULL; - char *server; + char *server, *errstr; PORT_INFO_CTR ctr; /* Parse parameters */ - if (!PyArg_ParseTupleAndKeywords(args, kw, "s|iO!", kwlist, - &server, &creds, &level, - &PyDict_Type)) + if (!PyArg_ParseTupleAndKeywords( + args, kw, "s|iO!", kwlist, &server, &creds, &level, + &PyDict_Type)) return NULL; if (server[0] == '\\' && server[1] == '\\') server += 2; - mem_ctx = talloc_init(); - cli = open_pipe_creds(server, creds, cli_spoolss_initialise); + if (!(cli = open_pipe_creds( + server, creds, cli_spoolss_initialise, &errstr))) { + PyErr_SetString(spoolss_error, errstr); + free(errstr); + return NULL; + } + + if (!(mem_ctx = talloc_init())) { + PyErr_SetString( + spoolss_error, "unable to initialise talloc context\n"); + return NULL; + } /* Call rpc function */ diff --git a/source3/python/py_spoolss_printerdata.c b/source3/python/py_spoolss_printerdata.c index 24e2340059..e1e43fa736 100644 --- a/source3/python/py_spoolss_printerdata.c +++ b/source3/python/py_spoolss_printerdata.c @@ -100,7 +100,7 @@ PyObject *spoolss_hnd_getprinterdata(PyObject *self, PyObject *args, PyObject *k /* Parse parameters */ if (!PyArg_ParseTupleAndKeywords(args, kw, "s", kwlist, &value)) - return NULL; + return NULL; /* Call rpc function */ @@ -132,8 +132,8 @@ PyObject *spoolss_hnd_setprinterdata(PyObject *self, PyObject *args, PyObject *k uint32 data_size, data_type; WERROR werror; - if (!PyArg_ParseTupleAndKeywords(args, kw, "O!", kwlist, - &PyDict_Type, &py_data)) + 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)) @@ -209,7 +209,7 @@ PyObject *spoolss_hnd_deleteprinterdata(PyObject *self, PyObject *args, PyObject /* Parse parameters */ if (!PyArg_ParseTupleAndKeywords(args, kw, "s", kwlist, &value)) - return NULL; + return NULL; /* Call rpc function */ diff --git a/source3/python/py_spoolss_printers.c b/source3/python/py_spoolss_printers.c index 36ba22a7c4..7ee94a48f7 100644 --- a/source3/python/py_spoolss_printers.c +++ b/source3/python/py_spoolss_printers.c @@ -24,7 +24,7 @@ PyObject *spoolss_openprinter(PyObject *self, PyObject *args, PyObject *kw) { - char *full_name, *computer_name = NULL; + char *unc_name, *server = NULL, *errstr; TALLOC_CTX *mem_ctx; POLICY_HND hnd; WERROR werror; @@ -34,25 +34,26 @@ PyObject *spoolss_openprinter(PyObject *self, PyObject *args, PyObject *kw) struct cli_state *cli; if (!PyArg_ParseTupleAndKeywords( - args, kw, "s|O!i", kwlist, &full_name, &PyDict_Type, &creds, - &desired_access)) { - + args, kw, "s|O!i", kwlist, &unc_name, &PyDict_Type, &creds, + &desired_access)) goto done; - } /* FIXME: Return name format exception for names without a UNC prefix */ - computer_name = strdup(full_name + 2); + server = strdup(unc_name + 2); - if (strchr(computer_name, '\\')) { - char *c = strchr(computer_name, '\\'); + if (strchr(server, '\\')) { + char *c = strchr(server, '\\'); *c = 0; } if (!(cli = open_pipe_creds( - computer_name, creds, cli_spoolss_initialise))) + server, creds, cli_spoolss_initialise, &errstr))) { + PyErr_SetString(spoolss_error, errstr); + free(errstr); goto done; + } if (!(mem_ctx = talloc_init())) { PyErr_SetString(spoolss_error, @@ -61,7 +62,7 @@ PyObject *spoolss_openprinter(PyObject *self, PyObject *args, PyObject *kw) } werror = cli_spoolss_open_printer_ex( - cli, mem_ctx, full_name, "", desired_access, computer_name, + cli, mem_ctx, unc_name, "", desired_access, server, "", &hnd); if (!W_ERROR_IS_OK(werror)) { @@ -74,7 +75,7 @@ PyObject *spoolss_openprinter(PyObject *self, PyObject *args, PyObject *kw) result = new_spoolss_policy_hnd_object(cli, mem_ctx, &hnd); done: - SAFE_FREE(computer_name); + SAFE_FREE(server); return result; } @@ -187,8 +188,8 @@ PyObject *spoolss_hnd_setprinter(PyObject *self, PyObject *args, PyObject *kw) /* Parse parameters */ - if (!PyArg_ParseTupleAndKeywords(args, kw, "O!", kwlist, - &PyDict_Type, &info)) + if (!PyArg_ParseTupleAndKeywords( + args, kw, "O!", kwlist, &PyDict_Type, &info)) return NULL; /* Check dictionary contains a level */ @@ -277,20 +278,30 @@ PyObject *spoolss_enumprinters(PyObject *self, PyObject *args, PyObject *kw) "creds", NULL}; TALLOC_CTX *mem_ctx; struct cli_state *cli; - char *server, *name = NULL; + char *server, *errstr; /* Parse parameters */ - if (!PyArg_ParseTupleAndKeywords(args, kw, "s|siiO!", kwlist, - &server, &name, &level, &flags, - &PyDict_Type, &creds)) + if (!PyArg_ParseTupleAndKeywords( + args, kw, "s|iiO!", kwlist, &server, &level, &flags, + &PyDict_Type, &creds)) return NULL; if (server[0] == '\\' && server[1] == '\\') server += 2; - mem_ctx = talloc_init(); - cli = open_pipe_creds(server, creds, cli_spoolss_initialise); + if (!(cli = open_pipe_creds( + server, creds, cli_spoolss_initialise, &errstr))) { + PyErr_SetString(spoolss_error, errstr); + free(errstr); + return NULL; + } + + if (!(mem_ctx = talloc_init())) { + PyErr_SetString( + spoolss_error, "unable to initialise talloc context\n"); + return NULL; + } /* Call rpc function */ @@ -369,7 +380,7 @@ PyObject *spoolss_addprinterex(PyObject *self, PyObject *args, PyObject *kw) { static char *kwlist[] = { "server", "printername", "info", "creds", NULL}; - char *printername, *server; + char *printername, *server, *errstr; PyObject *info, *result = NULL, *creds = NULL; struct cli_state *cli = NULL; TALLOC_CTX *mem_ctx = NULL; @@ -383,13 +394,17 @@ PyObject *spoolss_addprinterex(PyObject *self, PyObject *args, PyObject *kw) return NULL; if (!(cli = open_pipe_creds( - server, creds, cli_spoolss_initialise))) + server, creds, cli_spoolss_initialise, &errstr))) { + PyErr_SetString(spoolss_error, errstr); + free(errstr); goto done; + } - mem_ctx = talloc_init(); - - if (!(cli = open_pipe_creds(server, creds, cli_spoolss_initialise))) - goto done; + if (!(mem_ctx = talloc_init())) { + PyErr_SetString( + spoolss_error, "unable to initialise talloc context\n"); + return NULL; + } if (!py_to_PRINTER_INFO_2(&info2, info, mem_ctx)) { PyErr_SetString(spoolss_error, diff --git a/source3/python/py_spoolss_proto.h b/source3/python/py_spoolss_proto.h index b197003c79..5b68ef815a 100644 --- a/source3/python/py_spoolss_proto.h +++ b/source3/python/py_spoolss_proto.h @@ -21,7 +21,7 @@ PyObject *spoolss_getprinterdriverdir(PyObject *self, PyObject *args, PyObject *spoolss_addprinterdriver(PyObject *self, PyObject *args, PyObject *kw); PyObject *spoolss_addprinterdriverex(PyObject *self, PyObject *args, - PyObject *kw); + PyObject *kw); PyObject *spoolss_deleteprinterdriver(PyObject *self, PyObject *args, PyObject *kw); PyObject *spoolss_deleteprinterdriverex(PyObject *self, PyObject *args, -- cgit From 70da1dec973e1736a6ec9f12a1598a077f36e274 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Thu, 16 May 2002 05:13:50 +0000 Subject: Shorten some debug messages. (This used to be commit 179c68bd0db7c2631fcf052a746acacedf3c47ac) --- source3/python/py_lsa.c | 2 +- source3/python/py_samr.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/python') diff --git a/source3/python/py_lsa.c b/source3/python/py_lsa.c index 82055181cc..0f71187aa6 100644 --- a/source3/python/py_lsa.c +++ b/source3/python/py_lsa.c @@ -75,7 +75,7 @@ static PyObject *lsa_open_policy(PyObject *self, PyObject *args, if (!(mem_ctx = talloc_init())) { PyErr_SetString( - lsa_error, "unable to initialise talloc context\n"); + lsa_error, "unable to init talloc context\n"); return NULL; } diff --git a/source3/python/py_samr.c b/source3/python/py_samr.c index d0573171f3..6256629592 100644 --- a/source3/python/py_samr.c +++ b/source3/python/py_samr.c @@ -296,7 +296,7 @@ static PyObject *samr_connect(PyObject *self, PyObject *args, PyObject *kw) if (!(mem_ctx = talloc_init())) { PyErr_SetString(samr_ntstatus, - "unable to initialise talloc context\n"); + "unable to init talloc context\n"); goto done; } -- cgit From ce8990949343899f07ac98205cd8d4fa622c542a Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Thu, 16 May 2002 05:16:06 +0000 Subject: Fix return value for enumprinterdrivers(), getprinterdriverdir(). Set info level key in getprinterdriverdir() return info. (This used to be commit cb4bfd39eb83efddb29b3a3bc70c2a8713f80ef2) --- source3/python/py_spoolss_drivers.c | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) (limited to 'source3/python') diff --git a/source3/python/py_spoolss_drivers.c b/source3/python/py_spoolss_drivers.c index 64d3a37afa..ec85f9dd6f 100644 --- a/source3/python/py_spoolss_drivers.c +++ b/source3/python/py_spoolss_drivers.c @@ -26,20 +26,20 @@ PyObject *spoolss_enumprinterdrivers(PyObject *self, PyObject *args, PyObject *kw) { WERROR werror; - PyObject *result = Py_None, *creds = NULL; + 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", "creds", "level", "arch", NULL}; + 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|O!is", kwlist, &server, &PyDict_Type, - &creds, &level, &arch)) + args, kw, "s|iO!s", kwlist, &server, &level, &PyDict_Type, + &creds, &arch)) return NULL; /* Call rpc function */ @@ -53,7 +53,7 @@ PyObject *spoolss_enumprinterdrivers(PyObject *self, PyObject *args, if (!(mem_ctx = talloc_init())) { PyErr_SetString( - spoolss_error, "unable to initialise talloc context\n"); + spoolss_error, "unable to init talloc context\n"); goto done; } @@ -72,7 +72,7 @@ PyObject *spoolss_enumprinterdrivers(PyObject *self, PyObject *args, } /* Return value */ - + switch (level) { case 1: result = PyDict_New(); @@ -151,9 +151,8 @@ PyObject *spoolss_enumprinterdrivers(PyObject *self, PyObject *args, break; default: - PyErr_SetString(spoolss_error, "unknown info level returned"); - result = NULL; - break; + PyErr_SetString(spoolss_error, "unknown info level"); + goto done; } done: @@ -163,7 +162,6 @@ PyObject *spoolss_enumprinterdrivers(PyObject *self, PyObject *args, if (mem_ctx) talloc_destroy(mem_ctx); - Py_INCREF(result); return result; } @@ -229,9 +227,9 @@ PyObject *spoolss_getprinterdriverdir(PyObject *self, PyObject *args, PyObject *kw) { WERROR werror; - PyObject *result = Py_None, *creds = NULL; + PyObject *result = NULL, *creds = NULL; DRIVER_DIRECTORY_CTR ctr; - uint32 needed, level; + uint32 needed, level = 1; char *arch = "Windows NT x86", *server, *errstr; static char *kwlist[] = {"server", "level", "arch", "creds", NULL}; struct cli_state *cli = NULL; @@ -255,7 +253,7 @@ PyObject *spoolss_getprinterdriverdir(PyObject *self, PyObject *args, if (!(mem_ctx = talloc_init())) { PyErr_SetString( - spoolss_error, "unable to initialise talloc context\n"); + spoolss_error, "unable to init talloc context\n"); goto done; } @@ -268,7 +266,7 @@ PyObject *spoolss_getprinterdriverdir(PyObject *self, PyObject *args, if (!W_ERROR_IS_OK(werror)) { PyErr_SetObject(spoolss_werror, py_werror_tuple(werror)); - return NULL; + goto done; } /* Return value */ @@ -276,7 +274,12 @@ PyObject *spoolss_getprinterdriverdir(PyObject *self, PyObject *args, switch (level) { case 1: py_from_DRIVER_DIRECTORY_1(&result, ctr.info1); + PyDict_SetItemString( + result, "level", PyInt_FromLong(1)); break; + default: + PyErr_SetString(spoolss_error, "unknown info level"); + goto done; } done: @@ -286,7 +289,6 @@ PyObject *spoolss_getprinterdriverdir(PyObject *self, PyObject *args, if (mem_ctx) talloc_destroy(mem_ctx); - Py_INCREF(result); return result; } @@ -315,7 +317,7 @@ PyObject *spoolss_addprinterdriver(PyObject *self, PyObject *args, if (!(mem_ctx = talloc_init())) { PyErr_SetString( - spoolss_error, "unable to initialise talloc context\n"); + spoolss_error, "unable to init talloc context\n"); return NULL; } -- cgit From 0227141bd1e9543d8d8f2dddfc9f729e7975d6a1 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Thu, 16 May 2002 05:17:43 +0000 Subject: Set exception object when enumjobs returns non-zero NT status. (This used to be commit b1818eb37572f4d30efef998d926ac111e78cb48) --- source3/python/py_spoolss_jobs.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'source3/python') diff --git a/source3/python/py_spoolss_jobs.c b/source3/python/py_spoolss_jobs.c index 29475f9e3b..856e6252ea 100644 --- a/source3/python/py_spoolss_jobs.c +++ b/source3/python/py_spoolss_jobs.c @@ -52,8 +52,10 @@ PyObject *spoolss_hnd_enumjobs(PyObject *self, PyObject *args, PyObject *kw) result = Py_None; - if (!W_ERROR_IS_OK(werror)) + if (!W_ERROR_IS_OK(werror)) { + PyErr_SetObject(spoolss_werror, py_werror_tuple(werror)); goto done; + } result = PyList_New(num_jobs); -- cgit From 66115cf64be78907cf33ab5f7b0d3a33a3c7afd4 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Thu, 16 May 2002 05:19:30 +0000 Subject: Fix memory leaks and return values in error returns for enumports(). Return enumerated ports as a hash of hashes instead of a list of hashes. (This used to be commit c469ada3d3b12b6a6e243d004faaae5f96cd3d96) --- source3/python/py_spoolss_ports.c | 56 ++++++++++++++++++++++++++++----------- 1 file changed, 40 insertions(+), 16 deletions(-) (limited to 'source3/python') diff --git a/source3/python/py_spoolss_ports.c b/source3/python/py_spoolss_ports.c index fb3f47c746..54ccf32fcc 100644 --- a/source3/python/py_spoolss_ports.c +++ b/source3/python/py_spoolss_ports.c @@ -25,7 +25,7 @@ PyObject *spoolss_enumports(PyObject *self, PyObject *args, PyObject *kw) { WERROR werror; - PyObject *result, *creds = NULL; + PyObject *result = NULL, *creds = NULL; int level = 1; uint32 i, needed, num_ports; static char *kwlist[] = {"server", "level", "creds", NULL}; @@ -37,8 +37,8 @@ PyObject *spoolss_enumports(PyObject *self, PyObject *args, PyObject *kw) /* Parse parameters */ if (!PyArg_ParseTupleAndKeywords( - args, kw, "s|iO!", kwlist, &server, &creds, &level, - &PyDict_Type)) + args, kw, "s|iO!", kwlist, &server, &level, + &PyDict_Type, &creds)) return NULL; if (server[0] == '\\' && server[1] == '\\') @@ -48,13 +48,13 @@ PyObject *spoolss_enumports(PyObject *self, PyObject *args, PyObject *kw) server, creds, cli_spoolss_initialise, &errstr))) { PyErr_SetString(spoolss_error, errstr); free(errstr); - return NULL; + goto done; } if (!(mem_ctx = talloc_init())) { PyErr_SetString( - spoolss_error, "unable to initialise talloc context\n"); - return NULL; + spoolss_error, "unable to init talloc context\n"); + goto done; } /* Call rpc function */ @@ -67,39 +67,63 @@ PyObject *spoolss_enumports(PyObject *self, PyObject *args, PyObject *kw) cli, mem_ctx, needed, NULL, level, &num_ports, &ctr); - /* Return value */ - - result = Py_None; - - if (!W_ERROR_IS_OK(werror)) + if (!W_ERROR_IS_OK(werror)) { + PyErr_SetObject(spoolss_werror, py_werror_tuple(werror)); goto done; + } - result = PyList_New(num_ports); - + /* Return value */ + switch (level) { case 1: + result = PyDict_New(); + for (i = 0; i < num_ports; i++) { PyObject *value; + fstring name; + + rpcstr_pull(name, ctr.port.info_1[i].port_name.buffer, + sizeof(fstring), -1, STR_TERMINATE); py_from_PORT_INFO_1(&value, &ctr.port.info_1[i]); - PyList_SetItem(result, i, value); + PyDict_SetItemString( + value, "level", PyInt_FromLong(1)); + + PyDict_SetItemString(result, name, value); } break; case 2: + result = PyDict_New(); + for(i = 0; i < num_ports; i++) { PyObject *value; + fstring name; + + rpcstr_pull(name, ctr.port.info_2[i].port_name.buffer, + sizeof(fstring), -1, STR_TERMINATE); py_from_PORT_INFO_2(&value, &ctr.port.info_2[i]); - PyList_SetItem(result, i, value); + PyDict_SetItemString( + value, "level", PyInt_FromLong(2)); + + PyDict_SetItemString(result, name, value); } break; + default: + PyErr_SetString(spoolss_error, "unknown info level"); + goto done; } done: - Py_INCREF(result); + if (cli) + cli_shutdown(cli); + + if (mem_ctx) + talloc_destroy(mem_ctx); + return result; } -- cgit From 9ad364acdb141c03c9ce3c0b85652b9defa8df58 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Thu, 16 May 2002 05:24:06 +0000 Subject: Fix memory leaks and return values in error returns for enumprinters(). Return enumerated printers as a hash of hashes instead of a list of hashes. (This used to be commit 1d0fd34d42e286fe7a41ca2d122f6bd7dc958b0a) --- source3/python/py_spoolss_printers.c | 77 ++++++++++++++++++++++-------------- 1 file changed, 48 insertions(+), 29 deletions(-) (limited to 'source3/python') diff --git a/source3/python/py_spoolss_printers.c b/source3/python/py_spoolss_printers.c index 7ee94a48f7..2edad20fda 100644 --- a/source3/python/py_spoolss_printers.c +++ b/source3/python/py_spoolss_printers.c @@ -57,7 +57,7 @@ PyObject *spoolss_openprinter(PyObject *self, PyObject *args, PyObject *kw) if (!(mem_ctx = talloc_init())) { PyErr_SetString(spoolss_error, - "unable to initialise talloc context\n"); + "unable to init talloc context\n"); goto done; } @@ -270,14 +270,13 @@ PyObject *spoolss_hnd_setprinter(PyObject *self, PyObject *args, PyObject *kw) PyObject *spoolss_enumprinters(PyObject *self, PyObject *args, PyObject *kw) { WERROR werror; - PyObject *result, *creds = NULL; + 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; - struct cli_state *cli; + static char *kwlist[] = {"server", "level", "flags", "creds", NULL}; + TALLOC_CTX *mem_ctx = NULL; + struct cli_state *cli = NULL; char *server, *errstr; /* Parse parameters */ @@ -294,13 +293,13 @@ PyObject *spoolss_enumprinters(PyObject *self, PyObject *args, PyObject *kw) server, creds, cli_spoolss_initialise, &errstr))) { PyErr_SetString(spoolss_error, errstr); free(errstr); - return NULL; + goto done; } if (!(mem_ctx = talloc_init())) { PyErr_SetString( - spoolss_error, "unable to initialise talloc context\n"); - return NULL; + spoolss_error, "unable to init talloc context\n"); + goto done; } /* Call rpc function */ @@ -314,62 +313,82 @@ PyObject *spoolss_enumprinters(PyObject *self, PyObject *args, PyObject *kw) cli, mem_ctx, needed, NULL, flags, level, &num_printers, &ctr); - /* Return value */ - if (!W_ERROR_IS_OK(werror)) { PyErr_SetObject(spoolss_werror, py_werror_tuple(werror)); - result = NULL; goto done; } - result = PyList_New(num_printers); - + /* 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]); - PyList_SetItem(result, i, value); + 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]); - PyList_SetItem(result, i, value); + 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; - py_from_PRINTER_INFO_2(&value, &ctr.printers_2[i]); + rpcstr_pull(name, ctr.printers_2[i].printername.buffer, + sizeof(fstring), -1, STR_TERMINATE); - PyList_SetItem(result, i, value); - } - - break; - case 3: - for(i = 0; i < num_printers; i++) { - PyObject *value; + py_from_PRINTER_INFO_2(&value, &ctr.printers_2[i]); - py_from_PRINTER_INFO_3(&value, &ctr.printers_3[i]); + PyDict_SetItemString( + value, "level", PyInt_FromLong(2)); - PyList_SetItem(result, i, value); + PyDict_SetItemString(result, name, value); } break; + default: + PyErr_SetString(spoolss_error, "unknown info level"); + goto done; } done: - cli_shutdown(cli); - talloc_destroy(mem_ctx); + if (cli) + cli_shutdown(cli); + + if (mem_ctx) + talloc_destroy(mem_ctx); return result; } @@ -402,7 +421,7 @@ PyObject *spoolss_addprinterex(PyObject *self, PyObject *args, PyObject *kw) if (!(mem_ctx = talloc_init())) { PyErr_SetString( - spoolss_error, "unable to initialise talloc context\n"); + spoolss_error, "unable to init talloc context\n"); return NULL; } -- cgit From c2f5c02e2817dac00b7d03060e4403a4de1e9898 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Thu, 16 May 2002 05:25:53 +0000 Subject: Renamed 'printer_name' field in python printer info to 'name' to be more consistent. (This used to be commit f8c198b74899d1be1725d0647c5f0cd7db870340) --- source3/python/py_spoolss_printers_conv.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/python') diff --git a/source3/python/py_spoolss_printers_conv.c b/source3/python/py_spoolss_printers_conv.c index b20382922c..676e21e99e 100644 --- a/source3/python/py_spoolss_printers_conv.c +++ b/source3/python/py_spoolss_printers_conv.c @@ -22,7 +22,7 @@ #include "python/py_conv.h" struct pyconv py_PRINTER_INFO_0[] = { - { "printer_name", PY_UNISTR, offsetof(PRINTER_INFO_0, printername) }, + { "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) }, @@ -72,7 +72,7 @@ struct pyconv py_PRINTER_INFO_0[] = { }; struct pyconv py_PRINTER_INFO_1[] = { - { "printer_name", PY_UNISTR, offsetof(PRINTER_INFO_1, name) }, + { "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) }, @@ -81,7 +81,7 @@ struct pyconv py_PRINTER_INFO_1[] = { struct pyconv py_PRINTER_INFO_2[] = { { "server_name", PY_UNISTR, offsetof(PRINTER_INFO_2, servername) }, - { "printer_name", PY_UNISTR, offsetof(PRINTER_INFO_2, printername) }, + { "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) }, -- cgit From 16f78e46bb6ded49ff908e48504473cae8530d29 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Thu, 16 May 2002 05:45:01 +0000 Subject: Removed unused variable. (This used to be commit 8d2f77ce956711f2afbadbeee50d82fbec9047dc) --- source3/python/py_spoolss_drivers_conv.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'source3/python') diff --git a/source3/python/py_spoolss_drivers_conv.c b/source3/python/py_spoolss_drivers_conv.c index 0eaf605cbe..446a465f3e 100644 --- a/source3/python/py_spoolss_drivers_conv.c +++ b/source3/python/py_spoolss_drivers_conv.c @@ -111,8 +111,6 @@ BOOL py_from_DRIVER_INFO_3(PyObject **dict, DRIVER_INFO_3 *info) BOOL py_to_DRIVER_INFO_3(DRIVER_INFO_3 *info, PyObject *dict) { - PyObject *obj; - to_struct(info, dict, py_DRIVER_INFO_3); return True; -- cgit From 535af3c3fe2bdac0f57729ea4aa01679314db10a Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Thu, 16 May 2002 07:32:55 +0000 Subject: Return enumerated forms as a hash of hashes instead of a list of hashes. (This used to be commit 2f86f01b88ccaaeee97588f339ebaeae5c4c06e9) --- source3/python/py_spoolss_forms.c | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) (limited to 'source3/python') diff --git a/source3/python/py_spoolss_forms.c b/source3/python/py_spoolss_forms.c index 762b13f73b..b0fe43dd57 100644 --- a/source3/python/py_spoolss_forms.c +++ b/source3/python/py_spoolss_forms.c @@ -219,18 +219,29 @@ PyObject *spoolss_hnd_enumforms(PyObject *self, PyObject *args, PyObject *kw) return NULL; } - result = PyList_New(num_forms); + 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); - for (i = 0; i < num_forms; i++) { - PyObject *obj = NULL; + py_from_FORM_1(&value, &forms[i]); - switch(level) { - case 1: - py_from_FORM_1(&obj, &forms[i]); - break; + PyDict_SetItemString( + value, "level", PyInt_FromLong(1)); + + PyDict_SetItemString(result, name, value); } - PyList_SetItem(result, i, obj); + break; + default: + PyErr_SetString(spoolss_error, "unknown info level"); + return NULL; } return result; -- cgit From 119716f16215ba00bc557cff9e60009cca61cc64 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Fri, 17 May 2002 02:24:06 +0000 Subject: to_struct() now returns a boolean which is false if not all the elements of the structure were present in the dictionary. (This used to be commit b26d9d793914b66050c374ec2c0e94fa37c7e0e4) --- source3/python/py_conv.c | 7 ++++++- source3/python/py_conv.h | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) (limited to 'source3/python') diff --git a/source3/python/py_conv.c b/source3/python/py_conv.c index 2dc12f348a..c6f39515af 100644 --- a/source3/python/py_conv.c +++ b/source3/python/py_conv.c @@ -78,7 +78,7 @@ PyObject *from_struct(void *s, struct pyconv *conv) /* Convert a Python dict to a structure */ -void to_struct(void *s, PyObject *dict, struct pyconv *conv) +BOOL to_struct(void *s, PyObject *dict, struct pyconv *conv) { int i; @@ -86,6 +86,9 @@ void to_struct(void *s, PyObject *dict, struct pyconv *conv) PyObject *obj; obj = PyDict_GetItemString(dict, conv[i].name); + + if (!obj) + return False; switch (conv[i].type) { case PY_UNISTR: { @@ -123,4 +126,6 @@ void to_struct(void *s, PyObject *dict, struct pyconv *conv) break; } } + + return True; } diff --git a/source3/python/py_conv.h b/source3/python/py_conv.h index 0de2d674de..ed06b9a852 100644 --- a/source3/python/py_conv.h +++ b/source3/python/py_conv.h @@ -30,7 +30,7 @@ struct pyconv { }; PyObject *from_struct(void *s, struct pyconv *conv); -void to_struct(void *s, PyObject *dict, struct pyconv *conv); +BOOL to_struct(void *s, PyObject *dict, struct pyconv *conv); /* Another version of offsetof (-: */ -- cgit From 1ab45841cc7ecfcfeba7a41ecfc34791171f41fa Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Fri, 17 May 2002 02:25:37 +0000 Subject: Added a utility function to extract the info key from a dictionary. (This used to be commit 4cafbcb205af11c478a2d9047554315915933e5d) --- source3/python/py_common.c | 17 +++++++++++++++++ source3/python/py_common_proto.h | 1 + 2 files changed, 18 insertions(+) (limited to 'source3/python') diff --git a/source3/python/py_common.c b/source3/python/py_common.c index 61eacced27..85305d027e 100644 --- a/source3/python/py_common.c +++ b/source3/python/py_common.c @@ -197,3 +197,20 @@ struct cli_state *open_pipe_creds(char *server, PyObject *creds, 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_common_proto.h b/source3/python/py_common_proto.h index dd823dd4c0..992d444fa4 100644 --- a/source3/python/py_common_proto.h +++ b/source3/python/py_common_proto.h @@ -14,6 +14,7 @@ PyObject *set_debuglevel(PyObject *self, PyObject *args); PyObject *py_setup_logging(PyObject *self, PyObject *args, PyObject *kw); struct cli_state *open_pipe_creds(char *server, PyObject *creds, cli_pipe_fn *connect_fn, char **errstr); +BOOL get_level_value(PyObject *dict, uint32 *level); /* The following definitions come from python/py_ntsec.c */ -- cgit From 191a4460780cb0e8b686dd70591d403e59123697 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Fri, 17 May 2002 02:28:26 +0000 Subject: Call get_level_value() utility function. (This used to be commit 2566dad274e0bced9e55cbc3c126c00e70373fbe) --- source3/python/py_spoolss_drivers.c | 29 ++++++++--------------------- 1 file changed, 8 insertions(+), 21 deletions(-) (limited to 'source3/python') diff --git a/source3/python/py_spoolss_drivers.c b/source3/python/py_spoolss_drivers.c index ec85f9dd6f..e95d548ef1 100644 --- a/source3/python/py_spoolss_drivers.c +++ b/source3/python/py_spoolss_drivers.c @@ -298,7 +298,7 @@ PyObject *spoolss_addprinterdriver(PyObject *self, PyObject *args, static char *kwlist[] = { "server", "info", "creds", NULL }; char *server, *errstr; uint32 level; - PyObject *info, *result = NULL, *creds = NULL, *level_obj; + PyObject *info, *result = NULL, *creds = NULL; WERROR werror; TALLOC_CTX *mem_ctx; struct cli_state *cli; @@ -328,29 +328,16 @@ PyObject *spoolss_addprinterdriver(PyObject *self, PyObject *args, goto done; } - if ((level_obj = PyDict_GetItemString(info, "level"))) { - - if (!PyInt_Check(level_obj)) { - PyErr_SetString(spoolss_error, - "level not an integer"); - goto done; - } - - level = PyInt_AsLong(level_obj); - - /* Only level 2, 3 supported by NT */ - - if (level != 3) { - PyErr_SetString(spoolss_error, - "unsupported info level"); - goto done; - } + if (!get_level_value(info, &level)) { + PyErr_SetString(spoolss_error, "invalid info level"); + return NULL; + } - } else { - PyErr_SetString(spoolss_error, "no info level present"); + if (level != 3) { + PyErr_SetString(spoolss_error, "unsupported info level"); goto done; } - + ZERO_STRUCT(ctr); switch(level) { -- cgit From 281ded3f7fdb9174bbfe264328c1a43269a66f33 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Fri, 17 May 2002 02:32:02 +0000 Subject: addform(), setform(): - call get_level_value() utility function - removed unused keyword args - clean up handling of name arg to cli call deleteform(): - removed unused keyword args (This used to be commit c9c2aac9035a11e3fe2d320504097b98a426dd63) --- source3/python/py_spoolss_forms.c | 70 ++++++++++++++++++++++++--------------- 1 file changed, 44 insertions(+), 26 deletions(-) (limited to 'source3/python') diff --git a/source3/python/py_spoolss_forms.c b/source3/python/py_spoolss_forms.c index b0fe43dd57..c677a37fb7 100644 --- a/source3/python/py_spoolss_forms.c +++ b/source3/python/py_spoolss_forms.c @@ -26,36 +26,47 @@ PyObject *spoolss_hnd_addform(PyObject *self, PyObject *args, PyObject *kw) { spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self; WERROR werror; - PyObject *py_form, *py_form_name; - char *form_name; + PyObject *info; FORM form; - int level = 1; - static char *kwlist[] = {"form", "level", NULL}; + int level; + static char *kwlist[] = {"form", NULL}; /* Parse parameters */ - + if (!PyArg_ParseTupleAndKeywords( - args, kw, "O!|i", kwlist, &PyDict_Type, &py_form, &level)) + args, kw, "O!", kwlist, &PyDict_Type, &info)) return NULL; /* Call rpc function */ - - if (!py_to_FORM(&form, py_form) || - !(py_form_name = PyDict_GetItemString(py_form, "name")) || - !(form_name = PyString_AsString(py_form_name))) { + + 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: + 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); @@ -121,32 +132,39 @@ PyObject *spoolss_hnd_setform(PyObject *self, PyObject *args, PyObject *kw) { spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self; WERROR werror; - PyObject *py_form, *py_form_name; - int level = 1; - static char *kwlist[] = {"form", "level", NULL}; - char *form_name; + PyObject *info, *form_name; + int level; + static char *kwlist[] = { "form", NULL}; FORM form; /* Parse parameters */ if (!PyArg_ParseTupleAndKeywords( - args, kw, "O!|i", kwlist, &PyDict_Type, &py_form, - &level)) + args, kw, "O!|i", 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, py_form) || - !(py_form_name = PyDict_GetItemString(py_form, "name")) || - !(form_name = PyString_AsString(py_form_name))) { + if (!py_to_FORM(&form, info)) { PyErr_SetString(spoolss_error, "invalid form"); return NULL; } - init_unistr2(&form.name, form_name, strlen(form_name) + 1); + form_name = PyDict_GetItemString(info, "name"); - werror = cli_spoolss_setform(hnd->cli, hnd->mem_ctx, &hnd->pol, - level, form_name, &form); + 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)); @@ -163,7 +181,7 @@ 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", "level", NULL}; + static char *kwlist[] = {"form_name", NULL}; char *form_name; /* Parse parameters */ -- cgit From 296583a5e1fc6eb58c14863855e652416983e7a4 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Fri, 17 May 2002 02:34:49 +0000 Subject: Add level field when converting FORM_1 to dict. More error checking when converting from dict to FORM_1. (This used to be commit 608b9ab29dca820d29a40a2c5df86c1ff7e751a9) --- source3/python/py_spoolss_forms_conv.c | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'source3/python') diff --git a/source3/python/py_spoolss_forms_conv.c b/source3/python/py_spoolss_forms_conv.c index 2ded9afe91..604777adcd 100644 --- a/source3/python/py_spoolss_forms_conv.c +++ b/source3/python/py_spoolss_forms_conv.c @@ -47,11 +47,27 @@ struct pyconv py_FORM_1[] = { BOOL py_from_FORM_1(PyObject **dict, FORM_1 *form) { *dict = from_struct(form, py_FORM_1); + + PyDict_SetItemString(*dict, "level", PyInt_FromLong(1)); + return True; } BOOL py_to_FORM(FORM *form, PyObject *dict) { - to_struct(form, dict, py_FORM); + PyObject *obj; + char *name; + + if (!to_struct(form, dict, py_FORM)) + return False; + + if (!(obj = PyDict_GetItemString(dict, "name")) || + !PyString_Check(obj)) + return False; + + name = PyString_AsString(obj); + + init_unistr2(&form->name, name, strlen(name) + 1); + return True; } -- cgit From 4f783edcf3a01572589866031fa312316a703a34 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Fri, 17 May 2002 02:39:07 +0000 Subject: Use get_level_value() utility fn. Cleaned up some local variable naming. (This used to be commit d4c7a85c2b5c45f1cc3273230d80a1d5923cd848) --- source3/python/py_spoolss_jobs.c | 35 +++++++++++------------------------ source3/python/py_spoolss_printers.c | 29 +++++++---------------------- 2 files changed, 18 insertions(+), 46 deletions(-) (limited to 'source3/python') diff --git a/source3/python/py_spoolss_jobs.c b/source3/python/py_spoolss_jobs.c index 856e6252ea..cc5d42e0ee 100644 --- a/source3/python/py_spoolss_jobs.c +++ b/source3/python/py_spoolss_jobs.c @@ -224,42 +224,29 @@ PyObject *spoolss_hnd_startdocprinter(PyObject *self, PyObject *args, PyObject * spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self; WERROR werror; static char *kwlist[] = { "document_info", NULL }; - PyObject *doc_info, *obj; + 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, &doc_info)) + args, kw, "O!", kwlist, &PyDict_Type, &info)) return NULL; /* Check document_info parameter */ - if ((obj = PyDict_GetItemString(doc_info, "level"))) { - - if (!PyInt_Check(obj)) { - PyErr_SetString(spoolss_error, - "level not an integer"); - return NULL; - } - - level = PyInt_AsLong(obj); - - /* Only level 1 supported by Samba! */ - - if (level != 1) { - PyErr_SetString(spoolss_error, - "unsupported info level"); - return NULL; - } + if (!get_level_value(info, &level)) { + PyErr_SetString(spoolss_error, "invalid info level"); + return NULL; + } - } else { - PyErr_SetString(spoolss_error, "no info level present"); + if (level != 1) { + PyErr_SetString(spoolss_error, "unsupported info level"); return NULL; } - if ((obj = PyDict_GetItemString(doc_info, "document_name"))) { + if ((obj = PyDict_GetItemString(info, "document_name"))) { if (!PyString_Check(obj) && obj != Py_None) { PyErr_SetString(spoolss_error, @@ -275,7 +262,7 @@ PyObject *spoolss_hnd_startdocprinter(PyObject *self, PyObject *args, PyObject * return NULL; } - if ((obj = PyDict_GetItemString(doc_info, "output_file"))) { + if ((obj = PyDict_GetItemString(info, "output_file"))) { if (!PyString_Check(obj) && obj != Py_None) { PyErr_SetString(spoolss_error, @@ -291,7 +278,7 @@ PyObject *spoolss_hnd_startdocprinter(PyObject *self, PyObject *args, PyObject * return NULL; } - if ((obj = PyDict_GetItemString(doc_info, "data_type"))) { + if ((obj = PyDict_GetItemString(info, "data_type"))) { if (!PyString_Check(obj) && obj != Py_None) { PyErr_SetString(spoolss_error, diff --git a/source3/python/py_spoolss_printers.c b/source3/python/py_spoolss_printers.c index 2edad20fda..54ea54682d 100644 --- a/source3/python/py_spoolss_printers.c +++ b/source3/python/py_spoolss_printers.c @@ -177,7 +177,7 @@ PyObject *spoolss_hnd_setprinter(PyObject *self, PyObject *args, PyObject *kw) { spoolss_policy_hnd_object *hnd = (spoolss_policy_hnd_object *)self; WERROR werror; - PyObject *info, *level_obj; + PyObject *info; PRINTER_INFO_CTR ctr; uint32 level; static char *kwlist[] = {"dict", NULL}; @@ -192,28 +192,13 @@ PyObject *spoolss_hnd_setprinter(PyObject *self, PyObject *args, PyObject *kw) args, kw, "O!", kwlist, &PyDict_Type, &info)) return NULL; - /* Check dictionary contains a level */ - - if ((level_obj = PyDict_GetItemString(info, "level"))) { - - if (!PyInt_Check(level_obj)) { - PyErr_SetString(spoolss_error, - "level not an integer"); - return NULL; - } - - level = PyInt_AsLong(level_obj); - - /* Only level 2, 3 supported by NT */ - - if (level != 2 && level != 3) { - PyErr_SetString(spoolss_error, - "unsupported info level"); - return NULL; - } + if (!get_level_value(info, &level)) { + PyErr_SetString(spoolss_error, "invalid info level"); + return NULL; + } - } else { - PyErr_SetString(spoolss_error, "no info level present"); + if (level != 2 && level != 3) { + PyErr_SetString(spoolss_error, "unsupported info level"); return NULL; } -- cgit From d62adde88a47f944bc938ac35b153d283b0a74d7 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 20 May 2002 02:55:35 +0000 Subject: Set level key in driver info structures. (This used to be commit 0caf7610dcf698d2c649e42f0630de4337cfcea2) --- source3/python/py_spoolss_drivers_conv.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'source3/python') diff --git a/source3/python/py_spoolss_drivers_conv.c b/source3/python/py_spoolss_drivers_conv.c index 446a465f3e..07823bd3ff 100644 --- a/source3/python/py_spoolss_drivers_conv.c +++ b/source3/python/py_spoolss_drivers_conv.c @@ -64,7 +64,6 @@ struct pyconv py_DRIVER_INFO_6[] = { { "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) }, @@ -84,6 +83,7 @@ struct pyconv py_DRIVER_DIRECTORY_1[] = { 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; } @@ -95,6 +95,7 @@ BOOL py_to_DRIVER_INFO_1(DRIVER_INFO_1 *info, PyObject *dict) 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; } @@ -106,6 +107,7 @@ BOOL py_to_DRIVER_INFO_2(DRIVER_INFO_2 *info, PyObject *dict) BOOL py_from_DRIVER_INFO_3(PyObject **dict, DRIVER_INFO_3 *info) { *dict = from_struct(info, py_DRIVER_INFO_3); + PyDict_SetItemString(*dict, "level", PyInt_FromLong(3)); return True; } @@ -119,6 +121,7 @@ BOOL py_to_DRIVER_INFO_3(DRIVER_INFO_3 *info, PyObject *dict) 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; } @@ -130,6 +133,7 @@ BOOL py_to_DRIVER_INFO_6(DRIVER_INFO_6 *info, PyObject *dict) 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; } -- cgit From 1aa06209a155f453f55686f48e420432ff62892c Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 20 May 2002 08:04:02 +0000 Subject: When converting from a dictionary to a Samba structure, check for any additional keys that may have been added and return False if so. (This used to be commit 96ccb2beb1d45f8122ff03fc2f7727bf065adbf6) --- source3/python/py_conv.c | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) (limited to 'source3/python') diff --git a/source3/python/py_conv.c b/source3/python/py_conv.c index c6f39515af..9093b54b00 100644 --- a/source3/python/py_conv.c +++ b/source3/python/py_conv.c @@ -80,15 +80,19 @@ PyObject *from_struct(void *s, struct pyconv *conv) 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) - return False; + goto done; switch (conv[i].type) { case PY_UNISTR: { @@ -125,7 +129,31 @@ BOOL to_struct(void *s, PyObject *dict, struct pyconv *conv) default: break; } + + /* Mark as visited */ + + PyDict_SetItemString(visited, conv[i].name, + PyInt_FromLong(1)); } - return True; + /* 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; } -- cgit From be92d4ac55caa3f44c5125cf4220bea4ca69e45e Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 20 May 2002 08:05:27 +0000 Subject: Decode info level 3 for getprinterdriver. Error checking for undecoded info levels. (This used to be commit 841b6cf63c1f22dcb8fa07796a44e20555fe5b59) --- source3/python/py_spoolss_drivers.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'source3/python') diff --git a/source3/python/py_spoolss_drivers.c b/source3/python/py_spoolss_drivers.c index e95d548ef1..1626684a1b 100644 --- a/source3/python/py_spoolss_drivers.c +++ b/source3/python/py_spoolss_drivers.c @@ -210,11 +210,15 @@ PyObject *spoolss_hnd_getprinterdriver(PyObject *self, PyObject *args, 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: - break; + PyErr_SetString(spoolss_error, "unsupported info level"); + return NULL; } Py_INCREF(result); -- cgit From 03a83917874cf699b5936aa3fee7922199b4e05e Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 20 May 2002 08:07:49 +0000 Subject: py_to_DRIVER_INFO_3: remove level key on copy of dictionary before calling to_struct(). (This used to be commit 274679d8ce33aaf664ffaaa6834d506f7b196fc6) --- source3/python/py_spoolss_drivers_conv.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'source3/python') diff --git a/source3/python/py_spoolss_drivers_conv.c b/source3/python/py_spoolss_drivers_conv.c index 07823bd3ff..dbf33905ae 100644 --- a/source3/python/py_spoolss_drivers_conv.c +++ b/source3/python/py_spoolss_drivers_conv.c @@ -113,9 +113,14 @@ BOOL py_from_DRIVER_INFO_3(PyObject **dict, DRIVER_INFO_3 *info) BOOL py_to_DRIVER_INFO_3(DRIVER_INFO_3 *info, PyObject *dict) { - to_struct(info, dict, py_DRIVER_INFO_3); + PyObject *dict_copy = PyDict_Copy(dict); + BOOL result; - return True; + 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) -- cgit From 641d6dc79e5d16e1fdb6c0986ea850dffddb7d86 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 20 May 2002 08:09:19 +0000 Subject: Remove level and name fields from dictionary copy in py_to_FORM() (This used to be commit ac15442579848f145dbdce6d51207321c4150c25) --- source3/python/py_spoolss_forms_conv.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'source3/python') diff --git a/source3/python/py_spoolss_forms_conv.c b/source3/python/py_spoolss_forms_conv.c index 604777adcd..1b006cbf51 100644 --- a/source3/python/py_spoolss_forms_conv.c +++ b/source3/python/py_spoolss_forms_conv.c @@ -55,16 +55,21 @@ BOOL py_from_FORM_1(PyObject **dict, FORM_1 *form) BOOL py_to_FORM(FORM *form, PyObject *dict) { - PyObject *obj; + PyObject *obj, *dict_copy = PyDict_Copy(dict); char *name; - if (!to_struct(form, dict, py_FORM)) - return False; - if (!(obj = PyDict_GetItemString(dict, "name")) || !PyString_Check(obj)) return False; + PyDict_DelItemString(dict_copy, "level"); + PyDict_DelItemString(dict_copy, "name"); + + if (!to_struct(form, dict_copy, py_FORM)) { + Py_DECREF(dict_copy); + return False; + } + name = PyString_AsString(obj); init_unistr2(&form->name, name, strlen(name) + 1); -- cgit From 8a35fba95bd966924216dc959b4edd18bd2bd47c Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Tue, 21 May 2002 07:43:35 +0000 Subject: A tdb module based on some tips from Mike Noriega. This version supports locking and tdb traversal using python callbacks. (This used to be commit f3530fd6180bb78a58a3f41ac1389c9f0ba7b183) --- source3/python/py_tdb.c | 606 +++++++++++++++++++++++++++++++++++++++++++++ source3/python/py_tdb.h | 29 +++ source3/python/setup.py.in | 9 + 3 files changed, 644 insertions(+) create mode 100644 source3/python/py_tdb.c create mode 100644 source3/python/py_tdb.h (limited to 'source3/python') diff --git a/source3/python/py_tdb.c b/source3/python/py_tdb.c new file mode 100644 index 0000000000..134eb93f54 --- /dev/null +++ b/source3/python/py_tdb.c @@ -0,0 +1,606 @@ +/* + Python wrappers for TDB module + + 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" + +/* Tdb exception */ + +PyObject *py_tdb_error; + +/* tdb handle object */ + +typedef struct { + PyObject_HEAD + TDB_CONTEXT *tdb; +} tdb_hnd_object; + +PyTypeObject tdb_hnd_type; + +PyObject *new_tdb_hnd_object(TDB_CONTEXT *tdb) +{ + tdb_hnd_object *obj; + + obj = PyObject_New(tdb_hnd_object, &tdb_hnd_type); + obj->tdb = tdb; + + return (PyObject *)obj; +} + +PyObject *py_tdb_close(PyObject *self, PyObject *args) +{ + tdb_hnd_object *obj; + + if (!PyArg_ParseTuple(args, "O!", &tdb_hnd_type, &obj)) + return NULL; + + if (tdb_close(obj->tdb) == -1) { + obj->tdb = NULL; + PyErr_SetString(py_tdb_error, strerror(errno)); + return NULL; + } + + obj->tdb = NULL; + + Py_INCREF(Py_None); + return Py_None; +} + +PyObject *py_tdb_open(PyObject *self, PyObject *args, PyObject *kw) +{ + static char *kwlist[] = { "name", "hash_size", "tdb_flags", + "open_flags", "mode", NULL }; + char *name; + int hash_size = 0, flags = TDB_DEFAULT, open_flags = -1, open_mode = 0600; + TDB_CONTEXT *tdb; + + if (!PyArg_ParseTupleAndKeywords( + args, kw, "s|iiii", kwlist, &name, &hash_size, &flags, + &open_flags, &open_mode)) + return NULL; + + /* Default open_flags to read/write */ + + if (open_flags == -1) { + if (access(name, W_OK) == -1) + open_flags = O_RDONLY; + else + open_flags = O_RDWR; + } + + if (!(tdb = tdb_open(name, hash_size, flags, open_flags, open_mode))) { + PyErr_SetString(py_tdb_error, strerror(errno)); + return NULL; + } + + return new_tdb_hnd_object(tdb); +} + +/* + * Allow a tdb to act as a python mapping (dictionary) + */ + +static int tdb_traverse_count(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA value, + void *state) +{ + /* Do nothing - tdb_traverse will return the number of records + traversed. */ + + return 0; +} + +static int tdb_hnd_length(tdb_hnd_object *obj) +{ + int result; + + result = tdb_traverse(obj->tdb, tdb_traverse_count, NULL); + + return result; +} + +static PyObject *tdb_hnd_subscript(tdb_hnd_object *obj, PyObject *key) +{ + TDB_DATA drec, krec; + PyObject *result; + + if (!PyArg_Parse(key, "s#", &krec.dptr, &krec.dsize)) + return NULL; + + drec = tdb_fetch(obj->tdb, krec); + + if (!drec.dptr) { + PyErr_SetString(PyExc_KeyError, + PyString_AsString(key)); + return NULL; + } + + result = PyString_FromStringAndSize(drec.dptr, drec.dsize); + free(drec.dptr); + + return result; +} + +static int tdb_ass_subscript(tdb_hnd_object *obj, PyObject *key, PyObject *value) +{ + TDB_DATA krec, drec; + + if (!PyArg_Parse(key, "s#", &krec.dptr, &krec.dsize)) { + PyErr_SetString(PyExc_TypeError, + "tdb mappings have string indices only"); + return -1; + } + + if (!obj->tdb) { + PyErr_SetString( + py_tdb_error, "tdb object has been closed"); + return -1; + } + + if (!value) { + + /* Delete value */ + + if (tdb_delete(obj->tdb, krec) == -1) { + PyErr_SetString(PyExc_KeyError, + PyString_AsString(value)); + return -1; + } + + } else { + + /* Set value */ + + if (!PyArg_Parse(value, "s#", &drec.dptr, &drec.dsize)) { + PyErr_SetString(PyExc_TypeError, + "tdb mappings have string elements only"); + return -1; + } + + errno = 0; + + if (tdb_store(obj->tdb, krec, drec, 0) < 0 ) { + if (errno != 0) + PyErr_SetFromErrno(py_tdb_error); + else + PyErr_SetString( + py_tdb_error, + (char *)tdb_errorstr(obj->tdb)); + + return -1; + } + } + + return 0; +} + +static PyMappingMethods tdb_mapping = { + (inquiry) tdb_hnd_length, + (binaryfunc) tdb_hnd_subscript, + (objobjargproc) tdb_ass_subscript +}; + +/* + * Utility methods + */ + +/* Return non-zero if a given key exists in the tdb */ + +PyObject *py_tdb_hnd_has_key(PyObject *self, PyObject *args) +{ + tdb_hnd_object *obj = (tdb_hnd_object *)self; + TDB_DATA key; + + if (!PyArg_ParseTuple(args, "s#", &key.dptr, &key.dsize)) + return NULL; + + if (!obj->tdb) { + PyErr_SetString( + py_tdb_error, "tdb object has been closed"); + return NULL; + } + + return PyInt_FromLong(tdb_exists(obj->tdb, key)); +} + +/* Return a list of keys in the tdb */ + +static int tdb_traverse_keys(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA value, + void *state) +{ + PyObject *key_list = (PyObject *)state; + + PyList_Append(key_list, + PyString_FromStringAndSize(key.dptr, key.dsize)); + + return 0; +} + +PyObject *py_tdb_hnd_keys(PyObject *self, PyObject *args) +{ + tdb_hnd_object *obj = (tdb_hnd_object *)self; + PyObject *key_list = PyList_New(0); + + if (!obj->tdb) { + PyErr_SetString(py_tdb_error, "tdb object has been closed"); + return NULL; + } + + if (tdb_traverse(obj->tdb, tdb_traverse_keys, key_list) == -1) { + PyErr_SetString(py_tdb_error, "error traversing tdb"); + Py_DECREF(key_list); + return NULL; + } + + return key_list; +} + +PyObject *py_tdb_hnd_first_key(PyObject *self, PyObject *args) +{ + tdb_hnd_object *obj = (tdb_hnd_object *)self; + TDB_DATA key; + + if (!obj->tdb) { + PyErr_SetString(py_tdb_error, "tdb object has been closed"); + return NULL; + } + + key = tdb_firstkey(obj->tdb); + + return Py_BuildValue("s#", key.dptr, key.dsize); +} + +PyObject *py_tdb_hnd_next_key(PyObject *self, PyObject *py_oldkey) +{ + tdb_hnd_object *obj = (tdb_hnd_object *)self; + TDB_DATA key, oldkey; + + if (!obj->tdb) { + PyErr_SetString(py_tdb_error, "tdb object has been closed"); + return NULL; + } + + if (!PyArg_Parse(py_oldkey, "s#", &oldkey.dptr, &oldkey.dsize)) + return NULL; + + key = tdb_nextkey(obj->tdb, oldkey); + + return Py_BuildValue("s#", key.dptr, key.dsize); +} + +/* + * Locking routines + */ + +PyObject *py_tdb_hnd_lock_all(PyObject *self, PyObject *args) +{ + tdb_hnd_object *obj = (tdb_hnd_object *)self; + int result; + + if (!obj->tdb) { + PyErr_SetString(py_tdb_error, "tdb object has been closed"); + return NULL; + } + + result = tdb_lockall(obj->tdb); + + return PyInt_FromLong(result != -1); +} + +PyObject *py_tdb_hnd_unlock_all(PyObject *self, PyObject *args) +{ + tdb_hnd_object *obj = (tdb_hnd_object *)self; + + if (!obj->tdb) { + PyErr_SetString(py_tdb_error, "tdb object has been closed"); + return NULL; + } + + tdb_unlockall(obj->tdb); + + Py_INCREF(Py_None); + return Py_None; +} + +/* Return an array of keys from a python object which must be a string or a + list of strings. */ + +static BOOL make_lock_list(PyObject *py_keys, TDB_DATA **keys, int *num_keys) +{ + /* Are we a list or a string? */ + + if (!PyList_Check(py_keys) && !PyString_Check(py_keys)) { + PyErr_SetString(PyExc_TypeError, "arg must be list of string"); + return False; + } + + if (PyList_Check(py_keys)) { + int i; + + /* Turn python list into array of keys */ + + *num_keys = PyList_Size(py_keys); + *keys = (TDB_DATA *)malloc(sizeof(TDB_DATA) * (*num_keys)); + + for (i = 0; i < *num_keys; i++) { + PyObject *key = PyList_GetItem(py_keys, i); + + if (!PyString_Check(key)) { + PyErr_SetString( + PyExc_TypeError, + "list elements must be strings"); + return False; + } + + PyArg_Parse(key, "s#", &(*keys)[i].dptr, + &(*keys)[i].dsize); + } + + } else { + + /* Turn python string into a single key */ + + *keys = (TDB_DATA *)malloc(sizeof(TDB_DATA)); + *num_keys = 1; + PyArg_Parse(py_keys, "s#", &(*keys)->dptr, &(*keys)->dsize); + } + + return True; +} + +PyObject *py_tdb_hnd_lock(PyObject *self, PyObject *args) +{ + tdb_hnd_object *obj = (tdb_hnd_object *)self; + PyObject *py_keys; + TDB_DATA *keys; + int num_keys, result; + + if (!obj->tdb) { + PyErr_SetString(py_tdb_error, "tdb object has been closed"); + return NULL; + } + + if (!PyArg_ParseTuple(args, "O", &py_keys)) + return NULL; + + if (!make_lock_list(py_keys, &keys, &num_keys)) + return NULL; + + result = tdb_lockkeys(obj->tdb, num_keys, keys); + + free(keys); + + return PyInt_FromLong(result != -1); +} + +PyObject *py_tdb_hnd_unlock(PyObject *self, PyObject *args) +{ + tdb_hnd_object *obj = (tdb_hnd_object *)self; + + if (!obj->tdb) { + PyErr_SetString(py_tdb_error, "tdb object has been closed"); + return NULL; + } + + if (!PyArg_ParseTuple(args, "")) + return NULL; + + tdb_unlockkeys(obj->tdb); + + Py_INCREF(Py_None); + return Py_None; +} + +/* + * tdb traversal + */ + +struct traverse_info { + PyObject *callback; + PyObject *state; +}; + +static int tdb_traverse_traverse(TDB_CONTEXT *tdb, TDB_DATA key, TDB_DATA value, + void *state) +{ + struct traverse_info *info = state; + PyObject *arglist, *py_result; + int result; + + arglist = Py_BuildValue("(s#s#O)", key.dptr, key.dsize, value.dptr, + value.dsize, info->state); + + py_result = PyEval_CallObject(info->callback, arglist); + + Py_DECREF(arglist); + + if (!PyInt_Check(py_result)) { + result = 1; /* Hmm - non-integer object returned by callback */ + goto done; + } + + result = PyInt_AsLong(py_result); + +done: + Py_DECREF(py_result); + return result; +} + +PyObject *py_tdb_hnd_traverse(PyObject *self, PyObject *args, PyObject *kw) +{ + tdb_hnd_object *obj = (tdb_hnd_object *)self; + static char *kwlist[] = { "traverse_fn", "state", NULL }; + PyObject *state = Py_None, *callback; + struct traverse_info info; + int result; + + if (!PyArg_ParseTupleAndKeywords( + args, kw, "O|O", kwlist, &callback, &state)) + return NULL; + + if (!PyCallable_Check(callback)) { + PyErr_SetString(PyExc_TypeError, "parameter must be callable"); + return NULL; + } + + Py_INCREF(callback); + Py_INCREF(state); + + info.callback = callback; + info.state = state; + + result = tdb_traverse(obj->tdb, tdb_traverse_traverse, &info); + + Py_DECREF(callback); + Py_DECREF(state); + + return PyInt_FromLong(result); +} + +/* + * Method dispatch table for this module + */ + +static PyMethodDef tdb_methods[] = { + { "open", (PyCFunction)py_tdb_open, METH_VARARGS | METH_KEYWORDS }, + { "close", (PyCFunction)py_tdb_close, METH_VARARGS }, + { NULL } +}; + +/* + * Methods on a tdb object + */ + +static PyMethodDef tdb_hnd_methods[] = { + { "keys", (PyCFunction)py_tdb_hnd_keys, METH_VARARGS }, + { "has_key", (PyCFunction)py_tdb_hnd_has_key, METH_VARARGS }, + { "first_key", (PyCFunction)py_tdb_hnd_first_key, METH_VARARGS }, + { "next_key", (PyCFunction)py_tdb_hnd_next_key, METH_VARARGS }, + { "lock_all", (PyCFunction)py_tdb_hnd_lock_all, METH_VARARGS }, + { "unlock_all", (PyCFunction)py_tdb_hnd_unlock_all, METH_VARARGS }, + { "lock", (PyCFunction)py_tdb_hnd_lock, METH_VARARGS }, + { "unlock", (PyCFunction)py_tdb_hnd_unlock, METH_VARARGS }, + { "traverse", (PyCFunction)py_tdb_hnd_traverse, METH_VARARGS | METH_KEYWORDS }, + { NULL } +}; + +/* Deallocate a tdb handle object */ + +static void tdb_hnd_dealloc(PyObject* self) +{ + tdb_hnd_object *hnd = (tdb_hnd_object *)self; + + if (hnd->tdb) { + tdb_close(hnd->tdb); + hnd->tdb = NULL; + } +} + +/* Return tdb handle attributes */ + +static PyObject *tdb_hnd_getattr(PyObject *self, char *attrname) +{ + return Py_FindMethod(tdb_hnd_methods, self, attrname); +} + +static char tdb_hnd_type_doc[] = +"Python wrapper for tdb."; + +PyTypeObject tdb_hnd_type = { + PyObject_HEAD_INIT(NULL) + 0, + "tdb", + sizeof(tdb_hnd_object), + 0, + tdb_hnd_dealloc, /* tp_dealloc*/ + 0, /* tp_print*/ + tdb_hnd_getattr, /* tp_getattr*/ + 0, /* tp_setattr*/ + 0, /* tp_compare*/ + 0, /* tp_repr*/ + 0, /* tp_as_number*/ + 0, /* tp_as_sequence*/ + &tdb_mapping, /* 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 */ + tdb_hnd_type_doc, /* tp_doc */ +}; + +/* Constants */ + +static struct const_vals { + char *name; + uint32 value; +} module_const_vals[] = { + + /* Flags for tdb_open() */ + + { "TDB_DEFAULT", TDB_DEFAULT }, + { "TDB_CLEAR_IF_FIRST", TDB_CLEAR_IF_FIRST }, + { "TDB_INTERNAL", TDB_INTERNAL }, + { "TDB_NOLOCK", TDB_NOLOCK }, + { "TDB_NOMMAP", TDB_NOMMAP }, + { "TDB_CONVERT", TDB_CONVERT }, + { "TDB_BIGENDIAN", TDB_BIGENDIAN }, + + { 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 inittdb(void) +{ + PyObject *module, *dict; + + /* Initialise module */ + + module = Py_InitModule("tdb", tdb_methods); + dict = PyModule_GetDict(module); + + py_tdb_error = PyErr_NewException("tdb.error", NULL, NULL); + PyDict_SetItemString(dict, "error", py_tdb_error); + + /* Initialise policy handle object */ + + tdb_hnd_type.ob_type = &PyType_Type; + + PyDict_SetItemString(dict, "tdb.hnd", + (PyObject *)&tdb_hnd_type); + + /* Initialise constants */ + + const_init(dict); +} diff --git a/source3/python/py_tdb.h b/source3/python/py_tdb.h new file mode 100644 index 0000000000..d4ce4920a6 --- /dev/null +++ b/source3/python/py_tdb.h @@ -0,0 +1,29 @@ +/* + 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_TDB_H +#define _PY_TDB_H + +#include "includes.h" +#include "Python.h" + +#include "python/py_common.h" + +#endif /* _PY_TDB_H */ diff --git a/source3/python/setup.py.in b/source3/python/setup.py.in index ceb86854c0..0895e25c08 100755 --- a/source3/python/setup.py.in +++ b/source3/python/setup.py.in @@ -141,5 +141,14 @@ setup( 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), + ], ) -- cgit From dc86e2b710048653fa75a3c39ca8a153a5a10e23 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Wed, 22 May 2002 00:43:04 +0000 Subject: Added a reminder about programs using the tdb bindings having to be licensed under the GPL. (This used to be commit aa3ec7618fe39ddc75755098433572b271197af4) --- source3/python/py_tdb.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'source3/python') diff --git a/source3/python/py_tdb.c b/source3/python/py_tdb.c index 134eb93f54..7d82d1177e 100644 --- a/source3/python/py_tdb.c +++ b/source3/python/py_tdb.c @@ -18,6 +18,14 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +/* + NOTE: Since tdb is licensed under the gdb, any program that uses these + bindings must also be licensed under the GPL. See the following URL for + details: + + http://www.gnu.org/licenses/gpl-faq.html#IfInterpreterIsGPL +*/ + #include "includes.h" #include "Python.h" -- cgit From 8955286b321db3b3283e99706cf294f191cdcc78 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Wed, 22 May 2002 23:31:44 +0000 Subject: Got gdb and gpl confused. (-: (This used to be commit 08356ec38a5be239b6ab53ee75f3735c29b677a7) --- source3/python/py_tdb.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/python') diff --git a/source3/python/py_tdb.c b/source3/python/py_tdb.c index 7d82d1177e..ae47924e25 100644 --- a/source3/python/py_tdb.c +++ b/source3/python/py_tdb.c @@ -19,9 +19,9 @@ */ /* - NOTE: Since tdb is licensed under the gdb, any program that uses these - bindings must also be licensed under the GPL. See the following URL for - details: + NOTE: Since tdb is licensed under the GPL, any program that uses these + bindings must also be licensed under the GPL or a GPL compatible + license. See the following URL for details: http://www.gnu.org/licenses/gpl-faq.html#IfInterpreterIsGPL */ -- cgit From c6d53c2798d07bc66d1bcc7112d3e73b8bf6d33b Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Thu, 23 May 2002 02:36:53 +0000 Subject: Another change to the GPL "abandon hope all who enter here" warning. (This used to be commit 1d75b548de8b667673cf136306388546eb3bd98d) --- source3/python/py_tdb.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source3/python') diff --git a/source3/python/py_tdb.c b/source3/python/py_tdb.c index ae47924e25..4969c1047e 100644 --- a/source3/python/py_tdb.c +++ b/source3/python/py_tdb.c @@ -19,11 +19,11 @@ */ /* - NOTE: Since tdb is licensed under the GPL, any program that uses these - bindings must also be licensed under the GPL or a GPL compatible - license. See the following URL for details: + NOTE: Since tdb is licenced under the GPL any program that uses these bindings + must be distributed under the GPL license terms since this is what + the GPL requires. - http://www.gnu.org/licenses/gpl-faq.html#IfInterpreterIsGPL + http://www.gnu.org/licenses/gpl-faq.html#IfInterpreterIsGPL */ #include "includes.h" -- cgit From 4f46de7972eaab44b492f2cfe8a9d9c2a728766c Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Thu, 23 May 2002 05:10:51 +0000 Subject: A graphical tdb browser using the gnome-python bindings. (This used to be commit 08dcfff2a22fd35a3e5cdca8ed137a7e5891fe53) --- source3/python/gtdbtool | 166 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 166 insertions(+) create mode 100755 source3/python/gtdbtool (limited to 'source3/python') diff --git a/source3/python/gtdbtool b/source3/python/gtdbtool new file mode 100755 index 0000000000..cb88792acc --- /dev/null +++ b/source3/python/gtdbtool @@ -0,0 +1,166 @@ +#!/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 + + # 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.set_usize(350,400) + scrolled_win.show() + + hbox = GtkHBox() + vbox.pack_end(hbox) + hbox.show() + + label = GtkLabel("Filter:") + hbox.pack_start(label, expand = 0) + label.show() + + self.entry = GtkEntry() + hbox.pack_end(self.entry) + 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(350,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.filter_regex = "" + + 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()) + self.text.insert_defaults(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() + self.set_value_text(t[list_item.get_data("raw_key")]) + + # 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 + +# Open handle on tdb + +t = tdb.open(sys.argv[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) + +# Show user interface + +w.build_ui("gtdbtool: %s" % sys.argv[1]) + +mainloop() -- cgit From 6a663f5a2af537e8f982abe79785535c702302bb Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Thu, 23 May 2002 22:53:59 +0000 Subject: Compile fix for enum trust dom wrapper. (This used to be commit 63e2c7c5fe6eca86222a7a76d81ce1ee93ebde22) --- source3/python/py_lsa.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/python') diff --git a/source3/python/py_lsa.c b/source3/python/py_lsa.c index 0f71187aa6..04af993e3e 100644 --- a/source3/python/py_lsa.c +++ b/source3/python/py_lsa.c @@ -270,7 +270,7 @@ static PyObject *lsa_enum_trust_dom(PyObject *self, PyObject *args) ntstatus = cli_lsa_enum_trust_dom(hnd->cli, hnd->mem_ctx, &hnd->pol, &enum_ctx, &num_domains, &domain_names, - &domain_sids); + &domain_names, &domain_sids); if (!NT_STATUS_IS_OK(ntstatus)) { PyErr_SetObject(lsa_ntstatus, py_ntstatus_tuple(ntstatus)); -- cgit From 82e4fb6fbbd2b2357a0ed0f1ecfe12532eb84897 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 27 May 2002 06:23:30 +0000 Subject: Some rearrangement of header files. (This used to be commit 0b2bd0a2290315056789f6aa1421678583086fc6) --- source3/python/py_lsa.h | 2 +- source3/python/py_samr.h | 2 +- source3/python/py_spoolss.h | 2 +- source3/python/py_tdb.h | 2 +- source3/python/py_winreg.h | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) (limited to 'source3/python') diff --git a/source3/python/py_lsa.h b/source3/python/py_lsa.h index a963fcac98..f9a30d2f7e 100644 --- a/source3/python/py_lsa.h +++ b/source3/python/py_lsa.h @@ -24,7 +24,7 @@ #include "includes.h" #include "Python.h" -#include "python/py_common.h" +#include "python/py_common_proto.h" /* LSA policy handle object */ diff --git a/source3/python/py_samr.h b/source3/python/py_samr.h index 52352cc64d..326bab5c14 100644 --- a/source3/python/py_samr.h +++ b/source3/python/py_samr.h @@ -24,7 +24,7 @@ #include "includes.h" #include "Python.h" -#include "python/py_common.h" +#include "python/py_common_proto.h" /* SAMR connect policy handle object */ diff --git a/source3/python/py_spoolss.h b/source3/python/py_spoolss.h index 777a2b5991..40a6ae972e 100644 --- a/source3/python/py_spoolss.h +++ b/source3/python/py_spoolss.h @@ -24,7 +24,7 @@ #include "includes.h" #include "Python.h" -#include "python/py_common.h" +#include "python/py_common_proto.h" /* Spoolss policy handle object */ diff --git a/source3/python/py_tdb.h b/source3/python/py_tdb.h index d4ce4920a6..794a20cf2b 100644 --- a/source3/python/py_tdb.h +++ b/source3/python/py_tdb.h @@ -24,6 +24,6 @@ #include "includes.h" #include "Python.h" -#include "python/py_common.h" +#include "python/py_common_proto.h" #endif /* _PY_TDB_H */ diff --git a/source3/python/py_winreg.h b/source3/python/py_winreg.h index e19674d218..088be724e2 100644 --- a/source3/python/py_winreg.h +++ b/source3/python/py_winreg.h @@ -24,6 +24,6 @@ #include "includes.h" #include "Python.h" -#include "python/py_common.h" +#include "python/py_common_proto.h" #endif /* _PY_WINREG_H */ -- cgit From b403e16e09db52b31bdf09a97fe81b82835da129 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 27 May 2002 06:28:18 +0000 Subject: Fixed dodgy arguments to PyArg_ParseTupleAndKeywords() (This used to be commit 45562b86039ec1b2f6d1cf3e9a5aa57cf87a796a) --- source3/python/py_spoolss_forms.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/python') diff --git a/source3/python/py_spoolss_forms.c b/source3/python/py_spoolss_forms.c index c677a37fb7..c216e00afe 100644 --- a/source3/python/py_spoolss_forms.c +++ b/source3/python/py_spoolss_forms.c @@ -140,7 +140,7 @@ PyObject *spoolss_hnd_setform(PyObject *self, PyObject *args, PyObject *kw) /* Parse parameters */ if (!PyArg_ParseTupleAndKeywords( - args, kw, "O!|i", kwlist, &PyDict_Type, &info)) + args, kw, "O!", kwlist, &PyDict_Type, &info)) return NULL; if (!get_level_value(info, &level)) { -- cgit From 3ec6d94f959d55f83dc065aee99abf49603a118b Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 27 May 2002 06:28:45 +0000 Subject: Fixed compiler warning. (This used to be commit 736eb3c7485c0e65a463f14f27ada55a1a3fd453) --- source3/python/py_spoolss_forms_conv.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'source3/python') diff --git a/source3/python/py_spoolss_forms_conv.c b/source3/python/py_spoolss_forms_conv.c index 1b006cbf51..6ef953cbc9 100644 --- a/source3/python/py_spoolss_forms_conv.c +++ b/source3/python/py_spoolss_forms_conv.c @@ -58,8 +58,9 @@ BOOL py_to_FORM(FORM *form, PyObject *dict) PyObject *obj, *dict_copy = PyDict_Copy(dict); char *name; - if (!(obj = PyDict_GetItemString(dict, "name")) || - !PyString_Check(obj)) + obj = PyDict_GetItemString(dict, "name"); + + if (!obj || !PyString_Check(obj)) return False; PyDict_DelItemString(dict_copy, "level"); -- cgit From bf7ca61cb4af4b156d954098ffa04cfa14a25641 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 27 May 2002 06:29:58 +0000 Subject: Honour return value of to_struct() when converting to Samba structures. (This used to be commit 1ef99e76632f6f6b866de491db8722c94f75a8c2) --- source3/python/py_spoolss_jobs_conv.c | 3 +-- source3/python/py_spoolss_printers_conv.c | 18 ++++++++++++++---- 2 files changed, 15 insertions(+), 6 deletions(-) (limited to 'source3/python') diff --git a/source3/python/py_spoolss_jobs_conv.c b/source3/python/py_spoolss_jobs_conv.c index 3481e96485..cb04ec6713 100644 --- a/source3/python/py_spoolss_jobs_conv.c +++ b/source3/python/py_spoolss_jobs_conv.c @@ -98,6 +98,5 @@ BOOL py_from_DOC_INFO_1(PyObject **dict, DOC_INFO_1 *info) BOOL py_to_DOC_INFO_1(DOC_INFO_1 *info, PyObject *dict) { - to_struct(info, dict, py_DOC_INFO_1); - return True; + return to_struct(info, dict, py_DOC_INFO_1); } diff --git a/source3/python/py_spoolss_printers_conv.c b/source3/python/py_spoolss_printers_conv.c index 676e21e99e..247db65b1e 100644 --- a/source3/python/py_spoolss_printers_conv.c +++ b/source3/python/py_spoolss_printers_conv.c @@ -163,7 +163,8 @@ BOOL py_to_DEVICEMODE(DEVICEMODE *devmode, PyObject *dict) { PyObject *obj; - to_struct(devmode, dict, py_DEVICEMODE); + if (!to_struct(devmode, dict, py_DEVICEMODE)) + return False; if (!(obj = PyDict_GetItemString(dict, "private"))) return False; @@ -203,7 +204,14 @@ BOOL py_from_PRINTER_INFO_1(PyObject **dict, PRINTER_INFO_1 *info) BOOL py_to_PRINTER_INFO_1(PRINTER_INFO_1 *info, PyObject *dict) { - return False; + 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; } /* @@ -232,7 +240,8 @@ BOOL py_to_PRINTER_INFO_2(PRINTER_INFO_2 *info, PyObject *dict, { PyObject *obj; - to_struct(info, dict, py_PRINTER_INFO_2); + if (!to_struct(info, dict, py_PRINTER_INFO_2)) + return False; if (!(obj = PyDict_GetItemString(dict, "security_descriptor"))) return False; @@ -274,7 +283,8 @@ BOOL py_to_PRINTER_INFO_3(PRINTER_INFO_3 *info, PyObject *dict, { PyObject *obj; - to_struct(info, dict, py_PRINTER_INFO_3); + if (!to_struct(info, dict, py_PRINTER_INFO_3)) + return False; if (!(obj = PyDict_GetItemString(dict, "security_descriptor"))) return False; -- cgit From f2cbcec5a4cd6dc6656b4966450c211be3ec451b Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 27 May 2002 06:32:11 +0000 Subject: Convert open_pipe_creds() to use new cli_full_connection() interface. Initialise global_myname in py_samba_init() function. (This used to be commit e5dcd3c7ccf0060d86a484b8307f747805b20c5f) --- source3/python/py_common.c | 59 ++++++++++++++++++++++------------------------ 1 file changed, 28 insertions(+), 31 deletions(-) (limited to 'source3/python') diff --git a/source3/python/py_common.c b/source3/python/py_common.c index 85305d027e..d81e141e9c 100644 --- a/source3/python/py_common.c +++ b/source3/python/py_common.c @@ -21,7 +21,7 @@ #include "includes.h" #include "Python.h" -#include "python/py_common.h" +#include "python/py_common_proto.h" /* Return a tuple of (error code, error string) from a WERROR */ @@ -45,6 +45,9 @@ static BOOL initialised; void py_samba_init(void) { + extern pstring global_myname; + char *p; + if (initialised) return; @@ -57,6 +60,11 @@ void py_samba_init(void) load_interfaces(); + fstrcpy(global_myname, myhostname()); + p = strchr(global_myname, '.'); + if (p) + *p = 0; + initialised = True; } @@ -124,27 +132,17 @@ PyObject *py_setup_logging(PyObject *self, PyObject *args, PyObject *kw) be freed by calling free(). */ struct cli_state *open_pipe_creds(char *server, PyObject *creds, - cli_pipe_fn *connect_fn, char **errstr) + char *pipe_name, char **errstr) { - struct ntuser_creds nt_creds; + char *username = "", *password = "", *domain = ""; struct cli_state *cli; + NTSTATUS result; + struct in_addr server_ip; + extern pstring global_myname; - cli = (struct cli_state *)malloc(sizeof(struct cli_state)); - if (!cli) { - *errstr = strdup("out of memory"); - return NULL; - } - - ZERO_STRUCTP(cli); - - /* Extract credentials from the python dictionary and initialise - the ntuser_creds struct from them. */ - - ZERO_STRUCT(nt_creds); - nt_creds.pwd.null_pwd = True; + /* Extract credentials from the python dictionary */ if (creds && PyDict_Size(creds) > 0) { - char *username, *password, *domain; PyObject *username_obj, *password_obj, *domain_obj; /* Check credentials passed are valid. This means the @@ -172,24 +170,23 @@ struct cli_state *open_pipe_creds(char *server, PyObject *creds, if (!username || !domain || !password) goto creds_error; - - /* Initialise nt_creds structure with passed creds */ - - fstrcpy(nt_creds.user_name, username); - fstrcpy(nt_creds.domain, domain); - - if (lp_encrypted_passwords()) - pwd_make_lm_nt_16(&nt_creds.pwd, password); - else - pwd_set_cleartext(&nt_creds.pwd, password); - - nt_creds.pwd.null_pwd = False; } /* Now try to connect */ - if (!connect_fn(cli, server, &nt_creds)) { - *errstr = strdup("error connecting to RPC pipe"); + if (!resolve_name(server, &server_ip, 0x20)) { + asprintf(errstr, "unable to resolve %s", server); + return NULL; + } + + result = cli_full_connection( + &cli, global_myname, server, &server_ip, 0, "IPC$", "IPC", + username, domain, password, strlen(password)); + + if (!NT_STATUS_IS_OK(result) || !cli_nt_session_open(cli, pipe_name)) { + cli_shutdown(cli); + free(cli); + *errstr = strdup("pipe not available"); return NULL; } -- cgit From 24def691ef1832d921e6f83daf9b1809de891bcf Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 27 May 2002 06:33:33 +0000 Subject: Check types of dictionary elements in to_struct() (This used to be commit 793f1042f153bd6ca3f75bebf719d47744ffecde) --- source3/python/py_conv.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'source3/python') diff --git a/source3/python/py_conv.c b/source3/python/py_conv.c index 9093b54b00..39b20ace86 100644 --- a/source3/python/py_conv.c +++ b/source3/python/py_conv.c @@ -99,9 +99,10 @@ BOOL to_struct(void *s, PyObject *dict, struct pyconv *conv) UNISTR *u = (UNISTR *)((char *)s + conv[i].offset); char *s = ""; - if (obj && PyString_Check(obj)) - s = PyString_AsString(obj); + if (!PyString_Check(obj)) + goto done; + s = PyString_AsString(obj); init_unistr(u, s); break; @@ -109,21 +110,20 @@ BOOL to_struct(void *s, PyObject *dict, struct pyconv *conv) case PY_UINT32: { uint32 *u = (uint32 *)((char *)s + conv[i].offset); - if (obj && PyInt_Check(obj)) - *u = PyInt_AsLong(obj); - else - *u = 0; + if (!PyInt_Check(obj)) + goto done; + + *u = PyInt_AsLong(obj); break; } case PY_UINT16: { uint16 *u = (uint16 *)((char *)s + conv[i].offset); - if (obj && PyInt_Check(obj)) - *u = PyInt_AsLong(obj); - else - *u = 0; + if (!PyInt_Check(obj)) + goto done; + *u = PyInt_AsLong(obj); break; } default: -- cgit From 343751ca95af59ac771295df45cc1d0a1cda31de Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 27 May 2002 06:34:13 +0000 Subject: Use new version of open_pipe_creds() function. A compile fix for enumerating trusted domains. (This used to be commit fc75c3ccc3bc45ab72db85d46dbedbbdb0e2dff7) --- source3/python/py_lsa.c | 36 ++++++++++++++++++++---------------- 1 file changed, 20 insertions(+), 16 deletions(-) (limited to 'source3/python') diff --git a/source3/python/py_lsa.c b/source3/python/py_lsa.c index 04af993e3e..7edd651642 100644 --- a/source3/python/py_lsa.c +++ b/source3/python/py_lsa.c @@ -54,11 +54,11 @@ static PyObject *lsa_open_policy(PyObject *self, PyObject *args, { static char *kwlist[] = { "servername", "creds", "access", NULL }; char *server, *errstr; - PyObject *creds = NULL, *result; + PyObject *creds = NULL, *result = NULL; uint32 desired_access = MAXIMUM_ALLOWED_ACCESS; - struct cli_state *cli; + struct cli_state *cli = NULL; NTSTATUS ntstatus; - TALLOC_CTX *mem_ctx; + TALLOC_CTX *mem_ctx = NULL; POLICY_HND hnd; if (!PyArg_ParseTupleAndKeywords( @@ -66,31 +66,36 @@ static PyObject *lsa_open_policy(PyObject *self, PyObject *args, &creds, &desired_access)) return NULL; - if (!(cli = open_pipe_creds( - server, creds, cli_lsa_initialise, &errstr))) { + if (!(cli = open_pipe_creds(server, creds, PIPE_LSARPC, &errstr))) { PyErr_SetString(lsa_error, errstr); free(errstr); return NULL; } if (!(mem_ctx = talloc_init())) { - PyErr_SetString( - lsa_error, "unable to init talloc context\n"); - return NULL; + PyErr_SetString(lsa_error, "unable to init talloc context\n"); + goto done; } ntstatus = cli_lsa_open_policy(cli, mem_ctx, True, SEC_RIGHTS_MAXIMUM_ALLOWED, &hnd); if (!NT_STATUS_IS_OK(ntstatus)) { - cli_shutdown(cli); - SAFE_FREE(cli); PyErr_SetObject(lsa_ntstatus, py_ntstatus_tuple(ntstatus)); - return NULL; + goto done; } result = new_lsa_policy_hnd_object(cli, mem_ctx, &hnd); +done: + if (!result) { + if (cli) + cli_shutdown(cli); + + if (mem_ctx) + talloc_destroy(mem_ctx); + } + return result; } @@ -259,7 +264,7 @@ static PyObject *lsa_enum_trust_dom(PyObject *self, PyObject *args) { lsa_policy_hnd_object *hnd = (lsa_policy_hnd_object *)self; NTSTATUS ntstatus; - uint32 enum_ctx = 0, num_domains, i; + uint32 enum_ctx = 0, num_domains, i, pref_num_domains = 0; char **domain_names; DOM_SID *domain_sids; PyObject *result; @@ -267,10 +272,9 @@ static PyObject *lsa_enum_trust_dom(PyObject *self, PyObject *args) if (!PyArg_ParseTuple(args, "")) return NULL; - ntstatus = cli_lsa_enum_trust_dom(hnd->cli, hnd->mem_ctx, - &hnd->pol, &enum_ctx, - &num_domains, &domain_names, - &domain_names, &domain_sids); + ntstatus = cli_lsa_enum_trust_dom( + hnd->cli, hnd->mem_ctx, &hnd->pol, &enum_ctx, + &pref_num_domains, &num_domains, &domain_names, &domain_sids); if (!NT_STATUS_IS_OK(ntstatus)) { PyErr_SetObject(lsa_ntstatus, py_ntstatus_tuple(ntstatus)); -- cgit From 2fe386d9b90c357020bbe4e5e3849d4874bc185c Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 27 May 2002 06:35:30 +0000 Subject: Use new version of open_pipe_creds() function. Fix memory leaks on error. (This used to be commit b44e82667252c0ff4477d77487ff92b3af8ad418) --- source3/python/py_samr.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'source3/python') diff --git a/source3/python/py_samr.c b/source3/python/py_samr.c index 6256629592..f715f891b4 100644 --- a/source3/python/py_samr.c +++ b/source3/python/py_samr.c @@ -276,9 +276,9 @@ 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; + struct cli_state *cli = NULL; POLICY_HND hnd; - TALLOC_CTX *mem_ctx; + TALLOC_CTX *mem_ctx = NULL; PyObject *result = NULL, *creds = NULL; NTSTATUS ntstatus; @@ -287,8 +287,7 @@ static PyObject *samr_connect(PyObject *self, PyObject *args, PyObject *kw) &creds, &desired_access)) return NULL; - if (!(cli = open_pipe_creds( - server, creds, cli_lsa_initialise, &errstr))) { + if (!(cli = open_pipe_creds(server, creds, PIPE_SAMR, &errstr))) { PyErr_SetString(samr_error, errstr); free(errstr); return NULL; @@ -312,6 +311,14 @@ static PyObject *samr_connect(PyObject *self, PyObject *args, PyObject *kw) result = new_samr_connect_hnd_object(cli, mem_ctx, &hnd); done: + if (!result) { + if (cli) + cli_shutdown(cli); + + if (mem_ctx) + talloc_destroy(cli); + } + return result; } -- cgit From c2f0e1638e3e8a0cd58054a562fc931b16651c8d Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 27 May 2002 06:36:06 +0000 Subject: Use new version of open_pipe_creds() function. Server argument to enumprinterdrivers() must be in UNC format. (This used to be commit 3b011eb65a45a2b919e0b759f426581100ac17fd) --- source3/python/py_spoolss_drivers.c | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) (limited to 'source3/python') diff --git a/source3/python/py_spoolss_drivers.c b/source3/python/py_spoolss_drivers.c index 1626684a1b..9b7a8d3294 100644 --- a/source3/python/py_spoolss_drivers.c +++ b/source3/python/py_spoolss_drivers.c @@ -42,10 +42,16 @@ PyObject *spoolss_enumprinterdrivers(PyObject *self, PyObject *args, &creds, &arch)) return NULL; + if (server[0] != '\\' || server[1] != '\\') { + PyErr_SetString(spoolss_error, "bad server name"); + return NULL; + } + + server += 2; + /* Call rpc function */ - if (!(cli = open_pipe_creds( - server, creds, cli_spoolss_initialise, &errstr))) { + if (!(cli = open_pipe_creds(server, creds, PIPE_SPOOLSS, &errstr))) { PyErr_SetString(spoolss_error, errstr); free(errstr); goto done; @@ -246,10 +252,16 @@ PyObject *spoolss_getprinterdriverdir(PyObject *self, PyObject *args, &arch, &PyDict_Type, &creds)) return NULL; + if (server[0] != '\\' || server[1] != '\\') { + PyErr_SetString(spoolss_error, "bad server name"); + return NULL; + } + + server += 2; + /* Call rpc function */ - if (!(cli = open_pipe_creds( - server, creds, cli_spoolss_initialise, &errstr))) { + if (!(cli = open_pipe_creds(server, creds, PIPE_SPOOLSS, &errstr))) { PyErr_SetString(spoolss_error, errstr); free(errstr); goto done; @@ -304,8 +316,8 @@ PyObject *spoolss_addprinterdriver(PyObject *self, PyObject *args, uint32 level; PyObject *info, *result = NULL, *creds = NULL; WERROR werror; - TALLOC_CTX *mem_ctx; - struct cli_state *cli; + TALLOC_CTX *mem_ctx = NULL; + struct cli_state *cli = NULL; PRINTER_DRIVER_CTR ctr; union { DRIVER_INFO_3 driver_3; @@ -325,8 +337,7 @@ PyObject *spoolss_addprinterdriver(PyObject *self, PyObject *args, return NULL; } - if (!(cli = open_pipe_creds( - server, creds, cli_spoolss_initialise, &errstr))) { + if (!(cli = open_pipe_creds(server, creds, PIPE_SPOOLSS, &errstr))) { PyErr_SetString(spoolss_error, errstr); free(errstr); goto done; @@ -334,7 +345,7 @@ PyObject *spoolss_addprinterdriver(PyObject *self, PyObject *args, if (!get_level_value(info, &level)) { PyErr_SetString(spoolss_error, "invalid info level"); - return NULL; + goto done; } if (level != 3) { @@ -371,8 +382,11 @@ PyObject *spoolss_addprinterdriver(PyObject *self, PyObject *args, result = Py_None; done: - cli_shutdown(cli); - talloc_destroy(mem_ctx); + if (cli) + cli_shutdown(cli); + + if (mem_ctx) + talloc_destroy(mem_ctx); return result; -- cgit From de4e9824bdfc28bd0c62b69db93d9b05065a0be1 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 27 May 2002 06:36:30 +0000 Subject: Use new version of open_pipe_creds() function. (This used to be commit e4aff324c28bfc08e73b627a5c7941109a3c2c2f) --- source3/python/py_spoolss_ports.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/python') diff --git a/source3/python/py_spoolss_ports.c b/source3/python/py_spoolss_ports.c index 54ccf32fcc..f0bea5175d 100644 --- a/source3/python/py_spoolss_ports.c +++ b/source3/python/py_spoolss_ports.c @@ -44,8 +44,7 @@ PyObject *spoolss_enumports(PyObject *self, PyObject *args, PyObject *kw) if (server[0] == '\\' && server[1] == '\\') server += 2; - if (!(cli = open_pipe_creds( - server, creds, cli_spoolss_initialise, &errstr))) { + if (!(cli = open_pipe_creds(server, creds, PIPE_SPOOLSS, &errstr))) { PyErr_SetString(spoolss_error, errstr); free(errstr); goto done; -- cgit From fdf42114cdf1e5c7033a072096ea10ebf2e38510 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 27 May 2002 06:38:36 +0000 Subject: Use new version of open_pipe_creds() function. Don't attempt to free client state returned by cli_full_connection() Fix memory leaks on error. Allow setprinter level 1 - doesn't work though. Extended interface to enumprinters(). The name value passed in the RPC request can be different from the server name in which case lots of weird and wonderful information is returned. Defaults to the server name. (This used to be commit c75bbda1021838074ff0f2e54edd68c69acccee0) --- source3/python/py_spoolss_printers.c | 79 +++++++++++++++++++++++++----------- 1 file changed, 56 insertions(+), 23 deletions(-) (limited to 'source3/python') diff --git a/source3/python/py_spoolss_printers.c b/source3/python/py_spoolss_printers.c index 54ea54682d..aa5f636b06 100644 --- a/source3/python/py_spoolss_printers.c +++ b/source3/python/py_spoolss_printers.c @@ -24,8 +24,8 @@ PyObject *spoolss_openprinter(PyObject *self, PyObject *args, PyObject *kw) { - char *unc_name, *server = NULL, *errstr; - TALLOC_CTX *mem_ctx; + char *unc_name, *server, *errstr; + TALLOC_CTX *mem_ctx = NULL; POLICY_HND hnd; WERROR werror; PyObject *result = NULL, *creds = NULL; @@ -36,10 +36,12 @@ PyObject *spoolss_openprinter(PyObject *self, PyObject *args, PyObject *kw) if (!PyArg_ParseTupleAndKeywords( args, kw, "s|O!i", kwlist, &unc_name, &PyDict_Type, &creds, &desired_access)) - goto done; + return NULL; - /* FIXME: Return name format exception for names without a UNC - prefix */ + if (unc_name[0] != '\\' || unc_name[1] != '\\') { + PyErr_SetString(spoolss_error, "bad printer name"); + return NULL; + } server = strdup(unc_name + 2); @@ -48,8 +50,7 @@ PyObject *spoolss_openprinter(PyObject *self, PyObject *args, PyObject *kw) *c = 0; } - if (!(cli = open_pipe_creds( - server, creds, cli_spoolss_initialise, &errstr))) { + if (!(cli = open_pipe_creds(server, creds, PIPE_SPOOLSS, &errstr))) { PyErr_SetString(spoolss_error, errstr); free(errstr); goto done; @@ -66,8 +67,6 @@ PyObject *spoolss_openprinter(PyObject *self, PyObject *args, PyObject *kw) "", &hnd); if (!W_ERROR_IS_OK(werror)) { - cli_shutdown(cli); - SAFE_FREE(cli); PyErr_SetObject(spoolss_werror, py_werror_tuple(werror)); goto done; } @@ -75,6 +74,14 @@ PyObject *spoolss_openprinter(PyObject *self, PyObject *args, PyObject *kw) 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; @@ -182,6 +189,7 @@ PyObject *spoolss_hnd_setprinter(PyObject *self, PyObject *args, PyObject *kw) uint32 level; static char *kwlist[] = {"dict", NULL}; union { + PRINTER_INFO_1 printers_1; PRINTER_INFO_2 printers_2; PRINTER_INFO_3 printers_3; } pinfo; @@ -197,7 +205,7 @@ PyObject *spoolss_hnd_setprinter(PyObject *self, PyObject *args, PyObject *kw) return NULL; } - if (level != 2 && level != 3) { + if (level < 1 && level > 3) { PyErr_SetString(spoolss_error, "unsupported info level"); return NULL; } @@ -207,6 +215,16 @@ PyObject *spoolss_hnd_setprinter(PyObject *self, PyObject *args, PyObject *kw) 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; @@ -259,23 +277,23 @@ PyObject *spoolss_enumprinters(PyObject *self, PyObject *args, PyObject *kw) PRINTER_INFO_CTR ctr; int level = 1, flags = PRINTER_ENUM_LOCAL, i; uint32 needed, num_printers; - static char *kwlist[] = {"server", "level", "flags", "creds", NULL}; + static char *kwlist[] = {"server", "name", "level", "flags", + "creds", NULL}; TALLOC_CTX *mem_ctx = NULL; struct cli_state *cli = NULL; - char *server, *errstr; + char *server, *errstr, *name = NULL; /* Parse parameters */ if (!PyArg_ParseTupleAndKeywords( - args, kw, "s|iiO!", kwlist, &server, &level, &flags, - &PyDict_Type, &creds)) + args, kw, "s|siiO!", kwlist, &server, &name, &level, + &flags, &PyDict_Type, &creds)) return NULL; if (server[0] == '\\' && server[1] == '\\') server += 2; - if (!(cli = open_pipe_creds( - server, creds, cli_spoolss_initialise, &errstr))) { + if (!(cli = open_pipe_creds(server, creds, PIPE_SPOOLSS, &errstr))) { PyErr_SetString(spoolss_error, errstr); free(errstr); goto done; @@ -287,15 +305,28 @@ PyObject *spoolss_enumprinters(PyObject *self, PyObject *args, PyObject *kw) 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, + cli, mem_ctx, 0, &needed, name, flags, level, &num_printers, &ctr); if (W_ERROR_V(werror) == ERRinsufficientbuffer) werror = cli_spoolss_enum_printers( - cli, mem_ctx, needed, NULL, flags, level, + cli, mem_ctx, needed, NULL, name, flags, level, &num_printers, &ctr); if (!W_ERROR_IS_OK(werror)) { @@ -397,8 +428,7 @@ PyObject *spoolss_addprinterex(PyObject *self, PyObject *args, PyObject *kw) &PyDict_Type, &info, &PyDict_Type, &creds)) return NULL; - if (!(cli = open_pipe_creds( - server, creds, cli_spoolss_initialise, &errstr))) { + if (!(cli = open_pipe_creds(server, creds, PIPE_SPOOLSS, &errstr))) { PyErr_SetString(spoolss_error, errstr); free(errstr); goto done; @@ -407,7 +437,7 @@ PyObject *spoolss_addprinterex(PyObject *self, PyObject *args, PyObject *kw) if (!(mem_ctx = talloc_init())) { PyErr_SetString( spoolss_error, "unable to init talloc context\n"); - return NULL; + goto done; } if (!py_to_PRINTER_INFO_2(&info2, info, mem_ctx)) { @@ -424,8 +454,11 @@ PyObject *spoolss_addprinterex(PyObject *self, PyObject *args, PyObject *kw) result = Py_None; done: - cli_shutdown(cli); - talloc_destroy(mem_ctx); + if (cli) + cli_shutdown(cli); + + if (mem_ctx) + talloc_destroy(mem_ctx); return result; } -- cgit From 0f1de232c254bdcc3d2b381f0724697750a907dd Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 27 May 2002 06:39:10 +0000 Subject: More automatically generated prototype madness. (This used to be commit 8e1a15a625b72711bcfab77403e6a6b91e434756) --- source3/python/py_common_proto.h | 2 +- source3/python/py_ntsec.c | 2 +- source3/python/py_winbind.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/python') diff --git a/source3/python/py_common_proto.h b/source3/python/py_common_proto.h index 992d444fa4..143ea2947c 100644 --- a/source3/python/py_common_proto.h +++ b/source3/python/py_common_proto.h @@ -13,7 +13,7 @@ PyObject *get_debuglevel(PyObject *self, PyObject *args); PyObject *set_debuglevel(PyObject *self, PyObject *args); PyObject *py_setup_logging(PyObject *self, PyObject *args, PyObject *kw); struct cli_state *open_pipe_creds(char *server, PyObject *creds, - cli_pipe_fn *connect_fn, char **errstr); + char *pipe_name, char **errstr); BOOL get_level_value(PyObject *dict, uint32 *level); /* The following definitions come from python/py_ntsec.c */ diff --git a/source3/python/py_ntsec.c b/source3/python/py_ntsec.c index 8981f0c3ac..f216d96aa8 100644 --- a/source3/python/py_ntsec.c +++ b/source3/python/py_ntsec.c @@ -21,7 +21,7 @@ #include "includes.h" #include "Python.h" -#include "python/py_common.h" +#include "python/py_common_proto.h" /* Convert a SID to a Python dict */ diff --git a/source3/python/py_winbind.c b/source3/python/py_winbind.c index e55d12afb2..49c7f8e924 100644 --- a/source3/python/py_winbind.c +++ b/source3/python/py_winbind.c @@ -23,7 +23,7 @@ #include "includes.h" #include "Python.h" -#include "py_common.h" +#include "py_common_proto.h" /* * Exceptions raised by this module -- cgit From d26bcfaf955027d0a61e2b3557f3062e47c25ccd Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 27 May 2002 07:47:58 +0000 Subject: Use a fixed size font for displaying tdb values. Added a (regexp, function) pair to register display functions for keys matching regular expressions. Expand the size of the value scrolling window. Added hex dump function and some regexps to display DRIVERS, SECDESC and PRINTERS keys in hex instead of ascii. (This used to be commit 7d10dc5f7bd12e25ea3e64b380a029c89929156f) --- source3/python/gtdbtool | 115 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 111 insertions(+), 4 deletions(-) (limited to 'source3/python') diff --git a/source3/python/gtdbtool b/source3/python/gtdbtool index cb88792acc..670fca9973 100755 --- a/source3/python/gtdbtool +++ b/source3/python/gtdbtool @@ -20,6 +20,8 @@ class gtdbtool: 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. @@ -70,7 +72,7 @@ class gtdbtool: scrolled_win = GtkScrolledWindow() scrolled_win.set_policy(POLICY_AUTOMATIC, POLICY_AUTOMATIC) hpaned.add2(scrolled_win) - scrolled_win.set_usize(350,400) + scrolled_win.set_usize(500,400) scrolled_win.show() self.text = GtkText() @@ -83,7 +85,7 @@ class gtdbtool: self.menu = GtkMenu() self.menu.show() - self.filter_regex = "" + self.font = load_font("fixed") self.update_keylist() @@ -107,14 +109,30 @@ class gtdbtool: def set_value_text(self, text): self.text.delete_text(0, self.text.get_length()) - self.text.insert_defaults(text) + + # 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() - self.set_value_text(t[list_item.get_data("raw_key")]) + + # 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. @@ -143,8 +161,90 @@ class gtdbtool: 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 " + sys.exit(1) + t = tdb.open(sys.argv[1]) # Create user interface @@ -159,6 +259,13 @@ def display_key_x00(key): 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]) -- cgit From d21f10d3e65ebdee7db8e4c122a0a623b65bcd49 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Tue, 28 May 2002 02:08:39 +0000 Subject: Allow None to be used as a valid credential in open_policy. Added {get,set}_debuglevel() and setup_logging() functions. (This used to be commit b6e860546a622e6da238faf56d7c1567c6cf63a5) --- source3/python/py_lsa.c | 41 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) (limited to 'source3/python') diff --git a/source3/python/py_lsa.c b/source3/python/py_lsa.c index 7edd651642..0665578e60 100644 --- a/source3/python/py_lsa.c +++ b/source3/python/py_lsa.c @@ -62,10 +62,15 @@ static PyObject *lsa_open_policy(PyObject *self, PyObject *args, POLICY_HND hnd; if (!PyArg_ParseTupleAndKeywords( - args, kw, "s|O!i", kwlist, &server, &PyDict_Type, - &creds, &desired_access)) + args, kw, "s|Oi", kwlist, &server, &creds, &desired_access)) return NULL; + 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_LSARPC, &errstr))) { PyErr_SetString(lsa_error, errstr); free(errstr); @@ -360,6 +365,38 @@ static PyMethodDef lsa_methods[] = { METH_VARARGS, "Close a policy handle" }, + /* 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)" }, + { NULL } }; -- cgit From e99a265bad36f2525a5b04734ff996e66b624711 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Tue, 28 May 2002 02:09:54 +0000 Subject: Allow None to be used as a valid credential for functions that take a credential as a parameter. (This used to be commit 166aee6cc2abb5f6e91ebf3d4ec37454034b8dcd) --- source3/python/py_samr.c | 10 ++++++++-- source3/python/py_spoolss_drivers.c | 30 ++++++++++++++++++++++++------ source3/python/py_spoolss_ports.c | 9 +++++++-- source3/python/py_spoolss_printers.c | 18 +++++++++++++++--- 4 files changed, 54 insertions(+), 13 deletions(-) (limited to 'source3/python') diff --git a/source3/python/py_samr.c b/source3/python/py_samr.c index f715f891b4..733a57c1d4 100644 --- a/source3/python/py_samr.c +++ b/source3/python/py_samr.c @@ -283,10 +283,16 @@ static PyObject *samr_connect(PyObject *self, PyObject *args, PyObject *kw) NTSTATUS ntstatus; if (!PyArg_ParseTupleAndKeywords( - args, kw, "s|O!i", kwlist, &server, &PyDict_Type, - &creds, &desired_access)) + args, kw, "s|Oi", kwlist, &server, &creds, + &desired_access)) return NULL; + 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); diff --git a/source3/python/py_spoolss_drivers.c b/source3/python/py_spoolss_drivers.c index 9b7a8d3294..19fe5800aa 100644 --- a/source3/python/py_spoolss_drivers.c +++ b/source3/python/py_spoolss_drivers.c @@ -38,8 +38,8 @@ PyObject *spoolss_enumprinterdrivers(PyObject *self, PyObject *args, /* Parse parameters */ if (!PyArg_ParseTupleAndKeywords( - args, kw, "s|iO!s", kwlist, &server, &level, &PyDict_Type, - &creds, &arch)) + args, kw, "s|iOs", kwlist, &server, &level, &creds, + &arch)) return NULL; if (server[0] != '\\' || server[1] != '\\') { @@ -49,6 +49,12 @@ PyObject *spoolss_enumprinterdrivers(PyObject *self, PyObject *args, 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))) { @@ -248,8 +254,8 @@ PyObject *spoolss_getprinterdriverdir(PyObject *self, PyObject *args, /* Parse parameters */ if (!PyArg_ParseTupleAndKeywords( - args, kw, "s|isO!", kwlist, &server, &level, - &arch, &PyDict_Type, &creds)) + args, kw, "s|isO", kwlist, &server, &level, + &arch, &creds)) return NULL; if (server[0] != '\\' || server[1] != '\\') { @@ -259,6 +265,12 @@ PyObject *spoolss_getprinterdriverdir(PyObject *self, PyObject *args, 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))) { @@ -324,13 +336,19 @@ PyObject *spoolss_addprinterdriver(PyObject *self, PyObject *args, } dinfo; if (!PyArg_ParseTupleAndKeywords( - args, kw, "sO!|O!", kwlist, &server, &PyDict_Type, - &info, &PyDict_Type, &creds)) + 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"); diff --git a/source3/python/py_spoolss_ports.c b/source3/python/py_spoolss_ports.c index f0bea5175d..8d59274a00 100644 --- a/source3/python/py_spoolss_ports.c +++ b/source3/python/py_spoolss_ports.c @@ -37,13 +37,18 @@ PyObject *spoolss_enumports(PyObject *self, PyObject *args, PyObject *kw) /* Parse parameters */ if (!PyArg_ParseTupleAndKeywords( - args, kw, "s|iO!", kwlist, &server, &level, - &PyDict_Type, &creds)) + args, kw, "s|iO", kwlist, &server, &level, &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 (!(cli = open_pipe_creds(server, creds, PIPE_SPOOLSS, &errstr))) { PyErr_SetString(spoolss_error, errstr); free(errstr); diff --git a/source3/python/py_spoolss_printers.c b/source3/python/py_spoolss_printers.c index aa5f636b06..934bfcc818 100644 --- a/source3/python/py_spoolss_printers.c +++ b/source3/python/py_spoolss_printers.c @@ -34,7 +34,7 @@ PyObject *spoolss_openprinter(PyObject *self, PyObject *args, PyObject *kw) struct cli_state *cli; if (!PyArg_ParseTupleAndKeywords( - args, kw, "s|O!i", kwlist, &unc_name, &PyDict_Type, &creds, + args, kw, "s|Oi", kwlist, &unc_name, &creds, &desired_access)) return NULL; @@ -50,6 +50,12 @@ PyObject *spoolss_openprinter(PyObject *self, PyObject *args, PyObject *kw) *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); @@ -286,13 +292,19 @@ PyObject *spoolss_enumprinters(PyObject *self, PyObject *args, PyObject *kw) /* Parse parameters */ if (!PyArg_ParseTupleAndKeywords( - args, kw, "s|siiO!", kwlist, &server, &name, &level, - &flags, &PyDict_Type, &creds)) + args, kw, "s|siiO", kwlist, &server, &name, &level, + &flags, &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 (!(cli = open_pipe_creds(server, creds, PIPE_SPOOLSS, &errstr))) { PyErr_SetString(spoolss_error, errstr); free(errstr); -- cgit From 6aad72916aff00eb11f747e7fd5a01ac98b56929 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Tue, 28 May 2002 02:33:11 +0000 Subject: Raise a ValueError if server names aren't given in UNC format. (This used to be commit f5a1a3190dc0d4ecdf55b870633a83ee125b816e) --- source3/python/py_spoolss_drivers.c | 6 +++--- source3/python/py_spoolss_ports.c | 8 ++++++-- source3/python/py_spoolss_printers.c | 10 +++++++--- 3 files changed, 16 insertions(+), 8 deletions(-) (limited to 'source3/python') diff --git a/source3/python/py_spoolss_drivers.c b/source3/python/py_spoolss_drivers.c index 19fe5800aa..b5357a78ad 100644 --- a/source3/python/py_spoolss_drivers.c +++ b/source3/python/py_spoolss_drivers.c @@ -43,7 +43,7 @@ PyObject *spoolss_enumprinterdrivers(PyObject *self, PyObject *args, return NULL; if (server[0] != '\\' || server[1] != '\\') { - PyErr_SetString(spoolss_error, "bad server name"); + PyErr_SetString(PyExc_ValueError, "UNC name required"); return NULL; } @@ -259,7 +259,7 @@ PyObject *spoolss_getprinterdriverdir(PyObject *self, PyObject *args, return NULL; if (server[0] != '\\' || server[1] != '\\') { - PyErr_SetString(spoolss_error, "bad server name"); + PyErr_SetString(PyExc_ValueError, "UNC name required"); return NULL; } @@ -340,7 +340,7 @@ PyObject *spoolss_addprinterdriver(PyObject *self, PyObject *args, &info, &creds)) return NULL; - if (server[0] == '\\' && server[1] == '\\') + if (server[0] == '\\' || server[1] == '\\') server += 2; if (creds && creds != Py_None && !PyDict_Check(creds)) { diff --git a/source3/python/py_spoolss_ports.c b/source3/python/py_spoolss_ports.c index 8d59274a00..b5f2102e5e 100644 --- a/source3/python/py_spoolss_ports.c +++ b/source3/python/py_spoolss_ports.c @@ -40,8 +40,12 @@ PyObject *spoolss_enumports(PyObject *self, PyObject *args, PyObject *kw) args, kw, "s|iO", kwlist, &server, &level, &creds)) return NULL; - if (server[0] == '\\' && server[1] == '\\') - server += 2; + 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, diff --git a/source3/python/py_spoolss_printers.c b/source3/python/py_spoolss_printers.c index 934bfcc818..4294df5a6d 100644 --- a/source3/python/py_spoolss_printers.c +++ b/source3/python/py_spoolss_printers.c @@ -39,7 +39,7 @@ PyObject *spoolss_openprinter(PyObject *self, PyObject *args, PyObject *kw) return NULL; if (unc_name[0] != '\\' || unc_name[1] != '\\') { - PyErr_SetString(spoolss_error, "bad printer name"); + PyErr_SetString(PyExc_ValueError, "UNC name required"); return NULL; } @@ -296,8 +296,12 @@ PyObject *spoolss_enumprinters(PyObject *self, PyObject *args, PyObject *kw) &flags, &creds)) return NULL; - if (server[0] == '\\' && server[1] == '\\') - server += 2; + 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, -- cgit From 6aaaa165b7135a845f9fe66c4bc4fe5742d3c7e7 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Tue, 28 May 2002 03:14:28 +0000 Subject: Raise a ValueError if server name isn't given in UNC format. (This used to be commit 77be88668d9669a0aaa331c4bbb0faad978f0990) --- source3/python/py_lsa.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'source3/python') diff --git a/source3/python/py_lsa.c b/source3/python/py_lsa.c index 0665578e60..21e6463c5f 100644 --- a/source3/python/py_lsa.c +++ b/source3/python/py_lsa.c @@ -71,6 +71,13 @@ static PyObject *lsa_open_policy(PyObject *self, PyObject *args, return NULL; } + if (server[0] != '\\' || server[1] != '\\') { + PyErr_SetString(PyExc_ValueError, "UNC name required"); + return NULL; + } + + server += 2; + if (!(cli = open_pipe_creds(server, creds, PIPE_LSARPC, &errstr))) { PyErr_SetString(lsa_error, errstr); free(errstr); -- cgit From d80f078647c62b6d8e66a717ba67e36cc1107f4b Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Tue, 28 May 2002 03:15:09 +0000 Subject: Separate error handling for cli_full_connection() and cli_nt_session_open() (This used to be commit 6f269de03e91b823a30a2a12e41f25f1fa050870) --- source3/python/py_common.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'source3/python') diff --git a/source3/python/py_common.c b/source3/python/py_common.c index d81e141e9c..eb36fc552c 100644 --- a/source3/python/py_common.c +++ b/source3/python/py_common.c @@ -183,10 +183,15 @@ struct cli_state *open_pipe_creds(char *server, PyObject *creds, &cli, global_myname, server, &server_ip, 0, "IPC$", "IPC", username, domain, password, strlen(password)); - if (!NT_STATUS_IS_OK(result) || !cli_nt_session_open(cli, pipe_name)) { + 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); - *errstr = strdup("pipe not available"); + asprintf(errstr, "error opening %s", pipe_name); return NULL; } -- cgit From 3adb868e04c2e9bf81a36e6b85722d02172d498a Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Tue, 4 Jun 2002 01:41:44 +0000 Subject: Fix long list scrolling bug. Added some padding around the filter entry to make it look nicer. When resizing the window the scrolling list should get bigger/smaller not the filter entry widget. (This used to be commit f504be133cd9659163a609eb11a09a36e56166ee) --- source3/python/gtdbtool | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'source3/python') diff --git a/source3/python/gtdbtool b/source3/python/gtdbtool index 670fca9973..6513366790 100755 --- a/source3/python/gtdbtool +++ b/source3/python/gtdbtool @@ -44,19 +44,18 @@ class gtdbtool: scrolled_win = GtkScrolledWindow() scrolled_win.set_policy(POLICY_AUTOMATIC, POLICY_AUTOMATIC) vbox.pack_start(scrolled_win) - scrolled_win.set_usize(350,400) scrolled_win.show() hbox = GtkHBox() - vbox.pack_end(hbox) + vbox.pack_end(hbox, expand = 0, padding = 5) hbox.show() label = GtkLabel("Filter:") - hbox.pack_start(label, expand = 0) + hbox.pack_start(label, expand = 0, padding = 5) label.show() self.entry = GtkEntry() - hbox.pack_end(self.entry) + hbox.pack_end(self.entry, padding = 5) self.entry.show() self.entry.connect("activate", self.filter_activated) -- cgit From d35c5f39a5aed7fba83e7096204c7b8925905b57 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Thu, 20 Jun 2002 00:51:07 +0000 Subject: Compile fix for new arguments to cli_full_connection() (This used to be commit 0d05c8ce54c3fa859abb8bd2ac13cacaed63e95c) --- source3/python/py_common.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) (limited to 'source3/python') diff --git a/source3/python/py_common.c b/source3/python/py_common.c index eb36fc552c..471a53da84 100644 --- a/source3/python/py_common.c +++ b/source3/python/py_common.c @@ -137,8 +137,6 @@ struct cli_state *open_pipe_creds(char *server, PyObject *creds, char *username = "", *password = "", *domain = ""; struct cli_state *cli; NTSTATUS result; - struct in_addr server_ip; - extern pstring global_myname; /* Extract credentials from the python dictionary */ @@ -174,14 +172,9 @@ struct cli_state *open_pipe_creds(char *server, PyObject *creds, /* Now try to connect */ - if (!resolve_name(server, &server_ip, 0x20)) { - asprintf(errstr, "unable to resolve %s", server); - return NULL; - } - result = cli_full_connection( - &cli, global_myname, server, &server_ip, 0, "IPC$", "IPC", - username, domain, password, strlen(password)); + &cli, NULL, server, NULL, 0, "IPC$", "IPC", + username, domain, password); if (!NT_STATUS_IS_OK(result)) { *errstr = strdup("error connecting to IPC$ pipe"); -- cgit From b21b66c5444d5cddd5c11b184ba2a86a31c9a994 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Thu, 20 Jun 2002 00:54:43 +0000 Subject: Added samr_open_domain() call. (This used to be commit 97f70f2cfff72d6040c72d34a569f5c889cbff2e) --- source3/python/py_samr.c | 96 ++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 77 insertions(+), 19 deletions(-) (limited to 'source3/python') diff --git a/source3/python/py_samr.c b/source3/python/py_samr.c index 733a57c1d4..ce6eda99c2 100644 --- a/source3/python/py_samr.c +++ b/source3/python/py_samr.c @@ -38,7 +38,72 @@ 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 } }; @@ -74,7 +139,7 @@ PyObject *new_samr_connect_hnd_object(struct cli_state *cli, TALLOC_CTX *mem_ctx o->cli = cli; o->mem_ctx = mem_ctx; - memcpy(&o->pol, pol, sizeof(POLICY_HND)); + memcpy(&o->connect_pol, pol, sizeof(POLICY_HND)); return (PyObject*)o; } @@ -113,20 +178,6 @@ PyTypeObject samr_domain_hnd_type = { 0, /*tp_hash */ }; -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->pol, pol, sizeof(POLICY_HND)); - - return (PyObject*)o; -} - /* SAMR user handle object */ static void py_samr_user_hnd_dealloc(PyObject* self) @@ -170,7 +221,7 @@ PyObject *new_samr_user_hnd_object(struct cli_state *cli, TALLOC_CTX *mem_ctx, o->cli = cli; o->mem_ctx = mem_ctx; - memcpy(&o->pol, pol, sizeof(POLICY_HND)); + memcpy(&o->user_pol, pol, sizeof(POLICY_HND)); return (PyObject*)o; } @@ -218,7 +269,7 @@ PyObject *new_samr_group_hnd_object(struct cli_state *cli, TALLOC_CTX *mem_ctx, o->cli = cli; o->mem_ctx = mem_ctx; - memcpy(&o->pol, pol, sizeof(POLICY_HND)); + memcpy(&o->group_pol, pol, sizeof(POLICY_HND)); return (PyObject*)o; } @@ -266,7 +317,7 @@ PyObject *new_samr_alias_hnd_object(struct cli_state *cli, TALLOC_CTX *mem_ctx, o->cli = cli; o->mem_ctx = mem_ctx; - memcpy(&o->pol, pol, sizeof(POLICY_HND)); + memcpy(&o->alias_pol, pol, sizeof(POLICY_HND)); return (PyObject*)o; } @@ -287,6 +338,13 @@ static PyObject *samr_connect(PyObject *self, PyObject *args, PyObject *kw) &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"); @@ -322,7 +380,7 @@ done: cli_shutdown(cli); if (mem_ctx) - talloc_destroy(cli); + talloc_destroy(mem_ctx); } return result; -- cgit From 6905730c3eede966f574c35794e559ab93235245 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Thu, 20 Jun 2002 00:56:27 +0000 Subject: Renamed policy handle field in object containers to avoid cut&paste bugs. (This used to be commit 93309c0ad4cd66680f94d7a46028b4d392d1cc06) --- source3/python/py_samr.h | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'source3/python') diff --git a/source3/python/py_samr.h b/source3/python/py_samr.h index 326bab5c14..22c3660ef9 100644 --- a/source3/python/py_samr.h +++ b/source3/python/py_samr.h @@ -32,7 +32,7 @@ typedef struct { PyObject_HEAD struct cli_state *cli; TALLOC_CTX *mem_ctx; - POLICY_HND pol; + POLICY_HND connect_pol; } samr_connect_hnd_object; /* SAMR domain policy handle object */ @@ -41,7 +41,7 @@ typedef struct { PyObject_HEAD struct cli_state *cli; TALLOC_CTX *mem_ctx; - POLICY_HND pol; + POLICY_HND domain_pol; } samr_domain_hnd_object; /* SAMR user policy handle object */ @@ -50,7 +50,7 @@ typedef struct { PyObject_HEAD struct cli_state *cli; TALLOC_CTX *mem_ctx; - POLICY_HND pol; + POLICY_HND user_pol; } samr_user_hnd_object; /* SAMR group policy handle object */ @@ -59,7 +59,7 @@ typedef struct { PyObject_HEAD struct cli_state *cli; TALLOC_CTX *mem_ctx; - POLICY_HND pol; + POLICY_HND group_pol; } samr_group_hnd_object; /* SAMR alias policy handle object */ @@ -68,7 +68,7 @@ typedef struct { PyObject_HEAD struct cli_state *cli; TALLOC_CTX *mem_ctx; - POLICY_HND pol; + POLICY_HND alias_pol; } samr_alias_hnd_object; extern PyTypeObject samr_connect_hnd_type, samr_domain_hnd_type, @@ -78,6 +78,6 @@ extern PyTypeObject samr_connect_hnd_type, samr_domain_hnd_type, extern PyObject *samr_error; -// #include "python/py_samr_proto.h" +/* #include "python/py_samr_proto.h" */ #endif /* _PY_SAMR_H */ -- cgit From cad934c8e942aa5003e51488ee4b4c04b0071d77 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Thu, 11 Jul 2002 22:19:31 +0000 Subject: Compile fix for flags field to cli_full_connection() (This used to be commit 802f30a1b34888823c1fc80121b3917cb6825119) --- source3/python/py_common.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/python') diff --git a/source3/python/py_common.c b/source3/python/py_common.c index 471a53da84..890422536e 100644 --- a/source3/python/py_common.c +++ b/source3/python/py_common.c @@ -174,7 +174,7 @@ struct cli_state *open_pipe_creds(char *server, PyObject *creds, result = cli_full_connection( &cli, NULL, server, NULL, 0, "IPC$", "IPC", - username, domain, password); + username, domain, password, 0); if (!NT_STATUS_IS_OK(result)) { *errstr = strdup("error connecting to IPC$ pipe"); -- cgit From 246ec5ad07f35451aa6a8fa7ba502dcc5de04130 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Thu, 11 Jul 2002 23:08:51 +0000 Subject: Another compile fix. (This used to be commit ef5c9698b06c5df99ec07ee781cc54d2e348ba8a) --- source3/python/py_spoolss_printers.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/python') diff --git a/source3/python/py_spoolss_printers.c b/source3/python/py_spoolss_printers.c index 4294df5a6d..8d4cd24778 100644 --- a/source3/python/py_spoolss_printers.c +++ b/source3/python/py_spoolss_printers.c @@ -337,12 +337,12 @@ PyObject *spoolss_enumprinters(PyObject *self, PyObject *args, PyObject *kw) /* Call rpc function */ werror = cli_spoolss_enum_printers( - cli, mem_ctx, 0, &needed, name, flags, level, + 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, name, flags, level, + cli, mem_ctx, needed, NULL, flags, level, &num_printers, &ctr); if (!W_ERROR_IS_OK(werror)) { -- cgit From 46deff915e3ff75141e6e2a4ab090bb7639c8a8e Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Thu, 11 Jul 2002 23:18:41 +0000 Subject: Regenerated. (This used to be commit 7ead9602ce8c30a57cb83d56fb76228945a7599f) --- source3/python/samba-head.patch | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'source3/python') diff --git a/source3/python/samba-head.patch b/source3/python/samba-head.patch index 0894533487..41b040d8f6 100644 --- a/source3/python/samba-head.patch +++ b/source3/python/samba-head.patch @@ -1,18 +1,19 @@ Index: Makefile.in =================================================================== RCS file: /data/cvs/samba/source/Makefile.in,v -retrieving revision 1.475 -diff -u -r1.475 Makefile.in ---- Makefile.in 2002/05/09 04:44:00 1.475 -+++ Makefile.in 2002/05/13 07:26:04 -@@ -792,6 +792,45 @@ +retrieving revision 1.494 +diff -u -r1.494 Makefile.in +--- Makefile.in 2002/07/03 07:37:50 1.494 ++++ Makefile.in 2002/07/11 23:18:11 +@@ -834,6 +834,46 @@ -$(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) ++ $(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\ @@ -54,11 +55,11 @@ diff -u -r1.475 Makefile.in Index: configure.in =================================================================== RCS file: /data/cvs/samba/source/configure.in,v -retrieving revision 1.307 -diff -u -r1.307 configure.in ---- configure.in 2002/05/11 00:36:33 1.307 -+++ configure.in 2002/05/13 07:26:06 -@@ -2892,7 +2892,7 @@ +retrieving revision 1.321 +diff -u -r1.321 configure.in +--- configure.in 2002/07/03 00:44:39 1.321 ++++ configure.in 2002/07/11 23:18:11 +@@ -2820,7 +2820,7 @@ builddir=`pwd` AC_SUBST(builddir) -- cgit