source: branches/samba-3.5.x/source3/web/startstop.c@ 791

Last change on this file since 791 was 454, checked in by Silvan Scherrer, 15 years ago

Samba Server 3.5: merged changes from 3.3

File size: 3.6 KB
Line 
1/*
2 Unix SMB/CIFS implementation.
3 start/stop nmbd and smbd
4 Copyright (C) Andrew Tridgell 1998
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20#include "includes.h"
21
22#ifdef __OS2__
23 /* fork() in klibc on OS/2 ends all children when parent
24 is closed, therefore we use spawn() */
25#include "process.h"
26#define SWAT_HELPER(WHAT, WHO) \
27 asprintf(&binfile, "%s/swathelp.cmd", getcwd(NULL, _MAX_PATH)); \
28 int rc; \
29 rc=spawnl(P_NOWAIT, binfile, binfile, #WHAT, #WHO, NULL);
30#endif
31
32#include "web/swat_proto.h"
33#include "dynconfig.h"
34
35
36/** Startup smbd from web interface. */
37void start_smbd(void)
38{
39 char *binfile = NULL;
40
41 if (geteuid() != 0) {
42 return;
43 }
44
45#ifdef __OS2__
46 /* fork() in klibc on OS/2 ends all children when parent
47 is closed, therefore we use spawn() */
48 SWAT_HELPER(start, smbd)
49#else
50 if (fork()) {
51 return;
52 }
53
54 if (asprintf(&binfile, "%s/smbd", get_dyn_SBINDIR()) > 0) {
55 become_daemon(true, false);
56 execl(binfile, binfile, "-D", NULL);
57 }
58 exit(0);
59#endif
60}
61
62/* startup nmbd */
63void start_nmbd(void)
64{
65 char *binfile = NULL;
66
67 if (geteuid() != 0) {
68 return;
69 }
70
71#ifdef __OS2__
72 /* fork() in klibc on OS/2 ends all children when parent
73 is closed, therefore we use spawn() */
74 SWAT_HELPER(start, nmbd)
75#else
76 if (fork()) {
77 return;
78 }
79
80 if (asprintf(&binfile, "%s/nmbd", get_dyn_SBINDIR()) > 0) {
81 become_daemon(true, false);
82 execl(binfile, binfile, "-D", NULL);
83 }
84 exit(0);
85#endif
86}
87
88/** Startup winbindd from web interface. */
89void start_winbindd(void)
90{
91 char *binfile = NULL;
92
93 if (geteuid() != 0) {
94 return;
95 }
96
97#ifdef __OS2__
98 /* fork() in klibc on OS/2 ends all children when parent
99 is closed, therefore we use spawn() */
100 SWAT_HELPER(start, winbindd)
101#else
102 if (fork()) {
103 return;
104 }
105
106 if (asprintf(&binfile, "%s/winbindd", get_dyn_SBINDIR()) > 0) {
107 become_daemon(true, false);
108 execl(binfile, binfile, NULL);
109 }
110 exit(0);
111#endif
112}
113
114
115/* stop smbd */
116void stop_smbd(void)
117{
118 pid_t pid = pidfile_pid("smbd");
119
120 if (geteuid() != 0) return;
121
122#ifdef __OS2__ /* we do it a bit nicer */
123 if (smbd_running()) {
124 char *binfile = NULL;
125 SWAT_HELPER(stop, smbd)
126 }
127#else
128 if (pid <= 0) return;
129
130 kill(pid, SIGTERM);
131#endif
132}
133
134/* stop nmbd */
135void stop_nmbd(void)
136{
137 pid_t pid = pidfile_pid("nmbd");
138
139 if (geteuid() != 0) return;
140
141#ifdef __OS2__ /* we do it a bit nicer */
142 if (nmbd_running()) {
143 char *binfile = NULL;
144 SWAT_HELPER(stop, nmbd)
145 }
146#else
147 if (pid <= 0) return;
148
149 kill(pid, SIGTERM);
150#endif
151}
152#ifdef WITH_WINBIND
153/* stop winbindd */
154void stop_winbindd(void)
155{
156 pid_t pid = pidfile_pid("winbindd");
157
158 if (geteuid() != 0) return;
159
160#ifdef __OS2__ /* we do it a bit nicer */
161 if (winbindd_running()) {
162 char *binfile = NULL;
163 SWAT_HELPER(stop, winbindd)
164 }
165#else
166 if (pid <= 0) return;
167
168 kill(pid, SIGTERM);
169#endif
170}
171#endif
172/* kill a specified process */
173void kill_pid(struct server_id pid)
174{
175 if (geteuid() != 0) return;
176
177 if (procid_to_pid(&pid) <= 0) return;
178
179 kill(procid_to_pid(&pid), SIGTERM);
180}
Note: See TracBrowser for help on using the repository browser.