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

* Fixed the pesky cosmetic bug with /dcc CHAT /ctcp CHAT
* Spruced up the realpath()/getpwuid() calls


svn: 740

Bryan Drewery 22 лет назад
Родитель
Сommit
f66920c2e8
7 измененных файлов с 71 добавлено и 50 удалено
  1. 3 0
      src/chanprog.c
  2. 2 0
      src/main.c
  3. 17 17
      src/mod/ctcp.mod/ctcp.c
  4. 9 9
      src/mod/server.mod/server.c
  5. 14 3
      src/mod/server.mod/servmsg.c
  6. 13 15
      src/mod/transfer.mod/transfer.c
  7. 13 6
      src/shell.c

+ 3 - 0
src/chanprog.c

@@ -694,6 +694,9 @@ int shouldjoin(struct chanset_t *chan)
     return 0; 
 #ifdef G_BACKUP
   struct flag_record fr = { FR_CHAN | FR_ANYWH | FR_GLOBAL, 0, 0, 0, 0 };
+ 
+  if (!chan || (chan && !chan->name || (chan->name && !chan->name[0])))
+    return 0;
 
   get_user_flagrec(get_user_by_handle(userlist, conf.bot->nick), &fr, chan->name);
   return (!channel_inactive(chan)

+ 2 - 0
src/main.c

@@ -603,7 +603,9 @@ static void startup_checks() {
                  conffile.binname);
     sdprintf(STR("newbin at: %s"), newbin);
     
+    ContextNote("realpath()");
     realpath(binname, real);		/* get the realpath of binname */
+    ContextNote("realpath(): Success");
     /* running from wrong dir, or wrong bin name.. lets try to fix that :) */
     if (strcmp(binname, newbin) && strcmp(newbin, real)) { 		/* if wrong path and new path != current */
       int ok = 1;

+ 17 - 17
src/mod/ctcp.mod/ctcp.c

@@ -440,14 +440,14 @@ static int ctcp_FINGER(char *nick, char *uhost, struct userrec *u, char *object,
   else
     idletime = 0;
   if (!(pwd = getpwuid(conf.uid)))
-    return 0;
+    return BIND_RET_LOG;
 #ifndef GECOS_DELIMITER
 #define GECOS_DELIMITER ','
 #endif
   if ((p = strchr(pwd->pw_gecos, GECOS_DELIMITER)) != NULL)
     *p = 0;
   dprintf(DP_HELP, STR("NOTICE %s :\001%s %s (%s@%s) Idle %ld second%s\001\n"), nick, keyword, pwd->pw_gecos, pwd->pw_name, (char *) (strchr(botuserhost, '@') + 1), idletime, (idletime == 1) ? "" : "s");
-  return 1;
+  return BIND_RET_BREAK;
 }
 
 static int ctcp_ECHO(char *nick, char *uhost, struct userrec *u, char *object, char *keyword, char *text)
@@ -456,14 +456,14 @@ static int ctcp_ECHO(char *nick, char *uhost, struct userrec *u, char *object, c
 
   strncpyz(reply, text, sizeof(reply));
   dprintf(DP_HELP, STR("NOTICE %s :\001%s %s\001\n"), nick, keyword, reply);
-  return 1;
+  return BIND_RET_BREAK;
 }
 static int ctcp_PING(char *nick, char *uhost, struct userrec *u, char *object, char *keyword, char *text)
 {
 
   if (strlen(text) <= 80)       /* bitchx ignores > 80 */
     dprintf(DP_HELP, STR("NOTICE %s :\001%s %s\001\n"), nick, keyword, text);
-  return 1;
+  return BIND_RET_BREAK;
 }
 
 static int ctcp_VERSION(char *nick, char *uhost, struct userrec *u, char *object, char *keyword, char *text)
@@ -501,14 +501,14 @@ static int ctcp_VERSION(char *nick, char *uhost, struct userrec *u, char *object
   dprintf(DP_HELP, STR("NOTICE %s :\001%s %s%s\001\n"), nick, keyword, ctcpversion, s);
 /* if mirc send second reply here.. */
 
-  return 1;
+  return BIND_RET_BREAK;
 }
 
 static int ctcp_WHOAMI(char *nick, char *uhost, struct userrec *u, char *object, char *keyword, char *text)
 {
 
   dprintf(DP_HELP, STR("NOTICE %s :\002BitchX\002: Access Denied\n"), nick);
-  return 1;
+  return BIND_RET_BREAK;
 }
 
 static int ctcp_OP(char *nick, char *uhost, struct userrec *u, char *object, char *keyword, char *text)
@@ -522,7 +522,7 @@ static int ctcp_OP(char *nick, char *uhost, struct userrec *u, char *object, cha
       *p = 0;
     dprintf(DP_HELP, STR("NOTICE %s :\002BitchX\002: I'm not on %s or I'm not opped\n"), nick, chan);
   }
-  return 1;
+  return BIND_RET_BREAK;
 }
 
 static int ctcp_INVITE_UNBAN(char *nick, char *uhost, struct userrec *u, char *object, char *keyword, char *text)
@@ -539,14 +539,14 @@ static int ctcp_INVITE_UNBAN(char *nick, char *uhost, struct userrec *u, char *o
       if (chan->status & CHAN_ACTIVE) {
         if (!egg_strcasecmp(chan->name, chname)) {
           dprintf(DP_HELP, STR("NOTICE %s :\002BitchX\002: Access Denied\n"), nick);
-          return 0;
+          return BIND_RET_LOG;
         }
       }
       chan = chan->next;
     }
     dprintf(DP_HELP, STR("NOTICE %s :\002BitchX\002: I'm not on that channel\n"), nick);
   }
