Explorar o código

Fixed main.c to allow no ip/host/ipsix
Fixed ident for use with ipv6
Made some changes that should hopefully fix the BSD ipv6 problems..


svn: 118

Bryan Drewery %!s(int64=23) %!d(string=hai) anos
pai
achega
328e33b561
Modificáronse 9 ficheiros con 64 adicións e 62 borrados
  1. 12 3
      src/botnet.c
  2. 1 8
      src/chanprog.c
  3. 18 9
      src/dcc.c
  4. 4 0
      src/eggdrop.h
  5. 1 0
      src/lang.h
  6. 22 40
      src/main.c
  7. 1 1
      src/mod/module.h
  8. 5 0
      src/net.c
  9. 0 1
      src/users.c

+ 12 - 3
src/botnet.c

@@ -1011,7 +1011,11 @@ int botlink(char *linker, int idx, char *nick)
       dcc[i].u.dns->dns_failure = botlink_resolve_failure;
       dcc[i].u.dns->dns_type = RES_IPBYHOST;
       dcc[i].u.dns->type = &DCC_FORK_BOT;
+#ifdef USE_IPV6
+      botlink_resolve_success(i);
+#else
       dcc_dnsipbyhost(bi->address);
+#endif /* USE_IPV6 */
       return 1;
     }
   }
@@ -1020,13 +1024,13 @@ int botlink(char *linker, int idx, char *nick)
 
 static void botlink_resolve_failure(int i)
 {
-  char s[81];
+//  char s[81];
 
 //  putlog(LOG_BOTS, "*", DCC_LINKFAIL, dcc[i].nick);
-  strcpy(s, dcc[i].nick);
+//  strcpy(s, dcc[i].nick);
   nfree(dcc[i].u.dns->cptr);
   lostdcc(i);
-  autolink_cycle(s);          /* Check for more auto-connections */
+//  autolink_cycle(s);          /* Check for more auto-connections */
 }
 
 static void botlink_resolve_success(int i)
@@ -1048,8 +1052,13 @@ static void botlink_resolve_success(int i)
   dcc[i].sock = getsock(SOCK_STRONGCONN);
 #endif /* USE_IPV6 */
   nfree(linker);
+
   if (dcc[i].sock < 0 ||
+#ifdef USE_IPV6
+      open_telnet_raw(dcc[i].sock, dcc[i].host,
+#else
       open_telnet_raw(dcc[i].sock, iptostr(htonl(dcc[i].addr)),
+#endif /* USE_IPV6 */
 		      dcc[i].port) < 0)
     failed_link(i);
 }

+ 1 - 8
src/chanprog.c

@@ -25,7 +25,7 @@ extern struct userrec	*userlist;
 extern log_t		*logs;
 extern Tcl_Interp	*interp;
 extern char		 ver[], botnetnick[], firewall[], myip[], origbotname[],
-			 motdfile[], userfile[], helpdir[], tempdir[],
+			 motdfile[], userfile[], tempdir[],
 			 notify_new[], owner[], configfile[],
                          netpass[], botuser[], owners[], hubs[];
 
@@ -362,7 +362,6 @@ void tell_settings(int idx)
   dprintf(idx, "Userfile: %s   \n", userfile);
 #endif
   dprintf(idx, "Directories:\n");
-  dprintf(idx, "  Help    : %s\n", helpdir);
   dprintf(idx, "  Temp    : %s\n", tempdir);
   fr.global = default_flags;
 
@@ -568,7 +567,6 @@ void chanprog()
 
 
   admin[0] = 0;
-  helpdir[0] = 0;
 
   /* cache our ip on load instead of every 30 seconds -zip */
   cache_my_ip();
@@ -657,11 +655,6 @@ void chanprog()
 
   /* We should be safe now */
 
-
-  if (helpdir[0])
-    if (helpdir[strlen(helpdir) - 1] != '/')
-      strcat(helpdir, "/");
-
   if (tempdir[0])
     if (tempdir[strlen(tempdir) - 1] != '/')
       strcat(tempdir, "/");

+ 18 - 9
src/dcc.c

@@ -35,7 +35,7 @@ extern time_t		 now;
 extern int		 egg_numver, connect_timeout, conmask, backgrd,
 			 max_dcc, default_flags, debug_output,
 			 ignore_time;
