From 2561b2d2e275bf1ca1aa7cab8b3942cff7d8b5f7 Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Sat, 7 Mar 2009 00:04:05 +0100 Subject: s3-spoolss: use pidl for _spoolss_EnumMonitors. Guenther --- source3/include/proto.h | 1 - source3/rpc_server/srv_spoolss.c | 22 +---- source3/rpc_server/srv_spoolss_nt.c | 192 +++++++++++++++++++++--------------- 3 files changed, 112 insertions(+), 103 deletions(-) diff --git a/source3/include/proto.h b/source3/include/proto.h index f64297c1e0..a4e8626d88 100644 --- a/source3/include/proto.h +++ b/source3/include/proto.h @@ -6130,7 +6130,6 @@ WERROR _spoolss_enumprinterdrivers( pipes_struct *p, SPOOL_Q_ENUMPRINTERDRIVERS WERROR enumports_hook(TALLOC_CTX *ctx, int *count, char ***lines ); 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); WERROR _spoolss_getjob( pipes_struct *p, SPOOL_Q_GETJOB *q_u, SPOOL_R_GETJOB *r_u); WERROR _spoolss_enumprinterkey(pipes_struct *p, SPOOL_Q_ENUMPRINTERKEY *q_u, SPOOL_R_ENUMPRINTERKEY *r_u); WERROR _spoolss_enumprinterdataex(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATAEX *q_u, SPOOL_R_ENUMPRINTERDATAEX *r_u); diff --git a/source3/rpc_server/srv_spoolss.c b/source3/rpc_server/srv_spoolss.c index c65b65119e..616eb1dbf0 100644 --- a/source3/rpc_server/srv_spoolss.c +++ b/source3/rpc_server/srv_spoolss.c @@ -581,27 +581,7 @@ static bool api_spoolss_enumprintprocdatatypes(pipes_struct *p) static bool api_spoolss_enumprintmonitors(pipes_struct *p) { - SPOOL_Q_ENUMPRINTMONITORS q_u; - SPOOL_R_ENUMPRINTMONITORS 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_enumprintmonitors("", &q_u, data, 0)) { - DEBUG(0,("spoolss_io_q_enumprintmonitors: unable to unmarshall SPOOL_Q_ENUMPRINTMONITORS.\n")); - return False; - } - - r_u.status = _spoolss_enumprintmonitors(p, &q_u, &r_u); - - if (!spoolss_io_r_enumprintmonitors("", &r_u, rdata, 0)) { - DEBUG(0,("spoolss_io_r_enumprintmonitors: unable to marshall SPOOL_R_ENUMPRINTMONITORS.\n")); - return False; - } - - return True; + return proxy_spoolss_call(p, NDR_SPOOLSS_ENUMMONITORS); } /**************************************************************************** diff --git a/source3/rpc_server/srv_spoolss_nt.c b/source3/rpc_server/srv_spoolss_nt.c index 8b1e21a518..0a4f5ae05c 100644 --- a/source3/rpc_server/srv_spoolss_nt.c +++ b/source3/rpc_server/srv_spoolss_nt.c @@ -8914,126 +8914,162 @@ WERROR _spoolss_EnumPrintProcDataTypes(pipes_struct *p, } } +/**************************************************************************** + fill_monitor_1 +****************************************************************************/ + +static WERROR fill_monitor_1(TALLOC_CTX *mem_ctx, + struct spoolss_MonitorInfo1 *r, + const char *monitor_name) +{ + r->monitor_name = talloc_strdup(mem_ctx, monitor_name); + W_ERROR_HAVE_NO_MEMORY(r->monitor_name); + + return WERR_OK; +} + +/**************************************************************************** + fill_monitor_2 +****************************************************************************/ + +static WERROR fill_monitor_2(TALLOC_CTX *mem_ctx, + struct spoolss_MonitorInfo2 *r, + const char *monitor_name, + const char *environment, + const char *dll_name) +{ + r->monitor_name = talloc_strdup(mem_ctx, monitor_name); + W_ERROR_HAVE_NO_MEMORY(r->monitor_name); + r->environment = talloc_strdup(mem_ctx, environment); + W_ERROR_HAVE_NO_MEMORY(r->environment); + r->dll_name = talloc_strdup(mem_ctx, dll_name); + W_ERROR_HAVE_NO_MEMORY(r->dll_name); + + return WERR_OK; +} + /**************************************************************************** enumprintmonitors level 1. ****************************************************************************/ -static WERROR enumprintmonitors_level_1(RPC_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) +static WERROR enumprintmonitors_level_1(TALLOC_CTX *mem_ctx, + union spoolss_MonitorInfo **info_p, + uint32_t offered, + uint32_t *needed, + uint32_t *count) { - PRINTMONITOR_1 *info_1; + union spoolss_MonitorInfo *info; WERROR result = WERR_OK; int i; - if((info_1 = SMB_MALLOC_ARRAY(PRINTMONITOR_1, 2)) == NULL) - return WERR_NOMEM; - - *returned = 2; + info = TALLOC_ARRAY(mem_ctx, union spoolss_MonitorInfo, 2); + W_ERROR_HAVE_NO_MEMORY(info); - init_unistr(&(info_1[0].name), SPL_LOCAL_PORT ); - init_unistr(&(info_1[1].name), SPL_TCPIP_PORT ); + *count = 2; - for ( i=0; i<*returned; i++ ) { - *needed += spoolss_size_printmonitor_info_1(&info_1[i]); + result = fill_monitor_1(info, &info[0].info1, + SPL_LOCAL_PORT /* FIXME */); + if (!W_ERROR_IS_OK(result)) { + goto out; } - if (*needed > offered) { - result = WERR_INSUFFICIENT_BUFFER; + result = fill_monitor_1(info, &info[1].info1, + SPL_TCPIP_PORT /* FIXME */); + if (!W_ERROR_IS_OK(result)) { goto out; } - if (!rpcbuf_alloc_size(buffer, *needed)) { - result = WERR_NOMEM; - goto out; + for (i=0; i<*count; i++) { + *needed += ndr_size_spoolss_MonitorInfo1(&info[i].info1, NULL, 0); } - for ( i=0; i<*returned; i++ ) { - smb_io_printmonitor_info_1("", buffer, &info_1[i], 0); + if (*needed > offered) { + result = WERR_INSUFFICIENT_BUFFER; + goto out; } out: - SAFE_FREE(info_1); + if (!W_ERROR_IS_OK(result)) { + TALLOC_FREE(info); + *count = 0; + return result; + } - if ( !W_ERROR_IS_OK(result) ) - *returned = 0; + *info_p = info; - return result; + return WERR_OK; } /**************************************************************************** enumprintmonitors level 2. ****************************************************************************/ -static WERROR enumprintmonitors_level_2(RPC_BUFFER *buffer, uint32 offered, uint32 *needed, uint32 *returned) +static WERROR enumprintmonitors_level_2(TALLOC_CTX *mem_ctx, + union spoolss_MonitorInfo **info_p, + uint32_t offered, + uint32_t *needed, + uint32_t *count) { - PRINTMONITOR_2 *info_2; + union spoolss_MonitorInfo *info; WERROR result = WERR_OK; int i; - if((info_2 = SMB_MALLOC_ARRAY(PRINTMONITOR_2, 2)) == NULL) - return WERR_NOMEM; - - *returned = 2; - - init_unistr( &(info_2[0].name), SPL_LOCAL_PORT ); - init_unistr( &(info_2[0].environment), "Windows NT X86" ); - init_unistr( &(info_2[0].dll_name), "localmon.dll" ); + info = TALLOC_ARRAY(mem_ctx, union spoolss_MonitorInfo, 2); + W_ERROR_HAVE_NO_MEMORY(info); - init_unistr( &(info_2[1].name), SPL_TCPIP_PORT ); - init_unistr( &(info_2[1].environment), "Windows NT X86" ); - init_unistr( &(info_2[1].dll_name), "tcpmon.dll" ); + *count = 2; - for ( i=0; i<*returned; i++ ) { - *needed += spoolss_size_printmonitor_info_2(&info_2[i]); + result = fill_monitor_2(info, &info[0].info2, + SPL_LOCAL_PORT, /* FIXME */ + "Windows NT X86", /* FIXME */ + "localmon.dll"); + if (!W_ERROR_IS_OK(result)) { + goto out; } - if (*needed > offered) { - result = WERR_INSUFFICIENT_BUFFER; + result = fill_monitor_2(info, &info[1].info2, + SPL_TCPIP_PORT, /* FIXME */ + "Windows NT X86", /* FIXME */ + "tcpmon.dll"); + if (!W_ERROR_IS_OK(result)) { goto out; } - if (!rpcbuf_alloc_size(buffer, *needed)) { - result = WERR_NOMEM; - goto out; + for (i=0; i<*count; i++) { + *needed += ndr_size_spoolss_MonitorInfo2(&info[i].info2, NULL, 0); } - for ( i=0; i<*returned; i++ ) { - smb_io_printmonitor_info_2("", buffer, &info_2[i], 0); + if (*needed > offered) { + result = WERR_INSUFFICIENT_BUFFER; + goto out; } out: - SAFE_FREE(info_2); + if (!W_ERROR_IS_OK(result)) { + TALLOC_FREE(info); + *count = 0; + return result; + } - if ( !W_ERROR_IS_OK(result) ) - *returned = 0; + *info_p = info; - return result; + return WERR_OK; } -/**************************************************************************** -****************************************************************************/ +/**************************************************************** + _spoolss_EnumMonitors +****************************************************************/ -WERROR _spoolss_enumprintmonitors(pipes_struct *p, SPOOL_Q_ENUMPRINTMONITORS *q_u, SPOOL_R_ENUMPRINTMONITORS *r_u) +WERROR _spoolss_EnumMonitors(pipes_struct *p, + struct spoolss_EnumMonitors *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(5,("spoolss_enumprintmonitors\n")); + DEBUG(5,("_spoolss_EnumMonitors\n")); /* * Enumerate the print monitors ... @@ -9042,14 +9078,19 @@ WERROR _spoolss_enumprintmonitors(pipes_struct *p, SPOOL_Q_ENUMPRINTMONITORS *q_ * and I can use my nice printer checker. */ - *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 enumprintmonitors_level_1(buffer, offered, needed, returned); + return enumprintmonitors_level_1(p->mem_ctx, r->out.info, + r->in.offered, r->out.needed, + r->out.count); case 2: - return enumprintmonitors_level_2(buffer, offered, needed, returned); + return enumprintmonitors_level_2(p->mem_ctx, r->out.info, + r->in.offered, r->out.needed, + r->out.count); default: return WERR_UNKNOWN_LEVEL; } @@ -10287,17 +10328,6 @@ WERROR _spoolss_WaitForPrinterChange(pipes_struct *p, return WERR_NOT_SUPPORTED; } -/**************************************************************** - _spoolss_EnumMonitors -****************************************************************/ - -WERROR _spoolss_EnumMonitors(pipes_struct *p, - struct spoolss_EnumMonitors *r) -{ - p->rng_fault_state = true; - return WERR_NOT_SUPPORTED; -} - /**************************************************************** _spoolss_AddPort ****************************************************************/ -- cgit