Makefile 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. # Makefile to (re-)generate db versions of system database files.
  2. # Copyright (C) 1996-2021 Free Software Foundation, Inc.
  3. # This file is part of the GNU C Library.
  4. # Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
  5. #
  6. # The GNU C Library is free software; you can redistribute it and/or
  7. # modify it under the terms of the GNU Lesser General Public
  8. # License as published by the Free Software Foundation; either
  9. # version 2.1 of the License, or (at your option) any later version.
  10. # The GNU C Library is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. # Lesser General Public License for more details.
  14. # You should have received a copy of the GNU Lesser General Public
  15. # License along with the GNU C Library; if not, see
  16. # <https://www.gnu.org/licenses/>.
  17. DATABASES = $(wildcard /etc/passwd /etc/group /etc/ethers /etc/protocols \
  18. /etc/rpc /etc/services /etc/shadow /etc/gshadow \
  19. /etc/netgroup)
  20. VAR_DB = /var/db
  21. AWK = awk
  22. MAKEDB = makedb --quiet
  23. all: $(patsubst %,$(VAR_DB)/%.db,$(notdir $(DATABASES)))
  24. $(VAR_DB)/passwd.db: /etc/passwd
  25. @printf %s "$(patsubst %.db,%,$(@F))... "
  26. @$(AWK) 'BEGIN { FS=":"; OFS=":" } \
  27. /^[ \t]*$$/ { next } \
  28. /^[ \t]*#/ { next } \
  29. /^[^#]/ { printf ".%s ", $$1; print; \
  30. printf "=%s ", $$3; print }' $^ | \
  31. $(MAKEDB) -o $@ -
  32. @echo "done."
  33. $(VAR_DB)/group.db: /etc/group
  34. @printf %s "$(patsubst %.db,%,$(@F))... "
  35. @$(AWK) 'BEGIN { FS=":"; OFS=":" } \
  36. /^[ \t]*$$/ { next } \
  37. /^[ \t]*#/ { next } \
  38. /^[^#]/ { printf ".%s ", $$1; print; \
  39. printf "=%s ", $$3; print; \
  40. if ($$4 != "") { \
  41. split($$4, grmems, ","); \
  42. for (memidx in grmems) { \
  43. mem=grmems[memidx]; \
  44. if (members[mem] == "") \
  45. members[mem]=$$3; \
  46. else \
  47. members[mem]=members[mem] "," $$3; \
  48. } \
  49. delete grmems; } } \
  50. END { for (mem in members) \
  51. printf ":%s %s %s\n", mem, mem, members[mem]; }' $^ | \
  52. $(MAKEDB) -o $@ -
  53. @echo "done."
  54. $(VAR_DB)/ethers.db: /etc/ethers
  55. @printf %s "$(patsubst %.db,%,$(@F))... "
  56. @$(AWK) '/^[ \t]*$$/ { next } \
  57. /^[ \t]*#/ { next } \
  58. /^[^#]/ { printf ".%s ", $$1; print; \
  59. printf "=%s ", $$2; print }' $^ | \
  60. $(MAKEDB) -o $@ -
  61. @echo "done."
  62. $(VAR_DB)/protocols.db: /etc/protocols
  63. @printf %s "$(patsubst %.db,%,$(@F))... "
  64. @$(AWK) '/^[ \t]*$$/ { next } \
  65. /^[ \t]*#/ { next } \
  66. /^[^#]/ { printf ".%s ", $$1; print; \
  67. printf "=%s ", $$2; print; \
  68. for (i = 3; i <= NF && !($$i ~ /^#/); ++i) \
  69. { printf ".%s ", $$i; print } }' $^ | \
  70. $(MAKEDB) -o $@ -
  71. @echo "done."
  72. $(VAR_DB)/rpc.db: /etc/rpc
  73. @printf %s "$(patsubst %.db,%,$(@F))... "
  74. @$(AWK) '/^[ \t]*$$/ { next } \
  75. /^[ \t]*#/ { next } \
  76. /^[^#]/ { printf ".%s ", $$1; print; \
  77. printf "=%s ", $$2; print; \
  78. for (i = 3; i <= NF && !($$i ~ /^#/); ++i) \
  79. { printf ".%s ", $$i; print } }' $^ | \
  80. $(MAKEDB) -o $@ -
  81. @echo "done."
  82. $(VAR_DB)/services.db: /etc/services
  83. @printf %s "$(patsubst %.db,%,$(@F))... "
  84. @$(AWK) 'BEGIN { FS="[ \t/]+" } \
  85. /^[ \t]*$$/ { next } \
  86. /^[ \t]*#/ { next } \
  87. /^[^#]/ { sub(/[ \t]*#.*$$/, "");\
  88. printf ":%s/%s ", $$1, $$3; print; \
  89. printf ":%s/ ", $$1; print; \
  90. printf "=%s/%s ", $$2, $$3; print; \
  91. printf "=%s/ ", $$2; print; \
  92. for (i = 4; i <= NF && !($$i ~ /^#/); ++i) \
  93. { printf ":%s/%s ", $$i, $$3; print; \
  94. printf ":%s/ ", $$i; print } }' $^ | \
  95. $(MAKEDB) -o $@ -
  96. @echo "done."
  97. $(VAR_DB)/shadow.db: /etc/shadow
  98. @printf %s "$(patsubst %.db,%,$(@F))... "
  99. @$(AWK) 'BEGIN { FS=":"; OFS=":" } \
  100. /^[ \t]*$$/ { next } \
  101. /^[ \t]*#/ { next } \
  102. /^[^#]/ { printf ".%s ", $$1; print }' $^ | \
  103. (umask 077 && $(MAKEDB) -o $@ -)
  104. @echo "done."
  105. @if chgrp shadow $@ 2>/dev/null; then \
  106. chmod g+r $@; \
  107. else \
  108. chown 0 $@; chgrp 0 $@; chmod 600 $@; \
  109. echo; \
  110. echo "Warning: The shadow password database $@"; \
  111. echo "has been set to be readable only by root. You may want"; \
  112. echo "to make it readable by the \`shadow' group depending"; \
  113. echo "on your configuration."; \
  114. echo; \
  115. fi
  116. $(VAR_DB)/gshadow.db: /etc/gshadow
  117. @printf %s "$(patsubst %.db,%,$(@F))... "
  118. @$(AWK) 'BEGIN { FS=":"; OFS=":" } \
  119. /^[ \t]*$$/ { next } \
  120. /^[ \t]*#/ { next } \
  121. /^[^#]/ { printf ".%s ", $$1; print }' $^ | \
  122. (umask 077 && $(MAKEDB) -o $@ -)
  123. @echo "done."
  124. @if chgrp shadow $@ 2>/dev/null; then \
  125. chmod g+r $@; \
  126. else \
  127. chown 0 $@; chgrp 0 $@; chmod 600 $@; \
  128. echo; \
  129. echo "Warning: The shadow group database $@"; \
  130. echo "has been set to be readable only by root. You may want"; \
  131. echo "to make it readable by the \`shadow' group depending"; \
  132. echo "on your configuration."; \
  133. echo; \
  134. fi
  135. $(VAR_DB)/netgroup.db: /etc/netgroup
  136. @printf %s "$(patsubst %.db,%,$(@F))... "
  137. @$(AWK) 'BEGIN { ini=1 } \
  138. /^[ \t]*$$/ { next } \
  139. /^[ \t]*#/ { next } \
  140. /^[^#]/ { if (sub(/[ \t]*\\$$/, " ") == 0) end="\n"; \
  141. else end=""; \
  142. gsub(/[ \t]+/, " "); \
  143. sub(/^[ \t]*/, ""); \
  144. if (ini == 0) printf "%s%s", $$0, end; \
  145. else printf ".%s %s%s", $$1, $$0, end; \
  146. ini=end == "" ? 0 : 1; } \
  147. END { if (ini==0) printf "\n" }' $^ | \
  148. $(MAKEDB) -o $@ -
  149. @echo "done."