about summary refs log tree commit diff
diff options
context:
space:
mode:
authorAlexander Barton <alex@barton.de>2011-12-28 15:07:24 +0100
committerAlexander Barton <alex@barton.de>2011-12-28 15:11:01 +0100
commit69fa6f268af88128248523b33b85aa1ab2759a82 (patch)
tree6878ed460d3b2ad15002d35b9968109a5291bbe7
parent43509fd22c30e0ce1f1eb02fd584a0693177d880 (diff)
downloadngircd-69fa6f268af88128248523b33b85aa1ab2759a82.tar.gz
ngircd-69fa6f268af88128248523b33b85aa1ab2759a82.zip
LUSERS reply: only count "visible" channels
Rename Channel_Count() to Channel_CountVisible() and only count channels
that are visible to the requesting client, so the existence of secret
channels is no longer revealed by using LUSERS.

Reported by Cahata -- thanks!
-rw-r--r--src/ngircd/channel.c21
-rw-r--r--src/ngircd/channel.h2
-rw-r--r--src/ngircd/irc-info.c3
3 files changed, 19 insertions, 7 deletions
diff --git a/src/ngircd/channel.c b/src/ngircd/channel.c
index 2dbf53a2..4d323f27 100644
--- a/src/ngircd/channel.c
+++ b/src/ngircd/channel.c
@@ -352,20 +352,31 @@ Channel_Quit( CLIENT *Client, const char *Reason )
 } /* Channel_Quit */
 
 
+/**
+ * Get number of channels this server knows and that are "visible" to
+ * the given client. If no client is given, all channels will be counted.
+ *
+ * @param Client The client to check or NULL.
+ * @return Number of channels visible to the client.
+ */
 GLOBAL unsigned long
-Channel_Count( void )
+Channel_CountVisible (CLIENT *Client)
 {
 	CHANNEL *c;
 	unsigned long count = 0;
 
 	c = My_Channels;
-	while( c )
-	{
-		count++;
+	while(c) {
+		if (Client) {
+			if (!strchr(Channel_Modes(c), 's')
+			    || Channel_IsMemberOf(c, Client))
+				count++;
+		} else
+			count++;
 		c = c->next;
 	}
 	return count;
-} /* Channel_Count */
+}
 
 
 GLOBAL unsigned long
diff --git a/src/ngircd/channel.h b/src/ngircd/channel.h
index f44e1946..ba3f2ca6 100644
--- a/src/ngircd/channel.h
+++ b/src/ngircd/channel.h
@@ -72,7 +72,7 @@ GLOBAL void Channel_Quit PARAMS(( CLIENT *Client, const char *Reason ));
 GLOBAL void Channel_Kick PARAMS((CLIENT *Peer, CLIENT *Target, CLIENT *Origin,
 				 const char *Name, const char *Reason));
 
-GLOBAL unsigned long Channel_Count PARAMS(( void ));
+GLOBAL unsigned long Channel_CountVisible PARAMS((CLIENT *Client));
 GLOBAL unsigned long Channel_MemberCount PARAMS(( CHANNEL *Chan ));
 GLOBAL int Channel_CountForUser PARAMS(( CLIENT *Client ));
 
diff --git a/src/ngircd/irc-info.c b/src/ngircd/irc-info.c
index cdd03bb1..01192570 100644
--- a/src/ngircd/irc-info.c
+++ b/src/ngircd/irc-info.c
@@ -1317,7 +1317,8 @@ IRC_Send_LUSERS(CLIENT *Client)
 
 	/* Number of created channels */
 	if (!IRC_WriteStrClient(Client, RPL_LUSERCHANNELS_MSG,
-				Client_ID(Client), Channel_Count()))
+				Client_ID(Client),
+				Channel_CountVisible(Client)))
 		return DISCONNECTED;
 
 	/* Number of local users, services and servers */