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