2005-01-30 13:24:36 +03: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 06:07:03 +04:00
the Free Software Foundation ; either version 3 of the License , or
2005-01-30 13:24:36 +03: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 06:07:03 +04:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
2005-01-30 13:24:36 +03:00
*/
# include "includes.h"
2020-11-20 17:27:17 +03:00
# include "samba/service_task.h"
# include "samba/service.h"
2005-01-30 13:24:36 +03:00
# include "nbt_server/nbt_server.h"
2005-12-30 15:43:11 +03:00
# include "nbt_server/wins/winsserver.h"
2006-03-07 14:07:23 +03:00
# include "system/network.h"
2006-08-17 17:37:04 +04:00
# include "lib/socket/netif.h"
2006-12-13 14:19:51 +03:00
# include "auth/auth.h"
# include "dsdb/samdb/samdb.h"
2007-12-03 19:41:50 +03:00
# include "param/param.h"
2005-01-30 13:24:36 +03:00
2017-04-20 22:24:43 +03:00
NTSTATUS server_service_nbtd_init ( TALLOC_CTX * ) ;
2011-03-19 02:45:45 +03:00
2005-01-30 13:24:36 +03:00
/*
startup the nbtd task
*/
2018-08-23 00:35:52 +03:00
static NTSTATUS nbtd_task_init ( struct task_server * task )
2005-01-30 13:24:36 +03:00
{
2005-02-06 11:25:53 +03:00
struct nbtd_server * nbtsrv ;
2005-01-30 13:41:15 +03:00
NTSTATUS status ;
2007-12-12 00:23:14 +03:00
struct interface * ifaces ;
2005-01-30 13:24:36 +03:00
2011-06-02 09:40:28 +04:00
load_interface_list ( task , task - > lp_ctx , & ifaces ) ;
2007-12-12 00:23:14 +03:00
2011-05-02 09:57:19 +04:00
if ( iface_list_count ( ifaces ) = = 0 ) {
2009-09-19 05:05:55 +04:00
task_server_terminate ( task , " nbtd: no network interfaces configured " , false ) ;
2018-08-23 00:35:52 +03:00
return NT_STATUS_UNSUCCESSFUL ;
2005-02-16 04:48:11 +03:00
}
2013-02-06 13:58:18 +04: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 00:35:52 +03:00
return NT_STATUS_UNSUCCESSFUL ;
2013-02-06 13:58:18 +04:00
}
2006-03-09 20:48:41 +03:00
task_server_set_title ( task , " task[nbtd] " ) ;
2005-02-06 11:25:53 +03:00
nbtsrv = talloc ( task , struct nbtd_server ) ;
2005-01-30 13:24:36 +03:00
if ( nbtsrv = = NULL ) {
2009-09-19 05:05:55 +04:00
task_server_terminate ( task , " nbtd: out of memory " , true ) ;
2018-08-23 00:35:52 +03:00
return NT_STATUS_NO_MEMORY ;
2005-01-30 13:24:36 +03:00
}
2005-01-31 04:57:58 +03:00
nbtsrv - > task = task ;
nbtsrv - > interfaces = NULL ;
nbtsrv - > bcast_interface = NULL ;
2005-02-06 11:25:53 +03:00
nbtsrv - > wins_interface = NULL ;
2005-01-30 13:24:36 +03:00
2005-01-30 13:41:15 +03:00
/* start listening on the configured network interfaces */
2007-12-12 00:23:14 +03:00
status = nbtd_startup_interfaces ( nbtsrv , task - > lp_ctx , ifaces ) ;
2005-01-30 13:41:15 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2009-09-19 05:05:55 +04:00
task_server_terminate ( task , " nbtd failed to setup interfaces " , true ) ;
2018-08-23 00:35:52 +03:00
return status ;
2005-01-30 13:41:15 +03:00
}
2005-01-30 13:24:36 +03:00
2018-04-11 21:41:30 +03:00
nbtsrv - > sam_ctx = samdb_connect ( nbtsrv ,
task - > event_ctx ,
task - > lp_ctx ,
system_session ( task - > lp_ctx ) ,
NULL ,
0 ) ;
2006-12-13 14:19:51 +03:00
if ( nbtsrv - > sam_ctx = = NULL ) {
2009-09-19 05:05:55 +04:00
task_server_terminate ( task , " nbtd failed to open samdb " , true ) ;
2018-08-23 00:35:52 +03:00
return NT_STATUS_UNSUCCESSFUL ;
2006-12-13 14:19:51 +03:00
}
2005-02-12 02:54:37 +03:00
/* start the WINS server, if appropriate */
status = nbtd_winsserver_init ( nbtsrv ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
2009-09-19 05:05:55 +04:00
task_server_terminate ( task , " nbtd failed to start WINS server " , true ) ;
2018-08-23 00:35:52 +03:00
return status ;
2005-02-12 02:54:37 +03:00
}
2005-10-04 05:51:55 +04:00
nbtd_register_irpc ( nbtsrv ) ;
2005-09-26 01:01:56 +04:00
2005-01-31 04:57:58 +03:00
/* start the process of registering our names on all interfaces */
2005-02-04 04:39:10 +03:00
nbtd_register_names ( nbtsrv ) ;
2005-07-10 05:08:10 +04:00
irpc_add_name ( task - > msg_ctx , " nbt_server " ) ;
2018-08-23 00:35:52 +03:00
return NT_STATUS_OK ;
2005-01-30 13:24:36 +03:00
}
/*
register ourselves as a available server
*/
2017-04-20 22:24:43 +03:00
NTSTATUS server_service_nbtd_init ( TALLOC_CTX * ctx )
2005-01-30 13:24:36 +03:00
{
2018-08-23 00:29:56 +03:00
static const struct service_details details = {
2017-09-14 22:09:23 +03:00
. inhibit_fork_on_accept = true ,
2018-08-23 00:35:52 +03:00
. inhibit_pre_fork = true ,
. task_init = nbtd_task_init ,
. post_fork = NULL
2017-09-14 22:09:23 +03:00
} ;
2018-08-23 00:35:52 +03:00
return register_server_service ( ctx , " nbt " , & details ) ;
2005-01-30 13:24:36 +03:00
}