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. Added menu function display file.
Display ascii textfiles now uses the More Y/n/= prompt. Display ascii textfiles now uses the More Y/n/= prompt.
mbuser:
Added nopper code during pack.
mbcico: mbcico:
Removed some heavy debug code from ttyio functions to increase Removed some heavy debug code from ttyio functions to increase
throughput. throughput.

View File

@ -4,7 +4,7 @@
* Purpose ...............: Hangup functions * Purpose ...............: Hangup functions
* *
***************************************************************************** *****************************************************************************
* Copyright (C) 1997-2002 * Copyright (C) 1997-2003
* *
* Michiel Broek FIDO: 2:280/2802 * Michiel Broek FIDO: 2:280/2802
* Beekmansbos 10 * Beekmansbos 10
@ -51,117 +51,117 @@ int do_mailout = FALSE;
void Good_Bye(int onsig) void Good_Bye(int onsig)
{ {
FILE *pUsrConfig, *pExitinfo; FILE *pUsrConfig, *pExitinfo;
char *temp; char *temp;
long offset; long offset;
time_t t_end; time_t t_end;
IsDoing("Hangup"); IsDoing("Hangup");
temp = calloc(PATH_MAX, sizeof(char)); temp = calloc(PATH_MAX, sizeof(char));
Syslog('+', "Good_Bye()"); Syslog('+', "Good_Bye()");
if (onsig != SIGHUP) if (onsig != SIGHUP)
DisplayFile((char *)"goodbye"); DisplayFile((char *)"goodbye");
if (do_mailout) if (do_mailout)
CreateSema((char *)"mailout"); CreateSema((char *)"mailout");
SaveLastCallers(); 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);
/*
* 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); sprintf(temp, "%s/%s/exitinfo", CFG.bbs_usersdir, exitinfo.Name);
unlink(temp); if ((pExitinfo = fopen(temp,"rb")) != NULL) {
free(temp); fread(&usrconfighdr, sizeof(usrconfighdr), 1, pUsrConfig);
unlink("taglist"); offset = usrconfighdr.hdrsize + (grecno * usrconfighdr.recsize);
fread(&exitinfo, sizeof(exitinfo), 1, pExitinfo);
/* usrconfig = exitinfo;
* Flush all data to the user, wait 5 seconds to fclose(pExitinfo);
* be sure the user received all data, this program
* and parent are also finished.
*/
colour(7, 0);
fflush(stdout);
fflush(stdin);
sleep(5);
Unsetraw(); usrconfig.iLastFileArea = iAreaNumber;
Free_Language(); if (!iAreaNumber)
free(pTTY); 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 #ifdef MEMWATCH
mwTerm(); mwTerm();
#endif #endif
exit(onsig); exit(onsig);
} }
void Quick_Bye(int onsig) void Quick_Bye(int onsig)
{ {
char *temp; char *temp;
temp = calloc(PATH_MAX, sizeof(char)); temp = calloc(PATH_MAX, sizeof(char));
Syslog('+', "Quick_Bye"); Syslog('+', "Quick_Bye");
socket_shutdown(mypid); socket_shutdown(mypid);
sprintf(temp, "%s/tmp/mbsebbs%d", getenv("MBSE_ROOT"), getpid()); sprintf(temp, "%s/tmp/mbsebbs%d", getenv("MBSE_ROOT"), getpid());
unlink(temp); unlink(temp);
free(temp); free(temp);
colour(7, 0); colour(7, 0);
fflush(stdout); fflush(stdout);
fflush(stdin); fflush(stdin);
sleep(3); sleep(3);
Free_Language(); Free_Language();
free(pTTY); free(pTTY);
#ifdef MEMWATCH #ifdef MEMWATCH
mwTerm(); mwTerm();
#endif #endif
exit(MBERR_OK); exit(MBERR_OK);
} }

View File

@ -54,45 +54,46 @@
*/ */
int InitExitinfo() int InitExitinfo()
{ {
FILE *pUsrConfig, *pExitinfo; FILE *pUsrConfig, *pExitinfo;
char *temp; char *temp;
long offset; long offset;
temp = calloc(PATH_MAX, sizeof(char)); temp = calloc(PATH_MAX, sizeof(char));
sprintf(temp, "%s/etc/users.data", getenv("MBSE_ROOT")); sprintf(temp, "%s/etc/users.data", getenv("MBSE_ROOT"));
if ((pUsrConfig = fopen(temp,"r+b")) == NULL) { if ((pUsrConfig = fopen(temp,"r+b")) == NULL) {
WriteError("$Can't open %s for writing", temp); 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);
}
free(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() void ReadExitinfo()
{ {
FILE *pExitinfo; FILE *pExitinfo;
char *temp; char *temp;
temp = calloc(PATH_MAX, sizeof(char)); temp = calloc(PATH_MAX, sizeof(char));
sprintf(temp, "%s/%s/exitinfo", CFG.bbs_usersdir, sUnixName); sprintf(temp, "%s/%s/exitinfo", CFG.bbs_usersdir, sUnixName);
mkdirs(temp, 0770); mkdirs(temp, 0770);
if ((pExitinfo = fopen(temp,"r+b")) == NULL) if ((pExitinfo = fopen(temp,"r+b")) == NULL)
InitExitinfo(); InitExitinfo();
else { else {
fflush(stdin); fflush(stdin);
fread(&exitinfo, sizeof(exitinfo), 1, pExitinfo); fread(&exitinfo, sizeof(exitinfo), 1, pExitinfo);
fclose(pExitinfo); fclose(pExitinfo);
} }
free(temp); free(temp);
} }
@ -127,19 +128,19 @@ void ReadExitinfo()
*/ */
void WriteExitinfo() void WriteExitinfo()
{ {
FILE *pExitinfo; FILE *pExitinfo;
char *temp; char *temp;
temp = calloc(PATH_MAX, sizeof(char)); temp = calloc(PATH_MAX, sizeof(char));
sprintf(temp, "%s/%s/exitinfo", CFG.bbs_usersdir, sUnixName); sprintf(temp, "%s/%s/exitinfo", CFG.bbs_usersdir, sUnixName);
if ((pExitinfo = fopen(temp,"w+b")) == NULL) if ((pExitinfo = fopen(temp,"w+b")) == NULL)
WriteError("$WriteExitinfo() failed"); WriteError("$WriteExitinfo() failed");
else { else {
fwrite(&exitinfo, sizeof(exitinfo), 1, pExitinfo); fwrite(&exitinfo, sizeof(exitinfo), 1, pExitinfo);
fclose(pExitinfo); fclose(pExitinfo);
} }
free(temp); free(temp);
} }

View File

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