- Notifications
You must be signed in to change notification settings - Fork5
Commit080eabe
committed
Fix libpq's behavior when /etc/passwd isn't readable.
Some users run their applications in chroot environments that lack an/etc/passwd file. This means that the current UID's user name and homedirectory are not obtainable. libpq used to be all right with that,so long as the database role name to use was specified explicitly.But commita4c8f14 broke such cases bycausing any failure of pg_fe_getauthname() to be treated as a hard error.In any case it did little to advance its nominal goal of causing errorsin pg_fe_getauthname() to be reported better. So revert that and insteadput some real error-reporting code in place. This requires changes to theAPIs of pg_fe_getauthname() and pqGetpwuid(), since the latter haddeparted from the POSIX-specified API of getpwuid_r() in a way that madeit impossible to distinguish actual lookup errors from "no such user".To allow such failures to be reported, while not failing if the callersupplies a role name, add a second call of pg_fe_getauthname() inconnectOptions2(). This is a tad ugly, and could perhaps be avoided withsome refactoring of PQsetdbLogin(), but I'll leave that idea for later.(Note that the complained-of misbehavior only occurs in PQsetdbLogin,not when using the PQconnect functions, because in the latter we willnever bother to call pg_fe_getauthname() if the user gives a role name.)In passing also clean up the Windows-side usage of GetUserName(): therecommended buffer size is 257 bytes, the passed buffer length shouldbe the buffer size not buffer size less 1, and any error is reportedby GetLastError() not errno.Per report from Christoph Berg. Back-patch to 9.4 where the chrootfailure case was introduced. The generally poor reporting of errorshere is of very long standing, of course, but given the lack of fieldcomplaints about it we won't risk changing these APIs further back(even though they're theoretically internal to libpq).1 parentde6429a commit080eabe
File tree
7 files changed
+97
-43
lines changed- src
- common
- include
- interfaces/libpq
- port
7 files changed
+97
-43
lines changedLines changed: 7 additions & 5 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
26 | 26 |
| |
27 | 27 |
| |
28 | 28 |
| |
29 |
| - | |
30 |
| - | |
| 29 | + | |
| 30 | + | |
31 | 31 |
| |
32 | 32 |
| |
33 | 33 |
| |
| |||
50 | 50 |
| |
51 | 51 |
| |
52 | 52 |
| |
53 |
| - | |
| 53 | + | |
| 54 | + | |
54 | 55 |
| |
55 |
| - | |
| 56 | + | |
56 | 57 |
| |
57 | 58 |
| |
58 | 59 |
| |
59 | 60 |
| |
60 | 61 |
| |
61 |
| - | |
| 62 | + | |
| 63 | + | |
62 | 64 |
| |
63 | 65 |
| |
64 | 66 |
| |
|
Lines changed: 1 addition & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
433 | 433 |
| |
434 | 434 |
| |
435 | 435 |
| |
436 |
| - | |
| 436 | + | |
437 | 437 |
| |
438 | 438 |
| |
439 | 439 |
| |
|
Lines changed: 36 additions & 14 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
714 | 714 |
| |
715 | 715 |
| |
716 | 716 |
| |
717 |
| - | |
718 |
| - | |
| 717 | + | |
| 718 | + | |
| 719 | + | |
719 | 720 |
| |
720 | 721 |
| |
721 |
| - | |
| 722 | + | |
722 | 723 |
| |
| 724 | + | |
723 | 725 |
| |
724 |
| - | |
725 | 726 |
| |
726 | 727 |
| |
727 |
| - | |
728 |
| - | |
| 728 | + | |
| 729 | + | |
| 730 | + | |
729 | 731 |
| |
| 732 | + | |
730 | 733 |
| |
731 | 734 |
| |
732 | 735 |
| |
| 736 | + | |
733 | 737 |
| |
734 | 738 |
| |
735 | 739 |
| |
| |||
741 | 745 |
| |
742 | 746 |
| |
743 | 747 |
| |
744 |
| - | |
745 |
| - | |
746 |
| - | |
747 |
| - | |
748 |
| - | |
749 | 748 |
| |
750 | 749 |
| |
751 | 750 |
| |
| 751 | + | |
| 752 | + | |
| 753 | + | |
| 754 | + | |
752 | 755 |
| |
753 |
| - | |
| 756 | + | |
| 757 | + | |
754 | 758 |
| |
| 759 | + | |
| 760 | + | |
| 761 | + | |
| 762 | + | |
| 763 | + | |
| 764 | + | |
| 765 | + | |
| 766 | + | |
| 767 | + | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
755 | 771 |
| |
756 | 772 |
| |
757 |
| - | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
758 | 780 |
| |
759 | 781 |
| |
760 | 782 |
| |
761 |
| - | |
| 783 | + | |
762 | 784 |
| |
763 | 785 |
| |
764 | 786 |
| |
|
Lines changed: 1 addition & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
19 | 19 |
| |
20 | 20 |
| |
21 | 21 |
| |
22 |
| - | |
| 22 | + | |
23 | 23 |
| |
24 | 24 |
|
Lines changed: 37 additions & 17 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
764 | 764 |
| |
765 | 765 |
| |
766 | 766 |
| |
| 767 | + | |
| 768 | + | |
| 769 | + | |
| 770 | + | |
| 771 | + | |
| 772 | + | |
| 773 | + | |
| 774 | + | |
| 775 | + | |
| 776 | + | |
| 777 | + | |
| 778 | + | |
| 779 | + | |
| 780 | + | |
| 781 | + | |
| 782 | + | |
| 783 | + | |
767 | 784 |
| |
768 | 785 |
| |
769 | 786 |
| |
770 |
| - | |
771 |
| - | |
| 787 | + | |
772 | 788 |
| |
773 | 789 |
| |
774 | 790 |
| |
| |||
1967 | 1983 |
| |
1968 | 1984 |
| |
1969 | 1985 |
| |
| 1986 | + | |
1970 | 1987 |
| |
1971 | 1988 |
| |
1972 | 1989 |
| |
| |||
1987 | 2004 |
| |
1988 | 2005 |
| |
1989 | 2006 |
| |
1990 |
| - | |
1991 |
| - | |
| 2007 | + | |
1992 | 2008 |
| |
1993 | 2009 |
| |
1994 |
| - | |
1995 |
| - | |
1996 |
| - | |
| 2010 | + | |
| 2011 | + | |
| 2012 | + | |
| 2013 | + | |
| 2014 | + | |
| 2015 | + | |
| 2016 | + | |
| 2017 | + | |
| 2018 | + | |
1997 | 2019 |
| |
1998 | 2020 |
| |
1999 | 2021 |
| |
| |||
4605 | 4627 |
| |
4606 | 4628 |
| |
4607 | 4629 |
| |
4608 |
| - | |
| 4630 | + | |
| 4631 | + | |
| 4632 | + | |
| 4633 | + | |
| 4634 | + | |
4609 | 4635 |
| |
4610 | 4636 |
| |
4611 | 4637 |
| |
4612 |
| - | |
4613 |
| - | |
4614 |
| - | |
4615 |
| - | |
4616 |
| - | |
4617 |
| - | |
4618 |
| - | |
4619 |
| - | |
| 4638 | + | |
4620 | 4639 |
| |
4621 | 4640 |
| |
4622 | 4641 |
| |
| |||
5843 | 5862 |
| |
5844 | 5863 |
| |
5845 | 5864 |
| |
5846 |
| - | |
| 5865 | + | |
| 5866 | + | |
5847 | 5867 |
| |
5848 | 5868 |
| |
5849 | 5869 |
| |
|
Lines changed: 2 additions & 1 deletion
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
777 | 777 |
| |
778 | 778 |
| |
779 | 779 |
| |
780 |
| - | |
| 780 | + | |
| 781 | + | |
781 | 782 |
| |
782 | 783 |
| |
783 | 784 |
| |
|
Lines changed: 13 additions & 4 deletions
Original file line number | Diff line number | Diff line change | |
---|---|---|---|
| |||
83 | 83 |
| |
84 | 84 |
| |
85 | 85 |
| |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
86 | 92 |
| |
87 | 93 |
| |
88 | 94 |
| |
| |||
93 | 99 |
| |
94 | 100 |
| |
95 | 101 |
| |
96 |
| - | |
| 102 | + | |
97 | 103 |
| |
98 | 104 |
| |
99 | 105 |
| |
100 | 106 |
| |
101 | 107 |
| |
102 | 108 |
| |
| 109 | + | |
103 | 110 |
| |
| 111 | + | |
| 112 | + | |
104 | 113 |
| |
105 | 114 |
| |
106 |
| - | |
107 | 115 |
| |
| 116 | + | |
108 | 117 |
| |
| 118 | + | |
| 119 | + | |
109 | 120 |
| |
110 |
| - | |
111 |
| - | |
112 | 121 |
| |
113 | 122 |
| |
114 | 123 |
| |
|
0 commit comments
Comments
(0)