Skip to content

Commit 98ae2c8

Browse files
committed
libpq: Remove code for SCM credential authentication
Support for SCM credential authentication has been removed in the backend in 9.1, and libpq has kept some code to handle it for compatibility. Commit be4585b, that did the cleanup of the backend code, has done so because the code was not really portable originally. And, as there are likely little chances that this is used these days, this removes the remaining code from libpq. An error will now be raised by libpq if attempting to connect to a server that returns AUTH_REQ_SCM_CREDS, instead. References to SCM credential authentication are removed from the protocol documentation. This removes some meson and configure checks. Author: Michael Paquier Reviewed-by: Tom Lane Discussion: https://postgr.es/m/ZBLH8a4otfqgd6Kn@paquier.xyz
1 parent 10b6745 commit 98ae2c8

File tree

10 files changed

+1
-178
lines changed

10 files changed

+1
-178
lines changed

configure

-16
Original file line numberDiff line numberDiff line change
@@ -15181,22 +15181,6 @@ cat >>confdefs.h <<_ACEOF
1518115181
_ACEOF
1518215182

1518315183

15184-
ac_fn_c_check_type "$LINENO" "struct cmsgcred" "ac_cv_type_struct_cmsgcred" "#include <sys/socket.h>
15185-
#include <sys/param.h>
15186-
#ifdef HAVE_SYS_UCRED_H
15187-
#include <sys/ucred.h>
15188-
#endif
15189-
"
15190-
if test "x$ac_cv_type_struct_cmsgcred" = xyes; then :
15191-
15192-
cat >>confdefs.h <<_ACEOF
15193-
#define HAVE_STRUCT_CMSGCRED 1
15194-
_ACEOF
15195-
15196-
15197-
fi
15198-
15199-
1520015184
ac_fn_c_check_type "$LINENO" "struct option" "ac_cv_type_struct_option" "#ifdef HAVE_GETOPT_H
1520115185
#include <getopt.h>
1520215186
#endif

configure.ac

-7
Original file line numberDiff line numberDiff line change
@@ -1682,13 +1682,6 @@ AC_DEFINE_UNQUOTED([pg_restrict], [$pg_restrict],
16821682
[Define to keyword to use for C99 restrict support, or to nothing if not
16831683
supported])
16841684

