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"
2006-03-09 20:48:41 +03:00
# include "smbd/service.h"
2005-01-30 05:55:30 +03:00
# include "smbd/service_task.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"
2005-01-30 05:55:30 +03:00
/*
terminate a task service
*/
2005-06-26 03:53:14 +04:00
void task_server_terminate ( struct task_server * task , const char * reason )
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 ) ) ;
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 ,
2007-01-10 13:52:09 +03:00
struct server_id server_id , void * private )
2005-01-30 05:55:30 +03:00
{
struct task_state * state = talloc_get_type ( private , struct task_state ) ;
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
2007-10-01 22:52:55 +04:00
task - > msg_ctx = messaging_init ( task ,
2007-12-02 19:09:52 +03:00
lp_messaging_path ( task , task - > lp_ctx ) ,
2007-12-14 01:23:25 +03:00
task - > server_id ,
lp_iconv_convenience ( task - > lp_ctx ) ,
task - > event_ctx ) ;
2005-01-30 05:55:30 +03:00
if ( ! task - > msg_ctx ) {
2005-06-26 03:53:14 +04:00
task_server_terminate ( task , " messaging_init() failed " ) ;
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 ) ;
}