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