1998-03-14 16:00:09 +03:00
/*
2002-01-30 09:08:46 +03:00
Unix SMB / CIFS implementation .
1998-03-14 16:00:09 +03: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 23:25:36 +04:00
the Free Software Foundation ; either version 3 of the License , or
1998-03-14 16:00:09 +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 04:52:41 +04:00
along with this program . If not , see < http : //www.gnu.org/licenses/>.
1998-03-14 16:00:09 +03:00
*/
# include "includes.h"
2004-10-07 08:01:18 +04:00
# include "web/swat_proto.h"
2001-11-19 05:49:53 +03:00
# include "dynconfig.h"
1998-03-14 16:00:09 +03:00
2001-11-19 05:49:53 +03:00
/** Startup smbd from web interface. */
1998-03-14 16:00:09 +03:00
void start_smbd ( void )
{
2007-12-04 04:17:05 +03:00
char * binfile = NULL ;
1998-03-14 16:00:09 +03:00
2007-12-04 04:17:05 +03:00
if ( geteuid ( ) ! = 0 ) {
return ;
}
1998-03-14 16:00:09 +03:00
if ( fork ( ) ) {
return ;
}
2007-12-04 04:17:05 +03:00
if ( asprintf ( & binfile , " %s/smbd " , dyn_SBINDIR ) > 0 ) {
become_daemon ( true , false ) ;
execl ( binfile , binfile , " -D " , NULL ) ;
}
1998-03-14 16:00:09 +03:00
exit ( 0 ) ;
}
/* startup nmbd */
void start_nmbd ( void )
{
2007-12-04 04:17:05 +03:00
char * binfile = NULL ;
1998-03-14 16:00:09 +03:00
2007-12-04 04:17:05 +03:00
if ( geteuid ( ) ! = 0 ) {
return ;
}
1998-03-14 16:00:09 +03:00
if ( fork ( ) ) {
return ;
}
2007-12-04 04:17:05 +03:00
if ( asprintf ( & binfile , " %s/nmbd " , dyn_SBINDIR ) > 0 ) {
become_daemon ( true , false ) ;
execl ( binfile , binfile , " -D " , NULL ) ;
}
1998-03-14 16:00:09 +03:00
exit ( 0 ) ;
}
2002-08-17 18:34:48 +04:00
/** Startup winbindd from web interface. */
void start_winbindd ( void )
{
2007-12-04 04:17:05 +03:00
char * binfile = NULL ;
2002-08-17 18:34:48 +04:00
2007-12-04 04:17:05 +03:00
if ( geteuid ( ) ! = 0 ) {
return ;
}
2002-08-17 18:34:48 +04:00
if ( fork ( ) ) {
return ;
}
2007-12-04 04:17:05 +03:00
if ( asprintf ( & binfile , " %s/winbindd " , dyn_SBINDIR ) > 0 ) {
become_daemon ( true , false ) ;
execl ( binfile , binfile , NULL ) ;
}
2002-08-17 18:34:48 +04:00
exit ( 0 ) ;
}
1998-03-14 16:00:09 +03:00
/* stop smbd */
void stop_smbd ( void )
{
1998-09-29 01:43:48 +04:00
pid_t pid = pidfile_pid ( " smbd " ) ;
1998-03-14 16:00:09 +03:00
if ( geteuid ( ) ! = 0 ) return ;
2002-03-20 09:57:03 +03:00
if ( pid < = 0 ) return ;
1998-03-14 16:00:09 +03:00
kill ( pid , SIGTERM ) ;
}
/* stop nmbd */
void stop_nmbd ( void )
{
1998-09-29 01:43:48 +04:00
pid_t pid = pidfile_pid ( " nmbd " ) ;
1998-03-14 16:00:09 +03:00
if ( geteuid ( ) ! = 0 ) return ;
2002-03-20 09:57:03 +03:00
if ( pid < = 0 ) return ;
1998-03-14 16:00:09 +03:00
kill ( pid , SIGTERM ) ;
}
2002-08-17 18:34:48 +04:00
# ifdef WITH_WINBIND
/* stop winbindd */
void stop_winbindd ( void )
{
pid_t pid = pidfile_pid ( " winbindd " ) ;
1998-03-15 05:37:52 +03:00
2002-08-17 18:34:48 +04:00
if ( geteuid ( ) ! = 0 ) return ;
if ( pid < = 0 ) return ;
kill ( pid , SIGTERM ) ;
}
# endif
1998-03-15 05:37:52 +03:00
/* kill a specified process */
2007-05-07 13:35:35 +04:00
void kill_pid ( struct server_id pid )
1998-03-15 05:37:52 +03:00
{
if ( geteuid ( ) ! = 0 ) return ;
2005-09-30 21:13:37 +04:00
if ( procid_to_pid ( & pid ) < = 0 ) return ;
1998-03-15 05:37:52 +03:00
2005-09-30 21:13:37 +04:00
kill ( procid_to_pid ( & pid ) , SIGTERM ) ;
1998-03-15 05:37:52 +03:00
}