Makefile.yp revision 12891
1#
2# Makefile for the NIS databases
3#
4# $Id: Makefile.yp,v 1.1 1995/12/09 04:33:14 wpaul Exp $
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, comment out this next line so
15# that changes to the NIS maps can be propagated to the slave servers.
16# (By default we assume that we are only serving a small domain with
17# only one server.)
18#
19NOPUSH = "True"
20
21# If you want to use a FreeBSD NIS server to serve non-FreeBSD clients
22# (i.e. clients who expect the password field in the passwd maps to be
23# valid) then uncomment this line. This will cause $YPDIR/passwd to
24# be generated with valid password fields. This is insecure: FreeBSD
25# normally only serves the master.passwd maps (which have real encrypted
26# passwords in them) to the superuser on other FreeBSD machines, but
27# non-FreeBSD clients (e.g. SunOS, Solaris (without NIS+), IRIX, HP-UX,
28# etc...) will only work properly in 'unsecure' mode.
29# 
30#UNSECURE = "True"
31
32# These are commands which this Makefile needs to properly rebuild the
33# NIS databases. Don't change these unless you have a good reason. Also
34# be sure not to place an @ in front of /usr/bin/awk: it isn't necessary
35# and it'll break everything in sight.
36#
37AWK = /usr/bin/awk
38RM  = @/bin/rm -f
39RCAT = /bin/cat
40CAT = @$(RCAT)
41
42DBLOAD = /usr/sbin/yp_mkdb -m `hostname`
43MKNETID = /usr/libexec/mknetid
44YPPUSH = /usr/bin/yppush
45DOMAIN = `/bin/domainname`
46REVNETGROUP = /usr/libexec/revnetgroup
47
48YPSRCDIR = /etc
49YPDIR = /var/yp
50YPMAPDIR = $(YPDIR)/$(DOMAIN)
51
52# These are the files from which the NIS databases are built. You may edit
53# these to taste in the event that you wish to keep your NIS source files
54# seperate from your NIS server's actual configuration files. Note that the
55# NIS passwd and master.passwd files are stored in /var/yp: the server's
56# real password database is not used by default. However, you may use
57# the real /etc/passwd and /etc/master.passwd files by:
58#
59#
60# - invoking yppasswdd without the -m option (yppasswdd will use
61#   /etc/master.passwd if no alternate master.passwd file is specified
62#   and do a 'pwd_mkdb' as needed).
63# - Specifying the location of the master.passwd file using the
64#   MASTER_PASSWD variable, i.e.:
65#
66#   # make MASTER_PASSWD=/path/to/some/other/master.passwd
67#
68# - (optionally): editing this Makefile to change the default location.
69#
70# To add a user, edit $(YPDIR)/master.passwd and type 'make'. The raw
71# passwd file will be generated from the master.passwd file automagically.
72#
73ETHERS    = $(YPSRCDIR)/ethers	   # ethernet addresses (for rarpd)
74BOOTPARAMS= $(YPSRCDIR)/bootparams # for booting Sun boxes (bootparamd)
75HOSTS     = $(YPSRCDIR)/hosts
76NETWORKS  = $(YPSRCDIR)/networks
77PROTOCOLS = $(YPSRCDIR)/protocols
78RPC 	  = $(YPSRCDIR)/rpc
79SERVICES  = $(YPSRCDIR)/services
80GROUP     = $(YPSRCDIR)/group
81NETGROUP  = $(YPSRCDIR)/netgroup
82PASSWD    = $(YPDIR)/passwd
83.if !defined(MASTER_PASSWD)
84MASTER    = $(YPDIR)/master.passwd
85.else
86MASTER	  = $(MASTER_PASSWD)
87.endif
88YPSERVERS = $(YPDIR)/ypservers	# List of all NIS servers for a domain
89PUBLICKEY = $(YPSRCDIR)/publickey
90
91target: 
92	@if [ ! -d $(DOMAIN) ]; then mkdir $(DOMAIN); fi; \
93	cd $(DOMAIN) ; echo "NIS Map update started on `date`" ; \
94	make -f ../Makefile all; echo "NIS Map update completed."
95
96# If you don't want some of these maps built, feel free to comment
97# them out from this list.
98# Note that we don't build the ethers or boorparams maps by default
99# since /etc/ethers and /etc/bootparams are not likely to be present
100# on all systems.
101#
102
103all:  master.passwd passwd hosts group networks protocols \
104      rpc services servers netid # publickey netgroup ethers bootparam
105
106ethers:	   ethers.byname ethers.byaddr
107bootparam: bootparams
108hosts:	   hosts.byname hosts.byaddr
109networks:  networks.byaddr networks.byname
110protocols: protocols.bynumber protocols.byname
111rpc:	   rpc.byname rpc.bynumber
112services:  services.byname
113passwd:    passwd.byname passwd.byuid
114group:     group.byname group.bygid
115netgrp:    netgroup
116netid:	   netid.byname
117servers:   ypservers
118publickey: publickey.byname
119
120master.passwd:	master.passwd.byname master.passwd.byuid
121
122
123ypservers: $(YPSERVERS)
124	@echo "Updating $@..."
125	$(RM) $@
126	$(CAT) $(YPSERVERS) | \
127	$(AWK) '{ if ($$1 != "" && $$1 != "#") print $$0"\t"$$0 }' $^ \
128		| $(DBLOAD) -i $(YPSERVERS) -o $(YPMAPDIR)/$@ - $@
129	@if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi
130	@if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi
131
132ethers.byname: $(ETHERS)
133	@echo "Updating $@..."
134	$(RM) $@
135	$(CAT) $(ETHERS) | \
136	$(AWK) '{ if ($$1 != "" && $$1 != "#" && $$1 != "+") \
137		print $$2"\t"$$0 }' $^ | $(DBLOAD) -i $(ETHERS) \
138							-o $(YPMAPDIR)/$@ - $@
139	@if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) -i $(ETHERS) $@; fi
140	@if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi
141
142
143ethers.byaddr: $(ETHERS)
144	@echo "Updating $@..."
145	$(RM) $@
146	$(CAT) $(ETHERS) | \
147	$(AWK) '{ if ($$1 != "" && $$1 != "#" && $$1 != "+") \
148		print $$1"\t"$$0 }' $^ | $(DBLOAD) -i $(ETHERS) \
149							-o $(YPMAPDIR)/$@ - $@
150	@if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi
151	@if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi
152
153
154bootparams: $(BOOTPARAMS)
155	@echo "Updating $@..."
156	$(RM) $@
157	$(CAT) $(BOOTPARAMS) | \
158	$(AWK) '{ if ($$1 != "" && $$1 != "#" && $$1 != "+") \
159		print $$0 }' $^ | $(DBLOAD) -i $(BOOTPARAMS) \
160							-o $(YPMAPDIR)/$@ - $@
161	@if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi
162	@if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi
163
164
165netgroup: $(NETGROUP) netgroup.byhost netgroup.byuser
166	@echo "Updating $@..."
167	$(RM) $@
168	$(CAT) $(NETGROUP) | \
169	$(AWK) '{ if ($$1 != "" && $$1 != "#" && $$1 != "+") \
170		print $$0 }' $^ | $(DBLOAD) -i $(NETGROUP) \
171							-o $(YPMAPDIR)/$@ - $@
172	@if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi
173	@if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi
174	@$(MAKE) -f ../Makefile netid
175
176
177netgroup.byhost: $(NETGROUP)
178	@echo "Updating $@..."
179	$(RM) $@
180	$(CAT) $(NETGROUP) | $(REVNETGROUP) -h -f $(NETGROUP) | \
181	$(AWK) '{ if ($$1 != "" && $$1 != "#" && $$1 != "+") \
182		print $$0 }' $^ | $(DBLOAD) -i $(NETGROUP) \
183							-o $(YPMAPDIR)/$@ - $@
184	@if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi
185	@if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi
186
187
188netgroup.byuser: $(NETGROUP)
189	@echo "Updating $@..."
190	$(RM) $@
191	$(CAT) $(NETGROUP) | $(REVNETGROUP) -u -f $(NETGROUP) | \
192	$(AWK) '{ if ($$1 != "" && $$1 != "#" && $$1 != "+") \
193		print $$0 }' $^ | $(DBLOAD) -i $(NETGROUP) \
194							-o $(YPMAPDIR)/$@ - $@
195	@if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi
196	@if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi
197
198
199hosts.byname: $(HOSTS)
200	@echo "Updating $@..."
201	$(RM) $@
202	$(CAT) $(HOSTS) | \
203	$(AWK) '/^[0-9]/ { for (n=2; n<=NF && $$n !~ "#"; n++) \
204		print $$n"\t"$$0 }' $^ | $(DBLOAD) -i $(HOSTS)  \
205							-o $(YPMAPDIR)/$@ - $@
206	@if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi
207	@if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi
208	@$(MAKE) -f ../Makefile netid
209
210hosts.byaddr: $(HOSTS)
211	@echo "Updating $@..."
212	$(RM) $@
213	$(CAT) $(HOSTS) | \
214	$(AWK) '$$1 !~ "#" { print $$1"\t"$$0 }' $^ \
215		| $(DBLOAD) -i $(HOSTS) -o $(YPMAPDIR)/$@ - $@
216	@if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi
217	@if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi
218	@$(MAKE) -f ../Makefile netid
219
220
221networks.byname: $(NETWORKS)
222	@echo "Updating $@..."
223	$(RM) $@
224	$(CAT) $(NETWORKS) | \
225	$(AWK) \
226	   '$$1 !~ "#"  { print $$1"\t"$$0; \
227			  for (n=3; n<=NF && $$n !~ "#"; n++) \
228			      print $$n"\t"$$0 \
229			}' $^ | $(DBLOAD) -i $(NETWORKS) -o $(YPMAPDIR)/$@ - $@
230	@if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi
231	@if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi
232
233
234networks.byaddr: $(NETWORKS)
235	@echo "Updating $@..."
236	$(RM) $@
237	$(CAT) $(NETWORKS) | \
238	$(AWK) '$$1 !~ "#" { print $$2"\t"$$0 }' $^ \
239		| $(DBLOAD) -i $(NETWORKS) -o $(YPMAPDIR)/$@ - $@
240	@if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi
241	@if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi
242
243
244protocols.byname: $(PROTOCOLS)
245	@echo "Updating $@..."
246	$(RM) $@
247	$(CAT) $(PROTOCOLS) | \
248	$(AWK) \
249	   '$$1 !~ "#"	{ print $$1"\t"$$0; \
250			  for (n=3; n<=NF && $$n !~ "#"; n++) \
251			      print $$n"\t"$$0 \
252			}' $^ | $(DBLOAD) -i $(PROTOCOLS) \
253							-o $(YPMAPDIR)/$@ - $@
254	@if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi
255	@if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi
256
257
258protocols.bynumber: $(PROTOCOLS)
259	@echo "Updating $@..."
260	$(RM) $@
261	$(CAT) $(PROTOCOLS) | \
262	$(AWK) '$$1 !~ "#" { print $$2"\t"$$0 }' $^ \
263		| $(DBLOAD) -i $(PROTOCOLS) -o $(YPMAPDIR)/$@ - $@
264	@if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi
265	@if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi
266
267
268rpc.byname: $(RPC)
269	@echo "Updating $@..."
270	$(RM) $@
271	$(CAT) $(RPC) | \
272	$(AWK) \
273	   '$$1 !~ "#"  { print $$1"\t"$$0; \
274			  for (n=3; n<=NF && $$n !~ "#"; n++) \
275			      print $$n"\t"$$0 \
276			}' $^ | $(DBLOAD) -i $(RPC) -o $(YPMAPDIR)/$@ - $@
277	@if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi
278	@if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi
279
280
281rpc.bynumber: $(RPC)
282	@echo "Updating $@..."
283	$(RM) $@
284	$(CAT) $(RPC) | \
285	$(AWK) '$$1 !~ "#" { print $$2"\t"$$0 }' $^ \
286		| $(DBLOAD)  -i $(RPC) -o $(YPMAPDIR)/$@ - $@
287	@if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi
288	@if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi
289
290
291services.byname: $(SERVICES)
292	@echo "Updating $@..."
293	$(RM) $@
294	$(CAT) $(SERVICES) | \
295	$(AWK) \
296	   '$$1 !~ "#"  { if (index($$2,"udp")) { printf("%s/udp",$$1) } \
297			  else { printf("%s/tcp",$$1) }; print "\t"$$0 \
298			}' $^ | $(DBLOAD) -i $(SERVICES) -o $(YPMAPDIR)/$@ - $@
299	@if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi
300	@if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi
301
302
303publickey.byname: $(PUBLICKEY)
304	@echo "Updating $@..."
305	$(RM) $@
306	$(CAT) $(PUBLICKEY) | \
307	$(AWK) '$$1 !~ "#" { print $$1"\t"$$2 }' $^ \
308		| $(DBLOAD)  -i $(PUBLICKEY) -o $(YPMAPDIR)/$@ - $@
309	@if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi
310	@if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi
311
312
313$(PASSWD): $(MASTER)
314	@echo "Creating new $@ file from $(MASTER)..."
315	$(RM) $@
316	@if [ ! $(UNSECURE) ]; then \
317	$(RCAT) $(MASTER) | \
318	$(AWK) -F: '{if ($$1 != "+") \
319		print $$1":*:"$$3":"$$4":"$$8":"$$9":"$$10}' $^ \
320		> $(PASSWD) ; \
321	else $(RCAT) $(MASTER) | \
322	$(AWK) -F: '{if ($$1 != "+") \
323		print $$1":"$$2":"$$3":"$$4":"$$8":"$$9":"$$10}' $^ \
324		> $(PASSWD) ; fi
325
326
327passwd.byname: $(PASSWD)
328	@echo "Updating $@..."
329	$(RM) $@
330	$(CAT) $(PASSWD) | \
331	$(AWK) -F: '{ if ($$1 != "+") print $$1"\t"$$0 }' $^ \
332		| $(DBLOAD) -i $(PASSWD) -o $(YPMAPDIR)/$@ - $@
333	@if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi
334	@if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi
335
336passwd.byuid: $(PASSWD)
337	@echo "Updating $@..."
338	$(RM) $@
339	$(CAT) $(PASSWD) | \
340	$(AWK) -F: '{ if ($$1 != "+") print $$3"\t"$$0 }' $^ \
341		| $(DBLOAD) -i $(PASSWD) -o $(YPMAPDIR)/$@ - $@
342	@if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi
343	@if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi
344	@$(MAKE) -f ../Makefile netid
345
346
347group.byname: $(GROUP)
348	@echo "Updating $@..."
349	$(RM) $@
350	$(CAT) $(GROUP) | \
351	$(AWK) -F: '{ if ($$1 != "+") print $$1"\t"$$0 }' $^ \
352		| $(DBLOAD) -i $(GROUP) -o $(YPMAPDIR)/$@ - $@
353	@if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi
354	@if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi
355
356
357group.bygid: $(GROUP)
358	@echo "Updating $@..."
359	$(RM) $@
360	$(CAT) $(GROUP) | \
361	$(AWK) -F: '{ if ($$1 != "+") print $$3"\t"$$0 }' $^ \
362		| $(DBLOAD) -i $(GROUP) -o $(YPMAPDIR)/$@ - $@
363	@if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi
364	@if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi
365	@$(MAKE) -f ../Makefile netid
366
367
368netid.byname: $(GROUP) $(PASSWD)
369	@echo "Updating $@..."
370	$(RM) $@
371	@$(MKNETID) $(PASSWD) $(GROUP) `basename \`pwd\`` \
372		| $(DBLOAD) -o $(YPMAPDIR)/$@ - $@
373	@if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi
374	@if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi
375
376
377master.passwd.byname: $(MASTER)
378	@echo "Updating $@..."
379	$(RM) $@
380	$(CAT) $(MASTER) | \
381	$(AWK) -F: '{ if ($$1 != "+") print $$1"\t"$$0 }' $^ \
382		| $(DBLOAD) -i $(MASTER) -o $(YPMAPDIR)/$@ - $@
383	@if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi
384	@if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi
385
386
387master.passwd.byuid: $(MASTER)
388	@echo "Updating $@..."
389	$(RM) $@
390	$(CAT) $(MASTER) | \
391	$(AWK) -F: '{ if ($$1 != "+") print $$3"\t"$$0 }' $^ \
392		| $(DBLOAD) -i $(MASTER) -o $(YPMAPDIR)/$@ - $@
393	@if [ ! $(NOPUSH) ]; then $(YPPUSH) -d $(DOMAIN) $@; fi
394	@if [ ! $(NOPUSH) ]; then echo "Pushed $@ map." ; fi
395