2 * Unix SMB/Netbios implementation.
4 * RPC Pipe client / server routines
5 * Copyright (C) Andrew Tridgell 1992-2000,
6 * Copyright (C) Luke Kenneth Casson Leighton 1996-2000,
7 * Copyright (C) Paul Ashton 1997-2000,
8 * Copyright (C) Jean Francois Micouleau 1998-2000,
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.
26 #include "rpc_parse.h"
27 #include "rpc_client.h"
30 extern int DEBUGLEVEL;
32 /****************************************************************************
33 do a SPOOLSS Enum Printer Drivers
34 ****************************************************************************/
35 uint32 spoolss_enum_printerdrivers(const char * srv_name,
36 const char *environment,
38 NEW_BUFFER *buffer, uint32 offered,
39 uint32 *needed, uint32 *returned)
43 SPOOL_Q_ENUMPRINTERDRIVERS q_o;
44 SPOOL_R_ENUMPRINTERDRIVERS r_o;
46 struct cli_connection *con = NULL;
48 if (!cli_connection_init(srv_name, PIPE_SPOOLSS, &con))
51 prs_init(&buf , MAX_PDU_FRAG_LEN, 4, MARSHALL);
52 prs_init(&rbuf, 0, 4, UNMARSHALL);
54 /* create and send a MSRPC command with api SPOOLSS_ENUM_PRINTERS */
56 DEBUG(5,("SPOOLSS Enum Printer Drivers (Server: %s Environment: %s level: %d)\n",
57 srv_name, environment, level));
59 make_spoolss_q_enumprinterdrivers(&q_o, srv_name, environment,
60 level, buffer, offered);
62 /* turn parameters into data stream */
63 if (!spoolss_io_q_enumprinterdrivers("", &q_o, &buf, 0) ) {
67 cli_connection_unlink(con);
70 if(!rpc_con_pipe_req(con, SPOOLSS_ENUMPRINTERDRIVERS, &buf, &rbuf)) {
74 cli_connection_unlink(con);
80 prs_switch_type(&buffer->prs, UNMARSHALL);
81 prs_set_offset(&buffer->prs, 0);
84 if(!new_spoolss_io_r_enumprinterdrivers("", &r_o, &rbuf, 0)) {
86 cli_connection_unlink(con);
90 *returned=r_o.returned;
95 cli_connection_unlink(con);
100 /****************************************************************************
101 do a SPOOLSS Enum Printers
102 ****************************************************************************/
103 uint32 spoolss_enum_printers(uint32 flags, fstring srv_name, uint32 level,
104 NEW_BUFFER *buffer, uint32 offered,
105 uint32 *needed, uint32 *returned)
109 SPOOL_Q_ENUMPRINTERS q_o;
110 SPOOL_R_ENUMPRINTERS r_o;
112 struct cli_connection *con = NULL;
114 if (!cli_connection_init(srv_name, PIPE_SPOOLSS, &con))
117 prs_init(&buf , MAX_PDU_FRAG_LEN, 4, MARSHALL);
118 prs_init(&rbuf, 0, 4, UNMARSHALL);
120 /* create and send a MSRPC command with api SPOOLSS_ENUM_PRINTERS */
122 DEBUG(5,("SPOOLSS Enum Printers (Server: %s level: %d)\n", srv_name, level));
124 make_spoolss_q_enumprinters(&q_o, flags, "", level, buffer, offered);
126 /* turn parameters into data stream */
127 if (!spoolss_io_q_enumprinters("", &q_o, &buf, 0) ) {
131 cli_connection_unlink(con);
134 if(!rpc_con_pipe_req(con, SPOOLSS_ENUMPRINTERS, &buf, &rbuf)) {
138 cli_connection_unlink(con);
144 prs_switch_type(&buffer->prs, UNMARSHALL);
145 prs_set_offset(&buffer->prs, 0);
148 if(!new_spoolss_io_r_enumprinters("", &r_o, &rbuf, 0)) {
150 cli_connection_unlink(con);
154 *returned=r_o.returned;
159 cli_connection_unlink(con);
164 /****************************************************************************
165 do a SPOOLSS Enum Ports
166 ****************************************************************************/
167 uint32 spoolss_enum_ports(fstring srv_name, uint32 level,
168 NEW_BUFFER *buffer, uint32 offered,
169 uint32 *needed, uint32 *returned)
173 SPOOL_Q_ENUMPORTS q_o;
174 SPOOL_R_ENUMPORTS r_o;
176 struct cli_connection *con = NULL;
178 if (!cli_connection_init(srv_name, PIPE_SPOOLSS, &con))
181 prs_init(&buf , MAX_PDU_FRAG_LEN, 4, MARSHALL);
182 prs_init(&rbuf, 0, 4, UNMARSHALL);
184 /* create and send a MSRPC command with api SPOOLSS_ENUMPORTS */
186 DEBUG(5,("SPOOLSS Enum Ports (Server: %s level: %d)\n", srv_name, level));
188 make_spoolss_q_enumports(&q_o, "", level, buffer, offered);
190 /* turn parameters into data stream */
191 if (!spoolss_io_q_enumports("", &q_o, &buf, 0) ) {
195 cli_connection_unlink(con);
198 if(!rpc_con_pipe_req(con, SPOOLSS_ENUMPORTS, &buf, &rbuf)) {
202 cli_connection_unlink(con);
208 prs_switch_type(&buffer->prs, UNMARSHALL);
209 prs_set_offset(&buffer->prs, 0);
212 if(!new_spoolss_io_r_enumports("", &r_o, &rbuf, 0)) {
214 cli_connection_unlink(con);
218 *returned=r_o.returned;
223 cli_connection_unlink(con);
228 /****************************************************************************
229 do a SPOOLSS Enum Jobs
230 ****************************************************************************/
231 uint32 spoolss_enum_jobs(const POLICY_HND *hnd, uint32 firstjob, uint32 numofjobs,
232 uint32 level, NEW_BUFFER *buffer, uint32 offered,
233 uint32 *needed, uint32 *returned)
237 SPOOL_Q_ENUMJOBS q_o;
238 SPOOL_R_ENUMJOBS r_o;
241 return NT_STATUS_INVALID_PARAMETER;
243 prs_init(&buf , MAX_PDU_FRAG_LEN, 4, MARSHALL);
244 prs_init(&rbuf, 0, 4, UNMARSHALL);
246 /* create and send a MSRPC command with api SPOOLSS_ENUMJOBS */
248 DEBUG(5,("SPOOLSS Enum Jobs level: %d)\n", level));
250 make_spoolss_q_enumjobs(&q_o, hnd, firstjob, numofjobs, level, buffer, offered);
252 /* turn parameters into data stream */
253 if (!spoolss_io_q_enumjobs("", &q_o, &buf, 0)) {
258 if(!rpc_hnd_pipe_req(hnd, SPOOLSS_ENUMJOBS, &buf, &rbuf))
269 if(!spoolss_io_r_enumjobs("", &r_o, &rbuf, 0)) {
274 *returned=r_o.returned;
282 /***************************************************************************
283 do a SPOOLSS Enum printer datas
284 ****************************************************************************/
285 uint32 spoolss_enum_printerdata(const POLICY_HND *hnd, uint32 idx,
286 uint32 *valuelen, uint16 *value, uint32 *rvaluelen,
288 uint32 *datalen, uint8 *data, uint32 *rdatalen)
292 SPOOL_Q_ENUMPRINTERDATA q_o;
293 SPOOL_R_ENUMPRINTERDATA r_o;
296 return NT_STATUS_INVALID_PARAMETER;
298 prs_init(&buf , MAX_PDU_FRAG_LEN, 4, MARSHALL);
299 prs_init(&rbuf, 0, 4, UNMARSHALL);
301 /* create and send a MSRPC command with api SPOOLSS_ENUMJOBS */
303 DEBUG(5,("SPOOLSS Enum Printer data)\n"));
305 make_spoolss_q_enumprinterdata(&q_o, hnd, idx, *valuelen, *datalen);
307 /* turn parameters into data stream */
308 if (!spoolss_io_q_enumprinterdata("", &q_o, &buf, 0)) {
313 if(!rpc_hnd_pipe_req(hnd, SPOOLSS_ENUMPRINTERDATA, &buf, &rbuf)) {
324 if(!spoolss_io_r_enumprinterdata("", &r_o, &rbuf, 0)) {
328 *valuelen=r_o.valuesize;
329 *rvaluelen=r_o.realvaluesize;
331 *datalen=r_o.datasize;
332 *rdatalen=r_o.realdatasize;
340 /****************************************************************************
341 do a SPOOLSS Enum printer datas
342 ****************************************************************************/
343 uint32 spoolss_getprinter(const POLICY_HND *hnd, uint32 level,
344 NEW_BUFFER *buffer, uint32 offered,
349 SPOOL_Q_GETPRINTER q_o;
350 SPOOL_R_GETPRINTER r_o;
353 return NT_STATUS_INVALID_PARAMETER;
355 prs_init(&buf , MAX_PDU_FRAG_LEN, 4, MARSHALL);
356 prs_init(&rbuf, 0, 4, UNMARSHALL);
358 /* create and send a MSRPC command with api SPOOLSS_ENUMJOBS */
360 DEBUG(5,("SPOOLSS Enum Printer data)\n"));
362 make_spoolss_q_getprinter(&q_o, hnd, level, buffer, offered);
364 /* turn parameters into data stream */
365 if (!spoolss_io_q_getprinter("", &q_o, &buf, 0)) {
370 if(!rpc_hnd_pipe_req(hnd, SPOOLSS_GETPRINTER, &buf, &rbuf)) {
378 prs_switch_type(&buffer->prs, UNMARSHALL);
379 prs_set_offset(&buffer->prs, 0);
382 if(!spoolss_io_r_getprinter("", &r_o, &rbuf, 0)) {
394 /****************************************************************************
395 do a SPOOLSS Enum printer driver
396 ****************************************************************************/
397 uint32 spoolss_getprinterdriver(const POLICY_HND *hnd,
398 const char *environment, uint32 level,
399 NEW_BUFFER *buffer, uint32 offered,
404 SPOOL_Q_GETPRINTERDRIVER2 q_o;
405 SPOOL_R_GETPRINTERDRIVER2 r_o;
408 return NT_STATUS_INVALID_PARAMETER;
410 prs_init(&buf , MAX_PDU_FRAG_LEN, 4, MARSHALL);
411 prs_init(&rbuf, 0, 4, UNMARSHALL);
413 /* create and send a MSRPC command with api SPOOLSS_ENUMJOBS */
415 DEBUG(5,("SPOOLSS Enum Printer driver)\n"));
417 make_spoolss_q_getprinterdriver2(&q_o, hnd, environment, level, 2, 0, buffer, offered);
419 /* turn parameters into data stream */
420 if (!spoolss_io_q_getprinterdriver2("", &q_o, &buf, 0)) {
425 if(!rpc_hnd_pipe_req(hnd, SPOOLSS_GETPRINTERDRIVER2, &buf, &rbuf)) {
433 prs_switch_type(&buffer->prs, UNMARSHALL);
434 prs_set_offset(&buffer->prs, 0);
437 if(!spoolss_io_r_getprinterdriver2("", &r_o, &rbuf, 0)) {
451 /****************************************************************************
452 do a SPOOLSS Open Printer Ex
453 ****************************************************************************/
454 BOOL spoolss_open_printer_ex( const char *printername,
455 const char *datatype, uint32 access_required,
456 const char *station, const char *username,
461 SPOOL_Q_OPEN_PRINTER_EX q_o;
462 BOOL valid_pol = False;
466 struct cli_connection *con = NULL;
468 memset(srv_name, 0, sizeof(srv_name));
469 fstrcpy(srv_name, printername);
471 s = strchr(&srv_name[2], '\\');
475 if (!cli_connection_init(srv_name, PIPE_SPOOLSS, &con))
478 if (hnd == NULL) return False;
480 prs_init(&buf , MAX_PDU_FRAG_LEN, 4, MARSHALL);
481 prs_init(&rbuf, 0, 4, UNMARSHALL);
483 /* create and send a MSRPC command with api SPOOLSS_OPENPRINTEREX */
485 DEBUG(5,("SPOOLSS Open Printer Ex\n"));
487 make_spoolss_q_open_printer_ex(&q_o, printername, datatype,
488 access_required, station, username);
490 /* turn parameters into data stream */
491 if (spoolss_io_q_open_printer_ex("", &q_o, &buf, 0) &&
492 rpc_con_pipe_req(con, SPOOLSS_OPENPRINTEREX, &buf, &rbuf))
494 SPOOL_R_OPEN_PRINTER_EX r_o;
497 spoolss_io_r_open_printer_ex("", &r_o, &rbuf, 0);
499 if (prs_offset(&rbuf)!= 0 && r_o.status != 0)
501 /* report error code */
502 DEBUG(5,("SPOOLSS_OPENPRINTEREX: %s\n", get_nt_error_msg(r_o.status)));
508 /* ok, at last: we're happy. return the policy handle */
511 /* associate the handle returned with the current
512 state of the clienjt connection */
513 valid_pol = RpcHndList_set_connection(hnd, con);
524 /****************************************************************************
526 ****************************************************************************/
527 BOOL spoolss_closeprinter(POLICY_HND *hnd)
531 SPOOL_Q_CLOSEPRINTER q_c;
532 BOOL valid_close = False;
537 /* create and send a MSRPC command with api SPOOLSS_CLOSEPRINTER */
539 prs_init(&buf , MAX_PDU_FRAG_LEN, 4, MARSHALL);
540 prs_init(&rbuf, 0, 4, UNMARSHALL);
542 DEBUG(4,("SPOOL Close Printer\n"));
544 /* store the parameters */
545 make_spoolss_q_closeprinter(&q_c, hnd);
547 /* turn parameters into data stream */
548 if (spoolss_io_q_closeprinter("", &q_c, &buf, 0) &&
549 rpc_hnd_pipe_req(hnd, SPOOLSS_CLOSEPRINTER, &buf, &rbuf))
551 SPOOL_R_CLOSEPRINTER r_c;
553 spoolss_io_r_closeprinter("", &r_c, &rbuf, 0);
555 if (prs_offset(&rbuf)!=0 && r_c.status != 0)
557 /* report error code */
558 DEBUG(0,("SPOOL_CLOSEPRINTER: %s\n", get_nt_error_msg(r_c.status)));
567 /* disassociate with the cli_connection */
568 RpcHndList_del_connection(hnd);
573 /****************************************************************************
574 do a SPOOLSS Get printer datas
575 ****************************************************************************/
576 uint32 spoolss_getprinterdata(const POLICY_HND *hnd, const UNISTR2 *valuename,
585 SPOOL_Q_GETPRINTERDATA q_o;
586 SPOOL_R_GETPRINTERDATA r_o;
589 return NT_STATUS_INVALID_PARAMETER;
591 prs_init(&buf , MAX_PDU_FRAG_LEN, 4, MARSHALL);
592 prs_init(&rbuf, 0, 4, UNMARSHALL);
594 /* create and send a MSRPC command with api SPOOLSS_GETPRINTERDATA */
596 DEBUG(5,("SPOOLSS Get Printer data)\n"));
598 make_spoolss_q_getprinterdata(&q_o, hnd, valuename, in_size);
600 /* turn parameters into data stream */
601 if (!spoolss_io_q_getprinterdata("", &q_o, &buf, 0)) {
606 if (!rpc_hnd_pipe_req(hnd, SPOOLSS_GETPRINTERDATA, &buf, &rbuf)) {
616 if(!spoolss_io_r_getprinterdata("", &r_o, &rbuf, 0)) {
630 /****************************************************************************
631 do a SPOOLSS Get Printer Driver Direcotry
632 ****************************************************************************/
633 uint32 spoolss_getprinterdriverdir(fstring srv_name, fstring env_name, uint32 level,
634 NEW_BUFFER *buffer, uint32 offered,
639 SPOOL_Q_GETPRINTERDRIVERDIR q_o;
640 SPOOL_R_GETPRINTERDRIVERDIR r_o;
642 struct cli_connection *con = NULL;
644 if (!cli_connection_init(srv_name, PIPE_SPOOLSS, &con))
647 prs_init(&buf , MAX_PDU_FRAG_LEN, 4, MARSHALL);
648 prs_init(&rbuf, 0, 4, UNMARSHALL);
650 /* create and send a MSRPC command with api SPOOLSS_ENUM_PRINTERS */
652 DEBUG(5,("SPOOLSS GetPrinterDriverDir (Server: %s Env: %s level: %d)\n",
653 srv_name, env_name, level));
655 make_spoolss_q_getprinterdriverdir(&q_o, srv_name, env_name, level,
658 /* turn parameters into data stream */
659 if (!spoolss_io_q_getprinterdriverdir("", &q_o, &buf, 0) ) {
663 cli_connection_unlink(con);
666 if(!rpc_con_pipe_req(con, SPOOLSS_GETPRINTERDRIVERDIRECTORY, &buf, &rbuf)) {
670 cli_connection_unlink(con);
676 prs_switch_type(&buffer->prs, UNMARSHALL);
677 prs_set_offset(&buffer->prs, 0);
680 if(!spoolss_io_r_getprinterdriverdir("", &r_o, &rbuf, 0)) {
682 cli_connection_unlink(con);
689 cli_connection_unlink(con);