a2b95d76c486d837cb3d96202ba3c8ac2c38145d
[kai/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 "smbd/service_task.h"
25 #include "smbd/service.h"
26 #include "nbt_server/nbt_server.h"
27 #include "nbt_server/wins/winsserver.h"
28 #include "system/network.h"
29 #include "lib/socket/netif.h"
30 #include "auth/auth.h"
31 #include "dsdb/samdb/samdb.h"
32
33 /*
34   startup the nbtd task
35 */
36 static void nbtd_task_init(struct task_server *task)
37 {
38         struct nbtd_server *nbtsrv;
39         NTSTATUS status;
40
41         if (iface_count() == 0) {
42                 task_server_terminate(task, "nbtd: no network interfaces configured");
43                 return;
44         }
45
46         task_server_set_title(task, "task[nbtd]");
47
48         nbtsrv = talloc(task, struct nbtd_server);
49         if (nbtsrv == NULL) {
50                 task_server_terminate(task, "nbtd: out of memory");
51                 return;
52         }
53
54         nbtsrv->task            = task;
55         nbtsrv->interfaces      = NULL;
56         nbtsrv->bcast_interface = NULL;
57         nbtsrv->wins_interface  = NULL;
58
59         /* start listening on the configured network interfaces */
60         status = nbtd_startup_interfaces(nbtsrv);
61         if (!NT_STATUS_IS_OK(status)) {
62                 task_server_terminate(task, "nbtd failed to setup interfaces");
63                 return;
64         }
65
66         nbtsrv->sam_ctx = samdb_connect(nbtsrv, anonymous_session(nbtsrv));
67         if (nbtsrv->sam_ctx == NULL) {
68                 task_server_terminate(task, "nbtd failed to open samdb");
69                 return;
70         }
71
72         /* start the WINS server, if appropriate */
73         status = nbtd_winsserver_init(nbtsrv);
74         if (!NT_STATUS_IS_OK(status)) {
75                 task_server_terminate(task, "nbtd failed to start WINS server");
76                 return;
77         }
78
79         nbtd_register_irpc(nbtsrv);
80
81         /* start the process of registering our names on all interfaces */
82         nbtd_register_names(nbtsrv);
83
84         irpc_add_name(task->msg_ctx, "nbt_server");
85
86
87 }
88
89
90 /*
91   initialise the nbt server
92  */
93 static NTSTATUS nbtd_init(struct event_context *event_ctx, const struct model_ops *model_ops)
94 {
95         return task_server_startup(event_ctx, model_ops, nbtd_task_init);
96 }
97
98
99 /*
100   register ourselves as a available server
101 */
102 NTSTATUS server_service_nbtd_init(void)
103 {
104         return register_server_service("nbt", nbtd_init);
105 }