/[cvs]/eggdrop1.8/src/dcc.c
ViewVC logotype

Diff of /eggdrop1.8/src/dcc.c

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.1 by simple, Mon Jul 26 21:11:06 2010 UTC revision 1.2 by pseudo, Thu Aug 5 18:12:05 2010 UTC
# Line 268  void failed_link(int idx) Line 268  void failed_link(int idx)
268    
269    /* Try next port */    /* Try next port */
270    killsock(dcc[idx].sock);    killsock(dcc[idx].sock);
   dcc[idx].sock = getsock(SOCK_STRONGCONN);  
271    dcc[idx].port++;    dcc[idx].port++;
272    dcc[idx].timeval = now;    dcc[idx].timeval = now;
273      dcc[idx].sock = getsock(setsockname(&dcc[idx].sockname, dcc[idx].host,
274                                          dcc[idx].port, 1), SOCK_STRONGCONN);
275    if (dcc[idx].sock < 0 ||    if (dcc[idx].sock < 0 ||
276        open_telnet_raw(dcc[idx].sock, dcc[idx].addr ?        open_telnet_raw(dcc[idx].sock, &dcc[idx].sockname) < 0)
                       iptostr(htonl(dcc[idx].addr)) : dcc[idx].host,  
                       dcc[idx].port) < 0) {  
277      failed_link(idx);      failed_link(idx);
278    }    }
 }  
