1#
2# Makefile for the NIS databases
3#
4# $FreeBSD$
5#
6# This Makefile should only be run on the NIS master server of a domain.
7# All updated maps will be pushed to all NIS slave servers listed in the
8# /var/yp/ypservers file. Please make sure that the hostnames of all
9# NIS servers in your domain are listed in /var/yp/ypservers.
10#
11# This Makefile can be modified to support more NIS maps if desired.
12#
13
14# If this machine is an NIS master, reset this variable (NOPUSH=)
15# in Makefile.local so that changes to the NIS maps can be propagated to
16# the slave servers.  (By default we assume that we are only serving a
17# small domain with only one server.)
18#
19NOPUSH = "True"
20
21# If this machine does not wish to generate a linux-style shadow map
22# from the master.passwd file, reset this variable (SHADOW=) in
23# Makefile.local.
24SHADOW = "True"
25
26# If you want to use a FreeBSD NIS server to serve non-FreeBSD clients
27# (i.e. clients who expect the password field in the passwd maps to be
28# valid) then set this variable (UNSECURE="True") in Makefile.local.
29# This will cause $YPDIR/passwd to be generated with valid password
30# fields.  This is insecure: FreeBSD normally only serves the
31# master.passwd and shadow maps (which have real encrypted passwords
32# in them) to the superuser on other FreeBSD machines, but non-FreeBSD
33# clients (e.g. SunOS, Solaris (without NIS+), IRIX, HP-UX, etc...)
34# will only work properly in 'unsecure' mode.
35# 
36#UNSECURE = "True"
37
38# The following line encodes the YP_INTERDOMAIN key into the hosts.byname
39# and hosts.byaddr maps so that ypserv(8) will do DNS lookups to resolve
40# hosts not in the current domain.  Resetting this variable in
41# Makefile.local (B=) will disable the DNS lookups.
42B=-b
43
44# Normally, the master.passwd.* and shadow.* maps are guarded against access
45# from non-privileged users.  By resetting S in Makefile.local (S=), the
46# YP_SECURE key will be removed from these maps, allowing anyone to access
47# them.
48S=-s
49
50# These are commands which this Makefile needs to properly rebuild the
51# NIS databases. Don't change these unless you have a good reason. Also
52# be sure not to place an @ in front of /usr/bin/awk: it isn't necessary
53# and it'll break everything in sight.
54#
55AWK = /usr/bin/awk
56RM  = @/bin/rm -f
57MV  = @/bin/mv -f
58RMV  = /bin/mv -f
59
60MKDB = /usr/sbin/yp_mkdb
61DBLOAD = $(MKDB) -m `hostname`
62MKNETID = /usr/libexec/mknetid
63NEWALIASES = /usr/bin/newaliases
64YPPUSH = /usr/sbin/yppush
65.if !defined(UPDATE_DOMAIN)
66DOMAIN = `/bin/domainname`
67.else
68DOMAIN = $(UPDATE_DOMAIN)
69.endif
70REVNETGROUP = /usr/libexec/revnetgroup
71TMP = `echo $@.$$$$`
72
73# It is advisable to create a separate directory to contain the
74# source files used to generate your NIS maps. If you intend to
75# support multiple domains, something like /src/dir/$DOMAIN
76# would work well.
77YPSRCDIR = /etc
78.if !defined(YP_DIR)
79YPDIR = /var/yp
80.else
81YPDIR = $(YP_DIR)
82.endif
83YPMAPDIR = $(YPDIR)/$(DOMAIN)
84
85# These are the files from which the NIS databases are built. You may edit
86# these to taste in the event that you wish to keep your NIS source files
87# separate from your NIS server's actual configuration files. Note that the
88# NIS passwd and master.passwd files are stored in /var/yp: the server's
89# real password database is not used by default. However, you may use
90# the real /etc/passwd and /etc/master.passwd files by:
91#
92#
93# - invoking yppasswdd with `-t /etc/master.passwd' (yppasswdd will do a
94#   'pwd_mkdb' as needed if /etc/master.passwd is thus specified).
95# - Specifying the location of the master.passwd file using the
96#   MASTER_PASSWD variable, i.e.:
97#
98#   # make MASTER_PASSWD=/path/to/some/other/master.passwd
99#
100# - (optionally): editing this Makefile to change the default location.
101#
102# To add a user, edit $(YPDIR)/master.passwd and type 'make'. The raw
103# passwd file will be generated from the master.passwd file automagically.
104#
105ETHERS    = $(YPSRCDIR)/ethers	   # ethernet addresses (for rarpd)
106BOOTPARAMS= $(YPSRCDIR)/bootparams # for booting Sun boxes (bootparamd)
107HOSTS     = $(YPSRCDIR)/hosts
108IPNODES   = $(YPDIR)/ipnodes
109NETWORKS  = $(YPSRCDIR)/networks
110PROTOCOLS = $(YPSRCDIR)/protocols
111RPC 	  = $(YPSRCDIR)/rpc
112SERVICES  = $(YPSRCDIR)/services
113SHELLS    = $(YPSRCDIR)/shells
114GROUP     = $(YPSRCDIR)/group
115ALIASES   = $(YPSRCDIR)/mail/aliases
116NETGROUP  = $(YPDIR)/netgroup
117PASSWD    = $(YPDIR)/passwd
118.if !defined(MASTER_PASSWD)
119MASTER    = $(YPDIR)/master.passwd
120.else
121MASTER	  = $(MASTER_PASSWD)
122.endif
123YPSERVERS = $(YPDIR)/ypservers	# List of all NIS servers for a domain
124PUBLICKEY = $(YPSRCDIR)/publickey
125NETID     = $(YPSRCDIR)/netid
126AMDHOST   = $(YPSRCDIR)/amd.map
127
128target: 
129	@if [ ! -d $(DOMAIN) ]; then mkdir $(DOMAIN); fi; \
130	cd $(DOMAIN) ; echo "NIS Map update started on `date` for domain $(DOMAIN)" ; \
131	make -f ../Makefile all; echo "NIS Map update completed."
132
133# Read overrides.  Note, the current directory will be /var/yp/<domain>
134# when 'all' is built.
135.if exists(${YPDIR}/Makefile.local)
136.include "${YPDIR}/Makefile.local"
137.endif
138
139# List of maps that are always built.
140# If you want to omit some of them, feel free to comment
141# them out from this list.
142TARGETS= servers hosts networks protocols rpc services shells group
143#TARGETS+= aliases
144
145# Sanity checks: filter out targets we can't build
146# Note that we don't build the ethers or boorparams maps by default
147# since /etc/ethers and /etc/bootparams are not likely to be present
148# on all systems.
149.if exists($(ETHERS))
150TARGETS+= ethers
151.else
152ETHERS= /dev/null
153.endif
154
155.if exists($(BOOTPARAMS))
156TARGETS+= bootparams
157.else
158BOOTPARAMS= /dev/null
159.endif
160
161.if exists($(NETGROUP))
162TARGETS+= netgrp
163.else
164NETGROUP= /dev/null
165.endif
166
167.if exists($(MASTER))
168TARGETS+= passwd master.passwd netid
169.if ${SHADOW} == "\"True\""
170TARGETS+= shadow
171.endif
172.else
173MASTER= /dev/null
174TARGETS+= nopass
175.endif
176
177.if exists($(PUBLICKEY))
178TARGETS+= publickey
179.else
180PUBLICKEY= /dev/null
181.endif
182
183.if exists($(AMDHOST))
184TARGETS+= amd.map
185.else
186AMDHOST= /dev/null
187.endif
188
189.if exists($(IPNODES))
190TARGETS+= ipnodes
191.else
192IPNODES= /dev/null
193.endif
194
195all: $(TARGETS)
196
197ethers:	   ethers.byname ethers.byaddr
198bootparam: bootparams
199hosts:	   hosts.byname hosts.byaddr
200ipnodes:   ipnodes.byname ipnodes.byaddr
201networks:  networks.byaddr networks.byname
202protocols: protocols.bynumber protocols.byname
203rpc:	   rpc.byname rpc.bynumber
204services:  services.byname
205passwd:    passwd.byname passwd.byuid
206shadow:    shadow.byname shadow.byuid
207group:     group.byname group.bygid
208netgrp:    netgroup
209netid:	   netid.byname
210servers:   ypservers
211publickey: publickey.byname
212aliases:   mail.aliases
213
214master.passwd:	master.passwd.byname master.passwd.byuid
215
216#
217# This is a special target used only when doing in-place updates with
218# rpc.yppasswdd. In this case, the maps will be updated by the rpc.yppasswdd
219# server and won't need to be remade. They will have to be pushed to the
220# slaves however. Calling this target implicitly insures that this will
221# happen.
222#
223pushpw:
224	@$(DBLOAD) -c
225	@if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) master.passwd.byname ; fi
226	@if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) master.passwd.byuid ; fi
227.if ${SHADOW} == "\"True\""
228	@if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) shadow.byname ; fi
229	@if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) shadow.byuid ; fi
230.endif
231	@if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) passwd.byname ; fi
232	@if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) passwd.byuid ; fi
233
234pushmap:
235	@if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $(PUSHMAP) ; fi
236
237nopass:
238	@echo ""
239	@echo "                ********WARNING********"
240	@echo "  Couldn't find the master.passwd source file. This file"
241	@echo "  is needed to generate the master.passwd and passwd maps."
242	@echo "  The default location is /var/yp/master.passwd. You should"
243	@echo "  edit /var/yp/Makefile and set the MASTER variable to point"
244	@echo "  to the source file you wish to use for building the passwd"
245	@echo "  maps, or else invoke make(1) in the following manner:"
246	@echo ""
247	@echo "        make MASTER_PASSWD=/path/to/master.passwd"
248	@echo ""
249
250mail.aliases: $(ALIASES)
251	@echo "Updating $@..."
252	@$(NEWALIASES) -oA$(ALIASES)
253	@$(MKDB) -u $(ALIASES).db \
254		| $(DBLOAD) -i $(ALIASES) -o $(YPMAPDIR)/$@ - $(TMP); \
255		$(RMV) $(TMP) $@
256	@$(DBLOAD) -c
257	@if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi
258	@if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi
259
260
261ypservers: $(YPSERVERS)
262	@echo "Updating $@..."
263	@$(AWK) '{ if ($$1 != "" && $$1 !~ "^#.*") print $$0"\t"$$0 }' \
264		$(YPSERVERS) \
265		| $(DBLOAD) -i $(YPSERVERS) -o $(YPMAPDIR)/$@ - $(TMP); \
266		$(RMV) $(TMP) $@
267	@$(DBLOAD) -c
268	@if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi
269	@if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi
270
271ethers.byname: $(ETHERS)
272	@echo "Updating $@..."
273.if ${ETHERS} == "/dev/null"
274	@echo "Ethers source file not found -- skipping"
275.else
276	@$(AWK) '{ if ($$1 != "" && $$1 !~ "^#.*" && $$1 != "+") \
277		print $$2"\t"$$0 }' $(ETHERS) | $(DBLOAD) -i $(ETHERS) \
278		-o $(YPMAPDIR)/$@ - $(TMP); $(RMV) $(TMP) $@
279	@$(DBLOAD) -c
280	@if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi
281	@if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi
282.endif
283
284ethers.byaddr: $(ETHERS)
285	@echo "Updating $@..."
286.if ${ETHERS} == "/dev/null"
287	@echo "Ethers source file not found -- skipping"
288.else
289	@$(AWK) '{ if ($$1 != "" && $$1 !~ "^#.*" && $$1 != "+") \
290		print $$1"\t"$$0 }' $(ETHERS) | $(DBLOAD) -i $(ETHERS) \
291		-o $(YPMAPDIR)/$@ - $(TMP); $(RMV) $(TMP) $@
292	@$(DBLOAD) -c
293	@if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi
294	@if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi
295.endif
296
297
298bootparams: $(BOOTPARAMS)
299	@echo "Updating $@..."
300.if ${BOOTPARAMS} == "/dev/null"
301	@echo "Bootparams source file not found -- skipping"
302.else
303	@$(AWK) '{ if ($$1 != "" && $$1 !~ "^#.*" && $$1 != "+") \
304		print $$0 }' $(BOOTPARAMS) | $(DBLOAD) -i $(BOOTPARAMS) \
305		-o $(YPMAPDIR)/$@ - $(TMP); $(RMV) $(TMP) $@
306	@$(DBLOAD) -c
307	@if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi
308	@if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi
309.endif
310
311
312netgroup: $(NETGROUP) netgroup.byhost netgroup.byuser
313	@echo "Updating $@..."
314.if ${NETGROUP} == "/dev/null"
315	@echo "Netgroup source file not found -- skipping"
316.else
317	@$(AWK) '{ if ($$1 != "" && $$1 !~ "^#.*" && $$1 != "+") \
318		print $$0 }' $(NETGROUP) | $(DBLOAD) -i $(NETGROUP) \
319		-o $(YPMAPDIR)/$@ - $(TMP); $(RMV) $(TMP) $@
320	@$(DBLOAD) -c
321	@if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi
322	@if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi
323.endif
324
325
326netgroup.byhost: $(NETGROUP)
327	@echo "Updating $@..."
328.if ${NETGROUP} == "/dev/null"
329	@echo "Netgroup source file not found -- skipping"
330.else
331	@$(REVNETGROUP) -h -f $(NETGROUP) | \
332	$(AWK) '{ if ($$1 != "" && $$1 !~ "^#.*" && $$1 != "+") \
333		print $$0 }' | $(DBLOAD) -i $(NETGROUP) \
334		-o $(YPMAPDIR)/$@ - $(TMP); $(RMV) $(TMP) $@
335	@$(DBLOAD) -c
336	@if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi
337	@if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi
338.endif
339
340
341netgroup.byuser: $(NETGROUP)
342	@echo "Updating $@..."
343.if ${NETGROUP} == "/dev/null"
344	@echo "Netgroup source file not found -- skipping"
345.else
346	@$(REVNETGROUP) -u -f $(NETGROUP) | \
347	$(AWK) '{ if ($$1 != "" && $$1 !~ "^#.*" && $$1 != "+") \
348		print $$0 }' | $(DBLOAD) -i $(NETGROUP) \
349		-o $(YPMAPDIR)/$@ - $(TMP); $(RMV) $(TMP) $@
350	@$(DBLOAD) -c
351	@if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi
352	@if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi
353.endif
354
355
356hosts.byname: $(HOSTS)
357	@echo "Updating $@..."
358	@$(AWK) '/^[0-9]/ { for (n=2; n<=NF && $$n !~ "^#.*"; n++) \
359		print $$n"\t"$$0 }' $(HOSTS) | $(DBLOAD) ${B} -i $(HOSTS)  \
360		-o $(YPMAPDIR)/$@ - $(TMP); $(RMV) $(TMP) $@
361	@$(DBLOAD) -c
362	@if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi
363	@if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi
364
365
366hosts.byaddr: $(HOSTS)
367	@echo "Updating $@..."
368	@$(AWK) '$$1 !~ "^#.*" { print $$1"\t"$$0 }' $(HOSTS) \
369		| $(DBLOAD) ${B} -i $(HOSTS) -o $(YPMAPDIR)/$@ - $(TMP); \
370		$(RMV) $(TMP) $@
371	@$(DBLOAD) -c
372	@if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi
373	@if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi
374
375
376ipnodes.byname: $(IPNODES)
377	@echo "Updating $@..."
378.if ${IPNODES} == "/dev/null"
379	@echo "Ipnodes source file not found -- skipping"
380.else
381	@$(AWK) '/^[0-9a-fA-F:]/ { for (n=2; n<=NF && $$n !~ "^#.*"; n++) \
382		print $$n"\t"$$0 }' $(IPNODES) | $(DBLOAD) ${B} -i $(IPNODES)  \
383		-o $(YPMAPDIR)/$@ - $(TMP); $(RMV) $(TMP) $@
384	@$(DBLOAD) -c
385	@if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi
386	@if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi
387.endif
388
389
390ipnodes.byaddr: $(IPNODES)
391	@echo "Updating $@..."
392.if ${IPNODES} == "/dev/null"
393	@echo "Ipnodes source file not found -- skipping"
394.else
395	@$(AWK) '$$1 !~ "^#.*" { print $$1"\t"$$0 }' $(IPNODES) \
396		| $(DBLOAD) ${B} -i $(IPNODES) -o $(YPMAPDIR)/$@ - $(TMP); \
397		$(RMV) $(TMP) $@
398	@$(DBLOAD) -c
399	@if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi
400	@if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi
401.endif
402
403
404networks.byname: $(NETWORKS)
405	@echo "Updating $@..."
406	@$(AWK) \
407	   '$$1 !~ "^#.*"  { print $$1"\t"$$0; \
408			  for (n=3; n<=NF && $$n !~ "^#.*"; n++) \
409			      print $$n"\t"$$0 \
410		}' $(NETWORKS) \
411		| $(DBLOAD) -i $(NETWORKS) -o $(YPMAPDIR)/$@ - $(TMP); \
412		$(RMV) $(TMP) $@
413	@$(DBLOAD) -c
414	@if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi
415	@if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi
416
417
418networks.byaddr: $(NETWORKS)
419	@echo "Updating $@..."
420	@$(AWK) '$$1 !~ "^#.*" { print $$2"\t"$$0 }' $(NETWORKS) \
421		| $(DBLOAD) -i $(NETWORKS) -o $(YPMAPDIR)/$@ - $(TMP); \
422		$(RMV) $(TMP) $@
423	@$(DBLOAD) -c
424	@if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi
425	@if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi
426
427
428protocols.byname: $(PROTOCOLS)
429	@echo "Updating $@..."
430	@$(AWK) \
431	   '$$1 !~ "^#.*"	{ print $$1"\t"$$0; \
432			  for (n=3; n<=NF && $$n !~ "^#.*"; n++) \
433			      print $$n"\t"$$0 \
434			}' $(PROTOCOLS) | $(DBLOAD) -i $(PROTOCOLS) \
435		-o $(YPMAPDIR)/$@ - $(TMP); $(RMV) $(TMP) $@
436	@$(DBLOAD) -c
437	@if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi
438	@if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi
439
440
441protocols.bynumber: $(PROTOCOLS)
442	@echo "Updating $@..."
443	@$(AWK) '$$1 !~ "^#.*" { print $$2"\t"$$0 }' $(PROTOCOLS) \
444		| $(DBLOAD) -i $(PROTOCOLS) -o $(YPMAPDIR)/$@ - $(TMP); \
445		$(RMV) $(TMP) $@
446	@$(DBLOAD) -c
447	@if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi
448	@if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi
449
450
451rpc.byname: $(RPC)
452	@echo "Updating $@..."
453	@$(AWK) \
454	   '$$1 !~ "^#.*"  { print $$1"\t"$$0; \
455			  for (n=3; n<=NF && $$n !~ "^#.*"; n++) \
456			      print $$n"\t"$$0 \
457		}' $(RPC) | $(DBLOAD) -i $(RPC) -o $(YPMAPDIR)/$@ - $(TMP); \
458		$(RMV) $(TMP) $@
459	@$(DBLOAD) -c
460	@if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi
461	@if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi
462
463
464rpc.bynumber: $(RPC)
465	@echo "Updating $@..."
466	@$(AWK) '$$1 !~ "^#.*" { print $$2"\t"$$0 }' $(RPC) \
467		| $(DBLOAD)  -i $(RPC) -o $(YPMAPDIR)/$@ - $(TMP); \
468		$(RMV) $(TMP) $@
469	@$(DBLOAD) -c
470	@if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi
471	@if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi
472
473
474services.byname: $(SERVICES)
475	@echo "Updating $@..."
476	@$(AWK) \
477	   '$$1 !~ "^#.*"  { for (n=1; n<=NF && $$n !~ "^#.*"; n++) { \
478				if (split($$2, t, "/")) { \
479					printf("%s/%s", $$n, t[2]) }; \
480					print "\t"$$0;	\
481					if (n == 1) n = 2; \
482			   } ; print $$2"\t"$$0 ; \
483		}' $(SERVICES) \
484		| $(DBLOAD) -i $(SERVICES) -o $(YPMAPDIR)/$@ - $(TMP); \
485		$(RMV) $(TMP) $@
486	@$(DBLOAD) -c
487	@if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi
488	@if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi
489
490shells: $(SHELLS)
491	@echo "Updating $@..."
492	@$(AWK) '{ if ($$1 != "" && $$1 !~ "^#.*") print $$0"\t"$$0 }' \
493		$(SHELLS) \
494		| $(DBLOAD) -i $(SHELLS) -o $(YPMAPDIR)/$@ - $(TMP); \
495	 $(RMV) $(TMP) $@
496	@$(DBLOAD) -c
497	@if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi
498	@if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi
499
500publickey.byname: $(PUBLICKEY)
501	@echo "Updating $@..."
502.if ${PUBLICKEY} == "/dev/null"
503	@echo "Publickey source file not found -- skipping"
504.else
505	@$(AWK) '$$1 !~ "^#.*" { print $$1"\t"$$2 }' $(PUBLICKEY) \
506		| $(DBLOAD)  -i $(PUBLICKEY) -o $(YPMAPDIR)/$@ - $(TMP); \
507		$(RMV) $(TMP) $@
508	@$(DBLOAD) -c
509	@if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi
510	@if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi
511.endif
512
513
514$(PASSWD): $(MASTER)
515	@echo "Creating new $@ file from $(MASTER)..."
516	@if [ ! $(UNSECURE) ]; then \
517	$(AWK) -F: '{if ($$1 != "" && $$1 !~ "^#.*" && $$1 != "+") \
518		print $$1":*:"$$3":"$$4":"$$8":"$$9":"$$10}' $(MASTER) \
519		> $(PASSWD) ; \
520	else \
521	$(AWK) -F: '{if ($$1 != "" && $$1 !~ "^#.*" && $$1 != "+") \
522		print $$1":"$$2":"$$3":"$$4":"$$8":"$$9":"$$10}' $(MASTER) \
523		> $(PASSWD) ; fi
524
525
526passwd.byname: $(PASSWD)
527	@echo "Updating $@..."
528	@$(AWK) -F: '{ if ($$1 != "" && $$1 !~ "^#.*" && $$1 != "+") \
529		print $$1"\t"$$0 }' $(PASSWD) \
530		| $(DBLOAD) -f -i $(PASSWD) -o $(YPMAPDIR)/$@ - $(TMP); \
531		$(RMV) $(TMP) $@
532	@$(DBLOAD) -c
533	@if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi
534	@if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi
535
536
537passwd.byuid: $(PASSWD)
538	@echo "Updating $@..."
539	@$(AWK) -F: '{ if ($$1 != "" && $$1 !~ "^#.*" && $$1 != "+") \
540		print $$3"\t"$$0 }' $(PASSWD) \
541		| $(DBLOAD) -f -i $(PASSWD) -o $(YPMAPDIR)/$@ - $(TMP); \
542		$(RMV) $(TMP) $@
543	@$(DBLOAD) -c
544	@if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi
545	@if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi
546
547
548group.byname: $(GROUP)
549	@echo "Updating $@..."
550	@$(AWK) -F: '{ if ($$1 != "" && $$1 !~ "^#.*" && $$1 != "+") \
551		print $$1"\t"$$0 }' $(GROUP) \
552		| $(DBLOAD) -f -i $(GROUP) -o $(YPMAPDIR)/$@ - $(TMP); \
553		$(RMV) $(TMP) $@
554	@$(DBLOAD) -c
555	@if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi
556	@if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi
557
558
559group.bygid: $(GROUP)
560	@echo "Updating $@..."
561	@$(AWK) -F: '{ if ($$1 != "" && $$1 !~ "^#.*" && $$1 != "+") \
562		print $$3"\t"$$0 }' $(GROUP) \
563		| $(DBLOAD) -f -i $(GROUP) -o $(YPMAPDIR)/$@ - $(TMP); \
564		$(RMV) $(TMP) $@
565	@$(DBLOAD) -c
566	@if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi
567	@if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi
568
569
570netid.byname: $(GROUP) $(PASSWD) $(HOSTS)
571	@echo "Updating $@..."
572	@$(MKNETID) -q -p $(PASSWD) -g $(GROUP) -h $(HOSTS) -n $(NETID) \
573		-d $(DOMAIN) | $(DBLOAD) -o $(YPMAPDIR)/$@ - $(TMP); \
574		$(RMV) $(TMP) $@
575	@$(DBLOAD) -c
576	@if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi
577	@if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi
578
579
580master.passwd.byname: $(MASTER)
581	@echo "Updating $@..."
582.if ${MASTER} == "/dev/null"
583	@echo "Master.passwd source file not found -- skipping"
584.else
585	@$(AWK) -F: '{ if ($$1 != "" && $$1 !~ "^#.*" && $$1 != "+") \
586		print $$1"\t"$$0 }' $(MASTER) \
587		| $(DBLOAD) ${S} -f -i $(MASTER) -o $(YPMAPDIR)/$@ - $(TMP); \
588		$(RMV) $(TMP) $@
589	@$(DBLOAD) -c
590	@if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi
591	@if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi
592.endif
593
594
595master.passwd.byuid: $(MASTER)
596	@echo "Updating $@..."
597.if ${MASTER} == "/dev/null"
598	@echo "Master.passwd source file not found -- skipping"
599.else
600	@$(AWK) -F: '{ if ($$1 != "" && $$1 !~ "^#.*" && $$1 != "+") \
601		print $$3"\t"$$0 }' $(MASTER) \
602		| $(DBLOAD) ${S} -f -i $(MASTER) -o $(YPMAPDIR)/$@ - $(TMP); \
603		$(RMV) $(TMP) $@
604	@$(DBLOAD) -c
605	@if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi
606	@if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi
607.endif
608
609
610shadow.byname: $(MASTER)
611	@echo "Updating $@..."
612.if ${MASTER} == "/dev/null"
613	@echo "Master.passwd source file not found -- skipping"
614.else
615	@$(AWK) -F: '{ if ($$1 != "" && $$1 !~ "^#.*" && $$1 != "+") \
616		print $$1"\t"$$1":"$$2":12000:0:99999:7:::" }' $(MASTER) \
617		| sed 's/\(	[^:]*:\)\*:/\1!:/' \
618		| $(DBLOAD) ${S} -f -i $(PASSWD) -o $(YPMAPDIR)/$@ - $(TMP); \
619		$(RMV) $(TMP) $@
620	@$(DBLOAD) -c
621	@if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi
622	@if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi
623.endif
624
625shadow.byuid: $(MASTER)
626	@echo "Updating $@..."
627.if ${MASTER} == "/dev/null"
628	@echo "Master.passwd source file not found -- skipping"
629.else
630	@$(AWK) -F: '{ if ($$1 != "" && $$1 !~ "^#.*" && $$1 != "+") \
631		print $$3"\t"$$1":"$$2":12000:0:99999:7:::" }' $(MASTER) \
632		| sed 's/\(	[^:]*:\)\*:/\1!:/' \
633		| $(DBLOAD) ${S} -f -i $(PASSWD) -o $(YPMAPDIR)/$@ - $(TMP); \
634		$(RMV) $(TMP) $@
635	@$(DBLOAD) -c
636	@if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi
637	@if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi
638.endif
639
640amd.map: $(AMDHOST)
641	@echo "Updating $@..."
642	@$(AWK) '$$1 !~ "^#.*"  { \
643	  for (i = 1; i <= NF; i++) \
644	  if (i == NF) { \
645	    if (substr($$i, length($$i), 1) == "\\") \
646	      printf("%s", substr($$i, 1, length($$i) - 1)); \
647	    else \
648	      printf("%s\n", $$i); \
649	  } \
650	  else \
651	    printf("%s ", $$i); \
652	}' $(AMDHOST) | \
653	$(DBLOAD) -i $(AMDHOST) -o $(YPMAPDIR)/$@ - $(TMP); \
654		$(RMV) $(TMP) $@
655	@$(DBLOAD) -c
656	@if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi
657	@if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi
658