Ejemplo n.º 1
0
int reg_newcon(char *data)
{
    char    *tty, *uid, *prg, *city;
    int	    retval;
    pid_t   pid;

    strtok(data, ",");
    pid = (pid_t)atoi(strtok(NULL, ","));
    tty = xstrcpy(strtok(NULL, ","));
    uid = xstrcpy(cldecode(strtok(NULL, ",")));
    prg = xstrcpy(cldecode(strtok(NULL, ",")));
    city = xstrcpy(cldecode(strtok(NULL, ";")));

    /*
     * Abort if no empty record is found 
     */
    if ((retval = reg_find((pid_t)0)) == -1) {
	Syslog('?', "Maximum clients (%d) reached", MAXCLIENT);
	retval = -1;
    } else {
	memset((char *)&reginfo[retval], 0, sizeof(reg_info));
	reginfo[retval].pid = pid;
	strncpy((char *)&reginfo[retval].tty, tty, 6);
	strncpy((char *)&reginfo[retval].uname, uid, 35);
	strncpy((char *)&reginfo[retval].prg, prg, 14); 
	strncpy((char *)&reginfo[retval].city, city, 35);
	strcpy((char *)&reginfo[retval].doing, "-"); 
	reginfo[retval].started = (int)time(NULL); 
	reginfo[retval].lastcon = (int)time(NULL);
	reginfo[retval].altime = 600;

	/*
	 * Everyone says do not disturb, unless the flag
	 * is cleared by the owner of this process.
	 */
	reginfo[retval].silent = 1;

	stat_inc_clients();
	if (strcmp(prg, (char *)"ftncico") == 0)
	    mailers++;
	Syslog('-', "Registered client pgm \"%s\", pid %d, slot %d, mailers %d, TCP/IP %d", 
		prg, (int)pid, retval, mailers, ipmailers);
    }

    free(uid);
    free(prg);
    free(city);
    free(tty);
    return retval;
}
Ejemplo n.º 2
0
Archivo: funcs.c Proyecto: bbs-io/mbse
/*
 * Check BBS open status, return FALSE if the bbs is closed.
 * Display the reason why to the user.
 */
int CheckStatus()
{
    static	char buf[81], msg[81];

    snprintf(buf, 81, "SBBS:0;");
    if (socket_send(buf) == 0) {
	strncpy(buf, socket_receive(), 80);
	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';
	Enter(2);
	PUTCHAR('\007');
	snprintf(msg, 81, "*** %s ***", cldecode(buf+8));
	PUTSTR(msg);
	Syslog('+', "Send user message \"%s\"", cldecode(buf+8));
	Enter(3);
    }
    return FALSE;
}
Ejemplo n.º 3
0
/*
 * Update username and city for this process.
 */
int reg_user(char *data)
{
    char    *user, *city;
    int	    rec;
    pid_t   pid;

    strtok(data, ",");
    pid  = (pid_t)atoi(strtok(NULL, ","));
    user = xstrcpy(cldecode(strtok(NULL, ",")));
    city = xstrcpy(cldecode(strtok(NULL, ";")));

    if ((rec = reg_find(pid)) == -1) {
	free(user);
	free(city);
	return -1;
    }

    strncpy((char *)&reginfo[rec].uname, user, 35);
    strncpy((char *)&reginfo[rec].city,  city, 35);
    reginfo[rec].lastcon = (int)time(NULL);
    free(user);
    free(city);
    return 0;
}
Ejemplo n.º 4
0
int userlog(char *param)
{
    char	*prname, *prpid, *grade, *msg;
    static char	lfn[PATH_MAX], token[14];
    int		rc;

    lfn[0] = '\0';
    strncpy(token, strtok(param, ","), 14);
    strncpy(token, strtok(NULL, ","), 14);
    snprintf(lfn, PATH_MAX, "%s/log/%s", getenv("FTND_ROOT"), token);
    prname = strtok(NULL, ",");
    prpid  = strtok(NULL, ",");
    grade  = strtok(NULL, ",");
    msg    = xstrcpy(cldecode(strtok(NULL, ";")));
    rc = ulog(lfn, grade, prname, prpid, msg);
    free(msg);
    return rc;
}
Ejemplo n.º 5
0
/*
 * Update doing information for this process.
 */
int reg_doing(char *data)
{
    char    *line;
    int	    rec;
    pid_t   pid;

    strtok(data, ",");
    pid = (pid_t)atoi(strtok(NULL, ","));
    line = xstrcpy(cldecode(strtok(NULL, ";")));

    if ((rec = reg_find(pid)) == -1) {
	free(line);
	return -1;
    }

    strncpy(reginfo[rec].doing, line, 35);
    reginfo[rec].lastcon = (int)time(NULL);
    free(line);
    return 0;
}
Ejemplo n.º 6
0
/*
 * Page sysop for a chat
 */
int reg_page(char *data)
{
    char    *reason;
    int     i, rec;
    pid_t   pid;

    strtok(data, ",");
    pid = (pid_t)atoi(strtok(NULL, ","));
    reason = xstrcpy(cldecode(strtok(NULL, ";")));

    Syslog('+', "reg_page: pid=%d, reason=\"%s\"", (int)pid, reason);

    if (!sysop_present) {
	free(reason);
	return 2;
    }

    /*
     * Check if another user is paging the sysop or has paged the sysop.
     * If so, mark sysop busy.
     */
    for (i = 1; i < MAXCLIENT; i++) {
	if (reginfo[i].pid && (reginfo[i].pid != pid) && (reginfo[i].paging || reginfo[i].haspaged)) {
	    free(reason);
	    return 1;
	}
    }

    if ((rec = reg_find(pid)) == -1) {
	free(reason);
	return 3;
    }

    /*
     * All seems well, accept the page
     */
    reginfo[rec].paging = TRUE;
    strncpy(reginfo[rec].reason, reason, 80);
    reginfo[rec].lastcon = (int)time(NULL);
    return 0;
}
Ejemplo n.º 7
0
/*
 * Chat, if the parameters are not NULL, a connection with the named
 * channel is made with the give username which will be forced to the
 * used nick name. This mode is used for forced sysop chat.
 * If the parameters are NULL, then it's up to the user what happens.
 */
