r14402: Generate seperate headers for RPC client functions.
[samba.git] / source4 / torture / rpc / atsvc.c
1 /* 
2    Unix SMB/CIFS implementation.
3    test suite for atsvc rpc operations
4
5    Copyright (C) Tim Potter 2003
6    
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (at your option) any later version.
11    
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16    
17    You should have received a copy of the GNU General Public License
18    along with this program; if not, write to the Free Software
19    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22 #include "includes.h"
23 #include "torture/torture.h"
24 #include "librpc/gen_ndr/ndr_atsvc.h"
25 #include "librpc/gen_ndr/ndr_atsvc_c.h"
26 #include "torture/rpc/rpc.h"
27
28 static BOOL test_JobGetInfo(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, uint32_t job_id)
29 {
30         NTSTATUS status;
31         struct atsvc_JobGetInfo r;
32
33         r.in.servername = dcerpc_server_name(p);
34         r.in.job_id = job_id;
35
36         status = dcerpc_atsvc_JobGetInfo(p, mem_ctx, &r);
37
38         if (!NT_STATUS_IS_OK(status)) {
39                 printf("JobGetInfo failed - %s\n", nt_errstr(status));
40                 return False;
41         }
42
43         return True;
44 }
45
46 static BOOL test_JobDel(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, uint32_t min_job_id,
47                         uint32_t max_job_id)
48 {
49         NTSTATUS status;
50         struct atsvc_JobDel r;
51
52         r.in.servername = dcerpc_server_name(p);
53         r.in.min_job_id = min_job_id;
54         r.in.max_job_id = max_job_id;
55
56         status = dcerpc_atsvc_JobDel(p, mem_ctx, &r);
57
58         if (!NT_STATUS_IS_OK(status)) {
59                 printf("JobDel failed - %s\n", nt_errstr(status));
60                 return False;
61         }
62
63         return True;
64 }
65
66 static BOOL test_JobEnum(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
67 {
68         NTSTATUS status;
69         struct atsvc_JobEnum r;
70         struct atsvc_enum_ctr ctr;
71         uint32_t resume_handle = 0, i;
72         BOOL ret = True;
73
74         printf("\ntesting JobEnum\n");
75
76         r.in.servername = dcerpc_server_name(p);
77         ctr.entries_read = 0;
78         ctr.first_entry = NULL;
79         r.in.ctr = r.out.ctr = &ctr;
80         r.in.preferred_max_len = 0xffffffff;
81         r.in.resume_handle = r.out.resume_handle = &resume_handle;
82
83         status = dcerpc_atsvc_JobEnum(p, mem_ctx, &r);
84
85         if (!NT_STATUS_IS_OK(status)) {
86                 printf("JobEnum failed - %s\n", nt_errstr(status));
87                 return False;
88         }
89
90         for (i = 0; r.out.ctr && i < r.out.ctr->entries_read; i++) {
91                 if (!test_JobGetInfo(p, mem_ctx, r.out.ctr->first_entry[i].job_id)) {
92                         ret = False;
93                 }
94         }
95
96         return ret;
97 }
98
99 static BOOL test_JobAdd(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
100 {
101         NTSTATUS status;
102         struct atsvc_JobAdd r;
103         struct atsvc_JobInfo info;
104
105         printf("\ntesting JobAdd\n");
106
107         r.in.servername = dcerpc_server_name(p);
108         info.job_time = 0x050ae4c0; /* 11:30pm */
109         info.days_of_month = 0;     /* n/a */
110         info.days_of_week = 0x02;   /* Tuesday */
111         info.flags = 0x11;          /* periodic, non-interactive */
112         info.command = "foo.exe";
113         r.in.job_info = &info;
114
115         status = dcerpc_atsvc_JobAdd(p, mem_ctx, &r);
116
117         if (!NT_STATUS_IS_OK(status)) {
118                 printf("JobAdd failed - %s\n", nt_errstr(status));
119                 return False;
120         }
121
122         /* Run EnumJobs again in case there were no jobs to begin with */
123
124         if (!test_JobEnum(p, mem_ctx)) {
125                 return False;
126         }
127
128         if (!test_JobGetInfo(p, mem_ctx, r.out.job_id)) {
129                 return False;
130         }
131
132         if (!test_JobDel(p, mem_ctx, r.out.job_id, r.out.job_id)) {
133                 return False;
134         }
135
136         return True;
137 }
138
139 BOOL torture_rpc_atsvc(void)
140 {
141         NTSTATUS status;
142         struct dcerpc_pipe *p;
143         TALLOC_CTX *mem_ctx;
144         BOOL ret = True;
145
146         mem_ctx = talloc_init("torture_rpc_atsvc");
147
148         status = torture_rpc_connection(mem_ctx, &p, &dcerpc_table_atsvc);
149         if (!NT_STATUS_IS_OK(status)) {
150                 talloc_free(mem_ctx);
151                 return False;
152         }
153
154         if (!test_JobEnum(p, mem_ctx)) {
155                 talloc_free(mem_ctx);
156                 return False;
157         }
158
159         if (!test_JobAdd(p, mem_ctx)) {
160                 talloc_free(mem_ctx);
161                 return False;
162         }
163
164         talloc_free(mem_ctx);
165
166         return ret;
167 }