Implementation clean-ups.

* Have Conn_Password return an empty string when no password has been set,
  to play better with pam.c.

* Use strdup in Conn_SetPassword.
This commit is contained in:
Brett Smith 2012-08-23 12:24:34 -04:00
parent 7df4c12da9
commit c1d7f6216f
1 changed files with 5 additions and 3 deletions

View File

@ -922,6 +922,9 @@ GLOBAL const char*
Conn_Password( CONN_ID Idx ) Conn_Password( CONN_ID Idx )
{ {
assert( Idx > NONE ); assert( Idx > NONE );
if (My_Connections[Idx].pwd == NULL)
return (char*)"\0";
else
return My_Connections[Idx].pwd; return My_Connections[Idx].pwd;
} /* Conn_Password */ } /* Conn_Password */
@ -929,12 +932,11 @@ GLOBAL void
Conn_SetPassword( CONN_ID Idx, const char *Pwd ) Conn_SetPassword( CONN_ID Idx, const char *Pwd )
{ {
assert( Idx > NONE ); assert( Idx > NONE );
My_Connections[Idx].pwd = calloc(strlen(Pwd) + 1, sizeof(char)); My_Connections[Idx].pwd = strdup(Pwd);
if (My_Connections[Idx].pwd == NULL) { if (My_Connections[Idx].pwd == NULL) {
Log(LOG_EMERG, "Can't allocate memory! [Conn_SetPassword]"); Log(LOG_EMERG, "Can't allocate memory! [Conn_SetPassword]");
exit(1); exit(1);
} }
strcpy( My_Connections[Idx].pwd, Pwd );
} /* Conn_SetPassword */ } /* Conn_SetPassword */
/** /**