Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit58445c5

Browse files
committed
Further cleanup from the strong-random patch.
Also use the new facility for generating RADIUS authenticator requests,and salt in chkpass extension.Reword the error messages to be nicer. Fix bogus error code used in themessage in BackendStartup.
1 parent9bbbf02 commit58445c5

File tree

3 files changed

+13
-17
lines changed

3 files changed

+13
-17
lines changed

‎contrib/chkpass/chkpass.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#endif
1818

1919
#include"fmgr.h"
20+
#include"utils/backend_random.h"
2021
#include"utils/builtins.h"
2122

2223
PG_MODULE_MAGIC;
@@ -77,8 +78,12 @@ chkpass_in(PG_FUNCTION_ARGS)
7778

7879
result= (chkpass*)palloc0(sizeof(chkpass));
7980

80-
mysalt[0]=salt_chars[random()&0x3f];
81-
mysalt[1]=salt_chars[random()&0x3f];
81+
if (!pg_backend_random(mysalt,2))
82+
ereport(ERROR,
83+
(errmsg("could not generate random salt")));
84+
85+
mysalt[0]=salt_chars[mysalt[0]&0x3f];
86+
mysalt[1]=salt_chars[mysalt[1]&0x3f];
8287
mysalt[2]=0;/* technically the terminator is not necessary
8388
* but I like to play safe */
8489

‎src/backend/libpq/auth.c

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -194,9 +194,6 @@ static int pg_SSPI_make_upn(char *accountname,
194194
* RADIUS Authentication
195195
*----------------------------------------------------------------
196196
*/
197-
#ifdefUSE_OPENSSL
198-
#include<openssl/rand.h>
199-
#endif
200197
staticintCheckRADIUSAuth(Port*port);
201198

202199

@@ -718,7 +715,7 @@ CheckMD5Auth(Port *port, char **logdetail)
718715
if (!pg_backend_random(md5Salt,4))
719716
{
720717
ereport(LOG,
721-
(errmsg("could notacquire random number for MD5 salt.")));
718+
(errmsg("could notgenerate random MD5 salt.")));
722719
returnSTATUS_ERROR;
723720
}
724721

@@ -2550,18 +2547,12 @@ CheckRADIUSAuth(Port *port)
25502547
/* Construct RADIUS packet */
25512548
packet->code=RADIUS_ACCESS_REQUEST;
25522549
packet->length=RADIUS_HEADER_LENGTH;
2553-
#ifdefUSE_OPENSSL
2554-
if (RAND_bytes(packet->vector,RADIUS_VECTOR_LENGTH)!=1)
2550+
if (!pg_backend_random((char*)packet->vector,RADIUS_VECTOR_LENGTH))
25552551
{
25562552
ereport(LOG,
25572553
(errmsg("could not generate random encryption vector")));
25582554
returnSTATUS_ERROR;
25592555
}
2560-
#else
2561-
for (i=0;i<RADIUS_VECTOR_LENGTH;i++)
2562-
/* Use a lower strengh random number of OpenSSL is not available */
2563-
packet->vector[i]=random() %255;
2564-
#endif
25652556
packet->id=packet->vector[0];
25662557
radius_add_attribute(packet,RADIUS_SERVICE_TYPE, (unsignedchar*)&service,sizeof(service));
25672558
radius_add_attribute(packet,RADIUS_USER_NAME, (unsignedchar*)port->user_name,strlen(port->user_name));

‎src/backend/postmaster/postmaster.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3903,8 +3903,8 @@ BackendStartup(Port *port)
39033903
{
39043904
free(bn);
39053905
ereport(LOG,
3906-
(errcode(ERRCODE_OUT_OF_MEMORY),
3907-
errmsg("could notacquire randomnumber")));
3906+
(errcode(ERRCODE_INTERNAL_ERROR),
3907+
errmsg("could notgenerate randomcancel key")));
39083908
returnSTATUS_ERROR;
39093909
}
39103910

@@ -5288,7 +5288,7 @@ StartAutovacuumWorker(void)
52885288
{
52895289
ereport(LOG,
52905290
(errcode(ERRCODE_INTERNAL_ERROR),
5291-
errmsg("could notacquire randomnumber")));
5291+
errmsg("could notgenerate randomcancel key")));
52925292
return;
52935293
}
52945294

@@ -5594,7 +5594,7 @@ assign_backendlist_entry(RegisteredBgWorker *rw)
55945594
{
55955595
ereport(LOG,
55965596
(errcode(ERRCODE_INTERNAL_ERROR),
5597-
errmsg("could notacquire randomnumber")));
5597+
errmsg("could notgenerate randomcancel key")));
55985598

55995599
rw->rw_crashed_at=GetCurrentTimestamp();
56005600
return false;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp