are the cleartext password, and the SQL name of the user it is for.
algorithm> specifies the encryption algorithm
to use to encrypt the password. Currently supported algorithms are
- md5>, scram-sha-256> and plain>.
+ md5> and scram-sha-256> (on> and
+ off> are also accepted as aliases for md5>, for
+ compatibility with older server versions). Note that support for
scram-sha-256> was introduced in PostgreSQL>
version 10, and will not work correctly with older server versions. If
algorithm> is NULL>, this function will query
{
PQclear(res);
printfPQExpBuffer(&conn->errorMessage,
- libpq_gettext("password_encryption value too long\n"));
+ libpq_gettext("password_encryption value too long\n"));
return NULL;
}
strcpy(algobuf, val);
algorithm = algobuf;
}
- /* Ok, now we know what algorithm to use */
+ /*
+ * Also accept "on" and "off" as aliases for "md5", because
+ * password_encryption was a boolean before PostgreSQL 10. We refuse to
+ * send the password in plaintext even if it was "off".
+ */
+ if (strcmp(algorithm, "on") == 0 ||
+ strcmp(algorithm, "off") == 0 ||
+ strcmp(algorithm, "plain") == 0)
+ algorithm = "md5";
+ /*
+ * Ok, now we know what algorithm to use
+ */
if (strcmp(algorithm, "scram-sha-256") == 0)
{
crypt_pwd = pg_fe_scram_build_verifier(passwd);
}
}
}
- else if (strcmp(algorithm, "plain") == 0)
- {
- crypt_pwd = strdup(passwd);
- }
else
{
printfPQExpBuffer(&conn->errorMessage,
- libpq_gettext("unknown password encryption algorithm\n"));
+ libpq_gettext("unknown password encryption algorithm\n"));
return NULL;
}