*/
bool client_proto(SBuf *sbuf, SBufEvent evtype, struct MBuf *pkt) _MUSTCHECK;
-bool set_pool(PgSocket *client, const char *dbname, const char *username, bool takeover) _MUSTCHECK;
+bool set_pool(PgSocket *client, const char *dbname, const char *username, const char *password, bool takeover) _MUSTCHECK;
bool handle_auth_response(PgSocket *client, PktHdr *pkt);
void launch_new_connection(PgPool *pool);
bool use_client_socket(int fd, PgAddr *addr, const char *dbname, const char *username, uint64_t ckey, int oldfd, int linkfd,
- const char *client_end, const char *std_string, const char *datestyle, const char *timezone)
+ const char *client_end, const char *std_string, const char *datestyle, const char *timezone,
+ const char *password)
_MUSTCHECK;
bool use_server_socket(int fd, PgAddr *addr, const char *dbname, const char *username, uint64_t ckey, int oldfd, int linkfd,
- const char *client_end, const char *std_string, const char *datestyle, const char *timezone)
+ const char *client_end, const char *std_string, const char *datestyle, const char *timezone,
+ const char *password)
_MUSTCHECK;
void activate_client(PgSocket *client);
const char *client_enc,
const char *std_strings,
const char *datestyle,
- const char *timezone)
+ const char *timezone,
+ const char *password)
{
struct msghdr msg;
struct cmsghdr *cmsg;
struct PktBuf *pkt = pktbuf_temp();
- pktbuf_write_DataRow(pkt, "issssiqissss",
+ pktbuf_write_DataRow(pkt, "issssiqisssss",
fd, task, user, db, addr, port, ckey, link,
- client_enc, std_strings, datestyle, timezone);
+ client_enc, std_strings, datestyle, timezone,
+ password);
if (pkt->failed)
return false;
iovec.iov_base = pkt->buf;
const struct PStr *datestyle = v->var_list[VDateStyle];
const struct PStr *timezone = v->var_list[VTimeZone];
char addrbuf[PGADDR_BUF];
+ const char *password = NULL;
mbuf_init_fixed_reader(&tmp, sk->cancel_key, 8);
if (!mbuf_get_uint64be(&tmp, &ckey))
return false;
+ if (sk->pool->db->auth_user && sk->auth_user && !find_user(sk->auth_user->name))
+ password = sk->auth_user->passwd;
return send_one_fd(admin, sbuf_socket(&sk->sbuf),
is_server_socket(sk) ? "server" : "client",
client_encoding ? client_encoding->str : NULL,
std_strings ? std_strings->str : NULL,
datestyle ? datestyle->str : NULL,
- timezone ? timezone->str : NULL);
+ timezone ? timezone->str : NULL,
+ password);
}
static bool show_pooler_cb(void *arg, int fd, const PgAddr *a)
return send_one_fd(arg, fd, "pooler", NULL, NULL,
pga_ntop(a, buf, sizeof(buf)), pga_port(a), 0, 0,
- NULL, NULL, NULL, NULL);
+ NULL, NULL, NULL, NULL, NULL);
}
/* send a row with sendmsg, optionally attaching a fd */
* Dangerous to show to everybody:
* - can lock pooler as code flips async option
* - show cancel keys for all users
+ * - shows passwords (md5) for dynamic users
*/
if (!admin->admin_user)
return admin_error(admin, "admin access needed");
/*
* send resultset
*/
- SEND_RowDescription(res, admin, "issssiqissss",
+ SEND_RowDescription(res, admin, "issssiqisssss",
"fd", "task",
"user", "database",
"addr", "port",
"cancel", "link",
"client_encoding", "std_strings",
- "datestyle", "timezone");
+ "datestyle", "timezone", "password");
if (res)
res = show_pooler_fds(admin);
return true;
}
-bool set_pool(PgSocket *client, const char *dbname, const char *username, bool takeover)
+bool set_pool(PgSocket *client, const char *dbname, const char *username, const char *password, bool takeover)
{
/* find database */
client->db = find_database(dbname);
client->auth_user = find_user(username);
if (!client->auth_user && client->db->auth_user) {
if (takeover) {
- client->auth_user = add_db_user(client->db, username, "");
+ client->auth_user = add_db_user(client->db, username, password);
return finish_set_pool(client, takeover);
}
start_auth_request(client, username);
}
/* find pool */
- return set_pool(client, dbname, username, false);
+ return set_pool(client, dbname, username, "", false);
}
/* decide on packets of client in login phase */
const char *dbname, const char *username,
uint64_t ckey, int oldfd, int linkfd,
const char *client_enc, const char *std_string,
- const char *datestyle, const char *timezone)
+ const char *datestyle, const char *timezone,
+ const char *password)
{
PgSocket *client;
PktBuf tmp;
return false;
client->suspended = 1;
- if (!set_pool(client, dbname, username, true))
+ if (!set_pool(client, dbname, username, password, true))
return false;
change_client_state(client, CL_ACTIVE);
const char *dbname, const char *username,
uint64_t ckey, int oldfd, int linkfd,
const char *client_enc, const char *std_string,
- const char *datestyle, const char *timezone)
+ const char *datestyle, const char *timezone,
+ const char *password)
{
PgDatabase *db = find_database(dbname);
PgUser *user;
else
user = find_user(username);
if (!user && db->auth_user)
- user = add_db_user(db, username, "");
+ user = add_db_user(db, username, password);
pool = get_pool(db, user);
if (!pool)
{
int fd;
char *task, *saddr, *user, *db;
- char *client_enc, *std_string, *datestyle, *timezone;
+ char *client_enc, *std_string, *datestyle, *timezone, *password;
int oldfd, port, linkfd;
int got;
uint64_t ckey;
fatal("broken fd packet");
/* parse row contents */
- got = scan_text_result(pkt, "issssiqissss", &oldfd, &task, &user, &db,
+ got = scan_text_result(pkt, "issssiqisssss", &oldfd, &task, &user, &db,
&saddr, &port, &ckey, &linkfd,
- &client_enc, &std_string, &datestyle, &timezone);
+ &client_enc, &std_string, &datestyle, &timezone,
+ &password);
if (got < 0 || task == NULL || saddr == NULL)
fatal("NULL data from old process");
user ? user : "NULL", db ? db : "NULL",
client_enc ? client_enc : "NULL");
+ if (!password)
+ password = "";
+
/* fill address */
if (strcmp(saddr, "unix") == 0) {
pga_set(&addr, AF_UNIX, cf_listen_port);
/* decide what to do with it */
if (strcmp(task, "client") == 0)
res = use_client_socket(fd, &addr, db, user, ckey, oldfd, linkfd,
- client_enc, std_string, datestyle, timezone);
+ client_enc, std_string, datestyle, timezone,
+ password);
else if (strcmp(task, "server") == 0)
res = use_server_socket(fd, &addr, db, user, ckey, oldfd, linkfd,
- client_enc, std_string, datestyle, timezone);
+ client_enc, std_string, datestyle, timezone,
+ password);
else if (strcmp(task, "pooler") == 0)
res = use_pooler_socket(fd, pga_is_unix(&addr));
else