1998-03-14 13:00:09 +00:00
/*
2002-01-30 06:08:46 +00:00
Unix SMB / CIFS implementation .
1998-03-14 13:00:09 +00:00
start / stop nmbd and smbd
Copyright ( C ) Andrew Tridgell 1998
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 2 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 , write to the Free Software
Foundation , Inc . , 675 Mass Ave , Cambridge , MA 0213 9 , USA .
*/
# include "includes.h"
2002-06-25 02:29:09 +00:00
# include "../web/swat_proto.h"
2001-11-19 02:49:53 +00:00
# include "dynconfig.h"
1998-03-14 13:00:09 +00:00
2001-11-19 02:49:53 +00:00
/** Need to wait for daemons to startup */
1998-03-14 13:00:09 +00:00
# define SLEEP_TIME 3
2001-11-19 02:49:53 +00:00
/** Startup smbd from web interface. */
1998-03-14 13:00:09 +00:00
void start_smbd ( void )
{
pstring binfile ;
if ( geteuid ( ) ! = 0 ) return ;
if ( fork ( ) ) {
sleep ( SLEEP_TIME ) ;
return ;
}
2001-11-19 02:49:53 +00:00
slprintf ( binfile , sizeof ( pstring ) - 1 , " %s/smbd " , dyn_SBINDIR ) ;
1998-03-14 13:00:09 +00:00
2003-01-03 17:32:11 +00:00
become_daemon ( True ) ;
1998-03-14 13:00:09 +00:00
1998-03-17 00:32:34 +00:00
execl ( binfile , binfile , " -D " , NULL ) ;
1998-03-14 13:00:09 +00:00
exit ( 0 ) ;
}
/* startup nmbd */
void start_nmbd ( void )
{
pstring binfile ;
if ( geteuid ( ) ! = 0 ) return ;
if ( fork ( ) ) {
sleep ( SLEEP_TIME ) ;
return ;
}
2001-11-19 02:49:53 +00:00
slprintf ( binfile , sizeof ( pstring ) - 1 , " %s/nmbd " , dyn_SBINDIR ) ;
1998-03-14 13:00:09 +00:00
2003-01-03 17:32:11 +00:00
become_daemon ( True ) ;
1998-03-14 13:00:09 +00:00
1998-03-17 00:32:34 +00:00
execl ( binfile , binfile , " -D " , NULL ) ;
1998-03-14 13:00:09 +00:00
exit ( 0 ) ;
}
2002-07-27 01:37:33 +00:00
/** Startup winbindd from web interface. */
void start_winbindd ( void )
{
pstring binfile ;
if ( geteuid ( ) ! = 0 ) return ;
if ( fork ( ) ) {
sleep ( SLEEP_TIME ) ;
return ;
}
slprintf ( binfile , sizeof ( pstring ) - 1 , " %s/winbindd " , dyn_SBINDIR ) ;
2003-01-03 17:32:11 +00:00
become_daemon ( True ) ;
2002-07-27 01:37:33 +00:00
execl ( binfile , binfile , NULL ) ;
exit ( 0 ) ;
}
1998-03-14 13:00:09 +00:00
/* stop smbd */
void stop_smbd ( void )
{
1998-09-28 21:43:48 +00:00
pid_t pid = pidfile_pid ( " smbd " ) ;
1998-03-14 13:00:09 +00:00
if ( geteuid ( ) ! = 0 ) return ;
2002-03-20 06:57:03 +00:00
if ( pid < = 0 ) return ;
1998-03-14 13:00:09 +00:00
kill ( pid , SIGTERM ) ;
}
/* stop nmbd */
void stop_nmbd ( void )
{
1998-09-28 21:43:48 +00:00
pid_t pid = pidfile_pid ( " nmbd " ) ;
1998-03-14 13:00:09 +00:00
if ( geteuid ( ) ! = 0 ) return ;
2002-03-20 06:57:03 +00:00
if ( pid < = 0 ) return ;
1998-03-14 13:00:09 +00:00
kill ( pid , SIGTERM ) ;
}
2002-07-27 01:37:33 +00:00
# ifdef WITH_WINBIND
/* stop winbindd */
void stop_winbindd ( void )
{
pid_t pid = pidfile_pid ( " winbindd " ) ;
1998-03-15 02:37:52 +00:00
2002-07-27 01:37:33 +00:00
if ( geteuid ( ) ! = 0 ) return ;
if ( pid < = 0 ) return ;
kill ( pid , SIGTERM ) ;
}
# endif
1998-03-15 02:37:52 +00:00
/* kill a specified process */
1998-09-28 21:43:48 +00:00
void kill_pid ( pid_t pid )
1998-03-15 02:37:52 +00:00
{
if ( geteuid ( ) ! = 0 ) return ;
if ( pid < = 0 ) return ;
kill ( pid , SIGTERM ) ;
sleep ( SLEEP_TIME ) ;
}