r25598: Add missing become_root/unbecome_root around calls of add_aliases.
[samba.git] / source / python / py_spoolss_ports.c
index 54ccf32fcc20a6c139aeb06299988da10d6596ff..8dad35b79df95d3219726c50a817010c6ce6a55b 100644 (file)
@@ -5,7 +5,7 @@
    
    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
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
    
    This program is distributed in the hope that it will be useful,
@@ -14,8 +14,7 @@
    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.
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 #include "python/py_spoolss.h"
@@ -26,7 +25,7 @@ PyObject *spoolss_enumports(PyObject *self, PyObject *args, PyObject *kw)
 {
        WERROR werror;
        PyObject *result = NULL, *creds = NULL;
-       int level = 1;
+       uint32 level = 1;
        uint32 i, needed, num_ports;
        static char *kwlist[] = {"server", "level", "creds", NULL};
        TALLOC_CTX *mem_ctx = NULL;
@@ -37,21 +36,29 @@ 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 (server[0] != '\\' || server[1] != '\\') {
+               PyErr_SetString(PyExc_ValueError, "UNC name required");
+               return NULL;
+       }
 
-       if (!(cli = open_pipe_creds(
-                     server, creds, cli_spoolss_initialise, &errstr))) {
+       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, PI_SPOOLSS, &errstr))) {
                PyErr_SetString(spoolss_error, errstr);
                free(errstr);
                goto done;
        }
 
-       if (!(mem_ctx = talloc_init())) {
+       if (!(mem_ctx = talloc_init("spoolss_enumports"))) {
                PyErr_SetString(
                        spoolss_error, "unable to init talloc context\n");
                goto done;
@@ -59,13 +66,8 @@ PyObject *spoolss_enumports(PyObject *self, PyObject *args, PyObject *kw)
 
        /* Call rpc function */
        
-       werror = cli_spoolss_enum_ports(
-               cli, mem_ctx, 0, &needed, level, &num_ports, &ctr);
-
-       if (W_ERROR_V(werror) == ERRinsufficientbuffer)
-               werror = cli_spoolss_enum_ports(
-                       cli, mem_ctx, needed, NULL, level,
-                       &num_ports, &ctr);
+       werror = rpccli_spoolss_enum_ports( 
+               cli->pipe_list, mem_ctx, level, &num_ports, &ctr);
 
        if (!W_ERROR_IS_OK(werror)) {
                PyErr_SetObject(spoolss_werror, py_werror_tuple(werror));