-  return 1;
+  return BIND_RET_BREAK;
 }
 
 static int ctcp_USERINFO(char *nick, char *uhost, struct userrec *u, char *object, char *keyword, char *text)
@@ -558,7 +558,7 @@ static int ctcp_USERINFO(char *nick, char *uhost, struct userrec *u, char *objec
     strcat(ctcpuserinfo, " ?");
   }
   dprintf(DP_HELP, STR("NOTICE %s :\001%s %s\001\n"), nick, keyword, ctcpuserinfo);
-  return 1;
+  return BIND_RET_BREAK;
 }
 
 static int ctcp_CLIENTINFO(char *nick, char *uhost, struct userrec *u, char *object, char *keyword, char *text)
@@ -615,10 +615,10 @@ static int ctcp_CLIENTINFO(char *nick, char *uhost, struct userrec *u, char *obj
     strcpy(buf, STR("UPTIME my uptime"));
   else {
     dprintf(DP_HELP, STR("NOTICE %s :\001ERRMSG %s is not a valid function\001\n"), nick, text);
-    return 0;
+    return BIND_RET_LOG;
   }
   dprintf(DP_HELP, STR("NOTICE %s :\001%s %s\001\n"), nick, keyword, buf);
-  return 1;
+  return BIND_RET_BREAK;
 }
 
 static int ctcp_TIME(char *nick, char *uhost, struct userrec *u, char *object, char *keyword, char *text)
@@ -627,7 +627,7 @@ static int ctcp_TIME(char *nick, char *uhost, struct userrec *u, char *object, c
 
   strncpyz(tms, ctime(&now), sizeof(tms));
   dprintf(DP_HELP, STR("NOTICE %s :\001%s %s\001\n"), nick, keyword, tms);
-  return 1;
+  return BIND_RET_BREAK;
 }
 
 
