From 69d24d869bf97978b31a51fe8e8d08cac4874d67 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 21 Dec 1999 04:54:30 +0000 Subject: first cut at using the tdb code for the connections structure, the SWAT status page and smbstatus. It made the code _much_ simpler, I wish we'd done a database module a long time ago! (This used to be commit 4951755413c11d4c5b9af4699a6e622056d52433) --- source3/web/statuspage.c | 117 +++++++++++++++++++++++++---------------------- 1 file changed, 63 insertions(+), 54 deletions(-) (limited to 'source3/web/statuspage.c') diff --git a/source3/web/statuspage.c b/source3/web/statuspage.c index 304a122e23..8b7108c0b5 100644 --- a/source3/web/statuspage.c +++ b/source3/web/statuspage.c @@ -71,15 +71,68 @@ static void print_share_mode(share_mode_entry *e, char *fname) } +/* kill off any connections chosen by the user */ +static int traverse_fn1(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf) +{ + struct connections_data crec; + memcpy(&crec, dbuf.dptr, sizeof(crec)); + + if (crec.cnum == -1 && process_exists(crec.pid)) { + char buf[30]; + slprintf(buf,sizeof(buf)-1,"kill_%d", (int)crec.pid); + if (cgi_variable(buf)) { + kill_pid(crec.pid); + } + } + return 0; +} + +/* traversal fn for showing machine connections */ +static int traverse_fn2(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf) +{ + struct connections_data crec; + memcpy(&crec, dbuf.dptr, sizeof(crec)); + + if (crec.cnum != -1 || !process_exists(crec.pid)) return 0; + + printf("%d%s%s%s\n", + (int)crec.pid, + crec.machine,crec.addr, + tstring(crec.start)); + if (geteuid() == 0) { + printf("\n", + (int)crec.pid); + } + printf("\n"); + + return 0; +} + +/* traversal fn for showing share connections */ +static int traverse_fn3(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf) +{ + struct connections_data crec; + memcpy(&crec, dbuf.dptr, sizeof(crec)); + + if (crec.cnum != -1 || !process_exists(crec.pid)) return 0; + + printf("%s%s%s%d%s%s\n", + crec.name,uidtoname(crec.uid), + gidtoname(crec.gid),(int)crec.pid, + crec.machine, + tstring(crec.start)); + return 0; +} + + /* show the current server status */ void status_page(void) { - struct connect_record crec; pstring fname; - FILE *f; char *v; int autorefresh=0; int refresh_interval=30; + TDB_CONTEXT *tdb; if (cgi_variable("smbd_restart")) { if (smbd_running()) @@ -123,24 +176,10 @@ void status_page(void) pstrcpy(fname,lp_lockdir()); standard_sub_basic(fname); trim_string(fname,"","/"); - pstrcat(fname,"/STATUS..LCK"); - - - f = sys_fopen(fname,"r"); - if (f) { - while (!feof(f)) { - if (fread(&crec,sizeof(crec),1,f) != 1) break; - if (crec.magic == 0x280267 && crec.cnum == -1 && - process_exists(crec.pid)) { - char buf[30]; - slprintf(buf,sizeof(buf)-1,"kill_%d", (int)crec.pid); - if (cgi_variable(buf)) { - kill_pid(crec.pid); - } - } - } - fclose(f); - } + pstrcat(fname,"/connections.tdb"); + + tdb = tdb_open(fname, 0, O_RDONLY, 0); + if (tdb) tdb_traverse(tdb, traverse_fn1); printf("

Server Status

\n"); @@ -159,8 +198,7 @@ void status_page(void) printf("

\n"); - f = sys_fopen(fname,"r"); - if (!f) { + if (!tdb) { /* open failure either means no connections have been made or status=no */ if (!lp_status(-1)) @@ -207,44 +245,15 @@ void status_page(void) } printf("\n"); - while (f && !feof(f)) { - if (fread(&crec,sizeof(crec),1,f) != 1) - break; - if (crec.magic == 0x280267 && - crec.cnum == -1 && - process_exists(crec.pid)) { - printf("%d%s%s%s\n", - (int)crec.pid, - crec.machine,crec.addr, - tstring(crec.start)); - if (geteuid() == 0) { - printf("\n", - (int)crec.pid); - } - printf("\n"); - } - } + if (tdb) tdb_traverse(tdb, traverse_fn2); printf("

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

Active Shares

\n"); printf("\n"); printf("\n\n"); - while (f && !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),(int)crec.pid, - crec.machine, - tstring(crec.start)); - } - } + if (tdb) tdb_traverse(tdb, traverse_fn3); printf("
ShareUserGroupPIDClientDate
%s%s%s%d%s%s

\n"); @@ -257,7 +266,7 @@ void status_page(void) locking_end(); printf("\n"); - if (f) fclose(f); + tdb_close(tdb); printf("\n"); -- cgit