1 # Makefile to (re-)generate db versions of system database files.
2 # Copyright (C) 1996, 1997, 1998, 2011 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, write to the Free
19 # Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
22 DATABASES = $(wildcard /etc/passwd /etc/group /etc/ethers /etc/protocols \
23 /etc/rpc /etc/services /etc/shadow /etc/gshadow \
29 MAKEDB = makedb --quiet
31 all: $(patsubst %,$(VAR_DB)/%.db,$(notdir $(DATABASES)))
34 $(VAR_DB)/passwd.db: /etc/passwd
35 @echo -n "$(patsubst %.db,%,$(@F))... "
36 @$(AWK) 'BEGIN { FS=":"; OFS=":" } \
37 /^[ \t]*$$/ { next } \
39 /^[^#]/ { printf ".%s ", $$1; print; \
40 printf "=%s ", $$3; print }' $^ | \
44 $(VAR_DB)/group.db: /etc/group
45 @echo -n "$(patsubst %.db,%,$(@F))... "
46 @$(AWK) 'BEGIN { FS=":"; OFS=":" } \
47 /^[ \t]*$$/ { next } \
49 /^[^#]/ { printf ".%s ", $$1; print; \
50 printf "=%s ", $$3; print; \
52 split($$4, grmems, ","); \
53 for (memidx in grmems) { \
55 if (members[mem] == "") \
58 members[mem]=members[mem] "," $$3; \
61 END { for (mem in members) \
62 printf ":%s $s %s\n", mem, mem, members[mem]; }' $^ | \
66 $(VAR_DB)/ethers.db: /etc/ethers
67 @echo -n "$(patsubst %.db,%,$(@F))... "
68 @$(AWK) '/^[ \t]*$$/ { next } \
70 /^[^#]/ { printf ".%s ", $$1; print; \
71 printf "=%s ", $$2; print }' $^ | \
75 $(VAR_DB)/protocols.db: /etc/protocols
76 @echo -n "$(patsubst %.db,%,$(@F))... "
77 @$(AWK) '/^[ \t]*$$/ { next } \
79 /^[^#]/ { printf ".%s ", $$1; print; \
80 printf "=%s ", $$2; print; \
81 for (i = 3; i <= NF && !($$i ~ /^#/); ++i) \
82 { printf ".%s ", $$i; print } }' $^ | \
86 $(VAR_DB)/rpc.db: /etc/rpc
87 @echo -n "$(patsubst %.db,%,$(@F))... "
88 @$(AWK) '/^[ \t]*$$/ { next } \
90 /^[^#]/ { printf ".%s ", $$1; print; \
91 printf "=%s ", $$2; print; \
92 for (i = 3; i <= NF && !($$i ~ /^#/); ++i) \
93 { printf ".%s ", $$i; print } }' $^ | \
97 $(VAR_DB)/services.db: /etc/services
98 @echo -n "$(patsubst %.db,%,$(@F))... "
99 @$(AWK) 'BEGIN { FS="[ \t/]+" } \
100 /^[ \t]*$$/ { next } \
101 /^[ \t]*#/ { next } \
102 /^[^#]/ { sub(/[ \t]*#.*$$/, "");\
103 printf ":%s/%s ", $$1, $$3; print; \
104 printf ":%s/ ", $$1; print; \
105 printf "=%s/%s ", $$2, $$3; print; \
106 printf "=%s/ ", $$2; print; \
107 for (i = 4; i <= NF && !($$i ~ /^#/); ++i) \
108 { printf ":%s/%s ", $$i, $$3; print; \
109 printf ":%s/ ", $$i; print } }' $^ | \
113 $(VAR_DB)/shadow.db: /etc/shadow
114 @echo -n "$(patsubst %.db,%,$(@F))... "
115 @$(AWK) 'BEGIN { FS=":"; OFS=":" } \
116 /^[ \t]*$$/ { next } \
117 /^[ \t]*#/ { next } \
118 /^[^#]/ { printf ".%s ", $$1; print }' $^ | \
119 (umask 077 && $(MAKEDB) -o $@ -)
121 @if chgrp shadow $@ 2>/dev/null; then \
124 chown 0 $@; chgrp 0 $@; chmod 600 $@; \
126 echo "Warning: The shadow password database $@"; \
127 echo "has been set to be readable only by root. You may want"; \
128 echo "to make it readable by the \`shadow' group depending"; \
129 echo "on your configuration."; \
133 $(VAR_DB)/gshadow.db: /etc/gshadow
134 @echo -n "$(patsubst %.db,%,$(@F))... "
135 @$(AWK) 'BEGIN { FS=":"; OFS=":" } \
136 /^[ \t]*$$/ { next } \
137 /^[ \t]*#/ { next } \
138 /^[^#]/ { printf ".%s ", $$1; print }' $^ | \
139 (umask 077 && $(MAKEDB) -o $@ -)
141 @if chgrp shadow $@ 2>/dev/null; then \
144 chown 0 $@; chgrp 0 $@; chmod 600 $@; \
146 echo "Warning: The shadow group database $@"; \
147 echo "has been set to be readable only by root. You may want"; \
148 echo "to make it readable by the \`shadow' group depending"; \
149 echo "on your configuration."; \
153 $(VAR_DB)/netgroup.db: /etc/netgroup
154 @echo -n "$(patsubst %.db,%,$(@F))... "
155 @$(AWK) 'BEGIN { ini=1 } \
156 /^[ \t]*$$/ { next } \
157 /^[ \t]*#/ { next } \
158 /^[^#]/ { if (sub(/[ \t]*\\$$/, " ") == 0) end="\n"; \
160 gsub(/[ \t]+/, " "); \
161 sub(/^[ \t]*/, ""); \
162 if (ini == 0) printf "%s%s", $$0, end; \
163 else printf ".%s %s%s", $$1, $$0, end; \
164 ini=end == "" ? 0 : 1; } \
165 END { if (ini==0) printf "\n" }' $^ | \