@@ -88,6 +88,17 @@ static Port *pam_port_cludge; /* Workaround for passing "Port *port" into
8888#endif /* USE_PAM */
8989
9090
91+ /*----------------------------------------------------------------
92+ * BSD authentication
93+ *----------------------------------------------------------------
94+ */
95+ #ifdef USE_BSD_AUTH
96+ #include <bsd_auth.h>
97+
98+ static int CheckBSDAuth (Port * port , char * user );
99+ #endif /* USE_BSD_AUTH */
100+
101+
91102/*----------------------------------------------------------------
92103 * LDAP authentication
93104 *----------------------------------------------------------------
@@ -258,6 +269,9 @@ auth_failed(Port *port, int status, char *logdetail)
258269 case uaPAM :
259270 errstr = gettext_noop ("PAM authentication failed for user \"%s\"" );
260271 break ;
272+ case uaBSD :
273+ errstr = gettext_noop ("BSD authentication failed for user \"%s\"" );
274+ break ;
261275 case uaLDAP :
262276 errstr = gettext_noop ("LDAP authentication failed for user \"%s\"" );
263277 break ;
@@ -529,6 +543,14 @@ ClientAuthentication(Port *port)
529543#endif /* USE_PAM */
530544 break ;
531545
546+ case uaBSD :
547+ #ifdef USE_BSD_AUTH
548+ status = CheckBSDAuth (port , port -> user_name );
549+ #else
550+ Assert (false);
551+ #endif /* USE_BSD_AUTH */
552+ break ;
553+
532554 case uaLDAP :
533555#ifdef USE_LDAP
534556 status = CheckLDAPAuth (port );
@@ -1856,6 +1878,38 @@ CheckPAMAuth(Port *port, char *user, char *password)
18561878#endif /* USE_PAM */
18571879
18581880
1881+ /*----------------------------------------------------------------
1882+ * BSD authentication system
1883+ *----------------------------------------------------------------
1884+ */
1885+ #ifdef USE_BSD_AUTH
1886+ static int
1887+ CheckBSDAuth (Port * port , char * user )
1888+ {
1889+ char * passwd ;
1890+ int retval ;
1891+
1892+ /* Send regular password request to client, and get the response */
1893+ sendAuthRequest (port , AUTH_REQ_PASSWORD );
1894+
1895+ passwd = recv_password_packet (port );
1896+ if (passwd == NULL )
1897+ return STATUS_EOF ;
1898+
1899+ /*
1900+ * Ask the BSD auth system to verify password. Note that auth_userokay
1901+ * will overwrite the password string with zeroes, but it's just a
1902+ * temporary string so we don't care.
1903+ */
1904+ retval = auth_userokay (user , NULL , "auth-postgresql" , passwd );
1905+
1906+ if (!retval )
1907+ return STATUS_ERROR ;
1908+
1909+ return STATUS_OK ;
1910+ }
1911+ #endif /* USE_BSD_AUTH */
1912+
18591913
18601914/*----------------------------------------------------------------
18611915 * LDAP authentication system
0 commit comments