Commit 5f65e567 authored by Per Cederqvist's avatar Per Cederqvist
Browse files

(dump_connections): New function.

(check_kill_flg): Call dump_connections if any connection was killed.
(login_request): Set the "peer" field.  (Bug 706).
parent 60caf6ee
/*
* $Id: connections.c,v 0.75 2002/08/11 09:36:56 ceder Exp $
* $Id: connections.c,v 0.76 2002/08/16 00:24:10 ceder Exp $
* Copyright (C) 1991-2002 Lysator Academic Computer Association.
*
* This file is part of the LysKOM server.
......@@ -546,6 +546,44 @@ add_to_kill_list(Connection *conn)
kill_list[kill_list_size-1] = conn->session_no;
}
void
dump_connections(void)
{
Session_no s;
Connection *conn;
FILE *fp;
if ((fp = fopen(param.connection_status_file_tmp, "w")) == NULL)
{
kom_log("dump_connections(): can't open file %s\n",
param.connection_status_file_tmp);
return;
}
for (s = 0; (s = traverse_connections(s)) != 0;)
{
conn = get_conn_by_number(s);
fprintf(fp, "%d %lu %s\n", conn->isc_session->fd, conn->session_no,
conn->peer);
}
if (fclose(fp) < 0)
{
kom_log("dump_connections(): fclose failed: %s (ignored)\n",
strerror(errno));
}
if (rename(param.connection_status_file_tmp,
param.connection_status_file) < 0)
{
kom_log("dump_connections(): can't rename %s to %s\n",
param.connection_status_file_tmp,
param.connection_status_file);
}
}
/*
* check_kill_flg must NEVER be called inside an atomic call!
*/
......@@ -553,6 +591,7 @@ static void
check_kill_flg(void)
{
Connection *conn;
Bool changed = FALSE;
if ( active_connection != NULL )
{
......@@ -573,6 +612,7 @@ check_kill_flg(void)
{
logout_client (conn);
end_of_atomic (FALSE);
changed = TRUE;
}
}
......@@ -581,6 +621,9 @@ check_kill_flg(void)
sfree (kill_list);
kill_list = NULL;
}
if (changed == TRUE)
dump_connections();
}
......@@ -628,6 +671,8 @@ login_request(IscEvent *event)
Connection * cp;
const char *realuser;
char *hostname = NULL;
char peername[256];
size_t len;
/* Supress logins if /etc/nologin exists */
if (fexists(param.nologin_file))
......@@ -672,6 +717,22 @@ login_request(IscEvent *event)
s_crea_str(&cp->ident_user, realuser);
BUG(("\n[Client %lu from %s is connecting]\n", cp->session_no, hostname));
isc_getipnum(event->session->info.tcp.raddr, peername, sizeof(peername)-1);
len = strlen(peername);
snprintf(peername + len, sizeof(peername) - len, " %d",
isc_getportnum(event->session->info.tcp.raddr));
len = strlen(peername) + 1;
if (len >= sizeof(peername))
{
kom_log("login_request(): truncated remote peer address %s.\n",
peername);
}
cp->peer = smalloc(len);
strcpy(cp->peer, peername);
dump_connections();
}
static void
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment