]> arthur.barton.de Git - ngircd.git/blobdiff - src/ngircd/conn.c
Dynamically allocate memory for connection password.
[ngircd.git] / src / ngircd / conn.c
index 06236fd43e2ab1269e91e1065efa11786da0ed40..03c423e35e0d5616e7204e4488ebfe1cf6953bdd 100644 (file)
@@ -918,6 +918,24 @@ va_dcl
        return ok;
 } /* Conn_WriteStr */
 
+GLOBAL const char*
+Conn_Password( CONN_ID Idx )
+{
+  assert( Idx > NONE );
+  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 );
+} /* Conn_SetPassword */
 
 /**
  * Append Data to the outbound write buffer of a connection.
@@ -1146,6 +1164,8 @@ 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);
 
        /* Clean up connection structure (=free it) */
        Init_Conn_Struct( Idx );