r15436: Add test for LIBNET_RPC_CONNECT_DC_INFO level. Display received
[bbaumbach/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 "libcli/security/security.h"
26 #include "librpc/ndr/libndr.h"
27 #include "librpc/gen_ndr/ndr_lsa.h"
28 #include "librpc/gen_ndr/ndr_samr.h"
29 #include "librpc/rpc/dcerpc.h"
30 #include "torture/torture.h"
31
32
33 static BOOL test_lsa_connect(struct libnet_context *ctx)
34 {
35         NTSTATUS status;
36         struct libnet_RpcConnect connect;
37         connect.level            = LIBNET_RPC_CONNECT_BINDING;
38         connect.in.binding       = lp_parm_string(-1, "torture", "binding");
39         connect.in.dcerpc_iface  = &dcerpc_table_lsarpc;
40
41         status = libnet_RpcConnect(ctx, ctx, &connect);
42
43         if (!NT_STATUS_IS_OK(status)) {
44                 printf("Couldn't connect to rpc service %s on %s: %s\n",
45                        connect.in.dcerpc_iface->name, connect.in.binding,
46                        nt_errstr(status));
47
48                 return False;
49         }
50
51         return True;
52 }
53
54
55 static BOOL test_lsa_dcinfo_connect(struct libnet_context *ctx)
56 {
57         NTSTATUS status;
58         struct libnet_RpcConnect connect;
59         connect.level           = LIBNET_RPC_CONNECT_DC_INFO;
60         connect.in.binding      = lp_parm_string(-1, "torture", "binding");
61         connect.in.dcerpc_iface = &dcerpc_table_lsarpc;
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.binding,
68                        nt_errstr(status));
69
70                 return False;
71         }
72
73         printf("Domain Controller Info:\n");
74         printf("\tDomain Name:\t %s\n", connect.out.domain_name);
75         printf("\tDomain SID:\t %s\n", dom_sid_string(ctx, connect.out.domain_sid));
76         printf("\tRealm:\t\t %s\n", connect.out.realm);
77         printf("\tGUID:\t\t %s\n", GUID_string(ctx, connect.out.guid));
78
79         return True;
80 }
81
82
83 static BOOL test_samr_connect(struct libnet_context *ctx)
84 {
85         NTSTATUS status;
86         struct libnet_RpcConnect connect;
87         connect.level            = LIBNET_RPC_CONNECT_BINDING;
88         connect.in.binding       = lp_parm_string(-1, "torture", "binding");
89         connect.in.dcerpc_iface  = &dcerpc_table_samr;
90
91         status = libnet_RpcConnect(ctx, ctx, &connect);
92
93         if (!NT_STATUS_IS_OK(status)) {
94                 printf("Couldn't connect to rpc service %s on %s: %s\n",
95                        connect.in.dcerpc_iface->name, connect.in.binding,
96                        nt_errstr(status));
97
98                 return False;
99         }
100
101         return True;
102 }
103
104 BOOL torture_rpc_connect(struct torture_context *torture)
105 {
106         struct libnet_context *ctx;
107         
108         ctx = libnet_context_init(NULL);
109         ctx->cred = cmdline_credentials;
110
111         printf("Testing connection to lsarpc interface\n");
112         if (!test_lsa_connect(ctx)) {
113                 printf("failed to connect lsarpc interface\n");
114                 return False;
115         }
116
117         printf("Testing connection with domain info to lsarpc interface\n");
118         if (!test_lsa_dcinfo_connect(ctx)) {
119                 printf("failed to connect lsarpc interface\n");
120                 return False;
121         }
122
123         printf("Testing connection to SAMR service\n");
124         if (!test_samr_connect(ctx)) {
125                 printf("failed to connect samr interface\n");
126                 return False;
127         }
128
129         return True;
130 }