r2699: Correct handle ServerAlive() and ServerAlive2() + add torture tests
[samba.git] / source4 / torture / rpc / oxidresolve.c
1 /* 
2    Unix SMB/CIFS implementation.
3    test suite for oxidresolve operations
4
5    Copyright (C) Jelmer Vernooij 2004
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 int test_SimplePing(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
25 {
26         struct SimplePing r;
27         NTSTATUS status;
28         HYPER_T h = 10;
29
30         r.in.SetId = &h;
31
32         status = dcerpc_SimplePing(p, mem_ctx, &r);
33         if(NT_STATUS_IS_ERR(status)) {
34                 fprintf(stderr, "SimplePing: %s\n", nt_errstr(status));
35                 return 0;
36         }
37
38         if(!W_ERROR_IS_OK(r.out.result)) {
39                 fprintf(stderr, "SimplePing: %s\n", win_errstr(r.out.result));
40                 return 0;
41         }
42
43         return 1;
44 }
45
46 static int test_ServerAlive(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
47 {
48         struct ServerAlive r;
49         NTSTATUS status;
50
51         status = dcerpc_ServerAlive(p, mem_ctx, &r);
52         if(NT_STATUS_IS_ERR(status)) {
53                 fprintf(stderr, "ServerAlive: %s\n", nt_errstr(status));
54                 return 0;
55         }
56
57         if(!W_ERROR_IS_OK(r.out.result)) {
58                 fprintf(stderr, "ServerAlive: %s\n", win_errstr(r.out.result));
59                 return 0;
60         }
61
62         return 1;
63 }
64
65
66 static int test_ServerAlive2(struct dcerpc_pipe *p, TALLOC_CTX *mem_ctx)
67 {
68         struct ServerAlive2 r;
69         NTSTATUS status;
70
71         status = dcerpc_ServerAlive2(p, mem_ctx, &r);
72         if(NT_STATUS_IS_ERR(status)) {
73                 fprintf(stderr, "ServerAlive2: %s\n", nt_errstr(status));
74                 return 0;
75         }
76
77         if(!W_ERROR_IS_OK(r.out.result)) {
78                 fprintf(stderr, "ServerAlive2: %s\n", win_errstr(r.out.result));
79                 return 0;
80         }
81
82         return 1;
83 }
84
85 BOOL torture_rpc_oxidresolve(int dummy)
86 {
87         NTSTATUS status;
88        struct dcerpc_pipe *p;
89         TALLOC_CTX *mem_ctx;
90         BOOL ret = True;
91
92         mem_ctx = talloc_init("torture_rpc_oxidresolve");
93
94         status = torture_rpc_connection(&p, 
95                                         DCERPC_IOXIDRESOLVER_NAME, 
96                                         DCERPC_IOXIDRESOLVER_UUID, 
97                                         DCERPC_IOXIDRESOLVER_VERSION);
98
99         if (!NT_STATUS_IS_OK(status)) {
100                 return False;
101         }
102
103         if(!test_SimplePing(p, mem_ctx))
104                 ret = False;
105
106         if(!test_ServerAlive(p, mem_ctx))
107                 ret = False;
108
109         if(!test_ServerAlive2(p, mem_ctx))
110                 ret = False;
111
112         talloc_destroy(mem_ctx);
113
114         torture_rpc_close(p);
115
116         return ret;
117 }