diff options
| author | Tom Lane | 2010-04-20 23:48:47 +0000 |
|---|---|---|
| committer | Tom Lane | 2010-04-20 23:48:47 +0000 |
| commit | ea46000a40cf583401504e095ca1a49f57fa0227 (patch) | |
| tree | 759478262148b456ade1c7350bbd7137317e1188 /src/backend/catalog/genbki.pl | |
| parent | 7de2dfccc5868d8ba1c00a6bf7de67d9d50bc7bc (diff) | |
Arrange for client authentication to occur before we select a specific
database to connect to. This is necessary for the walsender code to work
properly (it was previously using an untenable assumption that template1 would
always be available to connect to). This also gets rid of a small security
shortcoming that was introduced in the original patch to eliminate the flat
authentication files: before, you could find out whether or not the requested
database existed even if you couldn't pass the authentication checks.
The changes needed to support this are mainly just to treat pg_authid and
pg_auth_members as nailed relations, so that we can read them without having
to be able to locate real pg_class entries for them. This mechanism was
already debugged for pg_database, but we hadn't recognized the value of
applying it to those catalogs too.
Since the current code doesn't have support for accessing toast tables before
we've brought up all of the relcache, remove pg_authid's toast table to ensure
that no one can store an out-of-line toasted value of rolpassword. The case
seems quite unlikely to occur in practice, and was effectively unsupported
anyway in the old "flatfiles" implementation.
Update genbki.pl to actually implement the same rules as bootstrap.c does for
not-nullability of catalog columns. The previous coding was a bit cheesy but
worked all right for the previous set of bootstrap catalogs. It does not work
for pg_authid, where rolvaliduntil needs to be nullable.
Initdb forced due to minor catalog changes (mainly the toast table removal).
Diffstat (limited to 'src/backend/catalog/genbki.pl')
| -rw-r--r-- | src/backend/catalog/genbki.pl | 37 |
1 files changed, 23 insertions, 14 deletions
diff --git a/src/backend/catalog/genbki.pl b/src/backend/catalog/genbki.pl index 008ae46465e..85d1d717a21 100644 --- a/src/backend/catalog/genbki.pl +++ b/src/backend/catalog/genbki.pl @@ -10,7 +10,7 @@ # Portions Copyright (c) 1996-2010, PostgreSQL Global Development Group # Portions Copyright (c) 1994, Regents of the University of California # -# $PostgreSQL: pgsql/src/backend/catalog/genbki.pl,v 1.7 2010/01/22 16:40:18 rhaas Exp $ +# $PostgreSQL: pgsql/src/backend/catalog/genbki.pl,v 1.8 2010/04/20 23:48:47 tgl Exp $ # #---------------------------------------------------------------------- @@ -183,13 +183,15 @@ foreach my $catname ( @{ $catalogs->{names} } ) # Generate entries for user attributes. my $attnum = 0; + my $priornotnull = 1; my @user_attrs = @{ $table->{columns} }; foreach my $attr (@user_attrs) { $attnum++; - my $row = emit_pgattr_row($table_name, $attr); + my $row = emit_pgattr_row($table_name, $attr, $priornotnull); $row->{attnum} = $attnum; $row->{attstattarget} = '-1'; + $priornotnull &= ($row->{attnotnull} eq 't'); # If it's bootstrapped, put an entry in postgres.bki. if ($is_bootstrap eq ' bootstrap') @@ -221,7 +223,7 @@ foreach my $catname ( @{ $catalogs->{names} } ) foreach my $attr (@SYS_ATTRS) { $attnum--; - my $row = emit_pgattr_row($table_name, $attr); + my $row = emit_pgattr_row($table_name, $attr, 1); $row->{attnum} = $attnum; $row->{attstattarget} = '0'; @@ -308,10 +310,11 @@ exit 0; # Given a system catalog name and a reference to a key-value pair corresponding # to the name and type of a column, generate a reference to a hash that -# represents a pg_attribute entry +# represents a pg_attribute entry. We must also be told whether preceding +# columns were all not-null. sub emit_pgattr_row { - my ($table_name, $attr) = @_; + my ($table_name, $attr, $priornotnull) = @_; my ($attname, $atttype) = %$attr; my %row; @@ -337,15 +340,21 @@ sub emit_pgattr_row $row{attalign} = $type->{typalign}; # set attndims if it's an array type $row{attndims} = $type->{typcategory} eq 'A' ? '1' : '0'; - # This approach to attnotnull is not really good enough; - # we need to know about prior column types too. Look at - # DefineAttr in bootstrap.c. For the moment it's okay for - # the column orders appearing in bootstrapped catalogs. - $row{attnotnull} = - $type->{typname} eq 'oidvector' ? 't' - : $type->{typname} eq 'int2vector' ? 't' - : $type->{typlen} eq 'NAMEDATALEN' ? 't' - : $type->{typlen} > 0 ? 't' : 'f'; + # attnotnull must be set true if the type is fixed-width and + # prior columns are too --- compare DefineAttr in bootstrap.c. + # oidvector and int2vector are also treated as not-nullable. + if ($priornotnull) + { + $row{attnotnull} = + $type->{typname} eq 'oidvector' ? 't' + : $type->{typname} eq 'int2vector' ? 't' + : $type->{typlen} eq 'NAMEDATALEN' ? 't' + : $type->{typlen} > 0 ? 't' : 'f'; + } + else + { + $row{attnotnull} = 'f'; + } last; } } |
