80b5ce7444bfa3966eb6b493d813dd1e4ae84012
[jpeach/samba.git] / source / web / startstop.c
1 /* 
2    Unix SMB/Netbios implementation.
3    Version 1.9.
4    start/stop nmbd and smbd
5    Copyright (C) Andrew Tridgell 1998
6    
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (at your option) any later version.
11    
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16    
17    You should have received a copy of the GNU General Public License
18    along with this program; if not, write to the Free Software
19    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22 #include "includes.h"
23 #include "smb.h"
24 #include "dynconfig.h"
25
26 /** Need to wait for daemons to startup */
27 #define SLEEP_TIME 3
28
29 /** Startup smbd from web interface. */
30 void start_smbd(void)
31 {
32         pstring binfile;
33
34         if (geteuid() != 0) return;
35
36         if (fork()) {
37                 sleep(SLEEP_TIME);
38                 return;
39         }
40
41         slprintf(binfile, sizeof(pstring) - 1, "%s/smbd", dyn_SBINDIR);
42
43         become_daemon();
44
45         execl(binfile, binfile, "-D", NULL);
46
47         exit(0);
48 }
49
50 /* startup nmbd */
51 void start_nmbd(void)
52 {
53         pstring binfile;
54
55         if (geteuid() != 0) return;
56
57         if (fork()) {
58                 sleep(SLEEP_TIME);
59                 return;
60         }
61
62         slprintf(binfile, sizeof(pstring) - 1, "%s/nmbd", dyn_SBINDIR);
63         
64         become_daemon();
65
66         execl(binfile, binfile, "-D", NULL);
67
68         exit(0);
69 }
70
71
72 /* stop smbd */
73 void stop_smbd(void)
74 {
75         pid_t pid = pidfile_pid("smbd");
76
77         if (geteuid() != 0) return;
78
79         if (pid == 0) return;
80
81         kill(pid, SIGTERM);
82 }
83
84 /* stop nmbd */
85 void stop_nmbd(void)
86 {
87         pid_t pid = pidfile_pid("nmbd");
88
89         if (geteuid() != 0) return;
90
91         if (pid == 0) return;
92
93         kill(pid, SIGTERM);
94 }
95
96 /* kill a specified process */
97 void kill_pid(pid_t pid)
98 {
99         if (geteuid() != 0) return;
100
101         if (pid <= 0) return;
102
103         kill(pid, SIGTERM);
104         sleep(SLEEP_TIME);
105 }