2005-01-30 05:55:30 +03:00
/*
Unix SMB / CIFS implementation .
helper functions for task based servers ( nbtd , winbind etc )
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 05:55:30 +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 05:55:30 +03:00
*/
# include "includes.h"
# include "process_model.h"
2005-06-05 10:53:07 +04:00
# include "lib/messaging/irpc.h"
2007-10-01 22:52:55 +04:00
# include "param/param.h"
2010-09-03 13:39:15 +04:00
# include "librpc/gen_ndr/ndr_irpc_c.h"
2005-01-30 05:55:30 +03:00
/*
terminate a task service
*/
2009-09-19 05:05:55 +04:00
void task_server_terminate ( struct task_server * task , const char * reason , bool fatal )
2005-01-30 05:55:30 +03:00
{
2008-12-29 22:24:57 +03:00
struct tevent_context * event_ctx = task - > event_ctx ;
2005-01-30 05:55:30 +03:00
const struct model_ops * model_ops = task - > model_ops ;
2005-06-26 03:53:14 +04:00
DEBUG ( 0 , ( " task_server_terminate: [%s] \n " , reason ) ) ;
2009-09-19 05:05:55 +04:00
if ( fatal ) {
2010-09-03 13:39:15 +04:00
struct dcerpc_binding_handle * irpc_handle ;
2009-09-19 05:05:55 +04:00
struct samba_terminate r ;
2010-09-03 13:39:15 +04:00
irpc_handle = irpc_binding_handle_by_name ( task , task - > msg_ctx ,
" samba " , & ndr_table_irpc ) ;
2010-09-15 07:14:42 +04:00
if ( irpc_handle ! = NULL ) {
r . in . reason = reason ;
dcerpc_samba_terminate_r ( irpc_handle , task , & r ) ;
}
2009-09-19 05:05:55 +04:00
}
2008-09-30 05:20:46 +04:00
model_ops - > terminate ( event_ctx , task - > lp_ctx , reason ) ;
2007-07-19 07:57:44 +04:00
/* don't free this above, it might contain the 'reason' being printed */
talloc_free ( task ) ;
2005-01-30 05:55:30 +03:00
}
/* used for the callback from the process model code */
struct task_state {
void ( * task_init ) ( struct task_server * ) ;
const struct model_ops * model_ops ;
} ;
/*
called by the process model code when the new task starts up . This then calls
the server specific startup code
*/
2008-12-29 22:24:57 +03:00
static void task_server_callback ( struct tevent_context * event_ctx ,
2008-01-06 04:03:43 +03:00
struct loadparm_context * lp_ctx ,
2009-02-02 10:41:28 +03:00
struct server_id server_id , void * private_data )
2005-01-30 05:55:30 +03:00
{
2009-02-02 10:41:28 +03:00
struct task_state * state = talloc_get_type ( private_data , struct task_state ) ;
2005-01-30 05:55:30 +03:00
struct task_server * task ;
task = talloc ( event_ctx , struct task_server ) ;
if ( task = = NULL ) return ;
task - > event_ctx = event_ctx ;
task - > model_ops = state - > model_ops ;
task - > server_id = server_id ;
2008-01-06 04:03:43 +03:00
task - > lp_ctx = lp_ctx ;
2005-01-30 05:55:30 +03:00
2011-05-03 04:40:33 +04:00
task - > msg_ctx = imessaging_init ( task ,
2011-07-22 08:55:32 +04:00
lpcfg_imessaging_path ( task , task - > lp_ctx ) ,
task - > server_id ,
task - > event_ctx , false ) ;
2005-01-30 05:55:30 +03:00
if ( ! task - > msg_ctx ) {
2011-05-03 04:40:33 +04:00
task_server_terminate ( task , " imessaging_init() failed " , true ) ;
2005-01-30 05:55:30 +03:00
return ;
}
state - > task_init ( task ) ;
}
/*
startup a task based server
*/
2008-12-29 22:24:57 +03:00
NTSTATUS task_server_startup ( struct tevent_context * event_ctx ,
2008-01-06 04:03:43 +03:00
struct loadparm_context * lp_ctx ,
2008-02-04 09:48:51 +03:00
const char * service_name ,
2005-01-30 05:55:30 +03:00
const struct model_ops * model_ops ,
void ( * task_init ) ( struct task_server * ) )
{
struct task_state * state ;
state = talloc ( event_ctx , struct task_state ) ;
NT_STATUS_HAVE_NO_MEMORY ( state ) ;
state - > task_init = task_init ;
state - > model_ops = model_ops ;
2008-02-04 09:48:51 +03:00
model_ops - > new_task ( event_ctx , lp_ctx , service_name , task_server_callback , state ) ;
2005-01-30 05:55:30 +03:00
return NT_STATUS_OK ;
}
2006-03-09 20:48:41 +03:00
/*
setup a task title
*/
void task_server_set_title ( struct task_server * task , const char * title )
{
task - > model_ops - > set_title ( task - > event_ctx , title ) ;
}