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(-) 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