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