s3-spoolss: use pidl for _spoolss_EnumPorts.
authorGünther Deschner <gd@samba.org>
Fri, 6 Mar 2009 22:38:57 +0000 (23:38 +0100)
committerGünther Deschner <gd@samba.org>
Fri, 6 Mar 2009 23:55:36 +0000 (00:55 +0100)
Guenther

source3/include/proto.h
source3/rpc_server/srv_spoolss.c
source3/rpc_server/srv_spoolss_nt.c

index b5f310012ce10d3b3a0058fcc07b7fd16de34e3d..74707a7607bbe2133b45c5331ab49d432c606213 100644 (file)
@@ -6128,7 +6128,6 @@ bool add_printer_hook(TALLOC_CTX *ctx, NT_USER_TOKEN *token, NT_PRINTER_INFO_LEV
 WERROR _spoolss_enumjobs( pipes_struct *p, SPOOL_Q_ENUMJOBS *q_u, SPOOL_R_ENUMJOBS *r_u);
 WERROR _spoolss_enumprinterdrivers( pipes_struct *p, SPOOL_Q_ENUMPRINTERDRIVERS *q_u, SPOOL_R_ENUMPRINTERDRIVERS *r_u);
 WERROR enumports_hook(TALLOC_CTX *ctx, int *count, char ***lines );
-WERROR _spoolss_enumports( pipes_struct *p, SPOOL_Q_ENUMPORTS *q_u, SPOOL_R_ENUMPORTS *r_u);
 WERROR _spoolss_enumprinterdata(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATA *q_u, SPOOL_R_ENUMPRINTERDATA *r_u);
 WERROR _spoolss_setprinterdata( pipes_struct *p, SPOOL_Q_SETPRINTERDATA *q_u, SPOOL_R_SETPRINTERDATA *r_u);
 WERROR _spoolss_enumprintmonitors(pipes_struct *p, SPOOL_Q_ENUMPRINTMONITORS *q_u, SPOOL_R_ENUMPRINTMONITORS *r_u);
index 5f6e7d8a2aae97d1528d180cef72d558029f8c2d..c65b65119eacd398c1a99c1fd34d14601c2bcdf4 100644 (file)
@@ -439,27 +439,7 @@ static bool api_spoolss_enumforms(pipes_struct *p)
 
 static bool api_spoolss_enumports(pipes_struct *p)
 {
-       SPOOL_Q_ENUMPORTS q_u;
-       SPOOL_R_ENUMPORTS r_u;
-       prs_struct *data = &p->in_data.data;
-       prs_struct *rdata = &p->out_data.rdata;
-
-       ZERO_STRUCT(q_u);
-       ZERO_STRUCT(r_u);
-
-       if(!spoolss_io_q_enumports("", &q_u, data, 0)) {
-               DEBUG(0,("spoolss_io_q_enumports: unable to unmarshall SPOOL_Q_ENUMPORTS.\n"));
-               return False;
-       }
-
-       r_u.status = _spoolss_enumports(p, &q_u, &r_u);
-
-       if (!spoolss_io_r_enumports("",&r_u,rdata,0)) {
-               DEBUG(0,("spoolss_io_r_enumports: unable to marshall SPOOL_R_ENUMPORTS.\n"));
-               return False;
-       }
-
-       return True;
+       return proxy_spoolss_call(p, NDR_SPOOLSS_ENUMPORTS);
 }
 
 /****************************************************************************
index 419e178389a5b589f33fa025a962f911d75b7039..8b1e21a5182e4275a72982a1e9a8342f8a52e145 100644 (file)
@@ -7446,9 +7446,14 @@ WERROR _spoolss_GetForm(pipes_struct *p,
 /****************************************************************************
 ****************************************************************************/
 
-static void fill_port_1(PORT_INFO_1 *port, const char *name)
+static WERROR fill_port_1(TALLOC_CTX *mem_ctx,
+                         struct spoolss_PortInfo1 *r,
+                         const char *name)
 {
-       init_unistr(&port->port_name, name);
+       r->port_name = talloc_strdup(mem_ctx, name);
+       W_ERROR_HAVE_NO_MEMORY(r->port_name);
+
+       return WERR_OK;
 }
 
 /****************************************************************************
@@ -7456,13 +7461,23 @@ static void fill_port_1(PORT_INFO_1 *port, const char *name)
  somehow.
 ****************************************************************************/
 
-static void fill_port_2(PORT_INFO_2 *port, const char *name)
+static WERROR fill_port_2(TALLOC_CTX *mem_ctx,
+                         struct spoolss_PortInfo2 *r,
+                         const char *name)
 {
-       init_unistr(&port->port_name, name);
-       init_unistr(&port->monitor_name, "Local Monitor");
-       init_unistr(&port->description, SPL_LOCAL_PORT );
-       port->port_type=PORT_TYPE_WRITE;
-       port->reserved=0x0;
+       r->port_name = talloc_strdup(mem_ctx, name);
+       W_ERROR_HAVE_NO_MEMORY(r->port_name);
+
+       r->monitor_name = talloc_strdup(mem_ctx, "Local Monitor");
+       W_ERROR_HAVE_NO_MEMORY(r->monitor_name);
+
+       r->description = talloc_strdup(mem_ctx, SPL_LOCAL_PORT); /* FIXME */
+       W_ERROR_HAVE_NO_MEMORY(r->description);
+
+       r->port_type = SPOOLSS_PORT_TYPE_WRITE;
+       r->reserved = 0;
+
+       return WERR_OK;
 }
 
 
@@ -7530,9 +7545,13 @@ WERROR enumports_hook(TALLOC_CTX *ctx, int *count, char ***lines )
  enumports level 1.
 ****************************************************************************/
 
-static WERROR enumports_level_1(RPC_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
+static WERROR enumports_level_1(TALLOC_CTX *mem_ctx,
+                               union spoolss_PortInfo **info_p,
+                               uint32_t offered,
+                               uint32_t *needed,
+                               uint32_t *count)
 {
-       PORT_INFO_1 *ports=NULL;
+       union spoolss_PortInfo *info = NULL;
        int i=0;
        WERROR result = WERR_OK;
        char **qlines = NULL;
@@ -7540,31 +7559,31 @@ static WERROR enumports_level_1(RPC_BUFFER *buffer, uint32 offered, uint32 *need
 
        result = enumports_hook(talloc_tos(), &numlines, &qlines );
        if (!W_ERROR_IS_OK(result)) {
-               TALLOC_FREE(qlines);
-               return result;
+               goto out;
        }
 
-       if(numlines) {
-               if((ports=SMB_MALLOC_ARRAY( PORT_INFO_1, numlines )) == NULL) {
-                       DEBUG(10,("Returning WERR_NOMEM [%s]\n",
-                                 win_errstr(WERR_NOMEM)));
-                       TALLOC_FREE(qlines);
-                       return WERR_NOMEM;
+       if (numlines) {
+               info = TALLOC_ARRAY(mem_ctx, union spoolss_PortInfo, numlines);
+               if (!info) {
+                       DEBUG(10,("Returning WERR_NOMEM\n"));
+                       result = WERR_NOMEM;
+                       goto out;
                }
 
                for (i=0; i<numlines; i++) {
                        DEBUG(6,("Filling port number [%d] with port [%s]\n", i, qlines[i]));
-                       fill_port_1(&ports[i], qlines[i]);
+                       result = fill_port_1(info, &info[i].info1, qlines[i]);
+                       if (!W_ERROR_IS_OK(result)) {
+                               goto out;
+                       }
                }
        }
        TALLOC_FREE(qlines);
 
-       *returned = numlines;
-
        /* check the required size. */
-       for (i=0; i<*returned; i++) {
+       for (i=0; i<numlines; i++) {
                DEBUGADD(6,("adding port [%d]'s size\n", i));
-               *needed += spoolss_size_port_info_1(&ports[i]);
+               *needed += ndr_size_spoolss_PortInfo1(&info[i].info1, NULL, 0);
        }
 
        if (*needed > offered) {
@@ -7572,64 +7591,64 @@ static WERROR enumports_level_1(RPC_BUFFER *buffer, uint32 offered, uint32 *need
                goto out;
        }
 
-       if (!rpcbuf_alloc_size(buffer, *needed)) {
-               result = WERR_NOMEM;
-               goto out;
-       }
-
-       /* fill the buffer with the ports structures */
-       for (i=0; i<*returned; i++) {
-               DEBUGADD(6,("adding port [%d] to buffer\n", i));
-               smb_io_port_1("", buffer, &ports[i], 0);
-       }
-
 out:
-       SAFE_FREE(ports);
+       if (!W_ERROR_IS_OK(result)) {
+               TALLOC_FREE(info);
+               TALLOC_FREE(qlines);
+               *count = 0;
+               *info_p = NULL;
+               return result;
+       }
 
-       if ( !W_ERROR_IS_OK(result) )
-               *returned = 0;
+       *info_p = info;
+       *count = numlines;
 
-       return result;
+       return WERR_OK;
 }
 
 /****************************************************************************
  enumports level 2.
 ****************************************************************************/
 
-static WERROR enumports_level_2(RPC_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned)
+static WERROR enumports_level_2(TALLOC_CTX *mem_ctx,
+                               union spoolss_PortInfo **info_p,
+                               uint32_t offered,
+                               uint32_t *needed,
+                               uint32_t *count)
 {
-       PORT_INFO_2 *ports=NULL;
+       union spoolss_PortInfo *info = NULL;
        int i=0;
        WERROR result = WERR_OK;
        char **qlines = NULL;
        int numlines = 0;
 
        result = enumports_hook(talloc_tos(), &numlines, &qlines );
-       if ( !W_ERROR_IS_OK(result)) {
-               TALLOC_FREE(qlines);
-               return result;
+       if (!W_ERROR_IS_OK(result)) {
+               goto out;
        }
 
-       if(numlines) {
-               if((ports=SMB_MALLOC_ARRAY( PORT_INFO_2, numlines)) == NULL) {
-                       TALLOC_FREE(qlines);
-                       return WERR_NOMEM;
+       if (numlines) {
+               info = TALLOC_ARRAY(mem_ctx, union spoolss_PortInfo, numlines);
+               if (!info) {
+                       DEBUG(10,("Returning WERR_NOMEM\n"));
+                       result = WERR_NOMEM;
+                       goto out;
                }
 
                for (i=0; i<numlines; i++) {
                        DEBUG(6,("Filling port number [%d] with port [%s]\n", i, qlines[i]));
-                       fill_port_2(&(ports[i]), qlines[i]);
+                       result = fill_port_2(info, &info[i].info2, qlines[i]);
+                       if (!W_ERROR_IS_OK(result)) {
+                               goto out;
+                       }
                }
        }
-
        TALLOC_FREE(qlines);
 
-       *returned = numlines;
-
        /* check the required size. */
-       for (i=0; i<*returned; i++) {
+       for (i=0; i<numlines; i++) {
                DEBUGADD(6,("adding port [%d]'s size\n", i));
-               *needed += spoolss_size_port_info_2(&ports[i]);
+               *needed += ndr_size_spoolss_PortInfo2(&info[i].info2, NULL, 0);
        }
 
        if (*needed > offered) {
@@ -7637,61 +7656,49 @@ static WERROR enumports_level_2(RPC_BUFFER *buffer, uint32 offered, uint32 *need
                goto out;
        }
 
-       if (!rpcbuf_alloc_size(buffer, *needed)) {
-               result = WERR_NOMEM;
-               goto out;
-       }
-
-       /* fill the buffer with the ports structures */
-       for (i=0; i<*returned; i++) {
-               DEBUGADD(6,("adding port [%d] to buffer\n", i));
-               smb_io_port_2("", buffer, &ports[i], 0);
-       }
-
 out:
-       SAFE_FREE(ports);
+       if (!W_ERROR_IS_OK(result)) {
+               TALLOC_FREE(info);
+               TALLOC_FREE(qlines);
+               *count = 0;
+               *info_p = NULL;
+               return result;
+       }
 
-       if ( !W_ERROR_IS_OK(result) )
-               *returned = 0;
+       *info_p = info;
+       *count = numlines;
 
-       return result;
+       return WERR_OK;
 }
 
-/****************************************************************************
- enumports.
-****************************************************************************/
+/****************************************************************
+ _spoolss_EnumPorts
+****************************************************************/
 
-WERROR _spoolss_enumports( pipes_struct *p, SPOOL_Q_ENUMPORTS *q_u, SPOOL_R_ENUMPORTS *r_u)
+WERROR _spoolss_EnumPorts(pipes_struct *p,
+                         struct spoolss_EnumPorts *r)
 {
-       uint32 level = q_u->level;
-       RPC_BUFFER *buffer = NULL;
-       uint32 offered = q_u->offered;
-       uint32 *needed = &r_u->needed;
-       uint32 *returned = &r_u->returned;
-
        /* that's an [in out] buffer */
 
-       if (!q_u->buffer && (offered!=0)) {
-               return WERR_INVALID_PARAM;
-       }
-
-       if (offered > MAX_RPC_DATA_SIZE) {
+       if (!r->in.buffer && (r->in.offered != 0)) {
                return WERR_INVALID_PARAM;
        }
 
-       rpcbuf_move(q_u->buffer, &r_u->buffer);
-       buffer = r_u->buffer;
-
-       DEBUG(4,("_spoolss_enumports\n"));
+       DEBUG(4,("_spoolss_EnumPorts\n"));
 
-       *returned=0;
-       *needed=0;
+       *r->out.count = 0;
+       *r->out.needed = 0;
+       *r->out.info = NULL;
 
-       switch (level) {
+       switch (r->in.level) {
        case 1:
-               return enumports_level_1(buffer, offered, needed, returned);
+               return enumports_level_1(p->mem_ctx, r->out.info,
+                                        r->in.offered, r->out.needed,
+                                        r->out.count);
        case 2:
-               return enumports_level_2(buffer, offered, needed, returned);
+               return enumports_level_2(p->mem_ctx, r->out.info,
+                                        r->in.offered, r->out.needed,
+                                        r->out.count);
        default:
                return WERR_UNKNOWN_LEVEL;
        }
@@ -10280,17 +10287,6 @@ WERROR _spoolss_WaitForPrinterChange(pipes_struct *p,
        return WERR_NOT_SUPPORTED;
 }
 
-/****************************************************************
- _spoolss_EnumPorts
-****************************************************************/
-
-WERROR _spoolss_EnumPorts(pipes_struct *p,
-                         struct spoolss_EnumPorts *r)
-{
-       p->rng_fault_state = true;
-       return WERR_NOT_SUPPORTED;
-}
-
 /****************************************************************
  _spoolss_EnumMonitors
 ****************************************************************/