r23792: convert Samba4 to GPLv3
[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 3 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, see <http://www.gnu.org/licenses/>.
19 */
20
21 #include "includes.h"
22 #include "torture/torture.h"
23 #include "librpc/gen_ndr/ndr_atsvc_c.h"
24 #include "torture/rpc/rpc.h"
25
26 static bool test_JobGetInfo(struct dcerpc_pipe *p, struct torture_context *tctx, uint32_t job_id)
27 {
28         NTSTATUS status;
29         struct atsvc_JobGetInfo r;
30
31         r.in.servername = dcerpc_server_name(p);
32         r.in.job_id = job_id;
33
34         status = dcerpc_atsvc_JobGetInfo(p, tctx, &r);
35
36         torture_assert_ntstatus_ok(tctx, status, "JobGetInfo failed");
37
38         return true;
39 }
40
41 static bool test_JobDel(struct dcerpc_pipe *p, struct torture_context *tctx, uint32_t min_job_id,
42                         uint32_t max_job_id)
43 {
44         NTSTATUS status;
45         struct atsvc_JobDel r;
46
47         r.in.servername = dcerpc_server_name(p);
48         r.in.min_job_id = min_job_id;
49         r.in.max_job_id = max_job_id;
50
51         status = dcerpc_atsvc_JobDel(p, tctx, &r);
52
53         torture_assert_ntstatus_ok(tctx, status, "JobDel failed");
54
55         return true;
56 }
57
58 static bool test_JobEnum(struct torture_context *tctx, struct dcerpc_pipe *p)
59 {
60         NTSTATUS status;
61         struct atsvc_JobEnum r;
62         struct atsvc_enum_ctr ctr;
63         uint32_t resume_handle = 0, i;
64         bool ret = true;
65
66         r.in.servername = dcerpc_server_name(p);
67         ctr.entries_read = 0;
68         ctr.first_entry = NULL;
69         r.in.ctr = r.out.ctr = &ctr;
70         r.in.preferred_max_len = 0xffffffff;
71         r.in.resume_handle = r.out.resume_handle = &resume_handle;
72
73         status = dcerpc_atsvc_JobEnum(p, tctx, &r);
74
75         torture_assert_ntstatus_ok(tctx, status, "JobEnum failed");
76
77         for (i = 0; i < r.out.ctr->entries_read; i++) {
78                 if (!test_JobGetInfo(p, tctx, r.out.ctr->first_entry[i].job_id)) {
79                         ret = False;
80                 }
81         }
82
83         return ret;
84 }
85
86 static bool test_JobAdd(struct torture_context *tctx, struct dcerpc_pipe *p)
87 {
88         NTSTATUS status;
89         struct atsvc_JobAdd r;
90         struct atsvc_JobInfo info;
91
92         r.in.servername = dcerpc_server_name(p);
93         info.job_time = 0x050ae4c0; /* 11:30pm */
94         info.days_of_month = 0;     /* n/a */
95         info.days_of_week = 0x02;   /* Tuesday */
96         info.flags = 0x11;          /* periodic, non-interactive */
97         info.command = "foo.exe";
98         r.in.job_info = &info;
99
100         status = dcerpc_atsvc_JobAdd(p, tctx, &r);
101
102         torture_assert_ntstatus_ok(tctx, status, "JobAdd failed");
103
104         /* Run EnumJobs again in case there were no jobs to begin with */
105
106         if (!test_JobEnum(tctx, p)) {
107                 return false;
108         }
109
110         if (!test_JobGetInfo(p, tctx, *r.out.job_id)) {
111                 return false;
112         }
113
114         if (!test_JobDel(p, tctx, *r.out.job_id, *r.out.job_id)) {
115                 return false;
116         }
117
118         return true;
119 }
120
121 struct torture_suite *torture_rpc_atsvc(void)
122 {
123         struct torture_suite *suite = torture_suite_create(
124                                                                                 talloc_autofree_context(),
125                                                                                 "ATSVC");
126         struct torture_tcase *tcase;
127         
128         tcase = torture_suite_add_rpc_iface_tcase(suite, "atsvc", 
129                                                                                           &dcerpc_table_atsvc);
130
131         torture_rpc_tcase_add_test(tcase, "JobEnum", test_JobEnum);
132         torture_rpc_tcase_add_test(tcase, "JobAdd", test_JobAdd);
133
134         return suite;
135 }