]> arthur.barton.de Git - ngircd.git/blobdiff - src/ngircd/conn.c
Merge branch 'better-chan-errors'
[ngircd.git] / src / ngircd / conn.c
index 03c423e35e0d5616e7204e4488ebfe1cf6953bdd..e57aa2423a3eea2bbdacea0500fe9e3452ddb0bf 100644 (file)
@@ -918,23 +918,29 @@ va_dcl
        return ok;
 } /* Conn_WriteStr */
 
-GLOBAL const char*
+GLOBAL char*
 Conn_Password( CONN_ID Idx )
 {
-  assert( Idx > NONE );
-  return My_Connections[Idx].pwd;
+       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 );
-  My_Connections[Idx].pwd = calloc(strlen(Pwd) + 1, sizeof(char));
-  if (My_Connections[Idx].pwd == NULL) {
-    Log(LOG_EMERG, "Can't allocate memory! [Conn_SetPassword]");
-    exit(1);
-  }
-  strcpy( My_Connections[Idx].pwd, 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 */
 
 /**
@@ -1165,7 +1171,7 @@ Conn_Close( CONN_ID Idx, const char *LogMsg, const char *FwdMsg, bool InformClie
        array_free(&My_Connections[Idx].rbuf);
        array_free(&My_Connections[Idx].wbuf);
        if (My_Connections[Idx].pwd != NULL)
-         free(My_Connections[Idx].pwd);
+               free(My_Connections[Idx].pwd);
 
        /* Clean up connection structure (=free it) */
        Init_Conn_Struct( Idx );
@@ -1859,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 <