X-Git-Url: http://git.pk910.de/?a=blobdiff_plain;f=ircd%2Fm_connect.c;h=ca4856d9d829bef15145e423787fb49ebaf0dbf0;hb=refs%2Fheads%2Fupstream-ssl;hp=81fe44913932295a18e8a90b6f8ba9dbee59d2fe;hpb=448cf2696162129b24174ea625684984378322aa;p=ircu2.10.12-pk.git diff --git a/ircd/m_connect.c b/ircd/m_connect.c index 81fe449..ca4856d 100644 --- a/ircd/m_connect.c +++ b/ircd/m_connect.c @@ -79,18 +79,13 @@ * note: it is guaranteed that parv[0]..parv[parc-1] are all * non-NULL pointers. */ -#if 0 -/* - * No need to include handlers.h here the signatures must match - * and we don't need to force a rebuild of all the handlers everytime - * we add a new one to the list. --Bleep - */ -#include "handlers.h" -#endif /* 0 */ +#include "config.h" + #include "client.h" #include "crule.h" #include "hash.h" #include "ircd.h" +#include "ircd_features.h" #include "ircd_log.h" #include "ircd_reply.h" #include "ircd_string.h" @@ -104,7 +99,7 @@ #include "s_user.h" #include "send.h" -#include +/* #include -- Now using assert in ircd_log.h */ #include /* @@ -120,7 +115,7 @@ int ms_connect(struct Client* cptr, struct Client* sptr, int parc, char* parv[]) { unsigned short port; unsigned short tmpport; - const char* crule_name; + const char* rule; struct ConfItem* aconf; struct Client* acptr; struct Jupe* ajupe; @@ -129,7 +124,7 @@ int ms_connect(struct Client* cptr, struct Client* sptr, int parc, char* parv[]) assert(0 != sptr); if (!IsPrivileged(sptr)) - return send_error_to_client(sptr, ERR_NOPRIVILEGES); + return send_reply(sptr, ERR_NOPRIVILEGES); if (parc < 4) { /* @@ -137,11 +132,12 @@ int ms_connect(struct Client* cptr, struct Client* sptr, int parc, char* parv[]) * checked it's args, if we don't have parc == 4, something * isn't right. */ + protocol_violation(sptr, "Too few parameters to connect"); return need_more_params(sptr, "CONNECT"); } - if (hunt_server(1, cptr, sptr, - "%s%s " TOK_CONNECT " %s %s :%s", 3, parc, parv) != HUNTED_ISME) + if (hunt_server_cmd(sptr, CMD_CONNECT, cptr, 1, "%s %s :%C", 3, parc, parv) + != HUNTED_ISME) return 0; /* @@ -150,17 +146,16 @@ int ms_connect(struct Client* cptr, struct Client* sptr, int parc, char* parv[]) * present below. --Bleep */ if (0 == (aconf = conf_find_server(parv[1]))) { - sendto_one(sptr, "%s NOTICE %s%s :Connect: Host %s not listed in ircd.conf", - NumServ(&me), NumNick(sptr), parv[1]); + sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :Connect: Host %s not listed " + "in ircd.conf", sptr, parv[1]); return 0; } /* * use aconf->name to look up the server */ if ((acptr = FindServer(aconf->name))) { - sendto_one(sptr, "%s NOTICE %s%s :Connect: Server %s %s %s.", - NumServ(&me), NumNick(sptr), parv[1], "already exists from", - acptr->from->name); + sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :Connect: Server %s already " + "exists from %s", sptr, parv[1], cli_name(cli_from(acptr))); return 0; } /* @@ -169,51 +164,52 @@ int ms_connect(struct Client* cptr, struct Client* sptr, int parc, char* parv[]) * are ored together. Oper connects are effected only by D * lines (CRULEALL) not d lines (CRULEAUTO). */ - if ((crule_name = conf_eval_crule(aconf))) { - sendto_one(sptr, "%s NOTICE %s%s :Connect: Disallowed by rule: %s", - NumServ(&me), NumNick(sptr), crule_name); + if ((rule = conf_eval_crule(aconf->name, CRULE_ALL))) { + sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :Connect: Disallowed by rule: %s", sptr, rule); return 0; } /* * Check to see if the server is juped; if it is, disallow the connect */ if ((ajupe = jupe_find(aconf->name)) && JupeIsActive(ajupe)) { - sendto_one(sptr, "%s NOTICE %s%s :Connect: Server %s is juped: %s", - NumServ(&me), NumNick(sptr), JupeServer(ajupe), - JupeReason(ajupe)); + sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :Connect: Server %s is juped: %s", + sptr, JupeServer(ajupe), JupeReason(ajupe)); return 0; } + /* - * Get port number from params, port must be non-zero if it comes from a - * server. + * Allow opers to /connect foo.* 0 bah.* to connect foo and bah + * using the conf's configured port */ - if ((port = atoi(parv[2])) == 0) { - sendto_one(sptr, "%s NOTICE %s%s :Connect: Invalid port number", - NumServ(&me), NumNick(sptr)); - return 0; - } + port = atoi(parv[2]); /* * save the old port */ - tmpport = aconf->port; - aconf->port = port; + tmpport = aconf->address.port; + if (port) + aconf->address.port = port; + else + port = aconf->address.port; + /* * Notify all operators about remote connect requests */ - sendto_ops_butone(0, &me, ":%s WALLOPS :Remote CONNECT %s %s from %s", - me.name, parv[1], parv[2] ? parv[2] : "", - get_client_name(sptr, HIDE_IP)); - ircd_log(L_INFO, "CONNECT From %s : %s %d", parv[0], parv[1], parv[2] ? parv[2] : ""); + sendwallto_group_butone(&me, WALL_WALLOPS, 0, + "Remote CONNECT %s %s from %s", parv[1], + parv[2] ? parv[2] : "", + get_client_name(sptr, HIDE_IP)); + log_write(LS_NETWORK, L_INFO, 0, "CONNECT From %C : %s %s", sptr, parv[1], + parv[2] ? parv[2] : ""); - if (connect_server(aconf, sptr, 0)) { - sendto_one(sptr, "%s NOTICE %s%s :*** Connecting to %s.", - NumServ(&me), NumNick(sptr), aconf->name); + if (connect_server(aconf, sptr)) { + sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :*** Connecting to %s.", sptr, + aconf->name); } else { - sendto_one(sptr, "%s NOTICE %s%s :*** Connection to %s failed", - NumServ(&me), NumNick(sptr), aconf->name); + sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :*** Connection to %s failed", + sptr, aconf->name); } - aconf->port = tmpport; + aconf->address.port = tmpport; return 0; } @@ -230,7 +226,7 @@ int mo_connect(struct Client* cptr, struct Client* sptr, int parc, char* parv[]) { unsigned short port; unsigned short tmpport; - const char* crule_name; + const char* rule; struct ConfItem* aconf; struct Client* acptr; struct Jupe* ajupe; @@ -251,28 +247,27 @@ int mo_connect(struct Client* cptr, struct Client* sptr, int parc, char* parv[]) /* * Only allow LocOps to make local CONNECTS --SRB */ - return 0; + return send_reply(cptr, ERR_NOPRIVILEGES); } else { struct Client* acptr2; struct Client* acptr3; if (!(acptr3 = find_match_server(parv[3]))) { - send_error_to_client(sptr, ERR_NOSUCHSERVER, parv[3]); - return 0; + return send_reply(sptr, ERR_NOSUCHSERVER, parv[3]); } /* * Look for closest matching server * needed for "/connect blah 4400 *"? */ - for (acptr2 = acptr3; acptr2 != &me; acptr2 = acptr2->serv->up) { - if (!match(parv[3], acptr2->name)) + for (acptr2 = acptr3; acptr2 != &me; acptr2 = cli_serv(acptr2)->up) { + if (!match(parv[3], cli_name(acptr2))) acptr3 = acptr2; } - parv[3] = acptr3->name; - if (hunt_server(1, cptr, sptr, "%s%s " TOK_CONNECT " %s %s :%s", - 3, parc, parv) != HUNTED_ISME) + parv[3] = cli_name(acptr3); + if (hunt_server_cmd(sptr, CMD_CONNECT, cptr, 1, "%s %s :%C", 3, parc, + parv) != HUNTED_ISME) return 0; } } @@ -282,18 +277,16 @@ int mo_connect(struct Client* cptr, struct Client* sptr, int parc, char* parv[]) * present below. --Bleep */ if (0 == (aconf = conf_find_server(parv[1]))) { - sendto_one(sptr, - ":%s NOTICE %s :Connect: Host %s not listed in ircd.conf", - me.name, parv[0], parv[1]); + sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :Connect: Host %s not listed " + "in ircd.conf", sptr, parv[1]); return 0; } /* * use aconf->name to look up the server, see above */ if ((acptr = FindServer(aconf->name))) { - sendto_one(sptr, ":%s NOTICE %s :Connect: Server %s %s %s.", - me.name, parv[0], parv[1], "already exists from", - acptr->from->name); + sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :Connect: Server %s already " + "exists from %s", sptr, parv[1], cli_name(cli_from(acptr))); return 0; } /* @@ -302,17 +295,16 @@ int mo_connect(struct Client* cptr, struct Client* sptr, int parc, char* parv[]) * are ored together. Oper connects are effected only by D * lines (CRULEALL) not d lines (CRULEAUTO). */ - if ((crule_name = conf_eval_crule(aconf))) { - sendto_one(sptr, ":%s NOTICE %s :Connect: Disallowed by rule: %s", - me.name, parv[0], crule_name); + if ((rule = conf_eval_crule(aconf->name, CRULE_ALL))) { + sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :Connect: Disallowed by rule: %s", sptr, rule); return 0; } /* * Check to see if the server is juped; if it is, disallow the connect */ if ((ajupe = jupe_find(aconf->name)) && JupeIsActive(ajupe)) { - sendto_one(sptr, "%s NOTICE %s%s :Connect: Server %s is juped: %s", - me.name, NumNick(sptr), JupeServer(ajupe), JupeReason(ajupe)); + sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :Connect: Server %s is juped: %s", + sptr, JupeServer(ajupe), JupeReason(ajupe)); return 0; } /* @@ -320,212 +312,32 @@ int mo_connect(struct Client* cptr, struct Client* sptr, int parc, char* parv[]) * use the default from configuration structure. If missing * from there, then use the precompiled default. */ - port = aconf->port; + port = aconf->address.port; if (parc > 2) { assert(0 != parv[2]); if (0 == (port = atoi(parv[2]))) { - sendto_one(sptr, ":%s NOTICE %s :Connect: Invalid port number", - me.name, parv[0]); + sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :Connect: Invalid port number", + sptr); return 0; } } - if (0 == port && 0 == (port = SERVER_PORT)) { - sendto_one(sptr, ":%s NOTICE %s :Connect: missing port number", - me.name, parv[0]); + if (0 == port && 0 == (port = feature_int(FEAT_SERVER_PORT))) { + sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :Connect: missing port number", + sptr); return 0; } - tmpport = aconf->port; - aconf->port = port; + tmpport = aconf->address.port; + aconf->address.port = port; - if (connect_server(aconf, sptr, 0)) { - sendto_one(sptr, ":%s NOTICE %s :*** Connecting to %s.", - me.name, parv[0], aconf->name); + if (connect_server(aconf, sptr)) { + sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :*** Connecting to %s.", sptr, + aconf->name); } else { - sendto_one(sptr, ":%s NOTICE %s :*** Connection to %s failed", - me.name, parv[0], aconf->name); + sendcmdto_one(&me, CMD_NOTICE, sptr, "%C :*** Connection to %s failed", + sptr, aconf->name); } - aconf->port = tmpport; + aconf->address.port = tmpport; return 0; } - - -#if 0 -/* - * XXX - remove when regression testing complete - * - * m_connect - Added by Jto 11 Feb 1989 - * - * parv[0] = sender prefix - * parv[1] = servername - * parv[2] = port number - * parv[3] = remote server - */ -int m_connect(struct Client *cptr, struct Client *sptr, int parc, char *parv[]) -{ - unsigned short port; - unsigned short tmpport; - struct ConfItem* aconf; - struct ConfItem* cconf; - struct Client* acptr; - struct Jupe* ajupe; - - if (!IsPrivileged(sptr)) { - sendto_one(sptr, err_str(ERR_NOPRIVILEGES), me.name, parv[0]); - return -1; - } - - if (IsLocOp(sptr) && parc > 3) /* Only allow LocOps to make */ - return 0; /* local CONNECTS --SRB */ - - if (parc > 3 && MyUser(sptr)) { - struct Client* acptr2; - struct Client* acptr3; - if (!(acptr3 = find_match_server(parv[3]))) { - sendto_one(sptr, err_str(ERR_NOSUCHSERVER), me.name, parv[0], parv[3]); - return 0; - } - - /* Look for closest matching server */ - for (acptr2 = acptr3; acptr2 != &me; acptr2 = acptr2->serv->up) - if (!match(parv[3], acptr2->name)) - acptr3 = acptr2; - - parv[3] = acptr3->name; - } - - if (hunt_server(1, cptr, sptr, - "%s%s " TOK_CONNECT " %s %s :%s", 3, parc, parv) != HUNTED_ISME) - return 0; - - if (parc < 2 || *parv[1] == '\0') { - return need_more_params(sptr, "CONNECT"); -#if 0 - return -1; -#endif - } - - if ((acptr = FindServer(parv[1]))) { - if (MyUser(sptr)) - sendto_one(sptr, ":%s NOTICE %s :Connect: Server %s %s %s.", - me.name, parv[0], parv[1], "already exists from", acptr->from->name); - else - sendto_one(sptr, "%s NOTICE %s%s :Connect: Server %s %s %s.", - NumServ(&me), NumNick(sptr), parv[1], "already exists from", - acptr->from->name); - return 0; - } - - for (aconf = GlobalConfList; aconf; aconf = aconf->next) { - if (CONF_SERVER == aconf->status && 0 == match(parv[1], aconf->name)) - break; - } -#if 0 - /* - * Checked first servernames, then try hostnames. - */ - if (!aconf) { - for (aconf = GlobalConfList; aconf; aconf = aconf->next) { - if (CONF_SERVER == aconf->status && 0 == match(parv[1], aconf->host)) - break; - } - } -#endif - if (!aconf) { - if (MyUser(sptr)) - sendto_one(sptr, ":%s NOTICE %s :Connect: Host %s not listed in ircd.conf", - me.name, parv[0], parv[1]); - else - sendto_one(sptr, "%s NOTICE %s%s :Connect: Host %s not listed in ircd.conf", - NumServ(&me), NumNick(sptr), parv[1]); - return 0; - } - /* - * Get port number from user, if given. If not specified, - * use the default from configuration structure. If missing - * from there, then use the precompiled default. - */ - tmpport = port = aconf->port; - if (parc > 2 && !BadPtr(parv[2])) { - if ((port = atoi(parv[2])) == 0) { - if (MyUser(sptr)) - sendto_one(sptr, ":%s NOTICE %s :Connect: Invalid port number", me.name, parv[0]); - else - sendto_one(sptr, "%s NOTICE %s%s :Connect: Invalid port number", - NumServ(&me), NumNick(sptr)); - return 0; - } - } - else if (port == 0 && (port = PORTNUM) == 0) { - if (MyUser(sptr)) - sendto_one(sptr, ":%s NOTICE %s :Connect: missing port number", - me.name, parv[0]); - else - sendto_one(sptr, "%s NOTICE %s%s :Connect: missing port number", - NumServ(&me), NumNick(sptr)); - return 0; - } - - /* - * Evaluate connection rules... If no rules found, allow the - * connect. Otherwise stop with the first true rule (ie: rules - * are ored together. Oper connects are effected only by D - * lines (CRULEALL) not d lines (CRULEAUTO). - */ - for (cconf = GlobalConfList; cconf; cconf = cconf->next) { - if ((CONF_CRULEALL == cconf->status) && - (0 == match(cconf->host, aconf->name))) { - if (crule_eval(cconf->passwd)) { - if (MyUser(sptr)) - sendto_one(sptr, ":%s NOTICE %s :Connect: Disallowed by rule: %s", - me.name, parv[0], cconf->name); - else - sendto_one(sptr, "%s NOTICE %s%s :Connect: Disallowed by rule: %s", - NumServ(&me), NumNick(sptr), cconf->name); - return 0; - } - } - } - /* - * Check to see if the server is juped; if it is, disallow the connect - */ - if ((ajupe = jupe_find(aconf->name)) && JupeIsActive(ajupe)) { - sendto_one(sptr, "%s NOTICE %s%s :Connect: Server %s is juped: %s", - NumServ(&me), NumNick(sptr), JupeServer(ajupe), - JupeReason(ajupe)); - return 0; - } - - /* - * Notify all operators about remote connect requests - */ - if (!IsAnOper(cptr)) { - sendto_ops_butone(0, &me, ":%s WALLOPS :Remote CONNECT %s %s from %s", - me.name, parv[1], parv[2] ? parv[2] : "", - get_client_name(sptr, HIDE_IP)); - ircd_log(L_INFO, "CONNECT From %s : %s %d", - parv[0], parv[1], parv[2] ? parv[2] : ""); - } - aconf->port = port; - if (connect_server(aconf, sptr, 0)) { - if (MyUser(sptr)) - sendto_one(sptr, ":%s NOTICE %s :*** Connecting to %s.", - me.name, parv[0], aconf->name); - else - sendto_one(sptr, "%s NOTICE %s%s :*** Connecting to %s.", - NumServ(&me), NumNick(sptr), aconf->name); - } - else { - if (MyUser(sptr)) - sendto_one(sptr, ":%s NOTICE %s :*** Connection to %s failed", - me.name, parv[0], aconf->name); - else - sendto_one(sptr, "%s NOTICE %s%s :*** Connection to %s failed", - NumServ(&me), NumNick(sptr), aconf->name); - } - aconf->port = tmpport; - return 0; -} -#endif /* 0 */ -