From d360320618fe3a7f53ac1f05ee3ac54323a03c82 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 15 Mar 1998 02:37:52 +0000 Subject: - added the ability to kill off individual connections from SWAT (from the status page) - split the claim_connection() code into its own file - fixed the claim_connection() code to lock the file when manipulating it - always claim a null connection at startup - fixed a bug in the pidfile code (This used to be commit abd4a17e21d12be3d1747e94ceb1915abaf135e3) --- source3/web/startstop.c | 11 +++ source3/web/statuspage.c | 194 +++++++++++++++++++++++++++++++++++++++++++++++ source3/web/swat.c | 137 --------------------------------- 3 files changed, 205 insertions(+), 137 deletions(-) create mode 100644 source3/web/statuspage.c (limited to 'source3/web') diff --git a/source3/web/startstop.c b/source3/web/startstop.c index 19781cc220..e60b13ae66 100644 --- a/source3/web/startstop.c +++ b/source3/web/startstop.c @@ -91,3 +91,14 @@ void stop_nmbd(void) kill(pid, SIGTERM); } + +/* kill a specified process */ +void kill_pid(int pid) +{ + if (geteuid() != 0) return; + + if (pid <= 0) return; + + kill(pid, SIGTERM); + sleep(SLEEP_TIME); +} diff --git a/source3/web/statuspage.c b/source3/web/statuspage.c new file mode 100644 index 0000000000..3a95d99d37 --- /dev/null +++ b/source3/web/statuspage.c @@ -0,0 +1,194 @@ +/* + Unix SMB/Netbios implementation. + Version 1.9. + web status page + Copyright (C) Andrew Tridgell 1997-1998 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" + + +static void print_share_mode(share_mode_entry *e, char *fname) +{ + printf("%d",e->pid); + printf(""); + switch ((e->share_mode>>4)&0xF) { + case DENY_NONE: printf("DENY_NONE"); break; + case DENY_ALL: printf("DENY_ALL "); break; + case DENY_DOS: printf("DENY_DOS "); break; + case DENY_READ: printf("DENY_READ "); break; + case DENY_WRITE:printf("DENY_WRITE "); break; + } + printf(""); + + printf(""); + switch (e->share_mode&0xF) { + case 0: printf("RDONLY "); break; + case 1: printf("WRONLY "); break; + case 2: printf("RDWR "); break; + } + printf(""); + + printf(""); + if((e->op_type & + (EXCLUSIVE_OPLOCK|BATCH_OPLOCK)) == + (EXCLUSIVE_OPLOCK|BATCH_OPLOCK)) + printf("EXCLUSIVE+BATCH "); + else if (e->op_type & EXCLUSIVE_OPLOCK) + printf("EXCLUSIVE "); + else if (e->op_type & BATCH_OPLOCK) + printf("BATCH "); + else + printf("NONE "); + printf(""); + + printf("%s%s\n", + fname,asctime(LocalTime((time_t *)&e->time.tv_sec))); +} + + +/* show the current server status */ +void status_page(void) +{ + struct connect_record crec; + pstring fname; + FILE *f; + int i, pid; + char *v; + + if (cgi_variable("smbd_start")) { + start_smbd(); + } + + if (cgi_variable("smbd_stop")) { + stop_smbd(); + } + + if (cgi_variable("nmbd_start")) { + start_nmbd(); + } + + if (cgi_variable("nmbd_stop")) { + stop_nmbd(); + } + + for (i=0;cgi_vnum(i, &v); i++) { + if (strncmp(v, "kill_", 5) != 0) continue; + pid = atoi(v+5); + if (pid > 0) { + printf("killing %d
\n", pid); + kill_pid(pid); + } + } + + + printf("

Server Status

\n"); + + printf("
\n"); + + pstrcpy(fname,lp_lockdir()); + standard_sub_basic(fname); + trim_string(fname,"","/"); + strcat(fname,"/STATUS..LCK"); + + f = fopen(fname,"r"); + if (!f) { + printf("Couldn't open status file %s\n",fname); + if (!lp_status(-1)) + printf("You need to have status=yes in your smb config file\n"); + return; + } + + + printf("\n"); + + printf("",VERSION); + + fflush(stdout); + if (smbd_running()) { + printf("\n"); + } else { + printf("\n"); + } + + fflush(stdout); + if (nmbd_running()) { + printf("\n"); + } else { + printf("\n"); + } + + printf("
version:%s
smbd:running
smbd:not running
nmbd:running
nmbd:not running
\n"); + fflush(stdout); + + + if (geteuid() != 0) + printf("NOTE: You are not logged in as root and won't be able to start/stop the server

\n"); + + printf("

Active Connections

\n"); + printf("\n"); + printf("\n"); + + while (!feof(f)) { + if (fread(&crec,sizeof(crec),1,f) != 1) + break; + if (crec.magic == 0x280267 && process_exists(crec.pid)) { + printf("\n", + crec.pid, + crec.machine,crec.addr, + asctime(LocalTime(&crec.start)), + crec.pid); + } + } + + printf("
PIDClientIP addressDateKill
%d%s%s%s

\n"); + + fseek(f, 0, SEEK_SET); + + printf("

Active Shares

\n"); + printf("\n"); + printf("\n\n"); + + while (!feof(f)) { + if (fread(&crec,sizeof(crec),1,f) != 1) + break; + if (crec.cnum == -1) continue; + if (crec.magic == 0x280267 && process_exists(crec.pid)) { + printf("\n", + crec.name,uidtoname(crec.uid), + gidtoname(crec.gid),crec.pid, + crec.machine, + asctime(LocalTime(&crec.start))); + } + } + + printf("
ShareUserGroupPIDClientDate
%s%s%s%d%s%s

\n"); + + printf("

Open Files

\n"); + printf("\n"); + printf("\n"); + + locking_init(1); + share_mode_forall(print_share_mode); + locking_end(); + printf("
PIDSharingR/WOplockFileDate
\n"); + + fclose(f); + + printf("
\n"); +} + diff --git a/source3/web/swat.c b/source3/web/swat.c index d9f890ce13..1a12d99ffd 100644 --- a/source3/web/swat.c +++ b/source3/web/swat.c @@ -491,143 +491,6 @@ static void printers_page(void) } -static void print_share_mode(share_mode_entry *e, char *fname) -{ - printf("%d",e->pid); - printf(""); - switch ((e->share_mode>>4)&0xF) { - case DENY_NONE: printf("DENY_NONE"); break; - case DENY_ALL: printf("DENY_ALL "); break; - case DENY_DOS: printf("DENY_DOS "); break; - case DENY_READ: printf("DENY_READ "); break; - case DENY_WRITE:printf("DENY_WRITE "); break; - } - printf(""); - - printf(""); - switch (e->share_mode&0xF) { - case 0: printf("RDONLY "); break; - case 1: printf("WRONLY "); break; - case 2: printf("RDWR "); break; - } - printf(""); - - printf(""); - if((e->op_type & - (EXCLUSIVE_OPLOCK|BATCH_OPLOCK)) == - (EXCLUSIVE_OPLOCK|BATCH_OPLOCK)) - printf("EXCLUSIVE+BATCH "); - else if (e->op_type & EXCLUSIVE_OPLOCK) - printf("EXCLUSIVE "); - else if (e->op_type & BATCH_OPLOCK) - printf("BATCH "); - else - printf("NONE "); - printf(""); - - printf("%s%s\n", - fname,asctime(LocalTime((time_t *)&e->time.tv_sec))); -} - - -/* show the current server status */ -static void status_page(void) -{ - struct connect_record crec; - pstring fname; - FILE *f; - - if (cgi_variable("smbd_start")) { - start_smbd(); - } - - if (cgi_variable("smbd_stop")) { - stop_smbd(); - } - - if (cgi_variable("nmbd_start")) { - start_nmbd(); - } - - if (cgi_variable("nmbd_stop")) { - stop_nmbd(); - } - - printf("

Server Status

\n"); - - printf("
\n"); - - pstrcpy(fname,lp_lockdir()); - standard_sub_basic(fname); - trim_string(fname,"","/"); - strcat(fname,"/STATUS..LCK"); - - f = fopen(fname,"r"); - if (!f) { - printf("Couldn't open status file %s\n",fname); - if (!lp_status(-1)) - printf("You need to have status=yes in your smb config file\n"); - return; - } - - - printf("\n"); - - printf("",VERSION); - - fflush(stdout); - if (smbd_running()) { - printf("\n"); - } else { - printf("\n"); - } - - fflush(stdout); - if (nmbd_running()) { - printf("\n"); - } else { - printf("\n"); - } - - printf("
version:%s
smbd:running
smbd:not running
nmbd:running
nmbd:not running
\n"); - fflush(stdout); - - - if (geteuid() != 0) - printf("NOTE: You are not logged in as root and won't be able to start/stop the server

\n"); - - printf("

Active Connections

\n"); - printf("\n"); - printf("\n\n"); - - while (!feof(f)) { - if (fread(&crec,sizeof(crec),1,f) != 1) - break; - if (crec.magic == 0x280267 && process_exists(crec.pid)) { - printf("\n", - crec.name,uidtoname(crec.uid), - gidtoname(crec.gid),crec.pid, - crec.machine,crec.addr, - asctime(LocalTime(&crec.start))); - } - } - - printf("
ShareUserGroupPIDClientDate
%s%s%s%d%s (%s)%s

\n"); - - printf("

Open Files

\n"); - printf("\n"); - printf("\n"); - - locking_init(1); - share_mode_forall(print_share_mode); - locking_end(); - printf("
PIDSharingR/WOplockFileDate
\n"); - - fclose(f); - - printf("
\n"); -} - int main(int argc, char *argv[]) { -- cgit