Line data Source code
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 3 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, see <http://www.gnu.org/licenses/>. 20 : */ 21 : 22 : #include "includes.h" 23 : #include "samba/service_task.h" 24 : #include "samba/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" 32 : 33 : NTSTATUS server_service_nbtd_init(TALLOC_CTX *); 34 : 35 : /* 36 : startup the nbtd task 37 : */ 38 65 : static NTSTATUS nbtd_task_init(struct task_server *task) 39 : { 40 2 : struct nbtd_server *nbtsrv; 41 2 : NTSTATUS status; 42 2 : struct interface *ifaces; 43 : 44 65 : load_interface_list(task, task->lp_ctx, &ifaces); 45 : 46 65 : if (iface_list_count(ifaces) == 0) { 47 0 : task_server_terminate(task, "nbtd: no network interfaces configured", false); 48 0 : return NT_STATUS_UNSUCCESSFUL; 49 : } 50 : 51 65 : if (lpcfg_disable_netbios(task->lp_ctx)) { 52 0 : task_server_terminate(task, "nbtd: 'disable netbios = yes' set in smb.conf, shutting down nbt server", false); 53 0 : return NT_STATUS_UNSUCCESSFUL; 54 : } 55 : 56 65 : task_server_set_title(task, "task[nbtd]"); 57 : 58 65 : nbtsrv = talloc(task, struct nbtd_server); 59 65 : if (nbtsrv == NULL) { 60 0 : task_server_terminate(task, "nbtd: out of memory", true); 61 0 : return NT_STATUS_NO_MEMORY; 62 : } 63 : 64 65 : nbtsrv->task = task; 65 65 : nbtsrv->interfaces = NULL; 66 65 : nbtsrv->bcast_interface = NULL; 67 65 : nbtsrv->wins_interface = NULL; 68 : 69 : /* start listening on the configured network interfaces */ 70 65 : status = nbtd_startup_interfaces(nbtsrv, task->lp_ctx, ifaces); 71 65 : if (!NT_STATUS_IS_OK(status)) { 72 0 : task_server_terminate(task, "nbtd failed to setup interfaces", true); 73 0 : return status; 74 : } 75 : 76 65 : nbtsrv->sam_ctx = samdb_connect(nbtsrv, 77 : task->event_ctx, 78 : task->lp_ctx, 79 : system_session(task->lp_ctx), 80 : NULL, 81 : 0); 82 65 : if (nbtsrv->sam_ctx == NULL) { 83 0 : task_server_terminate(task, "nbtd failed to open samdb", true); 84 0 : return NT_STATUS_UNSUCCESSFUL; 85 : } 86 : 87 : /* start the WINS server, if appropriate */ 88 65 : status = nbtd_winsserver_init(nbtsrv); 89 65 : if (!NT_STATUS_IS_OK(status)) { 90 0 : task_server_terminate(task, "nbtd failed to start WINS server", true); 91 0 : return status; 92 : } 93 : 94 65 : nbtd_register_irpc(nbtsrv); 95 : 96 : /* start the process of registering our names on all interfaces */ 97 65 : nbtd_register_names(nbtsrv); 98 : 99 65 : irpc_add_name(task->msg_ctx, "nbt_server"); 100 : 101 65 : return NT_STATUS_OK; 102 : } 103 : 104 : 105 : /* 106 : register ourselves as a available server 107 : */ 108 66 : NTSTATUS server_service_nbtd_init(TALLOC_CTX *ctx) 109 : { 110 3 : static const struct service_details details = { 111 : .inhibit_fork_on_accept = true, 112 : .inhibit_pre_fork = true, 113 : .task_init = nbtd_task_init, 114 : .post_fork = NULL 115 : }; 116 66 : return register_server_service(ctx, "nbt", &details); 117 : }