Skip to content

Commit b6d7ef6

Browse files
committed
Fix issues with scram authorization
1 parent bb8222f commit b6d7ef6

File tree

3 files changed

+31
-15
lines changed

3 files changed

+31
-15
lines changed

contrib/mmts/multimaster.c

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1111,38 +1111,31 @@ MtmPostPrepareTransaction(MtmCurrentTrans* x)
11111111
MtmLock(LW_EXCLUSIVE);
11121112
ts = (MtmTransState*)hash_search(MtmXid2State, &x->xid, HASH_FIND, NULL);
11131113
Assert(ts != NULL);
1114-
//if (x->gid[0]) MTM_LOG1("Preparing transaction %d (%s) at %ld", x->xid, x->gid, MtmGetCurrentTime());
11151114
if (!MtmIsCoordinator(ts) || Mtm->status == MTM_RECOVERY) {
1116-
MTM_TXTRACE(x, "recovery?");
11171115
MTM_LOG3("Preparing transaction %d (%s) at %ld", x->xid, x->gid, MtmGetCurrentTime());
11181116
Assert(x->gid[0]);
11191117
ts->votingCompleted = true;
1120-
MTM_TXTRACE(x, "recovery? 1");
11211118
if (Mtm->status != MTM_RECOVERY/* || Mtm->recoverySlot != MtmReplicationNodeId*/) {
1122-
MTM_TXTRACE(x, "recovery? 2");
11231119
MtmSend2PCMessage(ts, MSG_PREPARED); /* send notification to coordinator */
11241120
if (!MtmUseDtm) {
11251121
ts->status = TRANSACTION_STATUS_UNKNOWN;
11261122
}
11271123
} else {
1128-
MTM_TXTRACE(x, "recovery? 3");
11291124
ts->status = TRANSACTION_STATUS_UNKNOWN;
11301125
}
1131-
MTM_TXTRACE(x, "recovery? 4");
11321126
MtmUnlock();
1133-
MTM_TXTRACE(x, "recovery? 5");
11341127
MtmResetTransaction();
1135-
MTM_TXTRACE(x, "recovery? 6");
1136-
} else if (!ts->isLocal) {
1137-
MTM_TXTRACE(x, "not recovery?");
1138-
Mtm2PCVoting(x, ts);
1128+
} else {
1129+
if (!ts->isLocal) {
1130+
Mtm2PCVoting(x, ts);
1131+
} else {
1132+
ts->votingCompleted = true;
1133+
}
11391134
MtmUnlock();
11401135
if (x->isTwoPhase) {
11411136
MtmResetTransaction();
11421137
}
11431138
}
1144-
MTM_TXTRACE(x, "recovery? 7");
1145-
//if (x->gid[0]) MTM_LOG1("Prepared transaction %d (%s) csn=%ld at %ld: %d", x->xid, x->gid, ts->csn, MtmGetCurrentTime(), ts->status);
11461139
if (Mtm->inject2PCError == 3) {
11471140
Mtm->inject2PCError = 0;
11481141
elog(ERROR, "ERROR INJECTION for transaction %s (%lu)", x->gid, (long)x->xid);
@@ -1182,6 +1175,8 @@ MtmPreCommitPreparedTransaction(MtmCurrentTrans* x)
11821175
MtmLock(LW_EXCLUSIVE);
11831176

11841177
Mtm2PCVoting(x, ts);
1178+
} else {
1179+
ts->status = TRANSACTION_STATUS_UNKNOWN;
11851180
}
11861181

11871182
x->xid = ts->xid;

contrib/mmts/tests2/support/docker-regress.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ psql -U postgres regression <<-SQL
1111
SQL
1212

1313
./pg_regress --use-existing \
14-
--schedule=parallel_schedule \
14+
--schedule=serial_schedule \
1515
--host=node1 \
1616
--user=postgres
1717

src/backend/libpq/auth-scram.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -968,5 +968,26 @@ generate_nonce(char *result, int len)
968968
{
969969
/* Use the salt generated for SASL authentication */
970970
memset(result, 0, len);
971-
memcpy(result, MyProcPort->SASLSalt, Min(sizeof(MyProcPort->SASLSalt), len));
971+
if (MyProcPort == NULL) {
972+
int count;
973+
/* compute the salt to use for computing responses */
974+
while (count < sizeof(MyProcPort->SASLSalt) && count < len)
975+
{
976+
char byte;
977+
if (!pg_strong_random(&byte, 1))
978+
{
979+
elog(ERROR, "Could not generate random salt");
980+
}
981+
/*
982+
* Only ASCII printable characters, except commas are accepted in
983+
* the nonce.
984+
*/
985+
if (byte < '!' || byte > '~' || byte == ',')
986+
continue;
987+
988+
result[count++] = byte;
989+
}
990+
} else {
991+
memcpy(result, MyProcPort->SASLSalt, Min(sizeof(MyProcPort->SASLSalt), len));
992+
}
972993
}

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy