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

141 lines
3.6 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
*
*****************************************************************************
2005-08-29 12:19:39 +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"
2001-08-17 05:46:24 +00:00
#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
{
2003-05-08 18:59:31 +00:00
FILE *pUsrConfig, *pExitinfo;
char *temp;
long offset;
temp = calloc(PATH_MAX, sizeof(char));
2005-08-29 12:19:39 +00:00
snprintf(temp, PATH_MAX, "%s/etc/users.data", getenv("MBSE_ROOT"));
2003-05-08 18:59:31 +00:00
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);
2001-08-17 05:46:24 +00:00
free(temp);
2003-05-08 18:59:31 +00:00
return FALSE;
}
fread(&usrconfig, usrconfighdr.recsize, 1, pUsrConfig);
exitinfo = usrconfig;
fclose(pUsrConfig);
2005-08-29 12:19:39 +00:00
snprintf(temp, PATH_MAX, "%s/%s/exitinfo", CFG.bbs_usersdir, usrconfig.Name);
2003-05-08 18:59:31 +00:00
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;
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()
{
2003-05-08 18:59:31 +00:00
FILE *pExitinfo;
char *temp;
temp = calloc(PATH_MAX, sizeof(char));
2005-08-29 12:19:39 +00:00
snprintf(temp, PATH_MAX, "%s/%s/exitinfo", CFG.bbs_usersdir, sUnixName);
2003-05-08 18:59:31 +00:00
mkdirs(temp, 0770);
if ((pExitinfo = fopen(temp,"r+b")) == NULL)
InitExitinfo();
else {
fflush(stdin);
fread(&exitinfo, sizeof(exitinfo), 1, pExitinfo);
fclose(pExitinfo);
}
free(temp);
2001-08-17 05:46:24 +00:00
}
/*
* Function will rewrite userinfo from memory, so the latest information
* is available to other functions
*/
void WriteExitinfo()
{
2003-05-08 18:59:31 +00:00
FILE *pExitinfo;
char *temp;
temp = calloc(PATH_MAX, sizeof(char));
2005-08-29 12:19:39 +00:00
snprintf(temp, PATH_MAX, "%s/%s/exitinfo", CFG.bbs_usersdir, sUnixName);
2003-05-08 18:59:31 +00:00
if ((pExitinfo = fopen(temp,"w+b")) == NULL)
WriteError("$WriteExitinfo() failed");
else {
fwrite(&exitinfo, sizeof(exitinfo), 1, pExitinfo);
fclose(pExitinfo);
}
free(temp);
2001-08-17 05:46:24 +00:00
}