1 # $NetBSD: Makefile.yp,v 1.20 2004/12/29 13:08:24 grant Exp $
3 # This is the YP Makefile, used to create and push YP maps.
6 # Invoke with NOPUSH != "" to prevent the maps from being yppushed upon rebuild
10 # Password maps in standard YP are insecure, because the pw_passwd
11 # field is accessible by any user. FreeBSD, NetBSD and OpenBSD have
12 # a common solution: a secure map (generated with makedbm -s) can
13 # only be accessed by a client bound to a privileged port.
15 # Uncomment out the following if you need compatibility with
16 # sites that don't support this feature.
20 # Only include UID's >= ${MINUID} in the maps. Setting this to ~1000
21 # and using uid's > 1000 for users allows heterogeneous system support
22 # where low numbered uids and gids may have different meanings.
26 # In addition, by adding shadow to the list of rules we support
27 # linux and solaris type shadow maps.
41 MAKEDBM= /usr/sbin/makedbm
42 MAKEDBM_S= ${MAKEDBM} -s
43 MKALIAS= /usr/sbin/mkalias
44 MKNETID= /usr/sbin/mknetid
45 REVNETGROUP= /usr/sbin/revnetgroup
48 SENDMAIL= /usr/sbin/sendmail
50 STDETHERS= /usr/sbin/stdethers
51 STDHOSTS= /usr/sbin/stdhosts -n
53 YPPUSH= /usr/sbin/yppush
56 # We have a rule for ypservers, but we don't build it by default, since
57 # it seldom changes (only when slaves are added/deleted).
59 all: passwd aliases ${AMDMAPS} ethers group hosts ipnodes netgroup networks rpc services protocols netid
61 __makedbmesc: .USEBEFORE
62 if [ -f ${.ALLSRC} ]; then \
63 ${SED} -e "s/#.*$$//" ${.ALLSRC} | \
68 for (i = 1; i <= NF; i++) { \
70 if (substr($$i, length($$i), 1) == "\\") { \
71 printf("%s", substr($$i, 1, \
74 printf("%s\n", $$i); \
80 ${SED} -e "/^[ \t]*$$/d" | \
81 ${SORT} | ${MAKEDBM} - ${.ALLSRC:T}; \
84 passwd.time: ${DIR}/master.passwd
85 -@if [ -f ${.ALLSRC} ]; then \
87 if [ "${INSECURE}" != "yes" ]; then \
88 ${CAT} ${.ALLSRC} | ${CUT} -d: -f1-4,8-10 | \
89 ${AWK} -v minuid=${MINUID} \
90 'BEGIN { FS=":"; OFS="\t"; } /^[a-zA-Z0-9_]/ \
91 { if (minuid <= $$3) \
92 print $$1, $$1":*:"$$3":"$$4":"$$5":"$$6":"$$7 }' -|\
93 ${SORT} | ${MAKEDBM} - passwd.byname; \
94 ${CAT} ${.ALLSRC} | ${CUT} -d: -f1-4,8-10 |\
95 ${AWK} -v minuid=${MINUID} \
96 'BEGIN { FS=":"; OFS="\t"; } /^[a-zA-Z0-9_]/ \
97 { if (minuid <= $$3) \
98 print $$3, $$1":*:"$$3":"$$4":"$$5":"$$6":"$$7 }' -|\
99 ${SORT} | ${MAKEDBM} - passwd.byuid; \
101 ${CAT} ${.ALLSRC} | ${CUT} -d: -f1-4,8-10 | \
102 ${AWK} -v minuid=${MINUID} \
103 'BEGIN { FS=":"; OFS="\t"; } /^[a-zA-Z0-9_]/ \
104 { if (minuid <= $$3) \
105 print $$1, $$0 }' - | ${SORT} | \
106 ${MAKEDBM} - passwd.byname; \
107 ${CAT} ${.ALLSRC} | ${CUT} -d: -f1-4,8-10 |\
108 ${AWK} -v minuid=${MINUID} \
109 'BEGIN { FS=":"; OFS="\t"; } /^[a-zA-Z0-9_]/ \
110 { if (minuid <= $$3) \
111 print $$3, $$0 }' - | ${SORT} | \
112 ${MAKEDBM} - passwd.byuid; \
114 ${CAT} ${.ALLSRC} | \
115 ${AWK} 'BEGIN { FS=":"; OFS="\t"; } /^[a-zA-Z0-9_]/ \
116 { print $$1, $$0 }' - | ${SORT} | \
117 ${MAKEDBM_S} - master.passwd.byname; \
118 ${CAT} ${.ALLSRC} | \
119 ${AWK} 'BEGIN { FS=":"; OFS="\t"; } /^[a-zA-Z0-9_]/ \
120 { print $$3, $$0 }' - | ${SORT} | \
121 ${MAKEDBM_S} - master.passwd.byuid; \
122 ${TOUCH} ${.TARGET}; \
123 ${ECHO} "updated passwd"; \
124 if [ ! ${NOPUSH} ]; then \
125 ${YPPUSH} -d ${DOMAIN} passwd.byname; \
126 ${YPPUSH} -d ${DOMAIN} passwd.byuid; \
127 ${YPPUSH} -d ${DOMAIN} master.passwd.byname; \
128 ${YPPUSH} -d ${DOMAIN} master.passwd.byuid; \
129 ${ECHO} "pushed passwd"; \
134 ${ECHO} "couldn't find ${.ALLSRC}"; \
137 # XXX: This does not do modify/expire time correctly.
138 shadow.time: ${DIR}/master.passwd
139 -@if [ -f ${.ALLSRC} ]; then \
141 ${CAT} ${.ALLSRC} | ${CUT} -d: -f1-3 | \
142 ${AWK} -v minuid=${MINUID} \
143 'BEGIN { FS=":"; OFS="\t"; } /^[a-zA-Z0-9_]/ \
144 { if (minuid <= $$3) \
145 print $$1, $$1":"$$2":10779:0:99999:7:::" }' - | \
146 ${SORT} | ${MAKEDBM_S} - shadow.byname; \
147 ${TOUCH} ${.TARGET}; \
148 ${ECHO} "updated shadow"; \
149 if [ ! ${NOPUSH} ]; then \
150 ${YPPUSH} -d ${DOMAIN} shadow.byname; \
151 ${ECHO} "pushed shadow"; \
156 ${ECHO} "couldn't find ${.ALLSRC}"; \
159 aliases.time: ${DIR}/mail/aliases
160 -@if [ -f ${.ALLSRC} ]; then \
161 ${CP} -p ${.ALLSRC} ${DOMAIN}-aliases; \
162 ${SENDMAIL} -bi -oA${PWD}/${DOMAIN}-aliases; \
163 ${MAKEDBM} -u ${DOMAIN}-aliases | ${SORT} | \
164 ${EGREP} -v '(YP_LAST_MODIFIED|YP_MASTER_NAME)' | \
165 ${MAKEDBM} - mail.aliases; \
166 ${MKALIAS} mail.aliases mail.byaddr; \
167 ${TOUCH} ${.TARGET}; \
168 ${RM} ${DOMAIN}-aliases.db ${DOMAIN}-aliases; \
169 ${ECHO} "updated aliases"; \
170 if [ ! ${NOPUSH} ]; then \
171 ${YPPUSH} -d ${DOMAIN} mail.aliases; \
172 ${YPPUSH} -d ${DOMAIN} mail.byaddr; \
173 ${ECHO} "pushed aliases"; \
178 ${ECHO} "couldn't find ${.ALLSRC}"; \
182 .for MAP in ${AMDMAPS}
183 ${MAP}.time: ${AMDDIR}/${MAP} __makedbmesc
184 -@if [ -f ${.ALLSRC} ]; then \
185 ${TOUCH} ${.TARGET}; \
186 ${ECHO} "updated ${MAP}"; \
187 if [ ! ${NOPUSH} ]; then \
188 ${YPPUSH} -d ${DOMAIN} ${MAP}; \
189 ${ECHO} "pushed ${MAP}"; \
194 ${ECHO} "couldn't find ${.ALLSRC}"; \
199 ethers.time: ${DIR}/ethers
200 -@if [ -f ${.ALLSRC} ]; then \
201 ${STDETHERS} ${.ALLSRC} | ${SED} -e s/#.*$$// | \
202 ${AWK} 'BEGIN { FS="\t"; OFS="\t"; } { print $$1, $$0 }' | \
203 ${SORT} | ${MAKEDBM} - ethers.byaddr; \
204 ${STDETHERS} ${.ALLSRC} | \
205 ${AWK} 'BEGIN { FS="\t"; OFS="\t"; } { print $$2, $$0 }' | \
206 ${SORT} | ${MAKEDBM} - ethers.byname; \
207 ${TOUCH} ${.TARGET}; \
208 ${ECHO} "updated ethers"; \
209 if [ ! ${NOPUSH} ]; then \
210 ${YPPUSH} -d ${DOMAIN} ethers.byaddr; \
211 ${YPPUSH} -d ${DOMAIN} ethers.byname; \
212 ${ECHO} "pushed ethers"; \
217 ${ECHO} "couldn't find ${.ALLSRC}"; \
221 group.time: ${DIR}/group
222 -@if [ -f ${.ALLSRC} ]; then \
223 ${AWK} -v mingid=${MINGID} \
224 'BEGIN { FS=":"; OFS="\t"; } /^[a-zA-Z0-9_]/ \
225 { if (mingid <= $$3) print $$1, $$0 }' ${.ALLSRC} | \
226 ${SORT} | ${MAKEDBM} - group.byname; \
227 ${AWK} -v mingid=${MINGID} \
228 'BEGIN { FS=":"; OFS="\t"; } /^[a-zA-Z0-9_]/ \
229 { if (mingid <= $$3) print $$3, $$0 }' ${.ALLSRC} | \
230 ${SORT} | ${MAKEDBM} - group.bygid; \
231 ${TOUCH} ${.TARGET}; \
232 ${ECHO} "updated group"; \
233 if [ ! ${NOPUSH} ]; then \
234 ${YPPUSH} -d ${DOMAIN} group.byname; \
235 ${YPPUSH} -d ${DOMAIN} group.bygid; \
236 ${ECHO} "pushed group"; \
241 ${ECHO} "couldn't find ${.ALLSRC}"; \
245 # Solaris 8 does the following:
246 # - /etc/hosts and hosts.{byname,byaddr} are IPv4 only.
247 # - /etc/inet/ipnodes and ipnodes.{byname,byaddr} are used for protocol
248 # independent name-to-address mapping.
250 # For local name resolution, we made /etc/hosts protocol independent.
251 # For NIS name resolution, we obey Solaris 8 practice.
252 # - We keep hosts.{byname,byaddr} IPv4 only, to be friendly with Solaris 8
254 # - ipnodes.{byname,byaddr} is used for protocol independent mapping.
255 # We generate all the mappings from /etc/hosts, for compatibility with NetBSD
256 # local name resolution.
258 hosts.time: ${DIR}/hosts
259 -@if [ -f ${.ALLSRC} ]; then \
260 ${STDHOSTS} ${.ALLSRC} | ${SED} -e s/#.*$$// | \
261 ${AWK} '{for (i = 2; i <= NF; i++) print $$i, $$0 }' | \
262 ${SORT} | ${MAKEDBM} - hosts.byname; \
263 ${STDHOSTS} ${.ALLSRC} | \
264 ${AWK} 'BEGIN { OFS="\t"; } { print $$1, $$0 }' | \
265 ${SORT} | ${MAKEDBM} - hosts.byaddr; \
266 ${TOUCH} ${.TARGET}; \
267 ${ECHO} "updated hosts"; \
268 if [ ! ${NOPUSH} ]; then \
269 ${YPPUSH} -d ${DOMAIN} hosts.byname; \
270 ${YPPUSH} -d ${DOMAIN} hosts.byaddr; \
271 ${ECHO} "pushed hosts"; \
276 ${ECHO} "couldn't find ${.ALLSRC}"; \
280 ipnodes.time: ${DIR}/hosts
281 -@if [ -f ${.ALLSRC} ]; then \
282 ${STDHOSTS} -n ${.ALLSRC} | ${SED} -e s/#.*$$// | \
283 ${AWK} '{for (i = 2; i <= NF; i++) print $$i, $$0 }' | \
284 ${SORT} | ${MAKEDBM} - ipnodes.byname; \
285 ${STDHOSTS} -n ${.ALLSRC} | \
286 ${AWK} 'BEGIN { OFS="\t"; } { print $$1, $$0 }' | \
287 ${SORT} | ${MAKEDBM} - ipnodes.byaddr; \
288 ${TOUCH} ${.TARGET}; \
289 ${ECHO} "updated ipnodes"; \
290 if [ ! ${NOPUSH} ]; then \
291 ${YPPUSH} -d ${DOMAIN} ipnodes.byname; \
292 ${YPPUSH} -d ${DOMAIN} ipnodes.byaddr; \
293 ${ECHO} "pushed ipnodes"; \
298 ${ECHO} "couldn't find ${.ALLSRC}"; \
302 netgroup.time: ${DIR}/netgroup __makedbmesc
303 -@if [ -f ${.ALLSRC} ]; then \
304 ${CAT} ${.ALLSRC} | ${REVNETGROUP} -u -f - | \
305 ${SORT} | ${MAKEDBM} - netgroup.byuser; \
306 ${CAT} ${.ALLSRC} | ${REVNETGROUP} -h -f - | \
307 ${SORT} | ${MAKEDBM} - netgroup.byhost; \
308 ${TOUCH} ${.TARGET}; \
309 ${ECHO} "updated netgroup"; \
310 if [ ! ${NOPUSH} ]; then \
311 ${YPPUSH} -d ${DOMAIN} netgroup; \
312 ${YPPUSH} -d ${DOMAIN} netgroup.byuser; \
313 ${YPPUSH} -d ${DOMAIN} netgroup.byhost; \
314 ${ECHO} "pushed netgroup"; \
319 ${ECHO} "couldn't find ${.ALLSRC}"; \
323 networks.time: ${DIR}/networks
324 -@if [ -f ${.ALLSRC} ]; then \
325 ${SED} -e "/^#/d" -e s/#.*$$// ${.ALLSRC} | \
326 ${AWK} '{print $$1, $$0; \
327 for (i = 3;i <= NF;i++) print $$i,$$0}' | \
328 ${SORT} | ${MAKEDBM} - networks.byname; \
329 ${AWK} 'BEGIN { OFS="\t"; } $$1 !~ /^#/ { print $$2, $$0 }' \
331 ${SORT} | ${MAKEDBM} - networks.byaddr; \
332 ${TOUCH} ${.TARGET}; \
333 ${ECHO} "updated networks"; \
334 if [ ! ${NOPUSH} ]; then \
335 ${YPPUSH} -d ${DOMAIN} networks.byname; \
336 ${YPPUSH} -d ${DOMAIN} networks.byaddr; \
337 ${ECHO} "pushed networks"; \
342 ${ECHO} "couldn't find ${.ALLSRC}"; \
346 protocols.time: ${DIR}/protocols
347 -@if [ -f ${.ALLSRC} ]; then \
348 ${AWK} 'BEGIN { OFS="\t"; } $$1 !~ /^#/ { print $$2, $$0 }' \
350 ${SORT} | ${MAKEDBM} - protocols.bynumber; \
351 ${SED} -e "/^#/d" -e s/#.*$$// ${.ALLSRC} | \
352 ${AWK} '{print $$1, $$0; \
353 for (i = 3;i <= NF;i++) print $$i,$$0}' | \
354 ${SORT} | ${MAKEDBM} - protocols.byname; \
355 ${TOUCH} ${.TARGET}; \
356 ${ECHO} "updated protocols"; \
357 if [ ! ${NOPUSH} ]; then \
358 ${YPPUSH} -d ${DOMAIN} protocols.bynumber; \
359 ${YPPUSH} -d ${DOMAIN} protocols.byname; \
360 ${ECHO} "pushed protocols"; \
365 ${ECHO} "couldn't find ${.ALLSRC}"; \
370 -@if [ -f ${.ALLSRC} ]; then \
371 ${AWK} 'BEGIN { OFS="\t"; } $$1 !~ /^#/ { print $$2, $$0 }' \
373 ${SORT} | ${MAKEDBM} - rpc.bynumber; \
374 ${TOUCH} ${.TARGET}; \
375 ${ECHO} "updated rpc"; \
376 if [ ! ${NOPUSH} ]; then \
377 ${YPPUSH} -d ${DOMAIN} rpc.bynumber; \
378 ${ECHO} "pushed rpc"; \
383 ${ECHO} "couldn't find ${.ALLSRC}"; \
387 services.time: ${DIR}/services
388 -@if [ -f ${.ALLSRC} ]; then \
389 ${AWK} 'BEGIN { OFS="\t"; } $$1 !~ /^#/ { print $$2, $$0 }' \
391 ${SORT} | ${MAKEDBM} - services.byname; \
392 ${TOUCH} ${.TARGET}; \
393 ${ECHO} "updated services"; \
394 if [ ! ${NOPUSH} ]; then \
395 ${YPPUSH} -d ${DOMAIN} services.byname; \
396 ${ECHO} "pushed services"; \
401 ${ECHO} "couldn't find ${.ALLSRC}"; \
405 netid.time: ${DIR}/passwd ${DIR}/group ${DIR}/hosts ${DIR}/netid
406 -@${MKNETID} -q -d ${DOMAIN} -p ${DIR}/passwd -g ${DIR}/group -h \
407 ${DIR}/hosts -m ${DIR}/netid | \
408 ${SORT} | ${MAKEDBM} - netid.byname; \
409 ${TOUCH} ${.TARGET}; \
410 ${ECHO} "updated netid"; \
411 if [ ! ${NOPUSH} ]; then \
412 ${YPPUSH} -d ${DOMAIN} netid.byname; \
413 ${ECHO} "pushed netid"; \
419 ypservers.time: ${.CURDIR}/ypservers
420 -@${MAKEDBM} ypservers ypservers; \
421 ${TOUCH} ${.TARGET}; \
422 ${ECHO} "updated ypservers"; \
423 if [ ! ${NOPUSH} ]; then \
424 ${YPPUSH} -d ${DOMAIN} ypservers; \
425 ${ECHO} "pushed ypservers"; \
434 ipnodes: ipnodes.time
435 aliases: aliases.time
436 .for MAP in ${AMDMAPS}
440 netgroup: netgroup.time
441 networks: networks.time
443 services: services.time
445 protocols: protocols.time
447 ypservers: ypservers.time
453 .for MAP in ${AMDMAPS}
457 ${DIR}/master.passwd: