r7911: task_terminate() is defined in the macosx headers, so change the name
[samba.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 "lib/events/events.h"
25 #include "smbd/service_task.h"
26 #include "nbt_server/nbt_server.h"
27
28
29 /*
30   serve out the nbt statistics
31 */
32 static NTSTATUS nbtd_information(struct irpc_message *msg, 
33                                  struct nbtd_information *r)
34 {
35         struct nbtd_server *server = talloc_get_type(msg->private, struct nbtd_server);
36
37         switch (r->in.level) {
38         case NBTD_INFO_STATISTICS:
39                 r->out.info.stats = &server->stats;
40                 break;
41         }
42
43         return NT_STATUS_OK;
44 }
45
46
47
48 /*
49   startup the nbtd task
50 */
51 static void nbtd_task_init(struct task_server *task)
52 {
53         struct nbtd_server *nbtsrv;
54         NTSTATUS status;
55
56         if (iface_count() == 0) {
57                 task_server_terminate(task, "nbtd: no network interfaces configured");
58                 return;
59         }
60
61         nbtsrv = talloc(task, struct nbtd_server);
62         if (nbtsrv == NULL) {
63                 task_server_terminate(task, "nbtd: out of memory");
64                 return;
65         }
66
67         nbtsrv->task            = task;
68         nbtsrv->interfaces      = NULL;
69         nbtsrv->bcast_interface = NULL;
70         nbtsrv->wins_interface  = NULL;
71
72         /* start listening on the configured network interfaces */
73         status = nbtd_startup_interfaces(nbtsrv);
74         if (!NT_STATUS_IS_OK(status)) {
75                 task_server_terminate(task, "nbtd failed to setup interfaces");
76                 return;
77         }
78
79         /* start the WINS server, if appropriate */
80         status = nbtd_winsserver_init(nbtsrv);
81         if (!NT_STATUS_IS_OK(status)) {
82                 task_server_terminate(task, "nbtd failed to start WINS server");
83                 return;
84         }
85
86         /* setup monitoring */
87         status = IRPC_REGISTER(task->msg_ctx, irpc, NBTD_INFORMATION, 
88                                nbtd_information, nbtsrv);
89         if (!NT_STATUS_IS_OK(status)) {
90                 task_server_terminate(task, "nbtd failed to setup monitoring");
91                 return;
92         }
93
94         /* start the process of registering our names on all interfaces */
95         nbtd_register_names(nbtsrv);
96 }
97
98
99 /*
100   initialise the nbt server
101  */
102 static NTSTATUS nbtd_init(struct event_context *event_ctx, const struct model_ops *model_ops)
103 {
104         return task_server_startup(event_ctx, model_ops, nbtd_task_init);
105 }
106
107
108 /*
109   register ourselves as a available server
110 */
111 NTSTATUS server_service_nbtd_init(void)
112 {
113         return register_server_service("nbt", nbtd_init);
114 }