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
the Free Software Foundation ; either version 2 of the License , or
( 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
along with this program ; if not , write to the Free Software
Foundation , Inc . , 675 Mass Ave , Cambridge , MA 0213 9 , USA .
*/
# include "includes.h"
2005-02-03 14:56:03 +03:00
# include "lib/events/events.h"
2005-01-30 13:24:36 +03:00
# include "smbd/service_task.h"
# include "nbt_server/nbt_server.h"
2005-06-06 09:47:52 +04:00
/*
serve out the nbt statistics
*/
static NTSTATUS nbtd_information ( struct irpc_message * msg ,
struct nbtd_information * r )
{
struct nbtd_server * server = talloc_get_type ( msg - > private , struct nbtd_server ) ;
switch ( r - > in . level ) {
case NBTD_INFO_STATISTICS :
r - > out . info . stats = & server - > stats ;
break ;
}
return NT_STATUS_OK ;
}
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 ;
2005-01-30 13:24:36 +03:00
2005-02-16 04:48:11 +03:00
if ( iface_count ( ) = = 0 ) {
2005-06-26 03:53:14 +04:00
task_server_terminate ( task , " nbtd: no network interfaces configured " ) ;
2005-02-16 04:48:11 +03:00
return ;
}
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 ) {
2005-06-26 03:53:14 +04:00
task_server_terminate ( task , " nbtd: out of memory " ) ;
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 */
2005-02-04 04:39:10 +03:00
status = nbtd_startup_interfaces ( nbtsrv ) ;
2005-01-30 13:41:15 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
2005-06-26 03:53:14 +04:00
task_server_terminate ( task , " nbtd failed to setup interfaces " ) ;
2005-01-30 13:41:15 +03:00
return ;
}
2005-01-30 13:24:36 +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 ) ) {
2005-06-26 03:53:14 +04:00
task_server_terminate ( task , " nbtd failed to start WINS server " ) ;
2005-02-12 02:54:37 +03:00
return ;
}
2005-06-06 09:47:52 +04:00
/* setup monitoring */
status = IRPC_REGISTER ( task - > msg_ctx , irpc , NBTD_INFORMATION ,
nbtd_information , nbtsrv ) ;
if ( ! NT_STATUS_IS_OK ( status ) ) {
2005-06-26 03:53:14 +04:00
task_server_terminate ( task , " nbtd failed to setup monitoring " ) ;
2005-06-06 09:47:52 +04:00
return ;
}
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
}
/*
initialise the nbt server
*/
static NTSTATUS nbtd_init ( struct event_context * event_ctx , const struct model_ops * model_ops )
{
return task_server_startup ( event_ctx , model_ops , nbtd_task_init ) ;
}
/*
register ourselves as a available server
*/
NTSTATUS server_service_nbtd_init ( void )
{
return register_server_service ( " nbt " , nbtd_init ) ;
}