2 Unix SMB/CIFS implementation.
6 Copyright (C) Andrew Tridgell 2005
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.
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.
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.
24 #include "nbt_server/nbt_server.h"
25 #include "smbd/service_task.h"
26 #include "lib/socket/socket.h"
29 a list of mailslots that we have static handlers for
32 const char *mailslot_name;
33 dgram_mailslot_handler_t handler;
34 } mailslot_handlers[] = {
35 { NBT_MAILSLOT_NETLOGON, nbtd_mailslot_netlogon_handler },
36 { NBT_MAILSLOT_NTLOGON, nbtd_mailslot_ntlogon_handler },
37 { NBT_MAILSLOT_BROWSE, nbtd_mailslot_browse_handler }
41 receive an incoming dgram request. This is used for general datagram
42 requests. Mailslot requests for our listening mailslots
43 are handled in the specific mailslot handlers
45 void dgram_request_handler(struct nbt_dgram_socket *dgmsock,
46 struct nbt_dgram_packet *packet,
47 const struct nbt_peer_socket *src)
49 DEBUG(0,("General datagram request from %s:%d\n", src->addr, src->port));
50 NDR_PRINT_DEBUG(nbt_dgram_packet, packet);
55 setup the port 138 datagram listener for a given interface
57 NTSTATUS nbtd_dgram_setup(struct nbtd_interface *iface, const char *bind_address)
59 struct nbt_dgram_socket *bcast_dgmsock;
60 struct nbtd_server *nbtsrv = iface->nbtsrv;
62 /* the list of mailslots that we are interested in */
65 /* listen for broadcasts on port 138 */
66 bcast_dgmsock = nbt_dgram_socket_init(iface, nbtsrv->task->event_ctx);
67 NT_STATUS_HAVE_NO_MEMORY(bcast_dgmsock);
69 status = socket_listen(bcast_dgmsock->sock, iface->bcast_address,
70 lp_dgram_port(), 0, 0);
71 if (!NT_STATUS_IS_OK(status)) {
72 DEBUG(0,("Failed to bind to %s:%d - %s\n",
73 iface->bcast_address, lp_dgram_port(), nt_errstr(status)));
77 dgram_set_incoming_handler(bcast_dgmsock, dgram_request_handler, iface);
79 /* listen for unicasts on port 138 */
80 iface->dgmsock = nbt_dgram_socket_init(iface, nbtsrv->task->event_ctx);
81 NT_STATUS_HAVE_NO_MEMORY(iface->dgmsock);
83 status = socket_listen(iface->dgmsock->sock, bind_address,
84 lp_dgram_port(), 0, 0);
85 if (!NT_STATUS_IS_OK(status)) {
86 DEBUG(0,("Failed to bind to %s:%d - %s\n",
87 bind_address, lp_dgram_port(), nt_errstr(status)));
90 dgram_set_incoming_handler(iface->dgmsock, dgram_request_handler, iface);
93 for (i=0;i<ARRAY_SIZE(mailslot_handlers);i++) {
94 /* note that we don't need to keep the pointer
95 to the dgmslot around - the callback is all
97 struct dgram_mailslot_handler *dgmslot;
99 dgmslot = dgram_mailslot_listen(bcast_dgmsock,
100 mailslot_handlers[i].mailslot_name,
101 mailslot_handlers[i].handler, iface);
102 NT_STATUS_HAVE_NO_MEMORY(dgmslot);
104 dgmslot = dgram_mailslot_listen(iface->dgmsock,
105 mailslot_handlers[i].mailslot_name,
106 mailslot_handlers[i].handler, iface);
107 NT_STATUS_HAVE_NO_MEMORY(dgmslot);