summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>1998-03-15 02:37:52 +0000
committerAndrew Tridgell <tridge@samba.org>1998-03-15 02:37:52 +0000
commitd360320618fe3a7f53ac1f05ee3ac54323a03c82 (patch)
tree97120a8949d82c8e9aab435bb56f6f0301beed28
parent69bb6f6f5fa472d2bf5c619a09aecc3b0ce4c254 (diff)
downloadsamba-d360320618fe3a7f53ac1f05ee3ac54323a03c82.tar.gz
samba-d360320618fe3a7f53ac1f05ee3ac54323a03c82.tar.bz2
samba-d360320618fe3a7f53ac1f05ee3ac54323a03c82.zip
- 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)
-rw-r--r--source3/lib/pidfile.c12
-rw-r--r--source3/smbd/connection.c221
-rw-r--r--source3/smbd/server.c186
-rw-r--r--source3/utils/status.c1
-rw-r--r--source3/web/startstop.c11
-rw-r--r--source3/web/statuspage.c194
-rw-r--r--source3/web/swat.c137
7 files changed, 442 insertions, 320 deletions
diff --git a/source3/lib/pidfile.c b/source3/lib/pidfile.c
index 8dee7421de..6cad1436eb 100644
--- a/source3/lib/pidfile.c
+++ b/source3/lib/pidfile.c
@@ -35,10 +35,17 @@ void pidfile_create(char *name)
int fd;
char buf[20];
pstring pidFile;
+ int pid;
sprintf(pidFile, "%s/%s.pid", lp_lockdir(), name);
- fd = open(pidFile, O_NONBLOCK | O_CREAT | O_WRONLY | O_TRUNC, 0644);
+ pid = pidfile_pid(name);
+ if (pid > 0 && process_exists(pid)) {
+ DEBUG(0,("ERROR: %s is already running\n", name));
+ exit(1);
+ }
+
+ fd = open(pidFile, O_NONBLOCK | O_CREAT | O_WRONLY, 0644);
if (fd < 0) {
DEBUG(0,("ERROR: can't open %s: %s\n", pidFile,
strerror(errno)));
@@ -50,8 +57,9 @@ void pidfile_create(char *name)
exit(1);
}
+ memset(buf, 0, sizeof(buf));
sprintf(buf, "%u\n", (unsigned int) getpid());
- if (write(fd, buf, strlen(buf)) < 0) {
+ if (write(fd, buf, sizeof(buf)) != sizeof(buf)) {
DEBUG(0,("ERROR: can't write to %s: %s\n",
pidFile, strerror(errno)));
exit(1);
diff --git a/source3/smbd/connection.c b/source3/smbd/connection.c
new file mode 100644
index 0000000000..610afbc3e5
--- /dev/null
+++ b/source3/smbd/connection.c
@@ -0,0 +1,221 @@
+/*
+ Unix SMB/Netbios implementation.
+ Version 1.9.
+ connection claim routines
+ Copyright (C) Andrew Tridgell 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"
+
+
+extern connection_struct Connections[MAX_CONNECTIONS];
+extern fstring remote_machine;
+
+extern int DEBUGLEVEL;
+
+/****************************************************************************
+simple routines to do connection counting
+****************************************************************************/
+BOOL yield_connection(int cnum,char *name,int max_connections)
+{
+ struct connect_record crec;
+ pstring fname;
+ int fd;
+ int mypid = getpid();
+ int i;
+
+ DEBUG(3,("Yielding connection to %d %s\n",cnum,name));
+
+ if (max_connections <= 0)
+ return(True);
+
+ bzero(&crec,sizeof(crec));
+
+ pstrcpy(fname,lp_lockdir());
+ trim_string(fname,"","/");
+
+ strcat(fname,"/");
+ strcat(fname,name);
+ strcat(fname,".LCK");
+
+ fd = open(fname,O_RDWR);
+ if (fd == -1) {
+ DEBUG(2,("Couldn't open lock file %s (%s)\n",fname,strerror(errno)));
+ return(False);
+ }
+
+ if (fcntl_lock(fd,F_SETLKW,0,1,F_WRLCK)==False) {
+ DEBUG(0,("ERROR: can't get lock on %s\n", fname));
+ return False;
+ }
+
+ /* find the right spot */
+ for (i=0;i<max_connections;i++) {
+ if (read(fd, &crec,sizeof(crec)) != sizeof(crec)) {
+ DEBUG(2,("Entry not found in lock file %s\n",fname));
+ if (fcntl_lock(fd,F_SETLKW,0,1,F_UNLCK)==False) {
+ DEBUG(0,("ERROR: can't release lock on %s\n", fname));
+ }
+ close(fd);
+ return(False);
+ }
+ if (crec.pid == mypid && crec.cnum == cnum)
+ break;
+ }
+
+ if (crec.pid != mypid || crec.cnum != cnum) {
+ if (fcntl_lock(fd,F_SETLKW,0,1,F_UNLCK)==False) {
+ DEBUG(0,("ERROR: can't release lock on %s\n", fname));
+ }
+ close(fd);
+ DEBUG(2,("Entry not found in lock file %s\n",fname));
+ return(False);
+ }
+
+ bzero((void *)&crec,sizeof(crec));
+
+ /* remove our mark */
+ if (lseek(fd,i*sizeof(crec),SEEK_SET) != i*sizeof(crec) ||
+ write(fd, &crec,sizeof(crec)) != sizeof(crec)) {
+ DEBUG(2,("Couldn't update lock file %s (%s)\n",fname,strerror(errno)));
+ if (fcntl_lock(fd,F_SETLKW,0,1,F_UNLCK)==False) {
+ DEBUG(0,("ERROR: can't release lock on %s\n", fname));
+ }
+ close(fd);
+ return(False);
+ }
+
+ if (fcntl_lock(fd,F_SETLKW,0,1,F_UNLCK)==False) {
+ DEBUG(0,("ERROR: can't release lock on %s\n", fname));
+ }
+
+ DEBUG(3,("Yield successful\n"));
+
+ close(fd);
+ return(True);
+}
+
+
+/****************************************************************************
+simple routines to do connection counting
+****************************************************************************/
+BOOL claim_connection(int cnum,char *name,int max_connections,BOOL Clear)
+{
+ struct connect_record crec;
+ pstring fname;
+ int fd=-1;
+ int i,foundi= -1;
+ int total_recs;
+
+ if (max_connections <= 0)
+ return(True);
+
+ DEBUG(5,("trying claim %s %s %d\n",lp_lockdir(),name,max_connections));
+
+ pstrcpy(fname,lp_lockdir());
+ trim_string(fname,"","/");
+
+ if (!directory_exist(fname,NULL))
+ mkdir(fname,0755);
+
+ strcat(fname,"/");
+ strcat(fname,name);
+ strcat(fname,".LCK");
+
+ if (!file_exist(fname,NULL)) {
+ fd = open(fname,O_RDWR|O_CREAT|O_EXCL, 0644);
+ }
+
+ if (fd == -1) {
+ fd = open(fname,O_RDWR);
+ }
+
+ if (fd == -1) {
+ DEBUG(1,("couldn't open lock file %s\n",fname));
+ return(False);
+ }
+
+ if (fcntl_lock(fd,F_SETLKW,0,1,F_WRLCK)==False) {
+ DEBUG(0,("ERROR: can't get lock on %s\n", fname));
+ return False;
+ }
+
+ total_recs = file_size(fname) / sizeof(crec);
+
+ /* find a free spot */
+ for (i=0;i<max_connections;i++) {
+ if (i>=total_recs ||
+ lseek(fd,i*sizeof(crec),SEEK_SET) != i*sizeof(crec) ||
+ read(fd,&crec,sizeof(crec)) != sizeof(crec)) {
+ if (foundi < 0) foundi = i;
+ break;
+ }
+
+ if (Clear && crec.pid && !process_exists(crec.pid)) {
+ lseek(fd,i*sizeof(crec),SEEK_SET);
+ bzero((void *)&crec,sizeof(crec));
+ write(fd, &crec,sizeof(crec));
+ if (foundi < 0) foundi = i;
+ continue;
+ }
+ if (foundi < 0 && (!crec.pid || !process_exists(crec.pid))) {
+ foundi=i;
+ if (!Clear) break;
+ }
+ }
+
+ if (foundi < 0) {
+ DEBUG(3,("no free locks in %s\n",fname));
+ if (fcntl_lock(fd,F_SETLKW,0,1,F_UNLCK)==False) {
+ DEBUG(0,("ERROR: can't release lock on %s\n", fname));
+ }
+ close(fd);
+ return(False);
+ }
+
+ /* fill in the crec */
+ bzero((void *)&crec,sizeof(crec));
+ crec.magic = 0x280267;
+ crec.pid = getpid();
+ crec.cnum = cnum;
+ if (cnum != -1) {
+ crec.uid = Connections[cnum].uid;
+ crec.gid = Connections[cnum].gid;
+ StrnCpy(crec.name,lp_servicename(SNUM(cnum)),sizeof(crec.name)-1);
+ }
+ crec.start = time(NULL);
+
+ StrnCpy(crec.machine,remote_machine,sizeof(crec.machine)-1);
+ StrnCpy(crec.addr,client_addr(),sizeof(crec.addr)-1);
+
+ /* make our mark */
+ if (lseek(fd,foundi*sizeof(crec),SEEK_SET) != foundi*sizeof(crec) ||
+ write(fd, &crec,sizeof(crec)) != sizeof(crec)) {
+ if (fcntl_lock(fd,F_SETLKW,0,1,F_UNLCK)==False) {
+ DEBUG(0,("ERROR: can't release lock on %s\n", fname));
+ }
+ close(fd);
+ return(False);
+ }
+
+ if (fcntl_lock(fd,F_SETLKW,0,1,F_UNLCK)==False) {
+ DEBUG(0,("ERROR: can't release lock on %s\n", fname));
+ }
+
+ close(fd);
+ return(True);
+}
diff --git a/source3/smbd/server.c b/source3/smbd/server.c
index ca4a95f59d..64b293336b 100644
--- a/source3/smbd/server.c
+++ b/source3/smbd/server.c
@@ -3312,7 +3312,6 @@ int make_connection(char *service,char *user,char *password, int pwlen, char *de
connection_struct *pcon;
BOOL guest = False;
BOOL force = False;
- static BOOL first_connection = True;
strlower(service);
@@ -3518,9 +3517,7 @@ int make_connection(char *service,char *user,char *password, int pwlen, char *de
}
if (lp_status(SNUM(cnum)))
- claim_connection(cnum,"STATUS.",MAXSTATUS,first_connection);
-
- first_connection = False;
+ claim_connection(cnum,"STATUS.",MAXSTATUS,False);
} /* IS_IPC */
pcon->open = True;
@@ -4213,183 +4210,6 @@ void close_cnum(int cnum, uint16 vuid)
}
-/****************************************************************************
-simple routines to do connection counting
-****************************************************************************/
-BOOL yield_connection(int cnum,char *name,int max_connections)
-{
- struct connect_record crec;
- pstring fname;
- FILE *f;
- int mypid = getpid();
- int i;
-
- DEBUG(3,("Yielding connection to %d %s\n",cnum,name));
-
- if (max_connections <= 0)
- return(True);
-
- bzero(&crec,sizeof(crec));
-
- pstrcpy(fname,lp_lockdir());
- standard_sub(cnum,fname);
- trim_string(fname,"","/");
-
- strcat(fname,"/");
- strcat(fname,name);
- strcat(fname,".LCK");
-
- f = fopen(fname,"r+");
- if (!f)
- {
- DEBUG(2,("Couldn't open lock file %s (%s)\n",fname,strerror(errno)));
- return(False);
- }
-
- fseek(f,0,SEEK_SET);
-
- /* find a free spot */
- for (i=0;i<max_connections;i++)
- {
- if (fread(&crec,sizeof(crec),1,f) != 1)
- {
- DEBUG(2,("Entry not found in lock file %s\n",fname));
- fclose(f);
- return(False);
- }
- if (crec.pid == mypid && crec.cnum == cnum)
- break;
- }
-
- if (crec.pid != mypid || crec.cnum != cnum)
- {
- fclose(f);
- DEBUG(2,("Entry not found in lock file %s\n",fname));
- return(False);
- }
-
- bzero((void *)&crec,sizeof(crec));
-
- /* remove our mark */
- if (fseek(f,i*sizeof(crec),SEEK_SET) != 0 ||
- fwrite(&crec,sizeof(crec),1,f) != 1)
- {
- DEBUG(2,("Couldn't update lock file %s (%s)\n",fname,strerror(errno)));
- fclose(f);
- return(False);
- }
-
- DEBUG(3,("Yield successful\n"));
-
- fclose(f);
- return(True);
-}
-
-
-/****************************************************************************
-simple routines to do connection counting
-****************************************************************************/
-BOOL claim_connection(int cnum,char *name,int max_connections,BOOL Clear)
-{
- struct connect_record crec;
- pstring fname;
- FILE *f;
- int snum = SNUM(cnum);
- int i,foundi= -1;
- int total_recs;
-
- if (max_connections <= 0)
- return(True);
-
- DEBUG(5,("trying claim %s %s %d\n",lp_lockdir(),name,max_connections));
-
- pstrcpy(fname,lp_lockdir());
- standard_sub(cnum,fname);
- trim_string(fname,"","/");
-
- if (!directory_exist(fname,NULL))
- mkdir(fname,0755);
-
- strcat(fname,"/");
- strcat(fname,name);
- strcat(fname,".LCK");
-
- if (!file_exist(fname,NULL))
- {
- int oldmask = umask(022);
- f = fopen(fname,"w");
- if (f) fclose(f);
- umask(oldmask);
- }
-
- total_recs = file_size(fname) / sizeof(crec);
-
- f = fopen(fname,"r+");
-
- if (!f)
- {
- DEBUG(1,("couldn't open lock file %s\n",fname));
- return(False);
- }
-
- /* find a free spot */
- for (i=0;i<max_connections;i++)
- {
-
- if (i>=total_recs ||
- fseek(f,i*sizeof(crec),SEEK_SET) != 0 ||
- fread(&crec,sizeof(crec),1,f) != 1)
- {
- if (foundi < 0) foundi = i;
- break;
- }
-
- if (Clear && crec.pid && !process_exists(crec.pid))
- {
- fseek(f,i*sizeof(crec),SEEK_SET);
- bzero((void *)&crec,sizeof(crec));
- fwrite(&crec,sizeof(crec),1,f);
- if (foundi < 0) foundi = i;
- continue;
- }
- if (foundi < 0 && (!crec.pid || !process_exists(crec.pid)))
- {
- foundi=i;
- if (!Clear) break;
- }
- }
-
- if (foundi < 0)
- {
- DEBUG(3,("no free locks in %s\n",fname));
- fclose(f);
- return(False);
- }
-
- /* fill in the crec */
- bzero((void *)&crec,sizeof(crec));
- crec.magic = 0x280267;
- crec.pid = getpid();
- crec.cnum = cnum;
- crec.uid = Connections[cnum].uid;
- crec.gid = Connections[cnum].gid;
- StrnCpy(crec.name,lp_servicename(snum),sizeof(crec.name)-1);
- crec.start = time(NULL);
-
- StrnCpy(crec.machine,remote_machine,sizeof(crec.machine)-1);
- StrnCpy(crec.addr,client_addr(),sizeof(crec.addr)-1);
-
- /* make our mark */
- if (fseek(f,foundi*sizeof(crec),SEEK_SET) != 0 ||
- fwrite(&crec,sizeof(crec),1,f) != 1)
- {
- fclose(f);
- return(False);
- }
-
- fclose(f);
- return(True);
-}
#if DUMP_CORE
/*******************************************************************
@@ -5347,6 +5167,10 @@ static void usage(char *pname)
if(!open_oplock_ipc())
exit(1);
+ if (lp_status(-1)) {
+ claim_connection(-1,"STATUS.",MAXSTATUS,True);
+ }
+
process();
close_sockets();
diff --git a/source3/utils/status.c b/source3/utils/status.c
index 7c89ad6d63..f99fe9e561 100644
--- a/source3/utils/status.c
+++ b/source3/utils/status.c
@@ -199,6 +199,7 @@ static void print_share_mode(share_mode_entry *e, char *fname)
{
if (fread(&crec,sizeof(crec),1,f) != 1)
break;
+ if (crec.cnum == -1) continue;
if ( crec.magic == 0x280267 && process_exists(crec.pid)
&& Ucrit_checkUsername(uidtoname(crec.uid)) /* added by OH */
)
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("<tr><td>%d</td>",e->pid);
+ printf("<td>");
+ 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("</td>");
+
+ printf("<td>");
+ switch (e->share_mode&0xF) {
+ case 0: printf("RDONLY "); break;
+ case 1: printf("WRONLY "); break;
+ case 2: printf("RDWR "); break;
+ }
+ printf("</td>");
+
+ printf("<td>");
+ 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("</td>");
+
+ printf("<td>%s</td><td>%s</td></tr>\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<br>\n", pid);
+ kill_pid(pid);
+ }
+ }
+
+
+ printf("<H2>Server Status</H2>\n");
+
+ printf("<FORM method=post>\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("<table>\n");
+
+ printf("<tr><td>version:</td><td>%s</td></tr>",VERSION);
+
+ fflush(stdout);
+ if (smbd_running()) {
+ printf("<tr><td>smbd:</td><td>running</td><td><input type=submit name=\"smbd_stop\" value=\"Stop smbd\"></td></tr>\n");
+ } else {
+ printf("<tr><td>smbd:</td><td>not running</td><td><input type=submit name=\"smbd_start\" value=\"Start smbd\"></td></tr>\n");
+ }
+
+ fflush(stdout);
+ if (nmbd_running()) {
+ printf("<tr><td>nmbd:</td><td>running</td><td><input type=submit name=\"nmbd_stop\" value=\"Stop nmbd\"></td></tr>\n");
+ } else {
+ printf("<tr><td>nmbd:</td><td>not running</td><td><input type=submit name=\"nmbd_start\" value=\"Start nmbd\"></td></tr>\n");
+ }
+
+ printf("</table>\n");
+ fflush(stdout);
+
+
+ if (geteuid() != 0)
+ printf("<b>NOTE: You are not logged in as root and won't be able to start/stop the server</b><p>\n");
+
+ printf("<p><h3>Active Connections</h3>\n");
+ printf("<table border=1>\n");
+ printf("<tr><th>PID</th><th>Client</th><th>IP address</th><th>Date</th><th>Kill</th></tr>\n");
+
+ while (!feof(f)) {
+ if (fread(&crec,sizeof(crec),1,f) != 1)
+ break;
+ if (crec.magic == 0x280267 && process_exists(crec.pid)) {
+ printf("<tr><td>%d</td><td>%s</td><td>%s</td><td>%s</td><td><input type=submit value=\"X\" name=\"kill_%d\"></td></tr>\n",
+ crec.pid,
+ crec.machine,crec.addr,
+ asctime(LocalTime(&crec.start)),
+ crec.pid);
+ }
+ }
+
+ printf("</table><p>\n");
+
+ fseek(f, 0, SEEK_SET);
+
+ printf("<p><h3>Active Shares</h3>\n");
+ printf("<table border=1>\n");
+ printf("<tr><th>Share</th><th>User</th><th>Group</th><th>PID</th><th>Client</th><th>Date</th></tr>\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("<tr><td>%s</td><td>%s</td><td>%s</td><td>%d</td><td>%s</td><td>%s</td></tr>\n",
+ crec.name,uidtoname(crec.uid),
+ gidtoname(crec.gid),crec.pid,
+ crec.machine,
+ asctime(LocalTime(&crec.start)));
+ }
+ }
+
+ printf("</table><p>\n");
+
+ printf("<h3>Open Files</h3>\n");
+ printf("<table border=1>\n");
+ printf("<tr><th>PID</th><th>Sharing</th><th>R/W</th><th>Oplock</th><th>File</th><th>Date</th></tr>\n");
+
+ locking_init(1);
+ share_mode_forall(print_share_mode);
+ locking_end();
+ printf("</table>\n");
+
+ fclose(f);
+
+ printf("</FORM>\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("<tr><td>%d</td>",e->pid);
- printf("<td>");
- 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("</td>");
-
- printf("<td>");
- switch (e->share_mode&0xF) {
- case 0: printf("RDONLY "); break;
- case 1: printf("WRONLY "); break;
- case 2: printf("RDWR "); break;
- }
- printf("</td>");
-
- printf("<td>");
- 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("</td>");
-
- printf("<td>%s</td><td>%s</td></tr>\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("<H2>Server Status</H2>\n");
-
- printf("<FORM method=post>\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("<table>\n");
-
- printf("<tr><td>version:</td><td>%s</td></tr>",VERSION);
-
- fflush(stdout);
- if (smbd_running()) {
- printf("<tr><td>smbd:</td><td>running</td><td><input type=submit name=\"smbd_stop\" value=\"Stop smbd\"></td></tr>\n");
- } else {
- printf("<tr><td>smbd:</td><td>not running</td><td><input type=submit name=\"smbd_start\" value=\"Start smbd\"></td></tr>\n");
- }
-
- fflush(stdout);
- if (nmbd_running()) {
- printf("<tr><td>nmbd:</td><td>running</td><td><input type=submit name=\"nmbd_stop\" value=\"Stop nmbd\"></td></tr>\n");
- } else {
- printf("<tr><td>nmbd:</td><td>not running</td><td><input type=submit name=\"nmbd_start\" value=\"Start nmbd\"></td></tr>\n");
- }
-
- printf("</table>\n");
- fflush(stdout);
-
-
- if (geteuid() != 0)
- printf("<b>NOTE: You are not logged in as root and won't be able to start/stop the server</b><p>\n");
-
- printf("<p><h3>Active Connections</h3>\n");
- printf("<table border=1>\n");
- printf("<tr><th>Share</th><th>User</th><th>Group</th><th>PID</th><th>Client</th><th>Date</th></tr>\n\n");
-
- while (!feof(f)) {
- if (fread(&crec,sizeof(crec),1,f) != 1)
- break;
- if (crec.magic == 0x280267 && process_exists(crec.pid)) {
- printf("<tr><td>%s</td><td>%s</td><td>%s</td><td>%d</td><td>%s (%s)</td><td>%s</td></tr>\n",
- crec.name,uidtoname(crec.uid),
- gidtoname(crec.gid),crec.pid,
- crec.machine,crec.addr,
- asctime(LocalTime(&crec.start)));
- }
- }
-
- printf("</table><p>\n");
-
- printf("<h3>Open Files</h3>\n");
- printf("<table border=1>\n");
- printf("<tr><th>PID</th><th>Sharing</th><th>R/W</th><th>Oplock</th><th>File</th><th>Date</th></tr>\n");
-
- locking_init(1);
- share_mode_forall(print_share_mode);
- locking_end();
- printf("</table>\n");
-
- fclose(f);
-
- printf("</FORM>\n");
-}
-
int main(int argc, char *argv[])
{