filled in 'change share command' parameter in smb.conf. Also regenerated
[Samba.git] / source / rpc_client / cli_spoolss_notify.c
blob879a4f129fc50cbbee355b7c42f3e7472d862349
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 "rpc_client.h"
26 #include "nterr.h"
28 extern int DEBUGLEVEL;
29 extern pstring global_myname;
31 /*********************************************************
32 Disconnect from the client machine.
33 **********************************************************/
34 BOOL spoolss_disconnect_from_client( struct cli_state *cli)
36 cli_nt_session_close(cli);
37 cli_ulogoff(cli);
38 cli_shutdown(cli);
40 return True;
44 /*********************************************************
45 Connect to the client machine.
46 **********************************************************/
48 BOOL spoolss_connect_to_client( struct cli_state *cli, char *remote_machine)
50 ZERO_STRUCTP(cli);
51 if(cli_initialise(cli) == False) {
52 DEBUG(0,("connect_to_client: unable to initialize client connection.\n"));
53 return False;
56 if(!resolve_name( remote_machine, &cli->dest_ip, 0x20)) {
57 DEBUG(0,("connect_to_client: Can't resolve address for %s\n", remote_machine));
58 cli_shutdown(cli);
59 return False;
62 if (ismyip(cli->dest_ip)) {
63 DEBUG(0,("connect_to_client: Machine %s is one of our addresses. Cannot add to ourselves.\n", remote_machine));
64 cli_shutdown(cli);
65 return False;
68 if (!cli_connect(cli, remote_machine, &cli->dest_ip)) {
69 DEBUG(0,("connect_to_client: unable to connect to SMB server on machine %s. Error was : %s.\n", remote_machine, cli_errstr(cli) ));
70 cli_shutdown(cli);
71 return False;
74 if (!attempt_netbios_session_request(cli, global_myname, remote_machine, &cli->dest_ip)) {
75 DEBUG(0,("connect_to_client: machine %s rejected the NetBIOS session request. Error was %s\n", remote_machine, cli_errstr(cli) ));
76 cli_shutdown(cli);
77 return False;
80 cli->protocol = PROTOCOL_NT1;
82 if (!cli_negprot(cli)) {
83 DEBUG(0,("connect_to_client: machine %s rejected the negotiate protocol. Error was : %s.\n", remote_machine, cli_errstr(cli) ));
84 cli_shutdown(cli);
85 return False;
88 if (cli->protocol != PROTOCOL_NT1) {
89 DEBUG(0,("connect_to_client: machine %s didn't negotiate NT protocol.\n", remote_machine));
90 cli_shutdown(cli);
91 return False;
95 * Do an anonymous session setup.
98 if (!cli_session_setup(cli, "", "", 0, "", 0, "")) {
99 DEBUG(0,("connect_to_client: machine %s rejected the session setup. Error was : %s.\n", remote_machine, cli_errstr(cli) ));
100 cli_shutdown(cli);
101 return False;
104 if (!(cli->sec_mode & 1)) {
105 DEBUG(0,("connect_to_client: machine %s isn't in user level security mode\n", remote_machine));
106 cli_shutdown(cli);
107 return False;
110 if (!cli_send_tconX(cli, "IPC$", "IPC", "", 1)) {
111 DEBUG(0,("connect_to_client: machine %s rejected the tconX on the IPC$ share. Error was : %s.\n", remote_machine, cli_errstr(cli) ));
112 cli_shutdown(cli);
113 return False;
117 * Ok - we have an anonymous connection to the IPC$ share.
118 * Now start the NT Domain stuff :-).
121 if(cli_nt_session_open(cli, PIPE_SPOOLSS) == False) {
122 DEBUG(0,("connect_to_client: unable to open the domain client session to machine %s. Error was : %s.\n", remote_machine, cli_errstr(cli)));
123 cli_nt_session_close(cli);
124 cli_ulogoff(cli);
125 cli_shutdown(cli);
126 return False;
129 return True;
132 /***************************************************************************
133 do a reply open printer
134 ****************************************************************************/
136 BOOL cli_spoolss_reply_open_printer(struct cli_state *cli, char *printer, uint32 localprinter, uint32 type, uint32 *status, POLICY_HND *handle)
138 prs_struct rbuf;
139 prs_struct buf;
141 SPOOL_Q_REPLYOPENPRINTER q_s;
142 SPOOL_R_REPLYOPENPRINTER r_s;
144 prs_init(&buf, 1024, cli->mem_ctx, MARSHALL);
145 prs_init(&rbuf, 0, cli->mem_ctx, UNMARSHALL );
147 /* create and send a MSRPC command with api SPOOLSS_REPLYOPENPRINTER */
149 DEBUG(4,("cli_spoolss_reply_open_printer: srv:%s acct:%s sc: %d mc: %s clnt %s %x\n",
150 cli->srv_name_slash, cli->mach_acct, sec_chan_type, global_myname,
151 credstr(new_clnt_cred.challenge.data), new_clnt_cred.timestamp.time));
153 /* store the parameters */
154 make_spoolss_q_replyopenprinter(&q_s, printer, localprinter, type);
156 /* turn parameters into data stream */
157 if(!spoolss_io_q_replyopenprinter("", &q_s, &buf, 0)) {
158 DEBUG(0,("cli_spoolss_reply_open_printer: Error : failed to marshall NET_Q_SRV_PWSET struct.\n"));
159 prs_mem_free(&buf);
160 prs_mem_free(&rbuf);
161 return False;
164 /* send the data on \PIPE\ */
165 if (!rpc_api_pipe_req(cli, SPOOLSS_REPLYOPENPRINTER, &buf, &rbuf)) {
166 prs_mem_free(&buf);
167 prs_mem_free(&rbuf);
168 return False;
171 prs_mem_free(&buf);
173 /* turn data stream into parameters*/
174 if(!spoolss_io_r_replyopenprinter("", &r_s, &rbuf, 0)) {
175 prs_mem_free(&rbuf);
176 return False;
179 prs_mem_free(&rbuf);
181 memcpy(handle, &r_s.handle, sizeof(r_s.handle));
182 *status=r_s.status;
184 return True;
187 /***************************************************************************
188 do a reply open printer
189 ****************************************************************************/
191 BOOL cli_spoolss_reply_rrpcn(struct cli_state *cli, POLICY_HND *handle,
192 uint32 change_low, uint32 change_high, uint32 *status)
194 prs_struct rbuf;
195 prs_struct buf;
197 SPOOL_Q_REPLY_RRPCN q_s;
198 SPOOL_R_REPLY_RRPCN r_s;
200 prs_init(&buf, 1024, cli->mem_ctx, MARSHALL);
201 prs_init(&rbuf, 0, cli->mem_ctx, UNMARSHALL );
203 /* create and send a MSRPC command with api */
205 DEBUG(4,("cli_spoolss_reply_open_printer: srv:%s acct:%s sc: %d mc: %s clnt %s %x\n",
206 cli->srv_name_slash, cli->mach_acct, sec_chan_type, global_myname,
207 credstr(new_clnt_cred.challenge.data), new_clnt_cred.timestamp.time));
209 /* store the parameters */
210 make_spoolss_q_reply_rrpcn(&q_s, handle, change_low, change_high);
212 /* turn parameters into data stream */
213 if(!spoolss_io_q_reply_rrpcn("", &q_s, &buf, 0)) {
214 DEBUG(0,("cli_spoolss_reply_rrpcn: Error : failed to marshall SPOOL_Q_REPLY_RRPCN struct.\n"));
215 prs_mem_free(&buf);
216 prs_mem_free(&rbuf);
217 return False;
220 /* send the data on \PIPE\ */
221 if (!rpc_api_pipe_req(cli, SPOOLSS_RRPCN, &buf, &rbuf)) {
222 prs_mem_free(&buf);
223 prs_mem_free(&rbuf);
224 return False;
227 prs_mem_free(&buf);
229 /* turn data stream into parameters*/
230 if(!spoolss_io_r_reply_rrpcn("", &r_s, &rbuf, 0)) {
231 prs_mem_free(&rbuf);
232 return False;
235 prs_mem_free(&rbuf);
237 *status=r_s.status;
239 return True;
242 /***************************************************************************
243 do a reply open printer
244 ****************************************************************************/
246 BOOL cli_spoolss_reply_close_printer(struct cli_state *cli, POLICY_HND *handle, uint32 *status)
248 prs_struct rbuf;
249 prs_struct buf;
251 SPOOL_Q_REPLYCLOSEPRINTER q_s;
252 SPOOL_R_REPLYCLOSEPRINTER r_s;
254 prs_init(&buf, 1024, cli->mem_ctx, MARSHALL);
255 prs_init(&rbuf, 0, cli->mem_ctx, UNMARSHALL );
257 /* create and send a MSRPC command with api */
259 DEBUG(4,("cli_spoolss_reply_open_printer: srv:%s acct:%s sc: %d mc: %s clnt %s %x\n",
260 cli->srv_name_slash, cli->mach_acct, sec_chan_type, global_myname,
261 credstr(new_clnt_cred.challenge.data), new_clnt_cred.timestamp.time));
263 /* store the parameters */
264 make_spoolss_q_reply_closeprinter(&q_s, handle);
266 /* turn parameters into data stream */
267 if(!spoolss_io_q_replycloseprinter("", &q_s, &buf, 0)) {
268 DEBUG(0,("cli_spoolss_reply_close_printer: Error : failed to marshall SPOOL_Q_REPLY_CLOSEPRINTER struct.\n"));
269 prs_mem_free(&buf);
270 prs_mem_free(&rbuf);
271 return False;
274 /* send the data on \PIPE\ */
275 if (!rpc_api_pipe_req(cli, SPOOLSS_REPLYCLOSEPRINTER, &buf, &rbuf)) {
276 prs_mem_free(&buf);
277 prs_mem_free(&rbuf);
278 return False;
281 prs_mem_free(&buf);
283 /* turn data stream into parameters*/
284 if(!spoolss_io_r_replycloseprinter("", &r_s, &rbuf, 0)) {
285 prs_mem_free(&rbuf);
286 return False;
289 prs_mem_free(&rbuf);
291 *status=r_s.status;
293 return True;