r14464: Don't include ndr_BASENAME.h files unless strictly required, instead
[vlendec/samba-autobuild/.git] / source4 / torture / libnet / libnet_rpc.c
1 /* 
2    Unix SMB/CIFS implementation.
3    Test suite for libnet calls.
4
5    Copyright (C) Rafal Szczesniak 2005
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 "lib/cmdline/popt_common.h"
24 #include "libnet/libnet.h"
25 #include "librpc/gen_ndr/ndr_lsa.h"
26 #include "librpc/gen_ndr/ndr_samr.h"
27
28
29 static BOOL test_lsa_connect(struct libnet_context *ctx)
30 {
31         NTSTATUS status;
32         struct libnet_RpcConnect connect;
33         connect.level            = LIBNET_RPC_CONNECT_BINDING;
34         connect.in.binding       = lp_parm_string(-1, "torture", "binding");
35         connect.in.dcerpc_iface  = &dcerpc_table_lsarpc;
36
37         status = libnet_RpcConnect(ctx, ctx, &connect);
38
39         if (!NT_STATUS_IS_OK(status)) {
40                 printf("Couldn't connect to rpc service %s on %s: %s\n",
41                        connect.in.dcerpc_iface->name, connect.in.binding,
42                        nt_errstr(status));
43
44                 return False;
45         }
46
47         return True;
48 }
49
50
51 static BOOL test_samr_connect(struct libnet_context *ctx)
52 {
53         NTSTATUS status;
54         struct libnet_RpcConnect connect;
55         connect.level            = LIBNET_RPC_CONNECT_BINDING;
56         connect.in.binding       = lp_parm_string(-1, "torture", "binding");
57         connect.in.dcerpc_iface  = &dcerpc_table_samr;
58
59         status = libnet_RpcConnect(ctx, ctx, &connect);
60
61         if (!NT_STATUS_IS_OK(status)) {
62                 printf("Couldn't connect to rpc service %s on %s: %s\n",
63                        connect.in.dcerpc_iface->name, connect.in.binding,
64                        nt_errstr(status));
65
66                 return False;
67         }
68
69         return True;
70 }
71
72 BOOL torture_rpc_connect(void)
73 {
74         struct libnet_context *ctx;
75         
76         ctx = libnet_context_init(NULL);
77         ctx->cred = cmdline_credentials;
78
79         printf("Testing connection to lsarpc interface\n");
80         if (!test_lsa_connect(ctx)) {
81                 printf("failed to connect lsarpc interface\n");
82                 return False;
83         }
84
85         printf("Testing connection to SAMR service\n");
86         if (!test_samr_connect(ctx)) {
87                 printf("failed to connect samr interface\n");
88                 return False;
89         }
90
91         return True;
92 }