r5109: - fixed handling of zero-length subcontexts in the ndr library
[garming/samba-autobuild/.git] / source4 / nbt_server / nbt_server.c
1 /* 
2    Unix SMB/CIFS implementation.
3
4    NBT server task
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 "events.h"
25 #include "libcli/nbt/libnbt.h"
26 #include "smbd/service_task.h"
27 #include "nbt_server/nbt_server.h"
28
29
30 /*
31   receive an incoming request
32 */
33 static void nbt_request_handler(struct nbt_name_socket *nbtsock, 
34                                 struct nbt_name_packet *packet, 
35                                 const char *src_address, int src_port)
36 {
37         struct nbt_interface *iface = talloc_get_type(nbtsock->incoming.private, 
38                                                       struct nbt_interface);
39         DEBUG(0,("nbtd request from %s:%d\n", src_address, src_port));
40
41         NDR_PRINT_DEBUG(nbt_name_packet, packet);
42 }
43
44
45 /*
46   startup the nbtd task
47 */
48 static void nbtd_task_init(struct task_server *task)
49 {
50         struct nbt_server *nbtsrv;
51         struct nbt_interface *iface;
52         NTSTATUS status;
53
54         nbtsrv = talloc(task, struct nbt_server);
55         if (nbtsrv == NULL) {
56                 task_terminate(task, "nbtd: out of memory");
57                 return;
58         }
59
60         nbtsrv->task = task;
61         nbtsrv->interfaces = NULL;
62
63         /* start listening on the configured network interfaces */
64         status = nbt_startup_interfaces(nbtsrv);
65         if (!NT_STATUS_IS_OK(status)) {
66                 task_terminate(task, "nbtd failed to setup interfaces");
67                 return;
68         }
69
70         /* setup the incoming request handler for all our interfaces */
71         for (iface=nbtsrv->interfaces;iface;iface=iface->next) {
72                 nbt_set_incoming_handler(iface->nbtsock, nbt_request_handler, iface);
73         }
74 }
75
76
77 /*
78   initialise the nbt server
79  */
80 static NTSTATUS nbtd_init(struct event_context *event_ctx, const struct model_ops *model_ops)
81 {
82         return task_server_startup(event_ctx, model_ops, nbtd_task_init);
83 }
84
85
86 /*
87   register ourselves as a available server
88 */
89 NTSTATUS server_service_nbtd_init(void)
90 {
91         return register_server_service("nbt", nbtd_init);
92 }