static void start_auth_request(PgSocket *client, const char *username) { int res; char quoted_username[64], query[128]; client->auth_user = client->db->auth_user; /* have to fetch user info from db */ client->pool = get_pool(client->db, client->db->auth_user); if (!find_server(client)) { client->wait_for_user_conn = true; return; } slog_noise(client, "Doing auth_conn query"); client->wait_for_user_conn = false; client->wait_for_user = true; if (!sbuf_pause(&client->sbuf)) { release_server(client->link); disconnect_client(client, true, "pause failed"); return; } client->link->ready = 0; pg_quote_literal(quoted_username, username, sizeof(quoted_username)); snprintf(query, sizeof(query), "SELECT usename, passwd FROM pg_shadow WHERE usename=%s", quoted_username); SEND_generic(res, client->link, 'Q', "s", query); if (!res) disconnect_server(client->link, false, "unable to send login query"); }
static bool send_client_authreq(PgSocket *client) { uint8_t saltlen = 0; int res; int auth_type = client->client_auth_type; /* Always use plain text to communicate with clients during PAM authorization */ if (auth_type == AUTH_PAM) { auth_type = AUTH_PLAIN; } if (auth_type == AUTH_MD5) { saltlen = 4; get_random_bytes((void*)client->tmp_login_salt, saltlen); } else if (auth_type == AUTH_PLAIN) { /* nothing to do */ } else { return false; } SEND_generic(res, client, 'R', "ib", auth_type, client->tmp_login_salt, saltlen); if (!res) disconnect_client(client, false, "failed to send auth req"); return res; }
static bool send_client_authreq(PgSocket *client) { uint8_t saltlen = 0; int res; int auth = cf_auth_type; uint8_t randbuf[2]; if (auth == AUTH_CRYPT) { saltlen = 2; get_random_bytes(randbuf, saltlen); client->tmp_login_salt[0] = valid_crypt_salt[randbuf[0] & SALT_MASK]; client->tmp_login_salt[1] = valid_crypt_salt[randbuf[1] & SALT_MASK]; client->tmp_login_salt[2] = 0; } else if (cf_auth_type == AUTH_MD5) { saltlen = 4; get_random_bytes((void*)client->tmp_login_salt, saltlen); } else if (auth == AUTH_ANY) auth = AUTH_TRUST; SEND_generic(res, client, 'R', "ib", auth, client->tmp_login_salt, saltlen); return res; }