strncpy(clientlist[nick]->host, host,160);
strncpy(clientlist[nick]->dhost, dhost,160);
strncpy(clientlist[nick]->server, server,256);
- strncpy(clientlist[nick]->ident, ident,10); // +1 char to compensate for '~'
+ strncpy(clientlist[nick]->ident, ident,10); // +1 char to compensate for tilde
strncpy(clientlist[nick]->fullname, gecos,128);
clientlist[nick]->signon = TS;
clientlist[nick]->nping = 0; // this is ignored for a remote user anyway.
char* ipaddr = strtok(NULL," ");
char* ipport = strtok(NULL," ");
char* cookie = strtok(NULL," ");
+ log(DEBUG," ");
+ log(DEBUG," ");
+ log(DEBUG,"*** Connecting back to %s:%d",ipaddr,ipport);
me[defaultRoute]->MeshCookie(ipaddr,atoi(ipport),atoi(cookie),servername);
+ log(DEBUG," ");
}
void process_restricted_commands(char token,char* params,serverrec* source,serverrec* reply, char* udp_host,char* ipaddr,int port)
{
long authcookie = rand()*rand();
+ char buffer[MAXBUF];
switch(token)
{
WriteOpers("Server %s is starting netburst.",udp_host);
// now broadcast this new servers address out to all servers that are linked to us,
// except the newcomer. They'll all attempt to connect back to it.
- char buffer[MAXBUF];
- snprintf(buffer,MAXBUF,"+ %s %s %d %d",udp_host,ipaddr,port,authcookie);
- NetSendToAllExcept(buffer,udp_host);
+
+ // give the server its authcookie.
snprintf(buffer,MAXBUF,"~ %d",authcookie);
- NetSendToAllExcept(buffer,udp_host);
+ source->SendPacket(buffer,udp_host);
+ // tell all the other servers to use this authcookie to connect back again
+ snprintf(buffer,MAXBUF,"+ %s %s %d %d",udp_host,ipaddr,port,authcookie);
+ NetSendToAllExcept(udp_host,buffer);
break;
// ~
// Store authcookie
// without user or password, using it.
case '~':
auth_cookies.push_back(atoi(params));
- log(DEBUG,"Stored auth cookie, will permit servers with auth-cookie %d",atoi(params));
+ log(DEBUG,"*** Stored auth cookie, will permit servers with auth-cookie %d",atoi(params));
break;
// connect back to a server using an authcookie
case '+':
if (auth_cookies[u] == atoi(cookie))
{
WriteOpers("Allowed cookie from %s, is now part of the mesh",servername);
+
+
+ for (int j = 0; j < 32; j++)
+ {
+ if (me[j] != NULL)
+ {
+ for (int k = 0; k < me[j]->connectors.size(); k++)
+ {
+ if (!strcasecmp(me[j]->connectors[k].GetServerName().c_str(),udp_host))
+ {
+ me[j]->connectors[k].SetServerName(servername);
+ return;
+ }
+ }
+ }
+ WriteOpers("\2WARNING!\2 %s sent us an authentication packet but we are not authenticating with this server right now! Possible intrusion attempt!",udp_host);
+ return;
+ }
+
+
return;
}
}
// during a netburst, send all data to all other linked servers
if ((nb_start>0) && (udp_msg[0] != 'Y') && (udp_msg[0] != 'X') && (udp_msg[0] != 'F'))
{
- NetSendToAllExcept(udp_msg,udp_host);
+ NetSendToAllExcept(udp_host,udp_msg);
}
FOREACH_MOD OnPacketReceive(udp_msg);
handle_link_packet(udp_msg, udp_host, me[x]);