4cef705f0212cd24a5d26cc4fbb5cc6448b4dfee
[garming/samba-autobuild/.git] / source4 / nbt_server / dgram / browse.c
1 /* 
2    Unix SMB/CIFS implementation.
3
4    NBT datagram browse server
5
6    Copyright (C) Andrew Tridgell        2005
7    
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 2 of the License, or
11    (at your option) any later version.
12    
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17    
18    You should have received a copy of the GNU General Public License
19    along with this program; if not, write to the Free Software
20    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23 #include "includes.h"
24 #include "nbt_server/nbt_server.h"
25 #include "lib/socket/socket.h"
26
27 static const char *nbt_browse_opcode_string(enum nbt_browse_opcode r)
28 {
29         const char *val = NULL;
30
31         switch (r) {
32                 case HostAnnouncement: val = "HostAnnouncement"; break;
33                 case AnnouncementRequest: val = "AnnouncementRequest"; break;
34                 case Election: val = "Election"; break;
35                 case GetBackupListReq: val = "GetBackupListReq"; break;
36                 case GetBackupListResp: val = "GetBackupListResp"; break;
37                 case BecomeBackup: val = "BecomeBackup"; break;
38                 case DomainAnnouncement: val = "DomainAnnouncement"; break;
39                 case MasterAnnouncement: val = "MasterAnnouncement"; break;
40                 case ResetBrowserState: val = "ResetBrowserState"; break;
41                 case LocalMasterAnnouncement: val = "LocalMasterAnnouncement"; break;
42         }
43
44         return val;
45 }
46
47 /*
48   handle incoming browse mailslot requests
49 */
50 void nbtd_mailslot_browse_handler(struct dgram_mailslot_handler *dgmslot, 
51                                   struct nbt_dgram_packet *packet, 
52                                   struct socket_address *src)
53 {
54         struct nbt_browse_packet *browse = talloc(dgmslot, struct nbt_browse_packet);
55         struct nbt_name *name = &packet->data.msg.dest_name;
56         NTSTATUS status;
57
58         if (browse == NULL) goto failed;
59
60         status = dgram_mailslot_browse_parse(dgmslot, browse, packet, browse);
61         if (!NT_STATUS_IS_OK(status)) goto failed;
62
63         DEBUG(2,("Browse %s (Op %d) on '%s' '%s' from %s:%d\n", 
64                 nbt_browse_opcode_string(browse->opcode), browse->opcode,
65                 nbt_name_string(browse, name), dgmslot->mailslot_name,
66                 src->addr, src->port));
67
68         if (DEBUGLEVEL >= 10) {
69                 NDR_PRINT_DEBUG(nbt_browse_packet, browse);
70         }
71
72         talloc_free(browse);
73         return;
74
75 failed:
76         DEBUG(2,("nbtd browse handler failed from %s:%d to %s - %s\n",
77                  src->addr, src->port, nbt_name_string(browse, name),
78                  nt_errstr(status)));
79         talloc_free(browse);
80
81 }