This repository has been archived on 2024-04-08. You can view files and clone it, but cannot push or open issues or pull requests.
deb-mbse/mbsebbs/bye.c

203 lines
5.2 KiB
C
Raw Normal View History

2001-08-17 05:46:24 +00:00
/*****************************************************************************
*
2001-11-12 21:42:17 +00:00
* $Id$
2001-08-17 05:46:24 +00:00
* Purpose ...............: Hangup functions
*
*****************************************************************************
2005-08-29 12:59:00 +00:00
* Copyright (C) 1997-2005
2001-08-17 05:46:24 +00:00
*
* Michiel Broek FIDO: 2:280/2802
* Beekmansbos 10
* 1971 BV IJmuiden
* the Netherlands
*
* This file is part of MBSE BBS.
*
* This BBS 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, or (at your option) any
* later version.
*
* MBSE BBS 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 MBSE BBS; see the file COPYING. If not, write to the Free
2003-08-15 20:05:34 +00:00
* Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
2001-08-17 05:46:24 +00:00
*****************************************************************************/
2002-06-30 12:48:44 +00:00
#include "../config.h"
2004-02-21 17:22:00 +00:00
#include "../lib/mbselib.h"
2001-08-17 05:46:24 +00:00
#include "../lib/mbse.h"
2002-01-07 19:16:03 +00:00
#include "../lib/users.h"
#include "../lib/nodelist.h"
#include "dispfile.h"
2001-11-02 22:04:57 +00:00
#include "misc.h"
2001-08-17 05:46:24 +00:00
#include "language.h"
#include "bye.h"
#include "term.h"
2004-11-03 20:48:45 +00:00
#include "openport.h"
#include "ttyio.h"
2001-08-17 05:46:24 +00:00
extern pid_t mypid;
extern time_t t_start;
extern char *StartTime;
2004-11-03 20:48:45 +00:00
extern int hanged_up;
2001-08-17 05:46:24 +00:00
int do_mailout = FALSE;
void Good_Bye(int onsig)
{
2003-05-08 18:59:31 +00:00
FILE *pUsrConfig, *pExitinfo;
char *temp;
long offset;
time_t t_end;
2004-11-03 20:48:45 +00:00
int i;
2001-08-17 05:46:24 +00:00
2003-05-08 18:59:31 +00:00
IsDoing("Hangup");
temp = calloc(PATH_MAX, sizeof(char));
2003-11-02 11:34:59 +00:00
Syslog('+', "Good_Bye(%d)", onsig);
2001-08-17 05:46:24 +00:00
2003-11-02 11:34:59 +00:00
/*
* Don't display goodbye screen on SIGHUP and idle timeout.
* With idle timeout this will go into a loop.
*/
2004-11-04 20:49:32 +00:00
if ((onsig != SIGALRM) && (onsig != MBERR_TIMEOUT) && (hanged_up == 0))
2003-05-08 18:59:31 +00:00
DisplayFile((char *)"goodbye");
2001-08-17 05:46:24 +00:00
2003-05-08 18:59:31 +00:00
SaveLastCallers();
2001-08-17 05:46:24 +00:00
2003-05-08 18:59:31 +00:00
/*
* Update the users database record.
*/
2005-08-29 12:59:00 +00:00
snprintf(temp, PATH_MAX, "%s/etc/users.data", getenv("MBSE_ROOT"));
2003-05-10 11:51:43 +00:00
if ((pUsrConfig = fopen(temp,"r+")) != NULL) {
2005-08-29 12:59:00 +00:00
snprintf(temp, PATH_MAX, "%s/%s/exitinfo", CFG.bbs_usersdir, exitinfo.Name);
2003-05-08 18:59:31 +00:00
if ((pExitinfo = fopen(temp,"rb")) != NULL) {
fread(&usrconfighdr, sizeof(usrconfighdr), 1, pUsrConfig);
fread(&exitinfo, sizeof(exitinfo), 1, pExitinfo);
2001-08-17 05:46:24 +00:00
2003-05-08 18:59:31 +00:00
usrconfig = exitinfo;
fclose(pExitinfo);
usrconfig.iLastFileArea = iAreaNumber;
2001-08-17 05:46:24 +00:00
2003-05-08 18:59:31 +00:00
/* If time expired, do not say say successful logoff */
2004-11-03 20:48:45 +00:00
if (!iExpired && !hanged_up)
2003-05-08 18:59:31 +00:00
Syslog('+', "User successfully logged off BBS");
2001-08-17 05:46:24 +00:00
2003-05-08 18:59:31 +00:00
usrconfig.iLastMsgArea = iMsgAreaNumber;
2001-08-17 05:46:24 +00:00
2003-05-08 18:59:31 +00:00
offset = usrconfighdr.hdrsize + (grecno * usrconfighdr.recsize);
2003-05-10 11:51:43 +00:00
if (fseek(pUsrConfig, offset, SEEK_SET) != 0) {
2004-11-29 22:45:06 +00:00
WriteError("$Can't move pointer in file %s/etc/users.data", getenv("MBSE_ROOT"));
} else {
fwrite(&usrconfig, sizeof(usrconfig), 1, pUsrConfig);
2003-05-08 18:59:31 +00:00
}
fclose(pUsrConfig);
2001-08-17 05:46:24 +00:00
}
2003-05-08 18:59:31 +00:00
}
2004-11-03 20:48:45 +00:00
/*
* Flush all data to the user, wait 5 seconds to
* be sure the user received all data.
*/
2004-11-29 22:03:29 +00:00
if ((onsig != SIGALRM) && (onsig != MBERR_TIMEOUT) && (hanged_up == 0)) {
2004-11-03 20:48:45 +00:00
colour(LIGHTGRAY, BLACK);
sleep(4);
}
2004-11-29 22:45:06 +00:00
for (i = 0; i < NSIG; i++) {
if (i == SIGCHLD)
signal(i, SIG_DFL);
else if ((i != SIGKILL) && (i != SIGSTOP))
2004-11-29 22:47:42 +00:00
signal(i, SIG_DFL);
2004-11-29 22:45:06 +00:00
}
2004-11-03 20:48:45 +00:00
2004-11-29 22:45:06 +00:00
if ((onsig != SIGALRM) && (onsig != MBERR_TIMEOUT) && (hanged_up == 0)) {
cookedport();
}
2004-12-06 21:48:36 +00:00
/*
* Ignore SIGHUP during hangup.
*/
signal(SIGHUP, SIG_IGN);
2004-11-30 20:07:19 +00:00
hangup();
2004-11-03 20:48:45 +00:00
2004-11-30 20:07:19 +00:00
for (i = 0; i < NSIG; i++) {
if ((i == SIGHUP) || (i == SIGPIPE) || (i == SIGBUS) || (i == SIGILL) || (i == SIGSEGV) || (i == SIGTERM))
signal(i, SIG_DFL);
}
2004-11-29 19:48:20 +00:00
if (do_mailout)
CreateSema((char *)"mailout");
2003-05-08 18:59:31 +00:00
t_end = time(NULL);
Syslog(' ', "MBSEBBS finished in %s", t_elapsed(t_start, t_end));
2004-11-03 20:48:45 +00:00
sleep(1);
2003-05-08 18:59:31 +00:00
/*
* Start shutting down this session
*/
socket_shutdown(mypid);
2005-08-29 12:59:00 +00:00
snprintf(temp, PATH_MAX, "%s/tmp/mbsebbs%d", getenv("MBSE_ROOT"), getpid());
2003-05-08 18:59:31 +00:00
unlink(temp);
2005-08-29 12:59:00 +00:00
snprintf(temp, PATH_MAX, "%s/%s/exitinfo", CFG.bbs_usersdir, exitinfo.Name);
2003-05-08 18:59:31 +00:00
unlink(temp);
free(temp);
unlink("taglist");
Free_Language();
free(pTTY);
if (StartTime)
free(StartTime);
deinitnl();
2003-05-08 18:59:31 +00:00
exit(onsig);
2001-08-17 05:46:24 +00:00
}
void Quick_Bye(int onsig)
{
2003-05-08 18:59:31 +00:00
char *temp;
2004-08-25 18:57:24 +00:00
int i;
2003-05-08 18:59:31 +00:00
temp = calloc(PATH_MAX, sizeof(char));
Syslog('+', "Quick_Bye");
socket_shutdown(mypid);
2005-08-29 12:59:00 +00:00
snprintf(temp, PATH_MAX, "%s/tmp/mbsebbs%d", getenv("MBSE_ROOT"), getpid());
2003-05-08 18:59:31 +00:00
unlink(temp);
free(temp);
colour(LIGHTGRAY, BLACK);
sleep(3);
if ((onsig != SIGALRM) && (onsig != MBERR_TIMEOUT) && (hanged_up == 0)) {
cookedport();
}
/*
* Ignore SIGHUP during hangup
*/
signal(SIGHUP, SIG_IGN);
hangup();
2003-05-08 18:59:31 +00:00
2004-08-25 18:57:24 +00:00
/*
* Prevent that we call die() if something goes wrong next
*/
for (i = 0; i < NSIG; i++)
if ((i == SIGHUP) || (i == SIGPIPE) || (i == SIGBUS) || (i == SIGILL) || (i == SIGSEGV) || (i == SIGTERM))
signal(i, SIG_DFL);
2004-11-03 20:48:45 +00:00
2003-05-08 18:59:31 +00:00
free(pTTY);
if (StartTime)
free(StartTime);
2003-05-08 18:59:31 +00:00
exit(MBERR_OK);
2001-08-17 05:46:24 +00:00
}