Added timeout check to mbuser

This commit is contained in:
Michiel Broek 2003-05-08 18:59:31 +00:00
parent 77ba5b42d9
commit 932601b885
4 changed files with 158 additions and 151 deletions

View File

@ -20,6 +20,9 @@ v0.37.3 09-Apr-2003.
Added menu function display file.
Display ascii textfiles now uses the More Y/n/= prompt.
mbuser:
Added nopper code during pack.
mbcico:
Removed some heavy debug code from ttyio functions to increase
throughput.

View File

@ -4,7 +4,7 @@
* Purpose ...............: Hangup functions
*
*****************************************************************************
* Copyright (C) 1997-2002
* Copyright (C) 1997-2003
*
* Michiel Broek FIDO: 2:280/2802
* Beekmansbos 10
@ -51,117 +51,117 @@ int do_mailout = FALSE;
void Good_Bye(int onsig)
{
FILE *pUsrConfig, *pExitinfo;
char *temp;
long offset;
time_t t_end;
FILE *pUsrConfig, *pExitinfo;
char *temp;
long offset;
time_t t_end;
IsDoing("Hangup");
temp = calloc(PATH_MAX, sizeof(char));
Syslog('+', "Good_Bye()");
IsDoing("Hangup");
temp = calloc(PATH_MAX, sizeof(char));
Syslog('+', "Good_Bye()");
if (onsig != SIGHUP)
DisplayFile((char *)"goodbye");
if (onsig != SIGHUP)
DisplayFile((char *)"goodbye");
if (do_mailout)
CreateSema((char *)"mailout");
if (do_mailout)
CreateSema((char *)"mailout");
SaveLastCallers();
/*
* Update the users database record.
*/
sprintf(temp, "%s/etc/users.data", getenv("MBSE_ROOT"));
if ((pUsrConfig = fopen(temp,"r+b")) != NULL) {
sprintf(temp, "%s/%s/exitinfo", CFG.bbs_usersdir, exitinfo.Name);
if ((pExitinfo = fopen(temp,"rb")) != NULL) {
fread(&usrconfighdr, sizeof(usrconfighdr), 1, pUsrConfig);
offset = usrconfighdr.hdrsize + (grecno * usrconfighdr.recsize);
fread(&exitinfo, sizeof(exitinfo), 1, pExitinfo);
usrconfig = exitinfo;
fclose(pExitinfo);
usrconfig.iLastFileArea = iAreaNumber;
if (!iAreaNumber)
WriteError("Setting filearea to zero");
/* If time expired, do not say say successful logoff */
if(!iExpired)
Syslog('+', "User successfully logged off BBS");
usrconfig.iLastMsgArea = iMsgAreaNumber;
offset = usrconfighdr.hdrsize + (grecno * usrconfighdr.recsize);
if(fseek(pUsrConfig, offset, 0) != 0) {
WriteError("Can't move pointer in file %s", temp);
ExitClient(MBERR_GENERAL);
}
fwrite(&usrconfig, sizeof(usrconfig), 1, pUsrConfig);
fclose(pUsrConfig);
}
}
t_end = time(NULL);
Syslog(' ', "MBSEBBS finished in %s", t_elapsed(t_start, t_end));
/*
* Start shutting down this session
*/
socket_shutdown(mypid);
sprintf(temp, "%s/tmp/mbsebbs%d", getenv("MBSE_ROOT"), getpid());
unlink(temp);
SaveLastCallers();
/*
* Update the users database record.
*/
sprintf(temp, "%s/etc/users.data", getenv("MBSE_ROOT"));
if ((pUsrConfig = fopen(temp,"r+b")) != NULL) {
sprintf(temp, "%s/%s/exitinfo", CFG.bbs_usersdir, exitinfo.Name);
unlink(temp);
free(temp);
unlink("taglist");
if ((pExitinfo = fopen(temp,"rb")) != NULL) {
fread(&usrconfighdr, sizeof(usrconfighdr), 1, pUsrConfig);
offset = usrconfighdr.hdrsize + (grecno * usrconfighdr.recsize);
fread(&exitinfo, sizeof(exitinfo), 1, pExitinfo);
/*
* Flush all data to the user, wait 5 seconds to
* be sure the user received all data, this program
* and parent are also finished.
*/
colour(7, 0);
fflush(stdout);
fflush(stdin);
sleep(5);
usrconfig = exitinfo;
fclose(pExitinfo);
Unsetraw();
Free_Language();
free(pTTY);
usrconfig.iLastFileArea = iAreaNumber;
if (!iAreaNumber)
WriteError("Setting filearea to zero");
/* If time expired, do not say say successful logoff */
if (!iExpired)
Syslog('+', "User successfully logged off BBS");
usrconfig.iLastMsgArea = iMsgAreaNumber;
offset = usrconfighdr.hdrsize + (grecno * usrconfighdr.recsize);
Syslog('b', "Good_Bye: write users.data at offset %ld", offset);
if (fseek(pUsrConfig, offset, 0) != 0) {
WriteError("Can't move pointer in file %s", temp);
ExitClient(MBERR_GENERAL);
}
fwrite(&usrconfig, sizeof(usrconfig), 1, pUsrConfig);
fclose(pUsrConfig);
}
}
t_end = time(NULL);
Syslog(' ', "MBSEBBS finished in %s", t_elapsed(t_start, t_end));
/*
* Start shutting down this session
*/
socket_shutdown(mypid);
sprintf(temp, "%s/tmp/mbsebbs%d", getenv("MBSE_ROOT"), getpid());
unlink(temp);
sprintf(temp, "%s/%s/exitinfo", CFG.bbs_usersdir, exitinfo.Name);
unlink(temp);
free(temp);
unlink("taglist");
/*
* Flush all data to the user, wait 5 seconds to
* be sure the user received all data, this program
* and parent are also finished.
*/
colour(7, 0);
fflush(stdout);
fflush(stdin);
sleep(5);
Unsetraw();
Free_Language();
free(pTTY);
#ifdef MEMWATCH
mwTerm();
mwTerm();
#endif
exit(onsig);
exit(onsig);
}
void Quick_Bye(int onsig)
{
char *temp;
char *temp;
temp = calloc(PATH_MAX, sizeof(char));
Syslog('+', "Quick_Bye");
socket_shutdown(mypid);
sprintf(temp, "%s/tmp/mbsebbs%d", getenv("MBSE_ROOT"), getpid());
unlink(temp);
free(temp);
temp = calloc(PATH_MAX, sizeof(char));
Syslog('+', "Quick_Bye");
socket_shutdown(mypid);
sprintf(temp, "%s/tmp/mbsebbs%d", getenv("MBSE_ROOT"), getpid());
unlink(temp);
free(temp);
colour(7, 0);
fflush(stdout);
fflush(stdin);
sleep(3);
colour(7, 0);
fflush(stdout);
fflush(stdin);
sleep(3);
Free_Language();
free(pTTY);
Free_Language();
free(pTTY);
#ifdef MEMWATCH
mwTerm();
mwTerm();
#endif
exit(MBERR_OK);
exit(MBERR_OK);
}

