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/user.c
2001-11-10 17:14:16 +00:00

554 lines
13 KiB
C

/*****************************************************************************
*
* $Id$
* Purpose ...............: Main user login procedure. Checks for limits,
* new ratio's cats all the welcome screens, and
* does a lot of checking in general.
*
*****************************************************************************
* 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 "timeout.h"
#include "user.h"
#include "pwcheck.h"
#include "dispfile.h"
#include "funcs4.h"
#include "input.h"
#include "misc.h"
#include "bye.h"
#include "file.h"
#include "mail.h"
#include "change.h"
#include "menu.h"
#include "exitinfo.h"
#include "language.h"
#include "offline.h"
#include "statetbl.h"
#include "email.h"
extern int sock;
extern pid_t mypid;
char *StartTime;
/*
* Non global function prototypes
*/
void SwapDate(char *, char *); /* Swap two Date strings around */
char *Passwd = NULL;
/*
* Function will take two date strings in the following format DD-MM-YYYY and
* swap them around in the following format YYYYMMDD
* ie. 01-02-1995 will become 19950201 so that the leading Zeros are not in
* the beginning as leading Zeros will fall away if you try compare the
* two with a if statement (Millenium proof).
*/
void SwapDate(char *Date3, char *Date4)
{
char *temp2, *temp3;
temp2 = calloc(10, sizeof(char));
temp3 = calloc(10, sizeof(char));
Date1 = calloc(10, sizeof(char));
Date2 = calloc(10, sizeof(char));
temp2[0] = Date3[6];
temp2[1] = Date3[7];
temp2[2] = Date3[8];
temp2[3] = Date3[9];
temp2[4] = Date3[3];
temp2[5] = Date3[4];
temp2[6] = Date3[0];
temp2[7] = Date3[1];
temp2[8] = '\0';
temp3[0] = Date4[6];
temp3[1] = Date4[7];
temp3[2] = Date4[8];
temp3[3] = Date4[9];
temp3[4] = Date4[3];
temp3[5] = Date4[4];
temp3[6] = Date4[0];
temp3[7] = Date4[1];
temp3[8] = '\0';
strcpy(Date1, temp2);
strcpy(Date2, temp3);
free(temp2);
free(temp3);
}
void user()
{
FILE *pUsrConfig, *pLimits;
int i, x;
int FoundName = FALSE, iFoundLimit = FALSE;
register int recno;
int lrecno = 0;
long l1, l2;
unsigned crc = 0;
char *token;
char temp[PATH_MAX];
char temp1[84];
char sGetName[84];
char *FileName;
char *handle;
struct passwd *pw;
char *sGetPassword;
long offset;
time_t LastLogin;
struct stat st;
char UserName[36];
int IsNew = FALSE;
recno=0;
Syslog('+', "Unixmode login: %s", sUnixName);
if ((pw = getpwnam(sUnixName)))
strcpy(sGetName, pw->pw_gecos);
/*
* If there are more fields in the passwd gecos field
* then only get the first field.
*/
if (strchr(sGetName, ',') != NULL)
strcpy(sGetName, strtok(sGetName, ","));
if (!(CheckName(sGetName))) {
printf("Unknown username: %s\n", sGetName);
/* FATAL ERROR: You are not in the BBS users file.*/
printf("%s\n", (char *) Language(389));
/* Please run 'newuser' to create an account */
printf("%s\n", (char *) Language(390));
Syslog('?', "FATAL: Could not find user in BBS users file.");
Syslog('?', " and system is using unix accounts\n");
free(Passwd);
ExitClient(0);
}
if (CFG.iCapUserName || SYSOP)
strcpy(sGetName, tlcap(sGetName));
/*
* Copy username, split first and lastname.
*/
strcpy(UserName, tlcap(sGetName));
if ((strchr(sGetName,' ') == NULL && !CFG.iOneName)) {
token = strtok(sGetName, " ");
strcpy(FirstName, token);
token = strtok(NULL, "\0");
i = strlen(token);
for(x = 2; x < i; x++) {
if(token[x] == ' ')
token[x] = '\0';
}
strcpy(LastName, token);
} else
strcpy(FirstName, sGetName);
Syslog('+', "%s On-Line at %s", UserName, ttyinfo.comment);
/*
* Check some essential files, create them if they don't exist.
*/
ChkFiles();
sprintf(temp, "%s/etc/users.data", getenv("MBSE_ROOT"));
if ((pUsrConfig = fopen(temp,"r+b")) == NULL) {
/*
* This should only happen once, when you build the BBS
*/
WriteError("Can't open users file: %s", temp);
printf("Can't open userfile, run \"newuser\" first");
free(Passwd);
ExitClient(0);
}
handle = calloc(40, sizeof(char));
fread(&usrconfighdr, sizeof(usrconfighdr), 1, pUsrConfig);
strcpy(temp1, UserName);
while (fread(&usrconfig, usrconfighdr.recsize, 1, pUsrConfig) == 1) {
strcpy(temp, usrconfig.sUserName);
strcpy(handle, usrconfig.sHandle);
if ((strcasecmp(temp, temp1) == 0 || strcasecmp(handle, temp1) == 0)) {
FoundName = TRUE;
break;
} else
recno++;
}
free(handle);
if (!FoundName) {
Syslog('+', "Name not in user file");
Enter(1);
/* Scanning User File */
language(LIGHTGRAY, BLACK, 3);
Enter(1);
usrconfig.GraphMode = FALSE;
DisplayFile((char *)"notfound");
Enter(1);
/* Name entered: */
language(LIGHTGRAY, BLACK, 5);
printf("%s\n\n", UserName);
/* Did you spell your name correctly [Y/n] */
language(WHITE, BLACK, 4);
fflush(stdout);
fflush(stdin);
i = toupper(Getone());
if (i == Keystroke(4, 0) || i == '\r') {
/*
* Here we run newuser.
*/
Syslog('+', "Creating user ...");
// recno = newuser(UserName);
Quick_Bye(0);
IsNew = TRUE;
} else {
Enter(1);
Syslog('+', "User spelt his/her name incorrectly");
user();
}
}
/*
* Setup users favourite language.
*/
Set_Language(usrconfig.iLanguage);
Free_Language();
InitLanguage();
/*
* User logged in, tell it to the server.
*/
UserCity(mypid, usrconfig.sUserName, usrconfig.sLocation);
/*
* See if this user is the Sysop.
*/
strcpy(temp, UserName);
strcpy(temp1, CFG.sysop_name);
if ((strcasecmp(temp1, temp)) == 0)
SYSOP = TRUE; /* If login name is sysop, set SYSOP true */
grecno = recno;
/*
* Is this a new user?
*/
if (usrconfig.iTotalCalls == 0)
IsNew = TRUE;
offset = usrconfighdr.hdrsize + (recno * usrconfighdr.recsize);
if (fseek(pUsrConfig, offset, 0) != 0) {
printf("Can't move pointer there.");
getchar();
free(Passwd);
ExitClient(1);
}
fread(&usrconfig, usrconfighdr.recsize, 1, pUsrConfig);
TermInit(usrconfig.GraphMode);
sGetPassword = malloc(Max_passlen+1);
crc = usrconfig.iPassword;
sprintf(Passwd, "%s", usrconfig.Password);
IsDoing("Just Logged In");
alarm_on();
Pause();
if (usrconfig.Archiver[0] == '\0') {
usrconfig.Archiver[0] = 'Z';
usrconfig.Archiver[1] = 'I';
usrconfig.Archiver[2] = 'P';
Syslog('+', "Setup default archiver ZIP");
}
recno = 0;
free(sGetPassword);
/*
* Check users date format. We do it strict as we
* need this to be good for several other purposes.
* If it is correct, the users age is set in UserAge
*/
if (!Test_DOB(usrconfig.sDateOfBirth)) {
Syslog('!', "Error in Date of Birth");
Chg_DOB();
strcpy(usrconfig.sDateOfBirth, exitinfo.sDateOfBirth);
}
/*
* Check to see if user must expire
*/
sprintf(temp,"%s", (char *) GetDateDMY());
SwapDate(temp, usrconfig.sExpiryDate);
/* Convert Date1 & Date2 to longs for compare */
l1 = atol(Date1);
l2 = atol(Date2);
if(l1 >= l2 && l2 != 0) {
/*
* If Expiry Date is the same as today expire to
* Expire Sec level
*/
usrconfig.Security = usrconfig.ExpirySec;
Syslog('!', "User is expired, resetting level");
/*
* Show texfile to user telling him about this.
*/
DisplayFile((char *)"expired");
}
free(Date1);
free(Date2);
/*
* Copy limits.data into memory
*/
FileName = calloc(84, sizeof(char));
sprintf(FileName, "%s/etc/limits.data", getenv("MBSE_ROOT"));
if(( pLimits = fopen(FileName,"rb")) == NULL) {
perror("");
WriteError("Can't open file: %s", FileName);
} else {
fread(&LIMIThdr, sizeof(LIMIThdr), 1, pLimits);
while (fread(&LIMIT, sizeof(LIMIT), 1, pLimits) == 1) {
if (LIMIT.Security == usrconfig.Security.level) {
iFoundLimit = TRUE;
break;
} else
lrecno++;
}
fclose(pLimits);
}
free(FileName);
if(!iFoundLimit) {
Syslog('?', "Unknown Security Level in limits.data");
usrconfig.iTimeLeft = 0; /* Could not find limit, so set to Zero */
usrconfig.iTimeUsed = 0; /* Set to Zero as well */
} else {
/*
* Give user new time limit everyday, also new users get a new limit.
*/
sprintf(temp,"%s", (char *) GetDateDMY());
if (((strcmp(StrDateDMY(usrconfig.tLastLoginDate), temp)) != 0) || IsNew) {
/*
* If no timelimit set give user 24 hours.
*/
if (LIMIT.Time)
usrconfig.iTimeLeft = LIMIT.Time;
else
usrconfig.iTimeLeft = 86400;
usrconfig.iTimeUsed = 0; /* Set time used today to Zero */
usrconfig.iConnectTime = 0; /* Set connect time to Zero */
/*
* Give user new bytes and files every day if needed.
*/
if (LIMIT.DownK && LIMIT.DownF) {
usrconfig.DownloadKToday = LIMIT.DownK;
usrconfig.DownloadsToday = LIMIT.DownF;
}
}
} /* End of else */
usrconfig.iConnectTime = 0;
/* Copy Users Protocol into Memory */
Set_Protocol(usrconfig.sProtocol);
tlf(usrconfig.sProtocol);
/*
* Set last login Date and Time, copy previous session
* values in memory.
*/
sprintf(LastLoginDate, "%s", StrDateDMY(usrconfig.tLastLoginDate));
sprintf(LastLoginTime, "%s", StrTimeHMS(usrconfig.tLastLoginDate));
LastLogin = usrconfig.tLastLoginDate;
usrconfig.tLastLoginDate = ltime; /* Set current login to current date */
usrconfig.iTotalCalls++;
memset(&usrconfig.Password, 0, sizeof(usrconfig.Password));
sprintf(usrconfig.Password, "%s", Passwd);
/*
* Update user record.
*/
if (fseek(pUsrConfig, offset, 0) != 0)
WriteError("Can't move pointer in file: %s", temp);
else {
fwrite(&usrconfig, sizeof(usrconfig), 1, pUsrConfig);
fclose(pUsrConfig);
}
/*
* Write users structure to tmp file in ~/tmp
*/
InitExitinfo();
GetLastUser();
StartTime = xstrcpy(GetLocalHM());
ChangeHomeDir(exitinfo.Name, exitinfo.Email);
Syslog('+', "User successfully logged into BBS");
Syslog('+', "Level %d (%s), %d mins. left, port %s",
usrconfig.Security.level, LIMIT.Description, usrconfig.iTimeLeft, pTTY);
time(&Time2Go);
Time2Go += usrconfig.iTimeLeft * 60;
iUserTimeLeft = usrconfig.iTimeLeft;
DisplayFile((char *)"mainlogo");
DisplayFile((char *)"welcome");
/*
* The following files are only displayed if the user has
* turned the Bulletins on.
*/
if (exitinfo.ieNEWS) {
DisplayFile((char *)"welcome1");
DisplayFile((char *)"welcome2");
DisplayFile((char *)"welcome3");
DisplayFile((char *)"welcome4");
DisplayFile((char *)"welcome5");
DisplayFile((char *)"welcome6");
DisplayFile((char *)"welcome7");
DisplayFile((char *)"welcome8");
DisplayFile((char *)"welcome9");
sprintf(temp, "%s", (char *) GetDateDMY() );
if ((strcmp(usrconfig.sDateOfBirth, temp)) == 0)
DisplayFile((char *)"birthday");
/*
* Displays file if it exists DD-MM.A??
*/
sprintf(temp, "%s", (char *) GetDateDMY());
strcpy(temp1, "");
strncat(temp1, temp, 5);
sprintf(temp, "%s", temp1);
DisplayFile(temp);
/*
* Displays users security file if it exists
*/
sprintf(temp, "sec%d", usrconfig.Security.level);
DisplayFile(temp);
/*
* Display News file
*/
DisplayFile((char *)"news");
}
/*
* Display Onceonly file, first get the date of that
* file, search order is the same as in DisplayFile()
*/
st.st_mtime = 0;
if (usrconfig.GraphMode) {
sprintf(temp, "%s/onceonly.ans", lang.TextPath);
stat(temp, &st);
if (st.st_mtime == 0) {
sprintf(temp, "%s/onceonly.ans", CFG.bbs_txtfiles);
stat(temp, &st);
}
}
if (st.st_mtime == 0) {
sprintf(temp, "%s/onceonly.asc", lang.TextPath);
stat(temp, &st);
if (st.st_mtime == 0) {
sprintf(temp, "%s/onceonly.asc", CFG.bbs_txtfiles);
stat(temp, &st);
}
}
if ((st.st_mtime != 0) && (LastLogin < st.st_mtime))
DisplayFile((char *)"onceonly");
OLR_SyncTags();
if (usrconfig.MailScan)
CheckMail();
/*
* We don't show new files to new users, their lastlogin
* date is not yet set so they would see all the files
* which can be boring...
*/
if (usrconfig.ieFILE && (!IsNew))
NewfileScan(FALSE);
/*
* Copy last file Area in to current Area
*/
SetFileArea(usrconfig.iLastFileArea);
/*
* Copy Last Message Area in to Current Msg Area
*/
SetMsgArea(usrconfig.iLastMsgArea);
SetEmailArea((char *)"mailbox");
/*
* Set or Reset the DoNotDisturb flag, now is the time
* we may be interrupted.
*/
UserSilent(usrconfig.DoNotDisturb);
/*
* Start the menu, but first, wipe the password.
*/
memset(Passwd, 0, sizeof(Passwd));
free(Passwd);
menu();
}