#include "ircd_alloc.h"
#include "ircd_chattr.h"
#include "ircd_log.h"
+#include "ircd_reply.h"
+#include "ircd_snprintf.h"
#include "ircd_string.h"
#include "list.h"
#include "listener.h"
/*
* check against a set of time intervals
*/
-static int check_time_interval(char *interval, char *reply)
+static int check_time_interval(char *interval, char *reply, size_t reply_size)
{
struct tm* tptr;
char* p;
? (perm_min <= nowm && nowm <= perm_max)
: (perm_min <= nowm || nowm <= perm_max))
{
- sprintf_irc(reply, ":%%s %%d %%s :%s %d:%02d to %d:%02d.",
- "You are not allowed to connect from",
- perm_min_hours, perm_min_minutes,
- perm_max_hours, perm_max_minutes);
+ ircd_snprintf(0, reply, reply_size, ":You are not allowed to connect "
+ "from %d:%02d to %d:%02d.", perm_min_hours,
+ perm_min_minutes, perm_max_hours, perm_max_minutes);
return (ERR_YOUREBANNEDCREEP);
}
if ((perm_min < perm_max)
? (perm_min <= nowm + 5 && nowm + 5 <= perm_max)
: (perm_min <= nowm + 5 || nowm + 5 <= perm_max))
{
- sprintf_irc(reply, ":%%s %%d %%s :%d minute%s%s",
- perm_min - nowm, (perm_min - nowm) > 1 ? "s " : " ",
- "and you will be denied for further access");
+ ircd_snprintf(0, reply, reply_size, ":%d minute%s and you will be "
+ "denied for further access", perm_min - nowm,
+ (perm_min - nowm) > 1 ? "s" : "");
return (ERR_YOUWILLBEBANNED);
}
interval = p;
{
FBFILE* file = NULL;
char line[80];
- char* tmp;
+ char* tmp = NULL;
struct stat sb;
struct tm* tm;
if (NULL == (file = fbopen(filename, "r"))) {
- sendto_one(sptr, err_str(ERR_NOMOTD), me.name, parv);
- sendto_one(sptr,
- ":%s %d %s :Connection from your host is refused on this server.",
- me.name, ERR_YOUREBANNEDCREEP, parv);
+ send_reply(sptr, ERR_NOMOTD);
+ send_reply(sptr, SND_EXPLICIT | ERR_YOUREBANNEDCREEP,
+ ":Connection from your host is refused on this server.");
return;
}
fbstat(&sb, file);
*tmp = '\0';
if ((tmp = strchr(line, '\r')))
*tmp = '\0';
- /* sendto_one(sptr,
- * ":%s %d %s : %s.",
- * me.name, ERR_YOUREBANNEDCREEP, parv,line); */
- sendto_one(sptr, rpl_str(RPL_MOTD), me.name, parv, line);
+ send_reply(sptr, RPL_MOTD, line);
}
- sendto_one(sptr,
- ":%s %d %s :Connection from your host is refused on this server.",
- me.name, ERR_YOUREBANNEDCREEP, parv);
+ send_reply(sptr, SND_EXPLICIT | ERR_YOUREBANNEDCREEP,
+ ":Connection from your host is refused on this server.");
fbclose(file);
}
/*
* check_limit_and_attach - check client limits and attach I:line
+ *
+ * Made it accept 1 charactor, and 2 charactor limits (0->99 now),
+ * and dislallow more than 255 people here as well as in ipcheck.
+ * removed the old "ONE" scheme too.
+ * -- Isomer 2000-06-22
*/
-static int check_limit_and_attach(struct Client* cptr, struct ConfItem* aconf)
+static enum AuthorizationCheckResult
+check_limit_and_attach(struct Client* cptr, struct ConfItem* aconf)
{
+ int number = 255;
+
if (aconf->passwd) {
- /* Special case: exactly one digit */
- if (IsDigit(*aconf->passwd) && !aconf->passwd[1]) {
- /*
- * Refuse connections when there are already <digit>
- * clients connected with the same IP number
- */
- unsigned short nr = *aconf->passwd - '0';
- if (IPcheck_nr(cptr) > nr)
- return ACR_TOO_MANY_FROM_IP; /* Already got nr with that ip# */
- }
-#ifdef USEONE
- else if (0 == strcmp(aconf->passwd, "ONE")) {
- int i;
- for (i = HighestFd; i > -1; --i) {
- if (LocalClientArray[i] && MyUser(LocalClientArray[i]) &&
- LocalClientArray[i]->ip.s_addr == cptr->ip.s_addr)
- return ACR_TOO_MANY_FROM_IP; /* Already got one with that ip# */
- }
- }
-#endif
+ if (IsDigit(*aconf->passwd) && !aconf->passwd[1])
+ number = *aconf->passwd-'0';
+ else if (IsDigit(*aconf->passwd) && IsDigit(aconf->passwd[1]) &&
+ !aconf->passwd[2])
+ number = (*aconf->passwd-'0')*10+(aconf->passwd[1]-'0');
}
+ if (ip_registry_count(cptr->ip.s_addr) > number)
+ return ACR_TOO_MANY_FROM_IP;
return attach_conf(cptr, aconf);
}
/*
* Find the first (best) I line to attach.
*/
-int attach_iline(struct Client* cptr)
+enum AuthorizationCheckResult attach_iline(struct Client* cptr)
{
struct ConfItem* aconf;
const char* hname;
* connection). Note, that this automaticly changes the
* attachment if there was an old one...
*/
-int attach_conf(struct Client *cptr, struct ConfItem *aconf)
+enum AuthorizationCheckResult attach_conf(struct Client *cptr, struct ConfItem *aconf)
{
struct SLink *lp;
struct ConfItem *tmp;
char userhost[USERLEN + HOSTLEN + 3];
- /*
- * XXX - buffer overflow possible, unchecked variables
- */
if (user)
- sprintf_irc(userhost, "%s@%s", user, host);
+ ircd_snprintf(0, userhost, sizeof(userhost), "%s@%s", user, host);
else
ircd_strncpy(userhost, host, sizeof(userhost) - 1);
int found_g = 0;
if (1 == sig)
- sendto_ops("Got signal SIGHUP, reloading ircd conf. file");
+ sendto_opmask_butone(0, SNO_OLDSNO,
+ "Got signal SIGHUP, reloading ircd conf. file");
while ((tmp2 = *tmp)) {
if (tmp2->clients) {
CONF_HUB | CONF_LEAF | CONF_UWORLD);
}
if ((found_g = find_kill(acptr))) {
- sendto_op_mask(found_g == -2 ? SNO_GLINE : SNO_OPERKILL,
- found_g == -2 ? "G-line active for %s" : "K-line active for %s",
- get_client_name(acptr, HIDE_IP));
+ sendto_opmask_butone(0, found_g == -2 ? SNO_GLINE : SNO_OPERKILL,
+ found_g == -2 ? "G-line active for %s" :
+ "K-line active for %s",
+ get_client_name(acptr, HIDE_IP));
if (exit_client(cptr, acptr, &me, found_g == -2 ? "G-lined" :
"K-lined") == CPTR_KILLED)
ret = CPTR_KILLED;
len += strlen(aconf->host);
newhost = (char*) MyMalloc(len);
assert(0 != newhost);
- sprintf_irc(newhost, "*@%s", aconf->host);
+ ircd_snprintf(0, newhost, len, "*@%s", aconf->host);
MyFree(aconf->host);
aconf->host = newhost;
}
break;
else if (is_comment(tmp->passwd))
break;
- else if (check_time_interval(tmp->passwd, reply))
+ else if (check_time_interval(tmp->passwd, reply, sizeof(reply)))
break;
}
}
if (reply[0])
- sendto_one(cptr, reply, me.name, ERR_YOUREBANNEDCREEP, cptr->name);
+ send_reply(cptr, SND_EXPLICIT | ERR_YOUREBANNEDCREEP, reply);
else if (tmp) {
if (EmptyString(tmp->passwd))
- sendto_one(cptr,
- ":%s %d %s :Connection from your host is refused on this server.",
- me.name, ERR_YOUREBANNEDCREEP, cptr->name);
+ send_reply(cptr, SND_EXPLICIT | ERR_YOUREBANNEDCREEP,
+ ":Connection from your host is refused on this server.");
else {
if (*tmp->passwd == '"') {
- char *sbuf =
- sprintf_irc(sendbuf, ":%s %d %s :%s", me.name, ERR_YOUREBANNEDCREEP,
- cptr->name, &tmp->passwd[1]);
- sbuf[-1] = '.'; /* Overwrite last quote with a dot */
- sendbufto_one(cptr);
+ send_reply(cptr, SND_EXPLICIT | ERR_YOUREBANNEDCREEP, ":%*s.",
+ strlen(tmp->passwd + 1) - 1, tmp->passwd + 1);
}
else if (*tmp->passwd == '!')
killcomment(cptr, cptr->name, &tmp->passwd[1]);
#ifdef COMMENT_IS_FILE
killcomment(cptr, cptr->name, tmp->passwd);
#else
- sendto_one(cptr, ":%s %d %s :%s.", me.name, ERR_YOUREBANNEDCREEP,
- cptr->name, tmp->passwd);
+ send_reply(cptr, SND_EXPLICIT | ERR_YOUREBANNEDCREEP, ":%s.",
+ tmp->passwd);
#endif
}
}
/* find active glines */
/* added a check against the user's IP address to find_gline() -Kev */
- else if ((agline = gline_find(cptr, 0)) && GlineIsActive(agline))
- sendto_one(cptr, ":%s %d %s :%s.", me.name, ERR_YOUREBANNEDCREEP,
- cptr->name, GlineReason(agline));
+ else if ((agline = gline_lookup(cptr, 0)) && GlineIsActive(agline))
+ send_reply(cptr, SND_EXPLICIT | ERR_YOUREBANNEDCREEP, ":%s.",
+ GlineReason(agline));
else
agline = NULL; /* if a gline was found, it was inactive */
*/
enum AuthorizationCheckResult conf_check_client(struct Client *cptr)
{
- int acr;
+ enum AuthorizationCheckResult acr = ACR_OK;
ClearAccess(cptr);
if (IsConnecting(cptr) || IsHandshake(cptr)) {
c_conf = find_conf_byname(lp, cptr->name, CONF_SERVER);
if (!c_conf) {
- sendto_ops("Connect Error: lost C:line for %s", cptr->name);
+ sendto_opmask_butone(0, SNO_OLDSNO, "Connect Error: lost C:line for %s",
+ cptr->name);
det_confs_butmask(cptr, 0);
return -1;
}