r8094: Fix compiler warnings.
[gd/samba-autobuild/.git] / source4 / torture / libnet / libnet_lookup.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 #include "librpc/gen_ndr/ndr_nbt.h"
28
29
30 BOOL torture_lookup(void)
31 {
32         BOOL ret;
33         NTSTATUS status;
34         TALLOC_CTX *mem_ctx;
35         struct libnet_context *ctx;
36         struct libnet_Lookup lookup;
37         const char *address;
38
39         mem_ctx = talloc_init("test_lookup");
40
41         ctx = libnet_context_init(NULL);
42         ctx->cred = cmdline_credentials;
43
44         address = talloc_array(ctx, const char, 16);
45
46         lookup.in.hostname = lp_netbios_name();
47         lookup.in.methods  = lp_name_resolve_order();
48         lookup.in.type     = NBT_NAME_CLIENT;
49         lookup.out.address = &address;
50
51         status = libnet_Lookup(ctx, mem_ctx, &lookup);
52
53         if (!NT_STATUS_IS_OK(status)) {
54                 printf("Couldn't lookup name %s: %s\n", lookup.in.hostname, nt_errstr(status));
55                 ret = False;
56                 goto done;
57         }
58
59         ret = True;
60
61 done:
62         talloc_free(mem_ctx);
63         return ret;
64 }
65
66
67 BOOL torture_lookup_host(void)
68 {
69         BOOL ret;
70         NTSTATUS status;
71         TALLOC_CTX *mem_ctx;
72         struct libnet_context *ctx;
73         struct libnet_Lookup lookup;
74         const char *address;
75
76         mem_ctx = talloc_init("test_lookup_host");
77
78         ctx = libnet_context_init(NULL);
79         ctx->cred = cmdline_credentials;
80
81         address = talloc_array(mem_ctx, const char, 16);
82
83         lookup.in.hostname = lp_netbios_name();
84         lookup.in.methods  = lp_name_resolve_order();
85         lookup.out.address = &address;
86
87         status = libnet_LookupHost(ctx, mem_ctx, &lookup);
88
89         if (!NT_STATUS_IS_OK(status)) {
90                 printf("Couldn't lookup host %s: %s\n", lookup.in.hostname, nt_errstr(status));
91                 ret = False;
92                 goto done;
93         }
94
95         ret = True;
96
97 done:
98         talloc_free(mem_ctx);
99         return ret;
100 }
101
102
103 BOOL torture_lookup_pdc(void)
104 {
105         BOOL ret;
106         NTSTATUS status;
107         TALLOC_CTX *mem_ctx;
108         struct libnet_context *ctx;
109         struct libnet_Lookup lookup;
110         const char *address;
111
112         mem_ctx = talloc_init("test_lookup_pdc");
113
114         ctx = libnet_context_init(NULL);
115         ctx->cred = cmdline_credentials;
116
117         address = talloc_array(mem_ctx, const char, 16);
118
119         lookup.in.hostname = lp_workgroup();
120         lookup.in.methods  = lp_name_resolve_order();
121         lookup.out.address = &address;
122
123         status = libnet_LookupPdc(ctx, mem_ctx, &lookup);
124
125         if (!NT_STATUS_IS_OK(status)) {
126                 printf("Couldn't lookup pdc %s: %s\n", lookup.in.hostname, nt_errstr(status));
127                 ret = False;
128                 goto done;
129         }
130
131         ret = True;
132
133 done:
134         talloc_free(mem_ctx);
135         return ret;
136 }