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