1 # Makefile to (re-)generate db versions of system database files.
2 # Copyright (C) 1996-2023 Free Software Foundation, Inc.
3 # This file is part of the GNU C Library.
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.
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
14 # Lesser General Public License for more details.
16 # You should have received a copy of the GNU Lesser General Public
17 # License along with the GNU C Library; if not, see
18 # <https://www.gnu.org/licenses/>.
20 DATABASES = $(wildcard /etc/passwd /etc/group /etc/ethers /etc/protocols \
21 /etc/rpc /etc/services /etc/shadow /etc/gshadow \
27 MAKEDB = makedb --quiet
29 all: $(patsubst %,$(VAR_DB)/%.db,$(notdir $(DATABASES)))
32 $(VAR_DB)/passwd.db: /etc/passwd
33 @printf %s "$(patsubst %.db,%,$(@F))... "
34 @$(AWK) 'BEGIN { FS=":"; OFS=":" } \
35 /^[ \t]*$$/ { next } \
37 /^[^#]/ { printf ".%s ", $$1; print; \
38 printf "=%s ", $$3; print }' $^ | \
42 $(VAR_DB)/group.db: /etc/group
43 @printf %s "$(patsubst %.db,%,$(@F))... "
44 @$(AWK) 'BEGIN { FS=":"; OFS=":" } \
45 /^[ \t]*$$/ { next } \
47 /^[^#]/ { printf ".%s ", $$1; print; \
48 printf "=%s ", $$3; print; \
50 split($$4, grmems, ","); \
51 for (memidx in grmems) { \
53 if (members[mem] == "") \
56 members[mem]=members[mem] "," $$3; \
59 END { for (mem in members) \
60 printf ":%s %s %s\n", mem, mem, members[mem]; }' $^ | \
64 $(VAR_DB)/ethers.db: /etc/ethers
65 @printf %s "$(patsubst %.db,%,$(@F))... "
66 @$(AWK) '/^[ \t]*$$/ { next } \
68 /^[^#]/ { printf ".%s ", $$1; print; \
69 printf "=%s ", $$2; print }' $^ | \
73 $(VAR_DB)/protocols.db: /etc/protocols
74 @printf %s "$(patsubst %.db,%,$(@F))... "
75 @$(AWK) '/^[ \t]*$$/ { next } \
77 /^[^#]/ { printf ".%s ", $$1; print; \
78 printf "=%s ", $$2; print; \
79 for (i = 3; i <= NF && !($$i ~ /^#/); ++i) \
80 { printf ".%s ", $$i; print } }' $^ | \
84 $(VAR_DB)/rpc.db: /etc/rpc
85 @printf %s "$(patsubst %.db,%,$(@F))... "
86 @$(AWK) '/^[ \t]*$$/ { next } \
88 /^[^#]/ { printf ".%s ", $$1; print; \
89 printf "=%s ", $$2; print; \
90 for (i = 3; i <= NF && !($$i ~ /^#/); ++i) \
91 { printf ".%s ", $$i; print } }' $^ | \
95 $(VAR_DB)/services.db: /etc/services
96 @printf %s "$(patsubst %.db,%,$(@F))... "
97 @$(AWK) 'BEGIN { FS="[ \t/]+" } \
98 /^[ \t]*$$/ { next } \
100 /^[^#]/ { sub(/[ \t]*#.*$$/, "");\
101 printf ":%s/%s ", $$1, $$3; print; \
102 printf ":%s/ ", $$1; print; \
103 printf "=%s/%s ", $$2, $$3; print; \
104 printf "=%s/ ", $$2; print; \
105 for (i = 4; i <= NF && !($$i ~ /^#/); ++i) \
106 { printf ":%s/%s ", $$i, $$3; print; \
107 printf ":%s/ ", $$i; print } }' $^ | \
111 $(VAR_DB)/shadow.db: /etc/shadow
112 @printf %s "$(patsubst %.db,%,$(@F))... "
113 @$(AWK) 'BEGIN { FS=":"; OFS=":" } \
114 /^[ \t]*$$/ { next } \
115 /^[ \t]*#/ { next } \
116 /^[^#]/ { printf ".%s ", $$1; print }' $^ | \
117 (umask 077 && $(MAKEDB) -o $@ -)
119 @if chgrp shadow $@ 2>/dev/null; then \
122 chown 0 $@; chgrp 0 $@; chmod 600 $@; \
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."; \
131 $(VAR_DB)/gshadow.db: /etc/gshadow
132 @printf %s "$(patsubst %.db,%,$(@F))... "
133 @$(AWK) 'BEGIN { FS=":"; OFS=":" } \
134 /^[ \t]*$$/ { next } \
135 /^[ \t]*#/ { next } \
136 /^[^#]/ { printf ".%s ", $$1; print }' $^ | \
137 (umask 077 && $(MAKEDB) -o $@ -)
139 @if chgrp shadow $@ 2>/dev/null; then \
142 chown 0 $@; chgrp 0 $@; chmod 600 $@; \
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."; \
151 $(VAR_DB)/netgroup.db: /etc/netgroup
152 @printf %s "$(patsubst %.db,%,$(@F))... "
153 @$(AWK) 'BEGIN { ini=1 } \
154 /^[ \t]*$$/ { next } \
155 /^[ \t]*#/ { next } \
156 /^[^#]/ { if (sub(/[ \t]*\\$$/, " ") == 0) end="\n"; \
158 gsub(/[ \t]+/, " "); \
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" }' $^ | \