Collection of DPF-based plugins for packaging
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

111 lines
4.3KB

  1. # ===========================================================================
  2. # https://www.gnu.org/software/autoconf-archive/ax_pgsql_priv_root.html
  3. # ===========================================================================
  4. #
  5. # SYNOPSIS
  6. #
  7. # AX_PGSQL_PRIV_ROOT(DB, USER, [HOST], [PASSWORD], [ACTION_IF_FAILED], [ACTION_IF_OK])
  8. #
  9. # DESCRIPTION
  10. #
  11. # This macro checks wether the given PostgreSQL user has root privileges
  12. # (can create and drop databases) It is recommended to first call
  13. # AX_CHECK_PGSQL_DB, this makes it easier to locate the cause of error.
  14. # The macro AX_PROG_PGCLIENT is required by this one.
  15. #
  16. # The variable $pgclient_root_call is set for later use in Makefiles, if
  17. # you'd like to make use of this, you must do
  18. #
  19. # AC_SUBST(pgclient_root_call)
  20. #
  21. # after having called AX_CHECK_PGSQL_PRIV_ROOT. You can then do something
  22. # like the following in your Makefile.am:
  23. #
  24. # @pgclient_root_call@ -f file.sql
  25. #
  26. # If you want the user to set the data, you should support something like
  27. # these configure options:
  28. #
  29. # AC_ARG_WITH(pgsql-host,
  30. # [ --with-pgsql-host=HOST server is running on HOST @<:@local socket@:>@],
  31. # [pg_host=$withval], [pg_host=])
  32. #
  33. # AC_ARG_WITH(pgsql-db,
  34. # [ --with-pgsql-db=DBNAME use database DBNAME @<:@test@:>@],
  35. # [pg_db=$withval], [pg_db=test])
  36. #
  37. # AC_ARG_WITH(pgsql-root-user,
  38. # [ --with-pgsql-root-user=USER use user USER, must have root (all) privileges @<:@postgres@:>@],
  39. # [pg_root_user=$withval], [pg_root_user=postgres])
  40. #
  41. # AC_ARG_WITH(pgsql-password,
  42. # [ --with-pgsql-password=PASSWORD use password PASSWORD @<:@none@:>@],
  43. # [pg_password=$withval], [pg_password=""])
  44. #
  45. # You can then call the macro like this:
  46. #
  47. # AX_CHECK_PGSQL_PRIV_ROOT([$pg_db], [$pg_root_user], [$pg_host], [$pg_password], [AC_MSG_ERROR([We need root privileges on database!])])
  48. #
  49. # LICENSE
  50. #
  51. # Copyright (c) 2008 Moritz Sinn <moritz@freesources.org>
  52. #
  53. # This program is free software; you can redistribute it and/or modify it
  54. # under the terms of the GNU General Public License as published by the
  55. # Free Software Foundation; either version 2 of the License, or (at your
  56. # option) any later version.
  57. #
  58. # This program is distributed in the hope that it will be useful, but
  59. # WITHOUT ANY WARRANTY; without even the implied warranty of
  60. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
  61. # Public License for more details.
  62. #
  63. # You should have received a copy of the GNU General Public License along
  64. # with this program. If not, see <https://www.gnu.org/licenses/>.
  65. #
  66. # As a special exception, the respective Autoconf Macro's copyright owner
  67. # gives unlimited permission to copy, distribute and modify the configure
  68. # scripts that are the output of Autoconf when processing the Macro. You
  69. # need not follow the terms of the GNU General Public License when using
  70. # or distributing such scripts, even though portions of the text of the
  71. # Macro appear in them. The GNU General Public License (GPL) does govern
  72. # all other use of the material that constitutes the Autoconf Macro.
  73. #
  74. # This special exception to the GPL applies to versions of the Autoconf
  75. # Macro released by the Autoconf Archive. When you make and distribute a
  76. # modified version of the Autoconf Macro, you may extend this special
  77. # exception to the GPL to apply to your modified version as well.
  78. #serial 5
  79. AC_DEFUN([AX_CHECK_PGSQL_PRIV_ROOT], [
  80. AC_REQUIRE([AX_PROG_PGCLIENT])dnl
  81. AC_REQUIRE([AX_CHECK_PGSQL_DB])dnl
  82. AC_MSG_CHECKING([if PostgreSQL user $2 has root privileges])
  83. pgclient_root_call="$pgclient"
  84. if test "x$1" != "x"; then
  85. pgclient_root_call="$pgclient_root_call dbname=$1";
  86. fi
  87. if test "x$2" != "x"; then
  88. pgclient_root_call="$pgclient_root_call user=$2";
  89. fi
  90. if test "x$3" != "x"; then
  91. pgclient_root_call="$pgclient_root_call host=$3";
  92. fi
  93. if test "x$4" != "x"; then
  94. pgclient_root_call="$pgclient_root_call password=$4";
  95. fi
  96. testdb="test`date +%s`"
  97. echo "CREATE DATABASE $testdb; DROP DATABASE $testdb;" | $pgclient_root_call > /dev/null 2>&1
  98. if test "x$?" = "x0"; then
  99. AC_MSG_RESULT([yes])
  100. $6
  101. else
  102. AC_MSG_RESULT([no])
  103. $5
  104. fi;
  105. ])dnl