void Chat(char *username, char *channel)
{
    int		    width, curpos = 0, stop = FALSE, data, rc;
    unsigned char   ch;
    char	    sbuf[81], resp[128], *name, *mname;
    static char	    buf[200];
    time_t	    c_start, c_end;


    WhosDoingWhat(SYSOPCHAT, NULL);
    clear();

    rsize = rows - 5;
    rpointer = 0;

    if (SYSOP == TRUE) {
	/*
	 * Forbid the sysop to chat, the sysop MUST use mbmon.
	 */
	Syslog('+', "The Sysop attempted to chat");
	pout(LIGHTRED, BLACK, (char *) Language(29));
	Enter(1);
	Pause();
	return;
    }
   
    if (username && channel) {
	colour(LIGHTGREEN, BLACK);
	PUTCHAR('\007');
	/* *** Sysop is starting chat *** */
	pout(LIGHTGREEN, BLACK, (char *) Language(59));
	Enter(1);
	sleep(1);
	PUTCHAR('\007');
	sleep(1);
	PUTCHAR('\007');
	Syslog('+', "Sysop chat started");
	chat_with_sysop = TRUE;
    } else {
	Syslog('+', "User started chatting");
    }
    
    /*
     * Setup the screen, this is only possible in ANSI mode.
     */
    clear();
    locate(1, 1);
    colour(WHITE, BLUE);
    snprintf(buf, 200, "%-*s", cols, " MBSE BBS Chat Server");
    mvprintw(1, 1, buf);

    mname = xstrcpy(clencode(exitinfo.sUserName));
    name  = xstrcpy(clencode(exitinfo.Name));
    width = cols - (strlen(name) + 3);
    snprintf(buf, 200, "CCON,4,%d,%s,%s,0;", mypid, mname, name);
    free(mname);
    free(name);
    if (socket_send(buf) == 0) {
	strncpy(buf, socket_receive(), sizeof(buf)-1);
	if (strncmp(buf, "200:1,", 6) == 0) {
	    Syslog('!', "Chat server is not available");
	    colour(LIGHTRED, BLACK);
	    mvprintw(4, 1, (char *) Language(30));
	    Enter(2);
	    Pause();
	    chat_with_sysop = FALSE;
	    return;
	}
    }

    locate(rows - 2, 1);
    colour(WHITE, BLUE);
    snprintf(buf, 200, "%-*s", cols, " Type \"/EXIT\" to exit or \"/HELP\" for help.");
    mvprintw(rows - 2, 1, buf);

    colour(WHITE, BLACK);
    mvprintw(rows - 1, 1, ">");
    mvprintw(rows - 1, width + 2, "<");
    memset(&sbuf, 0, sizeof(sbuf));
    memset(&rbuf, 0, sizeof(rbuf));
    colour(LIGHTGRAY, BLACK);

    /*
     * If username and channelname are given, send the /nick and /join
     * commands to the chatserver.
     */
    if (username && channel) {
	snprintf(buf, 200, "CPUT:2,%d,/nick %s;", mypid, clencode(username));
	if (socket_send(buf) == 0)
	    strcpy(buf, socket_receive());
	snprintf(buf, 200, "CPUT:2,%d,/join %s;", mypid, clencode(channel));
	if (socket_send(buf) == 0)
	    strcpy(buf, socket_receive());
    }

    chatting = TRUE;
    c_start = time(NULL);

    while (stop == FALSE) {

	/*
	 * Check for new message, loop fast until no more data available.
	 */
	data = TRUE;
	while (data) {
	    snprintf(buf, 200, "CGET:1,%d;", mypid);
	    if (socket_send(buf) == 0) {
		strncpy(buf, socket_receive(), sizeof(buf)-1);
		if (strncmp(buf, "100:2,", 6) == 0) {
		    strncpy(resp, strtok(buf, ":"), 10);    /* Should be 100        */
		    strncpy(resp, strtok(NULL, ","), 5);    /* Should be 2          */
		    strncpy(resp, strtok(NULL, ","), 5);    /* 1= fatal, chat ended */
		    rc = atoi(resp);
		    memset(&resp, 0, sizeof(resp));
		    strncpy(resp, cldecode(strtok(NULL, ";")), 80);  /* The message          */
		    DispMsg(resp);
		    if (rc == 1) {
			Syslog('+', "Chat server error: %s", resp);
			stop = TRUE;
			data = FALSE;
		    }
		} else {
		    data = FALSE;
		}
	    }
	}

	if (stop)
	    break;

        /*
	 * Check for a pressed key, if so then process it.
	 * Allow hi-ascii for multi-language.
	 */
	ch = testkey(rows -1, curpos + 2);
	if ((ch == KEY_BACKSPACE) || (ch == KEY_RUBOUT) || (ch == KEY_DEL)) {
	    alarm_on();
	    if (curpos) {
		curpos--;
		sbuf[curpos] = '\0';
		BackErase();
	    } else {
		PUTCHAR(7);
	    }
	/* if KEY_DEL isprint, do no output again */
	} else if (isprint(ch) || traduce((char *)&ch)) {
	    alarm_on();
	    if (curpos < width) {
		PUTCHAR(ch);
		sbuf[curpos] = ch;
		curpos++;
	    } else {
		PUTCHAR(7);
	    }
	} else if ((ch == '\r') && curpos) {
	    alarm_on();
	    snprintf(buf, 200, "CPUT:2,%d,%s;", mypid, clencode(sbuf));
	    if (socket_send(buf) == 0) {
		strcpy(buf, socket_receive());
		if (strncmp(buf, "100:2,", 6) == 0) {
		    strncpy(resp, strtok(buf, ":"), 10);    /* Should be 100            */
		    strncpy(resp, strtok(NULL, ","), 5);    /* Should be 2              */
		    strncpy(resp, strtok(NULL, ","), 5);    /* 1= fatal, chat ended	*/
		    rc = atoi(resp);
		    strncpy(resp, cldecode(strtok(NULL, ";")), 80);  /* The message              */
		    DispMsg(resp);
		    if (rc == 1) {
			Syslog('+', "Chat server error: %s", resp);
			stop = TRUE;
		    }
		}
	    }
	    curpos = 0;
	    memset(&sbuf, 0, sizeof(sbuf));
	    locate(rows - 1, 2);
	    clrtoeol();
	    colour(WHITE, BLACK);
	    mvprintw(rows - 1, 1, ">");
	    mvprintw(rows - 1, width + 2, "<");
	    colour(LIGHTGRAY, BLACK);
	}
    }
    chatting = FALSE;
    c_end = time(NULL);
    mib_chats++;
    mib_chatminutes += (unsigned int) ((c_end - c_start) / 60);


    /* 
     * Before sending the close command, purge all outstanding messages.
     */
    data = TRUE;
    while (data) {
	snprintf(buf, 200, "CGET:1,%d;", mypid);
	if (socket_send(buf) == 0) {
	    strncpy(buf, socket_receive(), sizeof(buf)-1);
	    if (strncmp(buf, "100:2,", 6) == 0) {
		strncpy(resp, strtok(buf, ":"), 10);    /* Should be 100        */
		strncpy(resp, strtok(NULL, ","), 5);    /* Should be 2          */
		strncpy(resp, strtok(NULL, ","), 5);	/* 1= fatal error	*/
		rc = atoi(resp);
		memset(&resp, 0, sizeof(resp));
		strncpy(resp, cldecode(strtok(NULL, ";")), 80);  /* The message          */
		DispMsg(resp);
		if (rc == 1) {
		    Syslog('+', "Chat server error: %s", resp);
		    data = FALSE;   /* Even if there is more, prevent a loop */
		}
	    } else {
		data = FALSE;
	    }
	}
    }

    if (username && channel) {
	/*
	 * Disjoin sysop channel
	 */

	/* *** Sysop has terminated chat *** */
	snprintf(buf, 200, "%s", (char *) Language(60));
	DispMsg(buf);
	Syslog('+', "Sysop chat ended");
	chat_with_sysop = FALSE;
    } else {
	Syslog('+', "User chat ended");
    }

    /*
     * Close server connection
     */
    snprintf(buf, 200, "CCLO,1,%d;", mypid);
    if (socket_send(buf) == 0) {
	strcpy(buf, socket_receive());
    }
    sleep(2);
    clear();
}
Ejemplo n.º 8
0
char *ParseMacro( const char *line, int *dieselrc)
{
    static char	res[MAXSTR];
    const char	*i;
    char	*tmp1, *tmp2, *tmp3;
    int		j, l;
    char	code;

    res[0]='\0';
    *dieselrc=0;

    if ( *line == '#' )
	return res;

    tmp1 = calloc(MAXSTR, sizeof(char));
    tmp2 = calloc(MAXSTR, sizeof(char));
    tmp3 = calloc(MAXSTR, sizeof(char));

    tmp1[0]='\0';

    for (i = line; i[0] != '\0'; i++) {
	if ( (i[0] == '@') && isalpha(i[1]) ){
	    l=2;
	    i++;
	    if (i[0] != '@') {
		if ((code = i[0]) != '\0' )
		    i++;
		while (( i[0] == '_') || ( i[0] == '>') || ( i[0] == '<') ){
		    l++;
		    i++;
		}
		i--;
		snprintf(tmp2, MAXSTR, "@(GETVAR,%c)",code);
		if (!diesel(tmp2,tmp3)==0){
		    snprintf(tmp3, MAXSTR, "%c%c",'@',code);
		}
		if (l>2){
		    if ( *i != '>')
			l=-l;
		    snprintf(&tmp1[strlen(tmp1)], MAXSTR, "%*.*s", l, l, tmp3);
		}else{
		    snprintf(&tmp1[strlen(tmp1)], MAXSTR, "%s", tmp3);
		}
	    }else{
		tmp1[(j=strlen(tmp1))]='@';
		tmp1[j+1]='\0';
	    }
	}else{
	    tmp1[(j=strlen(tmp1))]=i[0];
	    tmp1[j+1]='\0';
	}
    }

    i = tmp1;
    snprintf(tmp2, MAXSTR, "%s", tmp1);

    if ((tmp1[0]=='@') && (tmp1[1]=='{')){
	i++;
	i++;
	for (j=2; ((tmp1[j]!='}') && (tmp1[j]!='\0'));j++){
	    i++;
	}
	if ( (tmp1[j]=='}') ){
	    i++;
	    res[0]='\0';
	    if (j>2)
		snprintf(res, MAXSTR, "%.*s",j-2, &tmp1[2]);
	    if ((diesel(res,tmp3)!=0) || (atoi(tmp3)==0))
		snprintf(tmp2, MAXSTR, "@!%s",i);
	    else
		snprintf(tmp2, MAXSTR, "%s",i);
	}
    }
    *dieselrc=diesel(tmp2, res);

    free(tmp1);
    free(tmp2);
    free(tmp3);
    while (isspace(res[strlen(res) - 1])) {
	res[strlen(res) - 1] = EOS;
    }
    if ((res[0] == '@') && (res[1] =='!' ))
	res[0]='\0';

    cldecode(res);
    return res;
}
Ejemplo n.º 9
0
void user(void)
{
    FILE	*pUsrConfig, *pLimits;
    int		i, x, FoundName = FALSE, iFoundLimit = FALSE, IsNew = FALSE, logins = 0, Start;
    int		l1, l2;
    char	*token, temp[PATH_MAX], temp1[84], UserName[37], buf[128], *fullname;
    time_t	LastLogin;
    struct stat st;

    grecno = 0;
    Syslog('+', "Unixmode login: %s", sUnixName);

    snprintf(temp, PATH_MAX, "%s/etc/users.data", getenv("FTND_ROOT"));
    if ((pUsrConfig = fopen(temp,"r+")) == NULL) {
	/*
	 * This should not happen.
	 */
	WriteError("$Can't open %s", temp);
	PUTSTR((char *)"Can't open userfile, run \"newuser\" first");
	Enter(1);
	ExitClient(FTNERR_OK);
    }

    fread(&usrconfighdr, sizeof(usrconfighdr), 1, pUsrConfig);
    while (fread(&usrconfig, usrconfighdr.recsize, 1, pUsrConfig) == 1) {
	if (strcmp(usrconfig.Name, sUnixName) == 0) {
	    FoundName = TRUE;
	    break;
	} else
	    grecno++;
    }
							
    if (!FoundName) {
	fclose(pUsrConfig);
	snprintf(temp, PATH_MAX, "Unknown username: %s\r\n", sUnixName);
	PUTSTR(temp);
	/* FATAL ERROR: You are not in the BBS users file.*/
	snprintf(temp, PATH_MAX, "%s\r\n", (char *) Language(389));
	PUTSTR(temp);
	/* Please run 'newuser' to create an account */
	snprintf(temp, PATH_MAX, "%s\r\n", (char *) Language(390));
	PUTSTR(temp);
	Syslog('?', "FATAL: Could not find user in BBS users file.");
	Syslog('?', "       and system is using unix accounts\n");
	Free_Language();
	ExitClient(FTNERR_OK);
    }

    /*
     * Copy username, split first and lastname.
     */
    strncpy(UserName, usrconfig.sUserName, sizeof(UserName)-1);
    if ((strchr(UserName,' ') == NULL) && !CFG.iOneName) {
	token = strtok(UserName, " ");
  	strncpy(FirstName, token, sizeof(FirstName)-1);
  	token = strtok(NULL, "\0");
	i = strlen(token);
	for (x = 2; x < i; x++) {
	    if (token[x] == ' ')
		token[x] = '\0';
	}
	strncpy(LastName, token, sizeof(LastName)-1);
    } else
	strncpy(FirstName, UserName, sizeof(FirstName)-1);
    strncpy(UserName, usrconfig.sUserName, sizeof(UserName)-1);
    Syslog('+', "%s On-Line from \"%s\", node %d", UserName, ttyinfo.comment, iNode);
    IsDoing("Just Logged In");

    /*
     * Check some essential files, create them if they don't exist.
     */
    ChkFiles();

    /*
     * Setup users favourite language.
     */
    utf8 = (usrconfig.Charset == FTNC_UTF8);
    Set_Language(usrconfig.iLanguage);
    Free_Language();
    InitLanguage();

    /*
     * User logged in, tell it to the server. Check if a location is
     * set, if Ask User location for new users is off, this field is
     * empty but we have to send something to the server.
     */
    if (strlen(usrconfig.sLocation))
	UserCity(mypid, usrconfig.Name, usrconfig.sLocation);
    else
	UserCity(mypid, usrconfig.Name, (char *)"N/A");

    /*
     * Count simultaneous logins
     */
    Start = TRUE;
    while (TRUE) {
	if (Start)
	    snprintf(buf, 128, "GMON:1,1;");
	else
	    snprintf(buf, 128, "GMON:1,0;");
	Start = FALSE;
	if (socket_send(buf) == 0) {
	    strcpy(buf, socket_receive());
	    if (strncmp(buf, "100:0;", 6) == 0)
		break;  /* No more data */
	    if (strstr(buf, "ftnbbs")) {
		/*
		 * Only ftnbbs is wanted
		 */
		strtok(buf, ",");				    /* response */
		strtok(NULL, ",");				    /* pid	*/
		strtok(NULL, ",");				    /* tty	*/
		fullname = xstrcpy(cldecode(strtok(NULL, ",")));    /* username */
		if (strcmp(fullname, usrconfig.Name) == 0) {
		    logins++;
		}
		free(fullname);
	    }
	}
    }
    if (CFG.max_logins && (logins > CFG.max_logins)) {
	Syslog('+', "User logins %d, allowed %d, disconnecting", logins, CFG.max_logins);
	colour(LIGHTRED, BLACK);
	snprintf(temp, PATH_MAX, "%s %d %s\r\n", (char *) Language(18), CFG.max_logins, (char *) Language(19));
	PUTSTR(temp);
	Quick_Bye(FTNERR_INIT_ERROR);
    }
    
    /*
     * Set last file and message area so these numbers are saved when
     * the user hangs up or is logged off before het gets to the main
     * menu. Later in this function the areas are set permanent.
     */
    iAreaNumber = usrconfig.iLastFileArea;
    iMsgAreaNumber = usrconfig.iLastMsgArea;

    /*
     * See if this user is the Sysop.
     */
    strcpy(temp, UserName);
    strcpy(temp1, CFG.sysop_name);
    if ((strcasecmp(CFG.sysop_name, UserName)) == 0) {
	/*
	 * If login name is sysop, set SYSOP true 
	 */
	SYSOP = TRUE;
	Syslog('+', "Sysop is online");
    }

    /*
     * Is this a new user?
     */
    if (usrconfig.iTotalCalls == 0)
	IsNew = TRUE;

    /*
     * Pause after logo screen.
     */
    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");
    }

    /*
     * 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
     */
    snprintf(temp,PATH_MAX, "%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
     */
    snprintf(temp, PATH_MAX, "%s/etc/limits.data", getenv("FTND_ROOT"));

    if ((pLimits = fopen(temp,"rb")) == NULL) {
	WriteError("$Can't open %s", temp);
    } else {
	fread(&LIMIThdr, sizeof(LIMIThdr), 1, pLimits);

	while (fread(&LIMIT, sizeof(LIMIT), 1, pLimits) == 1) {
 	    if (LIMIT.Security == usrconfig.Security.level) {
		iFoundLimit = TRUE;
		break;
	    }
	}
	fclose(pLimits);
    }

    if (!iFoundLimit) {
	WriteError("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.
	 */
	snprintf(temp,PATH_MAX, "%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) {
		usrconfig.DownloadKToday = LIMIT.DownK;
	    }
            if (LIMIT.DownF) {
                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.
     */
    snprintf(LastLoginDate, 12, "%s", StrDateDMY(usrconfig.tLastLoginDate));
    snprintf(LastLoginTime, 9, "%s", StrTimeHMS(usrconfig.tLastLoginDate));
    LastLogin = usrconfig.tLastLoginDate;
    usrconfig.tLastLoginDate = ltime; /* Set current login to current date */
    usrconfig.iTotalCalls++;

    /*
     * Update user record.
     */
    if (fseek(pUsrConfig, usrconfighdr.hdrsize + (grecno * usrconfighdr.recsize), 0) != 0) {
	WriteError("Can't seek in %s/etc/users.data", getenv("FTND_ROOT"));
    } else {
	fwrite(&usrconfig, sizeof(usrconfig), 1, pUsrConfig);
    }
    fclose(pUsrConfig);

    /*
     * Write users structure to tmp file in ~/home/unixname/exitinfo
     * A copy of the userrecord is also in the variable exitinfo.
     */
    if (! InitExitinfo())
	Good_Bye(FTNERR_INIT_ERROR);

    /*
     * If user has not set a preferred character set, force this
     */
    if (exitinfo.Charset == FTNC_NONE) {
	Chg_Charset();
    }

    setlocale(LC_CTYPE, getlocale(exitinfo.Charset)); 	 
    Syslog('b', "setlocale(LC_CTYPE, NULL) returns \"%s\"", printable(setlocale(LC_CTYPE, NULL), 0));

    GetLastUser();
    StartTime = xstrcpy(GetLocalHM());
    ChangeHomeDir(exitinfo.Name, exitinfo.Email);

    Syslog('+', "User successfully logged into BBS");
    Syslog('+', "Level %d (%s), %d mins. left, port %s", exitinfo.Security.level, LIMIT.Description, exitinfo.iTimeLeft, pTTY);
    Time2Go = time(NULL);
    Time2Go += exitinfo.iTimeLeft * 60;
    iUserTimeLeft = exitinfo.iTimeLeft;

    IsDoing("Welcome screens");
    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");

	snprintf(temp, PATH_MAX, "%s", (char *) GetDateDMY() );
	if ((strcmp(exitinfo.sDateOfBirth, temp)) == 0)
	    DisplayFile((char *)"birthday");

	/*
	 * Displays file if it exists DD-MM.A??
	 */
	snprintf(temp, PATH_MAX, "%s", (char *) GetDateDMY());
	strcpy(temp1, "");
	strncat(temp1, temp, 5);
	snprintf(temp, PATH_MAX, "%s", temp1);
	DisplayFile(temp);
	
	/*
	 * Displays users security file if it exists
	 */
	snprintf(temp, PATH_MAX, "sec%d", exitinfo.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;
    snprintf(temp, PATH_MAX, "%s/share/int/txtfiles/%s/onceonly.ans", getenv("FTND_ROOT"), lang.lc);
    stat(temp, &st);
    if (st.st_mtime == 0) {
	snprintf(temp, PATH_MAX, "%s/share/int/txtfiles/%s/onceonly.ans", getenv("FTND_ROOT"), CFG.deflang);
	stat(temp, &st);
    }
    if (st.st_mtime == 0) {
	snprintf(temp, PATH_MAX, "%s/share/int/txtfiles/%s/onceonly.asc", getenv("FTND_ROOT"), lang.lc);
	stat(temp, &st);
	if (st.st_mtime == 0) {
	    snprintf(temp, PATH_MAX, "%s/share/int/txtfiles/%s/onceonly.asc", getenv("FTND_ROOT"), CFG.deflang);
	    stat(temp, &st);
	}
    }

    if ((st.st_mtime != 0) && (LastLogin < st.st_mtime))
	DisplayFile((char *)"onceonly");
	
    OLR_SyncTags();

    if (exitinfo.MailScan) {
	IsDoing("New mail check");
	CheckMail();
    }

    /*
     * We don't show new files to new users.
     */
    if (exitinfo.ieFILE && (!IsNew)) {
	IsDoing("New files check");
	NewfileScan(FALSE);
    }
    
    /* 
     * Copy last file Area in to current Area 
     */
    SetFileArea(exitinfo.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.
     */
    menu();
}
Ejemplo n.º 10
0
/*
 * Send personal message
 */
int reg_spm(char *data)
{
    char    *from, *too, *txt, *logm;
    int	    i;

    strtok(data, ",");
    from = xstrcpy(cldecode(strtok(NULL, ",")));
    too  = xstrcpy(cldecode(strtok(NULL, ",")));
    txt  = xstrcpy(cldecode(strtok(NULL, ";")));
    Syslog('+', "PM from \"%s\" to \"%s\": \"%s\"", from, too, txt);

    for (i = 0; i < MAXCLIENT; i++) {
	if (reginfo[i].pid && (strcasecmp(reginfo[i].uname, too) == 0)) {
	    /*
	     *  If the in and out pointers are the same and the 
	     *  message present flag is still set, then this user
	     *  can't get anymore new messages.
	     */
	    if (reginfo[i].ismsg && (reginfo[i].ptr_in == reginfo[i].ptr_out)) {
		free(from);
		free(too);
		free(txt);
		return 2;
	    }

	    /*
	     *  If user has the "do not distrurb" flag set, but the sysop ignore's this.
	     */
	    if (reginfo[i].silent) {
		free(from);
		free(too);
		free(txt);
		return 1;
	    }

	    /*
	     *  If all is well, insert the new message.
	     */
	    strncpy((char *)&reginfo[i].fname[reginfo[i].ptr_in], from, 35);
	    strncpy((char *)&reginfo[i].msg[reginfo[i].ptr_in], txt, 80);
	    if (reginfo[i].ptr_in < RB)
		reginfo[i].ptr_in++;
	    else
		reginfo[i].ptr_in = 0;
	    reginfo[i].ismsg = TRUE;

	    if (CFG.iAutoLog && strlen(CFG.chat_log)) {
		logm = calloc(PATH_MAX, sizeof(char));
		snprintf(logm, PATH_MAX, "%s/log/%s", getenv("FTND_ROOT"), CFG.chat_log);
		ulog(logm, (char *)"+", from, (char *)"-1", txt);
		free(logm);
	    }

	    Syslog('+', "reg_spm: rec=%d in=%d out=%d ismsg=%d", i, reginfo[i].ptr_in, reginfo[i].ptr_out, reginfo[i].ismsg);
	    free(from);
	    free(too);
	    free(txt);
	    return 0;
	}
    }
    
    free(from);
    free(too);
    free(txt);
    return 3;   // Error, user not found
}