-extern char		 botnetnick[], ver[], origbotname[], notify_new[];
+extern char		 botnetnick[], ver[], origbotname[], notify_new[], thepass[];
 
 
 extern sock_list *socklist;
@@ -50,7 +50,7 @@ int	use_telnet_banner = 0;	/* Display telnet banner?		   */
 char	network[41] = "EFnet"; /* Name of the IRC network you're on  */
 int	password_timeout = 20;	/* Time to wait for a password from a user */
 int     auth_timeout = 40;
-int	bot_timeout = 25;	/* Bot timeout value			   */
+int	bot_timeout = 15;	/* Bot timeout value			   */
 int	identtimeout = 15;	/* Timeout value for ident lookups	   */
 int	dupwait_timeout = 5;	/* Timeout for rejecting duplicate entries */
 #ifdef LEAF
@@ -375,9 +375,11 @@ static void cont_link(int idx, char *buf, int ii)
     dcc[idx].u.bot->numver = 0;
     dprintf(idx, "%s\n", botnetnick);
     i = sizeof(sa);
-    /* myip myport hubnick mynick */
+
+    /* initkey-gen */
+    /* thepass myport hubnick mynick */
     getsockname(socklist[snum].sock, (struct sockaddr *) &sa, &i);
-    sprintf(tmp,"%8x@%4x@%s@%s", getmyip(), sa.sin_port, dcc[idx].nick, botnetnick);
+    sprintf(tmp,"%s@%4x@%s@%s", thepass, sa.sin_port, dcc[idx].nick, botnetnick);
     MD5_Init(&ctx);
     MD5_Update(&ctx, tmp, strlen(tmp));
     MD5_Final(socklist[snum].ikey, &ctx);
@@ -394,7 +396,7 @@ static void dcc_bot_new(int idx, char *buf, int x)
 /*  struct userrec *u = get_user_by_handle(userlist, dcc[idx].nick); */
   char *code;
   int i;
-
+  
   strip_telnet(dcc[idx].sock, buf, &x);
   code = newsplit(&buf);
   if (!egg_strcasecmp(code, "goodbye!")) {
@@ -411,7 +413,7 @@ static void dcc_bot_new(int idx, char *buf, int x)
        break;
       }
     }
