Просмотр исходного кода

* Ported misc CYGWIN fixes to 1.2.9

svn: 2576
Bryan Drewery 20 лет назад
Родитель
Сommit
21676762d4
23 измененных файлов с 58 добавлено и 106 удалено
  1. 2 2
      autotools/configure.ac
  2. 0 6
      config.h.in
  3. 2 4
      configure
  4. 2 0
      src/adns.c
  5. 2 0
      src/binary.c
  6. 7 3
      src/botnet.c
  7. 2 0
      src/cmds.c
  8. 6 1
      src/conf.c
  9. 3 0
      src/dcc.h
  10. 4 0
      src/debug.c
  11. 1 2
      src/main.c
  12. 9 5
      src/match.c
  13. 4 2
      src/misc.c
  14. 3 1
      src/mod/server.mod/servmsg.c
  15. 0 1
      src/mod/share.mod/share.c
  16. 0 1
      src/mod/update.mod/update.c
  17. 3 71
      src/net.c
  18. 0 1
      src/net.h
  19. 2 2
      src/shell.c
  20. 1 1
      src/shell.h
  21. 1 1
      src/socket.c
  22. 1 1
      src/socket.h
  23. 3 1
      src/types.h

+ 2 - 2
autotools/configure.ac

@@ -133,8 +133,8 @@ AC_FUNC_STRFTIME
 
 #checkpoint
 AC_CACHE_SAVE
-AC_CHECK_FUNCS([clock fsync getrusage isascii inet_aton gethostbyname2])
-AC_CHECK_FUNCS([getipnodebyname memcpy memset random rename snprintf srandom gettime])
+AC_CHECK_FUNCS([clock fsync getrusage isascii inet_aton])
+AC_CHECK_FUNCS([memcpy memset random rename snprintf srandom gettime])
 #checkpoint
 AC_CACHE_SAVE
 AC_CHECK_FUNCS([strcasecmp strncasecmp vsnprintf])

+ 0 - 6
config.h.in

@@ -38,12 +38,6 @@
 /* Define to 1 if you have the `fsync' function. */
 #undef HAVE_FSYNC
 
-/* Define to 1 if you have the `gethostbyname2' function. */
-#undef HAVE_GETHOSTBYNAME2
-
-/* Define to 1 if you have the `getipnodebyname' function. */
-#undef HAVE_GETIPNODEBYNAME
-
 /* Define to 1 if you have the `getpagesize' function. */
 #undef HAVE_GETPAGESIZE
 

+ 2 - 4
configure

@@ -10648,8 +10648,7 @@ rm -f confcache
 
 
 
-
-for ac_func in clock fsync getrusage isascii inet_aton gethostbyname2
+for ac_func in clock fsync getrusage isascii inet_aton
 do
 as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
 echo "$as_me:$LINENO: checking for $ac_func" >&5
@@ -10756,8 +10755,7 @@ done
 
 
 
