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 2 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, write to the Free Software
|
---|
18 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
---|
19 | */
|
---|
20 | #include "includes.h"
|
---|
21 | #ifdef __OS2__
|
---|
22 | #include "process.h"
|
---|
23 | #define exists(filename) (!access(filename, F_OK))
|
---|
24 | #define SWAT_HELPER(WHAT, WHO) slprintf(binfile, sizeof(pstring) - 1, "swathelp.cmd"); \
|
---|
25 | int rc; \
|
---|
26 | rc=spawnl(P_NOWAIT, binfile, binfile, #WHAT, #WHO, NULL);
|
---|
27 | // printf("BINDIR: %s",dyn_BINDIR); \
|
---|
28 | // printf("SBINDIR: %s",dyn_SBINDIR); \
|
---|
29 | // printf("SWATDIR: %s",dyn_SWATDIR); \
|
---|
30 | // printf(#WHAT " " #WHO " pid:%i", rc);
|
---|
31 | #endif
|
---|
32 | #include "web/swat_proto.h"
|
---|
33 | #include "dynconfig.h"
|
---|
34 |
|
---|
35 | /** Startup smbd from web interface. */
|
---|
36 | void start_smbd(void)
|
---|
37 | {
|
---|
38 | pstring binfile;
|
---|
39 | if (geteuid() != 0) return;
|
---|
40 |
|
---|
41 | #ifdef __OS2__ /* because fork() in our libc ends all child when parent is closed we use spawn() */
|
---|
42 | SWAT_HELPER(start, smbd)
|
---|
43 | #else
|
---|
44 | if (fork()) {
|
---|
45 | return;
|
---|
46 | }
|
---|
47 | slprintf(binfile, sizeof(pstring) - 1, "%s/smbd", dyn_SBINDIR);
|
---|
48 | become_daemon(True, False);
|
---|
49 | execl(binfile, binfile, "-D", NULL);
|
---|
50 | exit(0);
|
---|
51 | #endif
|
---|
52 | }
|
---|
53 | /* startup nmbd */
|
---|
54 | void start_nmbd(void)
|
---|
55 | {
|
---|
56 | pstring binfile;
|
---|
57 | if (geteuid() != 0) return;
|
---|
58 |
|
---|
59 | #ifdef __OS2__ /* because fork() in our libc ends all child when parent is closed we use spawn() */
|
---|
60 | SWAT_HELPER(start, nmbd)
|
---|
61 | #else
|
---|
62 | if (fork()) {
|
---|
63 | return;
|
---|
64 | }
|
---|
65 | slprintf(binfile, sizeof(pstring) - 1, "%s/nmbd", dyn_SBINDIR);
|
---|
66 |
|
---|
67 | become_daemon(True, False);
|
---|
68 | execl(binfile, binfile, "-D", NULL);
|
---|
69 | exit(0);
|
---|
70 | #endif
|
---|
71 | }
|
---|
72 | /** Startup winbindd from web interface. */
|
---|
73 | void start_winbindd(void)
|
---|
74 | {
|
---|
75 | pstring binfile;
|
---|
76 |
|
---|
77 | if (geteuid() != 0) return;
|
---|
78 |
|
---|
79 | #ifdef __OS2__ /* because fork() in our libc ends all child when parent is closed we use spawn() */
|
---|
80 | SWAT_HELPER(start, winbindd)
|
---|
81 | #else
|
---|
82 |
|
---|
83 | if (fork()) {
|
---|
84 | return;
|
---|
85 | }
|
---|
86 | slprintf(binfile, sizeof(pstring) - 1, "%s/winbindd", dyn_SBINDIR);
|
---|
87 | become_daemon(True, False);
|
---|
88 | execl(binfile, binfile, NULL);
|
---|
89 | exit(0);
|
---|
90 | #endif
|
---|
91 | }
|
---|
92 |
|
---|
93 | /* stop smbd */
|
---|
94 | void stop_smbd(void)
|
---|
95 | {
|
---|
96 | pid_t pid = pidfile_pid("smbd");
|
---|
97 | if (geteuid() != 0) return;
|
---|
98 |
|
---|
99 | #ifdef __OS2__ /* we do it a bit nicer */
|
---|
100 | if (smbd_running()) {
|
---|
101 | pstring binfile;
|
---|
102 | SWAT_HELPER(stop, smbd)
|
---|
103 | }
|
---|
104 | #else
|
---|
105 | if (pid <= 0) return;
|
---|
106 |
|
---|
107 | kill(pid, SIGTERM);
|
---|
108 | #endif
|
---|
109 | }
|
---|
110 | /* stop nmbd */
|
---|
111 | void stop_nmbd(void)
|
---|
112 | {
|
---|
113 | pid_t pid = pidfile_pid("nmbd");
|
---|
114 | if (geteuid() != 0) return;
|
---|
115 |
|
---|
116 | #ifdef __OS2__ /* we do it a bit nicer */
|
---|
117 | if (nmbd_running()) {
|
---|
118 | pstring binfile;
|
---|
119 | SWAT_HELPER(stop, nmbd)
|
---|
120 | }
|
---|
121 | #else
|
---|
122 | if (pid <= 0) return;
|
---|
123 |
|
---|
124 | kill(pid, SIGTERM);
|
---|
125 | #endif
|
---|
126 | }
|
---|
127 |
|
---|
128 | #ifdef WITH_WINBIND
|
---|
129 | /* stop winbindd */
|
---|
130 | void stop_winbindd(void)
|
---|
131 | {
|
---|
132 | pid_t pid = pidfile_pid("winbindd");
|
---|
133 |
|
---|
134 | if (geteuid() != 0) return;
|
---|
135 |
|
---|
136 | #ifdef __OS2__ /* we do it a bit nicer */
|
---|
137 | if (winbindd_running()) {
|
---|
138 | pstring binfile;
|
---|
139 | SWAT_HELPER(stop, winbindd)
|
---|
140 | }
|
---|
141 | #else
|
---|
142 | if (pid <= 0) return;
|
---|
143 |
|
---|
144 | kill(pid, SIGTERM);
|
---|
145 | #endif
|
---|
146 | }
|
---|
147 | #endif
|
---|
148 | /* kill a specified process */
|
---|
149 | void kill_pid(struct process_id pid)
|
---|
150 | {
|
---|
151 | if (geteuid() != 0) return;
|
---|
152 |
|
---|
153 | if (procid_to_pid(&pid) <= 0) return;
|
---|
154 |
|
---|
155 | kill(procid_to_pid(&pid), SIGTERM);
|
---|
156 | }
|
---|