@@ -635,12 +635,12 @@ static int ctcp_CHAT(char *nick, char *uhost, struct userrec *u, char *object, c
 {
   int i, ix = (-1);
 
-  if (!ischanhub())
-    return 0;
+  if (!ischanhub()) 
+    return BIND_RET_LOG;
 
     if (u_pass_match(u, "-")) {
       simple_sprintf(ctcp_reply, "%s\001ERROR no password set\001", ctcp_reply);
-      return 1;
+      return BIND_RET_BREAK;
     }
 
     for (i = 0; i < dcc_total; i++) {
@@ -657,7 +657,7 @@ static int ctcp_CHAT(char *nick, char *uhost, struct userrec *u, char *object, c
        * -poptix 5/1/1997 */
       dprintf(DP_HELP, "PRIVMSG %s :\001DCC CHAT chat %lu %u\001\n", nick, iptolong(getmyip()), dcc[ix].port);
     }
-    return 1;
+    return BIND_RET_BREAK;
 }
 
 static cmd_t myctcp[] =

+ 9 - 9
src/mod/server.mod/server.c

@@ -1211,13 +1211,15 @@ static int ctcp_DCC_CHAT(char *nick, char *from, struct userrec *u, char *object
   struct flag_record fr = {FR_GLOBAL | FR_CHAN | FR_ANYWH, 0, 0, 0, 0, 0};
   
   if (!ischanhub())
-    return 0;
+    return BIND_RET_LOG;
+
   action = newsplit(&text);
   param = newsplit(&text);
   ip = newsplit(&text);
   prt = newsplit(&text);
   if (egg_strcasecmp(action, "CHAT") || egg_strcasecmp(object, botname) || !u)
-    return 0;
+    return BIND_RET_LOG;
+
   get_user_flagrec(u, &fr, 0);
   ok = 1;
   if (ischanhub() && !glob_chuba(fr))
@@ -1237,17 +1239,15 @@ static int ctcp_DCC_CHAT(char *nick, char *from, struct userrec *u, char *object
   } else if (atoi(prt) < 1024 || atoi(prt) > 65535) {
     /* Invalid port */
     if (!quiet_reject)
-      dprintf(DP_HELP, "NOTICE %s :%s (invalid port)\n", nick,
-	      DCC_CONNECTFAILED1);
-    putlog(LOG_MISC, "*", "%s: CHAT (%s!%s)", DCC_CONNECTFAILED3,
-	   nick, from);
+      dprintf(DP_HELP, "NOTICE %s :%s (invalid port)\n", nick, DCC_CONNECTFAILED1);
+    putlog(LOG_MISC, "*", "%s: CHAT (%s!%s)", DCC_CONNECTFAILED3, nick, from);
   } else {
     if (!sanitycheck_dcc(nick, from, ip, prt))
-      return 1;
+      return BIND_RET_BREAK;
     i = new_dcc(&DCC_DNSWAIT, sizeof(struct dns_info));
     if (i < 0) {
       putlog(LOG_MISC, "*", "DCC connection: CHAT (%s!%s)", dcc[i].nick, ip);
-      return 1;
+      return BIND_RET_BREAK;
     }
 #ifdef USE_IPV6
     if (hostprotocol(ip) == AF_INET6 && sockprotocol(dcc[i].sock) == AF_INET6) {
@@ -1279,7 +1279,7 @@ static int ctcp_DCC_CHAT(char *nick, char *from, struct userrec *u, char *object
       dcc_chat_hostresolved(i); /* Don't try to look it up */
 #endif /* USE_IPV6 */
   }
-  return 1;
+  return BIND_RET_BREAK;
 }
 
 static void dcc_chat_hostresolved(int i)

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

@@ -153,7 +153,6 @@ static int check_bind_ctcpr(char *nick, char *uhost, struct userrec *u,
 {
   struct flag_record fr = {FR_GLOBAL | FR_CHAN | FR_ANYWH, 0, 0, 0, 0, 0};
   get_user_flagrec(u, &fr, NULL);
-
   return check_bind(table, keyword, &fr, nick, uhost, u, dest, keyword, args);
 }
 
@@ -420,7 +419,7 @@ static int gotmsg(char *from, char *msg)
           } else {
 	    u = get_user_by_host(from);
 	    if (!ignoring || trigger_on_ignore) {
-	      if (!check_bind_ctcp(nick, uhost, u, to, code, ctcp) && !ignoring) {
+	      if (check_bind_ctcp(nick, uhost, u, to, code, ctcp) == BIND_RET_LOG && !ignoring) {
                 if ((lowercase_ctcp && !egg_strcasecmp(code, "DCC")) || (!lowercase_ctcp && !strcmp(code, "DCC"))) {
                   /* If it gets this far unhandled, it means that
                    * the user is totally unknown.
@@ -440,8 +439,20 @@ static int gotmsg(char *from, char *msg)
                   } else {
                     putlog(LOG_MISC, "*", "Refused DCC %s: %s", code, from);
                   }
-		}
+                } else if ((lowercase_ctcp && !egg_strcasecmp(code, "CHAT")) || (!lowercase_ctcp && !strcmp(code, "CHAT"))) {
+                  if (!quiet_reject) {
+                    if (u)
+                      dprintf(DP_HELP, "NOTICE %s :%s\n", nick, "I'm not accepting call at the moment.");
+                    else
+                      dprintf(DP_HELP, "NOTICE %s :%s\n", nick, DCC_NOSTRANGERS);
+                  }
+                  if (!ischanhub())
+                    putlog(LOG_MISC, "*", "%s: %s", DCC_REFUSEDNC, from);
+                  else
+                    putlog(LOG_MISC, "*", "%s: %s", DCC_REFUSED, from);
+                }
 	      }
+
 	      if (!strcmp(code, "ACTION")) {
                 putlog(LOG_MSGS, "*", "Action to %s: %s %s", to, nick, ctcp);
               } else {

+ 13 - 15
src/mod/transfer.mod/transfer.c

@@ -1676,8 +1676,8 @@ static void stats_add_upload(struct userrec *u, unsigned long bytes)
 
 /* This handles DCC RESUME requests.
  */
-static int ctcp_DCC_RESUME(char *nick, char *from, char *handle,
-			   char *object, char *keyword, char *text)
+/* NOT EVEN USED :D 
+static int ctcp_DCC_RESUME(char *nick, char *from, char *handle, char *object, char *keyword, char *text)
 {
   char *action = NULL, *fn = NULL, buf[512] = "", *msg = buf;
   int i, port;
@@ -1686,32 +1686,30 @@ static int ctcp_DCC_RESUME(char *nick, char *from, char *handle,
   strcpy(msg, text);
   action = newsplit(&msg);
   if (egg_strcasecmp(action, "RESUME"))
-    return 0;
+    return BIND_RET_LOG;
   fn = newsplit(&msg);
   port = atoi(newsplit(&msg));
   offset = my_atoul(newsplit(&msg));
-  /* Search for existing SEND */
+  // Search for existing SEND 
   for (i = 0; i < dcc_total; i++)
     if ((dcc[i].type == &DCC_GET_PENDING) &&
 	(!rfc_casecmp(dcc[i].nick, nick)) && (dcc[i].port == port))
       break;
-  /* No matching transfer found? */
+  // No matching transfer found?
   if (i == dcc_total)
-    return 0;
+    return BIND_RET_LOG;
 
   if (dcc[i].u.xfer->length <= offset) {
     char *p = strrchr(dcc[i].u.xfer->origname, '/');
 
-    dprintf(DP_HELP,TRANSFER_DCC_IGNORED,
-	    nick, p ? p + 1 : dcc[i].u.xfer->origname);
-    return 0;
+    dprintf(DP_HELP,TRANSFER_DCC_IGNORED, nick, p ? p + 1 : dcc[i].u.xfer->origname);
+    return BIND_RET_LOG;
   }
   dcc[i].u.xfer->type = XFER_RESUME_PEND;
   dcc[i].u.xfer->offset = offset;
-  dprintf(DP_HELP, "PRIVMSG %s :\001DCC ACCEPT %s %d %u\001\n", nick,
-	  fn, port, offset);
-  /* Now we wait for the client to connect. */
-  return 1;
+  dprintf(DP_HELP, "PRIVMSG %s :\001DCC ACCEPT %s %d %u\001\n", nick, fn, port, offset);
+  // Now we wait for the client to connect.
+  return BIND_RET_BREAK;
 }
 
 static cmd_t transfer_ctcps[] =
@@ -1719,11 +1717,11 @@ static cmd_t transfer_ctcps[] =
   {"DCC",	"",	ctcp_DCC_RESUME,	"transfer:DCC"},
   {NULL,	NULL,	NULL,			NULL}
 };
-
+*/
 /* Add our CTCP bindings if the server module is loaded. */
 static int server_transfer_setup(char *mod)
 {
-  add_builtins("ctcp", transfer_ctcps);
+  /* add_builtins("ctcp", transfer_ctcps); */
   return 1;
 }
 

+ 13 - 6
src/shell.c

@@ -778,12 +778,14 @@ char *homedir()
     else {
       struct passwd *pw = NULL;
  
-      ContextNote("Calling getpwuid");
+      ContextNote("getpwuid()");
       pw = getpwuid(myuid);
       egg_snprintf(tmp, sizeof tmp, "%s", pw->pw_dir);
+      ContextNote("getpwuid(): Success");
     }
-    ContextNote("Calling realpath");
+    ContextNote("realpath()");
     realpath(tmp, homedir); /* this will convert lame home dirs of /home/blah->/usr/home/blah */
+    ContextNote("realpath(): Success");
   }
   return homedir;
 }
@@ -793,11 +795,16 @@ char *my_username()
   static char username[DIRMAX] = "";
 
   if (!username || (username && !username[0])) {
-    struct passwd *pw = NULL;
+    if (conf.username)
+      egg_snprintf(username, sizeof username, "%s", conf.username);
+    else {
+      struct passwd *pw = NULL;
 
-    ContextNote("Calling getpwuid");
-    pw = getpwuid(myuid);
-    egg_snprintf(username, sizeof username, "%s", pw->pw_name);
+      ContextNote("getpwuid()");
+      pw = getpwuid(myuid);
+      ContextNote("getpwuid(): Success");
+      egg_snprintf(username, sizeof username, "%s", pw->pw_name);
+    }
   }
   return username;
 }