r8081: Add simple test for RpcConnect function.
[gd/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 "libnet/composite.h"
26 #include "libcli/composite/monitor.h"
27
28
29 BOOL test_lsa_connect(struct libnet_context *ctx)
30 {
31         NTSTATUS status;
32         struct libnet_RpcConnect connect;
33         connect.level                     = LIBNET_RPC_CONNECT_PDC;
34         connect.in.domain_name            = lp_workgroup();
35         connect.in.dcerpc_iface_name      = DCERPC_LSARPC_NAME;
36         connect.in.dcerpc_iface_uuid      = DCERPC_LSARPC_UUID;
37         connect.in.dcerpc_iface_version   = DCERPC_LSARPC_VERSION;
38
39         status = libnet_RpcConnect(ctx, ctx, &connect);
40
41         if (!NT_STATUS_IS_OK(status)) {
42                 printf("Couldn't connect to rpc service %s on %s: %s\n",
43                        connect.in.dcerpc_iface_name, connect.in.domain_name,
44                        nt_errstr(status));
45
46                 return False;
47         }
48
49         return True;
50 }
51
52
53 BOOL test_samr_connect(struct libnet_context *ctx)
54 {
55         NTSTATUS status;
56         struct libnet_RpcConnect connect;
57         connect.level                     = LIBNET_RPC_CONNECT_PDC;
58         connect.in.domain_name            = lp_workgroup();
59         connect.in.dcerpc_iface_name      = DCERPC_SAMR_NAME;
60         connect.in.dcerpc_iface_uuid      = DCERPC_SAMR_UUID;
61         connect.in.dcerpc_iface_version   = DCERPC_SAMR_VERSION;
62
63         status = libnet_RpcConnect(ctx, ctx, &connect);
64
65         if (!NT_STATUS_IS_OK(status)) {
66                 printf("Couldn't connect to rpc service %s on %s: %s\n",
67                        connect.in.dcerpc_iface_name, connect.in.domain_name,
68                        nt_errstr(status));
69
70                 return False;
71         }
72
73         return True;
74 }
75
76
77 BOOL torture_rpc_connect(void)
78 {
79         struct libnet_context *ctx;
80         
81         ctx = libnet_context_init(NULL);
82         ctx->cred = cmdline_credentials;
83
84         if (!test_lsa_connect(ctx)) {
85                 printf("failed to connect lsarpc interface\n");
86                 return False;
87         }
88
89         if (!test_samr_connect(ctx)) {
90                 printf("failed to connect samr interface\n");
91                 return False;
92         }
93
94         return True;
95 }