From: Alexander Barton Date: Sun, 26 Aug 2012 17:14:29 +0000 (+0200) Subject: Merge branch 'move-connection-password' of git://arthur.barton.de/ngircd-alex X-Git-Tag: rel-20-rc1~104 X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bcefdef1eaed14d3156b7fb5b9ad6d3b7078efcf;hp=f79d41e92741fa2f6bc6fef957d278707ad4236a;p=ngircd.git Merge branch 'move-connection-password' of git://arthur.barton.de/ngircd-alex 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. --- diff --git a/contrib/MacOSX/ngIRCd.xcodeproj/project.pbxproj b/contrib/MacOSX/ngIRCd.xcodeproj/project.pbxproj index 6da1cb3e..ac3f6235 100644 --- a/contrib/MacOSX/ngIRCd.xcodeproj/project.pbxproj +++ b/contrib/MacOSX/ngIRCd.xcodeproj/project.pbxproj @@ -787,6 +787,7 @@ 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; diff --git a/doc/sample-ngircd.conf.tmpl b/doc/sample-ngircd.conf.tmpl index 6d9d7709..57e65892 100644 --- a/doc/sample-ngircd.conf.tmpl +++ b/doc/sample-ngircd.conf.tmpl @@ -297,15 +297,16 @@ # 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 ... diff --git a/man/ngircd.conf.5.tmpl b/man/ngircd.conf.5.tmpl index 71f00078..aff11a67 100644 --- a/man/ngircd.conf.5.tmpl +++ b/man/ngircd.conf.5.tmpl @@ -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] diff --git a/src/ngircd/client.c b/src/ngircd/client.c index 5ca99c03..0d2d4147 100644 --- a/src/ngircd/client.c +++ b/src/ngircd/client.c @@ -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).", diff --git a/src/ngircd/conf.c b/src/ngircd/conf.c index 923cdc02..3966dc90 100644 --- a/src/ngircd/conf.c +++ b/src/ngircd/conf.c @@ -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; } /** diff --git a/src/ngircd/conf.h b/src/ngircd/conf.h index 4e7e3796..8e66c07c 100644 --- a/src/ngircd/conf.h +++ b/src/ngircd/conf.h @@ -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]; diff --git a/src/ngircd/conn.c b/src/ngircd/conn.c index e7bf1db8..e57aa242 100644 --- a/src/ngircd/conn.c +++ b/src/ngircd/conn.c @@ -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 < diff --git a/src/ngircd/match.c b/src/ngircd/match.c index 79699ea0..75bf4358 100644 --- a/src/ngircd/match.c +++ b/src/ngircd/match.c @@ -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 */ diff --git a/src/ngircd/match.h b/src/ngircd/match.h index 2efe3f5b..d4107fb6 100644 --- a/src/ngircd/match.h +++ b/src/ngircd/match.h @@ -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 @@ -17,8 +17,14 @@ * 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 diff --git a/src/ngircd/messages.h b/src/ngircd/messages.h index 96ff2dea..9ad6be17 100644 --- a/src/ngircd/messages.h +++ b/src/ngircd/messages.h @@ -112,6 +112,7 @@ #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"