#include "hash.h"
#include "ircd_log.h"
#include "ircd_osdep.h"
+#include "ircd_reply.h"
#include "ircd_string.h"
#include "ircd.h"
#include "list.h"
#include "listener.h"
+#include "msg.h"
#include "numeric.h"
#include "numnicks.h"
#include "packet.h"
int HighestFd = -1;
struct sockaddr_in VirtualHost;
static char readbuf[SERVER_TCP_WINDOW];
-static int running_in_background;
/*
* report_error text constants
if (!errmsg)
errmsg = "Unknown error";
- if (!who)
+ if (EmptyString(who))
who = "unknown";
if (last_notice + 20 < CurrentTime) {
/*
* pace error messages so opers don't get flooded by transients
*/
- sendto_ops(text, who, errmsg);
+ sendto_opmask_butone(0, SNO_OLDSNO, text, who, errmsg);
last_notice = CurrentTime;
}
-
ircd_log(L_ERROR, text, who, errmsg);
-
- if (!running_in_background) {
- fprintf(stderr, text, who, errmsg);
- fprintf(stderr, "\n");
- }
errno = errtmp;
}
connect_server(aconf, 0, reply);
}
else
- sendto_ops("Connect to %s failed: host lookup", aconf->name);
+ sendto_opmask_butone(0, SNO_OLDSNO, "Connect to %s failed: host lookup",
+ aconf->name);
+}
+
+/*
+ * close_connections - closes all connections
+ * close stderr if specified
+ */
+void close_connections(int close_stderr)
+{
+ int i;
+ close(0);
+ close(1);
+ if (close_stderr)
+ close(2);
+ for (i = 3; i < MAXCONNECTIONS; ++i)
+ close(i);
}
+/*
+ * init_connection_limits - initialize process fd limit to
+ * MAXCONNECTIONS
+ */
+int init_connection_limits(void)
+{
+ int limit = os_set_fdlimit(MAXCONNECTIONS);
+ if (0 == limit)
+ return 1;
+ if (limit < 0) {
+ fprintf(stderr, "error setting max fd's to %d\n", limit);
+ }
+ else if (limit > 0) {
+ fprintf(stderr, "ircd fd table too big\nHard Limit: %d IRC max: %d\n",
+ limit, MAXCONNECTIONS);
+ fprintf(stderr, "set MAXCONNECTIONS to a smaller value");
+ }
+ return 0;
+}
/*
* connect_inet - set up address and port and make a connection
return bytes_written;
}
-/*
- * init_sys
- */
-void init_sys(void)
-{
- int fd;
- int limit = os_set_fdlimit(MAXCONNECTIONS);
- if (limit < 0) {
- fprintf(stderr, "error setting max fd's to %d\n", limit);
- exit(2);
- }
- else if (limit > 0) {
- fprintf(stderr, "ircd fd table too big\nHard Limit: %d IRC max: %d\n",
- limit, MAXCONNECTIONS);
- fprintf(stderr, "set MAXCONNECTIONS to a smaller value");
- exit(2);
- }
-
- for (fd = 3; fd < MAXCONNECTIONS; ++fd)
- {
- close(fd);
- LocalClientArray[fd] = NULL;
- }
- LocalClientArray[2] = 0;
- LocalClientArray[1] = 0;
- LocalClientArray[0] = 0;
- close(1);
- close(0);
-
- if (bootopt & BOOT_TTY) {
- /* debugging is going to a tty */
- init_resolver();
- return;
- }
- if (!(bootopt & BOOT_DEBUG))
- close(2);
-
- if (fork())
- exit(0);
- running_in_background = 1;
-#ifdef TIOCNOTTY
- if ((fd = open("/dev/tty", O_RDWR)) > -1) {
- ioctl(fd, TIOCNOTTY, 0);
- close(fd);
- }
-#endif
- setsid();
- init_resolver();
-}
void release_dns_reply(struct Client* cptr)
{
const char* msg = strerror(cptr->error);
if (!msg)
msg = "Unknown error";
- sendto_ops("Connection failed to %s: %s", cptr->name, msg);
+ sendto_opmask_butone(0, SNO_OLDSNO, "Connection failed to %s: %s",
+ cptr->name, msg);
return 0;
}
if (!(aconf = find_conf_byname(cptr->confs, cptr->name, CONF_SERVER))) {
- sendto_ops("Lost Server Line for %s", cptr->name);
+ sendto_opmask_butone(0, SNO_OLDSNO, "Lost Server Line for %s", cptr->name);
return 0;
}
+
if (!EmptyString(aconf->passwd))
- sendto_one(cptr, "PASS :%s", aconf->passwd);
+ sendrawto_one(cptr, MSG_PASS " :%s", aconf->passwd);
#if 0
/* dead code, already done in connect_server */
*/
cptr->lasttime = CurrentTime;
cptr->flags |= FLAGS_PINGSENT;
- sendto_one(cptr, "SERVER %s 1 " TIME_T_FMT " " TIME_T_FMT " J%s %s%s :%s",
- me.name, me.serv->timestamp, newts, MAJOR_PROTOCOL,
- NumServCap(&me), me.info);
+
+ sendrawto_one(cptr, MSG_SERVER " %s 1 %Tu %Tu J%s %s%s :%s",
+ me.name, me.serv->timestamp, newts, MAJOR_PROTOCOL,
+ NumServCap(&me), me.info);
return (IsDead(cptr)) ? 0 : 1;
}
for (i = HighestFd; i > 0; --i) {
if ((cptr = LocalClientArray[i]) && !IsRegistered(cptr)) {
- sendto_one(source, rpl_str(RPL_CLOSING), me.name, source->name,
- get_client_name(source, HIDE_IP), cptr->status);
+ send_reply(source, RPL_CLOSING, get_client_name(source, HIDE_IP));
exit_client(source, cptr, &me, "Oper Closing");
++count;
}
close(fd);
return;
}
- /*
- * XXX - do we really want to do this? is it needed?
- */
- os_disable_options(fd);
-
/*
* Add this local client to the IPcheck registry.
* If it is a connection to a user port and if the site has been throttled,
* reject the user.
*/
if (!IPcheck_local_connect(addr.sin_addr, &next_target) && !listener->server) {
- ++ServerStats->is_ref;
+#ifdef IPCHECKDEBUG
+ char buff[512];
+ snprintf(buff,512,"\n\rNOTICE * :IPCheck=%i connections active\n\r%s",
+ IPcheck_nr(cptr),
+ throttle_message);
+ buff[511]=0;
+ send(fd,buff,strlen(buff),0);
+#else
/*
* strlen(throttle_message) == 66
+ *
+ * strlen is slow, so we use the constant here.
*/
send(fd, throttle_message, 66, 0);
+#endif
close(fd);
+ ++ServerStats->is_ref;
return;
}
- new_client = make_client(NULL,
+ new_client = make_client(0,
(listener->server) ? STAT_UNKNOWN_SERVER : STAT_UNKNOWN_USER);
/*
* Copy ascii address to 'sockhost' just in case. Then we
}
if (write_ready) {
if (!on_write_unblocked(cptr) || IsDead(cptr)) {
- const char* msg = (cptr->error) ? strerror(cptr->error) : LastDeadComment(cptr);
+ const char* msg = (cptr->error) ? strerror(cptr->error) : cptr->info;
if (!msg)
msg = "Unknown error";
- exit_client(cptr, cptr, &me, (char*) msg);
+ exit_client(cptr, cptr, &me, msg);
continue;
}
}
flush_connections(poll_cptr[i]);
#endif
if (IsDead(cptr)) {
- const char* msg = (cptr->error) ? strerror(cptr->error) : LastDeadComment(cptr);
+ const char* msg = (cptr->error) ? strerror(cptr->error) : cptr->info;
if (!msg)
msg = "Unknown error";
exit_client(cptr, cptr, &me, (char*) msg);
const char* msg = (cptr->error) ? strerror(cptr->error) : "EOF from client";
if (!msg)
msg = "Unknown error";
- exit_client_msg(cptr, cptr, &me, "Read error to %s: %s",
- get_client_name(cptr, HIDE_IP), msg);
+ exit_client_msg(cptr, cptr, &me, "Read error: %s",
+ msg);
}
}
return 0;
if (FD_ISSET(i, &write_set)) {
--nfds;
if (!on_write_unblocked(cptr) || IsDead(cptr)) {
- const char* msg = (cptr->error) ? strerror(cptr->error) : LastDeadComment(cptr);
+ const char* msg = (cptr->error) ? strerror(cptr->error) : cptr->info;
if (!msg)
msg = "Unknown error";
if (FD_ISSET(i, &read_set))
flush_connections(LocalClientArray[i]);
#endif
if (IsDead(cptr)) {
- const char* msg = (cptr->error) ? strerror(cptr->error) : LastDeadComment(cptr);
+ const char* msg = (cptr->error) ? strerror(cptr->error) : cptr->info;
if (!msg)
msg = "Unknown error";
exit_client(cptr, cptr, &me, msg);
const char* msg = (cptr->error) ? strerror(cptr->error) : "EOF from client";
if (!msg)
msg = "Unknown error";
- exit_client_msg(cptr, cptr, &me, "Read error to %s: %s",
- get_client_name(cptr, HIDE_IP), msg);
+ exit_client_msg(cptr, cptr, &me, "Read error: %s",
+ msg);
}
}
return 0;
assert(0 != aconf);
if (aconf->dns_pending) {
- sendto_ops("Server %s connect DNS pending");
+ sendto_opmask_butone(0, SNO_OLDSNO, "Server %s connect DNS pending",
+ aconf->name);
return 0;
}
Debug((DEBUG_NOTICE, "Connect to %s[@%s]", aconf->name,
if ((cptr = FindClient(aconf->name))) {
if (IsServer(cptr) || IsMe(cptr)) {
- sendto_ops("Server %s already present from %s",
- aconf->name, cptr->from->name);
+ sendto_opmask_butone(0, SNO_OLDSNO, "Server %s already present from %s",
+ aconf->name, cptr->from->name);
if (by && IsUser(by) && !MyUser(by)) {
- sendto_one(by, "%s NOTICE %s%s :Server %s already present from %s",
- NumServ(&me), NumNick(by), aconf->name, cptr->from->name);
+ sendcmdto_one(&me, CMD_NOTICE, by, "%C :Server %s already present "
+ "from %s", by, aconf->name, cptr->from->name);
}
return 0;
}
else if (IsHandshake(cptr) || IsConnecting(cptr)) {
if (by && IsUser(by)) {
- if (MyUser(by))
- sendto_one(by, ":%s NOTICE %s :Connection to %s already in progress",
- me.name, by->name, cptr->name);
- else
- sendto_one(by, "%s NOTICE %s%s :Connection to %s already in progress",
- NumServ(&me), NumNick(by), cptr->name);
+ sendcmdto_one(&me, CMD_NOTICE, by, "%C :Connection to %s already in "
+ "progress", by, cptr->name);
}
return 0;
}
attach_confs_byhost(cptr, aconf->host, CONF_SERVER);
if (!find_conf_byhost(cptr->confs, aconf->host, CONF_SERVER)) {
- sendto_ops("Host %s is not enabled for connecting: no C-line", aconf->name);
+ sendto_opmask_butone(0, SNO_OLDSNO, "Host %s is not enabled for "
+ "connecting: no C-line", aconf->name);
if (by && IsUser(by) && !MyUser(by)) {
- sendto_one(by, "%s NOTICE %s%s :Connect to host %s failed: no C-line",
- NumServ(&me), NumNick(by), aconf->name);
+ sendcmdto_one(&me, CMD_NOTICE, by, "%C :Connect to host %s failed: no "
+ "C-line", by, aconf->name);
}
det_confs_butmask(cptr, 0);
free_client(cptr);
*/
if (!connect_inet(aconf, cptr)) {
if (by && IsUser(by) && !MyUser(by)) {
- sendto_one(by, "%s NOTICE %s%s :Couldn't connect to %s",
- NumServ(&me), NumNick(by), cptr->name);
+ sendcmdto_one(&me, CMD_NOTICE, by, "%C :Couldn't connect to %s", by,
+ cptr->name);
}
det_confs_butmask(cptr, 0);
free_client(cptr);