Refactored open_pipe_creds() function to remove unused parameter.
authorTim Potter <tpot@samba.org>
Thu, 16 May 2002 02:24:22 +0000 (02:24 +0000)
committerTim Potter <tpot@samba.org>
Thu, 16 May 2002 02:24:22 +0000 (02:24 +0000)
(This used to be commit 36ed06cb5078429445f3bbb0f69baa2e0f8356a4)

source3/python/py_common.c
source3/python/py_common.h
source3/python/py_common_proto.h
source3/python/py_lsa.c
source3/python/py_samr.c
source3/python/py_spoolss_drivers.c
source3/python/py_spoolss_ports.c
source3/python/py_spoolss_printers.c

index 5b80f09498c07193446142dae8c374601fc1dd6f..d286ed68f05194bde61525d03e14611f06cef126 100644 (file)
@@ -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 */
 
index f13224a020fe0c21ba432fdc8483776f63f643ee..1f5188971db8714306404f8227f42e6018d0fb4b 100644 (file)
@@ -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)(
index bca59689a45c69f56f10f2a7513815685e493432..98d970d7bcf6847a238a183c69871830100eb351 100644 (file)
@@ -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  */
 
index 23566282f62686deaab1fa950065a88b2015079f..cf96928790fa0ad1c7ea97f185ada3d7def5a6e2 100644 (file)
@@ -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;
        }
index 6c52ebe8cd6ba201c76cdc81f4fb107f337eb4e9..66d6266d104a08c4ba217624e37cbea7e66ff501 100644 (file)
@@ -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,
index 088dc54576bd721d84a3aa16a63d16910fd88dba..416d46f1d2d2d9dcc993bef002b4d9fce7d73d50 100644 (file)
@@ -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)
 {
index 2d73a6e033e511a2bbc0d3186f070ad0e2306790..8e74017f4a71d40c8968c0021c13278545f5374d 100644 (file)
@@ -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 */
        
index 164ba974b94f0e6e5ec3adad820bdabf6ca5aad5..36ba22a7c479719e38bad431ba3e3fcef69d1b11 100644 (file)
@@ -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)) {