xref: /openbsd/usr.sbin/ypserv/ypinit/Makefile.yp (revision 7b36286a)
1#	$OpenBSD: Makefile.yp,v 1.13 2002/11/01 23:54:18 fgsch Exp $
2
3YPDBDIR=/var/yp
4DIR=/etc
5AMDDIR=/etc/amd
6NOPUSH=""
7#
8AWK=/usr/bin/awk
9CAT=/bin/cat
10CP=/bin/cp
11RM=/bin/rm
12CUT=/usr/bin/cut
13ECHO=/bin/echo
14MAKEDBM=/usr/sbin/makedbm
15SED=/usr/bin/sed
16SENDMAIL=/usr/sbin/sendmail
17STDHOSTS=/usr/sbin/stdhosts
18STDETHERS=/usr/sbin/stdethers
19MKALIAS=/usr/sbin/mkalias
20MKNETID=/usr/sbin/mknetid
21REVNETGROUP=/usr/sbin/revnetgroup
22TOUCH=/usr/bin/touch
23DOMAIN="`/usr/bin/basename ${.CURDIR}`"
24YPPUSH=/usr/sbin/yppush
25
26# Password maps in standard YP is unsecure. This is due to the fact that
27# passwords are accessable for anyone. FreeBSD and now OpenBSD has a common
28# solution to this, maps can be secure (makedbm -s). If a map is secure only
29# a privileged user can access it.
30# For secure maps, leave UNSECURE blank.
31MAKEDBM-S=$(MAKEDBM) -s
32UNSECURE="True"
33
34# If you want ypserv to ask DNS for unknown hosts set USEDNS to -b
35USEDNS=
36
37all: passwd group hosts ethers networks rpc services protocols netid netgroup amd.home aliases
38
39passwd.time: $(DIR)/master.passwd
40	-@if [ -f $(>) ]; then \
41		if [ ! $(UNSECURE) ]; then \
42			$(CAT) $(>) | $(CUT) -d: -f1-4,8-10 | \
43			$(AWK) 'BEGIN { FS=":"; OFS="\t"; } /^[a-zA-Z0-9_]/ \
44			{ print $$1, $$1":*:"$$3":"$$4":"$$5":"$$6":"$$7 }' -|\
45			$(MAKEDBM) - passwd.byname; \
46			$(CAT) $(>) | $(CUT) -d: -f1-4,8-10 |\
47			$(AWK) 'BEGIN { FS=":"; OFS="\t"; } /^[a-zA-Z0-9_]/ \
48			{ print $$3, $$1":*:"$$3":"$$4":"$$5":"$$6":"$$7 }' -|\
49			$(MAKEDBM) - passwd.byuid; \
50		else \
51			$(CAT) $(>) | $(CUT) -d: -f1-4,8-10 | \
52			$(AWK) 'BEGIN { FS=":"; OFS="\t"; } /^[a-zA-Z0-9_]/ \
53			{ print $$1, $$0 }' - | $(MAKEDBM) - passwd.byname; \
54			$(CAT) $(>) | $(CUT) -d: -f1-4,8-10 |\
55			$(AWK) 'BEGIN { FS=":"; OFS="\t"; } /^[a-zA-Z0-9_]/ \
56			{ print $$3, $$0 }' - | $(MAKEDBM) - passwd.byuid; \
57		fi; \
58		$(CAT) $(>) | \
59		$(AWK) 'BEGIN { FS=":"; OFS="\t"; } /^[a-zA-Z0-9_]/ \
60		{ print $$1, $$0 }' - | $(MAKEDBM-S) - master.passwd.byname; \
61		$(CAT) $(>) | \
62		$(AWK) 'BEGIN { FS=":"; OFS="\t"; } /^[a-zA-Z0-9_]/ \
63		{ print $$3, $$0 }' - | $(MAKEDBM-S) - master.passwd.byuid; \
64		$(TOUCH) $(@); \
65		$(ECHO) "updated passwd"; \
66		if [ ! $(NOPUSH) ]; then \
67			$(YPPUSH) -d $(DOMAIN) passwd.byname; \
68			$(YPPUSH) -d $(DOMAIN) passwd.byuid; \
69			$(YPPUSH) -d $(DOMAIN) master.passwd.byname; \
70			$(YPPUSH) -d $(DOMAIN) master.passwd.byuid; \
71			$(ECHO) "pushed passwd"; \
72		else \
73			: ; \
74		fi \
75	else \
76		$(ECHO) "couldn't find $(>)"; \
77	fi
78
79
80group.time: $(DIR)/group
81	-@if [ -f $(>) ]; then \
82		$(AWK) 'BEGIN { FS=":"; OFS="\t"; } /^[a-zA-Z0-9_]/ \
83		{ print $$1, $$0 }' $(>) | \
84		$(MAKEDBM) - group.byname; \
85		$(AWK) 'BEGIN { FS=":"; OFS="\t"; } /^[a-zA-Z0-9_]/ \
86		{ print $$3, $$0 }' $(>) | \
87		$(MAKEDBM) - group.bygid; \
88		$(TOUCH) $(@); \
89		$(ECHO) "updated group"; \
90		if [ ! $(NOPUSH) ]; then \
91			$(YPPUSH) -d $(DOMAIN) group.byname; \
92			$(YPPUSH) -d $(DOMAIN) group.bygid; \
93			$(ECHO) "pushed group"; \
94		else \
95			: ; \
96		fi \
97	else \
98		$(ECHO) "couldn't find $(>)"; \
99	fi
100
101hosts.time: $(DIR)/hosts
102	-@if [ -f $(DIR)/hosts ]; then \
103		$(STDHOSTS) $(>) | $(SED) -e s/#.*$$// | \
104		$(AWK) '{for (i = 2; i <= NF; i++) print $$i, $$0 }' | \
105		$(MAKEDBM) $(USEDNS) - hosts.byname; \
106		$(STDHOSTS) $(>) | \
107		$(AWK) 'BEGIN { OFS="\t"; } { print $$1, $$0 }' | \
108		$(MAKEDBM) $(USEDNS) - hosts.byaddr; \
109		$(TOUCH) $(@); \
110		$(ECHO) "updated hosts"; \
111		if [ ! $(NOPUSH) ]; then \
112			$(YPPUSH) -d $(DOMAIN) hosts.byname; \
113			$(YPPUSH) -d $(DOMAIN) hosts.byaddr; \
114			$(ECHO) "pushed hosts"; \
115		else \
116			: ; \
117		fi \
118	else \
119		$(ECHO) "couldn't find $(>)"; \
120	fi
121
122ethers.time: $(DIR)/ethers
123	-@if [ -f $(DIR)/ethers ]; then \
124		$(STDETHERS) $(>) | $(SED) -e s/#.*$$// | \
125		$(AWK) 'BEGIN { FS="\t"; OFS="\t"; } { print $$1, $$0 }' | \
126		$(MAKEDBM) - ethers.byaddr; \
127		$(STDETHERS) $(>) | \
128		$(AWK) 'BEGIN { FS="\t"; OFS="\t"; } { print $$2, $$0 }' | \
129		$(MAKEDBM) - ethers.byname; \
130		$(TOUCH) $(@); \
131		$(ECHO) "updated ethers"; \
132		if [ ! $(NOPUSH) ]; then \
133			$(YPPUSH) -d $(DOMAIN) ethers.byaddr; \
134			$(YPPUSH) -d $(DOMAIN) ethers.byname; \
135			$(ECHO) "pushed ethers"; \
136		else \
137			: ; \
138		fi \
139	else \
140		$(ECHO) "couldn't find $(>)"; \
141	fi
142
143networks.time: $(DIR)/networks
144	-@if [ -f $(>) ]; then \
145		$(SED) -e "/^#/d" -e s/#.*$$// $(>) | \
146		$(AWK) '{print $$1, $$0; for (i = 3;i <= NF;i++) print $$i,$$0}' | \
147		$(MAKEDBM) - networks.byname; \
148		$(AWK) 'BEGIN { OFS="\t"; } $$1 !~ /^#/ { print $$2, $$0 }' $(>) | \
149		$(MAKEDBM) - networks.byaddr; \
150		$(TOUCH) $(@); \
151		$(ECHO) "updated networks"; \
152		if [ ! $(NOPUSH) ]; then \
153			$(YPPUSH) -d $(DOMAIN) networks.byname; \
154			$(YPPUSH) -d $(DOMAIN) networks.byaddr; \
155			$(ECHO) "pushed networks"; \
156		else \
157			: ; \
158		fi \
159	else \
160		$(ECHO) "couldn't find $(>)"; \
161	fi
162
163rpc.time: $(DIR)/rpc
164	-@if [ -f $(>) ]; then \
165		$(AWK) 'BEGIN { OFS="\t"; } $$1 !~ /^#/ { print $$2, $$0 }' $(>) | \
166		$(MAKEDBM) - rpc.bynumber; \
167		$(TOUCH) $(@); \
168		$(ECHO) "updated rpc"; \
169		if [ ! $(NOPUSH) ]; then \
170			$(YPPUSH) -d $(DOMAIN) rpc.bynumber; \
171			$(ECHO) "pushed rpc"; \
172		else \
173			: ; \
174		fi \
175	else \
176		$(ECHO) "couldn't find $(>)"; \
177	fi
178
179
180services.time: $(DIR)/services
181	-@if [ -f $(>) ]; then \
182		$(AWK) 'BEGIN { OFS="\t"; } $$1 !~ /^#/ { print $$2, $$0 }' $(>) | \
183		$(MAKEDBM) - services.byname; \
184		$(TOUCH) $(@); \
185		$(ECHO) "updated services"; \
186		if [ ! $(NOPUSH) ]; then \
187			$(YPPUSH) -d $(DOMAIN) services.byname; \
188			$(ECHO) "pushed services"; \
189		else \
190			: ; \
191		fi \
192	else \
193		$(ECHO) "couldn't find $(>)"; \
194	fi
195
196
197protocols.time: $(DIR)/protocols
198	-@if [ -f $(>) ]; then \
199		$(AWK) 'BEGIN { OFS="\t"; } $$1 !~ /^#/ { print $$2, $$0 }' $(>) | \
200		$(MAKEDBM) - protocols.bynumber; \
201		$(SED) -e "/^#/d" -e s/#.*$$// $(>) | \
202		$(AWK) '{print $$1, $$0; for (i = 3;i <= NF;i++) print $$i,$$0}' | \
203		$(MAKEDBM) - protocols.byname; \
204		$(TOUCH) $(@); \
205		$(ECHO) "updated protocols"; \
206		if [ ! $(NOPUSH) ]; then \
207			$(YPPUSH) -d $(DOMAIN) protocols.bynumber; \
208			$(YPPUSH) -d $(DOMAIN) protocols.byname; \
209			$(ECHO) "pushed protocols"; \
210		else \
211			: ; \
212		fi \
213	else \
214		$(ECHO) "couldn't find $(>)"; \
215	fi
216
217
218netid.time: $(DIR)/passwd $(DIR)/group $(DIR)/hosts $(DIR)/netid
219	-@$(MKNETID) -q -d $(DOMAIN) -p $(DIR)/passwd -g $(DIR)/group -h $(DIR)/hosts -m $(DIR)/netid | \
220	  $(MAKEDBM) - netid.byname; \
221	  $(TOUCH) $(@); \
222	  $(ECHO) "updated netid"; \
223	  if [ ! $(NOPUSH) ]; then \
224		$(YPPUSH) -d $(DOMAIN) netid.byname; \
225		$(ECHO) "pushed netid"; \
226	  else \
227		: ; \
228	  fi
229
230
231netgroup.time: $(DIR)/netgroup
232	-@if [ -f $(>) ]; then \
233		$(CAT) $(>) | $(MAKEDBM) - netgroup; \
234		$(CAT) $(>) | $(REVNETGROUP) -u -f - | \
235		$(MAKEDBM) - netgroup.byuser; \
236		$(CAT) $(>) | $(REVNETGROUP) -h -f - | \
237		$(MAKEDBM) - netgroup.byhost; \
238		$(TOUCH) $(@); \
239		$(ECHO) "updated netgroup"; \
240		if [ ! $(NOPUSH) ]; then \
241			$(YPPUSH) -d $(DOMAIN) netgroup; \
242			$(YPPUSH) -d $(DOMAIN) netgroup.byuser; \
243			$(YPPUSH) -d $(DOMAIN) netgroup.byhost; \
244			$(ECHO) "pushed netgroup"; \
245		else \
246			: ; \
247		fi \
248	else \
249		$(ECHO) "couldn't find $(>)"; \
250	fi
251
252
253amd.home.time: $(AMDDIR)/amd.home
254	-@if [ -f $(>) ]; then \
255		$(SED) -e "s/#.*$$//" -e "/^$$/d" $(>) | \
256		$(AWK) '{ \
257			    for (i = 1; i <= NF; i++) \
258				if (i == NF) { \
259				    if (substr($$i, length($$i), 1) == "\\") { \
260					printf("%s", substr($$i, 1, length($$i) - 1)); \
261				    } \
262				    else \
263					printf("%s\n", $$i); \
264				} \
265				else \
266				    printf("%s ", $$i); \
267			}' | \
268		$(MAKEDBM) - amd.home; \
269		$(TOUCH) $(@); \
270		$(ECHO) "updated amd.home"; \
271		if [ ! $(NOPUSH) ]; then \
272			$(YPPUSH) -d $(DOMAIN) amd.home; \
273			$(ECHO) "pushed amd.home"; \
274		else \
275			: ; \
276		fi \
277	else \
278		$(ECHO) "couldn't find $(>)"; \
279	fi
280
281
282aliases.time: $(DIR)/mail/aliases
283	-@if [ -f $(>) ]; then \
284		$(CP) -p $(>) $(DOMAIN)-aliases; \
285		$(SENDMAIL) -bi -oA$(PWD)/$(DOMAIN)-aliases; \
286		$(MAKEDBM) -U $(DOMAIN)-aliases | $(MAKEDBM) - mail.aliases; \
287		$(MKALIAS) mail.aliases mail.byaddr; \
288		$(TOUCH) $(@); \
289		$(RM) $(DOMAIN)-aliases.db $(DOMAIN)-aliases; \
290		$(ECHO) "updated aliases"; \
291		if [ ! $(NOPUSH) ]; then \
292			$(YPPUSH) -d $(DOMAIN) mail.aliases; \
293			$(YPPUSH) -d $(DOMAIN) mail.byaddr; \
294			$(ECHO) "pushed aliases"; \
295		else \
296			: ; \
297		fi \
298	else \
299		$(ECHO) "couldn't find $(>)"; \
300	fi
301
302
303
304passwd: passwd.time
305group: group.time
306hosts: hosts.time
307ethers: ethers.time
308networks: networks.time
309rpc: rpc.time
310services: services.time
311protocols: protocols.time
312netid: netid.time
313netgroup: netgroup.time
314amd.home: amd.home.time
315aliases: aliases.time
316$(DIR)/passwd:
317$(DIR)/group:
318$(DIR)/hosts:
319$(DIR)/ethers:
320$(DIR)/networks:
321$(DIR)/rpc:
322$(DIR)/services:
323$(DIR)/protocols:
324$(DIR)/netid:
325$(DIR)/master.passwd:
326$(DIR)/netgroup:
327$(DIR)/mail/aliases:
328$(AMDDIR)/amd.home:
329