2001-11-10 17:14:16 +00:00
|
|
|
/*****************************************************************************
|
|
|
|
*
|
|
|
|
* $Id$
|
|
|
|
* Purpose ...............: New user registration
|
|
|
|
*
|
|
|
|
*****************************************************************************
|
2005-08-29 10:59:47 +00:00
|
|
|
* Copyright (C) 1997-2005
|
2001-11-10 17:14:16 +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-11-10 17:14:16 +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-11-10 17:14:16 +00:00
|
|
|
#include "../lib/mbse.h"
|
2002-01-07 19:16:03 +00:00
|
|
|
#include "../lib/users.h"
|
2001-11-10 17:14:16 +00:00
|
|
|
#include "mbnewusr.h"
|
|
|
|
#include "funcs.h"
|
|
|
|
#include "input.h"
|
|
|
|
#include "language.h"
|
|
|
|
#include "misc.h"
|
|
|
|
#include "timeout.h"
|
|
|
|
#include "newuser.h"
|
2004-10-27 11:08:09 +00:00
|
|
|
#include "term.h"
|
2004-11-03 20:48:45 +00:00
|
|
|
#include "ttyio.h"
|
|
|
|
#include "openport.h"
|
2001-11-10 17:14:16 +00:00
|
|
|
|
|
|
|
|
2005-10-07 20:42:35 +00:00
|
|
|
extern int do_quiet; /* Logging quiet flag */
|
2001-11-10 17:14:16 +00:00
|
|
|
time_t t_start;
|
2001-11-11 12:07:39 +00:00
|
|
|
char *StartTime;
|
2005-10-07 20:42:35 +00:00
|
|
|
int cols = 80; /* Screen columns */
|
|
|
|
int rows = 80; /* Screen rows */
|
2001-11-10 17:14:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
2004-04-09 18:31:22 +00:00
|
|
|
char *p, *tty, temp[PATH_MAX];
|
|
|
|
FILE *pTty;
|
2004-11-03 20:48:45 +00:00
|
|
|
int i, rc = 0;
|
2004-04-09 18:31:22 +00:00
|
|
|
struct passwd *pw;
|
2005-08-30 18:58:18 +00:00
|
|
|
struct winsize ws;
|
2004-04-09 18:31:22 +00:00
|
|
|
|
|
|
|
pTTY = calloc(15, sizeof(char));
|
|
|
|
tty = ttyname(1);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get MBSE_ROOT Path and load Config into Memory
|
|
|
|
*/
|
|
|
|
FindMBSE();
|
|
|
|
if (!strlen(CFG.startname)) {
|
|
|
|
printf("FATAL: No bbs startname, edit mbsetup 1.2.10\n");
|
|
|
|
exit(MBERR_CONFIG_ERROR);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set uid and gid to the "mbse" user.
|
|
|
|
*/
|
|
|
|
if ((pw = getpwnam((char *)"mbse")) == NULL) {
|
|
|
|
perror("Can't find user \"mbse\" in /etc/passwd");
|
|
|
|
exit(MBERR_INIT_ERROR);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set effective user to mbse.bbs
|
|
|
|
*/
|
|
|
|
if ((seteuid(pw->pw_uid) == -1) || (setegid(pw->pw_gid) == -1)) {
|
|
|
|
perror("Can't seteuid() or setegid() to \"mbse\" user");
|
|
|
|
exit(MBERR_INIT_ERROR);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set local time and statistic indexes.
|
|
|
|
*/
|
|
|
|
Time_Now = t_start = time(NULL);
|
|
|
|
l_date = localtime(&Time_Now);
|
|
|
|
Diw = l_date->tm_wday;
|
|
|
|
Miy = l_date->tm_mon;
|
|
|
|
ltime = time(NULL);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Initialize this client with the server. We don't know
|
|
|
|
* who is at the other end of the line, so that's what we tell.
|
|
|
|
*/
|
|
|
|
do_quiet = TRUE;
|
|
|
|
InitClient((char *)"Unknown", (char *)"mbnewusr", (char *)"Unknown",
|
2003-09-09 19:39:51 +00:00
|
|
|
CFG.logfile, CFG.bbs_loglevel, CFG.error_log, CFG.mgrlog, CFG.debuglog);
|
2004-04-09 18:31:22 +00:00
|
|
|
IsDoing("Loging in");
|
2001-11-10 17:14:16 +00:00
|
|
|
|
2004-04-09 18:31:22 +00:00
|
|
|
Syslog(' ', " ");
|
|
|
|
Syslog(' ', "MBNEWUSR v%s", VERSION);
|
2001-11-10 17:14:16 +00:00
|
|
|
|
2005-08-30 18:58:18 +00:00
|
|
|
if (ioctl(1, TIOCGWINSZ, &ws) != -1 && (ws.ws_col > 0) && (ws.ws_row > 0)) {
|
2005-10-07 20:42:35 +00:00
|
|
|
cols = ws.ws_col;
|
|
|
|
rows = ws.ws_row;
|
2005-08-30 18:58:18 +00:00
|
|
|
}
|
|
|
|
|
2004-11-03 20:48:45 +00:00
|
|
|
if ((rc = rawport()) != 0) {
|
|
|
|
WriteError("Unable to set raw mode");
|
|
|
|
Fast_Bye(MBERR_OK);;
|
|
|
|
}
|
|
|
|
|
|
|
|
Enter(2);
|
|
|
|
PUTSTR((char *)"Loading MBSE BBS New User Registration ...");
|
|
|
|
Enter(2);
|
|
|
|
|
2004-04-09 18:31:22 +00:00
|
|
|
if ((p = getenv("CONNECT")) != NULL)
|
|
|
|
Syslog('+', "CONNECT %s", p);
|
|
|
|
if ((p = getenv("CALLER_ID")) != NULL)
|
|
|
|
if (strncmp(p, "none", 4))
|
|
|
|
Syslog('+', "CALLER %s", p);
|
2005-07-03 16:14:17 +00:00
|
|
|
if ((p = getenv("TERM")) != NULL)
|
2005-10-07 21:56:12 +00:00
|
|
|
Syslog('+', "TERM=%s %dx%d", p, cols, rows);
|
|
|
|
else
|
|
|
|
Syslog('+', "TERM=invalid %dx%d", cols, rows);
|
2001-11-10 17:14:16 +00:00
|
|
|
|
2004-04-09 18:31:22 +00:00
|
|
|
sUnixName[0] = '\0';
|
2001-11-10 17:14:16 +00:00
|
|
|
|
2004-04-09 18:31:22 +00:00
|
|
|
/*
|
|
|
|
* Initialize
|
|
|
|
*/
|
|
|
|
InitLanguage();
|
2001-11-10 17:14:16 +00:00
|
|
|
|
2004-04-09 18:31:22 +00:00
|
|
|
if ((tty = ttyname(0)) == NULL) {
|
|
|
|
WriteError("Not at a tty");
|
|
|
|
Fast_Bye(MBERR_OK);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strncmp("/dev/", tty, 5) == 0)
|
2005-08-29 10:59:47 +00:00
|
|
|
snprintf(pTTY, 15, "%s", tty+5);
|
2004-04-09 18:31:22 +00:00
|
|
|
else if (*tty == '/') {
|
|
|
|
tty = strrchr(ttyname(0), '/');
|
|
|
|
++tty;
|
2005-08-29 10:59:47 +00:00
|
|
|
snprintf(pTTY, 15, "%s", tty);
|
2004-04-09 18:31:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
umask(007);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Trap signals
|
|
|
|
*/
|
|
|
|
for (i = 0; i < NSIG; i++) {
|
2004-11-03 20:48:45 +00:00
|
|
|
if ((i == SIGHUP) || (i == SIGPIPE) || (i == SIGBUS) || (i == SIGILL) || (i == SIGSEGV) || (i == SIGTERM))
|
2004-04-09 18:31:22 +00:00
|
|
|
signal(i, (void (*))die);
|
|
|
|
else if (i == SIGCHLD)
|
|
|
|
signal(i, SIG_DFL);
|
2001-11-10 17:14:16 +00:00
|
|
|
else
|
2004-04-09 18:31:22 +00:00
|
|
|
signal(i, SIG_IGN);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Default set the terminal to ANSI mode. If your logo
|
|
|
|
* is in color, the user will see color no mather what.
|
|
|
|
*/
|
2005-10-07 21:56:12 +00:00
|
|
|
TermInit(1);
|
2004-04-09 18:31:22 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Now it's time to check if the bbs is open. If not, we
|
|
|
|
* log the user off.
|
|
|
|
*/
|
|
|
|
if (CheckStatus() == FALSE) {
|
|
|
|
Syslog('+', "Kicking user out, the BBS is closed");
|
|
|
|
Fast_Bye(MBERR_OK);
|
|
|
|
}
|
|
|
|
|
2005-08-29 10:59:47 +00:00
|
|
|
snprintf(temp, 81, "MBSE BBS v%s (Release: %s) on %s/%s", VERSION, ReleaseDate, OsName(), OsCPU());
|
2004-11-03 20:48:45 +00:00
|
|
|
poutCR(YELLOW, BLACK, temp);
|
|
|
|
pout(WHITE, BLACK, (char *)COPYRIGHT);
|
|
|
|
Enter(2);
|
2004-04-09 18:31:22 +00:00
|
|
|
|
2005-10-17 11:23:11 +00:00
|
|
|
if (((p = getenv("REMOTEHOST")) != NULL) || ((p = getenv("SSH_CLIENT")) != NULL)) {
|
2005-10-08 17:58:23 +00:00
|
|
|
/*
|
|
|
|
* Network connection, no tty checking but fill a ttyinfo record.
|
|
|
|
*/
|
|
|
|
memset(&ttyinfo, 0, sizeof(ttyinfo));
|
|
|
|
snprintf(ttyinfo.comment, 41, "%s", p);
|
|
|
|
snprintf(ttyinfo.tty, 7, "%s", pTTY);
|
|
|
|
snprintf(ttyinfo.speed, 21, "10 mbit");
|
|
|
|
snprintf(ttyinfo.flags, 31, "IBN,IFC,XX");
|
|
|
|
ttyinfo.type = NETWORK;
|
|
|
|
ttyinfo.available = TRUE;
|
2005-10-17 11:23:11 +00:00
|
|
|
ttyinfo.honor_zmh = FALSE;
|
2005-10-08 17:58:23 +00:00
|
|
|
snprintf(ttyinfo.name, 36, "Network port #%d", iNode);
|
2004-04-09 18:31:22 +00:00
|
|
|
} else {
|
2005-10-08 17:58:23 +00:00
|
|
|
/*
|
|
|
|
* Check if this port is available.
|
2001-11-10 17:14:16 +00:00
|
|
|
*/
|
2005-10-08 17:58:23 +00:00
|
|
|
snprintf(temp, PATH_MAX, "%s/etc/ttyinfo.data", getenv("MBSE_ROOT"));
|
|
|
|
|
|
|
|
if ((pTty = fopen(temp, "r")) == NULL) {
|
|
|
|
WriteError("Can't read %s", temp);
|
|
|
|
} else {
|
|
|
|
fread(&ttyinfohdr, sizeof(ttyinfohdr), 1, pTty);
|
|
|
|
|
|
|
|
while (fread(&ttyinfo, ttyinfohdr.recsize, 1, pTty) == 1) {
|
|
|
|
if (strcmp(ttyinfo.tty, pTTY) == 0)
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
fclose(pTty);
|
|
|
|
|
|
|
|
if ((strcmp(ttyinfo.tty, pTTY) != 0) || (!ttyinfo.available)) {
|
|
|
|
Syslog('+', "No BBS allowed on port \"%s\"", pTTY);
|
|
|
|
PUTSTR((char *)"No BBS on this port allowed!");
|
|
|
|
Enter(2);
|
|
|
|
Fast_Bye(MBERR_OK);
|
|
|
|
}
|
2001-11-10 17:14:16 +00:00
|
|
|
}
|
2004-04-09 18:31:22 +00:00
|
|
|
}
|
2001-11-10 17:14:16 +00:00
|
|
|
|
2005-10-08 17:58:23 +00:00
|
|
|
/*
|
|
|
|
* Ask whether to display Connect String
|
|
|
|
*/
|
|
|
|
if (CFG.iConnectString) {
|
|
|
|
/* Connected from */
|
|
|
|
snprintf(temp, 81, "%s\"%s\" ", (char *) Language(348), ttyinfo.comment);
|
|
|
|
pout(CYAN, BLACK, temp);
|
|
|
|
/* line */
|
|
|
|
snprintf(temp, 81, "%s%d ", (char *) Language(31), iNode);
|
|
|
|
pout(CYAN, BLACK, temp);
|
|
|
|
/* on */
|
|
|
|
snprintf(temp, 81, "%s %s", (char *) Language(135), ctime(<ime));
|
|
|
|
PUTSTR(temp);
|
|
|
|
Enter(1);
|
|
|
|
}
|
|
|
|
|
2004-04-09 18:31:22 +00:00
|
|
|
alarm_on();
|
|
|
|
Pause();
|
2001-11-10 17:14:16 +00:00
|
|
|
|
2005-10-07 20:42:35 +00:00
|
|
|
newuser();
|
2004-04-09 18:31:22 +00:00
|
|
|
Fast_Bye(MBERR_OK);
|
|
|
|
return 0;
|
2001-11-10 17:14:16 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|