10
10
*
11
11
*
12
12
* IDENTIFICATION
13
- * $Header: /cvsroot/pgsql/src/backend/libpq/hba.c,v 1.59 2001/08/01 23:52:50 tgl Exp $
13
+ * $Header: /cvsroot/pgsql/src/backend/libpq/hba.c,v 1.60 2001/08/02 14:27:40 tgl Exp $
14
14
*
15
15
*-------------------------------------------------------------------------
16
16
*/
@@ -290,26 +290,11 @@ parse_hba(List *line, hbaPort *port, bool *found_p, bool *error_p)
290
290
goto hba_syntax ;
291
291
292
292
/*
293
- * Disallow auth methods that need AF_INET sockets to work.
294
- * Allow "ident" if we can get the identity of the connection
295
- * peer on Unix domain sockets from the OS.
293
+ * Disallow auth methods that always need AF_INET sockets to work.
296
294
*/
297
295
if (port -> auth_method == uaKrb4 ||
298
296
port -> auth_method == uaKrb5 )
299
297
goto hba_syntax ;
300
- #ifndef SO_PEERCRED
301
- if (port -> auth_method == uaIdent )
302
- {
303
- /* Give a special error message for this case... */
304
- snprintf (PQerrormsg , PQERRORMSG_LENGTH ,
305
- "parse_hba: \"ident\" auth is not supported on local connections on this platform\n" );
306
- fputs (PQerrormsg , stderr );
307
- pqdebug ("%s" , PQerrormsg );
308
-
309
- * error_p = true;
310
- return ;
311
- }
312
- #endif
313
298
314
299
/*
315
300
* If this record doesn't match the parameters of the connection
@@ -326,23 +311,22 @@ parse_hba(List *line, hbaPort *port, bool *found_p, bool *error_p)
326
311
{
327
312
struct in_addr file_ip_addr , mask ;
328
313
329
- #ifdef USE_SSL
330
- /* If SSL, then check that we are on SSL */
331
314
if (strcmp (token , "hostssl" ) == 0 )
332
315
{
316
+ #ifdef USE_SSL
317
+ /* Record does not match if we are not on an SSL connection */
333
318
if (!port -> ssl )
334
319
return ;
335
320
336
321
/* Placeholder to require specific SSL level, perhaps? */
337
322
/* Or a client certificate */
338
323
339
324
/* Since we were on SSL, proceed as with normal 'host' mode */
340
- }
341
325
#else
342
- /* If not SSL, we don't support this */
343
- if (strcmp (token , "hostssl" ) == 0 )
326
+ /* We don't accept this keyword at all if no SSL support */
344
327
goto hba_syntax ;
345
328
#endif
329
+ }
346
330
347
331
/* Get the database. */
348
332
line = lnext (line );
@@ -866,8 +850,6 @@ ident_inet(const struct in_addr remote_ip_addr,
866
850
return ident_return ;
867
851
}
868
852
869
- #ifdef SO_PEERCRED
870
-
871
853
/*
872
854
* Ask kernel about the credentials of the connecting process and
873
855
* determine the symbolic name of the corresponding user.
@@ -878,26 +860,12 @@ ident_inet(const struct in_addr remote_ip_addr,
878
860
static bool
879
861
ident_unix (int sock , char * ident_user )
880
862
{
863
+ #ifdef SO_PEERCRED
864
+ /* Linux style: use getsockopt(SO_PEERCRED) */
881
865
struct ucred peercred ;
882
866
socklen_t so_len ;
883
867
struct passwd * pass ;
884
868
885
- #ifdef SO_PASSCRED
886
- int passcred = -1 ;
887
-
888
- so_len = sizeof (passcred );
889
- if (setsockopt (sock , SOL_SOCKET , SO_PASSCRED , & passcred , so_len ) != 0 )
890
- {
891
- /* We could not set the socket to pass credentials */
892
- snprintf (PQerrormsg , PQERRORMSG_LENGTH ,
893
- "Could not set the UNIX socket to pass credentials: %s\n" ,
894
- strerror (errno ));
895
- fputs (PQerrormsg , stderr );
896
- pqdebug ("%s" , PQerrormsg );
897
- return false;
898
- }
899
- #endif /* SO_PASSCRED */
900
-
901
869
errno = 0 ;
902
870
so_len = sizeof (peercred );
903
871
if (getsockopt (sock , SOL_SOCKET , SO_PEERCRED , & peercred , & so_len ) != 0 ||
@@ -928,9 +896,17 @@ ident_unix(int sock, char *ident_user)
928
896
StrNCpy (ident_user , pass -> pw_name , IDENT_USERNAME_MAX );
929
897
930
898
return true;
931
- }
899
+
900
+ #else /* not SO_PEERCRED */
901
+
902
+ snprintf (PQerrormsg , PQERRORMSG_LENGTH ,
903
+ "IDENT auth is not supported on local connections on this platform\n" );
904
+ fputs (PQerrormsg , stderr );
905
+ pqdebug ("%s" , PQerrormsg );
906
+ return false;
932
907
933
908
#endif /* SO_PEERCRED */
909
+ }
934
910
935
911
/*
936
912
* Determine the username of the initiator of the connection described
@@ -954,12 +930,10 @@ authident(hbaPort *port)
954
930
port -> laddr .in .sin_port , ident_user ))
955
931
return STATUS_ERROR ;
956
932
break ;
957
- #ifdef SO_PEERCRED
958
933
case AF_UNIX :
959
934
if (!ident_unix (port -> sock , ident_user ))
960
935
return STATUS_ERROR ;
961
936
break ;
962
- #endif
963
937
default :
964
938
return STATUS_ERROR ;
965
939
}
0 commit comments