]> arthur.barton.de Git - ngircd-alex.git/commitdiff
Merge branch 'move-connection-password' of git://arthur.barton.de/ngircd-alex
authorAlexander Barton <alex@barton.de>
Sun, 26 Aug 2012 17:14:29 +0000 (19:14 +0200)
committerAlexander Barton <alex@barton.de>
Sun, 26 Aug 2012 17:14:29 +0000 (19:14 +0200)
This patch series converts the statically allocated password buffer in the
CLIENT structure into a dynamically (and only when needed) allocated buffer
which is referenced by the CONNECTION structure.

This a) saves memory for clients not using passwords at all and b) allows
for "arbitrarily" long passwords.

By Brett Smith (5) and Alexander Barton (2).

* 'move-connection-password' of git://arthur.barton.de/ngircd-alex:
  Login_User(): use "conn" insted of calling Client_Conn(Client)
  Free already saved password when storing a new one
  Indentation and style fixes.
  Connection password is not constant.
  Implementation clean-ups.
  Dynamically allocate memory for connection password.
  Move client password from the Client to the Connection struct.

contrib/MacOSX/ngIRCd.xcodeproj/project.pbxproj
doc/sample-ngircd.conf.tmpl
man/ngircd.conf.5.tmpl
src/ngircd/client.c
src/ngircd/conf.c
src/ngircd/conf.h
src/ngircd/conn.c
src/ngircd/match.c
src/ngircd/match.h
src/ngircd/messages.h

index 6da1cb3e1e9cac2baa588f56c3572671b0ff96bb..ac3f6235381cea4879e4b0c09a1fee324ee93777 100644 (file)
                        isa = XCBuildConfiguration;
                        buildSettings = {
                                ARCHS = "$(ARCHS_STANDARD_32_64_BIT)";
+                               CODE_SIGN_IDENTITY = "Developer ID Application: Alexander Barton";
                                GCC_VERSION = 4.2;
                                GCC_WARN_ABOUT_RETURN_TYPE = YES;
                                GCC_WARN_UNUSED_VARIABLE = YES;
index 6d9d77098641ec4459375d56eb2a5a0d405dbd92..57e65892054b9bd20c1d2cc309dd9ccaca1c1a41 100644 (file)
        # Connect to the remote server using TLS/SSL (Default: false)
        ;SSLConnect = yes
 
-       # Define a (case insensitive) mask matching nick names that should be
-       # treated as IRC services when introduced via this remote server.
+       # Define a (case insensitive) list of masks matching nick names that
+       # should be treated as IRC services when introduced via this remote
+       # server, separated by commas (",").
        # REGULAR SERVERS DON'T NEED this parameter, so leave it empty
        # (which is the default).
        # When you are connecting IRC services which mask as a IRC server
        # and which use "virtual users" to communicate with, for example
        # "NickServ" and "ChanServ", you should set this parameter to
-       # something like "*Serv".
-       ;ServiceMask = *Serv
+       # something like "*Serv" or "NickServ,ChanServ,XyzServ".
+       ;ServiceMask = *Serv,Global
 
 [Server]
        # More [Server] sections, if you like ...
index 71f0007851e738222ed7064b71921d4bb09cd097..aff11a67bf86ec6c79d0daae9cfadeff345662f2 100644 (file)
@@ -422,14 +422,16 @@ You can use the IRC Operator command CONNECT later on to create the link.
 Connect to the remote server using TLS/SSL. Default: false.
 .TP
 \fBServiceMask\fR (string)
-Define a (case insensitive) mask matching nick names that should be treated as
-IRC services when introduced via this remote server. REGULAR SERVERS DON'T NEED
-this parameter, so leave it empty (which is the default).
+Define a (case insensitive) list of masks matching nick names that should be
+treated as IRC services when introduced via this remote server, separated
+by commas (","). REGULAR SERVERS DON'T NEED this parameter, so leave it empty
+(which is the default).
 .PP
 .RS
 When you are connecting IRC services which mask as a IRC server and which use
 "virtual users" to communicate with, for example "NickServ" and "ChanServ",
-you should set this parameter to something like "*Serv".
+you should set this parameter to something like "*Serv", "*Serv,OtherNick",
+or "NickServ,ChanServ,XyzServ".
 .SH [CHANNEL]
 Pre-defined channels can be configured in
 .I [Channel]
index 5ca99c03570c20b97bb92ab40b58f0c82c6f5f27..0d2d4147345046b87f7f3c6e46fd018749f4da36 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * ngIRCd -- The Next Generation IRC Daemon
- * Copyright (c)2001-2010 Alexander Barton (alex@barton.de)
+ * Copyright (c)2001-2012 Alexander Barton (alex@barton.de)
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -885,6 +885,16 @@ Client_CheckNick(CLIENT *Client, char *Nick)
                return false;
        }
 
