r5346: - a bit more preparation for the WINS server going in
[ira/wip.git] / source / 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 "lib/events/events.h"
25 #include "smbd/service_task.h"
26 #include "nbt_server/nbt_server.h"
27
28
29 /*
30   startup the nbtd task
31 */
32 static void nbtd_task_init(struct task_server *task)
33 {
34         struct nbtd_server *nbtsrv;
35         NTSTATUS status;
36
37         nbtsrv = talloc(task, struct nbtd_server);
38         if (nbtsrv == NULL) {
39                 task_terminate(task, "nbtd: out of memory");
40                 return;
41         }
42
43         nbtsrv->task            = task;
44         nbtsrv->interfaces      = NULL;
45         nbtsrv->bcast_interface = NULL;
46         nbtsrv->wins_interface  = NULL;
47
48         /* start listening on the configured network interfaces */
49         status = nbtd_startup_interfaces(nbtsrv);
50         if (!NT_STATUS_IS_OK(status)) {
51                 task_terminate(task, "nbtd failed to setup interfaces");
52                 return;
53         }
54
55         /* start the WINS server, if appropriate */
56         status = nbtd_winsserver_init(nbtsrv);
57         if (!NT_STATUS_IS_OK(status)) {
58                 task_terminate(task, "nbtd failed to start WINS server");
59                 return;
60         }
61
62         /* start the process of registering our names on all interfaces */
63         nbtd_register_names(nbtsrv);
64 }
65
66
67 /*
68   initialise the nbt server
69  */
70 static NTSTATUS nbtd_init(struct event_context *event_ctx, const struct model_ops *model_ops)
71 {
72         return task_server_startup(event_ctx, model_ops, nbtd_task_init);
73 }
74
75
76 /*
77   register ourselves as a available server
78 */
79 NTSTATUS server_service_nbtd_init(void)
80 {
81         return register_server_service("nbt", nbtd_init);
82 }