Skip to content

Commit

Permalink
databases/postgresql??-server: honour login class set in /etc/passwd
Browse files Browse the repository at this point in the history
If postgresql_login_class is not set, honour the setting in /etc/passwd.
The previous commit ignored the passwd setting and set the login class
to "default" if it was left unset.

PR:     275851
  • Loading branch information
Palle Girgensohn authored and Palle Girgensohn committed Jan 11, 2024
1 parent 59429c7 commit 4e2b811
Show file tree
Hide file tree
Showing 15 changed files with 145 additions and 100 deletions.
2 changes: 1 addition & 1 deletion databases/postgresql12-server/Makefile
@@ -1,7 +1,7 @@
DISTVERSION?= 12.17
# PORTREVISION must be ?= otherwise, all slave ports get this PORTREVISION and
# not their own. Probably best to keep it at ?=0 when reset here too.
PORTREVISION?= 2
PORTREVISION?= 3

MAINTAINER?= pgsql@FreeBSD.org

Expand Down
22 changes: 12 additions & 10 deletions databases/postgresql12-server/files/pkg-message-server.in
Expand Up @@ -14,7 +14,7 @@ is a periodic script, %%PREFIX%%/etc/periodic/daily/502.pgsql, that
you may find useful. You can use it to backup and perform vacuum on all
databases nightly. Per default, it performs `vacuum analyze'. See the
script for instructions. For autovacuum settings, please review
~postgres/data/postgresql.conf.
~%%PG_USER%%/data/postgresql.conf.

If you plan to access your PostgreSQL server using ODBC, please
consider running the SQL script %%PREFIX%%/share/postgresql/odbc.sql
Expand All @@ -30,28 +30,33 @@ To set limits, environment stuff like locale and collation and other
things, you can set up a class in /etc/login.conf before initializing
the database. Add something similar to this to /etc/login.conf:
---
postgres:\
%%PG_USER%%:\
:lang=en_US.UTF-8:\
:setenv=LC_COLLATE=C:\
:tc=default:
---
and run `cap_mkdb /etc/login.conf'.
Then add 'postgresql_login_class="postgres"' to /etc/rc.conf.
Then add 'postgresql_login_class="%%PG_USER%%"' to /etc/rc.conf, or
set it as the %%PG_USER%% user's login class in /etc/passwd.

======================================================================

To use PostgreSQL, enable it in rc.conf using

sysrc postgresql_enable=yes

To initialize the database, run

%%PREFIX%%/etc/rc.d/postgresql initdb
service postgresql initdb

You can then start PostgreSQL by running:

%%PREFIX%%/etc/rc.d/postgresql start
service postgresql start

For postmaster settings, see ~postgres/data/postgresql.conf
For postmaster settings, see ~%%PG_USER%%/data/postgresql.conf

NB. FreeBSD's PostgreSQL port logs to syslog by default
See ~postgres/data/postgresql.conf for more info
See ~%%PG_USER%%/data/postgresql.conf for more info

NB. If you're not using a checksumming filesystem like ZFS, you might
wish to enable data checksumming. It can be enabled during
Expand All @@ -61,9 +66,6 @@ NB. If you're not using a checksumming filesystem like ZFS, you might
and make sure you understand the performance implications.

======================================================================

To run PostgreSQL at startup, add
'postgresql_enable="YES"' to /etc/rc.conf
EOM
}
]
25 changes: 16 additions & 9 deletions databases/postgresql12-server/files/postgresql.in
Expand Up @@ -11,7 +11,8 @@
# postgresql_data="/var/db/%%PG_USER%%/data%%PG_VERSION%%"
# postgresql_flags="-w -s -m fast"
# postgresql_initdb_flags="--encoding=utf-8 --lc-collate=C"
# postgresql_login_class="default"
# # leave empty to use the login class set in in /etc/passwd:
# postgresql_login_class="my_custom_login_class"
# postgresql_profiles=""
#
# See %%PREFIX%%/share/doc/postgresql/README-server for more info
Expand All @@ -29,12 +30,13 @@ command=%%PREFIX%%/bin/pg_ctl
load_rc_config postgresql

