2 * Unix SMB/CIFS implementation.
3 * RPC Pipe client / server routines
4 * Copyright (C) Andrew Tridgell 1992-2000,
5 * Copyright (C) Luke Kenneth Casson Leighton 1996-2000,
6 * Copyright (C) Paul Ashton 1997-2000,
7 * Copyright (C) Jean Francois Micouleau 1998-2000,
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 #include "rpc_parse.h"
28 /****************************************************************************
29 do a SPOOLSS Enum Printer Drivers
30 ****************************************************************************/
31 uint32 spoolss_enum_printerdrivers(const char *srv_name, const char *environment,
32 uint32 level, NEW_BUFFER *buffer, uint32 offered,
33 uint32 *needed, uint32 *returned)
37 SPOOL_Q_ENUMPRINTERDRIVERS q_o;
38 SPOOL_R_ENUMPRINTERDRIVERS r_o;
39 TALLOC_CTX *ctx = prs_get_mem_context(&buffer->prs);
41 struct cli_connection *con = NULL;
43 if (!cli_connection_init(srv_name, PIPE_SPOOLSS, &con))
46 prs_init(&buf, MAX_PDU_FRAG_LEN, ctx, MARSHALL);
47 prs_init(&rbuf, 0, ctx, UNMARSHALL);
49 /* create and send a MSRPC command with api SPOOLSS_ENUM_PRINTERS */
51 DEBUG(5,("SPOOLSS Enum Printer Drivers (Server: %s Environment: %s level: %d)\n",
52 srv_name, environment, level));
54 make_spoolss_q_enumprinterdrivers(&q_o, srv_name, environment,
55 level, buffer, offered);
57 /* turn parameters into data stream */
58 if (spoolss_io_q_enumprinterdrivers("", &q_o, &buf, 0) &&
59 rpc_con_pipe_req(con, SPOOLSS_ENUMPRINTERDRIVERS, &buf, &rbuf))
64 prs_switch_type(&buffer->prs, UNMARSHALL);
65 prs_set_offset(&buffer->prs, 0);
68 if(spoolss_io_r_enumprinterdrivers("", &r_o, &rbuf, 0))
70 if (r_o.status != NT_STATUS_OK)
72 DEBUG(3,("SPOOLSS_ENUMPRINTERDRIVERS: %s\n", nt_errstr(r_o.status)));
75 *returned=r_o.returned;
82 cli_connection_unlink(con);
87 /****************************************************************************
88 do a SPOOLSS Enum Printers
89 ****************************************************************************/
90 uint32 spoolss_enum_printers(uint32 flags, fstring srv_name, uint32 level,
91 NEW_BUFFER *buffer, uint32 offered,
92 uint32 *needed, uint32 *returned)
96 SPOOL_Q_ENUMPRINTERS q_o;
97 SPOOL_R_ENUMPRINTERS r_o;
98 TALLOC_CTX *ctx = prs_get_mem_context(&buffer->prs);
100 struct cli_connection *con = NULL;
102 if (!cli_connection_init(srv_name, PIPE_SPOOLSS, &con))
105 prs_init(&buf, MAX_PDU_FRAG_LEN, ctx, MARSHALL);
106 prs_init(&rbuf, 0, ctx, UNMARSHALL);
108 /* create and send a MSRPC command with api SPOOLSS_ENUM_PRINTERS */
110 DEBUG(5,("SPOOLSS Enum Printers (Server: %s level: %d)\n", srv_name, level));
112 make_spoolss_q_enumprinters(&q_o, flags, "", level, buffer, offered);
114 /* turn parameters into data stream */
115 if (spoolss_io_q_enumprinters("", &q_o, &buf, 0) &&
116 rpc_con_pipe_req(con, SPOOLSS_ENUMPRINTERS, &buf, &rbuf))
120 prs_switch_type(&buffer->prs, UNMARSHALL);
121 prs_set_offset(&buffer->prs, 0);
124 if(new_spoolss_io_r_enumprinters("", &r_o, &rbuf, 0))
126 if (r_o.status != NT_STATUS_OK)
128 /* report error code */
129 DEBUG(3,("SPOOLSS_ENUMPRINTERS: %s\n", nt_errstr(r_o.status)));
133 *returned=r_o.returned;
141 cli_connection_unlink(con);
146 /****************************************************************************
147 do a SPOOLSS Enum Ports
148 ****************************************************************************/
149 uint32 spoolss_enum_ports(fstring srv_name, uint32 level,
150 NEW_BUFFER *buffer, uint32 offered,
151 uint32 *needed, uint32 *returned)
155 SPOOL_Q_ENUMPORTS q_o;
156 SPOOL_R_ENUMPORTS r_o;
157 TALLOC_CTX *ctx = prs_get_mem_context(&buffer->prs);
159 struct cli_connection *con = NULL;
161 if (!cli_connection_init(srv_name, PIPE_SPOOLSS, &con))
164 prs_init(&buf, MAX_PDU_FRAG_LEN, ctx, MARSHALL);
165 prs_init(&rbuf, 0, ctx, UNMARSHALL);
167 /* create and send a MSRPC command with api SPOOLSS_ENUMPORTS */
169 DEBUG(5,("SPOOLSS Enum Ports (Server: %s level: %d)\n", srv_name, level));
171 make_spoolss_q_enumports(&q_o, "", level, buffer, offered);
173 /* turn parameters into data stream */
174 if (spoolss_io_q_enumports("", &q_o, &buf, 0) &&
175 rpc_con_pipe_req(con, SPOOLSS_ENUMPORTS, &buf, &rbuf))
180 prs_switch_type(&buffer->prs, UNMARSHALL);
181 prs_set_offset(&buffer->prs, 0);
184 if(new_spoolss_io_r_enumports("", &r_o, &rbuf, 0))
186 if (r_o.status != NT_STATUS_OK)
188 DEBUG(3,("SPOOLSS_ENUMPORTS: %s\n", nt_errstr(r_o.status)));
192 *returned=r_o.returned;
199 cli_connection_unlink(con);
204 /****************************************************************************
205 do a SPOOLSS Enum Jobs
206 ****************************************************************************/
207 uint32 spoolss_enum_jobs(const POLICY_HND *hnd, uint32 firstjob, uint32 numofjobs,
208 uint32 level, NEW_BUFFER *buffer, uint32 offered,
209 uint32 *needed, uint32 *returned)
213 SPOOL_Q_ENUMJOBS q_o;
214 SPOOL_R_ENUMJOBS r_o;
215 TALLOC_CTX *ctx = prs_get_mem_context(&buffer->prs);
218 return NT_STATUS_INVALID_PARAMETER;
220 prs_init(&buf, MAX_PDU_FRAG_LEN, ctx, MARSHALL);
221 prs_init(&rbuf, 0, ctx, UNMARSHALL);
223 /* create and send a MSRPC command with api SPOOLSS_ENUMJOBS */
225 DEBUG(5,("SPOOLSS Enum Jobs level: %d)\n", level));
227 make_spoolss_q_enumjobs(&q_o, hnd, firstjob, numofjobs, level, buffer, offered);
229 /* turn parameters into data stream */
230 if (spoolss_io_q_enumjobs("", &q_o, &buf, 0) &&
231 rpc_hnd_pipe_req(hnd, SPOOLSS_ENUMJOBS, &buf, &rbuf))
238 if(spoolss_io_r_enumjobs("", &r_o, &rbuf, 0))
240 if (r_o.status != NT_STATUS_OK)
242 DEBUG(3,("SPOOLSS_ENUMJOBS: %s\n", nt_errstr(r_o.status)));
245 *returned=r_o.returned;
255 /***************************************************************************
256 do a SPOOLSS Enum printer datas
257 ****************************************************************************/
258 uint32 spoolss_enum_printerdata(const POLICY_HND *hnd, uint32 idx,
259 uint32 *valuelen, uint16 *value, uint32 *rvaluelen,
260 uint32 *type, uint32 *datalen, uint8 *data,
265 SPOOL_Q_ENUMPRINTERDATA q_o;
266 SPOOL_R_ENUMPRINTERDATA r_o;
267 TALLOC_CTX *mem_ctx = NULL;
270 return NT_STATUS_INVALID_PARAMETER;
272 if ((mem_ctx=talloc_init()) == NULL)
274 DEBUG(0,("msrpc_spoolss_enum_jobs: talloc_init failed!\n"));
277 prs_init(&buf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
278 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
280 /* create and send a MSRPC command with api SPOOLSS_ENUMPRINTERDATA*/
282 DEBUG(4,("SPOOLSS Enum Printer data\n"));
284 make_spoolss_q_enumprinterdata(&q_o, hnd, idx, *valuelen, *datalen);
286 /* turn parameters into data stream */
287 if (spoolss_io_q_enumprinterdata("", &q_o, &buf, 0) &&
288 rpc_hnd_pipe_req(hnd, SPOOLSS_ENUMPRINTERDATA, &buf, &rbuf))
296 if(spoolss_io_r_enumprinterdata("", &r_o, &rbuf, 0))
298 if (r_o.status != NT_STATUS_OK)
300 DEBUG(3,("SPOOLSS_ENUMPRINTERDATA: %s\n", nt_errstr(r_o.status)));
303 *valuelen=r_o.valuesize;
304 *rvaluelen=r_o.realvaluesize;
306 *datalen=r_o.datasize;
307 *rdatalen=r_o.realdatasize;
315 talloc_destroy(mem_ctx);
320 /****************************************************************************
321 do a SPOOLSS Enum printer datas
322 ****************************************************************************/
323 uint32 spoolss_getprinter(const POLICY_HND *hnd, uint32 level,
324 NEW_BUFFER *buffer, uint32 offered,
329 SPOOL_Q_GETPRINTER q_o;
330 SPOOL_R_GETPRINTER r_o;
331 TALLOC_CTX *ctx = prs_get_mem_context(&buffer->prs);
334 return NT_STATUS_INVALID_PARAMETER;
336 prs_init(&buf, MAX_PDU_FRAG_LEN, ctx, MARSHALL);
337 prs_init(&rbuf, 0, ctx, UNMARSHALL);
339 /* create and send a MSRPC command with api SPOOLSS_ENUMJOBS */
341 DEBUG(5,("SPOOLSS Enum Printer data)\n"));
343 make_spoolss_q_getprinter(&q_o, hnd, level, buffer, offered);
345 /* turn parameters into data stream */
346 if (spoolss_io_q_getprinter("", &q_o, &buf, 0) &&
347 rpc_hnd_pipe_req(hnd, SPOOLSS_GETPRINTER, &buf, &rbuf))
352 prs_switch_type(&buffer->prs, UNMARSHALL);
353 prs_set_offset(&buffer->prs, 0);
356 if(!spoolss_io_r_getprinter("", &r_o, &rbuf, 0))
358 if (r_o.status != NT_STATUS_OK)
360 DEBUG(3,("SPOOLSS_GETPRINTER: %s\n", nt_errstr(r_o.status)));
372 /****************************************************************************
373 do a SPOOLSS Enum printer driver
374 ****************************************************************************/
375 uint32 spoolss_getprinterdriver(const POLICY_HND *hnd,
376 const char *environment, uint32 level,
377 NEW_BUFFER *buffer, uint32 offered,
382 SPOOL_Q_GETPRINTERDRIVER2 q_o;
383 SPOOL_R_GETPRINTERDRIVER2 r_o;
384 TALLOC_CTX *ctx = prs_get_mem_context(&buffer->prs);
387 return NT_STATUS_INVALID_PARAMETER;
389 prs_init(&buf, MAX_PDU_FRAG_LEN, ctx, MARSHALL);
390 prs_init(&rbuf, 0, ctx, UNMARSHALL);
392 /* create and send a MSRPC command with api SPOOLSS_ENUMJOBS */
394 DEBUG(5,("SPOOLSS Enum Printer driver)\n"));
396 make_spoolss_q_getprinterdriver2(&q_o, hnd, environment, level, 2, 0, buffer, offered);
398 /* turn parameters into data stream */
399 if (spoolss_io_q_getprinterdriver2("", &q_o, &buf, 0) &&
400 rpc_hnd_pipe_req(hnd, SPOOLSS_GETPRINTERDRIVER2, &buf, &rbuf))
405 prs_switch_type(&buffer->prs, UNMARSHALL);
406 prs_set_offset(&buffer->prs, 0);
409 if(spoolss_io_r_getprinterdriver2("", &r_o, &rbuf, 0))
411 if (r_o.status != NT_STATUS_OK)
413 DEBUG(3,("SPOOLSS_GETPRINTERDRIVER2: %s\n", nt_errstr(r_o.status)));
428 /****************************************************************************
429 do a SPOOLSS Open Printer Ex
430 ****************************************************************************/
431 BOOL spoolss_open_printer_ex( const char *printername,
432 const char *datatype, uint32 access_required,
433 const char *station, const char *username,
438 SPOOL_Q_OPEN_PRINTER_EX q_o;
439 BOOL valid_pol = False;
442 struct cli_connection *con = NULL;
443 TALLOC_CTX *mem_ctx = NULL;
445 memset(srv_name, 0, sizeof(srv_name));
446 fstrcpy(srv_name, printername);
448 s = strchr_m(&srv_name[2], '\\');
452 if (!cli_connection_init(srv_name, PIPE_SPOOLSS, &con))
458 if ((mem_ctx=talloc_init()) == NULL)
460 DEBUG(0,("msrpc_spoolss_enum_jobs: talloc_init failed!\n"));
463 prs_init(&buf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
464 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
466 /* create and send a MSRPC command with api SPOOLSS_OPENPRINTEREX */
468 DEBUG(5,("SPOOLSS Open Printer Ex\n"));
470 make_spoolss_q_open_printer_ex(&q_o, printername, datatype,
471 access_required, station, username);
473 /* turn parameters into data stream */
474 if (spoolss_io_q_open_printer_ex("", &q_o, &buf, 0) &&
475 rpc_con_pipe_req(con, SPOOLSS_OPENPRINTEREX, &buf, &rbuf))
477 SPOOL_R_OPEN_PRINTER_EX r_o;
480 spoolss_io_r_open_printer_ex("", &r_o, &rbuf, 0);
482 if (prs_offset(&rbuf)!= 0 && r_o.status != 0)
484 /* report error code */
485 DEBUG(3,("SPOOLSS_OPENPRINTEREX: %s\n", nt_errstr(r_o.status)));
491 /* ok, at last: we're happy. return the policy handle */
494 /* associate the handle returned with the current
495 state of the clienjt connection */
496 valid_pol = RpcHndList_set_connection(hnd, con);
504 talloc_destroy(mem_ctx);
509 /****************************************************************************
510 do a SPOOLSS AddPrinterEx()
511 **ALWAYS** uses as PRINTER_INFO level 2 struct
512 ****************************************************************************/
513 BOOL spoolss_addprinterex(POLICY_HND *hnd, const char* srv_name, PRINTER_INFO_2 *info2)
517 SPOOL_Q_ADDPRINTEREX q_o;
518 SPOOL_R_ADDPRINTEREX r_o;
519 struct cli_connection *con = NULL;
520 TALLOC_CTX *mem_ctx = NULL;
521 fstring the_client_name;
522 BOOL valid_pol = True;
526 if (!cli_connection_init(srv_name, PIPE_SPOOLSS, &con))
527 return NT_STATUS_ACCESS_DENIED;
530 return NT_STATUS_INVALID_PARAMETER;
532 if ((mem_ctx=talloc_init()) == NULL)
534 DEBUG(0,("spoolss_addprinterex: talloc_init() failed!\n"));
535 return NT_STATUS_ACCESS_DENIED;
537 prs_init(&buf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
538 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
540 /* create and send a MSRPC command with api SPOOLSS_ENUMPORTS */
541 DEBUG(5,("SPOOLSS Add Printer Ex (Server: %s)\n", srv_name));
543 fstrcpy(the_client_name, "\\\\");
544 fstrcat(the_client_name, con->pCli_state->desthost);
545 strupper(the_client_name);
548 make_spoolss_q_addprinterex(mem_ctx, &q_o, srv_name, the_client_name,
549 /* "Administrator", */
550 con->pCli_state->user_name,
553 /* turn parameters into data stream and send the request */
554 if (spoolss_io_q_addprinterex("", &q_o, &buf, 0) &&
555 rpc_con_pipe_req(con, SPOOLSS_ADDPRINTEREX, &buf, &rbuf))
559 if(spoolss_io_r_addprinterex("", &r_o, &rbuf, 0))
561 if (r_o.status != NT_STATUS_OK)
563 /* report error code */
564 DEBUG(3,("SPOOLSS_ADDPRINTEREX: %s\n", nt_errstr(r_o.status)));
571 /* ok, at last: we're happy. return the policy handle */
572 copy_policy_hnd( hnd, &r_o.handle);
574 /* associate the handle returned with the current
575 state of the clienjt connection */
576 RpcHndList_set_connection(hnd, con);
585 talloc_destroy(mem_ctx);
590 /****************************************************************************
592 ****************************************************************************/
593 BOOL spoolss_closeprinter(POLICY_HND *hnd)
597 SPOOL_Q_CLOSEPRINTER q_c;
598 BOOL valid_close = False;
599 TALLOC_CTX *mem_ctx = NULL;
604 /* create and send a MSRPC command with api SPOOLSS_CLOSEPRINTER */
605 if ((mem_ctx=talloc_init()) == NULL)
607 DEBUG(0,("msrpc_spoolss_enum_jobs: talloc_init failed!\n"));
610 prs_init(&buf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
611 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
613 DEBUG(4,("SPOOL Close Printer\n"));
615 /* store the parameters */
616 make_spoolss_q_closeprinter(&q_c, hnd);
618 /* turn parameters into data stream */
619 if (spoolss_io_q_closeprinter("", &q_c, &buf, 0) &&
620 rpc_hnd_pipe_req(hnd, SPOOLSS_CLOSEPRINTER, &buf, &rbuf))
622 SPOOL_R_CLOSEPRINTER r_c;
624 spoolss_io_r_closeprinter("", &r_c, &rbuf, 0);
626 if (prs_offset(&rbuf)!=0 && r_c.status != 0)
628 /* report error code */
629 DEBUG(3,("SPOOL_CLOSEPRINTER: %s\n", nt_errstr(r_c.status)));
638 talloc_destroy(mem_ctx);
640 /* disassociate with the cli_connection */
641 RpcHndList_del_connection(hnd);
646 /****************************************************************************
647 do a SPOOLSS Get printer datas
648 ****************************************************************************/
649 uint32 spoolss_getprinterdata(const POLICY_HND *hnd, const UNISTR2 *valuename,
658 SPOOL_Q_GETPRINTERDATA q_o;
659 SPOOL_R_GETPRINTERDATA r_o;
660 TALLOC_CTX *mem_ctx = NULL;
663 return NT_STATUS_INVALID_PARAMETER;
665 if ((mem_ctx=talloc_init()) == NULL)
667 DEBUG(0,("msrpc_spoolss_enum_jobs: talloc_init failed!\n"));
670 prs_init(&buf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
671 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
673 /* create and send a MSRPC command with api SPOOLSS_GETPRINTERDATA */
675 DEBUG(5,("SPOOLSS Get Printer data)\n"));
677 make_spoolss_q_getprinterdata(&q_o, hnd,(UNISTR2 *)valuename, in_size);
679 /* turn parameters into data stream */
680 if (spoolss_io_q_getprinterdata("", &q_o, &buf, 0) &&
681 rpc_hnd_pipe_req(hnd, SPOOLSS_GETPRINTERDATA, &buf, &rbuf))
688 if(spoolss_io_r_getprinterdata("", &r_o, &rbuf, 0))
690 if (r_o.status != NT_STATUS_OK)
692 DEBUG(3,("SPOOLSS_GETPRINTERDATA: %s\n", nt_errstr(r_o.status)));
707 /****************************************************************************
708 do a SPOOLSS Get Printer Driver Direcotry
709 ****************************************************************************/
710 uint32 spoolss_getprinterdriverdir(fstring srv_name, fstring env_name, uint32 level,
711 NEW_BUFFER *buffer, uint32 offered,
716 SPOOL_Q_GETPRINTERDRIVERDIR q_o;
717 SPOOL_R_GETPRINTERDRIVERDIR r_o;
718 TALLOC_CTX *ctx = prs_get_mem_context(&buffer->prs);
720 struct cli_connection *con = NULL;
722 if (!cli_connection_init(srv_name, PIPE_SPOOLSS, &con))
725 prs_init(&buf, MAX_PDU_FRAG_LEN, ctx, MARSHALL);
726 prs_init(&rbuf, 0, ctx, UNMARSHALL);
728 /* create and send a MSRPC command with api SPOOLSS_ENUM_PRINTERS */
730 DEBUG(5,("SPOOLSS GetPrinterDriverDir (Server: %s Env: %s level: %d)\n",
731 srv_name, env_name, level));
733 make_spoolss_q_getprinterdriverdir(&q_o, srv_name, env_name, level,
736 /* turn parameters into data stream */
737 if (spoolss_io_q_getprinterdriverdir("", &q_o, &buf, 0) &&
738 rpc_con_pipe_req(con, SPOOLSS_GETPRINTERDRIVERDIRECTORY, &buf, &rbuf))
743 prs_switch_type(&buffer->prs, UNMARSHALL);
744 prs_set_offset(&buffer->prs, 0);
747 if(spoolss_io_r_getprinterdriverdir("", &r_o, &rbuf, 0))
749 if (r_o.status != NT_STATUS_OK)
751 DEBUG(3,("SPOOLSS_GETPRINTERDRIVERDIRECTORY: %s\n", nt_errstr(r_o.status)));
761 cli_connection_unlink(con);
766 /******************************************************************************
768 *****************************************************************************/
769 uint32 spoolss_addprinterdriver(const char *srv_name, uint32 level, PRINTER_DRIVER_CTR *info)
773 SPOOL_Q_ADDPRINTERDRIVER q_o;
774 SPOOL_R_ADDPRINTERDRIVER r_o;
775 TALLOC_CTX *mem_ctx = NULL;
776 struct cli_connection *con = NULL;
778 if (!cli_connection_init(srv_name, PIPE_SPOOLSS, &con))
781 if ((mem_ctx=talloc_init()) == NULL)
783 DEBUG(0,("msrpc_spoolss_enum_jobs: talloc_init failed!\n"));
786 prs_init(&buf, MAX_PDU_FRAG_LEN, mem_ctx, MARSHALL);
787 prs_init(&rbuf, 0, mem_ctx, UNMARSHALL);
789 /* make the ADDPRINTERDRIVER PDU */
790 make_spoolss_q_addprinterdriver(mem_ctx, &q_o, srv_name, level, info);
792 /* turn the data into an io stream */
793 if (spoolss_io_q_addprinterdriver("", &q_o, &buf, 0) &&
794 rpc_con_pipe_req(con, SPOOLSS_ADDPRINTERDRIVER, &buf, &rbuf))
798 if(spoolss_io_r_addprinterdriver("", &r_o, &rbuf, 0))
800 if (r_o.status != NT_STATUS_OK)
802 /* report error code */
803 DEBUG(3,("SPOOLSS_ADDPRINTERDRIVER: %s\n", nt_errstr(r_o.status)));
813 talloc_destroy(mem_ctx);