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.
26 extern int DEBUGLEVEL;
28 /****************************************************************************
29 add a job to the scheduler
30 ****************************************************************************/
32 char *srv_name, AT_JOB_INFO *info, char *command,
40 struct cli_connection *con = NULL;
42 if (!cli_connection_init(srv_name, PIPE_ATSVC, &con))
47 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
48 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
50 /* create and send a MSRPC command with api AT_ADD_JOB */
52 DEBUG(4,("Scheduler Add Job\n"));
54 /* store the parameters */
55 make_at_q_add_job(&q_a, srv_name, info, command);
57 /* turn parameters into data stream */
58 at_io_q_add_job("", &q_a, &buf, 0);
60 /* send the data on \PIPE\ */
61 if (rpc_con_pipe_req(con, AT_ADD_JOB, &buf, &rbuf))
65 at_io_r_add_job("", &r_a, &rbuf, 0);
68 if (p && r_a.status != 0)
70 /* report error code */
71 DEBUG(0,("AT_R_ADD_JOB: %s\n", 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 , 1024, 4, SAFETY_MARGIN, False);
107 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, 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 at_io_q_del_job("", &q_d, &buf, 0);
119 /* send the data on \PIPE\ */
120 if (rpc_con_pipe_req(con, AT_DEL_JOB, &buf, &rbuf))
124 at_io_r_del_job("", &r_d, &rbuf, 0);
125 p = rbuf.offset != 0;
127 if (p && r_d.status != 0)
129 /* report error code */
130 DEBUG(0,("AT_R_DEL_JOB: %s\n", get_nt_error_msg(r_d.status)));
138 cli_connection_unlink(con);
143 /****************************************************************************
144 enumerate scheduled jobs
145 ****************************************************************************/
146 BOOL at_enum_jobs( char *srv_name, uint32 *num_jobs,
147 AT_ENUM_INFO *jobs, char ***commands)
154 struct cli_connection *con = NULL;
156 if (!cli_connection_init(srv_name, PIPE_ATSVC, &con))
161 prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
162 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, True );
164 /* create and send a MSRPC command with api AT_DEL_JOB */
166 DEBUG(4,("Scheduler Enumerate Jobs\n"));
168 /* store the parameters */
169 make_at_q_enum_jobs(&q_e, srv_name);
171 /* turn parameters into data stream */
172 at_io_q_enum_jobs("", &q_e, &buf, 0);
174 /* send the data on \PIPE\ */
175 if (rpc_con_pipe_req(con, AT_ENUM_JOBS, &buf, &rbuf))
179 at_io_r_enum_jobs("", &r_e, &rbuf, 0);
180 p = rbuf.offset != 0;
182 if (p && r_e.status != 0)
184 /* report error code */
185 DEBUG(0,("AT_R_ENUM_JOBS: %s\n", get_nt_error_msg(r_e.status)));
194 memcpy(jobs, &r_e.info, r_e.num_entries * sizeof(AT_ENUM_INFO));
196 for (i = 0; i < r_e.num_entries; i++)
199 unistr2_to_ascii(cmd, &r_e.command[i], sizeof(cmd));
200 add_chars_to_array(num_jobs, commands, cmd);
202 if ((*num_jobs) != r_e.num_entries)
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 , 1024, 4, SAFETY_MARGIN, False);
236 prs_init(&rbuf, 0 , 4, SAFETY_MARGIN, 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 at_io_q_query_job("", &q_q, &buf, 0);
248 /* send the data on \PIPE\ */
249 if (rpc_con_pipe_req(con, AT_QUERY_JOB, &buf, &rbuf))
253 at_io_r_query_job("", &r_q, &rbuf, 0);
254 p = rbuf.offset != 0;
256 if (p && r_q.status != 0)
258 /* report error code */
259 DEBUG(0,("AT_R_QUERY_JOB: %s\n", get_nt_error_msg(r_q.status)));
265 memcpy(job, &r_q.info, sizeof(AT_JOB_INFO));
266 unistr2_to_ascii(command, &r_q.command,
274 cli_connection_unlink(con);