mirror of
https://github.com/postgres/postgres.git
synced 2025-05-02 11:44:50 +03:00
Get rid of another unconstify through API changes
This also makes the code in read_client_first_message() more similar to read_client_final_message(). Reported-by: Mark Dilger <hornschnorter@gmail.com> Discussion: https://www.postgresql.org/message-id/flat/53a28052-f9f3-1808-fed9-460fd43035ab%402ndquadrant.com
This commit is contained in:
parent
4b3b07fd5d
commit
86eea78694
@ -155,8 +155,8 @@ typedef struct
|
|||||||
char *logdetail;
|
char *logdetail;
|
||||||
} scram_state;
|
} scram_state;
|
||||||
|
|
||||||
static void read_client_first_message(scram_state *state, char *input);
|
static void read_client_first_message(scram_state *state, const char *input);
|
||||||
static void read_client_final_message(scram_state *state, char *input);
|
static void read_client_final_message(scram_state *state, const char *input);
|
||||||
static char *build_server_first_message(scram_state *state);
|
static char *build_server_first_message(scram_state *state);
|
||||||
static char *build_server_final_message(scram_state *state);
|
static char *build_server_final_message(scram_state *state);
|
||||||
static bool verify_client_proof(scram_state *state);
|
static bool verify_client_proof(scram_state *state);
|
||||||
@ -327,7 +327,7 @@ pg_be_scram_init(Port *port,
|
|||||||
* the client).
|
* the client).
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
pg_be_scram_exchange(void *opaq, char *input, int inputlen,
|
pg_be_scram_exchange(void *opaq, const char *input, int inputlen,
|
||||||
char **output, int *outputlen, char **logdetail)
|
char **output, int *outputlen, char **logdetail)
|
||||||
{
|
{
|
||||||
scram_state *state = (scram_state *) opaq;
|
scram_state *state = (scram_state *) opaq;
|
||||||
@ -811,11 +811,11 @@ read_any_attr(char **input, char *attr_p)
|
|||||||
* At this stage, any errors will be reported directly with ereport(ERROR).
|
* At this stage, any errors will be reported directly with ereport(ERROR).
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
read_client_first_message(scram_state *state, char *input)
|
read_client_first_message(scram_state *state, const char *input)
|
||||||
{
|
{
|
||||||
|
char *p = pstrdup(input);
|
||||||
char *channel_binding_type;
|
char *channel_binding_type;
|
||||||
|
|
||||||
input = pstrdup(input);
|
|
||||||
|
|
||||||
/*------
|
/*------
|
||||||
* The syntax for the client-first-message is: (RFC 5802)
|
* The syntax for the client-first-message is: (RFC 5802)
|
||||||
@ -881,8 +881,8 @@ read_client_first_message(scram_state *state, char *input)
|
|||||||
* Read gs2-cbind-flag. (For details see also RFC 5802 Section 6 "Channel
|
* Read gs2-cbind-flag. (For details see also RFC 5802 Section 6 "Channel
|
||||||
* Binding".)
|
* Binding".)
|
||||||
*/
|
*/
|
||||||
state->cbind_flag = *input;
|
state->cbind_flag = *p;
|
||||||
switch (*input)
|
switch (*p)
|
||||||
{
|
{
|
||||||
case 'n':
|
case 'n':
|
||||||
|
|
||||||
@ -896,14 +896,14 @@ read_client_first_message(scram_state *state, char *input)
|
|||||||
errmsg("malformed SCRAM message"),
|
errmsg("malformed SCRAM message"),
|
||||||
errdetail("The client selected SCRAM-SHA-256-PLUS, but the SCRAM message does not include channel binding data.")));
|
errdetail("The client selected SCRAM-SHA-256-PLUS, but the SCRAM message does not include channel binding data.")));
|
||||||
|
|
||||||
input++;
|
p++;
|
||||||
if (*input != ',')
|
if (*p != ',')
|
||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
(errcode(ERRCODE_PROTOCOL_VIOLATION),
|
(errcode(ERRCODE_PROTOCOL_VIOLATION),
|
||||||
errmsg("malformed SCRAM message"),
|
errmsg("malformed SCRAM message"),
|
||||||
errdetail("Comma expected, but found character \"%s\".",
|
errdetail("Comma expected, but found character \"%s\".",
|
||||||
sanitize_char(*input))));
|
sanitize_char(*p))));
|
||||||
input++;
|
p++;
|
||||||
break;
|
break;
|
||||||
case 'y':
|
case 'y':
|
||||||
|
|
||||||
@ -926,14 +926,14 @@ read_client_first_message(scram_state *state, char *input)
|
|||||||
errdetail("The client supports SCRAM channel binding but thinks the server does not. "
|
errdetail("The client supports SCRAM channel binding but thinks the server does not. "
|
||||||
"However, this server does support channel binding.")));
|
"However, this server does support channel binding.")));
|
||||||
#endif
|
#endif
|
||||||
input++;
|
p++;
|
||||||
if (*input != ',')
|
if (*p != ',')
|
||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
(errcode(ERRCODE_PROTOCOL_VIOLATION),
|
(errcode(ERRCODE_PROTOCOL_VIOLATION),
|
||||||
errmsg("malformed SCRAM message"),
|
errmsg("malformed SCRAM message"),
|
||||||
errdetail("Comma expected, but found character \"%s\".",
|
errdetail("Comma expected, but found character \"%s\".",
|
||||||
sanitize_char(*input))));
|
sanitize_char(*p))));
|
||||||
input++;
|
p++;
|
||||||
break;
|
break;
|
||||||
case 'p':
|
case 'p':
|
||||||
|
|
||||||
@ -947,7 +947,7 @@ read_client_first_message(scram_state *state, char *input)
|
|||||||
errmsg("malformed SCRAM message"),
|
errmsg("malformed SCRAM message"),
|
||||||
errdetail("The client selected SCRAM-SHA-256 without channel binding, but the SCRAM message includes channel binding data.")));
|
errdetail("The client selected SCRAM-SHA-256 without channel binding, but the SCRAM message includes channel binding data.")));
|
||||||
|
|
||||||
channel_binding_type = read_attr_value(&input, 'p');
|
channel_binding_type = read_attr_value(&p, 'p');
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* The only channel binding type we support is
|
* The only channel binding type we support is
|
||||||
@ -964,25 +964,25 @@ read_client_first_message(scram_state *state, char *input)
|
|||||||
(errcode(ERRCODE_PROTOCOL_VIOLATION),
|
(errcode(ERRCODE_PROTOCOL_VIOLATION),
|
||||||
errmsg("malformed SCRAM message"),
|
errmsg("malformed SCRAM message"),
|
||||||
errdetail("Unexpected channel-binding flag \"%s\".",
|
errdetail("Unexpected channel-binding flag \"%s\".",
|
||||||
sanitize_char(*input))));
|
sanitize_char(*p))));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Forbid optional authzid (authorization identity). We don't support it.
|
* Forbid optional authzid (authorization identity). We don't support it.
|
||||||
*/
|
*/
|
||||||
if (*input == 'a')
|
if (*p == 'a')
|
||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||||
errmsg("client uses authorization identity, but it is not supported")));
|
errmsg("client uses authorization identity, but it is not supported")));
|
||||||
if (*input != ',')
|
if (*p != ',')
|
||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
(errcode(ERRCODE_PROTOCOL_VIOLATION),
|
(errcode(ERRCODE_PROTOCOL_VIOLATION),
|
||||||
errmsg("malformed SCRAM message"),
|
errmsg("malformed SCRAM message"),
|
||||||
errdetail("Unexpected attribute \"%s\" in client-first-message.",
|
errdetail("Unexpected attribute \"%s\" in client-first-message.",
|
||||||
sanitize_char(*input))));
|
sanitize_char(*p))));
|
||||||
input++;
|
p++;
|
||||||
|
|
||||||
state->client_first_message_bare = pstrdup(input);
|
state->client_first_message_bare = pstrdup(p);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Any mandatory extensions would go here. We don't support any.
|
* Any mandatory extensions would go here. We don't support any.
|
||||||
@ -991,7 +991,7 @@ read_client_first_message(scram_state *state, char *input)
|
|||||||
* but it can only be sent in the server-final message. We prefer to fail
|
* but it can only be sent in the server-final message. We prefer to fail
|
||||||
* immediately (which the RFC also allows).
|
* immediately (which the RFC also allows).
|
||||||
*/
|
*/
|
||||||
if (*input == 'm')
|
if (*p == 'm')
|
||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||||
errmsg("client requires an unsupported SCRAM extension")));
|
errmsg("client requires an unsupported SCRAM extension")));
|
||||||
@ -1001,10 +1001,10 @@ read_client_first_message(scram_state *state, char *input)
|
|||||||
* startup message instead, still it is kept around if provided as it
|
* startup message instead, still it is kept around if provided as it
|
||||||
* proves to be useful for debugging purposes.
|
* proves to be useful for debugging purposes.
|
||||||
*/
|
*/
|
||||||
state->client_username = read_attr_value(&input, 'n');
|
state->client_username = read_attr_value(&p, 'n');
|
||||||
|
|
||||||
/* read nonce and check that it is made of only printable characters */
|
/* read nonce and check that it is made of only printable characters */
|
||||||
state->client_nonce = read_attr_value(&input, 'r');
|
state->client_nonce = read_attr_value(&p, 'r');
|
||||||
if (!is_scram_printable(state->client_nonce))
|
if (!is_scram_printable(state->client_nonce))
|
||||||
ereport(ERROR,
|
ereport(ERROR,
|
||||||
(errcode(ERRCODE_PROTOCOL_VIOLATION),
|
(errcode(ERRCODE_PROTOCOL_VIOLATION),
|
||||||
@ -1014,8 +1014,8 @@ read_client_first_message(scram_state *state, char *input)
|
|||||||
* There can be any number of optional extensions after this. We don't
|
* There can be any number of optional extensions after this. We don't
|
||||||
* support any extensions, so ignore them.
|
* support any extensions, so ignore them.
|
||||||
*/
|
*/
|
||||||
while (*input != '\0')
|
while (*p != '\0')
|
||||||
read_any_attr(&input, NULL);
|
read_any_attr(&p, NULL);
|
||||||
|
|
||||||
/* success! */
|
/* success! */
|
||||||
}
|
}
|
||||||
@ -1144,7 +1144,7 @@ build_server_first_message(scram_state *state)
|
|||||||
* Read and parse the final message received from client.
|
* Read and parse the final message received from client.
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
read_client_final_message(scram_state *state, char *input)
|
read_client_final_message(scram_state *state, const char *input)
|
||||||
{
|
{
|
||||||
char attr;
|
char attr;
|
||||||
char *channel_binding;
|
char *channel_binding;
|
||||||
|
@ -985,7 +985,7 @@ CheckSCRAMAuth(Port *port, char *shadow_pass, char **logdetail)
|
|||||||
* we pass 'logdetail' as NULL when doing a mock authentication,
|
* we pass 'logdetail' as NULL when doing a mock authentication,
|
||||||
* because we should already have a better error message in that case
|
* because we should already have a better error message in that case
|
||||||
*/
|
*/
|
||||||
result = pg_be_scram_exchange(scram_opaq, unconstify(char *, input), inputlen,
|
result = pg_be_scram_exchange(scram_opaq, input, inputlen,
|
||||||
&output, &outputlen,
|
&output, &outputlen,
|
||||||
logdetail);
|
logdetail);
|
||||||
|
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
/* Routines dedicated to authentication */
|
/* Routines dedicated to authentication */
|
||||||
extern void pg_be_scram_get_mechanisms(Port *port, StringInfo buf);
|
extern void pg_be_scram_get_mechanisms(Port *port, StringInfo buf);
|
||||||
extern void *pg_be_scram_init(Port *port, const char *selected_mech, const char *shadow_pass);
|
extern void *pg_be_scram_init(Port *port, const char *selected_mech, const char *shadow_pass);
|
||||||
extern int pg_be_scram_exchange(void *opaq, char *input, int inputlen,
|
extern int pg_be_scram_exchange(void *opaq, const char *input, int inputlen,
|
||||||
char **output, int *outputlen, char **logdetail);
|
char **output, int *outputlen, char **logdetail);
|
||||||
|
|
||||||
/* Routines to handle and check SCRAM-SHA-256 verifier */
|
/* Routines to handle and check SCRAM-SHA-256 verifier */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user