r14470: Remove some unnecessary headers.
[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_c.h"
25 #include "torture/rpc/rpc.h"
26
27 static BOOL test_JobGetInfo(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, uint32_t job_id)
28 {
29         NTSTATUS status;
30         struct atsvc_JobGetInfo r;
31
32         r.in.servername = dcerpc_server_name(p);
33         r.in.job_id = job_id;
34
35         status = dcerpc_atsvc_JobGetInfo(p, mem_ctx, &r);
36
37         if (!NT_STATUS_IS_OK(status)) {
38                 printf("JobGetInfo failed - %s\n", nt_errstr(status));
39                 return False;
40         }
41
42         return True;
43 }
44
45 static BOOL test_JobDel(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx, uint32_t min_job_id,
46                         uint32_t max_job_id)
47 {
48         NTSTATUS status;
49         struct atsvc_JobDel r;
50
51         r.in.servername = dcerpc_server_name(p);
52         r.in.min_job_id = min_job_id;
53         r.in.max_job_id = max_job_id;
54
55         status = dcerpc_atsvc_JobDel(p, mem_ctx, &r);
56
57         if (!NT_STATUS_IS_OK(status)) {
58                 printf("JobDel failed - %s\n", nt_errstr(status));
59                 return False;
60         }
61
62         return True;
63 }
64
65 static BOOL test_JobEnum(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
66 {
67         NTSTATUS status;
68         struct atsvc_JobEnum r;
69         struct atsvc_enum_ctr ctr;
70         uint32_t resume_handle = 0, i;
71         BOOL ret = True;
72
73         printf("\ntesting JobEnum\n");
74
75         r.in.servername = dcerpc_server_name(p);
76         ctr.entries_read = 0;
77         ctr.first_entry = NULL;
78         r.in.ctr = r.out.ctr = &ctr;
79         r.in.preferred_max_len = 0xffffffff;
80         r.in.resume_handle = r.out.resume_handle = &resume_handle;
81
82         status = dcerpc_atsvc_JobEnum(p, mem_ctx, &r);
83
84         if (!NT_STATUS_IS_OK(status)) {
85                 printf("JobEnum failed - %s\n", nt_errstr(status));
86                 return False;
87         }
88
89         for (i = 0; r.out.ctr && i < r.out.ctr->entries_read; i++) {
90                 if (!test_JobGetInfo(p, mem_ctx, r.out.ctr->first_entry[i].job_id)) {
91                         ret = False;
92                 }
93         }
94
95         return ret;
96 }
97
98 static BOOL test_JobAdd(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
99 {
100         NTSTATUS status;
101         struct atsvc_JobAdd r;
102         struct atsvc_JobInfo info;
103
104         printf("\ntesting JobAdd\n");
105
106         r.in.servername = dcerpc_server_name(p);
107         info.job_time = 0x050ae4c0; /* 11:30pm */
108         info.days_of_month = 0;     /* n/a */
109         info.days_of_week = 0x02;   /* Tuesday */
110         info.flags = 0x11;          /* periodic, non-interactive */
111         info.command = "foo.exe";
112         r.in.job_info = &info;
113
114         status = dcerpc_atsvc_JobAdd(p, mem_ctx, &r);
115
116         if (!NT_STATUS_IS_OK(status)) {
117                 printf("JobAdd failed - %s\n", nt_errstr(status));
118                 return False;
119         }
120
121         /* Run EnumJobs again in case there were no jobs to begin with */
122
123         if (!test_JobEnum(p, mem_ctx)) {
124                 return False;
125         }
126
127         if (!test_JobGetInfo(p, mem_ctx, r.out.job_id)) {
128                 return False;
129         }
130
131         if (!test_JobDel(p, mem_ctx, r.out.job_id, r.out.job_id)) {
132                 return False;
133         }
134
135         return True;
136 }
137
138 BOOL torture_rpc_atsvc(void)
139 {
140         NTSTATUS status;
141         struct dcerpc_pipe *p;
142         TALLOC_CTX *mem_ctx;
143         BOOL ret = True;
144
145         mem_ctx = talloc_init("torture_rpc_atsvc");
146
147         status = torture_rpc_connection(mem_ctx, &p, &dcerpc_table_atsvc);
148         if (!NT_STATUS_IS_OK(status)) {
149                 talloc_free(mem_ctx);
150                 return False;
151         }
152
153         if (!test_JobEnum(p, mem_ctx)) {
154                 talloc_free(mem_ctx);
155                 return False;
156         }
157
158         if (!test_JobAdd(p, mem_ctx)) {
159                 talloc_free(mem_ctx);
160                 return False;
161         }
162
163         talloc_free(mem_ctx);
164
165         return ret;
166 }