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"); }
uint32_t PgReader::fetchPcid() const { if (m_pcid) return m_pcid; log()->get(LogLevel::Debug) << "Fetching pcid ..." << std::endl; std::ostringstream oss; oss << "SELECT PC_Typmod_Pcid(a.atttypmod) AS pcid "; oss << "FROM pg_class c, pg_attribute a"; if (!m_schema_name.empty()) { oss << ", pg_namespace n"; } oss << " WHERE c.relname = " << pg_quote_literal(m_table_name); oss << " AND a.attname = " << pg_quote_literal(m_column_name); if (!m_schema_name.empty()) { oss << " AND c.relnamespace = n.oid AND n.nspname = " << pg_quote_literal(m_schema_name); } char *pcid_str = pg_query_once(m_session, oss.str()); uint32_t pcid = 0; if (pcid_str) { pcid = atoi(pcid_str); free(pcid_str); } if (!pcid) // Are pcid == 0 valid? { std::ostringstream oss; oss << "Unable to fetch pcid with column '" << m_column_name <<"' and table "; if (!m_schema_name.empty()) oss << "'" << m_schema_name << "'."; oss << "'" << m_table_name << "'"; throw pdal_error(oss.str()); } log()->get(LogLevel::Debug) << " got pcid = " << pcid << std::endl; m_pcid = pcid; return pcid; }