2 * Unix SMB/CIFS implementation.
3 * RPC Pipe client / server routines
4 * Copyright (C) Andrew Tridgell 1992-2000,
5 * Copyright (C) Jean Francois Micouleau 1998-2000,
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include "rpc_parse.h"
26 extern pstring global_myname;
28 /*********************************************************
29 Disconnect from the client machine.
30 **********************************************************/
31 BOOL spoolss_disconnect_from_client( struct cli_state *cli)
33 cli_nt_session_close(cli);
41 /*********************************************************
42 Connect to the client machine.
43 **********************************************************/
45 BOOL spoolss_connect_to_client( struct cli_state *cli, char *remote_machine)
48 if(cli_initialise(cli) == NULL) {
49 DEBUG(0,("connect_to_client: unable to initialize client connection.\n"));
53 if(!resolve_name( remote_machine, &cli->dest_ip, 0x20)) {
54 DEBUG(0,("connect_to_client: Can't resolve address for %s\n", remote_machine));
59 if (ismyip(cli->dest_ip)) {
60 DEBUG(0,("connect_to_client: Machine %s is one of our addresses. Cannot add to ourselves.\n", remote_machine));
65 if (!cli_connect(cli, remote_machine, &cli->dest_ip)) {
66 DEBUG(0,("connect_to_client: unable to connect to SMB server on machine %s. Error was : %s.\n", remote_machine, cli_errstr(cli) ));
71 if (!attempt_netbios_session_request(cli, global_myname, remote_machine, &cli->dest_ip)) {
72 DEBUG(0,("connect_to_client: machine %s rejected the NetBIOS session request. Error was %s\n", remote_machine, cli_errstr(cli) ));
77 cli->protocol = PROTOCOL_NT1;
79 if (!cli_negprot(cli)) {
80 DEBUG(0,("connect_to_client: machine %s rejected the negotiate protocol. Error was : %s.\n", remote_machine, cli_errstr(cli) ));
85 if (cli->protocol != PROTOCOL_NT1) {
86 DEBUG(0,("connect_to_client: machine %s didn't negotiate NT protocol.\n", remote_machine));
92 * Do an anonymous session setup.
95 if (!cli_session_setup(cli, "", "", 0, "", 0, "")) {
96 DEBUG(0,("connect_to_client: machine %s rejected the session setup. Error was : %s.\n", remote_machine, cli_errstr(cli) ));
101 if (!(cli->sec_mode & 1)) {
102 DEBUG(0,("connect_to_client: machine %s isn't in user level security mode\n", remote_machine));
107 if (!cli_send_tconX(cli, "IPC$", "IPC", "", 1)) {
108 DEBUG(0,("connect_to_client: machine %s rejected the tconX on the IPC$ share. Error was : %s.\n", remote_machine, cli_errstr(cli) ));
114 * Ok - we have an anonymous connection to the IPC$ share.
115 * Now start the NT Domain stuff :-).
118 if(cli_nt_session_open(cli, PIPE_SPOOLSS) == False) {
119 DEBUG(0,("connect_to_client: unable to open the domain client session to machine %s. Error was : %s.\n", remote_machine, cli_errstr(cli)));
120 cli_nt_session_close(cli);
129 /***************************************************************************
130 do a reply open printer
131 ****************************************************************************/
133 BOOL cli_spoolss_reply_open_printer(struct cli_state *cli, char *printer, uint32 localprinter, uint32 type, WERROR *status, POLICY_HND *handle)
138 SPOOL_Q_REPLYOPENPRINTER q_s;
139 SPOOL_R_REPLYOPENPRINTER r_s;
141 prs_init(&buf, 1024, cli->mem_ctx, MARSHALL);
142 prs_init(&rbuf, 0, cli->mem_ctx, UNMARSHALL );
144 /* create and send a MSRPC command with api SPOOLSS_REPLYOPENPRINTER */
146 DEBUG(4,("cli_spoolss_reply_open_printer: srv:%s acct:%s sc: %d mc: %s clnt %s %x\n",
147 cli->srv_name_slash, cli->mach_acct, sec_chan_type, global_myname,
148 credstr(new_clnt_cred.challenge.data), new_clnt_cred.timestamp.time));
150 /* store the parameters */
151 make_spoolss_q_replyopenprinter(&q_s, printer, localprinter, type);
153 /* turn parameters into data stream */
154 if(!spoolss_io_q_replyopenprinter("", &q_s, &buf, 0)) {
155 DEBUG(0,("cli_spoolss_reply_open_printer: Error : failed to marshall NET_Q_SRV_PWSET struct.\n"));
161 /* send the data on \PIPE\ */
162 if (!rpc_api_pipe_req(cli, SPOOLSS_REPLYOPENPRINTER, &buf, &rbuf)) {
170 /* turn data stream into parameters*/
171 if(!spoolss_io_r_replyopenprinter("", &r_s, &rbuf, 0)) {
178 memcpy(handle, &r_s.handle, sizeof(r_s.handle));
184 /***************************************************************************
185 do a reply open printer
186 ****************************************************************************/
188 BOOL cli_spoolss_reply_rrpcn(struct cli_state *cli, POLICY_HND *handle,
189 uint32 change_low, uint32 change_high, WERROR *status)
194 SPOOL_Q_REPLY_RRPCN q_s;
195 SPOOL_R_REPLY_RRPCN r_s;
197 prs_init(&buf, 1024, cli->mem_ctx, MARSHALL);
198 prs_init(&rbuf, 0, cli->mem_ctx, UNMARSHALL );
200 /* create and send a MSRPC command with api */
202 DEBUG(4,("cli_spoolss_reply_open_printer: srv:%s acct:%s sc: %d mc: %s clnt %s %x\n",
203 cli->srv_name_slash, cli->mach_acct, sec_chan_type, global_myname,
204 credstr(new_clnt_cred.challenge.data), new_clnt_cred.timestamp.time));
206 /* store the parameters */
207 make_spoolss_q_reply_rrpcn(&q_s, handle, change_low, change_high);
209 /* turn parameters into data stream */
210 if(!spoolss_io_q_reply_rrpcn("", &q_s, &buf, 0)) {
211 DEBUG(0,("cli_spoolss_reply_rrpcn: Error : failed to marshall SPOOL_Q_REPLY_RRPCN struct.\n"));
217 /* send the data on \PIPE\ */
218 if (!rpc_api_pipe_req(cli, SPOOLSS_RRPCN, &buf, &rbuf)) {
226 /* turn data stream into parameters*/
227 if(!spoolss_io_r_reply_rrpcn("", &r_s, &rbuf, 0)) {
239 /***************************************************************************
240 do a reply open printer
241 ****************************************************************************/
243 BOOL cli_spoolss_reply_close_printer(struct cli_state *cli, POLICY_HND *handle,
249 SPOOL_Q_REPLYCLOSEPRINTER q_s;
250 SPOOL_R_REPLYCLOSEPRINTER r_s;
252 prs_init(&buf, 1024, cli->mem_ctx, MARSHALL);
253 prs_init(&rbuf, 0, cli->mem_ctx, UNMARSHALL );
255 /* create and send a MSRPC command with api */
257 DEBUG(4,("cli_spoolss_reply_open_printer: srv:%s acct:%s sc: %d mc: %s clnt %s %x\n",
258 cli->srv_name_slash, cli->mach_acct, sec_chan_type, global_myname,
259 credstr(new_clnt_cred.challenge.data), new_clnt_cred.timestamp.time));
261 /* store the parameters */
262 make_spoolss_q_reply_closeprinter(&q_s, handle);
264 /* turn parameters into data stream */
265 if(!spoolss_io_q_replycloseprinter("", &q_s, &buf, 0)) {
266 DEBUG(0,("cli_spoolss_reply_close_printer: Error : failed to marshall SPOOL_Q_REPLY_CLOSEPRINTER struct.\n"));
272 /* send the data on \PIPE\ */
273 if (!rpc_api_pipe_req(cli, SPOOLSS_REPLYCLOSEPRINTER, &buf, &rbuf)) {
281 /* turn data stream into parameters*/
282 if(!spoolss_io_r_replycloseprinter("", &r_s, &rbuf, 0)) {