55 * wherein you authenticate a user by seeing what IP address the system
66 * says he comes from and possibly using ident).
77 *
8- *$Id: hba.c,v 1.47 1999/07/17 20:17:02 momjian Exp $
8+ *$Id: hba.c,v 1.48 1999/09/27 03:12:59 momjian Exp $
99 *
1010 *-------------------------------------------------------------------------
1111 */
@@ -146,9 +146,7 @@ read_hba_entry2(FILE *file, UserAuth *userauth_p, char *auth_arg,
146146
147147
148148static void
149- process_hba_record (FILE * file ,SockAddr * raddr ,const char * user ,
150- const char * database ,bool * matches_p ,bool * error_p ,
151- UserAuth * userauth_p ,char * auth_arg )
149+ process_hba_record (FILE * file ,hbaPort * port ,bool * matches_p ,bool * error_p )
152150{
153151/*---------------------------------------------------------------------------
154152 Process the non-comment record in the config file that is next on the file.
@@ -182,16 +180,16 @@ process_hba_record(FILE *file, SockAddr *raddr, const char *user,
182180
183181/* Read the rest of the line. */
184182
185- read_hba_entry2 (file ,userauth_p , auth_arg ,error_p );
183+ read_hba_entry2 (file ,& port -> auth_method , port -> auth_arg ,error_p );
186184
187185/*
188186 * For now, disallow methods that need AF_INET sockets to work.
189187 */
190188
191189if (!* error_p &&
192- (* userauth_p == uaIdent ||
193- * userauth_p == uaKrb4 ||
194- * userauth_p == uaKrb5 ))
190+ (port -> auth_method == uaIdent ||
191+ port -> auth_method == uaKrb4 ||
192+ port -> auth_method == uaKrb5 ))
195193* error_p = true;
196194
197195if (* error_p )
@@ -202,15 +200,33 @@ process_hba_record(FILE *file, SockAddr *raddr, const char *user,
202200 * sort of connection, ignore it.
203201 */
204202
205- if ((strcmp (db ,database )!= 0 && strcmp (db ,"all" )!= 0 &&
206- (strcmp (db ,"sameuser" )!= 0 || strcmp (database ,user )!= 0 ))||
207- raddr -> sa .sa_family != AF_UNIX )
203+ if ((strcmp (db ,port -> database )!= 0 && strcmp (db ,"all" )!= 0 &&
204+ (strcmp (db ,"sameuser" )!= 0 || strcmp (port -> database ,port -> user )!= 0 ))||
205+ port -> raddr . sa .sa_family != AF_UNIX )
208206return ;
209207}
210- else if (strcmp (buf ,"host" )== 0 )
208+ else if (strcmp (buf ,"host" )== 0 || strcmp ( buf , "hostssl" ) == 0 )
211209{
212210struct in_addr file_ip_addr ,
213211mask ;
212+ bool discard = 0 ;/* Discard this entry */
213+
214+ #ifdef USE_SSL
215+ /* If SSL, then check that we are on SSL */
216+ if (strcmp (buf ,"hostssl" )== 0 ) {
217+ if (!port -> ssl )
218+ discard = 1 ;
219+
220+ /* Placeholder to require specific SSL level, perhaps? */
221+ /* Or a client certificate */
222+
223+ /* Since we were on SSL, proceed as with normal 'host' mode */
224+ }
225+ #else
226+ /* If not SSL, we don't support this */
227+ if (strcmp (buf ,"hostssl" )== 0 )
228+ gotosyntax ;
229+ #endif
214230
215231/* Get the database. */
216232
@@ -252,20 +268,27 @@ process_hba_record(FILE *file, SockAddr *raddr, const char *user,
252268 * info from it.
253269 */
254270
255- read_hba_entry2 (file ,userauth_p , auth_arg ,error_p );
271+ read_hba_entry2 (file ,& port -> auth_method , port -> auth_arg ,error_p );
256272
257273if (* error_p )
258274gotosyntax ;
259275
276+ /*
277+ * If told to discard earlier. Moved down here so we don't get
278+ * "out of sync" with the file.
279+ */
280+ if (discard )
281+ return ;
282+
260283/*
261284 * If this record isn't for our database, or this is the wrong
262285 * sort of connection, ignore it.
263286 */
264287
265- if ((strcmp (db ,database )!= 0 && strcmp (db ,"all" )!= 0 &&
266- (strcmp (db ,"sameuser" )!= 0 || strcmp (database ,user )!= 0 ))||
267- raddr -> sa .sa_family != AF_INET ||
268- ((file_ip_addr .s_addr ^raddr -> in .sin_addr .s_addr )& mask .s_addr )!= 0x0000 )
288+ if ((strcmp (db ,port -> database )!= 0 && strcmp (db ,"all" )!= 0 &&
289+ (strcmp (db ,"sameuser" )!= 0 || strcmp (port -> database ,port -> user )!= 0 ))||
290+ port -> raddr . sa .sa_family != AF_INET ||
291+ ((file_ip_addr .s_addr ^port -> raddr . in .sin_addr .s_addr )& mask .s_addr )!= 0x0000 )
269292return ;
270293}
271294else
@@ -291,9 +314,7 @@ process_hba_record(FILE *file, SockAddr *raddr, const char *user,
291314
292315
293316static void
294- process_open_config_file (FILE * file ,SockAddr * raddr ,const char * user ,
295- const char * database ,bool * hba_ok_p ,
296- UserAuth * userauth_p ,char * auth_arg )
317+ process_open_config_file (FILE * file ,hbaPort * port ,bool * hba_ok_p )
297318{
298319/*---------------------------------------------------------------------------
299320 This function does the same thing as find_hba_entry, only with
@@ -316,8 +337,7 @@ process_open_config_file(FILE *file, SockAddr *raddr, const char *user,
316337if (c == '#' )
317338read_through_eol (file );
318339else
319- process_hba_record (file ,raddr ,user ,database ,
320- & found_entry ,& error ,userauth_p ,auth_arg );
340+ process_hba_record (file ,port ,& found_entry ,& error );
321341}
322342}
323343
@@ -326,7 +346,7 @@ process_open_config_file(FILE *file, SockAddr *raddr, const char *user,
326346/* If no matching entry was found, synthesize 'reject' entry. */
327347
328348if (!found_entry )
329- * userauth_p = uaReject ;
349+ port -> auth_method = uaReject ;
330350
331351* hba_ok_p = true;
332352}
@@ -335,8 +355,7 @@ process_open_config_file(FILE *file, SockAddr *raddr, const char *user,
335355
336356
337357static void
338- find_hba_entry (SockAddr * raddr ,const char * user ,const char * database ,
339- bool * hba_ok_p ,UserAuth * userauth_p ,char * auth_arg )
358+ find_hba_entry (hbaPort * port ,bool * hba_ok_p )
340359{
341360/*
342361 * Read the config file and find an entry that allows connection from
@@ -412,8 +431,7 @@ find_hba_entry(SockAddr *raddr, const char *user, const char *database,
412431}
413432else
414433{
415- process_open_config_file (file ,raddr ,user ,database ,hba_ok_p ,
416- userauth_p ,auth_arg );
434+ process_open_config_file (file ,port ,hba_ok_p );
417435FreeFile (file );
418436}
419437pfree (conf_file );
@@ -1057,8 +1075,7 @@ GetCharSetByHost(char *TableName, int host, const char *DataDir)
10571075#endif
10581076
10591077int
1060- hba_getauthmethod (SockAddr * raddr ,char * user ,char * database ,
1061- char * auth_arg ,UserAuth * auth_method )
1078+ hba_getauthmethod (hbaPort * port )
10621079{
10631080/*---------------------------------------------------------------------------
10641081 Determine what authentication method should be used when accessing database
@@ -1070,7 +1087,7 @@ hba_getauthmethod(SockAddr *raddr, char *user, char *database,
10701087----------------------------------------------------------------------------*/
10711088bool hba_ok = false;
10721089
1073- find_hba_entry (raddr , user , database , & hba_ok , auth_method , auth_arg );
1090+ find_hba_entry (port , & hba_ok );
10741091
10751092return hba_ok ?STATUS_OK :STATUS_ERROR ;
10761093}