279    
280  static void cont_link(int idx, char *buf, int i)  static void cont_link(int idx, char *buf, int i)
281  {  {
# Line 1123  static int detect_telnet_flood(char *flo Line 1121  static int detect_telnet_flood(char *flo
1121    
1122  static void dcc_telnet(int idx, char *buf, int i)  static void dcc_telnet(int idx, char *buf, int i)
1123  {  {
   unsigned long ip;  
1124    unsigned short port;    unsigned short port;
1125    int j = 0, sock;    int j = 0, sock;
   char s[UHOSTLEN + 1];  
1126    
1127    if (dcc_total + 1 > max_dcc && increase_socks_max()) {    if (dcc_total + 1 > max_dcc && increase_socks_max()) {
1128      j = answer(dcc[idx].sock, s, &ip, &port, 0);      sockname_t name;
1129        j = answer(dcc[idx].sock, &name, &port, 0);
1130      if (j != -1) {      if (j != -1) {
1131        dprintf(-j, "Sorry, too many connections already.\r\n");        dprintf(-j, "Sorry, too many connections already.\r\n");
1132        killsock(j);        killsock(j);
1133      }      }
1134      return;      return;
1135    }    }
1136    sock = answer(dcc[idx].sock, s, &ip, &port, 0);    i = new_dcc(&DCC_DNSWAIT, sizeof(struct dns_info));
1137      sock = answer(dcc[idx].sock, &dcc[i].sockname, &port, 0);
1138    while ((sock == -1) && (errno == EAGAIN))    while ((sock == -1) && (errno == EAGAIN))
1139      sock = answer(sock, s, &ip, &port, 0);      sock = answer(dcc[idx].sock, &dcc[i].sockname, &port, 0);
1140    if (sock < 0) {    if (sock < 0) {
1141      neterror(s);      putlog(LOG_MISC, "*", DCC_FAILED, strerror(errno));
     putlog(LOG_MISC, "*", DCC_FAILED, s);  
1142      return;      return;
1143    }    }
1144    /* Buffer data received on this socket.  */    /* Buffer data received on this socket.  */
# Line 1152  static void dcc_telnet(int idx, char *bu Line 1149  static void dcc_telnet(int idx, char *bu
1149  #else  #else
1150    if (port < 1024 || port > 65535) {    if (port < 1024 || port > 65535) {
1151  #endif  #endif
1152      putlog(LOG_BOTS, "*", DCC_BADSRC, s, port);      putlog(LOG_BOTS, "*", DCC_BADSRC, iptostr(&dcc[i].sockname.addr.sa), port);
1153      killsock(sock);      killsock(sock);
1154        lostdcc(i);
1155      return;      return;
1156    }    }
1157    
1158    i = new_dcc(&DCC_DNSWAIT, sizeof(struct dns_info));    dcc[i].u.dns->ip = &dcc[i].sockname;
1159    dcc[i].sock = sock;    dcc[i].sock = sock;
   dcc[i].addr = ip;  
1160    dcc[i].port = port;    dcc[i].port = port;
1161    dcc[i].timeval = now;    dcc[i].timeval = now;
1162    strcpy(dcc[i].nick, "*");    strcpy(dcc[i].nick, "*");
   dcc[i].u.dns->ip = ip;  
1163    dcc[i].u.dns->dns_success = dcc_telnet_hostresolved;    dcc[i].u.dns->dns_success = dcc_telnet_hostresolved;
1164    dcc[i].u.dns->dns_failure = dcc_telnet_hostresolved;    dcc[i].u.dns->dns_failure = dcc_telnet_hostresolved;
1165    dcc[i].u.dns->dns_type = RES_HOSTBYIP;    dcc[i].u.dns->dns_type = RES_HOSTBYIP;
1166    dcc[i].u.dns->ibuf = dcc[idx].sock;    dcc[i].u.dns->ibuf = dcc[idx].sock;
1167    dcc[i].u.dns->type = &DCC_IDENTWAIT;    dcc[i].u.dns->type = &DCC_IDENTWAIT;
1168    dcc_dnshostbyip(ip);    dcc_dnshostbyip(&dcc[i].sockname);
1169  }  }
1170    
1171  static void dcc_telnet_hostresolved(int i)  static void dcc_telnet_hostresolved(int i)
1172  {  {
1173    int idx;    int idx;
1174    int j = 0, sock;    int j = 0, sock;
1175    char s[UHOSTLEN], s2[UHOSTLEN + 20];    char s[UHOSTLEN + 20];
1176    
1177    strncpyz(dcc[i].host, dcc[i].u.dns->host, UHOSTLEN);    strncpyz(dcc[i].host, dcc[i].u.dns->host, UHOSTLEN);
1178    
# Line 1201  static void dcc_telnet_hostresolved(int Line 1197  static void dcc_telnet_hostresolved(int
1197        return;        return;
1198      }      }
1199    }    }
1200    sprintf(s2, "-telnet!telnet@%s", dcc[i].host);    sprintf(s, "-telnet!telnet@%s", dcc[i].host);
1201    if (match_ignore(s2) || detect_telnet_flood(s2)) {    if (match_ignore(s) || detect_telnet_flood(s)) {
1202      killsock(dcc[i].sock);      killsock(dcc[i].sock);
1203      lostdcc(i);      lostdcc(i);
1204      return;      return;
# Line 1211  static void dcc_telnet_hostresolved(int Line 1207  static void dcc_telnet_hostresolved(int
1207    changeover_dcc(i, &DCC_IDENTWAIT, 0);    changeover_dcc(i, &DCC_IDENTWAIT, 0);
1208    dcc[i].timeval = now;    dcc[i].timeval = now;
1209    dcc[i].u.ident_sock = dcc[idx].sock;    dcc[i].u.ident_sock = dcc[idx].sock;
1210    sock = open_telnet(iptostr(htonl(dcc[i].addr)), 113);    sock = -1;
   putlog(LOG_MISC, "*", DCC_TELCONN, dcc[i].host, dcc[i].port);  
   s[0] = 0;  
   if (sock < 0) {  
     if (sock == -2)  
       strcpy(s, "DNS lookup failed for ident");  
     else  
       neterror(s);  
   } else {  
1211      j = new_dcc(&DCC_IDENT, 0);      j = new_dcc(&DCC_IDENT, 0);
1212      if (j < 0) {    if (j < 0)
1213        killsock(sock);      putlog(LOG_MISC, "*", DCC_IDENTFAIL, dcc[i].host, strerror(errno));
1214        strcpy(s, "No Free DCC's");    else {
1215        egg_memcpy(&dcc[j].sockname, &dcc[i].sockname, sizeof(sockname_t));
1216        dcc[j].sock = getsock(dcc[j].sockname.family, 0);
1217        if (dcc[j].sock >= 0) {
1218          sockname_t name;
1219          name.addrlen = sizeof(name.addr);
1220          getsockname(dcc[i].sock, &name.addr.sa, &name.addrlen);
1221          bind(dcc[j].sock, &name.addr.sa, name.addrlen);
1222          setsnport(dcc[j].sockname, 113);
1223          if (connect(dcc[j].sock, &dcc[j].sockname.addr.sa,
1224              dcc[j].sockname.addrlen) < 0 && (errno != EINPROGRESS)) {
1225            killsock(dcc[j].sock);
1226            lostdcc(j);
1227            putlog(LOG_MISC, "*", DCC_IDENTFAIL, dcc[i].host, strerror(errno));
1228            j = 0;
1229          }
1230          sock = dcc[j].sock;
1231      }      }
1232    }    }
1233    if (s[0]) {    if (j < 0) {
     putlog(LOG_MISC, "*", DCC_IDENTFAIL, dcc[i].host, s);  
1234      sprintf(s, "telnet@%s", dcc[i].host);      sprintf(s, "telnet@%s", dcc[i].host);
1235      dcc_telnet_got_ident(i, s);      dcc_telnet_got_ident(i, s);
1236      return;      return;

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

webmaster@eggheads.org
ViewVC Help
Powered by ViewVC 1.1.23