-    putlog(LOG_DEBUG, "*", "snum: %d", snum);
+
     if (snum >= 0) {
       char *tmp,
        *p;
@@ -1324,7 +1326,12 @@ static void dcc_telnet_hostresolved(int i)
   changeover_dcc(i, &DCC_IDENTWAIT, 0);
   dcc[i].timeval = now;
   dcc[i].u.ident_sock = dcc[idx].sock;
-  sock = open_telnet(iptostr(htonl(dcc[i].addr)), 113);
+#ifdef USE_IPV6
+  if (sockprotocol(dcc[idx].sock) == AF_INET6)
+    sock = open_telnet(dcc[i].host, 113);
+  else
+#endif /* USE_IPV6 */
+    sock = open_telnet(iptostr(htonl(dcc[i].addr)), 113);
   putlog(LOG_MISC, "*", DCC_TELCONN, dcc[i].host, dcc[i].port);
   s[0] = 0;
   if (sock < 0) {
@@ -1614,8 +1621,10 @@ static void dcc_telnet_pass(int idx, int atr)
        *tmp2;
       char tmp[256];
       MD5_CTX ctx;
-
-      sprintf(tmp, "%8x@%4x@%s@%s", htonl(dcc[idx].addr), htons(dcc[idx].port), botnetnick, dcc[idx].nick);
+      
+      /* initkey-gen */
+      /* thepass port mynick botnetnick */
+      sprintf(tmp, "%s@%4x@%s@%s", thepass, htons(dcc[idx].port), botnetnick, dcc[idx].nick);
       MD5_Init(&ctx);
       MD5_Update(&ctx, tmp, strlen(tmp));
       MD5_Final(socklist[snum].okey, &ctx);

+ 4 - 0
src/eggdrop.h

@@ -435,6 +435,10 @@ struct script_info {
 #endif /* !defined(IN6_IS_ADDR_V4MAPPED) */
 
 #include <netinet/in.h>
+#include <netinet/socket.h>
+#ifdef __FreeBSD__
+# include <netinet6/in6.h>
+#endif
 union sockaddr_union {
   struct sockaddr sa;
   struct sockaddr_in sin;

+ 1 - 0
src/lang.h

@@ -388,6 +388,7 @@
 
 #define DCC_NOSTRANGERS		STR("I don't accept DCC chats from strangers.")
 #define DCC_REFUSED		STR("Refused DCC chat (no access)")
+#define DCC_REFUSEDNC		STR("Refused DCC chat (I'm not a chathub (+c))")
 #define DCC_REFUSED2		STR("No access")
 #define DCC_REFUSED3		STR("You must have a password set.")
 #define DCC_REFUSED4		STR("Refused DCC chat (no password)")

+ 22 - 40
src/main.c

@@ -106,7 +106,6 @@ char tempdir[DIRMAX] = "";
 char lock_file[40] = "";
 char *binname;
 char	configfile[121] = ""; /* Name of the config file */
-char	helpdir[121];		/* Directory of help files (if used) */
 char	textdir[121] = "";	/* Directory for text files that get dumped */
 int	keep_all_logs = 0;	/* Never erase logfiles, no matter how old
 				   they are? */
@@ -1007,38 +1006,38 @@ static void check_crontab()
 static void gotspawn(char *filename)
 {
   FILE *fp;
-  char templine[8192], *nick, *host, *ip, *temps, *ipsix;
+  char templine[8192], *nick = NULL, *host = NULL, *ip = NULL, *ipsix = NULL, *temps;
 
   if (!(fp = fopen(filename, "r")))
     fatal("Cannot read from local config (2)", 0);
 
-  //link_statics();
   check_static("blowfish", blowfish_start);
-  Context;
   module_load(ENCMOD);
 
-
   while(fscanf(fp,"%[^\n]\n",templine) != EOF) 
   {
     Context;
     temps = (char *) decrypt_string(netpass, decryptit(templine));
 
-    pscloak = atoi(newsplit(&temps));
 #ifdef S_PSCLOAK
     if (SDEBUG)
-      printf("GOTSPAWN, NOT CLOAKING\n");
+      printf("GOTSPAWN: %s\n", temps);
 #endif /* S_PSCLOAK */
-    nick = newsplit(&temps);
+
+    pscloak = atoi(newsplit(&temps));
+    if (temps[0])
+      nick = newsplit(&temps);
     if (!nick)
       fatal("invalid config (2).",0);
+    if (temps[0])
+      ip = newsplit(&temps);
+    if (temps[0])
+      host = newsplit(&temps);
+    if (temps[0])
+      ipsix = newsplit(&temps);
 
-    ip = newsplit(&temps);
-    if (!ip)
-      fatal("invalid config (2).",0);
+    snprintf(origbotname, 10, "%s", nick);
 
-    host = newsplit(&temps);
-    if (!host && (ip[0] != '!'))
-      fatal("invalid config (2).",0);
     if (ip[1]) {
       if (ip[0] == '!') { //natip
         ip++;
@@ -1048,8 +1047,6 @@ static void gotspawn(char *filename)
       }
     }
 
-    snprintf(origbotname, 10, "%s", nick);
-
     if (host && host[1]) {
       if (host[0] == '+') { //ip6 host
         host++;
@@ -1058,12 +1055,12 @@ static void gotspawn(char *filename)
         sprintf(hostname,"%s",host);
       }
     }
-    ipsix = newsplit(&temps);
 
     if (ipsix && ipsix[1]) {
       snprintf(myip6, 120, "%s", ipsix);
     }
   }
+
   fclose(fp);
   unlink(filename);
 }
@@ -1082,7 +1079,7 @@ static int spawnbot(char *bin, char *nick, char *ip, char *host, char *ipsix, in
   if (!(fp = fopen(buf, "w")))
     fatal("Cannot create spawnfiles...", 0);
 
-  lfprintf(fp, "%d %s %s %s %s\n", cloak, nick, ip, host ? host : ".", ipsix ? ipsix : ".");
+  lfprintf(fp, "%d %s %s %s %s\n", cloak, nick, ip ? ip : ".", host ? host : ".", ipsix ? ipsix : ".");
 
   fflush(fp);
   fclose(fp);
@@ -1482,7 +1479,7 @@ Context;
     if (!(f = fopen(cfile, "r")))
       fatal(STR("the local config is missing."),0);
     while(fscanf(f,"%[^\n]\n",templine) != EOF) {
-      char *nick=NULL,*host=NULL,*ip=NULL,*ipsix=NULL;
+      char *nick = NULL, *host = NULL, *ip = NULL, *ipsix = NULL;
       int skip = 0;
       Context;
       if (templine[0] != '+') {
@@ -1532,57 +1529,42 @@ Context;
         //we have the right uname/uid, safe to setup crontab now.
         i++;
         nick = newsplit(&temps);
-        if (!nick)
+        if (!nick || !nick[0])
           fatal("invalid config.",0);
         if (SDEBUG)
           printf("Read nick from config: %s\n", nick);
-
         if (temps[0])
           ip = newsplit(&temps);
-        if (!ip)
-          fatal("invalid config..",0);
         if (temps[0])
           host = newsplit(&temps);
-//        if (!host && (ip[0] != '!'))
-//          fatal("invalid config...",0);
-        if (host && !host[1] && (ip && ip[0] != '!'))
-          host[0] = '.';
-
         if (temps[0])
           ipsix = newsplit(&temps);
 
-        if (ipsix && !ipsix[1])
-          ipsix[0] = '.';
-
         if (i == 1) { //this is the first bot ran/parsed
           strncpyz(s, ctime(&now), sizeof s);
           strcpy(&s[11], &s[20]);
           printf("--- Loading %s (%s)\n\n", ver, s);
-#ifdef LEAF
+
           if (ip[0] == '!') { //natip
             ip++;
             sprintf(natip, "%s",ip);
           } else {
-#endif
-            snprintf(myip, 120, "%s", ip);
-#ifdef LEAF
+            if (ip && ip[1]) //only copy ip if it is longer than 1 char (.)
+              snprintf(myip, 120, "%s", ip);
           }
-#endif
           snprintf(origbotname, 10, "%s", nick);
 #ifdef HUB
           sprintf(userfile, "%s/.%s.user", confdir, nick);
 #endif
 
-          if (host && host[1]) {
-#ifdef LEAF
+          if (host && host[1]) { //only copy host if it is longer than 1 char (.)
             if (host[0] == '+') { //ip6 host
               host++;
               sprintf(hostname6, "%s",host);
             } else  //normal ip4 host
-#endif
               sprintf(hostname, "%s",host);
           }
-          if (ipsix && ipsix[1]) {
+          if (ipsix && ipsix[1]) { //only copy ipsix if it is longer than 1 char (.)
             snprintf(myip6, 120, "%s",ipsix);
           }
         } 

+ 1 - 1
src/mod/module.h

@@ -252,7 +252,7 @@
 #define ver ((char *)global[119])
 /* 120 - 123 */
 #define notify_new ((char *)global[120])
-//#define helpdir ((char *)global[121])
+/* 121 helpdir -- UNUSED */
 #define Version ((char *)global[122])
 #define botnetnick ((char *)global[123])
 /* 124 - 127 */

+ 5 - 0
src/net.c

@@ -17,6 +17,9 @@
 #  include <sys/select.h>
 #endif
 #include <netinet/in.h>
+#ifdef ___FreeBSD___
+# include <netinet6/in6.h>
+#endif
 #include <arpa/inet.h>		/* is this really necessary? */
 #include <errno.h>
 
@@ -650,6 +653,7 @@ int open_address_listen(IP addr, int *port)
   }
 #ifdef USE_IPV6
   if (af_def == AF_INET6) {
+debug0("Opening listen socket with AF_INET6");
       sock = getsock(SOCK_LISTEN, af_def);
       bzero((char *) &name6, sizeof(name6));
       name6.sin6_family = af_def;
@@ -677,6 +681,7 @@ int open_address_listen(IP addr, int *port)
     if (sock < 1)
       return -1;
 
+debug0("Opening listen socket with AF_INET");
     egg_bzero((char *) &name, sizeof(struct sockaddr_in));
     name.sin_family = AF_INET;
     name.sin_port = htons(*port); /* 0 = just assign us a port */

+ 0 - 1
src/users.c

@@ -1274,7 +1274,6 @@ Context;
   while (ul) {
     get_user_flagrec(ul, &fr, NULL);
 
-//printf("connect to? %s %s %d\n", ul->handle, u->handle, bot_hublevel(ul));
     if (glob_bot(fr) && 
         strcmp(ul->handle, botnetnick) && 
         strcmp(u->handle, avoidbot) &&