# set defaults
postgresql_enable=${postgresql_enable:-"NO"}
postgresql_flags=${postgresql_flags:-"-w -s -m fast"}
postgresql_user=${postgresql_user:-"%%PG_USER%%"}
eval postgresql_data=${postgresql_data:-"~${postgresql_user}/data%%PG_VERSION%%"}
postgresql_login_class=${postgresql_login_class:-"default"}
postgresql_initdb_flags=${postgresql_initdb_flags:-"--encoding=utf-8 --lc-collate=C"}
: ${postgresql_enable:="NO"}
: ${postgresql_flags:="-w -s -m fast"}
: ${postgresql_user:="%%PG_USER%%"}
eval _pgdir="~${postgresql_user}/data%%PG_VERSION%%"
: ${postgresql_data:="${_pgdir}"}
: ${postgresql_login_class:=""}
: ${postgresql_initdb_flags:="--encoding=utf-8 --lc-collate=C"}

name=postgresql
rcvar=postgresql_enable
Expand Down Expand Up @@ -62,6 +64,7 @@ if [ -n "$2" ]; then
eval postgresql_enable="\${postgresql_${profile}_enable:-${postgresql_enable}}"
eval postgresql_data="\${postgresql_${profile}_data:-${postgresql_data}}"
eval postgresql_flags="\${postgresql_${profile}_flags:-${postgresql_flags}}"
eval postgresql_login_class="\$postgresql_${profile}_login_class:-${postgresql_login_class}}"
eval postgresql_initdb_flags="\${postgresql_${profile}_initdb_flags:-${postgresql_initdb_flags}}"
fi
else
Expand Down Expand Up @@ -104,12 +107,16 @@ command_args="-D ${postgresql_data} ${postgresql_flags}"

postgresql_command()
{
${su_cmd} -l -c ${postgresql_login_class} ${postgresql_user} -c "exec ${command} ${command_args} ${rc_arg}"
${su_cmd} ${postgresql_login_class:+-c ${postgresql_login_class}} \
-l ${postgresql_user} \
-c "exec ${command} ${command_args} ${rc_arg}"
}

postgresql_initdb()
{
${su_cmd} -l -c ${postgresql_login_class} ${postgresql_user} -c "exec %%PREFIX%%/bin/initdb ${postgresql_initdb_flags} -D ${postgresql_data} -U ${postgresql_user}"
${su_cmd} ${postgresql_login_class:+-c ${postgresql_login_class}} \
-l ${postgresql_user} \
-c "exec %%PREFIX%%/bin/initdb ${postgresql_initdb_flags} -D ${postgresql_data} -U ${postgresql_user}"
}

run_rc_command "$1"
2 changes: 1 addition & 1 deletion databases/postgresql13-server/Makefile
@@ -1,7 +1,7 @@
DISTVERSION?= 13.13
# PORTREVISION must be ?= otherwise, all slave ports get this PORTREVISION and
# not their own. Probably best to keep it at ?=0 when reset here too.
PORTREVISION?= 2
PORTREVISION?= 3

MAINTAINER?= pgsql@FreeBSD.org

Expand Down
22 changes: 12 additions & 10 deletions databases/postgresql13-server/files/pkg-message-server.in
Expand Up @@ -14,7 +14,7 @@ is a periodic script, %%PREFIX%%/etc/periodic/daily/502.pgsql, that
you may find useful. You can use it to backup and perform vacuum on all
databases nightly. Per default, it performs `vacuum analyze'. See the
script for instructions. For autovacuum settings, please review
~postgres/data/postgresql.conf.
~%%PG_USER%%/data/postgresql.conf.

If you plan to access your PostgreSQL server using ODBC, please
consider running the SQL script %%PREFIX%%/share/postgresql/odbc.sql
Expand All @@ -30,28 +30,33 @@ To set limits, environment stuff like locale and collation and other
things, you can set up a class in /etc/login.conf before initializing
the database. Add something similar to this to /etc/login.conf:
---
postgres:\
%%PG_USER%%:\
:lang=en_US.UTF-8:\
:setenv=LC_COLLATE=C:\
:tc=default:
---
and run `cap_mkdb /etc/login.conf'.
Then add 'postgresql_login_class="postgres"' to /etc/rc.conf.
Then add 'postgresql_login_class="%%PG_USER%%"' to /etc/rc.conf, or
set it as the %%PG_USER%% user's login class in /etc/passwd.

