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

Commit6daf396

Browse files
committed
Add thread locking to SSL and Kerberos connections.
I have removed the docs mentioning that SSL and Kerberos are notthread-safe.Manfred Spraul
1 parentfcfa2c7 commit6daf396

File tree

7 files changed

+222
-46
lines changed

7 files changed

+222
-46
lines changed

‎doc/src/sgml/libpq.sgml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!--
2-
$PostgreSQL: pgsql/doc/src/sgml/libpq.sgml,v 1.149 2004/03/23 23:37:17 tgl Exp $
2+
$PostgreSQL: pgsql/doc/src/sgml/libpq.sgml,v 1.150 2004/03/24 03:44:58 momjian Exp $
33
-->
44

55
<chapter id="libpq">
@@ -3654,8 +3654,7 @@ call <function>fe_setauthsvc</function> at all.
36543654
<literal>crypt()</literal> operating system function, which is often
36553655
not thread-safe.<indexterm><primary>crypt</><secondary>thread
36563656
safety</></> It is better to use the <literal>md5</literal> method,
3657-
which is thread-safe on all platforms. <application>SSL</> connections
3658-
and <application>kerberos</> authentication are also not thread-safe.
3657+
which is thread-safe on all platforms.
36593658
</para>
36603659

36613660
<para>

‎src/backend/libpq/md5.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
*Portions Copyright (c) 1994, Regents of the University of California
1515
*
1616
* IDENTIFICATION
17-
* $PostgreSQL: pgsql/src/backend/libpq/md5.c,v 1.22 2003/11/29 19:51:49 pgsql Exp $
17+
* $PostgreSQL: pgsql/src/backend/libpq/md5.c,v 1.23 2004/03/24 03:44:58 momjian Exp $
1818
*/
1919

2020

@@ -271,7 +271,7 @@ calculateDigestFromBuffer(uint8 *b, uint32 len, uint8 sum[16])
271271
staticvoid
272272
bytesToHex(uint8b[16],char*s)
273273
{
274-
staticchar*hex="0123456789abcdef";
274+
staticconstchar*hex="0123456789abcdef";
275275
intq,
276276
w;
277277

‎src/interfaces/libpq/fe-auth.c

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* exceed INITIAL_EXPBUFFER_SIZE (currently 256 bytes).
1111
*
1212
* IDENTIFICATION
13-
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-auth.c,v 1.89 2004/01/07 18:56:29 neilc Exp $
13+
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-auth.c,v 1.90 2004/03/24 03:44:59 momjian Exp $
1414
*
1515
*-------------------------------------------------------------------------
1616
*/
@@ -590,15 +590,18 @@ fe_sendauth(AuthRequest areq, PGconn *conn, const char *hostname,
590590

591591
caseAUTH_REQ_KRB4:
592592
#ifdefKRB4
593+
pglock_thread();
593594
if (pg_krb4_sendauth(PQerrormsg,conn->sock,
594595
(structsockaddr_in*)&conn->laddr.addr,
595596
(structsockaddr_in*)&conn->raddr.addr,
596597
hostname)!=STATUS_OK)
597598
{
598599
snprintf(PQerrormsg,PQERRORMSG_LENGTH,
599600
libpq_gettext("Kerberos 4 authentication failed\n"));
601+
pgunlock_thread();
600602
returnSTATUS_ERROR;
601603
}
604+
pgunlock_thread();
602605
break;
603606
#else
604607
snprintf(PQerrormsg,PQERRORMSG_LENGTH,
@@ -608,13 +611,16 @@ fe_sendauth(AuthRequest areq, PGconn *conn, const char *hostname,
608611

609612
caseAUTH_REQ_KRB5:
610613
#ifdefKRB5
614+
pglock_thread();
611615
if (pg_krb5_sendauth(PQerrormsg,conn->sock,
612616
hostname)!=STATUS_OK)
613617
{
614618
snprintf(PQerrormsg,PQERRORMSG_LENGTH,
615619
libpq_gettext("Kerberos 5 authentication failed\n"));
620+
pgunlock_thread();
616621
returnSTATUS_ERROR;
617622
}
623+
pgunlock_thread();
618624
break;
619625
#else
620626
snprintf(PQerrormsg,PQERRORMSG_LENGTH,
@@ -722,6 +728,7 @@ fe_getauthname(char *PQerrormsg)
722728
if (authsvc==0)
723729
returnNULL;/* leave original error message in place */
724730

731+
pglock_thread();
725732
#ifdefKRB4
726733
if (authsvc==STARTUP_KRB4_MSG)
727734
name=pg_krb4_authname(PQerrormsg);
@@ -759,5 +766,6 @@ fe_getauthname(char *PQerrormsg)
759766

760767
if (name&& (authn= (char*)malloc(strlen(name)+1)))
761768
strcpy(authn,name);
769+
pgunlock_thread();
762770
returnauthn;
763771
}

‎src/interfaces/libpq/fe-connect.c

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
*
99
*
1010
* IDENTIFICATION
11-
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-connect.c,v 1.268 2004/03/10 21:12:47 momjian Exp $
11+
* $PostgreSQL: pgsql/src/interfaces/libpq/fe-connect.c,v 1.269 2004/03/24 03:44:59 momjian Exp $
1212
*
1313
*-------------------------------------------------------------------------
1414
*/
@@ -2902,7 +2902,7 @@ int
29022902
PQsetClientEncoding(PGconn*conn,constchar*encoding)
29032903
{
29042904
charqbuf[128];
2905-
staticcharquery[]="set client_encoding to '%s'";
2905+
staticconstcharquery[]="set client_encoding to '%s'";
29062906
PGresult*res;
29072907
intstatus;
29082908

@@ -3164,3 +3164,44 @@ PasswordFromFile(char *hostname, char *port, char *dbname, char *username)
31643164
#undef LINELEN
31653165
}
31663166

3167+
/*
3168+
* To keep the API consistent, the locking stubs are always provided, even
3169+
* if they are not required.
3170+
*/
3171+
3172+
void
3173+
PQinitSSL(intdo_init)
3174+
{
3175+
#ifdefUSE_SSL
3176+
pq_initssllib=do_init;
3177+
#endif
3178+
}
3179+
3180+
staticpgthreadlock_tdefault_threadlock;
3181+
staticvoid
3182+
default_threadlock(intacquire)
3183+
{
3184+
#ifdefENABLE_THREAD_SAFETY
3185+
staticpthread_mutex_tsinglethread_lock=PTHREAD_MUTEX_INITIALIZER;
3186+
if (acquire)
3187+
pthread_mutex_lock(&singlethread_lock);
3188+
else
3189+
pthread_mutex_unlock(&singlethread_lock);
3190+
#endif
3191+
}
3192+
3193+
pgthreadlock_t*g_threadlock=default_threadlock;
3194+
3195+
pgthreadlock_t*
3196+
PQregisterThreadLock(pgthreadlock_t*newhandler)
3197+
{
3198+
pgthreadlock_t*prev;
3199+
3200+
prev=g_threadlock;
3201+
if (newhandler)
3202+
g_threadlock=newhandler;
3203+
else
3204+
g_threadlock=default_threadlock;
3205+
returnprev;
3206+
}
3207+

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp