|
10 | 10 | *
|
11 | 11 | *
|
12 | 12 | * IDENTIFICATION
|
13 |
| - * $Header: /cvsroot/pgsql/src/backend/libpq/hba.c,v 1.100 2003/04/25 01:24:00 momjian Exp $ |
| 13 | + * $Header: /cvsroot/pgsql/src/backend/libpq/hba.c,v 1.101 2003/06/12 02:12:58 momjian Exp $ |
14 | 14 | *
|
15 | 15 | *-------------------------------------------------------------------------
|
16 | 16 | */
|
@@ -588,6 +588,7 @@ parse_hba(List *line, hbaPort *port, bool *found_p, bool *error_p)
|
588 | 588 | else if (strcmp(token, "host") == 0 || strcmp(token, "hostssl") == 0)
|
589 | 589 | {
|
590 | 590 | SockAddr file_ip_addr, mask;
|
| 591 | + char * cidr_slash; |
591 | 592 |
|
592 | 593 | if (strcmp(token, "hostssl") == 0)
|
593 | 594 | {
|
@@ -618,26 +619,48 @@ parse_hba(List *line, hbaPort *port, bool *found_p, bool *error_p)
|
618 | 619 | goto hba_syntax;
|
619 | 620 | user = lfirst(line);
|
620 | 621 |
|
621 |
| - /* Read the IP address field. */ |
| 622 | + /* Read the IP address field. (with or without CIDR netmask) */ |
622 | 623 | line = lnext(line);
|
623 | 624 | if (!line)
|
624 | 625 | goto hba_syntax;
|
625 | 626 | token = lfirst(line);
|
626 | 627 |
|
| 628 | + /* Check if it has a CIDR suffix and if so isolate it */ |
| 629 | + cidr_slash = strchr(token,'/'); |
| 630 | + if (cidr_slash) |
| 631 | + *cidr_slash = '\0'; |
| 632 | + |
| 633 | + /* Get the IP address either way */ |
627 | 634 | if(SockAddr_pton(&file_ip_addr, token) < 0)
|
| 635 | + { |
| 636 | + if (cidr_slash) |
| 637 | + *cidr_slash = '/'; |
628 | 638 | goto hba_syntax;
|
| 639 | + } |
629 | 640 |
|
630 |
| - /* Read the mask field. */ |
631 |
| - line = lnext(line); |
632 |
| - if (!line) |
633 |
| - goto hba_syntax; |
634 |
| - token = lfirst(line); |
| 641 | + /* Get the netmask */ |
| 642 | + if (cidr_slash) |
| 643 | + { |
| 644 | + *cidr_slash = '/'; |
| 645 | + if (SockAddr_cidr_mask(&mask, ++cidr_slash, file_ip_addr.sa.sa_family) < 0) |
| 646 | + goto hba_syntax; |
| 647 | + } |
| 648 | + else |
| 649 | + { |
| 650 | + /* Read the mask field. */ |
| 651 | + line = lnext(line); |
| 652 | + if (!line) |
| 653 | + goto hba_syntax; |
| 654 | + token = lfirst(line); |
| 655 | + |
| 656 | + if(SockAddr_pton(&mask, token) < 0) |
| 657 | + goto hba_syntax; |
| 658 | + |
| 659 | + if(file_ip_addr.sa.sa_family != mask.sa.sa_family) |
| 660 | + goto hba_syntax; |
| 661 | + } |
635 | 662 |
|
636 |
| - if(SockAddr_pton(&mask, token) < 0) |
637 |
| - goto hba_syntax; |
638 | 663 |
|
639 |
| - if(file_ip_addr.sa.sa_family != mask.sa.sa_family) |
640 |
| - goto hba_syntax; |
641 | 664 |
|
642 | 665 | /* Read the rest of the line. */
|
643 | 666 | line = lnext(line);
|
|
0 commit comments