======================================================================

To use PostgreSQL, enable it in rc.conf using

sysrc postgresql_enable=yes

To initialize the database, run

%%PREFIX%%/etc/rc.d/postgresql initdb
service postgresql initdb

You can then start PostgreSQL by running:

%%PREFIX%%/etc/rc.d/postgresql start
service postgresql start

For postmaster settings, see ~postgres/data/postgresql.conf
For postmaster settings, see ~%%PG_USER%%/data/postgresql.conf

NB. FreeBSD's PostgreSQL port logs to syslog by default
See ~postgres/data/postgresql.conf for more info
See ~%%PG_USER%%/data/postgresql.conf for more info

NB. If you're not using a checksumming filesystem like ZFS, you might
wish to enable data checksumming. It can be enabled during
Expand All @@ -61,9 +66,6 @@ NB. If you're not using a checksumming filesystem like ZFS, you might
and make sure you understand the performance implications.

======================================================================

To run PostgreSQL at startup, add
'postgresql_enable="YES"' to /etc/rc.conf
EOM
}
]
25 changes: 16 additions & 9 deletions databases/postgresql13-server/files/postgresql.in
Expand Up @@ -11,7 +11,8 @@
# postgresql_data="/var/db/%%PG_USER%%/data%%PG_VERSION%%"
# postgresql_flags="-w -s -m fast"
# postgresql_initdb_flags="--encoding=utf-8 --lc-collate=C"
# postgresql_login_class="default"
# # leave empty to use the login class set in in /etc/passwd:
# postgresql_login_class="my_custom_login_class"
# postgresql_profiles=""
#
# See %%PREFIX%%/share/doc/postgresql/README-server for more info
Expand All @@ -29,12 +30,13 @@ command=%%PREFIX%%/bin/pg_ctl
load_rc_config postgresql

# set defaults
postgresql_enable=${postgresql_enable:-"NO"}
postgresql_flags=${postgresql_flags:-"-w -s -m fast"}
postgresql_user=${postgresql_user:-"%%PG_USER%%"}
eval postgresql_data=${postgresql_data:-"~${postgresql_user}/data%%PG_VERSION%%"}
postgresql_login_class=${postgresql_login_class:-"default"}
postgresql_initdb_flags=${postgresql_initdb_flags:-"--encoding=utf-8 --lc-collate=C"}
: ${postgresql_enable:="NO"}
: ${postgresql_flags:="-w -s -m fast"}
: ${postgresql_user:="%%PG_USER%%"}
eval _pgdir="~${postgresql_user}/data%%PG_VERSION%%"
: ${postgresql_data:="${_pgdir}"}
: ${postgresql_login_class:=""}
: ${postgresql_initdb_flags:="--encoding=utf-8 --lc-collate=C"}

name=postgresql
rcvar=postgresql_enable
Expand Down Expand Up @@ -62,6 +64,7 @@ if [ -n "$2" ]; then
eval postgresql_enable="\${postgresql_${profile}_enable:-${postgresql_enable}}"
eval postgresql_data="\${postgresql_${profile}_data:-${postgresql_data}}"
eval postgresql_flags="\${postgresql_${profile}_flags:-${postgresql_flags}}"
eval postgresql_login_class="\$postgresql_${profile}_login_class:-${postgresql_login_class}}"
eval postgresql_initdb_flags="\${postgresql_${profile}_initdb_flags:-${postgresql_initdb_flags}}"
fi
else
Expand Down Expand Up @@ -104,12 +107,16 @@ command_args="-D ${postgresql_data} ${postgresql_flags}"