View File

@ -54,45 +54,46 @@
*/
int InitExitinfo()
{
FILE *pUsrConfig, *pExitinfo;
char *temp;
long offset;
FILE *pUsrConfig, *pExitinfo;
char *temp;
long offset;
temp = calloc(PATH_MAX, sizeof(char));
sprintf(temp, "%s/etc/users.data", getenv("MBSE_ROOT"));
temp = calloc(PATH_MAX, sizeof(char));
sprintf(temp, "%s/etc/users.data", getenv("MBSE_ROOT"));
if ((pUsrConfig = fopen(temp,"r+b")) == NULL) {
WriteError("$Can't open %s for writing", temp);
free(temp);
return FALSE;
}
fread(&usrconfighdr, sizeof(usrconfighdr), 1, pUsrConfig);
offset = usrconfighdr.hdrsize + (grecno * usrconfighdr.recsize);
if(fseek(pUsrConfig, offset, 0) != 0) {
WriteError("$Can't move pointer in %s", temp);
free(temp);
return FALSE;
}
fread(&usrconfig, usrconfighdr.recsize, 1, pUsrConfig);
exitinfo = usrconfig;
fclose(pUsrConfig);
sprintf(temp, "%s/%s/exitinfo", CFG.bbs_usersdir, usrconfig.Name);
if ((pExitinfo = fopen(temp, "w+b")) == NULL) {
WriteError("$Can't open %s for writing", temp);
free(temp);
return FALSE;
} else {
fwrite(&exitinfo, sizeof(exitinfo), 1, pExitinfo);
fclose(pExitinfo);
if (chmod(temp, 0600))
WriteError("$Can't chmod 0600 %s", temp);
}
if ((pUsrConfig = fopen(temp,"r+b")) == NULL) {
WriteError("$Can't open %s for writing", temp);
free(temp);
return TRUE;
return FALSE;
}
fread(&usrconfighdr, sizeof(usrconfighdr), 1, pUsrConfig);
offset = usrconfighdr.hdrsize + (grecno * usrconfighdr.recsize);
Syslog('b', "InitExitinfo: read users.data offset %ld", offset);
if (fseek(pUsrConfig, offset, 0) != 0) {
WriteError("$Can't move pointer in %s", temp);
free(temp);
return FALSE;
}
fread(&usrconfig, usrconfighdr.recsize, 1, pUsrConfig);
exitinfo = usrconfig;
fclose(pUsrConfig);
sprintf(temp, "%s/%s/exitinfo", CFG.bbs_usersdir, usrconfig.Name);
if ((pExitinfo = fopen(temp, "w+b")) == NULL) {
WriteError("$Can't open %s for writing", temp);
free(temp);
return FALSE;
} else {
fwrite(&exitinfo, sizeof(exitinfo), 1, pExitinfo);
fclose(pExitinfo);
if (chmod(temp, 0600))
WriteError("$Can't chmod 0600 %s", temp);
}
free(temp);
return TRUE;
}
@ -103,20 +104,20 @@ int InitExitinfo()
*/
void ReadExitinfo()
{
FILE *pExitinfo;
char *temp;
FILE *pExitinfo;
char *temp;
temp = calloc(PATH_MAX, sizeof(char));
sprintf(temp, "%s/%s/exitinfo", CFG.bbs_usersdir, sUnixName);
mkdirs(temp, 0770);
if ((pExitinfo = fopen(temp,"r+b")) == NULL)
InitExitinfo();
else {
fflush(stdin);
fread(&exitinfo, sizeof(exitinfo), 1, pExitinfo);
fclose(pExitinfo);
}
free(temp);
temp = calloc(PATH_MAX, sizeof(char));
sprintf(temp, "%s/%s/exitinfo", CFG.bbs_usersdir, sUnixName);
mkdirs(temp, 0770);
if ((pExitinfo = fopen(temp,"r+b")) == NULL)
InitExitinfo();
else {
fflush(stdin);
fread(&exitinfo, sizeof(exitinfo), 1, pExitinfo);
fclose(pExitinfo);
}
free(temp);
}
@ -127,19 +128,19 @@ void ReadExitinfo()
*/
void WriteExitinfo()
{
FILE *pExitinfo;
char *temp;
FILE *pExitinfo;
char *temp;
temp = calloc(PATH_MAX, sizeof(char));
temp = calloc(PATH_MAX, sizeof(char));
sprintf(temp, "%s/%s/exitinfo", CFG.bbs_usersdir, sUnixName);
if ((pExitinfo = fopen(temp,"w+b")) == NULL)
WriteError("$WriteExitinfo() failed");
else {
fwrite(&exitinfo, sizeof(exitinfo), 1, pExitinfo);
fclose(pExitinfo);
}
free(temp);
sprintf(temp, "%s/%s/exitinfo", CFG.bbs_usersdir, sUnixName);
if ((pExitinfo = fopen(temp,"w+b")) == NULL)
WriteError("$WriteExitinfo() failed");
else {
fwrite(&exitinfo, sizeof(exitinfo), 1, pExitinfo);
fclose(pExitinfo);
}
free(temp);
}

View File

@ -252,6 +252,7 @@ void UserPack(int days, int level, int pack)
memset(&usr, 0, sizeof(usr));
if (CFG.slow_util && do_quiet)
usleep(1);
Nopper();
}
fclose(fin);
delete = 0;
@ -311,6 +312,7 @@ void UserPack(int days, int level, int pack)
if (CFG.slow_util && do_quiet)
usleep(1);
Nopper();
if (usr.Deleted) {
if (!do_quiet) {
printf("Delete user %s\n", usr.Name);
@ -371,6 +373,7 @@ void UserPack(int days, int level, int pack)
record = 0;
while (fread(&usr, sizeof(usr), 1,fout) == 1) {
Nopper();
record++;
fwrite(&usr, sizeof(usr), 1, fin);
if (record >= highest)