[246] | 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) \
|
---|
[289] | 27 | asprintf(&binfile, "%s/swathelp.cmd", getcwd(NULL, _MAX_PATH)); \
|
---|
[246] | 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. */
|
---|
| 37 | void start_smbd(void)
|
---|
| 38 | {
|
---|
| 39 | char *binfile = NULL;
|
---|
| 40 |
|
---|
| 41 | if (geteuid() != 0) {
|
---|
| 42 | return;
|
---|
| 43 | }
|
---|
| 44 | #ifdef __OS2__
|
---|
| 45 | /* fork() in klibc on OS/2 ends all children when parent
|
---|
| 46 | is closed, therefore we use spawn() */
|
---|
| 47 | SWAT_HELPER(start, smbd)
|
---|
| 48 | #else
|
---|
| 49 | if (fork()) {
|
---|
| 50 | return;
|
---|
| 51 | }
|
---|
| 52 |
|
---|
| 53 | if (asprintf(&binfile, "%s/smbd", get_dyn_SBINDIR()) > 0) {
|
---|
| 54 | become_daemon(true, false);
|
---|
| 55 | execl(binfile, binfile, "-D", NULL);
|
---|
| 56 | }
|
---|
| 57 | exit(0);
|
---|
| 58 | #endif
|
---|
| 59 | }
|
---|
| 60 |
|
---|
| 61 | /* startup nmbd */
|
---|
| 62 | void start_nmbd(void)
|
---|
| 63 | {
|
---|
| 64 | char *binfile = NULL;
|
---|
| 65 |
|
---|
| 66 | if (geteuid() != 0) {
|
---|
| 67 | return;
|
---|
| 68 | }
|
---|
| 69 | #ifdef __OS2__
|
---|
| 70 | /* fork() in klibc on OS/2 ends all children when parent
|
---|
| 71 | is closed, therefore we use spawn() */
|
---|
| 72 | SWAT_HELPER(start, nmbd)
|
---|
| 73 | #else
|
---|
| 74 | if (fork()) {
|
---|
| 75 | return;
|
---|
| 76 | }
|
---|
| 77 |
|
---|
| 78 | if (asprintf(&binfile, "%s/nmbd", get_dyn_SBINDIR()) > 0) {
|
---|
| 79 | become_daemon(true, false);
|
---|
| 80 | execl(binfile, binfile, "-D", NULL);
|
---|
| 81 | }
|
---|
| 82 | exit(0);
|
---|
| 83 | #endif
|
---|
| 84 | }
|
---|
| 85 |
|
---|
| 86 | /** Startup winbindd from web interface. */
|
---|
| 87 | void start_winbindd(void)
|
---|
| 88 | {
|
---|
| 89 | char *binfile = NULL;
|
---|
| 90 |
|
---|
| 91 | if (geteuid() != 0) {
|
---|
| 92 | return;
|
---|
| 93 | }
|
---|
| 94 | #ifdef __OS2__
|
---|
| 95 | /* fork() in klibc on OS/2 ends all children when parent
|
---|
| 96 | is closed, therefore we use spawn() */
|
---|
| 97 | SWAT_HELPER(start, winbindd)
|
---|
| 98 | #else
|
---|
| 99 | if (fork()) {
|
---|
| 100 | return;
|
---|
| 101 | }
|
---|
| 102 |
|
---|
| 103 | if (asprintf(&binfile, "%s/winbindd", get_dyn_SBINDIR()) > 0) {
|
---|
| 104 | become_daemon(true, false);
|
---|
| 105 | execl(binfile, binfile, NULL);
|
---|
| 106 | }
|
---|
| 107 | exit(0);
|
---|
| 108 | #endif
|
---|
| 109 | }
|
---|
| 110 |
|
---|
| 111 |
|
---|
| 112 | /* stop smbd */
|
---|
| 113 | void stop_smbd(void)
|
---|
| 114 | {
|
---|
| 115 | pid_t pid = pidfile_pid("smbd");
|
---|
| 116 | if (geteuid() != 0) return;
|
---|
| 117 |
|
---|
| 118 | #ifdef __OS2__ /* we do it a bit nicer */
|
---|
| 119 | if (smbd_running()) {
|
---|
| 120 | char *binfile = NULL;
|
---|
| 121 | SWAT_HELPER(stop, smbd)
|
---|
| 122 | }
|
---|
| 123 | #else
|
---|
| 124 | if (pid <= 0) return;
|
---|
| 125 |
|
---|
| 126 | kill(pid, SIGTERM);
|
---|
| 127 | #endif
|
---|
| 128 | }
|
---|
| 129 | /* stop nmbd */
|
---|
| 130 | void stop_nmbd(void)
|
---|
| 131 | {
|
---|
| 132 | pid_t pid = pidfile_pid("nmbd");
|
---|
| 133 | if (geteuid() != 0) return;
|
---|
| 134 |
|
---|
| 135 | #ifdef __OS2__ /* we do it a bit nicer */
|
---|
| 136 | if (nmbd_running()) {
|
---|
| 137 | char *binfile = NULL;
|
---|
| 138 | SWAT_HELPER(stop, nmbd)
|
---|
| 139 | }
|
---|
| 140 | #else
|
---|
| 141 | if (pid <= 0) return;
|
---|
| 142 |
|
---|
| 143 | kill(pid, SIGTERM);
|
---|
| 144 | #endif
|
---|
| 145 | }
|
---|
| 146 |
|
---|
| 147 | #ifdef WITH_WINBIND
|
---|
| 148 | /* stop winbindd */
|
---|
| 149 | void stop_winbindd(void)
|
---|
| 150 | {
|
---|
| 151 | pid_t pid = pidfile_pid("winbindd");
|
---|
| 152 |
|
---|
| 153 | if (geteuid() != 0) return;
|
---|
| 154 |
|
---|
| 155 | #ifdef __OS2__ /* we do it a bit nicer */
|
---|
| 156 | if (winbindd_running()) {
|
---|
| 157 | char *binfile = NULL;
|
---|
| 158 | SWAT_HELPER(stop, winbindd)
|
---|
| 159 | }
|
---|
| 160 | #else
|
---|
| 161 | if (pid <= 0) return;
|
---|
| 162 |
|
---|
| 163 | kill(pid, SIGTERM);
|
---|
| 164 | #endif
|
---|
| 165 | }
|
---|
| 166 | #endif
|
---|
| 167 | /* kill a specified process */
|
---|
| 168 | void kill_pid(struct server_id pid)
|
---|
| 169 | {
|
---|
| 170 | if (geteuid() != 0) return;
|
---|
| 171 |
|
---|
| 172 | if (procid_to_pid(&pid) <= 0) return;
|
---|
| 173 |
|
---|
| 174 | kill(procid_to_pid(&pid), SIGTERM);
|
---|
| 175 | }
|
---|