]> 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.

1  2 
src/ngircd/client.c
src/ngircd/conn.c

diff --combined src/ngircd/client.c
index f163f72c371e2a84121a84d178c3552530109b3d,5ca99c03570c20b97bb92ab40b58f0c82c6f5f27..0d2d4147345046b87f7f3c6e46fd018749f4da36
@@@ -1,6 -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
@@@ -440,18 -440,6 +440,6 @@@ Client_SetFlags( CLIENT *Client, const 
  } /* Client_SetFlags */
  
  
- GLOBAL void
- Client_SetPassword( CLIENT *Client, const char *Pwd )
- {
-       /* set password sent by client */
-       assert( Client != NULL );
-       assert( Pwd != NULL );
-       strlcpy(Client->pwd, Pwd, sizeof(Client->pwd));
- } /* Client_SetPassword */
  GLOBAL void
  Client_SetAway( CLIENT *Client, const char *Txt )
  {
@@@ -714,14 -702,6 +702,6 @@@ Client_HostnameCloaked(CLIENT *Client
  } /* Client_HostnameCloaked */
  
  
- GLOBAL char *
- Client_Password( CLIENT *Client )
- {
-       assert( Client != NULL );
-       return Client->pwd;
- } /* Client_Password */
  GLOBAL char *
  Client_Modes( CLIENT *Client )
  {
@@@ -905,16 -885,6 +885,16 @@@ Client_CheckNick(CLIENT *Client, char *
                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,
@@@ -1185,7 -1155,7 +1165,7 @@@ Client_Introduce(CLIENT *From, CLIENT *
        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 --combined src/ngircd/conn.c
index 28a0341e0a28e1485c077393671b51702b1e6141,e7bf1db891cba610e4737a4e5f8347e5ff732a36..e57aa2423a3eea2bbdacea0500fe9e3452ddb0bf
@@@ -918,6 -918,30 +918,30 @@@ va_dc
        return ok;
  } /* Conn_WriteStr */
  
+ GLOBAL char*
+ Conn_Password( CONN_ID Idx )
+ {
+       assert( Idx > NONE );
+       if (My_Connections[Idx].pwd == NULL)
+               return (char*)"\0";
+       else
+               return My_Connections[Idx].pwd;
+ } /* Conn_Password */
+ GLOBAL void
+ Conn_SetPassword( CONN_ID Idx, const char *Pwd )
+ {
+       assert( Idx > NONE );
+       if (My_Connections[Idx].pwd)
+               free(My_Connections[Idx].pwd);
+       My_Connections[Idx].pwd = strdup(Pwd);
+       if (My_Connections[Idx].pwd == NULL) {
+               Log(LOG_EMERG, "Can't allocate memory! [Conn_SetPassword]");
+               exit(1);
+       }
+ } /* Conn_SetPassword */
  
  /**
   * Append Data to the outbound write buffer of a connection.
@@@ -1146,6 -1170,8 +1170,8 @@@ Conn_Close( CONN_ID Idx, const char *Lo
  
        array_free(&My_Connections[Idx].rbuf);
        array_free(&My_Connections[Idx].wbuf);
+       if (My_Connections[Idx].pwd != NULL)
+               free(My_Connections[Idx].pwd);
  
        /* Clean up connection structure (=free it) */
        Init_Conn_Struct( Idx );
@@@ -1839,10 -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 <