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