r12608: Remove some unused #include lines.
[kamenim/samba.git] / source4 / libcli / dgram / browse.c
1 /* 
2    Unix SMB/CIFS implementation.
3
4    handling for browsing dgram requests
5
6    Copyright (C) Jelmer Vernooij 2005
7         Heavily based on ntlogon.c
8    
9    This program is free software; you can redistribute it and/or modify
10    it under the terms of the GNU General Public License as published by
11    the Free Software Foundation; either version 2 of the License, or
12    (at your option) any later version.
13    
14    This program is distributed in the hope that it will be useful,
15    but WITHOUT ANY WARRANTY; without even the implied warranty of
16    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17    GNU General Public License for more details.
18    
19    You should have received a copy of the GNU General Public License
20    along with this program; if not, write to the Free Software
21    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 */
23
24 #include "includes.h"
25 #include "libcli/dgram/libdgram.h"
26
27 NTSTATUS dgram_mailslot_browse_send(struct nbt_dgram_socket *dgmsock,
28      struct nbt_name *dest_name, const struct nbt_peer_socket *dest,
29      struct nbt_name *src_name, struct nbt_browse_packet *request)
30 {
31         NTSTATUS status;
32         DATA_BLOB blob;
33         TALLOC_CTX *tmp_ctx = talloc_new(dgmsock);
34
35         status = ndr_push_struct_blob(&blob, tmp_ctx, request, 
36                                       (ndr_push_flags_fn_t)ndr_push_nbt_browse_packet);
37         if (!NT_STATUS_IS_OK(status)) {
38                 talloc_free(tmp_ctx);
39                 return status;
40         }
41
42         status = dgram_mailslot_send(dgmsock, DGRAM_DIRECT_UNIQUE, 
43                                      NBT_MAILSLOT_BROWSE,
44                                      dest_name, dest, 
45                                      src_name, &blob);
46         talloc_free(tmp_ctx);
47         return status;
48 }
49
50 NTSTATUS dgram_mailslot_browse_reply(struct nbt_dgram_socket *dgmsock,
51       struct nbt_dgram_packet *request, const char *mailslot_name,
52       struct nbt_browse_packet *reply)
53 {
54         NTSTATUS status;
55         DATA_BLOB blob;
56         TALLOC_CTX *tmp_ctx = talloc_new(dgmsock);
57         struct nbt_name myname;
58         struct nbt_peer_socket dest;
59
60         status = ndr_push_struct_blob(&blob, tmp_ctx, reply, 
61                                       (ndr_push_flags_fn_t)ndr_push_nbt_browse_packet);
62         if (!NT_STATUS_IS_OK(status)) {
63                 talloc_free(tmp_ctx);
64                 return status;
65         }
66
67         make_nbt_name_client(&myname, lp_netbios_name());
68
69         dest.port = request->src_port;
70         dest.addr = request->src_addr;
71         status = dgram_mailslot_send(dgmsock, DGRAM_DIRECT_UNIQUE, 
72                                      mailslot_name,
73                                      &request->data.msg.source_name,
74                                      &dest,
75                                      &myname, &blob);
76         talloc_free(tmp_ctx);
77         return status;
78 }
79
80 NTSTATUS dgram_mailslot_browse_parse(struct dgram_mailslot_handler *dgmslot,
81      TALLOC_CTX *mem_ctx, struct nbt_dgram_packet *dgram,
82          struct nbt_browse_packet *pkt)
83 {
84         DATA_BLOB data = dgram_mailslot_data(dgram);
85         NTSTATUS status;
86
87         status = ndr_pull_struct_blob(&data, mem_ctx, pkt, 
88                                       (ndr_pull_flags_fn_t)ndr_pull_nbt_browse_packet);
89         if (!NT_STATUS_IS_OK(status)) {
90                 DEBUG(0,("Failed to parse browse packet of length %d\n", 
91                          (int)data.length));
92                 if (DEBUGLVL(10)) {
93                         file_save("browse.dat", data.data, data.length);
94                 }
95         }
96         return status;
97 }