2001-08-17 05:46:24 +00:00
|
|
|
/*****************************************************************************
|
|
|
|
*
|
2001-11-10 17:14:16 +00:00
|
|
|
* $Id$
|
2001-08-17 05:46:24 +00:00
|
|
|
* Purpose ...............: Misc functions
|
|
|
|
*
|
|
|
|
*****************************************************************************
|
2002-01-07 19:16:03 +00:00
|
|
|
* Copyright (C) 1997-2002
|
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
|
|
|
|
* Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
#include "../lib/libs.h"
|
|
|
|
#include "../lib/mbse.h"
|
|
|
|
#include "../lib/structs.h"
|
2002-01-07 19:16:03 +00:00
|
|
|
#include "../lib/users.h"
|
2001-08-17 05:46:24 +00:00
|
|
|
#include "../lib/records.h"
|
|
|
|
#include "../lib/common.h"
|
|
|
|
#include "../lib/msgtext.h"
|
|
|
|
#include "../lib/msg.h"
|
|
|
|
#include "../lib/clcomm.h"
|
|
|
|
#include "funcs.h"
|
|
|
|
|
|
|
|
|
2001-11-12 21:42:17 +00:00
|
|
|
extern pid_t mypid; /* Original pid */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void UserSilent(int flag)
|
2001-08-17 05:46:24 +00:00
|
|
|
{
|
2001-11-12 21:42:17 +00:00
|
|
|
SockS("ADIS:2,%d,%d;", mypid, flag);
|
|
|
|
}
|
2001-08-17 05:46:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2001-11-12 21:42:17 +00:00
|
|
|
/*
|
|
|
|
* Check BBS open status, return FALSE if the bbs is closed.
|
|
|
|
* Display the reason why to the user.
|
|
|
|
*/
|
|
|
|
int CheckStatus()
|
|
|
|
{
|
|
|
|
static char buf[81];
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2001-11-12 21:42:17 +00:00
|
|
|
sprintf(buf, "SBBS:0;");
|
|
|
|
if (socket_send(buf) == 0) {
|
|
|
|
strcpy(buf, socket_receive());
|
|
|
|
if (strncmp(buf, "100:2,0", 7) == 0)
|
|
|
|
return TRUE;
|
|
|
|
if ((strncmp(buf, "100:2,2", 7) == 0) && (!ttyinfo.honor_zmh))
|
|
|
|
return TRUE;
|
|
|
|
buf[strlen(buf) -1] = '\0';
|
|
|
|
printf("\n\n\007*** %s ***\n\n\n", buf+8);
|
|
|
|
fflush(stdout);
|
|
|
|
}
|
|
|
|
return FALSE;
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-11-12 21:42:17 +00:00
|
|
|
/*
|
|
|
|
* Function to check if UserName exists and returns a 0 or 1
|
|
|
|
*/
|
|
|
|
int CheckName(char *Name)
|
|
|
|
{
|
|
|
|
FILE *fp;
|
|
|
|
int Status = FALSE;
|
|
|
|
char *temp, *temp1;
|
|
|
|
struct userhdr ushdr;
|
|
|
|
struct userrec us;
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2002-06-26 20:29:45 +00:00
|
|
|
temp = calloc(PATH_MAX, sizeof(char));
|
2001-11-12 21:42:17 +00:00
|
|
|
temp1 = calloc(81, sizeof(char));
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2001-11-12 21:42:17 +00:00
|
|
|
strcpy(temp1, tl(Name));
|
2001-08-17 05:46:24 +00:00
|
|
|
|
|
|
|
sprintf(temp, "%s/etc/users.data", getenv("MBSE_ROOT"));
|
2001-11-12 21:42:17 +00:00
|
|
|
if ((fp = fopen(temp,"rb")) != NULL) {
|
|
|
|
fread(&ushdr, sizeof(ushdr), 1, fp);
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2001-11-12 21:42:17 +00:00
|
|
|
while (fread(&us, ushdr.recsize, 1, fp) == 1) {
|
|
|
|
strcpy(temp, tl(us.sUserName));
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2001-11-12 21:42:17 +00:00
|
|
|
if((strcmp(temp, temp1)) == 0) {
|
|
|
|
Status = TRUE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
fclose(fp);
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
free(temp);
|
2001-11-12 21:42:17 +00:00
|
|
|
free(temp1);
|
|
|
|
return Status;
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-11-12 21:42:17 +00:00
|
|
|
/*
|
|
|
|
* Function will check and create a home directory for the user if
|
|
|
|
* needed. It will also change into the users home directory when
|
|
|
|
* they login.
|
|
|
|
*/
|
|
|
|
char *ChangeHomeDir(char *Name, int Mailboxes)
|
2001-08-17 05:46:24 +00:00
|
|
|
{
|
2001-11-12 21:42:17 +00:00
|
|
|
char *temp;
|
|
|
|
static char temp1[PATH_MAX];
|
|
|
|
FILE *fp;
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2001-11-12 21:42:17 +00:00
|
|
|
temp = calloc(PATH_MAX, sizeof(char));
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2001-11-12 21:42:17 +00:00
|
|
|
/*
|
|
|
|
* set umask bits to zero's then reset with mkdir
|
|
|
|
*/
|
|
|
|
umask(000);
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2001-11-12 21:42:17 +00:00
|
|
|
/*
|
|
|
|
* First check to see if users home directory exists
|
|
|
|
* else try create directory, as set in CFG.bbs_usersdir
|
|
|
|
*/
|
|
|
|
if ((access(CFG.bbs_usersdir, R_OK)) != 0) {
|
|
|
|
WriteError("$FATAL: Access to %s failed", CFG.bbs_usersdir);
|
|
|
|
free(temp);
|
|
|
|
ExitClient(1);
|
|
|
|
}
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2001-11-12 21:42:17 +00:00
|
|
|
sprintf(temp1, "%s/%s", CFG.bbs_usersdir, Name);
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2001-11-12 21:42:17 +00:00
|
|
|
/*
|
|
|
|
* Then check to see if users directory exists in the home dir
|
|
|
|
*/
|
|
|
|
if ((access(temp1, R_OK)) != 0) {
|
|
|
|
WriteError("$FATAL: Users homedir %s doesn't exist", temp1);
|
|
|
|
free(temp);
|
|
|
|
ExitClient(1);
|
|
|
|
}
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2001-11-12 21:42:17 +00:00
|
|
|
/*
|
|
|
|
* Change to users home directory
|
|
|
|
*/
|
|
|
|
if (chdir(temp1) != 0) {
|
|
|
|
WriteError("$FATAL: Can't change to users home dir, aborting: %s", temp1);
|
|
|
|
free(temp);
|
|
|
|
ExitClient(1);
|
|
|
|
}
|
|
|
|
setenv("HOME", temp1, 1);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check if user has a .signature file.
|
|
|
|
* If not, create a simple one.
|
|
|
|
*/
|
|
|
|
sprintf(temp, "%s/%s/.signature", CFG.bbs_usersdir, Name);
|
|
|
|
if (access(temp, R_OK)) {
|
|
|
|
Syslog('+', "Creating users .signature file");
|
|
|
|
if ((fp = fopen(temp, "w")) == NULL) {
|
|
|
|
WriteError("$Can't create %s", temp);
|
|
|
|
} else {
|
2002-06-24 21:55:03 +00:00
|
|
|
fprintf(fp, " Greetings, %s\n", exitinfo.sUserName);
|
|
|
|
if ((CFG.EmailMode == E_PRMISP) && exitinfo.Email && CFG.GiveEmail)
|
2001-11-12 21:42:17 +00:00
|
|
|
fprintf(fp, " email: %s@%s\n", exitinfo.Name, CFG.sysdomain);
|
|
|
|
fclose(fp);
|
|
|
|
}
|
|
|
|
}
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2001-11-12 21:42:17 +00:00
|
|
|
/*
|
|
|
|
* Check subdirectories, create them if they don't exist.
|
|
|
|
*/
|
|
|
|
sprintf(temp, "%s/wrk", temp1);
|
|
|
|
CheckDir(temp);
|
|
|
|
sprintf(temp, "%s/tag", temp1);
|
|
|
|
CheckDir(temp);
|
|
|
|
sprintf(temp, "%s/upl", temp1);
|
|
|
|
CheckDir(temp);
|
|
|
|
sprintf(temp, "%s/tmp", temp1);
|
|
|
|
CheckDir(temp);
|
|
|
|
sprintf(temp, "%s/.dosemu", temp1);
|
|
|
|
CheckDir(temp);
|
|
|
|
sprintf(temp, "%s/.dosemu/run", temp1);
|
|
|
|
CheckDir(temp);
|
|
|
|
sprintf(temp, "%s/.dosemu/tmp", temp1);
|
|
|
|
CheckDir(temp);
|
|
|
|
umask(007);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check users private emailboxes
|
|
|
|
*/
|
|
|
|
if (Mailboxes) {
|
|
|
|
sprintf(temp, "%s/mailbox", temp1);
|
|
|
|
if (Msg_Open(temp))
|
|
|
|
Msg_Close();
|
|
|
|
sprintf(temp, "%s/archive", temp1);
|
|
|
|
if (Msg_Open(temp))
|
|
|
|
Msg_Close();
|
|
|
|
sprintf(temp, "%s/trash", temp1);
|
|
|
|
if (Msg_Open(temp))
|
|
|
|
Msg_Close();
|
|
|
|
}
|
|
|
|
|
|
|
|
free(temp);
|
|
|
|
return temp1;
|
|
|
|
}
|
2001-08-17 05:46:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2001-11-12 21:42:17 +00:00
|
|
|
void CheckDir(char *dir)
|
|
|
|
{
|
|
|
|
if ((access(dir, R_OK) != 0)) {
|
|
|
|
Syslog('+', "Creating %s", dir);
|
|
|
|
if (mkdir(dir, 0770))
|
|
|
|
WriteError("$Can't create %s", dir);
|
|
|
|
}
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-11-12 21:42:17 +00:00
|
|
|
/*
|
|
|
|
* Function will find where MBSE is located on system and load
|
|
|
|
* the file $MBSE_ROOT/etc/config.data in memory.
|
|
|
|
*/
|
|
|
|
void FindMBSE()
|
2001-08-17 05:46:24 +00:00
|
|
|
{
|
2001-11-12 21:42:17 +00:00
|
|
|
FILE *pDataFile;
|
|
|
|
static char p[81];
|
|
|
|
char *FileName;
|
|
|
|
struct passwd *pw;
|
|
|
|
|
|
|
|
FileName = calloc(PATH_MAX, sizeof(char));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check if the environment is set, if not, then we create the
|
|
|
|
* environment from the passwd file.
|
|
|
|
*/
|
|
|
|
if (getenv("MBSE_ROOT") == NULL) {
|
|
|
|
pw = getpwnam("mbse");
|
|
|
|
memset(&p, 0, sizeof(p));
|
|
|
|
sprintf(p, "MBSE_ROOT=%s", pw->pw_dir);
|
|
|
|
putenv(p);
|
|
|
|
}
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2001-11-12 21:42:17 +00:00
|
|
|
if (getenv("MBSE_ROOT") == NULL) {
|
|
|
|
printf("FATAL ERROR: Environment variable MBSE_ROOT not set\n");
|
|
|
|
free(FileName);
|
|
|
|
#ifdef MEMWATCH
|
|
|
|
mwTerm();
|
|
|
|
#endif
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
sprintf(FileName, "%s/etc/config.data", getenv("MBSE_ROOT"));
|
|
|
|
|
|
|
|
if(( pDataFile = fopen(FileName, "rb")) == NULL) {
|
|
|
|
printf("FATAL ERROR: Can't open %s for reading!\n", FileName);
|
|
|
|
printf("Please run mbsetup to create configuration file.\n");
|
|
|
|
printf("Or check that your environment variable MBSE_ROOT is set to the BBS Path!\n");
|
|
|
|
free(FileName);
|
|
|
|
#ifdef MEMWATCH
|
|
|
|
mwTerm();
|
|
|
|
#endif
|
|
|
|
exit(1);
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
|
|
|
|
2001-11-12 21:42:17 +00:00
|
|
|
fread(&CFG, sizeof(CFG), 1, pDataFile);
|
|
|
|
free(FileName);
|
|
|
|
fclose(pDataFile);
|
|
|
|
}
|
2001-08-17 05:46:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2001-11-12 21:42:17 +00:00
|
|
|
/*
|
|
|
|
* Returns Mmm in the users language.
|
|
|
|
*/
|
|
|
|
char *GetMonth(int Month)
|
|
|
|
{
|
|
|
|
static char month[10];
|
|
|
|
|
|
|
|
switch (Month) {
|
|
|
|
case 1:
|
|
|
|
strcpy(month, *(mLanguage + 398));
|
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
strcpy(month, *(mLanguage + 399));
|
|
|
|
break;
|
|
|
|
case 3:
|
|
|
|
strcpy(month, *(mLanguage + 400));
|
|
|
|
break;
|
|
|
|
case 4:
|
|
|
|
strcpy(month, *(mLanguage + 401));
|
|
|
|
break;
|
|
|
|
case 5:
|
|
|
|
strcpy(month, *(mLanguage + 402));
|
|
|
|
break;
|
|
|
|
case 6:
|
|
|
|
strcpy(month, *(mLanguage + 403));
|
|
|
|
break;
|
|
|
|
case 7:
|
|
|
|
strcpy(month, *(mLanguage + 404));
|
|
|
|
break;
|
|
|
|
case 8:
|
|
|
|
strcpy(month, *(mLanguage + 405));
|
|
|
|
break;
|
|
|
|
case 9:
|
|
|
|
strcpy(month, *(mLanguage + 406));
|
|
|
|
break;
|
|
|
|
case 10:
|
|
|
|
strcpy(month, *(mLanguage + 407));
|
|
|
|
break;
|
|
|
|
case 11:
|
|
|
|
strcpy(month, *(mLanguage + 408));
|
|
|
|
break;
|
|
|
|
case 12:
|
|
|
|
strcpy(month, *(mLanguage + 409));
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
strcpy(month, "Unknown");
|
|
|
|
}
|
|
|
|
|
|
|
|
return(month);
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-11-12 21:42:17 +00:00
|
|
|
/* Returns DD-Mmm-YYYY */
|
|
|
|
char *GLCdateyy()
|
2001-08-17 05:46:24 +00:00
|
|
|
{
|
2001-11-12 21:42:17 +00:00
|
|
|
static char GLcdateyy[15];
|
|
|
|
char ntime[15];
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2001-12-23 16:44:18 +00:00
|
|
|
Time_Now = time(NULL);
|
2001-11-12 21:42:17 +00:00
|
|
|
l_date = localtime(&Time_Now);
|
|
|
|
|
|
|
|
sprintf(GLcdateyy,"%02d-",
|
|
|
|
l_date->tm_mday);
|
|
|
|
|
|
|
|
sprintf(ntime,"-%02d", l_date->tm_year+1900);
|
|
|
|
strcat(GLcdateyy, GetMonth(l_date->tm_mon+1));
|
|
|
|
strcat(GLcdateyy,ntime);
|
|
|
|
|
|
|
|
return(GLcdateyy);
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2001-11-12 21:42:17 +00:00
|
|
|
* Security Access Check
|
2001-08-17 05:46:24 +00:00
|
|
|
*/
|
2001-11-12 21:42:17 +00:00
|
|
|
int Access(securityrec us, securityrec ref)
|
2001-08-17 05:46:24 +00:00
|
|
|
{
|
2001-11-12 21:42:17 +00:00
|
|
|
Syslog('B', "User %5d %08lx %08lx", us.level, us.flags, ~us.flags);
|
|
|
|
Syslog('B', "Ref. %5d %08lx %08lx", ref.level, ref.flags, ref.notflags);
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2001-11-12 21:42:17 +00:00
|
|
|
if (us.level < ref.level)
|
|
|
|
return FALSE;
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2001-11-12 21:42:17 +00:00
|
|
|
if ((ref.notflags & ~us.flags) != ref.notflags)
|
|
|
|
return FALSE;
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2001-11-12 21:42:17 +00:00
|
|
|
if ((ref.flags & us.flags) != ref.flags)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
2001-08-17 05:46:24 +00:00
|
|
|
|
|
|
|
|