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