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
2007-07-09 19:25:36 +00:00
the Free Software Foundation ; either version 3 of the License , or
1998-03-14 13:00:09 +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 00:52:41 +00:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
1998-03-14 13:00:09 +00:00
*/
# include "includes.h"
2004-10-07 04:01:18 +00:00
# include "web/swat_proto.h"
2011-04-27 16:39:42 +10:00
# include "dynconfig/dynconfig.h"
2012-07-19 16:36:18 -07:00
# include "../lib/util/pidfile.h"
1998-03-14 13:00:09 +00:00
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 )
{
2007-12-03 17:17:05 -08:00
char * binfile = NULL ;
1998-03-14 13:00:09 +00:00
2007-12-03 17:17:05 -08:00
if ( geteuid ( ) ! = 0 ) {
return ;
}
1998-03-14 13:00:09 +00:00
if ( fork ( ) ) {
return ;
}
2007-12-10 11:30:37 -08:00
if ( asprintf ( & binfile , " %s/smbd " , get_dyn_SBINDIR ( ) ) > 0 ) {
2010-03-26 11:17:37 +01:00
become_daemon ( true , false , false ) ;
2007-12-03 17:17:05 -08:00
execl ( binfile , binfile , " -D " , NULL ) ;
}
1998-03-14 13:00:09 +00:00
exit ( 0 ) ;
}
/* startup nmbd */
void start_nmbd ( void )
{
2007-12-03 17:17:05 -08:00
char * binfile = NULL ;
1998-03-14 13:00:09 +00:00
2007-12-03 17:17:05 -08:00
if ( geteuid ( ) ! = 0 ) {
return ;
}
1998-03-14 13:00:09 +00:00
if ( fork ( ) ) {
return ;
}
2007-12-10 11:30:37 -08:00
if ( asprintf ( & binfile , " %s/nmbd " , get_dyn_SBINDIR ( ) ) > 0 ) {
2010-03-26 11:17:37 +01:00
become_daemon ( true , false , false ) ;
2007-12-03 17:17:05 -08:00
execl ( binfile , binfile , " -D " , NULL ) ;
}
1998-03-14 13:00:09 +00:00
exit ( 0 ) ;
}
2002-08-17 14:34:48 +00:00
/** Startup winbindd from web interface. */
void start_winbindd ( void )
{
2007-12-03 17:17:05 -08:00
char * binfile = NULL ;
2002-08-17 14:34:48 +00:00
2007-12-03 17:17:05 -08:00
if ( geteuid ( ) ! = 0 ) {
return ;
}
2002-08-17 14:34:48 +00:00
if ( fork ( ) ) {
return ;
}
2007-12-10 11:30:37 -08:00
if ( asprintf ( & binfile , " %s/winbindd " , get_dyn_SBINDIR ( ) ) > 0 ) {
2010-03-26 11:17:37 +01:00
become_daemon ( true , false , false ) ;
2007-12-03 17:17:05 -08:00
execl ( binfile , binfile , NULL ) ;
}
2002-08-17 14:34:48 +00:00
exit ( 0 ) ;
}
1998-03-14 13:00:09 +00:00
/* stop smbd */
void stop_smbd ( void )
{
2012-07-19 16:36:18 -07:00
pid_t pid = pidfile_pid ( lp_piddir ( ) , " 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 )
{
2012-07-19 16:36:18 -07:00
pid_t pid = pidfile_pid ( lp_piddir ( ) , " 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-08-17 14:34:48 +00:00
# ifdef WITH_WINBIND
/* stop winbindd */
void stop_winbindd ( void )
{
2012-07-19 16:36:18 -07:00
pid_t pid = pidfile_pid ( lp_piddir ( ) , " winbindd " ) ;
1998-03-15 02:37:52 +00:00
2002-08-17 14:34:48 +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 */
2007-05-07 09:35:35 +00:00
void kill_pid ( struct server_id pid )
1998-03-15 02:37:52 +00:00
{
if ( geteuid ( ) ! = 0 ) return ;
2005-09-30 17:13:37 +00:00
if ( procid_to_pid ( & pid ) < = 0 ) return ;
1998-03-15 02:37:52 +00:00
2005-09-30 17:13:37 +00:00
kill ( procid_to_pid ( & pid ) , SIGTERM ) ;
1998-03-15 02:37:52 +00:00
}