s3: This module needs rewriting...
[Samba.git] / source4 / nbt_server / nbt_server.c
blob4bccc02cc53bfd2000494b78f0ed7da89e143818
1 /*
2 Unix SMB/CIFS implementation.
4 NBT server task
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 3 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, see <http://www.gnu.org/licenses/>.
22 #include "includes.h"
23 #include "smbd/service_task.h"
24 #include "smbd/service.h"
25 #include "nbt_server/nbt_server.h"
26 #include "nbt_server/wins/winsserver.h"
27 #include "system/network.h"
28 #include "lib/socket/netif.h"
29 #include "auth/auth.h"
30 #include "dsdb/samdb/samdb.h"
31 #include "param/param.h"
34 startup the nbtd task
36 static void nbtd_task_init(struct task_server *task)
38 struct nbtd_server *nbtsrv;
39 NTSTATUS status;
40 struct interface *ifaces;
42 load_interfaces(task, lpcfg_interfaces(task->lp_ctx), &ifaces);
44 if (iface_count(ifaces) == 0) {
45 task_server_terminate(task, "nbtd: no network interfaces configured", false);
46 return;
49 task_server_set_title(task, "task[nbtd]");
51 nbtsrv = talloc(task, struct nbtd_server);
52 if (nbtsrv == NULL) {
53 task_server_terminate(task, "nbtd: out of memory", true);
54 return;
57 nbtsrv->task = task;
58 nbtsrv->interfaces = NULL;
59 nbtsrv->bcast_interface = NULL;
60 nbtsrv->wins_interface = NULL;
62 /* start listening on the configured network interfaces */
63 status = nbtd_startup_interfaces(nbtsrv, task->lp_ctx, ifaces);
64 if (!NT_STATUS_IS_OK(status)) {
65 task_server_terminate(task, "nbtd failed to setup interfaces", true);
66 return;
69 nbtsrv->sam_ctx = samdb_connect(nbtsrv, task->event_ctx, task->lp_ctx, system_session(task->lp_ctx), 0);
70 if (nbtsrv->sam_ctx == NULL) {
71 task_server_terminate(task, "nbtd failed to open samdb", true);
72 return;
75 /* start the WINS server, if appropriate */
76 status = nbtd_winsserver_init(nbtsrv);
77 if (!NT_STATUS_IS_OK(status)) {
78 task_server_terminate(task, "nbtd failed to start WINS server", true);
79 return;
82 nbtd_register_irpc(nbtsrv);
84 /* start the process of registering our names on all interfaces */
85 nbtd_register_names(nbtsrv);
87 irpc_add_name(task->msg_ctx, "nbt_server");
92 register ourselves as a available server
94 NTSTATUS server_service_nbtd_init(void)
96 return register_server_service("nbt", nbtd_task_init);