2005-01-30 02:55:30 +00: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 02:07:03 +00:00
the Free Software Foundation ; either version 3 of the License , or
2005-01-30 02:55:30 +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 02:55:30 +00:00
*/
# include "includes.h"
# include "process_model.h"
2005-06-05 06:53:07 +00:00
# include "lib/messaging/irpc.h"
2007-10-01 18:52:55 +00:00
# include "param/param.h"
2009-09-18 18:05:55 -07:00
# include "librpc/gen_ndr/ndr_irpc.h"
2005-01-30 02:55:30 +00:00
/*
terminate a task service
*/
2009-09-18 18:05:55 -07:00
void task_server_terminate ( struct task_server * task , const char * reason , bool fatal )
2005-01-30 02:55:30 +00:00
{
2008-12-29 20:24:57 +01:00
struct tevent_context * event_ctx = task - > event_ctx ;
2005-01-30 02:55:30 +00:00
const struct model_ops * model_ops = task - > model_ops ;
2005-06-25 23:53:14 +00:00
DEBUG ( 0 , ( " task_server_terminate: [%s] \n " , reason ) ) ;
2009-09-18 18:05:55 -07:00
if ( fatal ) {
struct samba_terminate r ;
struct server_id * sid ;
sid = irpc_servers_byname ( task - > msg_ctx , task , " samba " ) ;
r . in . reason = reason ;
IRPC_CALL ( task - > msg_ctx , sid [ 0 ] ,
irpc , SAMBA_TERMINATE ,
& r , NULL ) ;
}
2008-09-30 03:20:46 +02:00
model_ops - > terminate ( event_ctx , task - > lp_ctx , reason ) ;
2007-07-19 03:57:44 +00:00
/* don't free this above, it might contain the 'reason' being printed */
talloc_free ( task ) ;
2005-01-30 02:55:30 +00: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 20:24:57 +01:00
static void task_server_callback ( struct tevent_context * event_ctx ,
2008-01-05 19:03:43 -06:00
struct loadparm_context * lp_ctx ,
2009-02-02 08:41:28 +01:00
struct server_id server_id , void * private_data )
2005-01-30 02:55:30 +00:00
{
2009-02-02 08:41:28 +01:00
struct task_state * state = talloc_get_type ( private_data , struct task_state ) ;
2005-01-30 02:55:30 +00: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-05 19:03:43 -06:00
task - > lp_ctx = lp_ctx ;
2005-01-30 02:55:30 +00:00
2007-10-01 18:52:55 +00:00
task - > msg_ctx = messaging_init ( task ,
2007-12-02 17:09:52 +01:00
lp_messaging_path ( task , task - > lp_ctx ) ,
2007-12-13 23:23:25 +01:00
task - > server_id ,
lp_iconv_convenience ( task - > lp_ctx ) ,
task - > event_ctx ) ;
2005-01-30 02:55:30 +00:00
if ( ! task - > msg_ctx ) {
2009-09-18 18:05:55 -07:00
task_server_terminate ( task , " messaging_init() failed " , true ) ;
2005-01-30 02:55:30 +00:00
return ;
}
state - > task_init ( task ) ;
}
/*
startup a task based server
*/
2008-12-29 20:24:57 +01:00
NTSTATUS task_server_startup ( struct tevent_context * event_ctx ,
2008-01-05 19:03:43 -06:00
struct loadparm_context * lp_ctx ,
2008-02-04 17:48:51 +11:00
const char * service_name ,
2005-01-30 02:55:30 +00: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 17:48:51 +11:00
model_ops - > new_task ( event_ctx , lp_ctx , service_name , task_server_callback , state ) ;
2005-01-30 02:55:30 +00:00
return NT_STATUS_OK ;
}
2006-03-09 17:48:41 +00: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 ) ;
}