26
26
27
27
static ArrayType * get_hba_options (HbaLine * hba );
28
28
static void fill_hba_line (Tuplestorestate * tuple_store , TupleDesc tupdesc ,
29
- int lineno , HbaLine * hba , const char * err_msg );
29
+ int rule_number , int lineno , HbaLine * hba ,
30
+ const char * err_msg );
30
31
static void fill_hba_view (Tuplestorestate * tuple_store , TupleDesc tupdesc );
31
32
static void fill_ident_line (Tuplestorestate * tuple_store , TupleDesc tupdesc ,
32
- int lineno , IdentLine * ident , const char * err_msg );
33
+ int map_number , int lineno , IdentLine * ident ,
34
+ const char * err_msg );
33
35
static void fill_ident_view (Tuplestorestate * tuple_store , TupleDesc tupdesc );
34
36
35
37
@@ -157,14 +159,15 @@ get_hba_options(HbaLine *hba)
157
159
}
158
160
159
161
/* Number of columns in pg_hba_file_rules view */
160
- #define NUM_PG_HBA_FILE_RULES_ATTS 9
162
+ #define NUM_PG_HBA_FILE_RULES_ATTS 10
161
163
162
164
/*
163
165
* fill_hba_line
164
166
* Build one row of pg_hba_file_rules view, add it to tuplestore.
165
167
*
166
168
* tuple_store: where to store data
167
169
* tupdesc: tuple descriptor for the view
170
+ * rule_number: unique identifier among all valid rules
168
171
* lineno: pg_hba.conf line number (must always be valid)
169
172
* hba: parsed line data (can be NULL, in which case err_msg should be set)
170
173
* err_msg: error message (NULL if none)
@@ -174,7 +177,8 @@ get_hba_options(HbaLine *hba)
174
177
*/
175
178
static void
176
179
fill_hba_line (Tuplestorestate * tuple_store , TupleDesc tupdesc ,
177
- int lineno , HbaLine * hba , const char * err_msg )
180
+ int rule_number , int lineno , HbaLine * hba ,
181
+ const char * err_msg )
178
182
{
179
183
Datum values [NUM_PG_HBA_FILE_RULES_ATTS ];
180
184
bool nulls [NUM_PG_HBA_FILE_RULES_ATTS ];
@@ -193,6 +197,12 @@ fill_hba_line(Tuplestorestate *tuple_store, TupleDesc tupdesc,
193
197
memset (nulls , 0 , sizeof (nulls ));
194
198
index = 0 ;
195
199
200
+ /* rule_number, nothing on error */
201
+ if (err_msg )
202
+ nulls [index ++ ] = true;
203
+ else
204
+ values [index ++ ] = Int32GetDatum (rule_number );
205
+
196
206
/* line_number */
197
207
values [index ++ ] = Int32GetDatum (lineno );
198
208
@@ -336,7 +346,7 @@ fill_hba_line(Tuplestorestate *tuple_store, TupleDesc tupdesc,
336
346
else
337
347
{
338
348
/* no parsing result, so set relevant fields to nulls */
339
- memset (& nulls [1 ], true, (NUM_PG_HBA_FILE_RULES_ATTS - 2 ) * sizeof (bool ));
349
+ memset (& nulls [2 ], true, (NUM_PG_HBA_FILE_RULES_ATTS - 3 ) * sizeof (bool ));
340
350
}
341
351
342
352
/* error */
@@ -359,6 +369,7 @@ fill_hba_view(Tuplestorestate *tuple_store, TupleDesc tupdesc)
359
369
FILE * file ;
360
370
List * hba_lines = NIL ;
361
371
ListCell * line ;
372
+ int rule_number = 0 ;
362
373
MemoryContext linecxt ;
363
374
MemoryContext hbacxt ;
364
375
MemoryContext oldcxt ;
@@ -393,8 +404,12 @@ fill_hba_view(Tuplestorestate *tuple_store, TupleDesc tupdesc)
393
404
if (tok_line -> err_msg == NULL )
394
405
hbaline = parse_hba_line (tok_line , DEBUG3 );
395
406
396
- fill_hba_line (tuple_store , tupdesc , tok_line -> line_num ,
397
- hbaline , tok_line -> err_msg );
407
+ /* No error, set a new rule number */
408
+ if (tok_line -> err_msg == NULL )
409
+ rule_number ++ ;
410
+
411
+ fill_hba_line (tuple_store , tupdesc , rule_number ,
412
+ tok_line -> line_num , hbaline , tok_line -> err_msg );
398
413
}
399
414
400
415
/* Free tokenizer memory */
@@ -431,14 +446,15 @@ pg_hba_file_rules(PG_FUNCTION_ARGS)
431
446
}
432
447
433
448
/* Number of columns in pg_ident_file_mappings view */
434
- #define NUM_PG_IDENT_FILE_MAPPINGS_ATTS 5
449
+ #define NUM_PG_IDENT_FILE_MAPPINGS_ATTS 6
435
450
436
451
/*
437
452
* fill_ident_line: build one row of pg_ident_file_mappings view, add it to
438
453
* tuplestore
439
454
*
440
455
* tuple_store: where to store data
441
456
* tupdesc: tuple descriptor for the view
457
+ * map_number: unique identifier among all valid maps
442
458
* lineno: pg_ident.conf line number (must always be valid)
443
459
* ident: parsed line data (can be NULL, in which case err_msg should be set)
444
460
* err_msg: error message (NULL if none)
@@ -448,7 +464,8 @@ pg_hba_file_rules(PG_FUNCTION_ARGS)
448
464
*/
449
465
static void
450
466
fill_ident_line (Tuplestorestate * tuple_store , TupleDesc tupdesc ,
451
- int lineno , IdentLine * ident , const char * err_msg )
467
+ int map_number , int lineno , IdentLine * ident ,
468
+ const char * err_msg )
452
469
{
453
470
Datum values [NUM_PG_IDENT_FILE_MAPPINGS_ATTS ];
454
471
bool nulls [NUM_PG_IDENT_FILE_MAPPINGS_ATTS ];
@@ -461,6 +478,12 @@ fill_ident_line(Tuplestorestate *tuple_store, TupleDesc tupdesc,
461
478
memset (nulls , 0 , sizeof (nulls ));
462
479
index = 0 ;
463
480
481
+ /* map_number, nothing on error */
482
+ if (err_msg )
483
+ nulls [index ++ ] = true;
484
+ else
485
+ values [index ++ ] = Int32GetDatum (map_number );
486
+
464
487
/* line_number */
465
488
values [index ++ ] = Int32GetDatum (lineno );
466
489
@@ -473,7 +496,7 @@ fill_ident_line(Tuplestorestate *tuple_store, TupleDesc tupdesc,
473
496
else
474
497
{
475
498
/* no parsing result, so set relevant fields to nulls */
476
- memset (& nulls [1 ], true, (NUM_PG_IDENT_FILE_MAPPINGS_ATTS - 2 ) * sizeof (bool ));
499
+ memset (& nulls [2 ], true, (NUM_PG_IDENT_FILE_MAPPINGS_ATTS - 3 ) * sizeof (bool ));
477
500
}
478
501
479
502
/* error */
@@ -495,6 +518,7 @@ fill_ident_view(Tuplestorestate *tuple_store, TupleDesc tupdesc)
495
518
FILE * file ;
496
519
List * ident_lines = NIL ;
497
520
ListCell * line ;
521
+ int map_number = 0 ;
498
522
MemoryContext linecxt ;
499
523
MemoryContext identcxt ;
500
524
MemoryContext oldcxt ;
@@ -529,7 +553,12 @@ fill_ident_view(Tuplestorestate *tuple_store, TupleDesc tupdesc)
529
553
if (tok_line -> err_msg == NULL )
530
554
identline = parse_ident_line (tok_line , DEBUG3 );
531
555
532
- fill_ident_line (tuple_store , tupdesc , tok_line -> line_num , identline ,
556
+ /* no error, set a new mapping number */
557
+ if (tok_line -> err_msg == NULL )
558
+ map_number ++ ;
559
+
560
+ fill_ident_line (tuple_store , tupdesc , map_number ,
561
+ tok_line -> line_num , identline ,
533
562
tok_line -> err_msg );
534
563
}
535
564
0 commit comments