1010 *
1111 *
1212 * 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 $
1414 *
1515 *-------------------------------------------------------------------------
1616 */
@@ -290,26 +290,11 @@ parse_hba(List *line, hbaPort *port, bool *found_p, bool *error_p)
290290gotohba_syntax ;
291291
292292/*
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.
296294 */
297295if (port -> auth_method == uaKrb4 ||
298296port -> auth_method == uaKrb5 )
299297gotohba_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
313298
314299/*
315300 * 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)
326311{
327312struct in_addr file_ip_addr ,mask ;
328313
329- #ifdef USE_SSL
330- /* If SSL, then check that we are on SSL */
331314if (strcmp (token ,"hostssl" )== 0 )
332315{
316+ #ifdef USE_SSL
317+ /* Record does not match if we are not on an SSL connection */
333318if (!port -> ssl )
334319return ;
335320
336321/* Placeholder to require specific SSL level, perhaps? */
337322/* Or a client certificate */
338323
339324/* Since we were on SSL, proceed as with normal 'host' mode */
340- }
341325#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 */
344327gotohba_syntax ;
345328#endif
329+ }
346330
347331/* Get the database. */
348332line = lnext (line );
@@ -866,8 +850,6 @@ ident_inet(const struct in_addr remote_ip_addr,
866850return ident_return ;
867851}
868852
869- #ifdef SO_PEERCRED
870-
871853/*
872854 * Ask kernel about the credentials of the connecting process and
873855 * determine the symbolic name of the corresponding user.
@@ -878,26 +860,12 @@ ident_inet(const struct in_addr remote_ip_addr,
878860static bool
879861ident_unix (int sock ,char * ident_user )
880862{
863+ #ifdef SO_PEERCRED
864+ /* Linux style: use getsockopt(SO_PEERCRED) */
881865struct ucred peercred ;
882866socklen_t so_len ;
883867struct passwd * pass ;
884868
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-
901869errno = 0 ;
902870so_len = sizeof (peercred );
903871if (getsockopt (sock ,SOL_SOCKET ,SO_PEERCRED ,& peercred ,& so_len )!= 0 ||
@@ -928,9 +896,17 @@ ident_unix(int sock, char *ident_user)
928896StrNCpy (ident_user ,pass -> pw_name ,IDENT_USERNAME_MAX );
929897
930898return 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;
932907
933908#endif /* SO_PEERCRED */
909+ }
934910
935911/*
936912 * Determine the username of the initiator of the connection described
@@ -954,12 +930,10 @@ authident(hbaPort *port)
954930port -> laddr .in .sin_port ,ident_user ))
955931return STATUS_ERROR ;
956932break ;
957- #ifdef SO_PEERCRED
958933case AF_UNIX :
959934if (!ident_unix (port -> sock ,ident_user ))
960935return STATUS_ERROR ;
961936break ;
962- #endif
963937default :
964938return STATUS_ERROR ;
965939}