]>
Commit | Line | Data |
---|---|---|
19361cb7 | 1 | # Makefile to (re-)generate db versions of system database files. |
04277e02 | 2 | # Copyright (C) 1996-2019 Free Software Foundation, Inc. |
19361cb7 UD |
3 | # This file is part of the GNU C Library. |
4 | # Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996. | |
5 | # | |
41bdb6e2 | 6 | |
19361cb7 | 7 | # The GNU C Library is free software; you can redistribute it and/or |
41bdb6e2 AJ |
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. | |
19361cb7 UD |
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 | |
41bdb6e2 AJ |
15 | # Lesser General Public License for more details. |
16 | ||
17 | # You should have received a copy of the GNU Lesser General Public | |
59ba27a6 PE |
18 | # License along with the GNU C Library; if not, see |
19 | # <http://www.gnu.org/licenses/>. | |
19361cb7 | 20 | |
6e953631 | 21 | DATABASES = $(wildcard /etc/passwd /etc/group /etc/ethers /etc/protocols \ |
2666d441 UD |
22 | /etc/rpc /etc/services /etc/shadow /etc/gshadow \ |
23 | /etc/netgroup) | |
6e953631 UD |
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 | |
2c61c19f | 34 | @printf %s "$(patsubst %.db,%,$(@F))... " |
2666d441 | 35 | @$(AWK) 'BEGIN { FS=":"; OFS=":" } \ |
ecb9d3e1 UD |
36 | /^[ \t]*$$/ { next } \ |
37 | /^[ \t]*#/ { next } \ | |
6e953631 | 38 | /^[^#]/ { printf ".%s ", $$1; print; \ |
74015205 | 39 | printf "=%s ", $$3; print }' $^ | \ |
6e953631 UD |
40 | $(MAKEDB) -o $@ - |
41 | @echo "done." | |
42 | ||
43 | $(VAR_DB)/group.db: /etc/group | |
2c61c19f | 44 | @printf %s "$(patsubst %.db,%,$(@F))... " |
2666d441 | 45 | @$(AWK) 'BEGIN { FS=":"; OFS=":" } \ |
ecb9d3e1 UD |
46 | /^[ \t]*$$/ { next } \ |
47 | /^[ \t]*#/ { next } \ | |
6e953631 | 48 | /^[^#]/ { printf ".%s ", $$1; print; \ |
9f2da732 UD |
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) \ | |
98591e58 | 61 | printf ":%s %s %s\n", mem, mem, members[mem]; }' $^ | \ |
6e953631 UD |
62 | $(MAKEDB) -o $@ - |
63 | @echo "done." | |
64 | ||
65 | $(VAR_DB)/ethers.db: /etc/ethers | |
2c61c19f | 66 | @printf %s "$(patsubst %.db,%,$(@F))... " |
2666d441 | 67 | @$(AWK) '/^[ \t]*$$/ { next } \ |
ecb9d3e1 | 68 | /^[ \t]*#/ { next } \ |
afd4eb37 | 69 | /^[^#]/ { printf ".%s ", $$1; print; \ |
6e953631 UD |
70 | printf "=%s ", $$2; print }' $^ | \ |
71 | $(MAKEDB) -o $@ - | |
72 | @echo "done." | |
73 | ||
74 | $(VAR_DB)/protocols.db: /etc/protocols | |
2c61c19f | 75 | @printf %s "$(patsubst %.db,%,$(@F))... " |
2666d441 | 76 | @$(AWK) '/^[ \t]*$$/ { next } \ |
ecb9d3e1 | 77 | /^[ \t]*#/ { next } \ |
afd4eb37 | 78 | /^[^#]/ { printf ".%s ", $$1; print; \ |
6e953631 UD |
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 | |
2c61c19f | 86 | @printf %s "$(patsubst %.db,%,$(@F))... " |
2666d441 | 87 | @$(AWK) '/^[ \t]*$$/ { next } \ |
ecb9d3e1 | 88 | /^[ \t]*#/ { next } \ |
afd4eb37 | 89 | /^[^#]/ { printf ".%s ", $$1; print; \ |
6e953631 UD |
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 | |
2c61c19f | 97 | @printf %s "$(patsubst %.db,%,$(@F))... " |
2666d441 | 98 | @$(AWK) 'BEGIN { FS="[ \t/]+" } \ |
ecb9d3e1 UD |
99 | /^[ \t]*$$/ { next } \ |
100 | /^[ \t]*#/ { next } \ | |
2666d441 UD |
101 | /^[^#]/ { sub(/[ \t]*#.*$$/, "");\ |
102 | printf ":%s/%s ", $$1, $$3; print; \ | |
103 | printf ":%s/ ", $$1; print; \ | |
6e953631 | 104 | printf "=%s/%s ", $$2, $$3; print; \ |
ecb9d3e1 | 105 | printf "=%s/ ", $$2; print; \ |
6e953631 | 106 | for (i = 4; i <= NF && !($$i ~ /^#/); ++i) \ |
2666d441 UD |
107 | { printf ":%s/%s ", $$i, $$3; print; \ |
108 | printf ":%s/ ", $$i; print } }' $^ | \ | |
6e953631 UD |
109 | $(MAKEDB) -o $@ - |
110 | @echo "done." | |
111 | ||
112 | $(VAR_DB)/shadow.db: /etc/shadow | |
2c61c19f | 113 | @printf %s "$(patsubst %.db,%,$(@F))... " |
2666d441 | 114 | @$(AWK) 'BEGIN { FS=":"; OFS=":" } \ |
ecb9d3e1 UD |
115 | /^[ \t]*$$/ { next } \ |
116 | /^[ \t]*#/ { next } \ | |
6e953631 | 117 | /^[^#]/ { printf ".%s ", $$1; print }' $^ | \ |
361d49e6 | 118 | (umask 077 && $(MAKEDB) -o $@ -) |
6e953631 | 119 | @echo "done." |
361d49e6 UD |
120 | @if chgrp shadow $@ 2>/dev/null; then \ |
121 | chmod g+r $@; \ | |
122 | else \ | |
118bad87 | 123 | chown 0 $@; chgrp 0 $@; chmod 600 $@; \ |
361d49e6 UD |
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 | |
a68b0d31 | 131 | |
2666d441 | 132 | $(VAR_DB)/gshadow.db: /etc/gshadow |
2c61c19f | 133 | @printf %s "$(patsubst %.db,%,$(@F))... " |
2666d441 UD |
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 | ||
a68b0d31 | 152 | $(VAR_DB)/netgroup.db: /etc/netgroup |
2c61c19f | 153 | @printf %s "$(patsubst %.db,%,$(@F))... " |
2666d441 | 154 | @$(AWK) 'BEGIN { ini=1 } \ |
ecb9d3e1 UD |
155 | /^[ \t]*$$/ { next } \ |
156 | /^[ \t]*#/ { next } \ | |
2666d441 UD |
157 | /^[^#]/ { if (sub(/[ \t]*\\$$/, " ") == 0) end="\n"; \ |
158 | else end=""; \ | |
a68b0d31 | 159 | gsub(/[ \t]+/, " "); \ |
2666d441 UD |
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" }' $^ | \ | |
a68b0d31 UD |
165 | $(MAKEDB) -o $@ - |
166 | @echo "done." |