postgresql_command()
{
${su_cmd} -l -c ${postgresql_login_class} ${postgresql_user} -c "exec ${command} ${command_args} ${rc_arg}"
${su_cmd} ${postgresql_login_class:+-c ${postgresql_login_class}} \
-l ${postgresql_user} \
-c "exec ${command} ${command_args} ${rc_arg}"
}

postgresql_initdb()
{
${su_cmd} -l -c ${postgresql_login_class} ${postgresql_user} -c "exec %%PREFIX%%/bin/initdb ${postgresql_initdb_flags} -D ${postgresql_data} -U ${postgresql_user}"
${su_cmd} ${postgresql_login_class:+-c ${postgresql_login_class}} \
-l ${postgresql_user} \
-c "exec %%PREFIX%%/bin/initdb ${postgresql_initdb_flags} -D ${postgresql_data} -U ${postgresql_user}"
}

run_rc_command "$1"
2 changes: 1 addition & 1 deletion databases/postgresql14-server/Makefile
@@ -1,7 +1,7 @@
DISTVERSION?= 14.10
# PORTREVISION must be ?= otherwise, all slave ports get this PORTREVISION and
# not their own. Probably best to keep it at ?=0 when reset here too.
PORTREVISION?= 2
PORTREVISION?= 3

MAINTAINER?= pgsql@FreeBSD.org

Expand Down
22 changes: 12 additions & 10 deletions databases/postgresql14-server/files/pkg-message-server.in
Expand Up @@ -14,7 +14,7 @@ is a periodic script, %%PREFIX%%/etc/periodic/daily/502.pgsql, that
you may find useful. You can use it to backup and perform vacuum on all
databases nightly. Per default, it performs `vacuum analyze'. See the
script for instructions. For autovacuum settings, please review
~postgres/data/postgresql.conf.
~%%PG_USER%%/data/postgresql.conf.

If you plan to access your PostgreSQL server using ODBC, please
consider running the SQL script %%PREFIX%%/share/postgresql/odbc.sql
Expand All @@ -30,28 +30,33 @@ To set limits, environment stuff like locale and collation and other
things, you can set up a class in /etc/login.conf before initializing
the database. Add something similar to this to /etc/login.conf:
---
postgres:\
%%PG_USER%%:\
:lang=en_US.UTF-8:\
:setenv=LC_COLLATE=C:\
:tc=default:
---
and run `cap_mkdb /etc/login.conf'.
Then add 'postgresql_login_class="postgres"' to /etc/rc.conf.
Then add 'postgresql_login_class="%%PG_USER%%"' to /etc/rc.conf, or
set it as the %%PG_USER%% user's login class in /etc/passwd.

======================================================================

To use PostgreSQL, enable it in rc.conf using

sysrc postgresql_enable=yes

To initialize the database, run

%%PREFIX%%/etc/rc.d/postgresql initdb
service postgresql initdb

You can then start PostgreSQL by running:

%%PREFIX%%/etc/rc.d/postgresql start
service postgresql start

For postmaster settings, see ~postgres/data/postgresql.conf
For postmaster settings, see ~%%PG_USER%%/data/postgresql.conf

NB. FreeBSD's PostgreSQL port logs to syslog by default
See ~postgres/data/postgresql.conf for more info
See ~%%PG_USER%%/data/postgresql.conf for more info

NB. If you're not using a checksumming filesystem like ZFS, you might
wish to enable data checksumming. It can be enabled during
Expand All @@ -61,9 +66,6 @@ NB. If you're not using a checksumming filesystem like ZFS, you might
and make sure you understand the performance implications.

======================================================================