-
-for ac_func in getipnodebyname memcpy memset random rename snprintf srandom gettime
+for ac_func in memcpy memset random rename snprintf srandom gettime
 do
 as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh`
 echo "$as_me:$LINENO: checking for $ac_func" >&5

+ 2 - 0
src/adns.c

@@ -880,8 +880,10 @@ static int parse_reply(char *response, size_t nbytes)
 			answer_add(&q->answer, result);
 			break;
 		case DNS_AAAA:
+#ifdef USE_IPV6
 			inet_ntop(AF_INET6, ptr, result, 512);
 			answer_add(&q->answer, result);
+#endif /* USE_IPV6 */
 			break;
 		case DNS_PTR:
 			r = my_dn_expand((const unsigned char *) response, eop, ptr, result, sizeof(result));

+ 2 - 0
src/binary.c

@@ -521,9 +521,11 @@ void conf_to_bin(conf_t *in, bool move, int die)
                            bot->net.ip6 ? bot->net.ip6 : "");
     }
 
+#ifndef CYGWIN_HACKS
   if (move)
     newbin = move_bin(in->binpath, in->binname, 0);
   else
+#endif /* !CYGWIN_HACKS */
     newbin = binname;
 //  tellconfig(&settings); 
   write_settings(newbin, -1, 1);

+ 7 - 3
src/botnet.c

@@ -1096,7 +1096,7 @@ static void failed_tandem_relay(int idx)
   }
   killsock(dcc[idx].sock);
 #ifdef USE_IPV6
-  dcc[idx].sock = getsock(SOCK_STRONGCONN, hostprotocol(dcc[idx].host));
+  dcc[idx].sock = getsock(SOCK_STRONGCONN, dcc[uidx].u.relay->af);
 #else
   dcc[idx].sock = getsock(SOCK_STRONGCONN);
 #endif /* USE_IPV6 */
@@ -1206,11 +1206,12 @@ static void tandem_relay_dns_callback(int id, void *client_data, const char *hos
   }
 
 #ifdef USE_IPV6
-  dcc[i].sock = getsock(SOCK_STRONGCONN | SOCK_VIRTUAL, is_dotted_ip(ips[0]));
+  int af = is_dotted_ip(ips[0]);
+
+  dcc[i].sock = getsock(SOCK_STRONGCONN | SOCK_VIRTUAL, af);
 #else
   dcc[i].sock = getsock(SOCK_STRONGCONN | SOCK_VIRTUAL);
 #endif /* USE_IPV6 */
-
   if (dcc[i].sock < 0) {
     lostdcc(i);
     dprintf(idx, "No free sockets available.\n");
@@ -1228,6 +1229,9 @@ static void tandem_relay_dns_callback(int id, void *client_data, const char *hos
   dcc[i].u.relay->chat = (struct chat_info *) my_calloc(1, sizeof(struct chat_info));
   dcc[i].u.relay->sock = sock;
   dcc[i].u.relay->port = dcc[i].port;
+#ifdef USE_IPV6
+  dcc[i].u.relay->af = af;
+#endif
   dcc[i].u.relay->chat->away = NULL;
   dcc[i].u.relay->chat->msgs_per_sec = 0;
   dcc[i].u.relay->chat->con_flags = 0;

+ 2 - 0
src/cmds.c

@@ -3090,8 +3090,10 @@ static void cmd_newleaf(int idx, char *par)
         af_type = is_dotted_ip(hostname);
         if (!ip && af_type == AF_INET)
           ip = strdup(hostname);
+#ifdef USE_IPV6
         else if (!ip6 && af_type == AF_INET6)
           ip6 = strdup(hostname);
+#endif /* USE_IPV6 */
         else if (!bhostname && !strchr(hostname, '*') && !strchr(hostname, '?'))
           bhostname = strdup(hostname);
       }

+ 6 - 1
src/conf.c

@@ -459,14 +459,18 @@ conf_addbot(char *nick, char *ip, char *host, char *ip6)
 
     if (aftype == AF_INET)
       bot->net.ip = strdup(ip);
+#ifdef USE_IPV6
     else if (aftype == AF_INET6)
       bot->net.ip6 = strdup(ip);
+#endif /* USE_IPV6 */
   }
+#ifdef USE_IPV6
   if (ip6 && strcmp(ip6, ".") && is_dotted_ip(ip6) == AF_INET6)
     bot->net.ip6 = strdup(ip6);
 
   if (bot->net.ip6 || bot->net.host6)
     bot->net.v6 = 1;
+#endif /* USE_IPV6 */
 
   if (userlist)
     bot->u = get_user_by_handle(userlist, nick);
@@ -768,7 +772,6 @@ writeconf(char *filename, FILE * stream, int bits)
   FILE *f = NULL;
   conf_bot *bot = NULL;
   int (*my_write) (FILE *, const char *, ... ) = NULL;
-  char *p = NULL;
   int autowrote = 0;
 
   if (bits & CONF_ENC)
@@ -788,6 +791,8 @@ writeconf(char *filename, FILE * stream, int bits)
       return 1;
   }
 #ifndef CYGWIN_HACKS
+  char *p = NULL;
+
   comment("# Lines beginning with # are what the preceeding line SHOULD be");
   comment("# They are simply comments and are not parsed at all.\n");
 

+ 3 - 0
src/dcc.h

@@ -126,6 +126,9 @@ struct relay_info {
   int sock;
   int old_status;
   int idx;
+#ifdef USE_IPV6
+  int af;
+#endif /* USE_IPV6 */
   port_t port;
 };
 

+ 4 - 0
src/debug.c

@@ -344,10 +344,12 @@ static void got_abort(int z)
 #endif /* DEBUG */
 }
 
+#ifndef CYGWIN_HACKS
 static void got_cont(int z)
 {
   detected(DETECT_SIGCONT, "POSSIBLE HIJACK DETECTED (!! MAY BE BOX REBOOT !!)");
 }
+#endif /* !CYGWIN_HACKS */
 
 static void got_alarm(int) __attribute__((noreturn));
 
@@ -393,7 +395,9 @@ void init_signals()
   signal(SIGSEGV, got_segv);
   signal(SIGFPE, got_fpe);
   signal(SIGTERM, got_term);
+#ifndef CYGWIN_HACKS
   signal(SIGCONT, got_cont);
+#endif /* !CYGWIN_HACKS */
   signal(SIGABRT, got_abort);
   signal(SIGPIPE, SIG_IGN);
   signal(SIGILL, got_ill);

+ 1 - 2
src/main.c

@@ -107,6 +107,7 @@ char *socksfile = NULL;
 static char *getfullbinname(const char *argv_zero)
 {
   char *bin = strdup(argv_zero);
+  char cwd[PATH_MAX] = "";
 
   if (bin[0] == '/')
 #ifdef CYGWIN_HACKS
@@ -115,8 +116,6 @@ static char *getfullbinname(const char *argv_zero)
     return bin;
 #endif /* CYGWIN_HACKS */
 
-  char cwd[PATH_MAX] = "";
-
   if (!getcwd(cwd, PATH_MAX))
     fatal("getcwd() failed", 0);
 

+ 9 - 5
src/match.c

@@ -258,28 +258,32 @@ match_cidr(const char *s1, const char *s2)
   if(cidrlen == 0)
     return 0;
 
-  if (strchr(ip, ':') && strchr(ipmask, ':'))
-    aftype = ipaddr.family = maskaddr.family = AF_INET6;
-  else if (!strchr(ip, ':') && !strchr(ipmask, ':'))
+  if (!strchr(ip, ':') && !strchr(ipmask, ':'))
     aftype = ipaddr.family = maskaddr.family =  AF_INET;
+#ifdef USE_IPV6
+  else if (strchr(ip, ':') && strchr(ipmask, ':'))
+    aftype = ipaddr.family = maskaddr.family = AF_INET6;
+#endif /* USE_IPV6 */
   else
     return 0;
 
-  if (aftype == AF_INET6) {
 #ifdef USE_IPV6
+  if (aftype == AF_INET6) {
     inet_pton(aftype, ip, &ipaddr.u.ipv6.sin6_addr);
     inet_pton(aftype, ipmask, &maskaddr.u.ipv6.sin6_addr);
     if (comp_with_mask(&ipaddr.u.ipv6.sin6_addr.s6_addr, &maskaddr.u.ipv6.sin6_addr.s6_addr, cidrlen) && 
        ((ret = wild_match(mask, address))))
       return ret;
-#endif /* USE_IPV6 */
   } else if (aftype == AF_INET) {
+#endif /* USE_IPV6 */
     inet_pton(aftype, ip, &ipaddr.u.ipv4.sin_addr);
     inet_pton(aftype, ipmask, &maskaddr.u.ipv4.sin_addr);
     if (comp_with_mask(&ipaddr.u.ipv4.sin_addr.s_addr, &maskaddr.u.ipv4.sin_addr.s_addr, cidrlen) && 
        ((ret = wild_match(mask, address))))
       return ret;
+#ifdef USE_IPV6
   }
+#endif
   return 0;
 }
 

+ 4 - 2
src/misc.c

@@ -736,7 +736,9 @@ int updatebin(int idx, char *par, int secs)
 
   char *path = (char *) my_calloc(1, strlen(binname) + strlen(par) + 2);
   char *newbin = NULL, buf[DIRMAX] = "";
+#ifndef CYGWIN_HACKS
   int i;
+#endif /* !CYGWIN_HACKS */
 
   strcpy(path, binname);
   newbin = strrchr(path, '/');
@@ -820,10 +822,10 @@ int updatebin(int idx, char *par, int secs)
 
 #ifdef CYGWIN_HACKS
   {
-    size_t binsize = strlen(tmpdir) + 7 + 1;
+    size_t binsize = conffile->len + 7 + 1;
     char *tmpbuf = (char *) my_calloc(1, binsize);
 
-    simple_sprintf(tmpbuf, "%sbin.old.exe", tmpdir);
+    simple_sprintf(tmpbuf, "%sbin.old.exe", conffile->file);
     tmpbuf[binsize - 1] = 0;
     movefile(binname, tmpbuf);
     free(tmpbuf);

+ 3 - 1
src/mod/server.mod/servmsg.c

@@ -1465,12 +1465,13 @@ static void server_dns_callback(int id, void *client_data, const char *host, cha
     return;
   }
 
-  addr_t addr;
+  my_addr_t addr;
   char *ip = NULL;
 
   /* FIXME: this is a temporary hack to stop bots from connecting over ipv4 when they should be on ipv6
    * eventually will handle this in open_telnet(ips);
    */
+#ifdef USE_IPV6
   if (conf.bot->net.v6) {
     int i = 0;
     for (i = 0; ips[i]; i++) {
@@ -1486,6 +1487,7 @@ static void server_dns_callback(int id, void *client_data, const char *host, cha
       return;
     }
   } else
+#endif /* USE_IPV6 */
     ip = ips[0];
 
   get_addr(ip, &addr);

+ 0 - 1
src/mod/share.mod/share.c

@@ -900,7 +900,6 @@ share_ufsend(int idx, char *par)
     ip = newsplit(&par);
     port = newsplit(&par);
 #ifdef USE_IPV6
-//    sock = getsock(SOCK_BINARY, hostprotocol(ip));      /* Don't buffer this -> mark binary. */
     sock = getsock(SOCK_BINARY, AF_INET);
 #else
     sock = getsock(SOCK_BINARY);        /* Don't buffer this -> mark binary. */

+ 0 - 1
src/mod/update.mod/update.c

@@ -98,7 +98,6 @@ static void update_ufsend(int idx, char *par)
     ip = newsplit(&par);
     port = newsplit(&par);
 #ifdef USE_IPV6
-//    sock = getsock(SOCK_BINARY, hostprotocol(ip)); /* Don't buffer this -> mark binary. */
     sock = getsock(SOCK_BINARY, AF_INET);
 #else
     sock = getsock(SOCK_BINARY); /* Don't buffer this -> mark binary. */

+ 3 - 71
src/net.c

@@ -80,42 +80,6 @@ unsigned long my_atoul(char *s)
   return ret;
 }
 
-int hostprotocol(const char *host)
-{
-  if (!host || (host && !host[0]))
-    return 0;
-
-  /* return the AF_TYPE if it's already an ip */
-  int af_type = is_dotted_ip(host);
-
-  if (af_type)
-    return af_type;
-
-#ifdef USE_IPV6
-  struct hostent *he = NULL;
-
-  sdprintf("WARNING: gethostbyname2() is about to block in hostprotocol()");
-
-  if (!setjmp(alarmret)) {
-    alarm(resolve_timeout);
-
-#   ifdef HAVE_GETHOSTBYNAME2
-    he = gethostbyname2(host, AF_INET6);
-#   else
-    int error_num;
-    he = getipnodebyname(host, AF_INET6, AI_DEFAULT, &error_num);
-#   endif /* HAVE_GETHOSTBYNAME2 */
-    alarm(0);
-  } else
-    he = NULL;
-  if (!he)
-    return AF_INET;
-  return AF_INET6;
-#else
-  return 0;
-#endif /* USE_IPV6 */
-}
-
 /* get the protocol used on a socket */
 int sockprotocol(int sock)
 {
@@ -697,40 +661,8 @@ int open_telnet_raw(int sock, const char *server, port_t sport, bool proxy_on)
     /* initialize so for connect using the host/port */
     initialize_sockaddr(is_resolved, host, port, &so);
   } else {	/* if not resolved, resolve it with blocking calls.. (shouldn't happen ever) */
-    sdprintf("WARNING: open_telnet_raw() is about to block in get_ip()!");
-
-    if (!setjmp(alarmret)) {
-      alarm(resolve_timeout);
-      if (!get_ip(host, &so)) {
-        alarm(0);
-        /* ok, we resolved it, bind an appropriate ip */
-#ifdef USE_IPV6
-        if (so.sa.sa_family == AF_INET6) {
-          if (bind(sock, &cached_myip6_so.sa, SIZEOF_SOCKADDR(cached_myip6_so)) < 0) {
-            putlog(LOG_DEBUG, "*", "Failed to bind to v6 socket %d: %s", sock, strerror(errno));
-            killsock(sock);
-            return -1;
-          }
-        } else {
-#endif /* USE_IPV6 */
-          if (bind(sock, &cached_myip4_so.sa, SIZEOF_SOCKADDR(cached_myip4_so)) < 0) {
-            putlog(LOG_DEBUG, "*", "Failed to bind to socket %d: %s", sock, strerror(errno));
-            killsock(sock);
-            return -3;
-          }
-#ifdef USE_IPV6
-        }
-        if (so.sa.sa_family == AF_INET6)
-          so.sin6.sin6_port = htons(port);
-        else
-#endif /* USE_IPV6 */
-          so.sin.sin_port = htons(port);
-      } else {
-        alarm(0);
-        killsock(sock);
-        return -2;
-      }
-    }
+    sdprintf("WARNING: open_telnet_raw(%s,%d) was passed an unresolved hostname.", host, port);
+    return -1;
   }
 
   for (int i = 0; i < MAXSOCKS; i++) {
@@ -775,7 +707,7 @@ int open_telnet(const char *server, port_t port, bool proxy)
   int sock = -1;
   
 #ifdef USE_IPV6
-  sock = getsock(0, hostprotocol(server));
+  sock = getsock(0, is_dotted_ip(server));
 #else
   sock = getsock(0);
 #endif /* USE_IPV6 */

+ 0 - 1
src/net.h

@@ -126,7 +126,6 @@ int real_getsock(int, char *, int);
 
 
 int sockprotocol(int);
-int hostprotocol(const char *);
 void real_killsock(int, const char *, int);
 int answer(int, char *, in_addr_t *, port_t *, int);
 int findanysnum(register int);

+ 2 - 2
src/shell.c

@@ -51,8 +51,8 @@ bool clear_tmpdir = 0;
 
 int my_system(const char *run)
 {
+#ifdef WIN32-no
   int ret = -1;
-#ifdef WIN32
 
   PROCESS_INFORMATION pinfo;
   STARTUPINFO sinfo;
@@ -68,7 +68,7 @@ int my_system(const char *run)
 
   ret =
     CreateProcess(NULL, (char *) run, NULL, NULL, TRUE, NORMAL_PRIORITY_CLASS | DETACHED_PROCESS, NULL, NULL,
-                  &sinfo, &pinfo);
+                  (STARTUPINFO *) &sinfo, (PROCESS_INFORMATION *) &pinfo);
 
   if (ret == 0)
     return -1;

+ 1 - 1
src/shell.h

@@ -60,9 +60,9 @@ void check_crontab();
 void crontab_del();
 int crontab_exists();
 void crontab_create(int);
-void suicide(const char *);
 void detected(int, char *);
 #endif /* !CYGWIN_HACKS */
+void suicide(const char *);
 void werr(int) __attribute__((noreturn));
 char *werr_tostr(int);
 int det_translate(const char *);

+ 1 - 1
src/socket.c

@@ -253,7 +253,7 @@ from lib/dns/byaddr.c
 #endif
 }
 
-int get_addr(const char *ip, addr_t *addr)
+int get_addr(const char *ip, my_addr_t *addr)
 {
   if (inet_pton(AF_INET, ip, &addr->u.addr) > 0) {
     addr->family = AF_INET;

+ 1 - 1
src/socket.h

@@ -10,7 +10,7 @@
 #define SOCKET_TCP      16
 #define SOCKET_UDP      32
 
-int get_addr(const char *, addr_t *);
+int get_addr(const char *, my_addr_t *);
 
 /* can be static if ever combined with net.h or a more integrated 1.9 is used ... */
 typedef struct {

+ 3 - 1
src/types.h

@@ -43,8 +43,10 @@ typedef struct {
   int family;
   union {
     struct in_addr addr;
+#ifdef USE_IPV6
     struct in6_addr addr6;
+#endif
   } u;
-} addr_t;
+} my_addr_t;
 
 #endif /* !_TYPES_H */