/* * ms_connect - CONNECT command handler * * Added by Jto 11 Feb 1989 * * m_connect * parv[0] = sender prefix * parv[1] = servername * parv[2] = port number * parv[3] = remote server */ static void ms_connect(struct Client *client_p, struct Client *source_p, int parc, char *parv[]) { int port; int tmpport; struct ConfItem *aconf; struct Client *target_p; if(hunt_server(client_p, source_p, ":%s CONNECT %s %s :%s", 3, parc, parv) != HUNTED_ISME) { return; } if(*parv[1] == '\0') { sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), me.name, parv[0], "CONNECT"); return; } if((target_p = find_server(parv[1]))) { sendto_one(source_p, ":%s NOTICE %s :Connect: Server %s %s %s.", me.name, parv[0], parv[1], "already exists from", target_p->from->name); return; } /* * try to find the name, then host, if both fail notify ops and bail */ if(!(aconf = find_conf_by_name(parv[1], CONF_SERVER))) { if(!(aconf = find_conf_by_host(parv[1], CONF_SERVER))) { sendto_one(source_p, ":%s NOTICE %s :Connect: Host %s not listed in ircd.conf", me.name, parv[0], parv[1]); return; } } s_assert(0 != aconf); /* * Get port number from user, if given. If not specified, * use the default form configuration structure. If missing * from there, then use the precompiled default. */ tmpport = port = aconf->port; if(parc > 2 && !EmptyString(parv[2])) { port = atoi(parv[2]); /* if someone sends port 0, and we have a config port.. use it */ if(port == 0 && aconf->port) port = aconf->port; else if(port <= 0) { sendto_one(source_p, ":%s NOTICE %s :Connect: Illegal port number", me.name, parv[0]); return; } } else if(port <= 0 && (port = PORTNUM) <= 0) { sendto_one(source_p, ":%s NOTICE %s :Connect: missing port number", me.name, parv[0]); return; } /* * Notify all operators about remote connect requests */ sendto_wallops_flags(UMODE_WALLOP, &me, "Remote CONNECT %s %d from %s", parv[1], port, source_p->name); sendto_server(NULL, NULL, NOCAPS, NOCAPS, ":%s WALLOPS :Remote CONNECT %s %d from %s", me.name, parv[1], port, source_p->name); ilog(L_TRACE, "CONNECT From %s : %s %d", parv[0], parv[1], port); aconf->port = port; /* * at this point we should be calling connect_server with a valid * C:line and a valid port in the C:line */ if(serv_connect(aconf, source_p)) sendto_one(source_p, ":%s NOTICE %s :*** Connecting to %s.%d", me.name, parv[0], aconf->name, aconf->port); else sendto_one(source_p, ":%s NOTICE %s :*** Couldn't connect to %s.%d", me.name, parv[0], aconf->name, aconf->port); /* * client is either connecting with all the data it needs or has been * destroyed */ aconf->port = tmpport; }
/* * mo_connect - CONNECT command handler * * Added by Jto 11 Feb 1989 * * m_connect * parv[0] = sender prefix * parv[1] = servername * parv[2] = port number * parv[3] = remote server */ static void mo_connect(struct Client *client_p, struct Client *source_p, int parc, char *parv[]) { int port; int tmpport; struct ConfItem *aconf; struct Client *target_p; /* always privileged with handlers */ if(MyConnect(source_p) && !IsOperRemote(source_p) && parc > 3) { sendto_one(source_p, ":%s NOTICE %s :You need remote = yes;", me.name, parv[0]); return; } if(hunt_server(client_p, source_p, ":%s CONNECT %s %s :%s", 3, parc, parv) != HUNTED_ISME) { return; } if(*parv[1] == '\0') { sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), me.name, parv[0], "CONNECT"); return; } if((target_p = find_server(parv[1]))) { sendto_one(source_p, ":%s NOTICE %s :Connect: Server %s already exists from %s.", me.name, parv[0], parv[1], target_p->from->name); return; } /* * try to find the name, then host, if both fail notify ops and bail */ if(!(aconf = find_conf_by_name(parv[1], CONF_SERVER))) { if(!(aconf = find_conf_by_host(parv[1], CONF_SERVER))) { sendto_one(source_p, "NOTICE %s :Connect: Host %s not listed in ircd.conf", parv[0], parv[1]); return; } } s_assert(0 != aconf); /* * Get port number from user, if given. If not specified, * use the default form configuration structure. If missing * from there, then use the precompiled default. */ tmpport = port = aconf->port; if(parc > 2 && !EmptyString(parv[2])) { if((port = atoi(parv[2])) <= 0) { sendto_one(source_p, "NOTICE %s :Connect: Illegal port number", parv[0]); return; } } else if(port <= 0 && (port = PORTNUM) <= 0) { sendto_one(source_p, ":%s NOTICE %s :Connect: missing port number", me.name, parv[0]); return; } /* * Notify all operators about remote connect requests */ ilog(L_TRACE, "CONNECT From %s : %s %s", parv[0], parv[1], parv[2] ? parv[2] : ""); aconf->port = port; /* * at this point we should be calling connect_server with a valid * C:line and a valid port in the C:line */ if(serv_connect(aconf, source_p)) { #ifndef HIDE_SERVERS_IPS if(IsOperAdmin(source_p)) sendto_one(source_p, ":%s NOTICE %s :*** Connecting to %s[%s].%d", me.name, parv[0], aconf->host, aconf->name, aconf->port); else #endif sendto_one(source_p, ":%s NOTICE %s :*** Connecting to %s.%d", me.name, parv[0], aconf->name, aconf->port); } else { sendto_one(source_p, ":%s NOTICE %s :*** Couldn't connect to %s.%d", me.name, parv[0], aconf->name, aconf->port); } /* * client is either connecting with all the data it needs or has been * destroyed */ aconf->port = tmpport; }
/* * m_connect - CONNECT command handler * * Added by Jto 11 Feb 1989 * * m_connect * 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[]) { int port; int tmpport; struct ConfItem* aconf; struct Client* acptr; if (!IsPrivileged(sptr)) { sendto_one(sptr, form_str(ERR_NOPRIVILEGES), me.name, parv[0]); return -1; } if (IsLocOp(sptr) && parc > 3) { /* * Only allow LocOps to make local CONNECTS --SRB */ return 0; } if (MyConnect(sptr) && !IsOperRemote(sptr) && parc > 3) { sendto_one(sptr,":%s NOTICE %s :You have no R flag", me.name, parv[0]); return 0; } if (hunt_server(cptr, sptr, ":%s CONNECT %s %s :%s", 3, parc, parv) != HUNTED_ISME) return 0; if (parc < 2 || *parv[1] == '\0') { sendto_one(sptr, form_str(ERR_NEEDMOREPARAMS), me.name, parv[0], "CONNECT"); return -1; } if ((acptr = find_server(parv[1]))) { sendto_one(sptr, ":%s NOTICE %s :Connect: Server %s %s %s.", me.name, parv[0], parv[1], "already exists from", acptr->from->name); return 0; } /* * try to find the name, then host, if both fail notify ops and bail */ if (!(aconf = find_conf_by_name(parv[1], CONF_CONNECT_SERVER))) { #ifndef HIDE_SERVERS_IPS if (!(aconf = find_conf_by_host(parv[1], CONF_CONNECT_SERVER))) { #endif sendto_one(sptr, "NOTICE %s :Connect: Host %s not listed in ircd.conf", parv[0], parv[1]); return 0; #ifndef HIDE_SERVERS_IPS } #endif } assert(0 != aconf); /* * Get port number from user, if given. If not specified, * use the default form configuration structure. If missing * from there, then use the precompiled default. */ tmpport = port = aconf->port; if (parc > 2 && !EmptyString(parv[2])) { #ifdef NEG_PORT if ((port = atoi(parv[2])) < 0) #else if ((port = atoi(parv[2])) <= 0) #endif { sendto_one(sptr, "NOTICE %s :Connect: Illegal port number", parv[0]); return 0; } } #ifdef NEG_PORT else if (port < 0 && (port = PORTNUM) <= 0) #else else if (port <= 0 && (port = PORTNUM) <= 0) #endif { sendto_one(sptr, ":%s NOTICE %s :Connect: missing port number", me.name, parv[0]); return 0; } #ifdef NEG_PORT if (port == 0) port = tmpport; /* From conf */ if (port == 0) port = PORTNUM; /* Default if there wasn't one set in conf */ #endif /* * Notify all operators about remote connect requests */ if (!IsAnOper(cptr)) { sendto_ops_butone(NULL, &me, ":%s WALLOPS :Remote CONNECT %s %s from %s", me.name, parv[1], parv[2] ? parv[2] : "", get_client_name(sptr, FALSE)); irclog(L_TRACE, "CONNECT From %s : %s %s", parv[0], parv[1], parv[2] ? parv[2] : ""); } aconf->port = port; /* * at this point we should be calling connect_server with a valid * C:line and a valid port in the C:line */ if (connect_server(aconf, sptr, 0)) #if (defined SERVERHIDE) || (defined HIDE_SERVERS_IPS) sendto_one(sptr, ":%s NOTICE %s :*** Connecting to %s[%s].%d", me.name, parv[0], "255.255.255.255", aconf->name, aconf->port); else sendto_one(sptr, ":%s NOTICE %s :*** Couldn't connect to %s.%d", me.name, parv[0], "255.255.255.255",aconf->port); #else sendto_one(sptr, ":%s NOTICE %s :*** Connecting to %s[%s].%d", me.name, parv[0], aconf->host, aconf->name, aconf->port); else