2011-05-03 03:35:07 +04:00
/*
Unix SMB / CIFS implementation .
run s3 file server within Samba4
Copyright ( C ) Andrew Tridgell 2011
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"
# include "source4/smbd/service.h"
# include "source4/smbd/process_model.h"
# include "dynconfig.h"
2013-07-10 16:48:18 +04:00
# include "nsswitch/winbind_client.h"
2011-05-03 03:35:07 +04:00
/*
called if smbd exits
*/
static void file_server_smbd_done ( struct tevent_req * subreq )
{
2012-09-04 13:06:15 +04:00
struct task_server * task =
tevent_req_callback_data ( subreq ,
struct task_server ) ;
2011-05-03 03:35:07 +04:00
int sys_errno ;
int ret ;
ret = samba_runcmd_recv ( subreq , & sys_errno ) ;
if ( ret ! = 0 ) {
DEBUG ( 0 , ( " file_server smbd daemon died with exit status %d \n " , sys_errno ) ) ;
} else {
DEBUG ( 0 , ( " file_server smbd daemon exited normally \n " ) ) ;
}
2012-09-04 13:06:15 +04:00
task_server_terminate ( task , " smbd child process exited " , true ) ;
2011-05-03 03:35:07 +04:00
}
/*
startup a copy of smbd as a child daemon
*/
2018-08-23 00:35:52 +03:00
static NTSTATUS s3fs_task_init ( struct task_server * task )
2011-05-03 03:35:07 +04:00
{
2012-09-04 13:04:16 +04:00
struct tevent_req * subreq ;
2011-05-03 03:35:07 +04:00
const char * smbd_path ;
const char * smbd_cmd [ 2 ] = { NULL , NULL } ;
task_server_set_title ( task , " task[s3fs_parent] " ) ;
smbd_path = talloc_asprintf ( task , " %s/smbd " , dyn_SBINDIR ) ;
smbd_cmd [ 0 ] = smbd_path ;
2013-07-10 16:48:18 +04:00
/* the child should be able to call through nss_winbind */
( void ) winbind_on ( ) ;
2011-05-03 03:35:07 +04:00
/* start it as a child process */
2012-09-04 13:04:16 +04:00
subreq = samba_runcmd_send ( task , task - > event_ctx , timeval_zero ( ) , 1 , 0 ,
2011-05-03 03:35:07 +04:00
smbd_cmd ,
2012-12-14 06:52:46 +04:00
" -D " ,
2012-11-01 04:26:16 +04:00
" --option=server role check:inhibit=yes " ,
2012-02-09 07:07:00 +04:00
" --foreground " ,
debug_get_output_is_stdout ( ) ? " --log-stdout " : NULL ,
NULL ) ;
2013-07-10 16:48:18 +04:00
/* the parent should not be able to call through nss_winbind */
if ( ! winbind_off ( ) ) {
DEBUG ( 0 , ( " Failed to re-disable recursive winbindd calls after forking smbd \n " ) ) ;
task_server_terminate ( task , " Failed to re-disable recursive winbindd calls " , true ) ;
2018-08-23 00:35:52 +03:00
return NT_STATUS_UNSUCCESSFUL ;
2013-07-10 16:48:18 +04:00
}
2012-09-04 13:04:16 +04:00
if ( subreq = = NULL ) {
2011-05-03 03:35:07 +04:00
DEBUG ( 0 , ( " Failed to start smbd as child daemon \n " ) ) ;
2012-09-04 11:18:45 +04:00
task_server_terminate ( task , " Failed to startup s3fs smb task " , true ) ;
2018-08-23 00:35:52 +03:00
return NT_STATUS_UNSUCCESSFUL ;
2011-05-03 03:35:07 +04:00
}
2012-09-04 13:04:16 +04:00
tevent_req_set_callback ( subreq , file_server_smbd_done , task ) ;
2011-05-03 03:35:07 +04:00
2012-11-01 04:26:16 +04:00
DEBUG ( 5 , ( " Started file server child smbd \n " ) ) ;
2018-08-23 00:35:52 +03:00
return NT_STATUS_OK ;
2011-05-03 03:35:07 +04:00
}
/* called at smbd startup - register ourselves as a server service */
2017-04-20 22:24:43 +03:00
NTSTATUS server_service_s3fs_init ( TALLOC_CTX * ) ;
2011-05-03 03:35:07 +04:00
2017-04-20 22:24:43 +03:00
NTSTATUS server_service_s3fs_init ( TALLOC_CTX * ctx )
2011-05-03 03:35:07 +04:00
{
2017-09-14 22:09:23 +03:00
struct service_details details = {
. inhibit_fork_on_accept = true ,
2018-08-23 00:35:52 +03:00
. inhibit_pre_fork = true ,
. task_init = s3fs_task_init ,
. post_fork = NULL
2017-09-14 22:09:23 +03:00
} ;
2018-08-23 00:35:52 +03:00
return register_server_service ( ctx , " s3fs " , & details ) ;
2011-05-03 03:35:07 +04:00
}