+       if (Client_Type(Client) != CLIENT_SERVER
+           && Client_Type(Client) != CLIENT_SERVICE) {
+               /* Make sure that this isn't a restricted/forbidden nick name */
+               if (Conf_NickIsBlocked(Nick)) {
+                       IRC_WriteStrClient(Client, ERR_FORBIDDENNICKNAME_MSG,
+                                          Client_ID(Client), Nick);
+                       return false;
+               }
+       }
+
        /* Nickname already registered? */
        if (Client_Search(Nick)) {
                IRC_WriteStrClient(Client, ERR_NICKNAMEINUSE_MSG,
@@ -1155,7 +1165,7 @@ Client_Introduce(CLIENT *From, CLIENT *Client, int Type)
        Client_SetType(Client, Type);
 
        if (From) {
-               if (Conf_IsService(Conf_GetServer(Client_Conn(From)),
+               if (Conf_NickIsService(Conf_GetServer(Client_Conn(From)),
                                   Client_ID(Client)))
                        Client_SetType(Client, CLIENT_SERVICE);
                LogDebug("%s \"%s\" (+%s) registered (via %s, on %s, %d hop%s).",
index 923cdc025bf50be6bad356ff56e802b3e1a8dc14..3966dc908a1afff2bf5a95901c8cff6427b91524 100644 (file)
@@ -636,14 +636,41 @@ Conf_AddServer(const char *Name, UINT16 Port, const char *Host,
 }
 
 /**
- * Check if the given nick name is an service.
+ * Check if the given nick name is reserved for services on a particular server.
  *
+ * @param ConfServer The server index to check.
+ * @param Nick The nick name to check.
  * @returns true if the given nick name belongs to an "IRC service".
  */
 GLOBAL bool
-Conf_IsService(int ConfServer, const char *Nick)
+Conf_NickIsService(int ConfServer, const char *Nick)
 {
-       return MatchCaseInsensitive(Conf_Server[ConfServer].svs_mask, Nick);
+       assert (ConfServer >= 0);
+       assert (ConfServer < MAX_SERVERS);
+
+       return MatchCaseInsensitiveList(Conf_Server[ConfServer].svs_mask,
+                                       Nick, ",");
+}
+
+/**
+ * Check if the given nick name is blocked for "normal client" use.
+ *
+ * @param ConfServer The server index or NONE to check all configured servers.
+ * @param Nick The nick name to check.
+ * @returns true if the given nick name belongs to an "IRC service".
+ */
+GLOBAL bool
+Conf_NickIsBlocked(const char *Nick)
+{
+       int i;
+
+       for(i = 0; i < MAX_SERVERS; i++) {
+               if (!Conf_Server[i].name[0])
+                       continue;
+               if (Conf_NickIsService(i, Nick))
+                       return true;
+       }
+       return false;
 }
 
 /**
index 4e7e3796478d8f200b11661c4ade71488dcfbad3..8e66c07c3c671f3ecf119fc50f6fc313cdaa5307 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * ngIRCd -- The Next Generation IRC Daemon
- * Copyright (c)2001-2011 Alexander Barton (alex@barton.de) and Contributors.
+ * Copyright (c)2001-2012 Alexander Barton (alex@barton.de) and Contributors.
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -244,7 +244,8 @@ GLOBAL bool Conf_EnablePassiveServer PARAMS((const char *Name));
 GLOBAL bool Conf_DisableServer PARAMS(( const char *Name ));
 GLOBAL bool Conf_AddServer PARAMS(( const char *Name, UINT16 Port, const char *Host, const char *MyPwd, const char *PeerPwd ));
 
-GLOBAL bool Conf_IsService PARAMS((int ConfServer, const char *Nick));
+GLOBAL bool Conf_NickIsService PARAMS((int ConfServer, const char *Nick));
+GLOBAL bool Conf_NickIsBlocked PARAMS((const char *Nick));
 
 /* Password required by WEBIRC command */
 GLOBAL char Conf_WebircPwd[CLIENT_PASS_LEN];
index e7bf1db891cba610e4737a4e5f8347e5ff732a36..e57aa2423a3eea2bbdacea0500fe9e3452ddb0bf 100644 (file)
@@ -1865,10 +1865,10 @@ Check_Connections(void)
                                if (My_Connections[i].lastping <
                                    time(NULL) - Conf_PongTimeout) {
                                        /* Timeout */
-                                       LogDebug
-                                           ("Connection %d: Ping timeout: %d seconds.",
-                                            i, Conf_PongTimeout);
-                                       snprintf(msg, sizeof(msg), "Ping timeout: %d seconds", Conf_PongTimeout);
+                                       snprintf(msg, sizeof(msg),
+                                                "Ping timeout: %d seconds",
+                                                Conf_PongTimeout);
+                                       LogDebug("Connection %d: %s.", i, msg);
                                        Conn_Close(i, NULL, msg, true);
                                }
                        } else if (My_Connections[i].lastdata <
index 79699ea0d8740b7cf555af732d3c22ec1dfc9861..75bf4358395d27fa21b8a9c213c307a82a2196d6 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * ngIRCd -- The Next Generation IRC Daemon
- * Copyright (c)2001,2002 by Alexander Barton (alex@barton.de)
+ * Copyright (c)2001-2012 Alexander Barton (alex@barton.de) and Contributors.
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -48,9 +48,9 @@ static int Matche_After_Star PARAMS(( const char *p, const char *t ));
 /**
  * Match string with pattern.
  *
- * @param Pattern      Pattern to match with
- * @param String       Input string
- * @return             true if pattern matches
+ * @param Pattern Pattern to match with
+ * @param String Input string
+ * @return true if pattern matches
  */
 GLOBAL bool
 Match( const char *Pattern, const char *String )
@@ -64,17 +64,46 @@ Match( const char *Pattern, const char *String )
 /**
  * Match string with pattern case-insensitive.
  *
- * @param pattern      Pattern to match with
- * @param searchme     Input string, at most COMMAND_LEN-1 characters long
- * @return             true if pattern matches
+ * @param Pattern Pattern to match with
+ * @param String Input string, at most COMMAND_LEN-1 characters long
+ * @return true if pattern matches
  */
 GLOBAL bool
-MatchCaseInsensitive(const char *pattern, const char *searchme)
+MatchCaseInsensitive(const char *Pattern, const char *String)
 {
        char haystack[COMMAND_LEN];
 
-       strlcpy(haystack, searchme, sizeof(haystack));
-       return Match(pattern, ngt_LowerStr(haystack));
+       strlcpy(haystack, String, sizeof(haystack));
+       return Match(Pattern, ngt_LowerStr(haystack));
+} /* MatchCaseInsensitive */
+
+
+/**
+ * Match string with pattern case-insensitive.
+ *
+ * @param pattern Pattern to match with
+ * @param String Input string, at most COMMAND_LEN-1 characters long
+ * @param Separator Character separating the individual patterns in the list
+ * @return true if pattern matches
+ */
+GLOBAL bool
+MatchCaseInsensitiveList(const char *Pattern, const char *String,
+                    const char *Separator)
+{
+       char tmp_pattern[COMMAND_LEN], haystack[COMMAND_LEN], *ptr;
+
+       strlcpy(tmp_pattern, Pattern, sizeof(tmp_pattern));
+       strlcpy(haystack, String, sizeof(haystack));
+       ngt_LowerStr(haystack);
+
+       ptr = strtok(tmp_pattern, Separator);
+       while (ptr) {
+               ngt_TrimStr(ptr);
+               if (Match(ptr, haystack))
+                       return true;
+               ptr = strtok(NULL, Separator);
+       }
+       return false;
 } /* MatchCaseInsensitive */
 
 
index 2efe3f5ba7ad81b08d0d237487b7112b77e22ebc..d4107fb65d357fcdab95677685fa6340378b53d5 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * ngIRCd -- The Next Generation IRC Daemon
- * Copyright (c)2001,2002 by Alexander Barton (alex@barton.de)
+ * Copyright (c)2001-2012 Alexander Barton (alex@barton.de) and Contributors.
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
  * Wildcard pattern matching (header)
  */
 
-GLOBAL bool Match PARAMS(( const char *Pattern, const char *String ));
-GLOBAL bool MatchCaseInsensitive PARAMS(( const char *Pattern, const char *searchme ));
+GLOBAL bool Match PARAMS((const char *Pattern, const char *String));
+
+GLOBAL bool MatchCaseInsensitive PARAMS((const char *Pattern,
+                                        const char *String));
+
+GLOBAL bool MatchCaseInsensitiveList PARAMS((const char *Pattern,
+                                            const char *String,
+                                            const char *Separator));
 
 #endif
 
index 96ff2dea2cc8ab431eef03adb084e7f16d1e3f69..9ad6be1763d569f7af3b486e3620930f15127516 100644 (file)
 #define ERR_NONICKNAMEGIVEN_MSG                "431 %s :No nickname given"
 #define ERR_ERRONEUSNICKNAME_MSG       "432 %s %s :Erroneous nickname"
 #define ERR_NICKNAMETOOLONG_MSG                "432 %s %s :Nickname too long, max. %u characters"
+#define ERR_FORBIDDENNICKNAME_MSG      "432 %s %s :Nickname is forbidden/blocked"
 #define ERR_NICKNAMEINUSE_MSG          "433 %s %s :Nickname already in use"
 #define ERR_USERNOTINCHANNEL_MSG       "441 %s %s %s :They aren't on that channel"
 #define ERR_NOTONCHANNEL_MSG           "442 %s %s :You are not on that channel"