Refactor RandomSalt to handle salts of different lengths.
All we need is 4 bytes at the moment, for MD5 authentication. But in upcomint patches for SCRAM authentication, SCRAM will need a salt of different length. It's less scary for the caller to pass the buffer length anyway, than assume a certain-sized output buffer. Author: Michael Paquier Discussion: <CAB7nPqQvO4sxLFeS9D+NM3wpy08ieZdAj_6e117MQHZAfxBFsg@mail.gmail.com>
This commit is contained in:
parent
a79a685622
commit
fa878703f4
@ -404,7 +404,7 @@ static int initMasks(fd_set *rmask);
|
|||||||
static void report_fork_failure_to_client(Port *port, int errnum);
|
static void report_fork_failure_to_client(Port *port, int errnum);
|
||||||
static CAC_state canAcceptConnections(void);
|
static CAC_state canAcceptConnections(void);
|
||||||
static long PostmasterRandom(void);
|
static long PostmasterRandom(void);
|
||||||
static void RandomSalt(char *md5Salt);
|
static void RandomSalt(char *salt, int len);
|
||||||
static void signal_child(pid_t pid, int signal);
|
static void signal_child(pid_t pid, int signal);
|
||||||
static bool SignalSomeChildren(int signal, int targets);
|
static bool SignalSomeChildren(int signal, int targets);
|
||||||
static void TerminateChildren(int signal);
|
static void TerminateChildren(int signal);
|
||||||
@ -2342,7 +2342,7 @@ ConnCreate(int serverFd)
|
|||||||
* after. Else the postmaster's random sequence won't get advanced, and
|
* after. Else the postmaster's random sequence won't get advanced, and
|
||||||
* all backends would end up using the same salt...
|
* all backends would end up using the same salt...
|
||||||
*/
|
*/
|
||||||
RandomSalt(port->md5Salt);
|
RandomSalt(port->md5Salt, sizeof(port->md5Salt));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Allocate GSSAPI specific state struct
|
* Allocate GSSAPI specific state struct
|
||||||
@ -5083,23 +5083,21 @@ StartupPacketTimeoutHandler(void)
|
|||||||
* RandomSalt
|
* RandomSalt
|
||||||
*/
|
*/
|
||||||
static void
|
static void
|
||||||
RandomSalt(char *md5Salt)
|
RandomSalt(char *salt, int len)
|
||||||
{
|
{
|
||||||
long rand;
|
long rand;
|
||||||
|
int i;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* We use % 255, sacrificing one possible byte value, so as to ensure that
|
* We use % 255, sacrificing one possible byte value, so as to ensure that
|
||||||
* all bits of the random() value participate in the result. While at it,
|
* all bits of the random() value participate in the result. While at it,
|
||||||
* add one to avoid generating any null bytes.
|
* add one to avoid generating any null bytes.
|
||||||
*/
|
*/
|
||||||
rand = PostmasterRandom();
|
for (i = 0; i < len; i++)
|
||||||
md5Salt[0] = (rand % 255) + 1;
|
{
|
||||||
rand = PostmasterRandom();
|
rand = PostmasterRandom();
|
||||||
md5Salt[1] = (rand % 255) + 1;
|
salt[i] = (rand % 255) + 1;
|
||||||
rand = PostmasterRandom();
|
}
|
||||||
md5Salt[2] = (rand % 255) + 1;
|
|
||||||
rand = PostmasterRandom();
|
|
||||||
md5Salt[3] = (rand % 255) + 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
x
Reference in New Issue
Block a user