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