2 * Unix SMB/Netbios implementation.
4 * RPC client routines: scheduler service
5 * Copyright (C) Matthew Chapman 1999,
6 * Copyright (C) Luke Kenneth Casson Leighton 1996-1999,
7 * Copyright (C) Andrew Tridgell 1992-1999.
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"
26 #include "rpc_client.h"
28 extern int DEBUGLEVEL
;
30 /****************************************************************************
31 add a job to the scheduler
32 ****************************************************************************/
33 BOOL
at_add_job(char *srv_name
, AT_JOB_INFO
*info
, char *command
,
41 struct cli_connection
*con
= NULL
;
43 if (!cli_connection_init(srv_name
, PIPE_ATSVC
, &con
))
48 prs_init(&buf
, 0, 4, False
);
49 prs_init(&rbuf
, 0, 4, True
);
51 /* create and send a MSRPC command with api AT_ADD_JOB */
53 DEBUG(4, ("Scheduler Add Job\n"));
55 /* store the parameters */
56 make_at_q_add_job(&q_a
, srv_name
, info
, command
);
58 /* turn parameters into data stream */
59 if (at_io_q_add_job("", &q_a
, &buf
, 0) &&
60 rpc_con_pipe_req(con
, AT_ADD_JOB
, &buf
, &rbuf
))
64 at_io_r_add_job("", &r_a
, &rbuf
, 0);
67 if (p
&& r_a
.status
!= 0)
69 /* report error code */
70 DEBUG(0, ("AT_R_ADD_JOB: %s\n",
71 get_nt_error_msg(r_a
.status
)));
84 cli_connection_unlink(con
);
89 /****************************************************************************
91 ****************************************************************************/
92 BOOL
at_del_job(char *srv_name
, uint32 min_jobid
, uint32 max_jobid
)
99 struct cli_connection
*con
= NULL
;
101 if (!cli_connection_init(srv_name
, PIPE_ATSVC
, &con
))
106 prs_init(&buf
, 0, 4, False
);
107 prs_init(&rbuf
, 0, 4, True
);
109 /* create and send a MSRPC command with api AT_DEL_JOB */
111 DEBUG(4, ("Scheduler Delete Job\n"));
113 /* store the parameters */
114 make_at_q_del_job(&q_d
, srv_name
, min_jobid
, max_jobid
);
116 /* turn parameters into data stream */
117 if (at_io_q_del_job("", &q_d
, &buf
, 0) &&
118 rpc_con_pipe_req(con
, AT_DEL_JOB
, &buf
, &rbuf
))
122 at_io_r_del_job("", &r_d
, &rbuf
, 0);
123 p
= rbuf
.offset
!= 0;
125 if (p
&& r_d
.status
!= 0)
127 /* report error code */
128 DEBUG(0, ("AT_R_DEL_JOB: %s\n",
129 get_nt_error_msg(r_d
.status
)));
134 prs_free_data(&rbuf
);
135 prs_free_data(&buf
);
137 cli_connection_unlink(con
);
142 /****************************************************************************
143 enumerate scheduled jobs
144 ****************************************************************************/
145 BOOL
at_enum_jobs(char *srv_name
, uint32
*num_jobs
,
146 AT_ENUM_INFO
*jobs
, char ***commands
)
153 struct cli_connection
*con
= NULL
;
155 if (!cli_connection_init(srv_name
, PIPE_ATSVC
, &con
))
160 prs_init(&buf
, 0, 4, False
);
161 prs_init(&rbuf
, 0, 4, True
);
163 /* create and send a MSRPC command with api AT_DEL_JOB */
165 DEBUG(4, ("Scheduler Enumerate Jobs\n"));
167 /* store the parameters */
168 make_at_q_enum_jobs(&q_e
, srv_name
);
170 /* turn parameters into data stream */
171 if (at_io_q_enum_jobs("", &q_e
, &buf
, 0) &&
172 rpc_con_pipe_req(con
, AT_ENUM_JOBS
, &buf
, &rbuf
))
176 at_io_r_enum_jobs("", &r_e
, &rbuf
, 0);
177 p
= rbuf
.offset
!= 0;
179 if (p
&& r_e
.status
!= 0)
181 /* report error code */
182 DEBUG(0, ("AT_R_ENUM_JOBS: %s\n",
183 get_nt_error_msg(r_e
.status
)));
192 memcpy(jobs
, &r_e
.info
,
193 r_e
.num_entries
* sizeof(AT_ENUM_INFO
));
195 for (i
= 0; i
< r_e
.num_entries
; i
++)
198 unistr2_to_ascii(cmd
, &r_e
.command
[i
],
200 add_chars_to_array(num_jobs
, commands
, cmd
);
202 if ((*num_jobs
) != r_e
.num_entries
)
209 prs_free_data(&rbuf
);
210 prs_free_data(&buf
);
212 cli_connection_unlink(con
);
217 /****************************************************************************
218 query job information
219 ****************************************************************************/
220 BOOL
at_query_job(char *srv_name
,
221 uint32 jobid
, AT_JOB_INFO
*job
, fstring command
)
228 struct cli_connection
*con
= NULL
;
230 if (!cli_connection_init(srv_name
, PIPE_ATSVC
, &con
))
235 prs_init(&buf
, 0, 4, False
);
236 prs_init(&rbuf
, 0, 4, True
);
238 /* create and send a MSRPC command with api AT_QUERY_JOB */
240 DEBUG(4, ("Scheduler Query Job\n"));
242 /* store the parameters */
243 make_at_q_query_job(&q_q
, srv_name
, jobid
);
245 /* turn parameters into data stream */
246 if (at_io_q_query_job("", &q_q
, &buf
, 0) &&
247 rpc_con_pipe_req(con
, AT_QUERY_JOB
, &buf
, &rbuf
))
251 at_io_r_query_job("", &r_q
, &rbuf
, 0);
252 p
= rbuf
.offset
!= 0;
254 if (p
&& r_q
.status
!= 0)
256 /* report error code */
257 DEBUG(0, ("AT_R_QUERY_JOB: %s\n",
258 get_nt_error_msg(r_q
.status
)));
264 memcpy(job
, &r_q
.info
, sizeof(AT_JOB_INFO
));
265 unistr2_to_ascii(command
, &r_q
.command
,
270 prs_free_data(&rbuf
);
271 prs_free_data(&buf
);
273 cli_connection_unlink(con
);