db-Makefile 5.2 KB

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