Parcourir la source

* Ported [2540] to 1.2.12
* cmd_swhois is now -|- and hides all restricted information, channels; see 'help swhois'.


svn: 3093

Bryan Drewery il y a 20 ans
Parent
commit
8f890493e1
5 fichiers modifiés avec 69 ajouts et 9 suppressions
  1. 1 0
      doc/UPDATES
  2. 6 1
      misc/help.txt
  3. 3 3
      src/mod/irc.mod/cmdsirc.c
  4. 1 0
      src/mod/irc.mod/irc.h
  5. 58 5
      src/mod/server.mod/servmsg.c

+ 1 - 0
doc/UPDATES

@@ -12,6 +12,7 @@ Lines prefixed with '-' were disabled before release and are not finished, or ar
 * Added build os/architechture to output for ./binary -v
 * Added ARCH entry for bots in .whois
 * Added a new error code (22) which displays if attempting to run binary before using -C.
+* cmd_swhois is now -|- and hides all restricted information, channels; see 'help swhois'.
 
 1.2.11 - http://wraith.shatow.net/milestone/1.2.11
 * Fixed typo in help for .set/.conf/.channel

+ 6 - 1
misc/help.txt

@@ -1392,7 +1392,7 @@ See also: md5, sha1, encrypt, decrypt
 ::rehash
 ###  $brehash$b 
    Don't use this cmd.
-
+ 
    Reloads config data from binary. (Probably won't be needed as this is automatically
    updated after editing the binary with -C)
  
@@ -1676,6 +1676,11 @@ See also: die, conf
    display the whois as viewed by that server.
    If the nick is currently not online, a /WHOWAS is done automatically.
  
+   This cmd will hide restricted username/channel info as follows:
+    -Username will be hidden for higher level users
+    -Users will not see +private chans unless they are in the chan or chan is -sp
+    -Users will not see channels that are +s or +p unless they have op access there
+ 
 See also: find
 :leaf:topic
 ###  $btopic$b <text>

+ 3 - 3
src/mod/irc.mod/cmdsirc.c

@@ -47,10 +47,10 @@ static int has_op(int idx, struct chanset_t *chan)
 /* Finds a nick of the handle. Returns m->nick if
  * the nick was found, otherwise NULL (Sup 1Nov2000)
  */
-static char *getnick(char *handle, struct chanset_t *chan)
+char *getnick(const char *handle, struct chanset_t *chan)
 {
-  char s[UHOSTLEN] = "";
   struct userrec *u = NULL;
+  char s[UHOSTLEN] = "";
 
   for (register memberlist *m = chan->channel.member; m && m->nick[0]; m = m->next) {
     simple_snprintf(s, sizeof s, "%s!%s", m->nick, m->userhost);
@@ -1730,7 +1730,7 @@ static cmd_t irc_dcc[] =
   {"resetexempts",	"o|o",	 (Function) cmd_resetexempts,	NULL, LEAF|AUTH},
   {"resetinvites",	"o|o",	 (Function) cmd_resetinvites,	NULL, LEAF|AUTH},
   {"say",		"o|o",	 (Function) cmd_say,		NULL, LEAF},
-  {"swhois",		"n",	 (Function) cmd_swhois,		NULL, LEAF|AUTH},
+  {"swhois",		"",	 (Function) cmd_swhois,		NULL, LEAF|AUTH},
   {"topic",		"o|o",	 (Function) cmd_topic,		NULL, LEAF|AUTH},
   {"voice",		"o|o",	 (Function) cmd_voice,		NULL, LEAF|AUTH},
   {NULL,		NULL,	 NULL,				NULL, 0}

+ 1 - 0
src/mod/irc.mod/irc.h

@@ -111,6 +111,7 @@ void recheck_channel_modes(struct chanset_t *);
 void irc_report(int, int);
 void flush_modes();
 void reset_chan_info(struct chanset_t *);
+char *getnick(const char *, struct chanset_t *);
 
 extern int		max_bans, max_exempts, max_invites, max_modes;
 extern bool		use_354;

+ 58 - 5
src/mod/server.mod/servmsg.c

@@ -1131,9 +1131,12 @@ irc_whois(char *nick, const char *format, ...)
   egg_vsnprintf(va_out, sizeof(va_out) - 1, format, va);
   va_end(va);
 
-  for (int idx = 0; idx < dcc_total; idx++)
-    if (dcc[idx].type && dcc[idx].whois[0] && !rfc_casecmp(nick, dcc[idx].whois))
+  for (int idx = 0; idx < dcc_total; idx++) {
+    if (dcc[idx].type && dcc[idx].whois[0] && !rfc_casecmp(nick, dcc[idx].whois)) {
       dprintf(idx, "%s\n", va_out);
+      break;
+    }
+  }
 }
 
 void check_hostmask()
@@ -1182,14 +1185,55 @@ static int got311(char *from, char *msg)
   irc_whois(nick, "$b%s$b [%s@%s]", nick, username, address);
 
   simple_snprintf(uhost, sizeof uhost, "%s!%s@%s", nick, username, address);
-  if ((u = get_user_by_host(uhost))) 
-    irc_whois(nick, " username : $u%s$u", u->handle);
+  if ((u = get_user_by_host(uhost))) {
+    int idx = 0;
+    for (idx = 0; idx < dcc_total; idx++) {
+      if (dcc[idx].type && dcc[idx].whois[0] && !rfc_casecmp(nick, dcc[idx].whois)) {
+        if (whois_access(dcc[idx].user, u)) {
+          irc_whois(nick, " username : $u%s$u", u->handle);
+        }
+        break;
+      }
+    }
+  }
 
   irc_whois(nick, " ircname  : %s", msg);
   
   return 0;
 }
 
+static char *
+hide_chans(const char *nick, struct userrec *u, char *channels)
+{
+  char *chans = NULL, *chname = NULL, s[5] = "";
+  size_t len = strlen(channels) + 100 + 1;
+  struct chanset_t *chan = NULL;
+  struct flag_record fr = { FR_CHAN | FR_GLOBAL, 0, 0, 0 };
+
+  chans = (char *) my_calloc(1, len);
+
+  while ((chname = newsplit(&channels))[0]) {
+    /* save and skip any modes in front of #chan */
+    s[0] = 0;
+    while (chname[0] && chname[0] != '#') {
+      simple_snprintf(s, sizeof(s), "%c", chname[0]);
+      chname++;
+    }
+
+    chan = findchan_by_dname(chname);
+    if (chan)
+     get_user_flagrec(u, &fr, chan->dname);
+
+    if (!chan || getnick(u->handle, chan) || !(chan->channel.mode & (CHANPRIV|CHANSEC)) || chk_op(fr, chan)) {
+      if (chans[0])
+        simple_snprintf(chans, len, "%s %s%s", chans, s, chname);
+      else
+        simple_snprintf(chans, len, "%s%s", s, chname);
+    }
+  }
+  return chans;
+}
+
 /* 319 $me nick :channels */
 static int got319(char *from, char *msg)
 {
@@ -1199,7 +1243,16 @@ static int got319(char *from, char *msg)
   nick = newsplit(&msg);
   fixcolon(msg);
 
-  irc_whois(nick, " channels : %s", msg);
+  for (int idx = 0; idx < dcc_total; idx++) {
+    if (dcc[idx].type && dcc[idx].whois[0] && !rfc_casecmp(nick, dcc[idx].whois)) {
+      char *chans = NULL;
+
+      if ((chans = hide_chans(nick, dcc[idx].user, msg))) {
+        irc_whois(nick, " channels : %s", chans);
+        free(chans);
+      }
+    }
+  }
 
   return 0;
 }