Commit 36480f4d authored by Per Cederqvist's avatar Per Cederqvist
Browse files

Renamed login() to login_old().

Added login(), get_session_info_ident() and who_is_on_ident().
Support for invisible sessions and the Ident protocol (RFC 931).
parent b85cf259
/*
* $Id: session.c,v 0.5 1991/12/16 23:56:28 ceder Exp $
* $Id: session.c,v 0.6 1992/04/01 20:47:46 ceder Exp $
* Copyright (C) 1991 Lysator Academic Computer Association.
*
* This file is part of the LysKOM server.
......@@ -28,7 +28,7 @@
* Session control and miscellaneous.
*/
static char *rcsid = "$Id: session.c,v 0.5 1991/12/16 23:56:28 ceder Exp $";
static char *rcsid = "$Id: session.c,v 0.6 1992/04/01 20:47:46 ceder Exp $";
#include <time.h>
......@@ -81,13 +81,14 @@ leave_conf(void)
* be performed if ACTPERS is logged in.
*/
extern Success
login (Pers_no pers_no,
const String passwd)
login_old (Pers_no pers_no,
const String passwd)
{
Person *pers_p;
GET_P_STAT(pers_p, pers_no, FAILURE);
active_connection->invisible = FALSE;
#if 0
if ( !logins_allowed && !pers_p->privileges.wheel)
{
......@@ -114,7 +115,31 @@ login (Pers_no pers_no,
++pers_p->sessions;
s_strcpy(&pers_p->username, active_connection->username);
/* A Person should have separate fields for ident_user and hostname.
But for now, we use the syntax username(ident_user)@hostname. */
if (!s_empty(active_connection->ident_user))
{
if ( s_strcat(&client->username,
s_fcrea_str((const unsigned char *)"(")) != OK )
restart_kom("login: s_strcat (\n");
if ( s_strcat(&client->username, active_connection->ident_user) != OK )
restart_kom("login: s_strcat ident_user\n");
if ( s_strcat(&client->username,
s_fcrea_str((const unsigned char *)")")) != OK )
restart_kom("login: s_strcat )\n");
}
if ( s_strcat(&client->username,
s_fcrea_str((const unsigned char *)"@")) != OK )
restart_kom("prot_a_parse_packet: s_strcat\n");
if ( s_strcat(&client->username, client->hostname) != OK )
restart_kom("prot_a_parse_packet: s_strcat II\n");
mark_person_as_changed( pers_no );
async_login(ACTPERS, active_connection->session_no);
......@@ -122,6 +147,81 @@ login (Pers_no pers_no,
return OK;
}
/*
* Log in as user pers_no. If ACTPERS is a supervisor of pers_no the login
* will succeed regardless of the passwd. An logout() will automatically
* be performed if ACTPERS is logged in.
*/
extern Success
login (Pers_no pers_no,
const String passwd,
Bool invisible)
{
Person *pers_p;
GET_P_STAT(pers_p, pers_no, FAILURE);
active_connection->invisible = !!invisible; /* Normalize 17. */
#if 0
if ( !logins_allowed && !pers_p->privileges.wheel)
{
kom_errno = KOM_LOGIN_DISALLOWED;
return FAILURE;
}
#endif
if ( !is_supervisor(pers_no, NULL, ACTPERS, ACT_P)
&& chk_passwd(pers_p->pwd, passwd) == FAILURE )
{
kom_errno = KOM_PWD;
return FAILURE;
}
logout(); /*+++ How many tries are allowed before disconnection? */
ACTPERS = pers_no;
ACT_P = pers_p;
cached_lock_person(pers_no);
pers_p->last_login = time(&active_connection->session_start);
++pers_p->sessions;
s_strcpy(&pers_p->username, active_connection->username);
/* A Person should have separate fields for ident_user and hostname.
But for now, we use the syntax username(ident_user)@hostname. */
if (!s_empty(active_connection->ident_user))
{
if ( s_strcat(&client->username,
s_fcrea_str((const unsigned char *)"(")) != OK )
restart_kom("login: s_strcat (\n");
if ( s_strcat(&client->username, active_connection->ident_user) != OK )
restart_kom("login: s_strcat ident_user\n");
if ( s_strcat(&client->username,
s_fcrea_str((const unsigned char *)")")) != OK )
restart_kom("login: s_strcat )\n");
}
if ( s_strcat(&client->username,
s_fcrea_str((const unsigned char *)"@")) != OK )
restart_kom("prot_a_parse_packet: s_strcat\n");
if ( s_strcat(&client->username, client->hostname) != OK )
restart_kom("prot_a_parse_packet: s_strcat II\n");
mark_person_as_changed( pers_no );
if (!active_connection->invisible)
async_login(ACTPERS, active_connection->session_no);
return OK;
}
/*
* Log out. Does not disconnect the client. The person is also automatically
......@@ -133,8 +233,11 @@ logout( void )
{
if ( ACTPERS != 0 ) /* Is he logged in? Then log him out. */
{
async_i_am_off( ACTPERS );
async_logout( ACTPERS, active_connection->session_no );
if (active_connection->invisible)
{
async_i_am_off( ACTPERS );
async_logout( ACTPERS, active_connection->session_no );
}
leave_conf();
ACT_P->total_time_present +=
......@@ -201,14 +304,17 @@ pepsi (Conf_no conference)
if ( conference != 0 )
cached_lock_conf( conference );
info.person = ACTPERS;
info.what_am_i_doing = active_connection->what_am_i_doing;
info.username = active_connection->username;
info.working_conference = conference;
info.session_no = active_connection->session_no;
if (!active_connection->invisible)
{
info.person = ACTPERS;
info.what_am_i_doing = active_connection->what_am_i_doing;
info.username = active_connection->username;
info.working_conference = conference;
info.session_no = active_connection->session_no;
async_i_am_on(info);
}
async_i_am_on(info);
return OK;
}
......@@ -232,13 +338,17 @@ change_what_i_am_doing (String what_am_i_doing)
s_clear ( &active_connection->what_am_i_doing );
active_connection->what_am_i_doing = what_am_i_doing;
info.person = ACTPERS;
info.what_am_i_doing = active_connection->what_am_i_doing;
info.username = active_connection->username;
info.working_conference = active_connection->cwc;
info.session_no = active_connection->session_no;
if (!active_connection->invisible)
{
info.person = ACTPERS;
info.what_am_i_doing = active_connection->what_am_i_doing;
info.username = active_connection->username;
info.working_conference = active_connection->cwc;
info.session_no = active_connection->session_no;
async_i_am_on(info);
async_i_am_on(info);
}
return OK;
}
......@@ -277,7 +387,20 @@ who_is_on( Who_info_list *result )
result->info[ i ] = EMPTY_WHO_INFO;
result->info[ i ].person = cptr->pers_no;
result->info[ i ].what_am_i_doing = cptr->what_am_i_doing;
result->info[ i ].username = cptr->username;
/* Backward compatibility: Old clients want the username to be
user%host@host. result->info[i].username is free()d in
prot_a_output_who_info_list() in prot-a-output.c. */
if ( s_strcpy(&result->info[i].username, cptr->username) != OK )
restart_kom("who_is_on(): strcpy\n");
if ( s_strcat(&result->info[i].username,
s_fcrea_str((const unsigned char *)"@")) != OK )
restart_kom("who_is_on: s_strcat\n");
if ( s_strcat(&result->info[i].username, cptr->hostname) != OK )
restart_kom("prot_a_parse_packet: s_strcat II\n");
result->info[ i ].working_conference = cptr->cwc;
result->info[ i ].session_no = cptr->session_no;
++i;
......@@ -291,6 +414,56 @@ who_is_on( Who_info_list *result )
return OK;
}
/*
* Get info about what all the currently logged in persons are doing.
*/
extern Success
who_is_on_ident( Who_info_ident_list *result )
{
Connection *cptr;
int no_of_clients = 0;
int i;
Session_no session;
cptr = active_connection;
for ( session = 0; (session = traverse_connections(session)) != 0; )
{
cptr = get_conn_by_number(session);
if ( cptr->person != NULL )
++no_of_clients;
}
result->no_of_persons = no_of_clients;
result->info = tmp_alloc ( no_of_clients * sizeof(Who_info));
for ( session = 0, i = 0;
i < no_of_clients && (session = traverse_connections(session)) != 0; )
{
cptr = get_conn_by_number(session);
if ( cptr->person != NULL )
{
result->info[i] = EMPTY_WHO_INFO;
result->info[i].person = cptr->pers_no;
result->info[i].what_am_i_doing = cptr->what_am_i_doing;
result->info[i].username = cptr->username;
result->info[i].hostname = cptr->hostname;
result->info[i].ident_user = cptr->ident_user;
result->info[i].working_conference = cptr->cwc;
result->info[i].session_no = cptr->session_no;
++i;
}
}
if ( i != no_of_clients )
log("who_is_on_ident: i == %d, no_of_clients == %d\n",
i, no_of_clients);
return OK;
}
extern Success
get_session_info (Session_no session_no,
......@@ -307,13 +480,57 @@ get_session_info (Session_no session_no,
*result = EMPTY_SESSION_INFO;
result->person = cptr->pers_no;
result->what_am_i_doing = cptr->what_am_i_doing;
result->username = cptr->username;
result->working_conference = cptr->cwc;
result->session = cptr->session_no;
result->connection_time = cptr->session_start;
result->idle_time = difftime(time(NULL),
cptr->last_request);
/* Backward compatibility. result->username is free()d in
prot_a_reply() prot-a.c. */
if (s_strcpy(&result->username ,cptr->username) != OK)
restart_kom("get_session_info(): strcpy.\n");
if ( s_strcat(&result->username,
s_fcrea_str((const unsigned char *)"@")) != OK )
restart_kom("get_session_info: s_strcat\n");
if ( s_strcat(&result->username, client->hostname) != OK )
restart_kom("get_session_infot: s_strcat II\n");
return OK;
}
else
{
kom_errno = KOM_UNDEF_SESSION;
return FAILURE;
}
}
extern Success
get_session_info_ident (Session_no session_no,
Session_info_ident *result)
{
Connection *cptr;
CHK_LOGIN(FAILURE);
cptr = get_conn_by_number(session_no);
if ( cptr != NULL )
{
*result = EMPTY_SESSION_INFO;
result->person = cptr->pers_no;
result->what_am_i_doing = cptr->what_am_i_doing;
result->working_conference = cptr->cwc;
result->session = cptr->session_no;
result->connection_time = cptr->session_start;
result->idle_time = difftime(time(NULL),
cptr->last_request);
result->username = cptr->username;
result->hostname = cptr->hostname;
result->ident_user = cptr->ident_user;
return OK;
}
else
......
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