2014-03-28 05:35:21 +04:00
/*
Unix SMB / CIFS implementation .
run s3 winbindd server within Samba4
Copyright ( C ) Andrew Tridgell 2011
Copyright ( C ) Andrew Bartlett 2014
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 3 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 , see < http : //www.gnu.org/licenses/>.
*/
# include "includes.h"
# include "talloc.h"
# include "tevent.h"
# include "system/filesys.h"
# include "lib/param/param.h"
2020-11-20 17:27:17 +03:00
# include "source4/samba/service.h"
# include "source4/samba/process_model.h"
2014-03-28 05:35:21 +04:00
# include "dynconfig.h"
# include "nsswitch/winbind_client.h"
/*
called if winbindd exits
*/
static void winbindd_done ( struct tevent_req * subreq )
{
struct task_server * task =
tevent_req_callback_data ( subreq ,
struct task_server ) ;
int sys_errno ;
int ret ;
ret = samba_runcmd_recv ( subreq , & sys_errno ) ;
if ( ret ! = 0 ) {
DEBUG ( 0 , ( " winbindd daemon died with exit status %d \n " , sys_errno ) ) ;
} else {
DEBUG ( 0 , ( " winbindd daemon exited normally \n " ) ) ;
}
task_server_terminate ( task , " winbindd child process exited " , true ) ;
}
/*
startup a copy of winbindd as a child daemon
*/
2018-08-23 00:35:52 +03:00
static NTSTATUS winbindd_task_init ( struct task_server * task )
2014-03-28 05:35:21 +04:00
{
struct tevent_req * subreq ;
const char * winbindd_path ;
const char * winbindd_cmd [ 2 ] = { NULL , NULL } ;
2021-01-11 18:30:44 +03:00
const char * config_file = " " ;
2014-03-28 05:35:21 +04:00
task_server_set_title ( task , " task[winbindd_parent] " ) ;
winbindd_path = talloc_asprintf ( task , " %s/winbindd " , dyn_SBINDIR ) ;
2021-01-11 18:27:48 +03:00
if ( winbindd_path = = NULL ) {
return NT_STATUS_NO_MEMORY ;
}
2014-03-28 05:35:21 +04:00
winbindd_cmd [ 0 ] = winbindd_path ;
2021-01-11 18:30:44 +03:00
if ( ! is_default_dyn_CONFIGFILE ( ) ) {
config_file = talloc_asprintf ( task ,
" --configfile=%s " ,
get_dyn_CONFIGFILE ( ) ) ;
if ( config_file = = NULL ) {
return NT_STATUS_NO_MEMORY ;
}
}
2014-03-28 05:35:21 +04:00
/* start it as a child process */
subreq = samba_runcmd_send ( task , task - > event_ctx , timeval_zero ( ) , 1 , 0 ,
winbindd_cmd ,
" -D " ,
" --option=server role check:inhibit=yes " ,
" --foreground " ,
2021-01-11 18:30:44 +03:00
config_file ,
2021-01-11 11:52:36 +03:00
debug_get_output_is_stdout ( ) ? " --debug-stdout " : NULL ,
2014-03-28 05:35:21 +04:00
NULL ) ;
if ( subreq = = NULL ) {
DEBUG ( 0 , ( " Failed to start winbindd as child daemon \n " ) ) ;
task_server_terminate ( task , " Failed to startup winbindd task " , true ) ;
2018-08-23 00:35:52 +03:00
return NT_STATUS_UNSUCCESSFUL ;
2014-03-28 05:35:21 +04:00
}
tevent_req_set_callback ( subreq , winbindd_done , task ) ;
2015-01-27 18:32:48 +03:00
DEBUG ( 5 , ( " Started winbindd as a child daemon \n " ) ) ;
2018-08-23 00:35:52 +03:00
return NT_STATUS_OK ;
2014-03-28 05:35:21 +04:00
}
/* called at winbindd startup - register ourselves as a server service */
2017-04-20 22:24:43 +03:00
NTSTATUS server_service_winbindd_init ( TALLOC_CTX * ) ;
2014-03-28 05:35:21 +04:00
2017-04-20 22:24:43 +03:00
NTSTATUS server_service_winbindd_init ( TALLOC_CTX * ctx )
2014-03-28 05:35:21 +04:00
{
2018-08-23 00:29:56 +03:00
static const struct service_details details = {
2017-09-14 22:09:23 +03:00
. inhibit_fork_on_accept = true ,
. inhibit_pre_fork = true ,
2018-08-23 00:35:52 +03:00
. task_init = winbindd_task_init ,
. post_fork = NULL
2017-09-14 22:09:23 +03:00
} ;
2018-08-23 00:35:52 +03:00
NTSTATUS status = register_server_service ( ctx , " winbindd " , & details ) ;
2015-06-12 05:41:20 +03:00
if ( ! NT_STATUS_IS_OK ( status ) ) {
return status ;
}
2018-08-23 00:35:52 +03:00
return register_server_service ( ctx , " winbind " , & details ) ;
2014-03-28 05:35:21 +04:00
}