3 * Unix SMB/Netbios implementation.
5 * RPC Pipe client / server routines
6 * Copyright (C) Andrew Tridgell 1992-1997,
7 * Copyright (C) Luke Kenneth Casson Leighton 1996-1997,
8 * Copyright (C) Paul Ashton 1997.
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
32 extern int DEBUGLEVEL;
35 /****************************************************************************
36 do a SPOOLSS Enum Printers
37 ****************************************************************************/
38 BOOL spoolss_enum_printers(struct cli_state *cli, uint16 fnum,
39 uint32 flags, const char *servername,
46 SPOOL_Q_ENUMPRINTERS q_o;
47 BOOL valid_pol = False;
49 if (count == NULL || printers == NULL) return False;
51 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
52 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
54 /* create and send a MSRPC command with api SPOOLSS_ENUM_PRINTERS */
56 DEBUG(5,("SPOOLSS Enum Printers (Server: %s level: %d)\n",
59 make_spoolss_q_enumprinters(&q_o, flags, servername, level, 0x800);
61 /* turn parameters into data stream */
62 spoolss_io_q_enumprinters("", &q_o, &buf, 0);
64 /* send the data on \PIPE\ */
65 if (rpc_api_pipe_req(cli, fnum, SPOOLSS_ENUMPRINTERS, &buf, &rbuf))
67 SPOOL_R_ENUMPRINTERS r_o;
74 spoolss_io_r_enumprinters("", &r_o, &rbuf, 0);
77 if (p && r_o.status != 0)
79 /* report error code */
80 DEBUG(5,("SPOOLSS_ENUM_PRINTERS: %s\n", get_nt_error_msg(r_o.status)));
86 /* ok, at last: we're happy. return the policy handle */
87 (*count) = r_o.returned;
88 (*printers) = r_o.printer.info;
99 /****************************************************************************
100 do a SPOOLSS Open Printer Ex
101 ****************************************************************************/
102 BOOL spoolss_open_printer_ex(struct cli_state *cli, uint16 fnum,
104 uint32 cbbuf, uint32 devmod, uint32 des_access,
111 SPOOL_Q_OPEN_PRINTER_EX q_o;
112 BOOL valid_pol = False;
114 if (hnd == NULL) return False;
116 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
117 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
119 /* create and send a MSRPC command with api SPOOLSS_OPENPRINTEREX */
121 DEBUG(5,("SPOOLSS Open Printer Ex\n"));
123 make_spoolss_q_open_printer_ex(&q_o, printername,
124 cbbuf, devmod, des_access,
127 /* turn parameters into data stream */
128 spoolss_io_q_open_printer_ex("", &q_o, &buf, 0);
130 /* send the data on \PIPE\ */
131 if (rpc_api_pipe_req(cli, fnum, SPOOLSS_OPENPRINTEREX, &buf, &rbuf))
133 SPOOL_R_OPEN_PRINTER_EX r_o;
136 spoolss_io_r_open_printer_ex("", &r_o, &rbuf, 0);
137 p = rbuf.offset != 0;
139 if (p && r_o.status != 0)
141 /* report error code */
142 DEBUG(5,("SPOOLSS_OPENPRINTEREX: %s\n", get_nt_error_msg(r_o.status)));
148 /* ok, at last: we're happy. return the policy handle */
149 memcpy(hnd, r_o.handle.data, sizeof(hnd->data));
160 /****************************************************************************
162 ****************************************************************************/
163 BOOL spoolss_closeprinter(struct cli_state *cli, uint16 fnum, PRINTER_HND *hnd)
167 SPOOL_Q_CLOSEPRINTER q_c;
168 BOOL valid_close = False;
170 if (hnd == NULL) return False;
172 /* create and send a MSRPC command with api SPOOLSS_CLOSEPRINTER */
174 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
175 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
177 DEBUG(4,("SPOOL Close Printer\n"));
179 /* store the parameters */
180 make_spoolss_q_closeprinter(&q_c, hnd);
182 /* turn parameters into data stream */
183 spoolss_io_q_closeprinter("", &q_c, &buf, 0);
185 /* send the data on \PIPE\ */
186 if (rpc_api_pipe_req(cli, fnum, SPOOLSS_CLOSEPRINTER, &buf, &rbuf))
188 SPOOL_R_CLOSEPRINTER r_c;
191 spoolss_io_r_closeprinter("", &r_c, &rbuf, 0);
192 p = rbuf.offset != 0;
194 if (p && r_c.status != 0)
196 /* report error code */
197 DEBUG(0,("SPOOL_CLOSEPRINTER: %s\n", get_nt_error_msg(r_c.status)));
203 /* check that the returned policy handle is all zeros */
207 for (i = 0; i < sizeof(r_c.handle.data); i++)
209 if (r_c.handle.data[i] != 0)
217 DEBUG(0,("SPOOL_CLOSEPRINTER: non-zero handle returned\n"));