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

823 lines
21 KiB
C
Raw Normal View History

2001-08-17 05:46:24 +00:00
/*****************************************************************************
*
* $Id$
2001-08-17 05:46:24 +00:00
* Purpose ...............: New User login under Unix, creates both
* BBS and unix accounts.
*
*****************************************************************************
2005-08-11 20:20:22 +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-11-12 21:42:17 +00:00
#include "funcs.h"
#include "input.h"
2001-08-17 05:46:24 +00:00
#include "newuser.h"
#include "language.h"
#include "timeout.h"
#include "change.h"
#include "dispfile.h"
#include "term.h"
2004-11-03 20:48:45 +00:00
#include "ttyio.h"
#include "openport.h"
2001-08-17 05:46:24 +00:00
2001-11-12 21:42:17 +00:00
/*
* Internal prototypes
*/
char *NameGen(char *); /* Get and test for unix login */
char *NameCreate(char *, char *, char *); /* Create users login in passwd file */
int BadNames(char *); /* Check for Unwanted user names */
int TelephoneScan(char *, char *); /* Scans for Duplicate User Phone Numbers */
/*
* Variables
*/
extern int do_quiet; /* No logging to the screen */
extern pid_t mypid; /* Pid of this program */
char UnixName[9]; /* Unix Name */
extern char *ieHandle; /* Users Handle */
extern time_t t_start; /* Program starttime */
int do_mailout = FALSE; /* Just for linking */
2003-04-01 21:41:36 +00:00
int chat_with_sysop = FALSE; /* Just for linking */
2001-08-17 05:46:24 +00:00
2001-11-12 21:42:17 +00:00
/*
* The main newuser registration function
*/
int newuser()
2001-08-17 05:46:24 +00:00
{
2002-07-08 19:40:22 +00:00
FILE *pUsrConfig;
int i, x, Found, iLang, recno = 0, Count = 0, badname;
unsigned long crc;
char temp[PATH_MAX], *FullName, *temp1, *temp2, *Phone1, *Phone2;
long offset;
struct userrec us;
IsDoing("New user login");
Syslog('+', "Newuser registration");
clear();
DisplayFile((char *)"newuser");
if ((iLang = Chg_Language(TRUE)) == 0)
2002-10-20 20:58:55 +00:00
Fast_Bye(MBERR_INIT_ERROR);
2002-07-08 19:40:22 +00:00
Enter(1);
/* MBSE BBS - NEW USER REGISTRATION */
language(CYAN, BLACK, 37);
Enter(2);
memset(&usrconfig, 0, sizeof(usrconfig));
memset(&exitinfo, 0, sizeof(exitinfo));
temp1 = calloc(81, sizeof(char));
temp2 = calloc(81, sizeof(char));
Phone1 = calloc(81, sizeof(char));
Phone2 = calloc(81, sizeof(char));
FullName = calloc(81, sizeof(char));
usrconfig.iLanguage = iLang;
2005-08-11 20:20:22 +00:00
/* Set default editor */
if (strlen(CFG.externaleditor))
exitinfo.MsgEditor = EXTEDIT;
else
usrconfig.MsgEditor = FSEDIT;
2002-07-08 19:40:22 +00:00
do {
/* Please enter your First and Last name: */
language(CYAN, BLACK, 0);
alarm_on();
Getname(temp, 35);
strcpy(FullName, tlcap(temp));
Syslog('+', "Name entered: %s", FullName);
/*
* Secret escape name
*/
if ((strcasecmp(temp, "off")) == 0) {
Syslog('+', "Quick \"off\" logout");
2002-10-20 20:58:55 +00:00
Fast_Bye(MBERR_OK);
2002-07-08 19:40:22 +00:00
}
2001-08-17 05:46:24 +00:00
2002-07-08 19:40:22 +00:00
Count++;
if (Count >= CFG.iCRLoginCount) {
Enter(1);
/* Disconnecting user ... */
language(CFG.HiliteF, CFG.HiliteB, 2);
Enter(2);
Syslog('!', "Exceeded maximum login attempts");
2002-10-20 20:58:55 +00:00
Fast_Bye(MBERR_OK);
2002-07-08 19:40:22 +00:00
}
2001-08-17 05:46:24 +00:00
2002-07-08 19:40:22 +00:00
/*
* Check name, duplicate names, unwanted names, single names, they all get
* the same errormessage.
*/
2002-08-13 19:40:58 +00:00
badname = (BadNames(temp) || CheckName(temp) || ((strchr(temp, ' ') == NULL) && !CFG.iOneName));
2002-07-08 19:40:22 +00:00
if (badname) {
/* That login name already exists, please choose another one. */
language(LIGHTRED, BLACK, 386);
Enter(1);
}
2001-08-17 05:46:24 +00:00
2002-07-08 19:40:22 +00:00
} while (badname);
2001-08-17 05:46:24 +00:00
2002-07-08 19:40:22 +00:00
strcpy(FullName, tlcap(temp));
2002-07-08 19:40:22 +00:00
while (TRUE) {
Enter(1);
/* Please enter new password : */
language(LIGHTCYAN, BLACK, 39);
alarm_on();
Getpass(temp1);
if ((x = strlen(temp1)) >= CFG.password_length) {
Enter(1);
/* Please enter password again : */
language(LIGHTCYAN, BLACK, 40);
alarm_on();
2002-07-08 19:40:22 +00:00
Getpass(temp2);
if ((i = strcmp(temp1,temp2)) != 0) {
Enter(2);
2002-07-08 19:40:22 +00:00
/* Your passwords do not match! Try again. */
language(LIGHTRED, BLACK, 41);
Enter(1);
2002-07-08 19:40:22 +00:00
} else {
crc = StringCRC32(tu(temp1));
break;
}
2002-07-08 19:40:22 +00:00
} else {
Enter(2);
/* Your password must contain at least */
language(LIGHTRED, BLACK, 42);
2005-08-29 10:59:47 +00:00
snprintf(temp, 81, "%d ", CFG.password_length);
2004-11-03 20:48:45 +00:00
PUTSTR(temp);
2002-07-08 19:40:22 +00:00
/* characters! Try again. */
language(WHITE, BLACK, 43);
Enter(1);
}
}
2001-08-17 05:46:24 +00:00
2002-07-08 19:40:22 +00:00
memset(&usrconfig.Password, 0, sizeof(usrconfig.Password));
2005-08-29 10:59:47 +00:00
snprintf(usrconfig.Password, Max_passlen +1, "%s", temp2);
2002-07-08 19:40:22 +00:00
alarm_on();
2005-08-29 10:59:47 +00:00
snprintf(UnixName, 9, "%s", (char *) NameCreate(NameGen(FullName), FullName, temp2));
UserCity(mypid, UnixName, (char *)"Unknown");
2002-07-08 19:40:22 +00:00
strcpy(usrconfig.sUserName, FullName);
strcpy(usrconfig.Name, UnixName);
Time_Now = time(NULL);
l_date = localtime(&Time_Now);
ltime = time(NULL);
2002-07-08 19:40:22 +00:00
if (CFG.iAnsi) {
Enter(2);
/* Do you want ANSI and graphics mode [Y/n]: */
language(LIGHTGRAY, BLACK, 44);
2001-08-17 05:46:24 +00:00
alarm_on();
2002-07-08 19:40:22 +00:00
i = toupper(getchar());
2002-07-08 19:40:22 +00:00
if (i == Keystroke(44, 0) || i == '\n')
usrconfig.GraphMode = TRUE;
else
usrconfig.GraphMode = FALSE;
} else {
usrconfig.GraphMode = TRUE; /* Default set it to ANSI */
Enter(1);
}
exitinfo.GraphMode = usrconfig.GraphMode;
2004-02-21 17:22:00 +00:00
TermInit(exitinfo.GraphMode, 80, 24);
2002-07-08 19:40:22 +00:00
if (CFG.iVoicePhone) {
while (1) {
Enter(1);
/* Please enter you Voice Number */
language(LIGHTGREEN, BLACK, 45);
Enter(1);
pout(LIGHTGREEN, BLACK, (char *)": ");
colour(CFG.InputColourF, CFG.InputColourB);
alarm_on();
GetPhone(temp, 16);
2001-08-17 05:46:24 +00:00
2002-07-08 19:40:22 +00:00
if (strlen(temp) < 6) {
Enter(1);
/* Please enter a proper phone number */
language(LIGHTRED, BLACK, 47);
Enter(1);
} else {
strcpy(usrconfig.sVoicePhone, temp);
strcpy(Phone1, temp);
break;
}
}
} /* End of first if statement */
2001-08-17 05:46:24 +00:00
2002-07-08 19:40:22 +00:00
if (CFG.iDataPhone) {
while (TRUE) {
Enter(1);
/* Please enter you Data Number */
language(LIGHTGREEN, BLACK, 48);
Enter(1);
2001-08-17 05:46:24 +00:00
2002-07-08 19:40:22 +00:00
pout(LIGHTGREEN, BLACK, (char *)": ");
colour(CFG.InputColourF, CFG.InputColourB);
alarm_on();
GetPhone(temp, 16);
/*
* If no dataphone, copy voicephone.
*/
if (strcmp(temp, "") == 0) {
strcpy(usrconfig.sDataPhone, usrconfig.sVoicePhone);
break;
}
if (strlen(temp) < 6) {
2001-08-17 05:46:24 +00:00
Enter(1);
2002-07-08 19:40:22 +00:00
/* Please enter a proper phone number */
language(LIGHTRED, BLACK, 47);
Enter(1);
} else {
strcpy(usrconfig.sDataPhone, temp);
strcpy(Phone2, temp);
break;
}
2001-08-17 05:46:24 +00:00
}
2002-07-08 19:40:22 +00:00
} /* End of if Statement */
2001-11-02 22:34:32 +00:00
2002-07-08 19:40:22 +00:00
if (!CFG.iDataPhone)
2004-11-03 20:48:45 +00:00
Enter(1);
2002-07-08 19:40:22 +00:00
if (CFG.iLocation) {
while (TRUE) {
Enter(1);
/* Enter your location */
language(YELLOW, BLACK, 49);
colour(CFG.InputColourF, CFG.InputColourB);
alarm_on();
if (CFG.iCapLocation) { /* Cap Location is turned on, Capitalise first letter */
GetnameNE(temp, 24);
} else
GetstrC(temp, 80);
if (strlen(temp) < CFG.CityLen) {
2001-11-02 22:34:32 +00:00
Enter(1);
2002-07-08 19:40:22 +00:00
/* Please enter a longer location */
language(LIGHTRED, BLACK, 50);
2001-11-02 22:34:32 +00:00
Enter(1);
2005-08-29 10:59:47 +00:00
snprintf(temp, 81, "%s%d)", (char *) Language(74), CFG.CityLen);
2004-11-03 20:48:45 +00:00
PUTSTR(temp);
2001-11-02 22:34:32 +00:00
Enter(1);
2002-07-08 19:40:22 +00:00
} else {
strcpy(usrconfig.sLocation, temp);
UserCity(mypid, UnixName, temp);
2002-07-08 19:40:22 +00:00
break;
2001-11-02 22:34:32 +00:00
}
2001-08-17 05:46:24 +00:00
}
2002-07-08 19:40:22 +00:00
}
2001-08-17 05:46:24 +00:00
2002-07-08 19:40:22 +00:00
if (CFG.AskAddress) {
while (TRUE) {
Enter(1);
/* Your address, maximum 3 lines (only visible for the sysop): */
language(LIGHTMAGENTA, BLACK, 474);
Enter(1);
for (i = 0; i < 3; i++) {
2005-08-29 10:59:47 +00:00
snprintf(temp, 81, "%d: ", i+1);
2004-11-03 20:48:45 +00:00
pout(YELLOW, BLACK, temp);
2001-08-17 05:46:24 +00:00
colour(CFG.InputColourF, CFG.InputColourB);
alarm_on();
2002-07-08 19:40:22 +00:00
GetstrC(usrconfig.address[i], 40);
}
if (strlen(usrconfig.address[0]) || strlen(usrconfig.address[1]) || strlen(usrconfig.address[2]))
break;
Enter(1);
/* You need to enter your address here */
language(LIGHTRED, BLACK, 475);
Enter(1);
}
}
if (CFG.iHandle) {
do {
Enter(1);
/* Enter a handle (Enter to Quit): */
language(LIGHTRED, BLACK, 412);
colour(CFG.InputColourF, CFG.InputColourB);
alarm_on();
Getname(temp, 34);
2001-08-17 05:46:24 +00:00
2002-07-28 12:31:28 +00:00
badname = (strlen(temp) && (BadNames(temp) || CheckName(temp) || CheckUnixNames(temp)));
2002-07-08 19:40:22 +00:00
if (badname) {
2002-07-28 12:31:28 +00:00
Syslog('+', "User tried \"%s\" as Handle", MBSE_SS(temp));
2002-07-08 19:40:22 +00:00
/* That login name already exists, please choose another one. */
language(LIGHTRED, BLACK, 386);
Enter(1);
} else {
2001-08-17 05:46:24 +00:00
if(strcmp(temp, "") == 0)
2002-07-08 19:40:22 +00:00
strcpy(usrconfig.sHandle, "");
2001-08-17 05:46:24 +00:00
else
2002-07-08 19:40:22 +00:00
strcpy(usrconfig.sHandle, temp);
}
} while (badname);
}
2001-08-17 05:46:24 +00:00
2002-07-08 19:40:22 +00:00
/*
* Note, the users database always contains the english sex
*/
if (CFG.iSex) {
while (TRUE) {
Enter(1);
/* What is your sex? (M)ale or (F)emale: */
language(LIGHTBLUE, BLACK, 51);
colour(CFG.InputColourF, CFG.InputColourB);
alarm_on();
2004-11-03 20:48:45 +00:00
i = toupper(Readkey());
2001-08-17 05:46:24 +00:00
2002-07-08 19:40:22 +00:00
if (i == Keystroke(51, 0)) {
/* Male */
2005-08-29 10:59:47 +00:00
snprintf(usrconfig.sSex, 8, "Male");
2002-07-08 19:40:22 +00:00
pout(CFG.InputColourF, CFG.InputColourB, (char *) Language(52));
2001-08-17 05:46:24 +00:00
Enter(1);
2002-07-08 19:40:22 +00:00
break;
} else if (i == Keystroke(51, 1)) {
/* Female */
2005-08-29 10:59:47 +00:00
snprintf(usrconfig.sSex, 8, "Female");
2002-07-08 19:40:22 +00:00
pout(CFG.InputColourF, CFG.InputColourB, (char *) Language(53));
Enter(1);
break;
} else {
Enter(2);
/* Please answer M or F */
language(LIGHTRED, BLACK, 54);
Enter(1);
}
}
} else /* End of if Statement */
2005-08-29 10:59:47 +00:00
snprintf(usrconfig.sSex, 8, "Unknown"); /* If set off, set to Unknown */
2002-07-08 19:40:22 +00:00
if (CFG.iDOB) {
while (TRUE) {
Enter(1);
/* Please enter your Date of Birth DD-MM-YYYY: */
pout(CYAN, BLACK, (char *) Language(56));
colour(CFG.InputColourF, CFG.InputColourB);
alarm_on();
GetDate(temp, 10);
2001-08-17 05:46:24 +00:00
2005-08-29 10:59:47 +00:00
snprintf(temp1, 81, "%c%c%c%c", temp[6], temp[7], temp[8], temp[9]);
snprintf(temp2, 81, "%02d", l_date->tm_year);
2002-07-08 19:40:22 +00:00
iLang = atoi(temp2) + 1900;
2005-08-29 10:59:47 +00:00
snprintf(temp2, 81, "%04d", iLang);
2001-08-17 05:46:24 +00:00
2002-07-08 19:40:22 +00:00
if ((strcmp(temp1,temp2)) == 0) {
Enter(1);
/* Sorry you entered this year by mistake. */
pout(LIGHTRED, BLACK, (char *) Language(57));
Enter(1);
} else {
if((strlen(temp)) != 10) {
Enter(1);
2002-07-08 19:40:22 +00:00
/* Please enter the correct date format */
pout(LIGHTRED, BLACK, (char *) Language(58));
Enter(1);
} else {
2002-07-08 19:40:22 +00:00
strcpy(usrconfig.sDateOfBirth,temp);
break;
}
}
2001-08-17 05:46:24 +00:00
}
2002-07-08 19:40:22 +00:00
}
2001-08-17 05:46:24 +00:00
2002-07-08 19:40:22 +00:00
usrconfig.tFirstLoginDate = ltime; /* Set first login date to current date */
usrconfig.tLastLoginDate = (time_t)0; /* To force setting new limits */
strcpy(usrconfig.sExpiryDate,"00-00-0000");
usrconfig.ExpirySec = CFG.newuser_access;
usrconfig.Security = CFG.newuser_access;
usrconfig.Email = CFG.GiveEmail;
2001-08-17 05:46:24 +00:00
2002-07-08 19:40:22 +00:00
if (CFG.iHotkeys) {
while (TRUE) {
Enter(1);
/* Would you like hot-keyed menus [Y/n]: */
pout(LIGHTRED, BLACK, (char *) Language(62));
colour(CFG.InputColourF, CFG.InputColourB);
alarm_on();
GetstrC(temp, 8);
if ((toupper(temp[0]) == Keystroke(62, 0)) || (strcmp(temp,"") == 0)) {
usrconfig.HotKeys = TRUE;
break;
}
if (toupper(temp[0]) == Keystroke(62, 1)) {
usrconfig.HotKeys = FALSE;
break;
} else {
/* Please answer Y or N */
pout(WHITE, BLACK, (char *) Language(63));
}
2001-08-17 05:46:24 +00:00
}
2002-07-08 19:40:22 +00:00
} else
usrconfig.HotKeys = TRUE; /* Default set it to Hotkeys */
usrconfig.iTimeLeft = 20; /* Set Timeleft in users file to 20 */
if (CFG.AskScreenlen) {
Enter(1);
/* Please enter your Screen Length [24]: */
pout(LIGHTMAGENTA, BLACK, (char *) Language(64));
colour(CFG.InputColourF, CFG.InputColourB);
alarm_on();
Getnum(temp, 3);
2002-07-08 19:40:22 +00:00
if(strlen(temp) == 0)
usrconfig.iScreenLen = 24;
else
usrconfig.iScreenLen = atoi(temp);
} else {
2002-07-08 19:40:22 +00:00
usrconfig.iScreenLen = 24;
}
2004-02-21 17:22:00 +00:00
TermInit(usrconfig.GraphMode, 80, usrconfig.iScreenLen);
2002-07-08 19:40:22 +00:00
alarm_on();
usrconfig.tLastPwdChange = ltime; /* Days Since Last Password Change */
usrconfig.iLastFileArea = 1;
usrconfig.iLastMsgArea = 1;
2005-08-29 10:59:47 +00:00
snprintf(usrconfig.sProtocol, 21, "%s", (char *) Language(65));
2002-07-08 19:40:22 +00:00
usrconfig.DoNotDisturb = FALSE;
switch (CFG.AskNewmail) {
case NO: usrconfig.MailScan = FALSE;
break;
case YES: usrconfig.MailScan = TRUE;
break;
default: while (TRUE) {
Enter(1);
/* Check for new mail at login [Y/n]: */
pout(LIGHTRED, BLACK, (char *) Language(26));
colour(CFG.InputColourF, CFG.InputColourB);
alarm_on();
GetstrC(temp, 8);
if ((toupper(temp[0]) == Keystroke(26, 0)) || (strcmp(temp,"") == 0)) {
usrconfig.MailScan = TRUE;
break;
}
if (toupper(temp[0]) == Keystroke(26, 1)) {
usrconfig.MailScan = FALSE;
break;
}
/* Please answer Y or N */
pout(WHITE, BLACK, (char *) Language(63));
}
break;
}
switch (CFG.AskNewfiles) {
case NO: usrconfig.ieFILE = FALSE;
break;
case YES: usrconfig.ieFILE = TRUE;
break;
default: while (TRUE) {
Enter(1);
/* Check for new files at login [Y/n]: */
pout(LIGHTRED, BLACK, (char *) Language(27));
colour(CFG.InputColourF, CFG.InputColourB);
alarm_on();
GetstrC(temp, 8);
if ((toupper(temp[0]) == Keystroke(27, 0)) || (strcmp(temp,"") == 0)) {
usrconfig.ieFILE = TRUE;
break;
}
if (toupper(temp[0]) == Keystroke(27, 1)) {
usrconfig.ieFILE = FALSE;
break;
}
/* Please answer Y or N */
pout(WHITE, BLACK, (char *) Language(63));
}
break;
}
2002-07-08 19:40:22 +00:00
usrconfig.ieNEWS = TRUE;
usrconfig.Cls = TRUE;
usrconfig.More = TRUE;
usrconfig.ieASCII8 = TRUE;
/*
* Search a free slot in the users datafile
*/
2005-08-29 10:59:47 +00:00
snprintf(temp, PATH_MAX, "%s/etc/users.data", getenv("MBSE_ROOT"));
2002-07-08 19:40:22 +00:00
if ((pUsrConfig = fopen(temp, "r+")) == NULL) {
WriteError("Can't open file: %s", temp);
2002-10-20 20:58:55 +00:00
ExitClient(MBERR_GENERAL);
2002-07-08 19:40:22 +00:00
}
fread(&usrconfighdr, sizeof(usrconfighdr), 1, pUsrConfig);
offset = ftell(pUsrConfig);
Found = FALSE;
while ((fread(&us, usrconfighdr.recsize, 1, pUsrConfig) == 1) && (!Found)) {
if (us.sUserName[0] == '\0') {
Found = TRUE;
} else {
offset = ftell(pUsrConfig);
recno++;
2001-08-17 05:46:24 +00:00
}
2002-07-08 19:40:22 +00:00
}
2001-08-17 05:46:24 +00:00
2002-07-08 19:40:22 +00:00
if (Found)
fseek(pUsrConfig, offset, SEEK_SET);
else
fseek(pUsrConfig, 0, SEEK_END);
fwrite(&usrconfig, sizeof(usrconfig), 1, pUsrConfig);
fclose(pUsrConfig);
Enter(2);
/* Your user account has been created: */
pout(YELLOW, BLACK, (char *) Language(67));
Enter(2);
/* Login Name : */
pout(LIGHTBLUE, BLACK, (char *) Language(68));
colour(CYAN, BLACK);
2005-08-29 10:59:47 +00:00
snprintf(temp, 81, "%s (%s)", UnixName, FullName);
2004-11-03 20:48:45 +00:00
PUTSTR(temp);
Enter(1);
2002-07-08 19:40:22 +00:00
/* Password : */
pout(LIGHTBLUE, BLACK, (char *) Language(69));
pout(CYAN, BLACK, (char *)"<");
/* not displayed */
pout(WHITE, BLACK, (char *) Language(70));
2004-11-03 20:48:45 +00:00
pout(CYAN, BLACK, (char *)">");
Enter(2);
2001-08-17 05:46:24 +00:00
2002-07-08 19:40:22 +00:00
if (CFG.iVoicePhone && TelephoneScan(Phone1, FullName))
Syslog('!', "Duplicate phone numbers found");
2002-07-08 19:40:22 +00:00
if (CFG.iDataPhone && TelephoneScan(Phone2, FullName))
Syslog('!', "Duplicate phone numbers found");
free(temp1);
free(temp2);
free(Phone1);
free(Phone2);
DisplayFile((char *)"registered");
Syslog('+', "Completed new-user procedure");
/* New user registration completed. */
2004-11-03 20:48:45 +00:00
poutCR(LIGHTGREEN, BLACK, (char *) Language(71));
2002-07-08 19:40:22 +00:00
/* You need to login again with the name: */
pout(LIGHTRED, BLACK, (char *) Language(5));
pout(YELLOW, BLACK, UnixName);
Enter(2);
alarm_on();
Pause();
alarm_off();
2004-11-03 20:48:45 +00:00
Enter(1);
2002-07-08 19:40:22 +00:00
return 0;
2001-08-17 05:46:24 +00:00
}
2001-11-11 12:07:39 +00:00
void Fast_Bye(int onsig)
{
2002-07-08 19:40:22 +00:00
char *temp;
2004-11-03 20:48:45 +00:00
time_t t_end;
2001-11-11 12:07:39 +00:00
2002-07-08 19:40:22 +00:00
t_end = time(NULL);
Syslog(' ', "MBNEWUSR finished in %s", t_elapsed(t_start, t_end));
socket_shutdown(mypid);
2001-11-11 12:07:39 +00:00
2002-07-08 19:40:22 +00:00
temp = calloc(PATH_MAX, sizeof(char));
2005-08-29 10:59:47 +00:00
snprintf(temp, PATH_MAX, "%s/tmp/mbnewusr%d", getenv("MBSE_ROOT"), getpid());
2002-07-08 19:40:22 +00:00
unlink(temp);
free(temp);
colour(LIGHTGRAY, BLACK);
sleep(3);
2004-11-03 20:48:45 +00:00
cookedport();
signal(SIGHUP, SIG_IGN);
2004-11-03 20:48:45 +00:00
hangup();
2002-07-08 19:40:22 +00:00
Free_Language();
free(pTTY);
2002-10-20 20:58:55 +00:00
exit(MBERR_OK);
2001-11-11 12:07:39 +00:00
}
/*
* This function is the same as Fast_Bye(), it's here
* to link the other modules properly.
*/
void Good_Bye(int onsig)
{
Fast_Bye(onsig);
}
2001-11-12 21:42:17 +00:00
/*
* Function will ask user to create a unix login
* Name cannot be longer than 8 characters
*/
char *NameGen(char *FidoName)
{
2004-03-02 20:47:23 +00:00
static char *sUserName;
2002-07-08 19:40:22 +00:00
sUserName = calloc(10, sizeof(char));
Syslog('+', "NameGen(%s)", FidoName);
2002-07-28 12:31:28 +00:00
while ((strcmp(sUserName, "") == 0) || (CheckUnixNames(sUserName)) || (strlen(sUserName) < 3)) {
2004-11-03 20:48:45 +00:00
Enter(1);
pout(LIGHTRED, BLACK, (char *) Language(381));
Enter(2);
2002-07-08 19:40:22 +00:00
/* Please enter a login name (Maximum 8 characters) */
2004-11-03 20:48:45 +00:00
poutCR(WHITE, BLACK, (char *) Language(383));
2002-07-08 19:40:22 +00:00
/* ie. John Doe, login = jdoe */
2004-11-03 20:48:45 +00:00
poutCR(WHITE, BLACK, (char *) Language(384));
2002-07-08 19:40:22 +00:00
/* login > */
2004-11-03 20:48:45 +00:00
pout(LIGHTGREEN, BLACK, (char *) Language(385));
2002-07-08 19:40:22 +00:00
GetstrU(sUserName, 7);
2002-07-28 12:31:28 +00:00
if (CheckUnixNames(sUserName)) {
2004-11-03 20:48:45 +00:00
Enter(1);
2002-07-08 19:40:22 +00:00
/* That login name already exists, please choose another one. */
2004-11-03 20:48:45 +00:00
poutCR(LIGHTRED, BLACK, (char *) Language(386));
2002-07-28 12:31:28 +00:00
Syslog('+', "Users tried to use \"%s\" as Unix name", MBSE_SS(sUserName));
2002-07-08 19:40:22 +00:00
}
}
return sUserName;
2001-11-12 21:42:17 +00:00
}
2002-07-08 19:40:22 +00:00
2001-11-12 21:42:17 +00:00
/*
* Function will create the users name in the passwd file
*/
char *NameCreate(char *Name, char *Comment, char *Password)
{
2004-03-02 20:47:23 +00:00
char *progname, *args[16], *gidstr;
2002-07-08 19:40:22 +00:00
int err;
progname = calloc(PATH_MAX, sizeof(char));
2004-03-02 20:47:23 +00:00
gidstr = calloc(10, sizeof(char));
memset(args, 0, sizeof(args));
2002-07-08 19:40:22 +00:00
/*
* Call mbuseradd, this is a special setuid root program to create
* unix acounts and home directories.
*/
2005-08-29 10:59:47 +00:00
snprintf(progname, PATH_MAX, "%s/bin/mbuseradd", getenv("MBSE_ROOT"));
snprintf(gidstr, 10, "%d", getgid());
2004-03-02 20:47:23 +00:00
args[0] = progname;
args[1] = gidstr;
args[2] = Name;
args[3] = Comment;
args[4] = CFG.bbs_usersdir;
args[5] = NULL;
if ((err = execute(args, (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null"))) {
2002-07-08 19:40:22 +00:00
WriteError("Failed to create unix account");
free(progname);
2004-03-02 20:47:23 +00:00
free(gidstr);
2002-10-20 20:58:55 +00:00
ExitClient(MBERR_GENERAL);
2002-07-08 19:40:22 +00:00
}
2004-03-02 20:47:23 +00:00
free(gidstr);
2005-08-29 10:59:47 +00:00
snprintf(progname, PATH_MAX, "%s/bin/mbpasswd", getenv("MBSE_ROOT"));
2004-03-02 20:47:23 +00:00
memset(args, 0, sizeof(args));
args[0] = progname;
2005-08-27 12:06:48 +00:00
args[1] = Name;
args[2] = Password;
args[3] = NULL;
2002-07-08 19:40:22 +00:00
2004-03-02 20:47:23 +00:00
if ((err = execute(args, (char *)"/dev/null", (char *)"/dev/null", (char *)"/dev/null"))) {
2002-07-08 19:40:22 +00:00
WriteError("Failed to set unix password");
free(progname);
2002-10-20 20:58:55 +00:00
ExitClient(MBERR_GENERAL);
2002-07-08 19:40:22 +00:00
}
2004-11-03 20:48:45 +00:00
Enter(1);
2002-07-08 19:40:22 +00:00
/* Your "Unix Account" is created, you may use it the next time you call */
2004-11-03 20:48:45 +00:00
poutCR(YELLOW, BLACK, (char *) Language(382));
2002-07-08 19:40:22 +00:00
Syslog('+', "Created Unix account %s for %s", Name, Comment);
free(progname);
return Name;
2001-11-12 21:42:17 +00:00
}
/*
* Function will check for unwanted user names
*/
int BadNames(char *Username)
{
2002-07-08 19:40:22 +00:00
FILE *fp;
int iFoundName = FALSE;
char *temp, *String, *User;
temp = calloc(PATH_MAX, sizeof(char));
String = calloc(81, sizeof(char));
User = calloc(81, sizeof(char));
strcpy(User, tl(Username));
2005-08-29 10:59:47 +00:00
snprintf(temp, PATH_MAX, "%s/etc/badnames.ctl", getenv("MBSE_ROOT"));
2002-07-08 19:40:22 +00:00
if ((fp = fopen(temp, "r")) != NULL) {
while ((fgets(String, 80, fp)) != NULL) {
strcpy(String, tl(String));
Striplf(String);
if ((strstr(User, String)) != NULL) {
2004-11-03 20:48:45 +00:00
Enter(1);
pout(LIGHTRED, BLACK, (char *)"Sorry that name is not acceptable on this system");
Enter(1);
2002-07-28 12:31:28 +00:00
Syslog('+', "User tried username \"%s\", found in %s", Username, temp);
2002-07-08 19:40:22 +00:00
iFoundName = TRUE;
break;
}
2001-11-12 21:42:17 +00:00
}
2002-07-08 19:40:22 +00:00
fclose(fp);
}
2001-11-12 21:42:17 +00:00
2002-07-08 19:40:22 +00:00
free(temp);
free(String);
free(User);
return iFoundName;
2001-11-12 21:42:17 +00:00
}
/*
* Function will Scan Users Database for existing phone numbers. If
* found, it will write a log entry to the logfile. The user WILL NOT
* be notified about the same numbers
*/
int TelephoneScan(char *Number, char *Name)
{
2002-07-08 19:40:22 +00:00
FILE *fp;
int Status = FALSE;
char *temp;
struct userhdr uhdr;
struct userrec u;
temp = calloc(PATH_MAX, sizeof(char));
2005-08-29 10:59:47 +00:00
snprintf(temp, PATH_MAX, "%s/etc/users.data", getenv("MBSE_ROOT"));
2002-07-08 19:40:22 +00:00
if ((fp = fopen(temp,"rb")) != NULL) {
fread(&uhdr, sizeof(uhdr), 1, fp);
while (fread(&u, uhdr.recsize, 1, fp) == 1) {
if (strcasecmp(u.sUserName, Name) != 0)
if ((strlen(u.sVoicePhone) && (strcmp(u.sVoicePhone, Number) == 0)) ||
(strlen(u.sDataPhone) && (strcmp(u.sDataPhone, Number) == 0))) {
Status = TRUE;
Syslog('b', "Dupe phones ref: \"%s\" voice: \"%s\" data: \"%s\"", Number, u.sVoicePhone, u.sDataPhone);
Syslog('+', "Uses the same telephone number as %s", u.sUserName);
2001-11-12 21:42:17 +00:00
}
}
2002-07-08 19:40:22 +00:00
fclose(fp);
}
2001-11-12 21:42:17 +00:00
2002-07-08 19:40:22 +00:00
free(temp);
return Status;
2001-11-12 21:42:17 +00:00
}