MyBB Community Forums

Full Version: Postgresql authentication bug
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I told MyBB to connect to localhost as user "mybb", and it failed. I tracked it down to the following:

if($single_connection['hostname'] != "localhost")
{
	$this->connect_string .= " host={$single_connection['hostname']}";
}

This is incorrect. Connecting with host=localhost is not the same as connecting without specifying a host. Using no hostname means it'll use a Unix-domain socket connection instead of a TCP connection, and I need it to use TCP.

The default Postgresql configuration (at least in Ubuntu) does not allow password-based authentication over a Unix socket. I'm telling mybb to authenticate as something other than my own username. To do that, it needs to connect over TCP and use the password I've given.

Changing it to this fixed it for me:
if($single_connection['hostname'] != "")
{
	$this->connect_string .= " host={$single_connection['hostname']}";
}

To have the same default behavior, the default field in the setup form should also be changed from localhost to empty.

By the way, I'd also recommend only adding the user= field if it's not blank. That way, you can just leave it blank and it'll connect as the current user, which is more often than not what's wanted.