few cleanups to bring in line with 2.2
[Samba/gbeck.git] / source / rpc_client / cli_spoolss_notify.c
bloba67b56adc55f95a28e1833181beae7b1a25ad8a8
1 /*
2 * Unix SMB/Netbios implementation.
3 * Version 1.9.
4 * RPC Pipe client / server routines
5 * Copyright (C) Andrew Tridgell 1992-2000,
6 * Copyright (C) Jean Francois Micouleau 1998-2000,
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include "includes.h"
24 #include "rpc_parse.h"
25 #include "nterr.h"
27 extern int DEBUGLEVEL;
28 extern pstring global_myname;
30 /*********************************************************
31 Disconnect from the client machine.
32 **********************************************************/
33 BOOL spoolss_disconnect_from_client( struct cli_state *cli)
35 cli_nt_session_close(cli);
36 cli_ulogoff(cli);
37 cli_shutdown(cli);
39 return True;
43 /*********************************************************
44 Connect to the client machine.
45 **********************************************************/
47 BOOL spoolss_connect_to_client( struct cli_state *cli, char *remote_machine)
49 ZERO_STRUCTP(cli);
50 if(cli_initialise(cli) == False) {
51 DEBUG(0,("connect_to_client: unable to initialize client connection.\n"));
52 return False;
55 if(!resolve_name( remote_machine, &cli->dest_ip, 0x20)) {
56 DEBUG(0,("connect_to_client: Can't resolve address for %s\n", remote_machine));
57 cli_shutdown(cli);
58 return False;
61 if (ismyip(cli->dest_ip)) {
62 DEBUG(0,("connect_to_client: Machine %s is one of our addresses. Cannot add to ourselves.\n", remote_machine));
63 cli_shutdown(cli);
64 return False;
67 if (!cli_connect(cli, remote_machine, &cli->dest_ip)) {
68 DEBUG(0,("connect_to_client: unable to connect to SMB server on machine %s. Error was : %s.\n", remote_machine, cli_errstr(cli) ));
69 cli_shutdown(cli);
70 return False;
73 if (!attempt_netbios_session_request(cli, global_myname, remote_machine, &cli->dest_ip)) {
74 DEBUG(0,("connect_to_client: machine %s rejected the NetBIOS session request. Error was %s\n", remote_machine, cli_errstr(cli) ));
75 cli_shutdown(cli);
76 return False;
79 cli->protocol = PROTOCOL_NT1;
81 if (!cli_negprot(cli)) {
82 DEBUG(0,("connect_to_client: machine %s rejected the negotiate protocol. Error was : %s.\n", remote_machine, cli_errstr(cli) ));
83 cli_shutdown(cli);
84 return False;
87 if (cli->protocol != PROTOCOL_NT1) {
88 DEBUG(0,("connect_to_client: machine %s didn't negotiate NT protocol.\n", remote_machine));
89 cli_shutdown(cli);
90 return False;
94 * Do an anonymous session setup.
97 if (!cli_session_setup(cli, "", "", 0, "", 0, "")) {
98 DEBUG(0,("connect_to_client: machine %s rejected the session setup. Error was : %s.\n", remote_machine, cli_errstr(cli) ));
99 cli_shutdown(cli);
100 return False;
103 if (!(cli->sec_mode & 1)) {
104 DEBUG(0,("connect_to_client: machine %s isn't in user level security mode\n", remote_machine));
105 cli_shutdown(cli);
106 return False;
109 if (!cli_send_tconX(cli, "IPC$", "IPC", "", 1)) {
110 DEBUG(0,("connect_to_client: machine %s rejected the tconX on the IPC$ share. Error was : %s.\n", remote_machine, cli_errstr(cli) ));
111 cli_shutdown(cli);
112 return False;
116 * Ok - we have an anonymous connection to the IPC$ share.
117 * Now start the NT Domain stuff :-).
120 if(cli_nt_session_open(cli, PIPE_SPOOLSS) == False) {
121 DEBUG(0,("connect_to_client: unable to open the domain client session to machine %s. Error was : %s.\n", remote_machine, cli_errstr(cli)));
122 cli_nt_session_close(cli);
123 cli_ulogoff(cli);
124 cli_shutdown(cli);
125 return False;
128 return True;
131 /***************************************************************************
132 do a reply open printer
133 ****************************************************************************/
135 BOOL cli_spoolss_reply_open_printer(struct cli_state *cli, char *printer, uint32 localprinter, uint32 type, uint32 *status, POLICY_HND *handle)
137 prs_struct rbuf;
138 prs_struct buf;
140 SPOOL_Q_REPLYOPENPRINTER q_s;
141 SPOOL_R_REPLYOPENPRINTER r_s;
143 prs_init(&buf, 1024, cli->mem_ctx, MARSHALL);
144 prs_init(&rbuf, 0, cli->mem_ctx, UNMARSHALL );
146 /* create and send a MSRPC command with api SPOOLSS_REPLYOPENPRINTER */
148 DEBUG(4,("cli_spoolss_reply_open_printer: srv:%s acct:%s sc: %d mc: %s clnt %s %x\n",
149 cli->srv_name_slash, cli->mach_acct, sec_chan_type, global_myname,
150 credstr(new_clnt_cred.challenge.data), new_clnt_cred.timestamp.time));
152 /* store the parameters */
153 make_spoolss_q_replyopenprinter(&q_s, printer, localprinter, type);
155 /* turn parameters into data stream */
156 if(!spoolss_io_q_replyopenprinter("", &q_s, &buf, 0)) {
157 DEBUG(0,("cli_spoolss_reply_open_printer: Error : failed to marshall NET_Q_SRV_PWSET struct.\n"));
158 prs_mem_free(&buf);
159 prs_mem_free(&rbuf);
160 return False;
163 /* send the data on \PIPE\ */
164 if (!rpc_api_pipe_req(cli, SPOOLSS_REPLYOPENPRINTER, &buf, &rbuf)) {
165 prs_mem_free(&buf);
166 prs_mem_free(&rbuf);
167 return False;
170 prs_mem_free(&buf);
172 /* turn data stream into parameters*/
173 if(!spoolss_io_r_replyopenprinter("", &r_s, &rbuf, 0)) {
174 prs_mem_free(&rbuf);
175 return False;
178 prs_mem_free(&rbuf);
180 memcpy(handle, &r_s.handle, sizeof(r_s.handle));
181 *status=r_s.status;
183 return True;
186 /***************************************************************************
187 do a reply open printer
188 ****************************************************************************/
190 BOOL cli_spoolss_reply_rrpcn(struct cli_state *cli, POLICY_HND *handle,
191 uint32 change_low, uint32 change_high, uint32 *status)
193 prs_struct rbuf;
194 prs_struct buf;
196 SPOOL_Q_REPLY_RRPCN q_s;
197 SPOOL_R_REPLY_RRPCN r_s;
199 prs_init(&buf, 1024, cli->mem_ctx, MARSHALL);
200 prs_init(&rbuf, 0, cli->mem_ctx, UNMARSHALL );
202 /* create and send a MSRPC command with api */
204 DEBUG(4,("cli_spoolss_reply_open_printer: srv:%s acct:%s sc: %d mc: %s clnt %s %x\n",
205 cli->srv_name_slash, cli->mach_acct, sec_chan_type, global_myname,
206 credstr(new_clnt_cred.challenge.data), new_clnt_cred.timestamp.time));
208 /* store the parameters */
209 make_spoolss_q_reply_rrpcn(&q_s, handle, change_low, change_high);
211 /* turn parameters into data stream */
212 if(!spoolss_io_q_reply_rrpcn("", &q_s, &buf, 0)) {
213 DEBUG(0,("cli_spoolss_reply_rrpcn: Error : failed to marshall SPOOL_Q_REPLY_RRPCN struct.\n"));
214 prs_mem_free(&buf);
215 prs_mem_free(&rbuf);
216 return False;
219 /* send the data on \PIPE\ */
220 if (!rpc_api_pipe_req(cli, SPOOLSS_RRPCN, &buf, &rbuf)) {
221 prs_mem_free(&buf);
222 prs_mem_free(&rbuf);
223 return False;
226 prs_mem_free(&buf);
228 /* turn data stream into parameters*/
229 if(!spoolss_io_r_reply_rrpcn("", &r_s, &rbuf, 0)) {
230 prs_mem_free(&rbuf);
231 return False;
234 prs_mem_free(&rbuf);
236 *status=r_s.status;
238 return True;
241 /***************************************************************************
242 do a reply open printer
243 ****************************************************************************/
245 BOOL cli_spoolss_reply_close_printer(struct cli_state *cli, POLICY_HND *handle, uint32 *status)
247 prs_struct rbuf;
248 prs_struct buf;
250 SPOOL_Q_REPLYCLOSEPRINTER q_s;
251 SPOOL_R_REPLYCLOSEPRINTER r_s;
253 prs_init(&buf, 1024, cli->mem_ctx, MARSHALL);
254 prs_init(&rbuf, 0, cli->mem_ctx, UNMARSHALL );
256 /* create and send a MSRPC command with api */
258 DEBUG(4,("cli_spoolss_reply_open_printer: srv:%s acct:%s sc: %d mc: %s clnt %s %x\n",
259 cli->srv_name_slash, cli->mach_acct, sec_chan_type, global_myname,
260 credstr(new_clnt_cred.challenge.data), new_clnt_cred.timestamp.time));
262 /* store the parameters */
263 make_spoolss_q_reply_closeprinter(&q_s, handle);
265 /* turn parameters into data stream */
266 if(!spoolss_io_q_replycloseprinter("", &q_s, &buf, 0)) {
267 DEBUG(0,("cli_spoolss_reply_close_printer: Error : failed to marshall SPOOL_Q_REPLY_CLOSEPRINTER struct.\n"));
268 prs_mem_free(&buf);
269 prs_mem_free(&rbuf);
270 return False;
273 /* send the data on \PIPE\ */
274 if (!rpc_api_pipe_req(cli, SPOOLSS_REPLYCLOSEPRINTER, &buf, &rbuf)) {
275 prs_mem_free(&buf);
276 prs_mem_free(&rbuf);
277 return False;
280 prs_mem_free(&buf);
282 /* turn data stream into parameters*/
283 if(!spoolss_io_r_replycloseprinter("", &r_s, &rbuf, 0)) {
284 prs_mem_free(&rbuf);
285 return False;
288 prs_mem_free(&rbuf);
290 *status=r_s.status;
292 return True;