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