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"
# include "smbd/service_task.h"
2006-03-07 17:13:38 +03:00
# include "smbd/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
2011-03-19 02:45:45 +03:00
NTSTATUS server_service_nbtd_init ( void ) ;
2005-01-30 13:24:36 +03:00
/*
startup the nbtd task
*/
static void nbtd_task_init ( struct task_server * task )
{
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 ) ;
2005-02-16 04:48:11 +03:00
return ;
}
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 ) ;
return ;
}
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 ) ;
2005-01-30 13:24:36 +03:00
return ;
}
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 ) ;
2005-01-30 13:41:15 +03:00
return ;
}
2005-01-30 13:24:36 +03:00
2010-10-10 19:00:45 +04:00
nbtsrv - > sam_ctx = samdb_connect ( nbtsrv , task - > event_ctx , task - > lp_ctx , system_session ( task - > lp_ctx ) , 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 ) ;
2006-12-13 14:19:51 +03:00
return ;
}
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 ) ;
2005-02-12 02:54:37 +03:00
return ;
}
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 " ) ;
2005-01-30 13:24:36 +03:00
}
/*
register ourselves as a available server
*/
NTSTATUS server_service_nbtd_init ( void )
{
2008-02-04 13:58:29 +03:00
return register_server_service ( " nbt " , nbtd_task_init ) ;
2005-01-30 13:24:36 +03:00
}