[745] | 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 |
|
---|
[454] | 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 |
|
---|
[745] | 32 | #include "web/swat_proto.h"
|
---|
| 33 | #include "dynconfig.h"
|
---|
| 34 |
|
---|
| 35 |
|
---|
| 36 | /** Startup smbd from web interface. */
|
---|
| 37 | void start_smbd(void)
|
---|
| 38 | {
|
---|
| 39 | char *binfile = NULL;
|
---|
| 40 |
|
---|
| 41 | if (geteuid() != 0) {
|
---|
| 42 | return;
|
---|
| 43 | }
|
---|
| 44 |
|
---|
[454] | 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)
|
---|
[745] | 49 | #else
|
---|
| 50 | if (fork()) {
|
---|
| 51 | return;
|
---|
| 52 | }
|
---|
| 53 |
|
---|
| 54 | if (asprintf(&binfile, "%s/smbd", get_dyn_SBINDIR()) > 0) {
|
---|
| 55 | become_daemon(true, false, false);
|
---|
| 56 | execl(binfile, binfile, "-D", NULL);
|
---|
| 57 | }
|
---|
[454] | 58 | exit(0);
|
---|
[745] | 59 | #endif
|
---|
| 60 | }
|
---|
[454] | 61 |
|
---|
[745] | 62 | /* startup nmbd */
|
---|
| 63 | void start_nmbd(void)
|
---|
| 64 | {
|
---|
| 65 | char *binfile = NULL;
|
---|
| 66 |
|
---|
| 67 | if (geteuid() != 0) {
|
---|
| 68 | return;
|
---|
| 69 | }
|
---|
| 70 |
|
---|
[454] | 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)
|
---|
[745] | 75 | #else
|
---|
| 76 | if (fork()) {
|
---|
| 77 | return;
|
---|
| 78 | }
|
---|
| 79 |
|
---|
| 80 | if (asprintf(&binfile, "%s/nmbd", get_dyn_SBINDIR()) > 0) {
|
---|
| 81 | become_daemon(true, false, false);
|
---|
| 82 | execl(binfile, binfile, "-D", NULL);
|
---|
| 83 | }
|
---|
[454] | 84 | exit(0);
|
---|
[745] | 85 | #endif
|
---|
| 86 | }
|
---|
[454] | 87 |
|
---|
[745] | 88 | /** Startup winbindd from web interface. */
|
---|
| 89 | void start_winbindd(void)
|
---|
| 90 | {
|
---|
| 91 | char *binfile = NULL;
|
---|
| 92 |
|
---|
| 93 | if (geteuid() != 0) {
|
---|
| 94 | return;
|
---|
| 95 | }
|
---|
| 96 |
|
---|
[454] | 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)
|
---|
[745] | 101 | #else
|
---|
| 102 | if (fork()) {
|
---|
| 103 | return;
|
---|
| 104 | }
|
---|
| 105 |
|
---|
| 106 | if (asprintf(&binfile, "%s/winbindd", get_dyn_SBINDIR()) > 0) {
|
---|
| 107 | become_daemon(true, false, false);
|
---|
| 108 | execl(binfile, binfile, NULL);
|
---|
| 109 | }
|
---|
[454] | 110 | exit(0);
|
---|
[745] | 111 | #endif
|
---|
| 112 | }
|
---|
[454] | 113 |
|
---|
[745] | 114 |
|
---|
| 115 | /* stop smbd */
|
---|
| 116 | void stop_smbd(void)
|
---|
| 117 | {
|
---|
| 118 | pid_t pid = pidfile_pid("smbd");
|
---|
| 119 |
|
---|
| 120 | if (geteuid() != 0) return;
|
---|
| 121 |
|
---|
[454] | 122 | #ifdef __OS2__ /* we do it a bit nicer */
|
---|
| 123 | if (smbd_running()) {
|
---|
| 124 | char *binfile = NULL;
|
---|
| 125 | SWAT_HELPER(stop, smbd)
|
---|
| 126 | }
|
---|
[745] | 127 | #else
|
---|
| 128 | if (pid <= 0) return;
|
---|
| 129 |
|
---|
[454] | 130 | kill(pid, SIGTERM);
|
---|
[745] | 131 | #endif
|
---|
| 132 | }
|
---|
[454] | 133 |
|
---|
[745] | 134 | /* stop nmbd */
|
---|
| 135 | void stop_nmbd(void)
|
---|
| 136 | {
|
---|
| 137 | pid_t pid = pidfile_pid("nmbd");
|
---|
| 138 |
|
---|
| 139 | if (geteuid() != 0) return;
|
---|
| 140 |
|
---|
[454] | 141 | #ifdef __OS2__ /* we do it a bit nicer */
|
---|
| 142 | if (nmbd_running()) {
|
---|
| 143 | char *binfile = NULL;
|
---|
| 144 | SWAT_HELPER(stop, nmbd)
|
---|
| 145 | }
|
---|
[745] | 146 | #else
|
---|
| 147 | if (pid <= 0) return;
|
---|
| 148 |
|
---|
[454] | 149 | kill(pid, SIGTERM);
|
---|
[745] | 150 | #endif
|
---|
| 151 | }
|
---|
| 152 | #ifdef WITH_WINBIND
|
---|
| 153 | /* stop winbindd */
|
---|
| 154 | void stop_winbindd(void)
|
---|
| 155 | {
|
---|
| 156 | pid_t pid = pidfile_pid("winbindd");
|
---|
[454] | 157 |
|
---|
[745] | 158 | if (geteuid() != 0) return;
|
---|
| 159 |
|
---|
[454] | 160 | #ifdef __OS2__ /* we do it a bit nicer */
|
---|
| 161 | if (winbindd_running()) {
|
---|
| 162 | char *binfile = NULL;
|
---|
| 163 | SWAT_HELPER(stop, winbindd)
|
---|
| 164 | }
|
---|
[745] | 165 | #else
|
---|
| 166 | if (pid <= 0) return;
|
---|
| 167 |
|
---|
[454] | 168 | kill(pid, SIGTERM);
|
---|
[745] | 169 | #endif
|
---|
| 170 | }
|
---|
| 171 | #endif
|
---|
| 172 | /* kill a specified process */
|
---|
| 173 | void 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 | }
|
---|