To run PostgreSQL at startup, add
'postgresql_enable="YES"' to /etc/rc.conf
EOM
}
]
25 changes: 16 additions & 9 deletions databases/postgresql14-server/files/postgresql.in
Expand Up @@ -11,7 +11,8 @@
# postgresql_data="/var/db/%%PG_USER%%/data%%PG_VERSION%%"
# postgresql_flags="-w -s -m fast"
# postgresql_initdb_flags="--encoding=utf-8 --lc-collate=C"
# postgresql_login_class="default"
# # leave empty to use the login class set in in /etc/passwd:
# postgresql_login_class="my_custom_login_class"
# postgresql_profiles=""
#
# See %%PREFIX%%/share/doc/postgresql/README-server for more info
Expand All @@ -29,12 +30,13 @@ command=%%PREFIX%%/bin/pg_ctl
load_rc_config postgresql

# set defaults
postgresql_enable=${postgresql_enable:-"NO"}
postgresql_flags=${postgresql_flags:-"-w -s -m fast"}
postgresql_user=${postgresql_user:-"%%PG_USER%%"}
eval postgresql_data=${postgresql_data:-"~${postgresql_user}/data%%PG_VERSION%%"}
postgresql_login_class=${postgresql_login_class:-"default"}
postgresql_initdb_flags=${postgresql_initdb_flags:-"--encoding=utf-8 --lc-collate=C"}
: ${postgresql_enable:="NO"}
: ${postgresql_flags:="-w -s -m fast"}
: ${postgresql_user:="%%PG_USER%%"}
eval _pgdir="~${postgresql_user}/data%%PG_VERSION%%"
: ${postgresql_data:="${_pgdir}"}
: ${postgresql_login_class:=""}
: ${postgresql_initdb_flags:="--encoding=utf-8 --lc-collate=C"}

name=postgresql
rcvar=postgresql_enable
Expand Down Expand Up @@ -62,6 +64,7 @@ if [ -n "$2" ]; then
eval postgresql_enable="\${postgresql_${profile}_enable:-${postgresql_enable}}"
eval postgresql_data="\${postgresql_${profile}_data:-${postgresql_data}}"
eval postgresql_flags="\${postgresql_${profile}_flags:-${postgresql_flags}}"
eval postgresql_login_class="\$postgresql_${profile}_login_class:-${postgresql_login_class}}"
eval postgresql_initdb_flags="\${postgresql_${profile}_initdb_flags:-${postgresql_initdb_flags}}"
fi
else
Expand Down Expand Up @@ -104,12 +107,16 @@ command_args="-D ${postgresql_data} ${postgresql_flags}"

postgresql_command()
{
${su_cmd} -l -c ${postgresql_login_class} ${postgresql_user} -c "exec ${command} ${command_args} ${rc_arg}"
${su_cmd} ${postgresql_login_class:+-c ${postgresql_login_class}} \
-l ${postgresql_user} \
-c "exec ${command} ${command_args} ${rc_arg}"
}

postgresql_initdb()
{
${su_cmd} -l -c ${postgresql_login_class} ${postgresql_user} -c "exec %%PREFIX%%/bin/initdb ${postgresql_initdb_flags} -D ${postgresql_data} -U ${postgresql_user}"
${su_cmd} ${postgresql_login_class:+-c ${postgresql_login_class}} \
-l ${postgresql_user} \
-c "exec %%PREFIX%%/bin/initdb ${postgresql_initdb_flags} -D ${postgresql_data} -U ${postgresql_user}"
}

run_rc_command "$1"
2 changes: 1 addition & 1 deletion databases/postgresql15-server/Makefile
@@ -1,7 +1,7 @@
DISTVERSION?= 15.5
# PORTREVISION must be ?= otherwise, all slave ports get this PORTREVISION and
# not their own. Probably best to keep it at ?=0 when reset here too.
PORTREVISION?= 2
PORTREVISION?= 3

MAINTAINER?= pgsql@FreeBSD.org

Expand Down

0 comments on commit 4e2b811

Please sign in to comment.