2001-08-17 05:46:24 +00:00
|
|
|
/*****************************************************************************
|
|
|
|
*
|
2001-12-29 21:57:59 +00:00
|
|
|
* $Id$
|
2001-08-17 05:46:24 +00:00
|
|
|
* Purpose ...............: Buffers for registration information.
|
|
|
|
*
|
|
|
|
*****************************************************************************
|
2006-01-30 22:27:02 +00:00
|
|
|
* Copyright (C) 1997-2006
|
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.
|
|
|
|
*
|
|
|
|
* MB 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 MB BBS; see the file COPYING. If not, write to the Free
|
|
|
|
* Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2002-06-30 13:20:57 +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 "taskstat.h"
|
|
|
|
#include "taskregs.h"
|
2003-04-01 21:41:36 +00:00
|
|
|
#include "taskchat.h"
|
2001-08-17 05:46:24 +00:00
|
|
|
#include "taskutil.h"
|
|
|
|
|
|
|
|
extern reg_info reginfo[MAXCLIENT]; /* Array with clients */
|
2003-03-20 22:43:40 +00:00
|
|
|
extern struct sysconfig CFG; /* System config */
|
2001-08-17 05:46:24 +00:00
|
|
|
static int entrypos = 0; /* Status pointer */
|
2002-03-16 14:46:01 +00:00
|
|
|
static int mailers = 0; /* Registered mailers */
|
2003-03-19 22:45:46 +00:00
|
|
|
static int sysop_present = 0; /* Sysop present */
|
2002-03-23 13:12:29 +00:00
|
|
|
int ipmailers = 0; /* TCP/IP mail sessions */
|
2001-08-17 05:46:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
*
|
|
|
|
* Search for a pid.
|
|
|
|
*/
|
2006-05-22 12:09:15 +00:00
|
|
|
int reg_find(pid_t);
|
|
|
|
int reg_find(pid_t pids)
|
2001-08-17 05:46:24 +00:00
|
|
|
{
|
2003-03-19 22:45:46 +00:00
|
|
|
int i;
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2003-03-19 22:45:46 +00:00
|
|
|
for (i = 0; i < MAXCLIENT; i++) {
|
2006-05-22 12:09:15 +00:00
|
|
|
if (reginfo[i].pid == pids)
|
2003-03-19 22:45:46 +00:00
|
|
|
return i;
|
|
|
|
}
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2006-05-22 12:09:15 +00:00
|
|
|
WriteError("Panic, pid %d not found", (int)pids);
|
2003-03-19 22:45:46 +00:00
|
|
|
return -1;
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
*
|
|
|
|
* Registrate a new connection and fill the data.
|
|
|
|
*/
|
|
|
|
|
|
|
|
int reg_newcon(char *data)
|
|
|
|
{
|
2006-05-22 12:09:15 +00:00
|
|
|
char *tty, *uid, *prg, *city;
|
2003-03-19 22:45:46 +00:00
|
|
|
int retval;
|
2006-05-22 12:09:15 +00:00
|
|
|
pid_t pid;
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2006-05-22 12:09:15 +00:00
|
|
|
strtok(data, ",");
|
|
|
|
pid = (pid_t)atoi(strtok(NULL, ","));
|
|
|
|
tty = xstrcpy(strtok(NULL, ","));
|
2005-10-17 14:36:12 +00:00
|
|
|
uid = xstrcpy(cldecode(strtok(NULL, ",")));
|
|
|
|
prg = xstrcpy(cldecode(strtok(NULL, ",")));
|
|
|
|
city = xstrcpy(cldecode(strtok(NULL, ";")));
|
2003-03-19 22:45:46 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Abort if no empty record is found
|
|
|
|
*/
|
2006-05-22 12:09:15 +00:00
|
|
|
if ((retval = reg_find((pid_t)0)) == -1) {
|
2003-03-19 22:45:46 +00:00
|
|
|
Syslog('?', "Maximum clients (%d) reached", MAXCLIENT);
|
2006-05-22 12:09:15 +00:00
|
|
|
retval = -1;
|
|
|
|
} else {
|
|
|
|
memset((char *)®info[retval], 0, sizeof(reg_info));
|
|
|
|
reginfo[retval].pid = pid;
|
|
|
|
strncpy((char *)®info[retval].tty, tty, 6);
|
|
|
|
strncpy((char *)®info[retval].uname, uid, 35);
|
|
|
|
strncpy((char *)®info[retval].prg, prg, 14);
|
|
|
|
strncpy((char *)®info[retval].city, city, 35);
|
|
|
|
strcpy((char *)®info[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 *)"mbcico") == 0)
|
|
|
|
mailers++;
|
|
|
|
Syslog('-', "Registered client pgm \"%s\", pid %d, slot %d, mailers %d, TCP/IP %d",
|
|
|
|
prg, (int)pid, retval, mailers, ipmailers);
|
2003-03-19 22:45:46 +00:00
|
|
|
}
|
|
|
|
|
2005-10-17 14:36:12 +00:00
|
|
|
free(uid);
|
|
|
|
free(prg);
|
|
|
|
free(city);
|
2006-05-22 12:09:15 +00:00
|
|
|
free(tty);
|
2003-03-19 22:45:46 +00:00
|
|
|
return retval;
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int reg_closecon(char *data)
|
|
|
|
{
|
2006-05-22 12:09:15 +00:00
|
|
|
pid_t pid;
|
2003-03-19 22:45:46 +00:00
|
|
|
int rec;
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2006-05-22 12:09:15 +00:00
|
|
|
strtok(data, ",");
|
|
|
|
pid = (pid_t)atoi(strtok(NULL, ";"));
|
|
|
|
if ((rec = reg_find(pid)) == -1) {
|
2003-03-19 22:45:46 +00:00
|
|
|
return -1;
|
2006-05-22 12:09:15 +00:00
|
|
|
}
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2003-03-19 22:45:46 +00:00
|
|
|
if (strcmp(reginfo[rec].prg, (char *)"mbcico") == 0)
|
|
|
|
mailers--;
|
|
|
|
if (reginfo[rec].istcp)
|
|
|
|
ipmailers--;
|
2003-04-01 21:41:36 +00:00
|
|
|
if ((strcmp(reginfo[rec].prg, (char *)"mbsebbs") == 0) || (strcmp(reginfo[rec].prg, (char *)"mbmon") == 0))
|
2006-05-22 12:09:15 +00:00
|
|
|
chat_cleanuser(pid);
|
2003-04-01 21:41:36 +00:00
|
|
|
|
2006-05-22 12:09:15 +00:00
|
|
|
Syslog('-', "Unregistered client pgm \"%s\", pid %d, slot %d, mailers %d, TCP/IP %d",
|
|
|
|
reginfo[rec].prg, (int)pid, rec, mailers, ipmailers);
|
2003-03-19 22:45:46 +00:00
|
|
|
memset(®info[rec], 0, sizeof(reg_info));
|
|
|
|
stat_dec_clients();
|
|
|
|
return 0;
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check all registred connections.
|
|
|
|
*/
|
|
|
|
void reg_check(void)
|
|
|
|
{
|
2003-03-19 22:45:46 +00:00
|
|
|
int i;
|
|
|
|
time_t Now;
|
|
|
|
|
|
|
|
Now = time(NULL);
|
|
|
|
for (i = 1; i < MAXCLIENT; i++) {
|
|
|
|
if (reginfo[i].pid) {
|
|
|
|
if (kill(reginfo[i].pid, 0) == -1) {
|
|
|
|
if (errno == ESRCH) {
|
|
|
|
if (strcmp(reginfo[i].prg, (char *)"mbcico") == 0)
|
|
|
|
mailers--;
|
|
|
|
if (reginfo[i].istcp)
|
|
|
|
ipmailers--;
|
2003-04-01 21:41:36 +00:00
|
|
|
if ((strcmp(reginfo[i].prg, (char *)"mbsebbs") == 0) || (strcmp(reginfo[i].prg, (char *)"mbmon") == 0))
|
|
|
|
chat_cleanuser(reginfo[i].pid);
|
|
|
|
|
2003-03-19 22:45:46 +00:00
|
|
|
Syslog('?', "Stale registration found for pid %d (%s), mailers now %d, TCP/IP now %d",
|
2002-03-23 13:12:29 +00:00
|
|
|
reginfo[i].pid, reginfo[i].prg, mailers, ipmailers);
|
2003-03-19 22:45:46 +00:00
|
|
|
memset(®info[i], 0, sizeof(reg_info));
|
|
|
|
stat_dec_clients();
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
2003-03-19 22:45:46 +00:00
|
|
|
} else {
|
|
|
|
/*
|
|
|
|
* Check timeout
|
|
|
|
*/
|
2005-10-16 12:13:20 +00:00
|
|
|
if (((int)Now - reginfo[i].lastcon) >= reginfo[i].altime) {
|
2003-03-19 22:45:46 +00:00
|
|
|
if (reginfo[i].altime < 600) {
|
|
|
|
kill(reginfo[i].pid, SIGKILL);
|
|
|
|
Syslog('+', "Send SIGKILL to pid %d", reginfo[i].pid);
|
|
|
|
} else {
|
|
|
|
kill(reginfo[i].pid, SIGTERM);
|
|
|
|
Syslog('+', "Send SIGTERM to pid %d", reginfo[i].pid);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* 10 seconds to the next kill
|
|
|
|
*/
|
|
|
|
reginfo[i].altime = 10;
|
2005-10-16 12:13:20 +00:00
|
|
|
reginfo[i].lastcon = (int)time(NULL);
|
2003-03-19 22:45:46 +00:00
|
|
|
}
|
|
|
|
}
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
2003-03-19 22:45:46 +00:00
|
|
|
}
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Update doing information for this process.
|
|
|
|
*/
|
|
|
|
int reg_doing(char *data)
|
|
|
|
{
|
2006-05-22 12:09:15 +00:00
|
|
|
char *line;
|
2003-03-20 22:43:40 +00:00
|
|
|
int rec;
|
2006-05-22 12:09:15 +00:00
|
|
|
pid_t pid;
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2006-05-22 12:09:15 +00:00
|
|
|
strtok(data, ",");
|
|
|
|
pid = (pid_t)atoi(strtok(NULL, ","));
|
2005-10-17 14:36:12 +00:00
|
|
|
line = xstrcpy(cldecode(strtok(NULL, ";")));
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2005-10-17 14:36:12 +00:00
|
|
|
if ((rec = reg_find(pid)) == -1) {
|
|
|
|
free(line);
|
2003-03-20 22:43:40 +00:00
|
|
|
return -1;
|
2005-10-17 14:36:12 +00:00
|
|
|
}
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2003-03-20 22:43:40 +00:00
|
|
|
strncpy(reginfo[rec].doing, line, 35);
|
2005-10-16 12:13:20 +00:00
|
|
|
reginfo[rec].lastcon = (int)time(NULL);
|
2005-10-17 14:36:12 +00:00
|
|
|
free(line);
|
2003-03-20 22:43:40 +00:00
|
|
|
return 0;
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2002-03-23 13:12:29 +00:00
|
|
|
/*
|
|
|
|
* Registrate connection as TCP/IP connection
|
|
|
|
*/
|
|
|
|
int reg_ip(char *data)
|
|
|
|
{
|
2006-05-22 12:09:15 +00:00
|
|
|
pid_t pid;
|
2002-03-23 13:12:29 +00:00
|
|
|
int rec;
|
|
|
|
|
2006-05-22 12:09:15 +00:00
|
|
|
strtok(data, ",");
|
|
|
|
pid = (pid_t)atoi(strtok(NULL, ";"));
|
2002-03-23 13:12:29 +00:00
|
|
|
|
2006-05-22 12:09:15 +00:00
|
|
|
if ((rec = reg_find(pid)) == -1) {
|
2002-03-23 13:12:29 +00:00
|
|
|
return -1;
|
2006-05-22 12:09:15 +00:00
|
|
|
}
|
2002-03-23 13:12:29 +00:00
|
|
|
|
|
|
|
reginfo[rec].istcp = TRUE;
|
2005-10-16 12:13:20 +00:00
|
|
|
reginfo[rec].lastcon = (int)time(NULL);
|
2002-03-23 13:12:29 +00:00
|
|
|
ipmailers++;
|
2006-05-22 12:09:15 +00:00
|
|
|
Syslog('?', "TCP/IP session registered (%d), now %d sessions", (int)pid, ipmailers);
|
2002-03-23 13:12:29 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-08-17 05:46:24 +00:00
|
|
|
/*
|
|
|
|
* Update timer using NOP
|
|
|
|
*/
|
|
|
|
int reg_nop(char *data)
|
|
|
|
{
|
2006-05-22 12:09:15 +00:00
|
|
|
pid_t pid;
|
2003-03-20 22:43:40 +00:00
|
|
|
int rec;
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2006-05-22 12:09:15 +00:00
|
|
|
strtok(data, ",");
|
|
|
|
pid = (pid_t)atoi(strtok(NULL, ";"));
|
|
|
|
|
|
|
|
if ((rec = reg_find(pid)) == -1) {
|
2003-03-20 22:43:40 +00:00
|
|
|
return -1;
|
2006-05-22 12:09:15 +00:00
|
|
|
}
|
|
|
|
|
2005-10-16 12:13:20 +00:00
|
|
|
reginfo[rec].lastcon = (int)time(NULL);
|
2003-03-20 22:43:40 +00:00
|
|
|
return 0;
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Set new timer value
|
|
|
|
*/
|
|
|
|
int reg_timer(int Set, char *data)
|
|
|
|
{
|
2006-05-22 12:09:15 +00:00
|
|
|
pid_t pid;
|
2003-03-20 22:43:40 +00:00
|
|
|
int cnt, rec, val;
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2003-03-20 22:43:40 +00:00
|
|
|
cnt = atoi(strtok(data, ","));
|
|
|
|
if (Set) {
|
|
|
|
if (cnt != 2)
|
|
|
|
return -1;
|
2006-05-22 12:09:15 +00:00
|
|
|
pid = (pid_t)atoi(strtok(NULL, ","));
|
2003-03-20 22:43:40 +00:00
|
|
|
val = atoi(strtok(NULL, ";"));
|
|
|
|
if (val < 600)
|
|
|
|
val = 600;
|
|
|
|
} else {
|
|
|
|
if (cnt != 1)
|
|
|
|
return -1;
|
2006-05-22 12:09:15 +00:00
|
|
|
pid = (pid_t)atoi(strtok(NULL, ";"));
|
2003-03-20 22:43:40 +00:00
|
|
|
val = 600;
|
|
|
|
}
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2006-05-22 12:09:15 +00:00
|
|
|
if ((rec = reg_find(pid)) == -1) {
|
2003-03-20 22:43:40 +00:00
|
|
|
return -1;
|
2006-05-22 12:09:15 +00:00
|
|
|
}
|
2003-03-20 22:43:40 +00:00
|
|
|
|
|
|
|
reginfo[rec].altime = val;
|
2005-10-16 12:13:20 +00:00
|
|
|
reginfo[rec].lastcon = (int)time(NULL);
|
2006-05-22 12:09:15 +00:00
|
|
|
Syslog('r', "Set timeout value for %d to %d", (int)pid, val);
|
2003-03-20 22:43:40 +00:00
|
|
|
return 0;
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Update tty information for this process.
|
|
|
|
*/
|
|
|
|
int reg_tty(char *data)
|
|
|
|
{
|
2006-05-22 12:09:15 +00:00
|
|
|
char *tty;
|
2003-03-20 22:43:40 +00:00
|
|
|
int rec;
|
2006-05-22 12:09:15 +00:00
|
|
|
pid_t pid;
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2006-05-22 12:09:15 +00:00
|
|
|
strtok(data, ",");
|
|
|
|
pid = (pid_t)atoi(strtok(NULL, ","));
|
|
|
|
tty = xstrcpy(strtok(NULL, ";"));
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2006-05-22 12:09:15 +00:00
|
|
|
if ((rec = reg_find(pid)) == -1) {
|
|
|
|
free(tty);
|
2003-03-20 22:43:40 +00:00
|
|
|
return -1;
|
2006-05-22 12:09:15 +00:00
|
|
|
}
|
|
|
|
|
2003-03-20 22:43:40 +00:00
|
|
|
strncpy((char *)®info[rec].tty, tty, 6);
|
2005-10-16 12:13:20 +00:00
|
|
|
reginfo[rec].lastcon = (int)time(NULL);
|
2006-05-22 12:09:15 +00:00
|
|
|
free(tty);
|
2003-03-20 22:43:40 +00:00
|
|
|
return 0;
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Update the "do not disturb" flag.
|
|
|
|
*/
|
|
|
|
int reg_silent(char *data)
|
|
|
|
{
|
2006-05-22 12:09:15 +00:00
|
|
|
int rec, line;
|
|
|
|
pid_t pid;
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2006-05-22 12:09:15 +00:00
|
|
|
strtok(data, ",");
|
|
|
|
pid = (pid_t)atoi(strtok(NULL, ","));
|
|
|
|
line = atoi(strtok(NULL, ";"));
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2006-05-22 12:09:15 +00:00
|
|
|
if ((rec = reg_find(pid)) == -1) {
|
2003-03-20 22:43:40 +00:00
|
|
|
return -1;
|
2006-05-22 12:09:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
reginfo[rec].silent = line;
|
2005-10-16 12:13:20 +00:00
|
|
|
reginfo[rec].lastcon = (int)time(NULL);
|
2003-03-20 22:43:40 +00:00
|
|
|
return 0;
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Update username and city for this process.
|
|
|
|
*/
|
|
|
|
int reg_user(char *data)
|
|
|
|
{
|
2006-05-22 12:09:15 +00:00
|
|
|
char *user, *city;
|
2003-03-20 22:43:40 +00:00
|
|
|
int rec;
|
2006-05-22 12:09:15 +00:00
|
|
|
pid_t pid;
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2006-05-22 12:09:15 +00:00
|
|
|
strtok(data, ",");
|
|
|
|
pid = (pid_t)atoi(strtok(NULL, ","));
|
2005-10-17 14:36:12 +00:00
|
|
|
user = xstrcpy(cldecode(strtok(NULL, ",")));
|
|
|
|
city = xstrcpy(cldecode(strtok(NULL, ";")));
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2005-10-17 14:36:12 +00:00
|
|
|
if ((rec = reg_find(pid)) == -1) {
|
|
|
|
free(user);
|
|
|
|
free(city);
|
2003-03-20 22:43:40 +00:00
|
|
|
return -1;
|
2005-10-17 14:36:12 +00:00
|
|
|
}
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2003-03-20 22:43:40 +00:00
|
|
|
strncpy((char *)®info[rec].uname, user, 35);
|
|
|
|
strncpy((char *)®info[rec].city, city, 35);
|
2005-10-16 12:13:20 +00:00
|
|
|
reginfo[rec].lastcon = (int)time(NULL);
|
2005-10-17 14:36:12 +00:00
|
|
|
free(user);
|
|
|
|
free(city);
|
2003-03-20 22:43:40 +00:00
|
|
|
return 0;
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
2003-03-19 22:45:46 +00:00
|
|
|
* Register sysop available for chat
|
2001-08-17 05:46:24 +00:00
|
|
|
*/
|
2003-03-19 22:45:46 +00:00
|
|
|
int reg_sysop(char *data)
|
2001-08-17 05:46:24 +00:00
|
|
|
{
|
2006-05-22 12:09:15 +00:00
|
|
|
pid_t pid;
|
2003-03-23 21:27:14 +00:00
|
|
|
int rec;
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2006-05-22 12:09:15 +00:00
|
|
|
strtok(data, ",");
|
|
|
|
pid = (pid_t)atoi(strtok(NULL, ","));
|
2003-03-19 22:45:46 +00:00
|
|
|
sysop_present = atoi(strtok(NULL, ";"));
|
2003-03-23 21:27:14 +00:00
|
|
|
|
|
|
|
if ((rec = reg_find(pid)) != -1) {
|
2005-10-16 12:13:20 +00:00
|
|
|
reginfo[rec].lastcon = (int)time(NULL);
|
2003-03-23 21:27:14 +00:00
|
|
|
}
|
|
|
|
|
2003-03-19 22:45:46 +00:00
|
|
|
Syslog('+', "Sysop present for chat: %s", sysop_present ? "True":"False");
|
|
|
|
return 0;
|
|
|
|
}
|
2001-08-17 05:46:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2003-03-19 22:45:46 +00:00
|
|
|
/*
|
|
|
|
* Check for personal message
|
|
|
|
*/
|
2006-01-30 22:27:02 +00:00
|
|
|
void reg_ipm_r(char *data, char *buf)
|
2003-03-19 22:45:46 +00:00
|
|
|
{
|
2006-05-22 12:09:15 +00:00
|
|
|
char *name, *msg;
|
|
|
|
int rec;
|
|
|
|
pid_t pid;
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2003-03-19 22:45:46 +00:00
|
|
|
buf[0] = '\0';
|
2006-01-30 22:27:02 +00:00
|
|
|
snprintf(buf, SS_BUFSIZE, "100:0;");
|
2006-05-22 12:09:15 +00:00
|
|
|
strtok(data, ",");
|
|
|
|
pid = (pid_t)atoi(strtok(NULL, ";"));
|
2003-03-19 22:45:46 +00:00
|
|
|
|
|
|
|
if ((rec = reg_find(pid)) == -1)
|
2006-01-30 22:27:02 +00:00
|
|
|
return;
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2005-10-16 12:13:20 +00:00
|
|
|
reginfo[rec].lastcon = (int)time(NULL);
|
2003-03-24 19:44:38 +00:00
|
|
|
if (!reginfo[rec].ismsg)
|
2006-01-30 22:27:02 +00:00
|
|
|
return;
|
2003-03-19 22:45:46 +00:00
|
|
|
|
2005-10-17 14:36:12 +00:00
|
|
|
name = xstrcpy(clencode(reginfo[rec].fname[reginfo[rec].ptr_out]));
|
|
|
|
msg = xstrcpy(clencode(reginfo[rec].msg[reginfo[rec].ptr_out]));
|
2006-01-30 22:27:02 +00:00
|
|
|
snprintf(buf, SS_BUFSIZE, "100:2,%s,%s;", name, msg);
|
2003-03-19 22:45:46 +00:00
|
|
|
if (reginfo[rec].ptr_out < RB)
|
|
|
|
reginfo[rec].ptr_out++;
|
|
|
|
else
|
|
|
|
reginfo[rec].ptr_out = 0;
|
|
|
|
if (reginfo[rec].ptr_out == reginfo[rec].ptr_in)
|
|
|
|
reginfo[rec].ismsg = FALSE;
|
|
|
|
|
2003-03-24 19:44:38 +00:00
|
|
|
Syslog('+', "reg_ipm: in=%d out=%d ismsg=%d", reginfo[rec].ptr_in, reginfo[rec].ptr_out, reginfo[rec].ismsg);
|
2003-03-19 22:45:46 +00:00
|
|
|
|
2005-10-17 14:36:12 +00:00
|
|
|
free(name);
|
|
|
|
free(msg);
|
2006-01-30 22:27:02 +00:00
|
|
|
return;
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Send personal message
|
|
|
|
*/
|
|
|
|
int reg_spm(char *data)
|
|
|
|
{
|
2006-05-22 12:09:15 +00:00
|
|
|
char *from, *too, *txt, *logm;
|
2003-03-24 19:44:38 +00:00
|
|
|
int i;
|
2003-03-19 22:45:46 +00:00
|
|
|
|
2006-05-22 12:09:15 +00:00
|
|
|
strtok(data, ",");
|
2005-10-17 14:36:12 +00:00
|
|
|
from = xstrcpy(cldecode(strtok(NULL, ",")));
|
|
|
|
too = xstrcpy(cldecode(strtok(NULL, ",")));
|
|
|
|
txt = xstrcpy(cldecode(strtok(NULL, ";")));
|
2005-10-17 18:02:00 +00:00
|
|
|
Syslog('+', "PM from \"%s\" to \"%s\": \"%s\"", from, too, txt);
|
2003-03-20 22:43:40 +00:00
|
|
|
|
2003-03-19 22:45:46 +00:00
|
|
|
for (i = 0; i < MAXCLIENT; i++) {
|
2003-03-24 19:44:38 +00:00
|
|
|
if (reginfo[i].pid && (strcasecmp(reginfo[i].uname, too) == 0)) {
|
2003-03-19 22:45:46 +00:00
|
|
|
/*
|
|
|
|
* 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)) {
|
2005-10-17 14:36:12 +00:00
|
|
|
free(from);
|
|
|
|
free(too);
|
|
|
|
free(txt);
|
2003-03-24 19:44:38 +00:00
|
|
|
return 2;
|
2003-03-19 22:45:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If user has the "do not distrurb" flag set, but the sysop ignore's this.
|
|
|
|
*/
|
2003-03-24 19:44:38 +00:00
|
|
|
if (reginfo[i].silent) {
|
2005-10-17 14:36:12 +00:00
|
|
|
free(from);
|
|
|
|
free(too);
|
|
|
|
free(txt);
|
2003-03-24 19:44:38 +00:00
|
|
|
return 1;
|
2003-03-19 22:45:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If all is well, insert the new message.
|
|
|
|
*/
|
|
|
|
strncpy((char *)®info[i].fname[reginfo[i].ptr_in], from, 35);
|
|
|
|
strncpy((char *)®info[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;
|
|
|
|
|
2003-03-20 22:43:40 +00:00
|
|
|
if (CFG.iAutoLog && strlen(CFG.chat_log)) {
|
2003-12-16 21:50:32 +00:00
|
|
|
logm = calloc(PATH_MAX, sizeof(char));
|
2005-08-29 21:03:28 +00:00
|
|
|
snprintf(logm, PATH_MAX, "%s/log/%s", getenv("MBSE_ROOT"), CFG.chat_log);
|
2003-12-16 21:50:32 +00:00
|
|
|
ulog(logm, (char *)"+", from, (char *)"-1", txt);
|
|
|
|
free(logm);
|
2003-03-20 22:43:40 +00:00
|
|
|
}
|
|
|
|
|
2003-03-23 21:27:14 +00:00
|
|
|
Syslog('+', "reg_spm: rec=%d in=%d out=%d ismsg=%d", i, reginfo[i].ptr_in, reginfo[i].ptr_out, reginfo[i].ismsg);
|
2005-10-17 14:36:12 +00:00
|
|
|
free(from);
|
|
|
|
free(too);
|
|
|
|
free(txt);
|
2003-03-24 19:44:38 +00:00
|
|
|
return 0;
|
2003-03-19 22:45:46 +00:00
|
|
|
}
|
|
|
|
}
|
2003-03-24 19:44:38 +00:00
|
|
|
|
2005-10-17 14:36:12 +00:00
|
|
|
free(from);
|
|
|
|
free(too);
|
|
|
|
free(txt);
|
2003-03-24 19:44:38 +00:00
|
|
|
return 3; // Error, user not found
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2006-01-30 22:27:02 +00:00
|
|
|
void reg_fre_r(char *buf)
|
2001-08-17 05:46:24 +00:00
|
|
|
{
|
2003-03-20 22:43:40 +00:00
|
|
|
int i, users = 0, utils = 0;
|
|
|
|
|
|
|
|
for (i = 1; i < MAXCLIENT; i++) {
|
|
|
|
if (reginfo[i].pid) {
|
|
|
|
if ((!strncmp(reginfo[i].prg, "mbsebbs", 7)) ||
|
|
|
|
(!strncmp(reginfo[i].prg, "mbnewusr", 8)) ||
|
2006-02-04 16:30:48 +00:00
|
|
|
(!strncmp(reginfo[i].prg, "mbnntp", 6)))
|
2003-03-20 22:43:40 +00:00
|
|
|
users++;
|
|
|
|
|
|
|
|
if ((!strncmp(reginfo[i].prg, "mbfido", 6)) ||
|
|
|
|
(!strncmp(reginfo[i].prg, "mbmail", 6)) ||
|
|
|
|
(!strncmp(reginfo[i].prg, "mball", 5)) ||
|
|
|
|
(!strncmp(reginfo[i].prg, "mbaff", 5)) ||
|
|
|
|
(!strncmp(reginfo[i].prg, "mbcico", 6)) ||
|
|
|
|
(!strncmp(reginfo[i].prg, "mbfile", 6)) ||
|
|
|
|
(!strncmp(reginfo[i].prg, "mbmsg", 5)) ||
|
|
|
|
(!strncmp(reginfo[i].prg, "mbindex", 7)) ||
|
|
|
|
(!strncmp(reginfo[i].prg, "mbdiff", 6)) ||
|
|
|
|
(!strncmp(reginfo[i].prg, "mbuser", 6)))
|
|
|
|
utils++;
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
2003-03-20 22:43:40 +00:00
|
|
|
}
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2003-03-20 22:43:40 +00:00
|
|
|
if (users || utils)
|
2005-08-29 21:03:28 +00:00
|
|
|
snprintf(buf, 80, "100:1,Running utilities: %02d Active users: %02d;", utils, users);
|
2003-03-20 22:43:40 +00:00
|
|
|
else
|
2005-08-29 21:03:28 +00:00
|
|
|
snprintf(buf, 80, "100:0;");
|
2006-01-30 22:27:02 +00:00
|
|
|
return;
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Get registration information. The first time the parameter
|
|
|
|
* must be 1, for the next searches 0. Returns 100:0; if there
|
|
|
|
* is an error or the end of file is reached.
|
|
|
|
*/
|
2006-01-30 22:27:02 +00:00
|
|
|
void get_reginfo_r(int first, char *buf)
|
2001-08-17 05:46:24 +00:00
|
|
|
{
|
2005-10-17 14:36:12 +00:00
|
|
|
char *name, *prg, *city, *doing;
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2006-01-30 22:27:02 +00:00
|
|
|
snprintf(buf, SS_BUFSIZE, "100:0;");
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2003-03-20 22:43:40 +00:00
|
|
|
/*
|
|
|
|
* Loop forever until an error occours, eof is reached or
|
|
|
|
* the data is valid. Only in the last case valid data is
|
|
|
|
* returned to the caller.
|
|
|
|
*/
|
|
|
|
for (;;) {
|
|
|
|
if (first == 1)
|
|
|
|
entrypos = 0;
|
|
|
|
else
|
|
|
|
entrypos++;
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2003-03-20 22:43:40 +00:00
|
|
|
if (entrypos == MAXCLIENT)
|
2006-01-30 22:27:02 +00:00
|
|
|
return;
|
2001-08-17 05:46:24 +00:00
|
|
|
|
2003-03-20 22:43:40 +00:00
|
|
|
if ((int)reginfo[entrypos].pid != 0) {
|
2005-10-17 14:36:12 +00:00
|
|
|
name = xstrcpy(clencode(reginfo[entrypos].uname));
|
|
|
|
prg = xstrcpy(clencode(reginfo[entrypos].prg));
|
|
|
|
city = xstrcpy(clencode(reginfo[entrypos].city));
|
|
|
|
doing = xstrcpy(clencode( reginfo[entrypos].doing));
|
2006-01-30 22:27:02 +00:00
|
|
|
snprintf(buf, SS_BUFSIZE, "100:7,%d,%s,%s,%s,%s,%s,%d;",
|
2001-08-17 05:46:24 +00:00
|
|
|
reginfo[entrypos].pid, reginfo[entrypos].tty,
|
2005-10-17 14:36:12 +00:00
|
|
|
name, prg, city, doing, reginfo[entrypos].started);
|
|
|
|
free(name);
|
|
|
|
free(prg);
|
|
|
|
free(city);
|
|
|
|
free(doing);
|
2006-01-30 22:27:02 +00:00
|
|
|
return;
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
2003-03-20 22:43:40 +00:00
|
|
|
}
|
|
|
|
/* never reached */
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Page sysop for a chat
|
|
|
|
*/
|
|
|
|
int reg_page(char *data)
|
|
|
|
{
|
2006-05-22 12:09:15 +00:00
|
|
|
char *reason;
|
2003-03-20 22:43:40 +00:00
|
|
|
int i, rec;
|
2006-05-22 12:09:15 +00:00
|
|
|
pid_t pid;
|
|
|
|
|
|
|
|
strtok(data, ",");
|
|
|
|
pid = (pid_t)atoi(strtok(NULL, ","));
|
2005-10-17 14:36:12 +00:00
|
|
|
reason = xstrcpy(cldecode(strtok(NULL, ";")));
|
2003-03-20 22:43:40 +00:00
|
|
|
|
2006-05-22 12:09:15 +00:00
|
|
|
Syslog('+', "reg_page: pid=%d, reason=\"%s\"", (int)pid, reason);
|
2003-03-20 22:43:40 +00:00
|
|
|
|
2005-10-17 14:36:12 +00:00
|
|
|
if (!sysop_present) {
|
|
|
|
free(reason);
|
2003-03-20 22:43:40 +00:00
|
|
|
return 2;
|
2005-10-17 14:36:12 +00:00
|
|
|
}
|
2003-03-20 22:43:40 +00:00
|
|
|
|
|
|
|
/*
|
2003-04-02 21:36:47 +00:00
|
|
|
* Check if another user is paging the sysop or has paged the sysop.
|
|
|
|
* If so, mark sysop busy.
|
2003-03-20 22:43:40 +00:00
|
|
|
*/
|
|
|
|
for (i = 1; i < MAXCLIENT; i++) {
|
2006-05-22 12:09:15 +00:00
|
|
|
if (reginfo[i].pid && (reginfo[i].pid != pid) && (reginfo[i].paging || reginfo[i].haspaged)) {
|
2005-10-17 14:36:12 +00:00
|
|
|
free(reason);
|
2003-03-20 22:43:40 +00:00
|
|
|
return 1;
|
2005-10-17 14:36:12 +00:00
|
|
|
}
|
2003-03-20 22:43:40 +00:00
|
|
|
}
|
|
|
|
|
2005-10-17 14:36:12 +00:00
|
|
|
if ((rec = reg_find(pid)) == -1) {
|
|
|
|
free(reason);
|
2003-03-20 22:43:40 +00:00
|
|
|
return 3;
|
2005-10-17 14:36:12 +00:00
|
|
|
}
|
2003-03-20 22:43:40 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* All seems well, accept the page
|
|
|
|
*/
|
|
|
|
reginfo[rec].paging = TRUE;
|
|
|
|
strncpy(reginfo[rec].reason, reason, 80);
|
2005-10-16 12:13:20 +00:00
|
|
|
reginfo[rec].lastcon = (int)time(NULL);
|
2003-03-20 22:43:40 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Cancel page sysop for a chat
|
|
|
|
*/
|
|
|
|
int reg_cancel(char *data)
|
|
|
|
{
|
2006-05-22 12:09:15 +00:00
|
|
|
pid_t pid;
|
2003-03-20 22:43:40 +00:00
|
|
|
int rec;
|
|
|
|
|
2006-05-22 12:09:15 +00:00
|
|
|
strtok(data, ",");
|
|
|
|
pid = (pid_t)atoi(strtok(NULL, ";"));
|
2003-03-20 22:43:40 +00:00
|
|
|
|
2006-05-22 12:09:15 +00:00
|
|
|
Syslog('+', "reg_cancel: pid=%d", (int)pid);
|
2003-03-20 22:43:40 +00:00
|
|
|
|
|
|
|
if ((rec = reg_find(pid)) == -1)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (reginfo[rec].paging) {
|
|
|
|
reginfo[rec].paging = FALSE;
|
|
|
|
reginfo[rec].haspaged = TRUE;
|
|
|
|
}
|
2006-05-22 12:09:15 +00:00
|
|
|
|
2005-10-16 12:13:20 +00:00
|
|
|
reginfo[rec].lastcon = (int)time(NULL);
|
2003-03-20 22:43:40 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check paging status for from mbmon
|
|
|
|
*/
|
2006-01-30 22:27:02 +00:00
|
|
|
void reg_checkpage_r(char *data, char *buf)
|
2003-03-20 22:43:40 +00:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 1; i < MAXCLIENT; i++) {
|
|
|
|
if (reginfo[i].pid && reginfo[i].paging) {
|
2006-01-30 22:27:02 +00:00
|
|
|
snprintf(buf, SS_BUFSIZE, "100:3,%d,1,%s;", reginfo[i].pid, clencode(reginfo[i].reason));
|
|
|
|
return;
|
2003-03-20 22:43:40 +00:00
|
|
|
}
|
|
|
|
if (reginfo[i].pid && reginfo[i].haspaged) {
|
2006-01-30 22:27:02 +00:00
|
|
|
snprintf(buf, SS_BUFSIZE, "100:3,%d,0,%s;", reginfo[i].pid, clencode(reginfo[i].reason));
|
|
|
|
return;
|
2003-03-20 22:43:40 +00:00
|
|
|
}
|
|
|
|
}
|
2006-01-30 22:27:02 +00:00
|
|
|
snprintf(buf, SS_BUFSIZE, "100:0;");
|
|
|
|
return;
|
2001-08-17 05:46:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-04-02 21:36:47 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Check if this user has paged or is paging
|
|
|
|
*/
|
2006-05-22 12:09:15 +00:00
|
|
|
int reg_ispaging(pid_t pid)
|
2003-04-02 21:36:47 +00:00
|
|
|
{
|
|
|
|
int rec;
|
|
|
|
|
|
|
|
if ((rec = reg_find(pid)) == -1)
|
|
|
|
return FALSE;
|
|
|
|
|
|
|
|
return (reginfo[rec].paging || reginfo[rec].haspaged);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Mark that this user is now talking to the sysop
|
|
|
|
*/
|
2006-05-22 12:09:15 +00:00
|
|
|
void reg_sysoptalk(pid_t pid)
|
2003-04-02 21:36:47 +00:00
|
|
|
{
|
|
|
|
int rec;
|
|
|
|
|
|
|
|
if ((rec = reg_find(pid)) == -1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
reginfo[rec].paging = FALSE;
|
|
|
|
reginfo[rec].haspaged = FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|