summaryrefslogtreecommitdiff
path: root/source3/rpc_client/cli_atsvc.c
blob: bebc4d0bc76fe498faf02c371fe4f047ddaedd41 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
/* 
 *  Unix SMB/Netbios implementation.
 *  Version 2.1.
 *  RPC client routines: scheduler service
 *  Copyright (C) Matthew Chapman                   1999,
 *  Copyright (C) Luke Kenneth Casson Leighton 1996-1999,
 *  Copyright (C) Andrew Tridgell              1992-1999.
 *  
 *  This program is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation; either version 2 of the License, or
 *  (at your option) any later version.
 *  
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *  
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

#include "includes.h"

extern int DEBUGLEVEL;

/****************************************************************************
add a job to the scheduler
****************************************************************************/
BOOL at_add_job(struct cli_state *cli, uint16 fnum, 
		char *server_name, AT_JOB_INFO *info, char *command,
		uint32 *jobid)
{
	prs_struct rbuf;
	prs_struct buf; 
	AT_Q_ADD_JOB q_a;
	BOOL p = False;

	prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
	prs_init(&rbuf, 0   , 4, SAFETY_MARGIN, True );

	/* create and send a MSRPC command with api AT_ADD_JOB */

	DEBUG(4,("Scheduler Add Job\n"));

	/* store the parameters */
	make_at_q_add_job(&q_a, server_name, info, command);

	/* turn parameters into data stream */
	at_io_q_add_job("", &q_a, &buf, 0);

	/* send the data on \PIPE\ */
	if (rpc_api_pipe_req(cli, fnum, AT_ADD_JOB, &buf, &rbuf))
	{
		AT_R_ADD_JOB r_a;

		at_io_r_add_job("", &r_a, &rbuf, 0);
		p = rbuf.offset != 0;

		if (p && r_a.status != 0)
		{
			/* report error code */
			DEBUG(0,("AT_R_ADD_JOB: %s\n", get_nt_error_msg(r_a.status)));
			p = False;
		}

		if (p)
		{
			*jobid = r_a.jobid;
		}
	}

	prs_mem_free(&rbuf);
	prs_mem_free(&buf );

	return p;
}

/****************************************************************************
dequeue a job
****************************************************************************/
BOOL at_del_job(struct cli_state *cli, uint16 fnum, 
		char *server_name, uint32 min_jobid, uint32 max_jobid)
{
	prs_struct rbuf;
	prs_struct buf; 
	AT_Q_DEL_JOB q_d;
	BOOL p = False;

	prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
	prs_init(&rbuf, 0   , 4, SAFETY_MARGIN, True );

	/* create and send a MSRPC command with api AT_DEL_JOB */

	DEBUG(4,("Scheduler Delete Job\n"));

	/* store the parameters */
	make_at_q_del_job(&q_d, server_name, min_jobid, max_jobid);

	/* turn parameters into data stream */
	at_io_q_del_job("", &q_d, &buf, 0);

	/* send the data on \PIPE\ */
	if (rpc_api_pipe_req(cli, fnum, AT_DEL_JOB, &buf, &rbuf))
	{
		AT_R_DEL_JOB r_d;

		at_io_r_del_job("", &r_d, &rbuf, 0);
		p = rbuf.offset != 0;

		if (p && r_d.status != 0)
		{
			/* report error code */
			DEBUG(0,("AT_R_DEL_JOB: %s\n", get_nt_error_msg(r_d.status)));
			p = False;
		}
	}

	prs_mem_free(&rbuf);
	prs_mem_free(&buf );

	return p;
}

/****************************************************************************
enumerate scheduled jobs
****************************************************************************/
BOOL at_enum_jobs(struct cli_state *cli, uint16 fnum, 
		  char *server_name, uint32 *num_jobs,
		  AT_ENUM_INFO *jobs, fstring *commands)
{
	prs_struct rbuf;
	prs_struct buf; 
	AT_Q_ENUM_JOBS q_e;
	BOOL p = False;

	prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
	prs_init(&rbuf, 0   , 4, SAFETY_MARGIN, True );

	/* create and send a MSRPC command with api AT_DEL_JOB */

	DEBUG(4,("Scheduler Enumerate Jobs\n"));

	/* store the parameters */
	make_at_q_enum_jobs(&q_e, server_name);

	/* turn parameters into data stream */
	at_io_q_enum_jobs("", &q_e, &buf, 0);

	/* send the data on \PIPE\ */
	if (rpc_api_pipe_req(cli, fnum, AT_ENUM_JOBS, &buf, &rbuf))
	{
		AT_R_ENUM_JOBS r_e;

		at_io_r_enum_jobs("", &r_e, &rbuf, 0);
		p = rbuf.offset != 0;

		if (p && r_e.status != 0)
		{
			/* report error code */
			DEBUG(0,("AT_R_ENUM_JOBS: %s\n", get_nt_error_msg(r_e.status)));
			p = False;
		}

		if (p)
		{
			int i;

			*num_jobs = r_e.num_entries;
			memcpy(jobs, &r_e.info, r_e.num_entries * sizeof(AT_ENUM_INFO));

			for (i = 0; i < r_e.num_entries; i++)
			{
				unistr2_to_ascii(commands[i], &r_e.command[i],
						 sizeof(commands[i]));
			}
		}
	}

	prs_mem_free(&rbuf);
	prs_mem_free(&buf );

	return p;
}

/****************************************************************************
query job information
****************************************************************************/
BOOL at_query_job(struct cli_state *cli, uint16 fnum, char *server_name,
		  uint32 jobid, AT_JOB_INFO *job, fstring command)
{
	prs_struct rbuf;
	prs_struct buf; 
	AT_Q_QUERY_JOB q_q;
	BOOL p = False;

	prs_init(&buf , 1024, 4, SAFETY_MARGIN, False);
	prs_init(&rbuf, 0   , 4, SAFETY_MARGIN, True );

	/* create and send a MSRPC command with api AT_QUERY_JOB */

	DEBUG(4,("Scheduler Query Job\n"));

	/* store the parameters */
	make_at_q_query_job(&q_q, server_name, jobid);

	/* turn parameters into data stream */
	at_io_q_query_job("", &q_q, &buf, 0);

	/* send the data on \PIPE\ */
	if (rpc_api_pipe_req(cli, fnum, AT_QUERY_JOB, &buf, &rbuf))
	{
		AT_R_QUERY_JOB r_q;

		at_io_r_query_job("", &r_q, &rbuf, 0);
		p = rbuf.offset != 0;

		if (p && r_q.status != 0)
		{
			/* report error code */
			DEBUG(0,("AT_R_QUERY_JOB: %s\n", get_nt_error_msg(r_q.status)));
			p = False;
		}

		if (p)
		{
			memcpy(job, &r_q.info, sizeof(AT_JOB_INFO));
			unistr2_to_ascii(command, &r_q.command,
					 sizeof(fstring)-1);
		}
	}

	prs_mem_free(&rbuf);
	prs_mem_free(&buf );

	return p;
}