1685-
AC_CHECK_TYPES([struct cmsgcred], [], [],
1686-
[#include <sys/socket.h>
1687-
#include <sys/param.h>
1688-
#ifdef HAVE_SYS_UCRED_H
1689-
#include <sys/ucred.h>
1690-
#endif])
1691-
16921685
AC_CHECK_TYPES([struct option], [], [],
16931686
[#ifdef HAVE_GETOPT_H
16941687
#include <getopt.h>

doc/src/sgml/libpq.sgml

-10
Original file line numberDiff line numberDiff line change
@@ -1300,16 +1300,6 @@ postgresql://%2Fvar%2Flib%2Fpostgresql/dbname
13001300
</listitem>
13011301
</varlistentry>
13021302

1303-
<varlistentry>
1304-
<term><literal>creds</literal></term>
1305-
<listitem>
1306-
<para>
1307-
The server must request SCM credential authentication (deprecated
1308-
as of <productname>PostgreSQL</productname> 9.1).
1309-
</para>
1310-
</listitem>
1311-
</varlistentry>
1312-
13131303
<varlistentry>
13141304
<term><literal>none</literal></term>
13151305
<listitem>

doc/src/sgml/protocol.sgml

-52
Original file line numberDiff line numberDiff line change
@@ -315,24 +315,6 @@
315315
</listitem>
316316
</varlistentry>
317317

318-
<varlistentry>
319-
<term>AuthenticationSCMCredential</term>
320-
<listitem>
321-
<para>
322-
This response is only possible for local Unix-domain connections
323-
on platforms that support SCM credential messages. The frontend
324-
must issue an SCM credential message and then send a single data
325-
byte. (The contents of the data byte are uninteresting; it's
326-
only used to ensure that the server waits long enough to receive
327-
the credential message.) If the credential is acceptable,
328-
the server responds with an
329-
AuthenticationOk, otherwise it responds with an ErrorResponse.
330-
(This message type is only issued by pre-9.1 servers. It may
331-
eventually be removed from the protocol specification.)
332-
</para>
333-
</listitem>
334-
</varlistentry>
335-
336318
<varlistentry>
337319
<term>AuthenticationGSS</term>
338320
<listitem>
@@ -3449,40 +3431,6 @@ psql "dbname=postgres replication=database" -c "IDENTIFY_SYSTEM;"
34493431
</listitem>
34503432
</varlistentry>
34513433

3452-
<varlistentry id="protocol-message-formats-AuthenticationSCMCredential">
3453-
<term>AuthenticationSCMCredential (B)</term>
3454-
<listitem>
3455-
<variablelist>
3456-
<varlistentry>
3457-
<term>Byte1('R')</term>
3458-
<listitem>
3459-
<para>
3460-
Identifies the message as an authentication request.
3461-
</para>
3462-
</listitem>
3463-
</varlistentry>
3464-
3465-
<varlistentry>
3466-
<term>Int32(8)</term>
3467-
<listitem>
3468-
<para>
3469-
Length of message contents in bytes, including self.
3470-
</para>
3471-
</listitem>
3472-
</varlistentry>
3473-
3474-
<varlistentry>
3475-
<term>Int32(6)</term>
3476-
<listitem>
3477-
<para>
3478-
Specifies that an SCM credentials message is required.
3479-
</para>
3480-
</listitem>
3481-
</varlistentry>
3482-
</variablelist>
3483-
</listitem>
3484-
</varlistentry>
3485-
34863434
<varlistentry id="protocol-message-formats-AuthenticationGSS">
34873435
<term>AuthenticationGSS (B)</term>
34883436
<listitem>

meson.build

-14
Original file line numberDiff line numberDiff line change
@@ -2144,20 +2144,6 @@ foreach c : decl_checks
21442144
endforeach
21452145

21462146

2147-
if cc.has_type('struct cmsgcred',
2148-
args: test_c_args + ['@0@'.format(cdata.get('HAVE_SYS_UCRED_H')) == 'false' ? '' : '-DHAVE_SYS_UCRED_H'],
2149-
include_directories: postgres_inc,
2150-
prefix: '''
2151-
#include <sys/socket.h>
2152-
#include <sys/param.h>
2153-
#ifdef HAVE_SYS_UCRED_H
2154-
#include <sys/ucred.h>
2155-
#endif''')
2156-
cdata.set('HAVE_STRUCT_CMSGCRED', 1)
2157-
else
2158-
cdata.set('HAVE_STRUCT_CMSGCRED', false)
2159-
endif
2160-
21612147
if cc.has_type('struct option',
21622148
args: test_c_args, include_directories: postgres_inc,
21632149
prefix: '@0@'.format(cdata.get('HAVE_GETOPT_H')) == '1' ? '#include <getopt.h>' : '')

src/include/libpq/pqcomm.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ extern PGDLLIMPORT bool Db_user_namespace;
116116
#define AUTH_REQ_PASSWORD 3 /* Password */
117117
#define AUTH_REQ_CRYPT 4 /* crypt password. Not supported any more. */
118118
#define AUTH_REQ_MD5 5 /* md5 password */
119-
#define AUTH_REQ_SCM_CREDS 6 /* transfer SCM credentials */
119+
/* 6 is available. It was used for SCM creds, not supported any more. */
120120
#define AUTH_REQ_GSS 7 /* GSSAPI without wrap() */
121121
#define AUTH_REQ_GSS_CONT 8 /* Continue GSS exchanges */
122122
#define AUTH_REQ_SSPI 9 /* SSPI negotiate without wrap() */

src/include/pg_config.h.in

-3
Original file line numberDiff line numberDiff line change
@@ -427,9 +427,6 @@
427427
/* Define to 1 if you have the `strsignal' function. */
428428
#undef HAVE_STRSIGNAL
429429

430-
/* Define to 1 if the system has the type `struct cmsgcred'. */
431-
#undef HAVE_STRUCT_CMSGCRED
432-
433430
/* Define to 1 if the system has the type `struct option'. */
434431
#undef HAVE_STRUCT_OPTION
435432

src/interfaces/libpq/fe-auth.c

-70
Original file line numberDiff line numberDiff line change
@@ -688,68 +688,6 @@ pg_SASL_continue(PGconn *conn, int payloadlen, bool final)
688688
return STATUS_OK;
689689
}
690690

691-
/*
692-
* Respond to AUTH_REQ_SCM_CREDS challenge.
693-
*
694-
* Note: this is dead code as of Postgres 9.1, because current backends will
695-
* never send this challenge. But we must keep it as long as libpq needs to
696-
* interoperate with pre-9.1 servers. It is believed to be needed only on
697-
* Debian/kFreeBSD (ie, FreeBSD kernel with Linux userland, so that the
698-
* getpeereid() function isn't provided by libc).
699-
*/
700-
static int
701-
pg_local_sendauth(PGconn *conn)
702-
{
703-
#ifdef HAVE_STRUCT_CMSGCRED
704-
char buf;
705-
struct iovec iov;
706-
struct msghdr msg;
707-
struct cmsghdr *cmsg;
708-
union
709-
{
710-
struct cmsghdr hdr;
711-
unsigned char buf[CMSG_SPACE(sizeof(struct cmsgcred))];
712-
} cmsgbuf;
713-
714-
/*
715-
* The backend doesn't care what we send here, but it wants exactly one
716-
* character to force recvmsg() to block and wait for us.
717-
*/
718-
buf = '\0';
719-
iov.iov_base = &buf;
720-
iov.iov_len = 1;
721-
722-
memset(&msg, 0, sizeof(msg));
723-
msg.msg_iov = &iov;
724-
msg.msg_iovlen = 1;
725-
726-
/* We must set up a message that will be filled in by kernel */
727-
memset(&cmsgbuf, 0, sizeof(cmsgbuf));
728-
msg.msg_control = &cmsgbuf.buf;
729-
msg.msg_controllen = sizeof(cmsgbuf.buf);
730-
cmsg = CMSG_FIRSTHDR(&msg);
731-
cmsg->cmsg_len = CMSG_LEN(sizeof(struct cmsgcred));
732-
cmsg->cmsg_level = SOL_SOCKET;
733-
cmsg->cmsg_type = SCM_CREDS;
734-
735-
if (sendmsg(conn->sock, &msg, 0) == -1)
736-
{
737-
char sebuf[PG_STRERROR_R_BUFLEN];
738-
739-
appendPQExpBuffer(&conn->errorMessage,
740-
"pg_local_sendauth: sendmsg: %s\n",
741-
strerror_r(errno, sebuf, sizeof(sebuf)));
742-
return STATUS_ERROR;
743-
}
744-
745-
conn->client_finished_auth = true;
746-
return STATUS_OK;
747-
#else
748-
libpq_append_conn_error(conn, "SCM_CRED authentication method not supported");
749-
return STATUS_ERROR;
750-
#endif
751-
}
752-
753691
static int
754692
pg_password_sendauth(PGconn *conn, const char *password, AuthRequest areq)
755693
{
@@ -830,8 +768,6 @@ auth_method_description(AuthRequest areq)
830768
return libpq_gettext("server requested GSSAPI authentication");
831769
case AUTH_REQ_SSPI:
832770
return libpq_gettext("server requested SSPI authentication");
833-
case AUTH_REQ_SCM_CREDS:
834-
return libpq_gettext("server requested UNIX socket credentials");
835771
case AUTH_REQ_SASL:
836772
case AUTH_REQ_SASL_CONT:
837773
case AUTH_REQ_SASL_FIN:
@@ -922,7 +858,6 @@ check_expected_areq(AuthRequest areq, PGconn *conn)
922858
case AUTH_REQ_GSS:
923859
case AUTH_REQ_GSS_CONT:
924860
case AUTH_REQ_SSPI:
925-
case AUTH_REQ_SCM_CREDS:
926861
case AUTH_REQ_SASL:
927862
case AUTH_REQ_SASL_CONT:
928863
case AUTH_REQ_SASL_FIN:
@@ -1183,11 +1118,6 @@ pg_fe_sendauth(AuthRequest areq, int payloadlen, PGconn *conn)
11831118
}
11841119
break;
11851120

1186-
case AUTH_REQ_SCM_CREDS:
1187-
if (pg_local_sendauth(conn) != STATUS_OK)
1188-
return STATUS_ERROR;
1189-
break;
1190-
11911121
default:
11921122
libpq_append_conn_error(conn, "authentication method %u not supported", areq);
11931123
return STATUS_ERROR;

src/interfaces/libpq/fe-connect.c

-4
Original file line numberDiff line numberDiff line change
@@ -1333,10 +1333,6 @@ connectOptions2(PGconn *conn)
13331333
bits |= (1 << AUTH_REQ_SASL_CONT);
13341334
bits |= (1 << AUTH_REQ_SASL_FIN);
13351335
}
1336-
else if (strcmp(method, "creds") == 0)
1337-
{
1338-
bits = (1 << AUTH_REQ_SCM_CREDS);
1339-
}
13401336
else if (strcmp(method, "none") == 0)
13411337
{
13421338
/*

src/tools/msvc/Solution.pm

-1
Original file line numberDiff line numberDiff line change
@@ -338,7 +338,6 @@ sub GenerateFiles
338338
HAVE_STRLCPY => undef,
339339
HAVE_STRNLEN => 1,
340340
HAVE_STRSIGNAL => undef,
341-
HAVE_STRUCT_CMSGCRED => undef,
342341
HAVE_STRUCT_OPTION => undef,
343342
HAVE_STRUCT_SOCKADDR_SA_LEN => undef,
344343
HAVE_STRUCT_TM_TM_ZONE => undef,

0 commit comments

Comments
 (0)