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/exitinfo.c

143 lines
3.5 KiB
C
Raw Normal View History

2001-08-17 05:46:24 +00:00
/*****************************************************************************
*
* $Id$
2001-08-17 05:46:24 +00:00
* Purpose ...............: Exitinfo functions
*
*****************************************************************************
* Copyright (C) 1997-2001
*
* 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
* Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
*****************************************************************************/
#include "../lib/libs.h"
#include "../lib/mbse.h"
#include "../lib/structs.h"
#include "../lib/records.h"
#include "../lib/common.h"
#include "../lib/clcomm.h"
#include "funcs.h"
#include "input.h"
2001-08-17 05:46:24 +00:00
#include "language.h"
#include "oneline.h"
#include "misc.h"
#include "bye.h"
#include "timeout.h"
#include "timecheck.h"
#include "exitinfo.h"
/*
2001-11-12 21:42:17 +00:00
* Copy usersrecord into ~/home/unixname/exitinfo
2001-08-17 05:46:24 +00:00
*/
2001-11-11 12:07:39 +00:00
int InitExitinfo()
2001-08-17 05:46:24 +00:00
{
FILE *pUsrConfig, *pExitinfo;
char *temp;
long offset;
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);
2001-11-11 12:07:39 +00:00
return FALSE;
2001-08-17 05:46:24 +00:00
}
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);
2001-11-11 12:07:39 +00:00
return FALSE;
2001-08-17 05:46:24 +00:00
}
fread(&usrconfig, usrconfighdr.recsize, 1, pUsrConfig);
exitinfo = usrconfig;
fclose(pUsrConfig);
2001-11-12 21:42:17 +00:00
sprintf(temp, "%s/%s/exitinfo", CFG.bbs_usersdir, usrconfig.Name);
2001-11-11 12:07:39 +00:00
if ((pExitinfo = fopen(temp, "w+b")) == NULL) {
2001-08-17 05:46:24 +00:00
WriteError("$Can't open %s for writing", temp);
2001-11-11 12:07:39 +00:00
free(temp);
return FALSE;
} else {
2001-08-17 05:46:24 +00:00
fwrite(&exitinfo, sizeof(exitinfo), 1, pExitinfo);
fclose(pExitinfo);
2001-11-12 21:42:17 +00:00
if (chmod(temp, 0600))
WriteError("$Can't chmod 0600 %s", temp);
2001-08-17 05:46:24 +00:00
}
free(temp);
2001-11-11 12:07:39 +00:00
return TRUE;
2001-08-17 05:46:24 +00:00
}
/*
* Function will re-read users file in memory, so the latest information
* is available to other functions
*/
void ReadExitinfo()
{
FILE *pExitinfo;
char *temp;
temp = calloc(PATH_MAX, sizeof(char));
2001-11-12 21:42:17 +00:00
sprintf(temp, "%s/%s/exitinfo", CFG.bbs_usersdir, sUnixName);
2001-08-17 05:46:24 +00:00
mkdirs(temp);
2001-11-12 21:42:17 +00:00
if ((pExitinfo = fopen(temp,"r+b")) == NULL)
2001-08-17 05:46:24 +00:00
InitExitinfo();
else {
fflush(stdin);
fread(&exitinfo, sizeof(exitinfo), 1, pExitinfo);
fclose(pExitinfo);
}
free(temp);
}
/*
* Function will rewrite userinfo from memory, so the latest information
* is available to other functions
*/
void WriteExitinfo()
{
FILE *pExitinfo;
char *temp;
temp = calloc(PATH_MAX, sizeof(char));
2001-11-12 21:42:17 +00:00
sprintf(temp, "%s/%s/exitinfo", CFG.bbs_usersdir, sUnixName);
if ((pExitinfo = fopen(temp,"w+b")) == NULL)
2001-08-17 05:46:24 +00:00
WriteError("$WriteExitinfo() failed");
else {
fwrite(&exitinfo, sizeof(exitinfo), 1, pExitinfo);
fclose(pExitinfo);
}
free(temp);
}