preparing for release of alpha-2.6
[Samba/gbeck.git] / source / rpc_client / cli_atsvc.c
blobfcb6c011119e9ab6aefaf9c2438b8a1e98b94d3a
1 /*
2 * Unix SMB/Netbios implementation.
3 * Version 2.1.
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.
8 *
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.
24 #include "includes.h"
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,
34 uint32 *jobid)
36 prs_struct rbuf;
37 prs_struct buf;
38 AT_Q_ADD_JOB q_a;
39 BOOL p = False;
41 struct cli_connection *con = NULL;
43 if (!cli_connection_init(srv_name, PIPE_ATSVC, &con))
45 return False;
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))
62 AT_R_ADD_JOB r_a;
64 at_io_r_add_job("", &r_a, &rbuf, 0);
65 p = rbuf.offset != 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)));
72 p = False;
75 if (p)
77 *jobid = r_a.jobid;
81 prs_free_data(&rbuf);
82 prs_free_data(&buf );
84 cli_connection_unlink(con);
86 return p;
89 /****************************************************************************
90 dequeue a job
91 ****************************************************************************/
92 BOOL at_del_job(char *srv_name, uint32 min_jobid, uint32 max_jobid)
94 prs_struct rbuf;
95 prs_struct buf;
96 AT_Q_DEL_JOB q_d;
97 BOOL p = False;
99 struct cli_connection *con = NULL;
101 if (!cli_connection_init(srv_name, PIPE_ATSVC, &con))
103 return False;
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))
120 AT_R_DEL_JOB r_d;
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)));
130 p = False;
134 prs_free_data(&rbuf);
135 prs_free_data(&buf );
137 cli_connection_unlink(con);
139 return p;
142 /****************************************************************************
143 enumerate scheduled jobs
144 ****************************************************************************/
145 BOOL at_enum_jobs(char *srv_name, uint32 *num_jobs,
146 AT_ENUM_INFO *jobs, char ***commands)
148 prs_struct rbuf;
149 prs_struct buf;
150 AT_Q_ENUM_JOBS q_e;
151 BOOL p = False;
153 struct cli_connection *con = NULL;
155 if (!cli_connection_init(srv_name, PIPE_ATSVC, &con))
157 return False;
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))
174 AT_R_ENUM_JOBS r_e;
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)));
184 p = False;
187 if (p)
189 int i;
191 *num_jobs = 0;
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++)
197 fstring cmd;
198 unistr2_to_ascii(cmd, &r_e.command[i],
199 sizeof(cmd));
200 add_chars_to_array(num_jobs, commands, cmd);
202 if ((*num_jobs) != r_e.num_entries)
204 p = False;
209 prs_free_data(&rbuf);
210 prs_free_data(&buf );
212 cli_connection_unlink(con);
214 return p;
217 /****************************************************************************
218 query job information
219 ****************************************************************************/
220 BOOL at_query_job(char *srv_name,
221 uint32 jobid, AT_JOB_INFO *job, fstring command)
223 prs_struct rbuf;
224 prs_struct buf;
225 AT_Q_QUERY_JOB q_q;
226 BOOL p = False;
228 struct cli_connection *con = NULL;
230 if (!cli_connection_init(srv_name, PIPE_ATSVC, &con))
232 return False;
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))
249 AT_R_QUERY_JOB r_q;
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)));
259 p = False;
262 if (p)
264 memcpy(job, &r_q.info, sizeof(AT_JOB_INFO));
265 unistr2_to_ascii(command, &r_q.command,
266 sizeof(fstring)-1);
270 prs_free_data(&rbuf);
271 prs_free_data(&buf );
273 cli_connection_unlink(con);
275 return p;