2005-01-30 10:24:36 +00:00
/*
Unix SMB / CIFS implementation .
NBT server task
Copyright ( C ) Andrew Tridgell 2005
This program is free software ; you can redistribute it and / or modify
it under the terms of the GNU General Public License as published by
2007-07-10 02:07:03 +00:00
the Free Software Foundation ; either version 3 of the License , or
2005-01-30 10:24:36 +00:00
( at your option ) any later version .
This program is distributed in the hope that it will be useful ,
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
You should have received a copy of the GNU General Public License
2007-07-10 02:07:03 +00:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
2005-01-30 10:24:36 +00:00
*/
# include "includes.h"
2020-11-20 15:27:17 +01:00
# include "samba/service_task.h"
# include "samba/service.h"
2005-01-30 10:24:36 +00:00
# include "nbt_server/nbt_server.h"
2005-12-30 12:43:11 +00:00
# include "nbt_server/wins/winsserver.h"
2006-03-07 11:07:23 +00:00
# include "system/network.h"
2006-08-17 13:37:04 +00:00
# include "lib/socket/netif.h"
2006-12-13 11:19:51 +00:00
# include "auth/auth.h"
# include "dsdb/samdb/samdb.h"
2007-12-03 17:41:50 +01:00
# include "param/param.h"
2005-01-30 10:24:36 +00:00
2017-04-20 12:24:43 -07:00
NTSTATUS server_service_nbtd_init ( TALLOC_CTX * ) ;
2011-03-19 00:45:45 +01:00
2005-01-30 10:24:36 +00:00
/*
startup the nbtd task
*/
2018-08-23 09:35:52 +12:00
static NTSTATUS nbtd_task_init ( struct task_server * task )
2005-01-30 10:24:36 +00:00
{
2005-02-06 08:25:53 +00:00
struct nbtd_server * nbtsrv ;
2005-01-30 10:41:15 +00:00
NTSTATUS status ;
2007-12-11 22:23:14 +01:00
struct interface * ifaces ;
2005-01-30 10:24:36 +00:00
2011-06-02 15:40:28 +10:00
load_interface_list ( task , task - > lp_ctx , & ifaces ) ;
2007-12-11 22:23:14 +01:00
2011-05-02 15:57:19 +10:00
if ( iface_list_count ( ifaces ) = = 0 ) {
2009-09-18 18:05:55 -07:00
task_server_terminate ( task , " nbtd: no network interfaces configured " , false ) ;
2018-08-23 09:35:52 +12:00
return NT_STATUS_UNSUCCESSFUL ;
2005-02-16 01:48:11 +00:00
}
2013-02-06 20:58:18 +11:00
if ( lpcfg_disable_netbios ( task - > lp_ctx ) ) {
task_server_terminate ( task , " nbtd: 'disable netbios = yes' set in smb.conf, shutting down nbt server " , false ) ;
2018-08-23 09:35:52 +12:00
return NT_STATUS_UNSUCCESSFUL ;
2013-02-06 20:58:18 +11:00
}
2006-03-09 17:48:41 +00:00
task_server_set_title ( task , " task[nbtd] " ) ;
2005-02-06 08:25:53 +00:00
nbtsrv = talloc ( task , struct nbtd_server ) ;
2005-01-30 10:24:36 +00:00
if ( nbtsrv = = NULL ) {
2009-09-18 18:05:55 -07:00
task_server_terminate ( task , " nbtd: out of memory " , true ) ;
2018-08-23 09:35:52 +12:00
return NT_STATUS_NO_MEMORY ;
2005-01-30 10:24:36 +00:00
}
2005-01-31 01:57:58 +00:00
nbtsrv - > task = task ;
nbtsrv - > interfaces = NULL ;
nbtsrv - > bcast_interface = NULL ;
2005-02-06 08:25:53 +00:00
nbtsrv - > wins_interface = NULL ;
2005-01-30 10:24:36 +00:00
2005-01-30 10:41:15 +00:00
/* start listening on the configured network interfaces */
2007-12-11 22:23:14 +01:00
status = nbtd_startup_interfaces ( nbtsrv , task - > lp_ctx , ifaces ) ;
2005-01-30 10:41:15 +00:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2009-09-18 18:05:55 -07:00
task_server_terminate ( task , " nbtd failed to setup interfaces " , true ) ;
2018-08-23 09:35:52 +12:00
return status ;
2005-01-30 10:41:15 +00:00
}
2005-01-30 10:24:36 +00:00
2018-04-12 06:41:30 +12:00
nbtsrv - > sam_ctx = samdb_connect ( nbtsrv ,
task - > event_ctx ,
task - > lp_ctx ,
system_session ( task - > lp_ctx ) ,
NULL ,
0 ) ;
2006-12-13 11:19:51 +00:00
if ( nbtsrv - > sam_ctx = = NULL ) {
2009-09-18 18:05:55 -07:00
task_server_terminate ( task , " nbtd failed to open samdb " , true ) ;
2018-08-23 09:35:52 +12:00
return NT_STATUS_UNSUCCESSFUL ;
2006-12-13 11:19:51 +00:00
}
2005-02-11 23:54:37 +00:00
/* start the WINS server, if appropriate */
status = nbtd_winsserver_init ( nbtsrv ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
2009-09-18 18:05:55 -07:00
task_server_terminate ( task , " nbtd failed to start WINS server " , true ) ;
2018-08-23 09:35:52 +12:00
return status ;
2005-02-11 23:54:37 +00:00
}
2005-10-04 01:51:55 +00:00
nbtd_register_irpc ( nbtsrv ) ;
2005-09-25 21:01:56 +00:00
2005-01-31 01:57:58 +00:00
/* start the process of registering our names on all interfaces */
2005-02-04 01:39:10 +00:00
nbtd_register_names ( nbtsrv ) ;
2005-07-10 01:08:10 +00:00
irpc_add_name ( task - > msg_ctx , " nbt_server " ) ;
2018-08-23 09:35:52 +12:00
return NT_STATUS_OK ;
2005-01-30 10:24:36 +00:00
}
/*
register ourselves as a available server
*/
2017-04-20 12:24:43 -07:00
NTSTATUS server_service_nbtd_init ( TALLOC_CTX * ctx )
2005-01-30 10:24:36 +00:00
{
2018-08-23 09:29:56 +12:00
static const struct service_details details = {
2017-09-15 07:09:23 +12:00
. inhibit_fork_on_accept = true ,
2018-08-23 09:35:52 +12:00
. inhibit_pre_fork = true ,
. task_init = nbtd_task_init ,
. post_fork = NULL
2017-09-15 07:09:23 +12:00
} ;
2018-08-23 09:35:52 +12:00
return register_server_service ( ctx , " nbt " , & details ) ;
2005-01-30 10:24:36 +00:00
}