Ejemplo n.º 1
0
/*
 * Heavily modified from the ircu m_motd by codemastr
 * Also svsmotd support added
 */
DLLFUNC CMD_FUNC(m_rules)
{
	ConfigItem_tld *ptr;
	aMotd *temp;
	char userhost[USERLEN + HOSTLEN + 6];
	if (IsServer(sptr))
		return 0;
		
	if (hunt_server_token(cptr, sptr, MSG_RULES, TOK_RULES, ":%s", 1, parc,
	    parv) != HUNTED_ISME)
		return 0;
#ifndef TLINE_Remote
	if (!MyConnect(sptr))
	{
		temp = rules;
		goto playrules;
	}
#endif
	strlcpy(userhost,make_user_host(cptr->user->username, cptr->user->realhost), sizeof userhost);
	ptr = Find_tld(sptr, userhost);

	if (ptr)
	{
		temp = ptr->rules;

	}
	else
		temp = rules;

      playrules:
	if (temp == NULL)
	{
		sendto_one(sptr, err_str(ERR_NORULES), me.name, parv[0]);
		return 0;

	}

	sendto_one(sptr, rpl_str(RPL_RULESSTART), me.name, parv[0], me.name);

	while (temp)
	{
		sendto_one(sptr, rpl_str(RPL_RULES), me.name, parv[0],
		    temp->line);
		temp = temp->next;
	}
	sendto_one(sptr, rpl_str(RPL_ENDOFRULES), me.name, parv[0]);
	return 0;
}
Ejemplo n.º 2
0
/*
 * Modified from comstud by codemastr
 */
DLLFUNC CMD_FUNC(m_botmotd)
{
	aMotd *temp;
	ConfigItem_tld *ptr;
	char userhost[HOSTLEN + USERLEN + 6];

	if (hunt_server_token(cptr, sptr, MSG_BOTMOTD, TOK_BOTMOTD, ":%s", 1, parc,
	    parv) != HUNTED_ISME)
		return 0;

	if (!IsPerson(sptr))
		return 0;

	strlcpy(userhost,make_user_host(sptr->user->username, sptr->user->realhost), sizeof userhost);
	ptr = Find_tld(sptr, userhost);

	if (ptr)
	{
		if (ptr->botmotd)
			temp = ptr->botmotd;
		else
			temp = botmotd;
	}
	else
		temp = botmotd;

	if (!temp)
	{
		sendto_one(sptr, ":%s NOTICE %s :BOTMOTD File not found",
		    me.name, sptr->name);
		return 0;
	}
	sendto_one(sptr, ":%s NOTICE %s :- %s Bot Message of the Day - ",
	    me.name, sptr->name, me.name);

	while (temp)
	{
		sendto_one(sptr, ":%s NOTICE %s :- %s", me.name, sptr->name, temp->line);
		temp = temp->next;
	}
	sendto_one(sptr, ":%s NOTICE %s :End of /BOTMOTD command.", me.name, sptr->name);
	return 0;
}
Ejemplo n.º 3
0
/*
 * Modified from comstud by codemastr
 */
