Skip to content

Commit

Permalink
Fix for auth query when user password is empty
Browse files Browse the repository at this point in the history
  • Loading branch information
reshke committed Dec 5, 2021
1 parent 01f3c03 commit 8967555
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 6 deletions.
2 changes: 1 addition & 1 deletion Makefile
Expand Up @@ -8,7 +8,7 @@ CMAKE_BIN:=cmake

SKIP_CLEANUP_DOCKER:=

CMAKE_FLAGS:=-DCC_FLAGS="-Wextra -Wstrict-aliasing" -DUSE_SCRAM=NO
CMAKE_FLAGS:=-DCC_FLAGS="-Wextra -Wstrict-aliasing" -DUSE_SCRAM=YES
BUILD_TYPE=Release

COMPILE_CONCURRENCY=8
Expand Down
30 changes: 30 additions & 0 deletions config-examples/odyssey-dev-no-ldap.conf
Expand Up @@ -88,6 +88,36 @@ database default {
}

database "postgres" {
user "user_aq" {
authentication "scram-sha-256"
# password "passwd"
auth_query "SELECT usename, passwd FROM pg_shadow WHERE usename=$1"
auth_query_user "reshke"
auth_query_db "postgres"

storage "postgres_server"
# storage_password "1"
pool "session"
pool_size 1

pool_timeout 0

pool_ttl 60

pool_discard no

pool_cancel yes

pool_rollback yes

client_fwd_error yes

application_name_add_host yes
server_lifetime 3600
log_debug no
quantiles "0.99,0.95,0.5"
client_max 107
}
user "user1" {
authentication "clear_text"
password "passwd"
Expand Down
6 changes: 3 additions & 3 deletions documentation/configuration.md
Expand Up @@ -444,7 +444,7 @@ auth_common_name "test"
Enable remote route authentication. Use some other route to authenticate clients
following this logic:

Use selected 'auth\_query_db' and 'auth\_query\_user' to match a route.
Use selected 'auth\_query\_db' and 'auth\_query\_user' to match a route.
Use matched route server to send 'auth\_query' to get username and password needed
to authenticate a client.

Expand Down Expand Up @@ -482,8 +482,8 @@ Set remote server to use.

By default route database and user names are used as connection
parameters to remote server. It is possible to override this values
by specifying 'storage_db' and 'storage_user'. Remote server password
can be set using 'storage_password' field.
by specifying 'storage\_db' and 'storage\_user'. Remote server password
can be set using 'storage\_password' field.

```
storage "postgres_server"
Expand Down
2 changes: 2 additions & 0 deletions sources/auth.c
Expand Up @@ -125,6 +125,8 @@ static inline int od_auth_frontend_cleartext(od_client_t *client)
if (client->rule->auth_query) {
char peer[128];
od_getpeername(client->io.io, peer, sizeof(peer), 1, 0);
od_debug(&instance->logger, "auth", client, NULL,
"running auth_query for peer %s", peer);
rc = od_auth_query(client, peer);
if (rc == -1) {
od_error(&instance->logger, "auth", client, NULL,
Expand Down
18 changes: 17 additions & 1 deletion sources/auth_query.c
Expand Up @@ -73,6 +73,7 @@ static inline int od_auth_query_do(od_server_t *server, char *query,
/* count */
uint16_t count;
rc = kiwi_read16(&count, &pos, &pos_size);

if (kiwi_unlikely(rc == -1))
goto error;
if (count != 2)
Expand All @@ -81,8 +82,9 @@ static inline int od_auth_query_do(od_server_t *server, char *query,
/* user (not used) */
uint32_t user_len;
rc = kiwi_read32(&user_len, &pos, &pos_size);
if (kiwi_unlikely(rc == -1))
if (kiwi_unlikely(rc == -1)) {
goto error;
}
char *user = pos;
rc = kiwi_readn(user_len, &pos, &pos_size);
if (kiwi_unlikely(rc == -1))
Expand All @@ -93,12 +95,26 @@ static inline int od_auth_query_do(od_server_t *server, char *query,
/* password */
uint32_t password_len;
rc = kiwi_read32(&password_len, &pos, &pos_size);

if (password_len == -1) {
result->password = NULL;
result->password_len = password_len + 1;

od_debug(
&instance->logger, "auth_query",
server->client, server,
"auth_query returned empty password for user : %s",
user, result->password);
has_result = 1;
break;
}
if (password_len >
ODYSSEY_AUTH_QUERY_MAX_PASSSWORD_LEN) {
goto error;
}
if (kiwi_unlikely(rc == -1))
goto error;

char *password = pos;
rc = kiwi_readn(password_len, &pos, &pos_size);
if (kiwi_unlikely(rc == -1))
Expand Down
2 changes: 1 addition & 1 deletion sources/scram.h
@@ -1,7 +1,7 @@
#ifndef ODYSSEY_SCRAM_H
#define ODYSSEY_SCRAM_H

#if PG_VERSION_NUM >= 120000
#if PG_VERSION_NUM >= 130000
#define od_b64_encode(src, src_len, dst, dst_len) \
pg_b64_encode(src, src_len, dst, dst_len);
#define od_b64_decode(src, src_len, dst, dst_len) \
Expand Down

0 comments on commit 8967555

Please sign in to comment.