1 # Makefile to (re-)generate db versions of system database files.
2 # Copyright (C) 1996-2015 Free Software Foundation, Inc.
3 # This file is part of the GNU C Library.
4 # Contributed by Ulrich Drepper <drepper@cygnus.com>, 1996.
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.
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.
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/>.
21 DATABASES = $(wildcard /etc/passwd /etc/group /etc/ethers /etc/protocols \
22 /etc/rpc /etc/services /etc/shadow /etc/gshadow \
28 MAKEDB = makedb --quiet
30 all: $(patsubst %,$(VAR_DB)/%.db,$(notdir $(DATABASES)))
33 $(VAR_DB)/passwd.db: /etc/passwd
34 @printf %s "$(patsubst %.db,%,$(@F))... "
35 @$(AWK) 'BEGIN { FS=":"; OFS=":" } \
36 /^[ \t]*$$/ { next } \
38 /^[^#]/ { printf ".%s ", $$1; print; \
39 printf "=%s ", $$3; print }' $^ | \
43 $(VAR_DB)/group.db: /etc/group
44 @printf %s "$(patsubst %.db,%,$(@F))... "
45 @$(AWK) 'BEGIN { FS=":"; OFS=":" } \
46 /^[ \t]*$$/ { next } \
48 /^[^#]/ { printf ".%s ", $$1; print; \
49 printf "=%s ", $$3; print; \
51 split($$4, grmems, ","); \
52 for (memidx in grmems) { \
54 if (members[mem] == "") \
57 members[mem]=members[mem] "," $$3; \
60 END { for (mem in members) \
61 printf ":%s %s %s\n", mem, mem, members[mem]; }' $^ | \
65 $(VAR_DB)/ethers.db: /etc/ethers
66 @printf %s "$(patsubst %.db,%,$(@F))... "
67 @$(AWK) '/^[ \t]*$$/ { next } \
69 /^[^#]/ { printf ".%s ", $$1; print; \
70 printf "=%s ", $$2; print }' $^ | \
74 $(VAR_DB)/protocols.db: /etc/protocols
75 @printf %s "$(patsubst %.db,%,$(@F))... "
76 @$(AWK) '/^[ \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 } }' $^ | \
85 $(VAR_DB)/rpc.db: /etc/rpc
86 @printf %s "$(patsubst %.db,%,$(@F))... "
87 @$(AWK) '/^[ \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 } }' $^ | \
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 } }' $^ | \
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 $@ -)
120 @if chgrp shadow $@ 2>/dev/null; then \
123 chown 0 $@; chgrp 0 $@; chmod 600 $@; \
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."; \
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 $@ -)
140 @if chgrp shadow $@ 2>/dev/null; then \
143 chown 0 $@; chgrp 0 $@; chmod 600 $@; \
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."; \
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"; \
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" }' $^ | \