DLLFUNC CMD_FUNC(m_botmotd)
{
	aMotdLine *motdline;
	ConfigItem_tld *tld;
	char userhost[HOSTLEN + USERLEN + 6];

	if (hunt_server(cptr, sptr, ":%s BOTMOTD :%s", 1, parc, parv) != HUNTED_ISME)
		return 0;

	if (!IsPerson(sptr))
		return 0;

	strlcpy(userhost, make_user_host(sptr->user->username, sptr->user->realhost), sizeof(userhost));
	tld = Find_tld(sptr, userhost);

	motdline = NULL;
	if (tld)
		motdline = tld->botmotd.lines;
	if (!motdline)
		motdline = botmotd.lines;

	if (!motdline)
	{
		sendto_one(sptr, ":%s NOTICE %s :BOTMOTD File not found",
		    me.name, sptr->name);
		return 0;
	}
	sendto_one(sptr, ":%s NOTICE %s :- %s Bot Message of the Day - ",
	    me.name, sptr->name, me.name);

	while (motdline)
	{
		sendto_one(sptr, ":%s NOTICE %s :- %s", me.name, sptr->name, motdline->line);
		motdline = motdline->next;
	}
	sendto_one(sptr, ":%s NOTICE %s :End of /BOTMOTD command.", me.name, sptr->name);
	return 0;
}
Ejemplo n.º 4
0
int _register_user(aClient *cptr, aClient *sptr, char *nick, char *username, char *umode, char *virthost, char *ip)
{
	ConfigItem_ban *bconf;
	char *parv[3], *tmpstr;
#ifdef HOSTILENAME
	char stripuser[USERLEN + 1], *u1 = stripuser, *u2, olduser[USERLEN + 1],
	    userbad[USERLEN * 2 + 1], *ubad = userbad, noident = 0;
#endif
	int  xx;
	anUser *user = sptr->user;
	aClient *nsptr;
	int  i;
	char mo[256];
	char *tkllayer[9] = {
		me.name,	/*0  server.name */
		"+",		/*1  +|- */
		"z",		/*2  G   */
		"*",		/*3  user */
		NULL,		/*4  host */
		NULL,
		NULL,		/*6  expire_at */
		NULL,		/*7  set_at */
		NULL		/*8  reason */
	};
	aTKline *savetkl = NULL;
	ConfigItem_tld *tlds;
	cptr->last = TStime();
	parv[0] = sptr->name;
	parv[1] = parv[2] = NULL;
	nick = sptr->name; /* <- The data is always the same, but the pointer is sometimes not,
	                    *    I need this for one of my modules, so do not remove! ;) -- Syzop */
	
	if (MyConnect(sptr))
	{
		if ((i = check_client(sptr, username))) {
			/* This had return i; before -McSkaf */
			if (i == -5)
				return FLUSH_BUFFER;

			sendto_snomask(SNO_CLIENT,
			    "*** Notice -- %s from %s.",
			    i == -3 ? "Too many connections" :
			    "Unauthorized connection", get_client_host(sptr));
			ircstp->is_ref++;
			ircsprintf(mo, "This server is full.");
			return
			    exit_client(cptr, sptr, &me,
			    i ==
			    -3 ? mo :
			    "You are not authorized to connect to this server");
		}

		if (sptr->hostp)
		{
			/* reject ascci < 32 and ascii >= 127 (note: upper resolver might be even more strict) */
			for (tmpstr = sptr->sockhost; *tmpstr > ' ' && *tmpstr < 127; tmpstr++);
			
			/* if host contained invalid ASCII _OR_ the DNS reply is an IP-like reply
			 * (like: 1.2.3.4), then reject it and use IP instead.
			 */
			if (*tmpstr || !*user->realhost || (isdigit(*sptr->sockhost) && isdigit(*tmpstr - 1)))
				strncpyzt(sptr->sockhost, (char *)Inet_ia2p((struct IN_ADDR*)&sptr->ip), sizeof(sptr->sockhost));
		}
		strncpyzt(user->realhost, sptr->sockhost, sizeof(sptr->sockhost)); /* SET HOSTNAME */

		/*
		 * I do not consider *, ~ or ! 'hostile' in usernames,
		 * as it is easy to differentiate them (Use \*, \? and \\)
		 * with the possible?
		 * exception of !. With mIRC etc. ident is easy to fake
		 * to contain @ though, so if that is found use non-ident
		 * username. -Donwulff
		 *
		 * I do, We only allow a-z A-Z 0-9 _ - and . now so the
		 * !strchr(sptr->username, '@') check is out of date. -Cabal95
		 *
		 * Moved the noident stuff here. -OnyxDragon
		 */
		if (!(sptr->flags & FLAGS_DOID)) 
			strncpyzt(user->username, username, USERLEN + 1);
		else if (sptr->flags & FLAGS_GOTID) 
			strncpyzt(user->username, sptr->username, USERLEN + 1);
		else
		{

			/* because username may point to user->username */
			char temp[USERLEN + 1];
			strncpyzt(temp, username, USERLEN + 1);
			if (IDENT_CHECK == 0) {
				strncpyzt(user->username, temp, USERLEN + 1);
			}
			else {
				*user->username = '******';
				strncpyzt((user->username + 1), temp, USERLEN);
#ifdef HOSTILENAME
				noident = 1;
#endif
			}

		}
#ifdef HOSTILENAME
		/*
		 * Limit usernames to just 0-9 a-z A-Z _ - and .
		 * It strips the "bad" chars out, and if nothing is left
		 * changes the username to the first 8 characters of their
		 * nickname. After the MOTD is displayed it sends numeric
		 * 455 to the user telling them what(if anything) happened.
		 * -Cabal95
		 *
		 * Moved the noident thing to the right place - see above
		 * -OnyxDragon
		 * 
		 * No longer use nickname if the entire ident is invalid,
                 * if thats the case, it is likely the user is trying to cause
		 * problems so just ban them. (Using the nick could introduce
		 * hostile chars) -- codemastr
		 */
		for (u2 = user->username + noident; *u2; u2++)
		{
			if (isallowed(*u2))
				*u1++ = *u2;
			else if (*u2 < 32)
			{
				/*
				 * Make sure they can read what control
				 * characters were in their username.
				 */
				*ubad++ = '^';
				*ubad++ = *u2 + '@';
			}
			else
				*ubad++ = *u2;
		}
		*u1 = '\0';
		*ubad = '\0';
		if (strlen(stripuser) != strlen(user->username + noident))
		{
			if (stripuser[0] == '\0')
			{
				return exit_client(cptr, cptr, cptr, "Hostile username. Please use only 0-9 a-z A-Z _ - and . in your username.");
			}

			strcpy(olduser, user->username + noident);
			strncpy(user->username + 1, stripuser, USERLEN - 1);
			user->username[0] = '~';
			user->username[USERLEN] = '\0';
		}
		else
			u1 = NULL;
#endif

		/*
		 * following block for the benefit of time-dependent K:-lines
		 */
		if ((bconf =
		    Find_ban(sptr, make_user_host(user->username, user->realhost),
		    CONF_BAN_USER)))
		{
			ircstp->is_ref++;
			sendto_one(cptr,
			    ":%s %d %s :*** You are not welcome on this server (%s)"
			    " Email %s for more information.",
			    me.name, ERR_YOUREBANNEDCREEP,
			    cptr->name, bconf->reason ? bconf->reason : "",
			    KLINE_ADDRESS);
			return exit_client(cptr, cptr, cptr, "You are banned");
		}
		if ((bconf = Find_ban(NULL, sptr->info, CONF_BAN_REALNAME)))
		{
			ircstp->is_ref++;
			sendto_one(cptr,
			    ":%s %d %s :*** Your GECOS (real name) is not allowed on this server (%s)"
			    " Please change it and reconnect",
			    me.name, ERR_YOUREBANNEDCREEP,
			    cptr->name, bconf->reason ? bconf->reason : "");

			return exit_client(cptr, sptr, &me,
			    "Your GECOS (real name) is banned from this server");
		}
		tkl_check_expire(NULL);
		/* Check G/Z lines before shuns -- kill before quite -- codemastr */
		if ((xx = find_tkline_match(sptr, 0)) < 0)
		{
			ircstp->is_ref++;
			return xx;
		}
		find_shun(sptr);

		/* Technical note regarding next few lines of code:
		 * If the spamfilter matches, depending on the action:
		 *  If it's block/dccblock/whatever the retval is -1 ===> we return, client stays "locked forever".
		 *  If it's kill/tklline the retval is -2 ==> we return with -2 (aka: FLUSH_BUFFER)
		 *  If it's action is viruschan the retval is -5 ==> we continue, and at the end of this return
		 *    take special actions. We cannot do that directly here since the user is not fully registered
		 *    yet (at all).
		 *  -- Syzop
		 */
		spamfilter_build_user_string(spamfilter_user, sptr->name, sptr);
		xx = dospamfilter(sptr, spamfilter_user, SPAMF_USER, NULL, 0, &savetkl);
		if ((xx < 0) && (xx != -5))
			return xx;

		RunHookReturnInt(HOOKTYPE_PRE_LOCAL_CONNECT, sptr, !=0);
	}
	else
	{
Ejemplo n.º 5
0
/*
 * Heavily modified from the ircu m_motd by codemastr
 * Also svsmotd support added
 */
int short_motd(aClient *sptr)
{
       ConfigItem_tld *tld;
       aMotdFile *themotd;
       aMotdLine *motdline;
       struct tm *tm;
       char userhost[HOSTLEN + USERLEN + 6];
       char is_short;

       tm = NULL;
       is_short = 1;

       strlcpy(userhost,make_user_host(sptr->user->username, sptr->user->realhost), sizeof userhost);
       tld = Find_tld(sptr, userhost);

       /*
	* Try different sources of short MOTDs, falling back to the
	* long MOTD.
       */
       themotd = &smotd;
       if (tld && tld->smotd.lines)
	       themotd = &tld->smotd;

       /* try long MOTDs */
       if (!themotd->lines)
       {
	       is_short = 0;
	       if (tld && tld->motd.lines)
		       themotd = &tld->motd;
	       else
		       themotd = &motd;
       }

       if (!themotd->lines)
       {
               sendto_one(sptr, err_str(ERR_NOMOTD), me.name, sptr->name);
               return 0;
       }
       if (themotd->last_modified.tm_year)
       {
	       tm = &themotd->last_modified; /* for readability */
               sendto_one(sptr, rpl_str(RPL_MOTDSTART), me.name, sptr->name,
                   me.name);
               sendto_one(sptr, ":%s %d %s :- %d/%d/%d %d:%02d", me.name,
                   RPL_MOTD, sptr->name, tm->tm_mday, tm->tm_mon + 1,
                   1900 + tm->tm_year, tm->tm_hour, tm->tm_min);
       }
       if (is_short)
       {
               sendto_one(sptr, rpl_str(RPL_MOTD), me.name, sptr->name,
                       "This is the short MOTD. To view the complete MOTD type /motd");
               sendto_one(sptr, rpl_str(RPL_MOTD), me.name, sptr->name, "");
       }

       motdline = NULL;
       if (themotd)
	       motdline = themotd->lines;
       while (motdline)
       {
               sendto_one(sptr, rpl_str(RPL_MOTD), me.name, sptr->name,
                   motdline->line);
               motdline = motdline->next;
       }
       sendto_one(sptr, rpl_str(RPL_ENDOFMOTD), me.name, sptr->name);
       return 0;
}
Ejemplo n.º 6
0
DLLFUNC int m_rmtkl(aClient *cptr, aClient *sptr, int parc, char *parv[])
{
aTKline *tk, *next = NULL;
TKLType *tkltype;
char *types, *uhmask, *cmask, *p;
char gmt[256], flag;
int tklindex;

	if (!IsULine(sptr) && !(IsPerson(sptr) && IsAnOper(sptr)))
	{
		sendto_one(sptr, err_str(ERR_NOPRIVILEGES), me.name, parv[0]);
		return -1;
	}

	if (IsNotParam(1))
		return dumpit(sptr, rmtkl_help);

	if (IsNotParam(2))
	{
		sendto_one(sptr, err_str(ERR_NEEDMOREPARAMS), me.name, parv[0], "RMTKL");
		sendnotice(sptr, "Type '/RMTKL' for help");
		return 0;
	}

	types	= parv[1];
	uhmask	= parv[2];
	cmask	= IsParam(3) ? parv[3] : NULL;

	/* I don't add 'q' and 'Q' here. They are different. */
	if (strchr(types, '*'))
		types = "KzGZs";

	/* check access */
	if (!IsULine(sptr))
		for (p = types; *p; p++)
		{
			tkltype = find_TKLType_by_flag(*p);
			if (!tkltype->type)
				continue;
			if (((tkltype->type & TKL_GLOBAL) && !IsOper(sptr))
			    || !(sptr->oflag & tkltype->oflag))
			{
				sendto_one(sptr, err_str(ERR_NOPRIVILEGES),
					me.name, parv[0]);
				return -1;
			}
		}

	for (tkltype = tkl_types; tkltype->type; tkltype++)
	{
		flag		= tkltype->flag;
		tklindex	= tkl_hash(flag);

		if (!strchr(types, flag))
			continue;

		for (tk = tklines[tklindex]; tk; tk = next)
		{
			next = tk->next;

			if (tk->type != tkltype->type)
				continue;
			if (tk->type & TKL_NICK)
			{
				/*
				 * If it's a services hold (ie. NickServ is holding
				 * a nick), it's better not to touch it
				 */
				if (*tk->usermask == 'H')
					continue;
				if (match(uhmask, tk->hostmask))
					continue;
			}
			else
				if (match(uhmask, make_user_host(tk->usermask, tk->hostmask)))
					continue;

			if (cmask && _match(cmask, tk->reason))
				continue;

			strncpyzt(gmt, asctime(gmtime((TS *)&tk->set_at)),
				sizeof gmt);
			iCstrip(gmt);

			if (tk->type & TKL_NICK)
			{
				sendto_snomask(SNO_TKL, "%s removed %s %s (set at %s "
					"- reason: %s)",
					sptr->name, tkltype->txt, tk->hostmask, gmt,
					tk->reason);
				ircd_log(LOG_TKL, "%s removed %s %s (set at %s "
					"- reason: %s)",
					sptr->name, tkltype->txt, tk->hostmask,
					gmt, tk->reason);
			}
			else
			{
				sendto_snomask(SNO_TKL, "%s removed %s %s@%s (set at "
					"%s - reason: %s)",
					sptr->name, tkltype->txt, tk->usermask,
					tk->hostmask, gmt, tk->reason);
				ircd_log(LOG_TKL, "%s removed %s %s@%s (set at "
					"%s - reason: %s)",
					sptr->name, tkltype->txt, tk->usermask,
					tk->hostmask, gmt, tk->reason);
			}

			if ((tk->type & TKL_GLOBAL) && flag)
				sendto_serv_butone_token(&me, me.name, MSG_TKL, TOK_TKL,
					"- %c %s %s %s",
					flag, tk->usermask, tk->hostmask, parv[0]);
			if (tk->type & TKL_SHUN)
				tkl_check_local_remove_shun(tk);
			my_tkl_del_line(tk, tklindex);
		}
	}

	return 0;
}
Ejemplo n.º 7
0
/*
 * Heavily modified from the ircu m_motd by codemastr
 * Also svsmotd support added
 */
DLLFUNC CMD_FUNC(m_motd)
{
	ConfigItem_tld *ptr;
	aMotd *temp, *temp2;
	struct tm *tm = &motd_tm;
	int  svsnofile = 0;
	char userhost[HOSTLEN + USERLEN + 6];

	if (IsServer(sptr))
		return 0;
	if (hunt_server_token(cptr, sptr, MSG_MOTD, TOK_MOTD, ":%s", 1, parc, parv) !=
HUNTED_ISME)
		return 0;
#ifndef TLINE_Remote
	if (!MyConnect(sptr))
	{
		temp = motd;
		goto playmotd;
	}
#endif
	strlcpy(userhost,make_user_host(cptr->user->username, cptr->user->realhost), sizeof userhost);
	ptr = Find_tld(sptr, userhost);

	if (ptr)
	{
		temp = ptr->motd;
		tm = &ptr->motd_tm;
	}
	else
		temp = motd;

      playmotd:
	if (temp == NULL)
	{
		sendto_one(sptr, err_str(ERR_NOMOTD), me.name, parv[0]);
		svsnofile = 1;
		goto svsmotd;

	}

	if (tm)
	{
		sendto_one(sptr, rpl_str(RPL_MOTDSTART), me.name, parv[0],
		    me.name);
		sendto_one(sptr, ":%s %d %s :- %d/%d/%d %d:%02d", me.name,
		    RPL_MOTD, parv[0], tm->tm_mday, tm->tm_mon + 1,
		    1900 + tm->tm_year, tm->tm_hour, tm->tm_min);
	}

	while (temp)
	{
		sendto_one(sptr, rpl_str(RPL_MOTD), me.name, parv[0],
		    temp->line);
		temp = temp->next;
	}
      svsmotd:
	temp2 = svsmotd;
	while (temp2)
	{
		sendto_one(sptr, rpl_str(RPL_MOTD), me.name, parv[0],
		    temp2->line);
		temp2 = temp2->next;
	}
	if (svsnofile == 0)
		sendto_one(sptr, rpl_str(RPL_ENDOFMOTD), me.name, parv[0]);
	return 0;
}