Exemple #1
0
void sbbs_t::badlogin(char* user, char* passwd)
{
	char reason[128];
	ulong count;

	SAFEPRINTF(reason,"%s LOGIN", connection);
	count=loginFailure(startup->login_attempt_list, &client_addr, connection, user, passwd);
	if(startup->login_attempt_hack_threshold && count>=startup->login_attempt_hack_threshold)
		::hacklog(&cfg, reason, user, passwd, client_name, &client_addr);
	if(startup->login_attempt_filter_threshold && count>=startup->login_attempt_filter_threshold)
		filter_ip(&cfg, connection, "- TOO MANY CONSECUTIVE FAILED LOGIN ATTEMPTS"
			,client_name, client_ipaddr, user, /* fname: */NULL);

	mswait(startup->login_attempt_delay);
}
Exemple #2
0
static int
listen_for_IP()
{
	struct sockaddr_nl addr;
	int sock, len;
	const int RECV_SIZE = 512;
	char recv_buffer[RECV_SIZE];

	if ((sock = socket(PF_NETLINK, SOCK_RAW, NETLINK_ROUTE)) == -1)
	{
		_perror("couldn't open NETLINK_ROUTE socket");
		_assert(false);
		return 1;
	}

	memset(&addr, 0, sizeof(addr));
	addr.nl_family = AF_NETLINK;
	addr.nl_groups = RTMGRP_IPV6_IFADDR;

	if (bind(sock, (struct sockaddr *)&addr, sizeof(addr)) == -1) {
		_perror("couldn't bind");
		assert(false);
		return 1;
	}

	send_ip_list_request(sock);

	loop:
	while ((len = recv(sock, recv_buffer, RECV_SIZE, 0)) > 0)
	{
		struct nlmsghdr* nlh = (struct nlmsghdr*) recv_buffer;
		while (NLMSG_OK(nlh, len) && (nlh->nlmsg_type != NLMSG_DONE))
		{
			if (nlh->nlmsg_type == RTM_NEWADDR || nlh->nlmsg_type == RTM_GETADDR || nlh->nlmsg_type == RTM_DELADDR)
			{
				struct ifaddrmsg *ifa = (struct ifaddrmsg *) NLMSG_DATA(nlh);

				if(verbose_mode)
				{
					log_time();
					log("Message: [%d] flags: ", nlh->nlmsg_type);
					fprint_flags(global_output, ifa->ifa_flags);
					log(" scope: %d\n", ifa->ifa_scope);
				}

				if (ifa->ifa_family == AF_INET6)
				{
					void *address = NULL; //The IP Address:
					struct ifa_cacheinfo *ci = NULL; //Cache info for address:

					struct rtattr *rth = IFA_RTA(ifa);
					int rtl = IFA_PAYLOAD(nlh);

					while (rtl && RTA_OK(rth, rtl))
					{
						if (rth->rta_type == IFA_ADDRESS)
						{
							address = RTA_DATA(rth);

							if(verbose_mode)
							{
								log("[IFA_ADDRESS]");
								log_ipv6(address);
								log("\n");
							}
						}
						else if (rth->rta_type == IFA_CACHEINFO)
						{
							ci =  (struct ifa_cacheinfo *) RTA_DATA(rth);
							if(verbose_mode)
							{
								log("[IFA_CACHEINFO] valid: %d prefered: %d\n", ci->ifa_valid, ci->ifa_prefered);
							}
						}
						else
						{
							verbose_log("[?%d?]\n", rth->rta_type);
						}
						rth = RTA_NEXT(rth, rtl);
					}

					assert(address != NULL);
					assert(ci != NULL);

					filter_ip(address, ifa->ifa_flags, ifa->ifa_scope, ci->ifa_prefered);
				}
			}
			else if (nlh->nlmsg_type == NLMSG_ERROR)
			{
				struct nlmsgerr *err = (struct nlmsgerr*) NLMSG_DATA(nlh);
				if (nlh->nlmsg_len < NLMSG_LENGTH(sizeof(struct nlmsgerr)))
				{
					log("ERROR truncated\n");
				}
				else
				{
					errno = -err->error;
					_perror("RTNETLINK answers");
				}
				return -1;
			}
			nlh = NLMSG_NEXT(nlh, len);
		}

		fflush(global_output);
	}

	if (errno == EINTR || errno == EAGAIN) goto loop;	//Would a do..while be cleaner?

	assert(len != 0);
	assert(len > 0);
	return 0;
}