[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

patch for Makefile.yp



Hi :)

I made a small patch to Makefile.yp so that only UID/GID between a certain 
range will be included in NIS maps.
I'm no developer and this was inspired from NetBSD, so I cannot guaranty this 
is how it should be done. Anyway, I find this usefull and it seems to work 
well (at least here).
I hope something like this could make it in the official sources.
Thanks.

Regards,

Antoine

*** ps *** in case the mail badly wrap the diff, it is available here:
http://www.lphp.org/ressources/Makefile.yp.diff

--- usr.sbin/ypserv/ypinit/Makefile.yp.orig	Sat Nov  2 00:54:18 2002
+++ usr.sbin/ypserv/ypinit/Makefile.yp	Thu Nov 18 10:52:30 2004
@@ -14,6 +14,7 @@
 MAKEDBM=/usr/sbin/makedbm
 SED=/usr/bin/sed
 SENDMAIL=/usr/sbin/sendmail
+SORT=/usr/bin/sort
 STDHOSTS=/usr/sbin/stdhosts
 STDETHERS=/usr/sbin/stdethers
 MKALIAS=/usr/sbin/mkalias
@@ -34,33 +35,53 @@
 # If you want ypserv to ask DNS for unknown hosts set USEDNS to -b
 USEDNS=
 
+# Only include UID/GID between MIN/MAX range in the maps.
+MINUID?=	1000	# root
+MAXUID?=	2000	# nobody
+MINGID?=	1000	# root
+MAXGID?=	2000	# nobody
+
 all: passwd group hosts ethers networks rpc services protocols netid netgroup 
amd.home aliases
 
 passwd.time: $(DIR)/master.passwd
 	-_(_at_)_if [ -f $(>) ]; then \
 		if [ ! $(UNSECURE) ]; then \
 			$(CAT) $(>) | $(CUT) -d: -f1-4,8-10 | \
-			$(AWK) 'BEGIN { FS=":"; OFS="\t"; } /^[a-zA-Z0-9_]/ \
-			{ print $$1, $$1":*:"$$3":"$$4":"$$5":"$$6":"$$7 }' -|\
-			$(MAKEDBM) - passwd.byname; \
+			$(AWK) -v minuid=${MINUID} -v maxuid=${MAXUID} \
+			'BEGIN { FS=":"; OFS="\t"; } /^[a-zA-Z0-9_]/ \
+			{ if (minuid <= $$3 && maxuid >= $$3) \
+			print $$1, $$1":*:"$$3":"$$4":"$$5":"$$6":"$$7 }' -|\
+			${SORT} | $(MAKEDBM) - passwd.byname; \
 			$(CAT) $(>) | $(CUT) -d: -f1-4,8-10 |\
-			$(AWK) 'BEGIN { FS=":"; OFS="\t"; } /^[a-zA-Z0-9_]/ \
-			{ print $$3, $$1":*:"$$3":"$$4":"$$5":"$$6":"$$7 }' -|\
-			$(MAKEDBM) - passwd.byuid; \
+			$(AWK) -v minuid=${MINUID} -v maxuid=${MAXUID} \
+			'BEGIN { FS=":"; OFS="\t"; } /^[a-zA-Z0-9_]/ \
+			{ if (minuid <= $$3 && maxuid >= $$3) \
+			print $$3, $$1":*:"$$3":"$$4":"$$5":"$$6":"$$7 }' -|\
+			${SORT} | $(MAKEDBM) - passwd.byuid; \
 		else \
 			$(CAT) $(>) | $(CUT) -d: -f1-4,8-10 | \
-			$(AWK) 'BEGIN { FS=":"; OFS="\t"; } /^[a-zA-Z0-9_]/ \
-			{ print $$1, $$0 }' - | $(MAKEDBM) - passwd.byname; \
+			$(AWK) -v minuid=${MINUID} -v maxuid=${MAXUID} \
+			'BEGIN { FS=":"; OFS="\t"; } /^[a-zA-Z0-9_]/ \
+			{ if (minuid <= $$3 && maxuid >= $$3) \
+			print $$1, $$0 }' - | ${SORT} | \
+			$(MAKEDBM) - passwd.byname; \
 			$(CAT) $(>) | $(CUT) -d: -f1-4,8-10 |\
-			$(AWK) 'BEGIN { FS=":"; OFS="\t"; } /^[a-zA-Z0-9_]/ \
-			{ print $$3, $$0 }' - | $(MAKEDBM) - passwd.byuid; \
+			$(AWK) -v minuid=${MINUID} -v maxuid=${MAXUID} \
+			'BEGIN { FS=":"; OFS="\t"; } /^[a-zA-Z0-9_]/ \
+			{ if (minuid <= $$3 && maxuid >= $$3) \
+			print $$3, $$0 }' - | ${SORT} | \
+			$(MAKEDBM) - passwd.byuid; \
 		fi; \
 		$(CAT) $(>) | \
-		$(AWK) 'BEGIN { FS=":"; OFS="\t"; } /^[a-zA-Z0-9_]/ \
-		{ print $$1, $$0 }' - | $(MAKEDBM-S) - master.passwd.byname; \
+		$(AWK) -v minuid=${MINUID} -v maxuid=${MAXUID} \
+		'BEGIN { FS=":"; OFS="\t"; } /^[a-zA-Z0-9_]/ \
+		{ if (minuid <= $$3 && maxuid >= $$3) \
+		print $$1, $$0 }' - | $(MAKEDBM-S) - master.passwd.byname; \
 		$(CAT) $(>) | \
-		$(AWK) 'BEGIN { FS=":"; OFS="\t"; } /^[a-zA-Z0-9_]/ \
-		{ print $$3, $$0 }' - | $(MAKEDBM-S) - master.passwd.byuid; \
+		$(AWK) -v minuid=${MINUID} -v maxuid=${MAXUID} \
+		'BEGIN { FS=":"; OFS="\t"; } /^[a-zA-Z0-9_]/ \
+		{ if (minuid <= $$3 && maxuid >= $$3) \
+		print $$3, $$0 }' - | $(MAKEDBM-S) - master.passwd.byuid; \
 		$(TOUCH) $(@); \
 		$(ECHO) "updated passwd"; \
 		if [ ! $(NOPUSH) ]; then \
@@ -79,12 +100,14 @@
 
 group.time: $(DIR)/group
 	-_(_at_)_if [ -f $(>) ]; then \
-		$(AWK) 'BEGIN { FS=":"; OFS="\t"; } /^[a-zA-Z0-9_]/ \
-		{ print $$1, $$0 }' $(>) | \
-		$(MAKEDBM) - group.byname; \
-		$(AWK) 'BEGIN { FS=":"; OFS="\t"; } /^[a-zA-Z0-9_]/ \
-		{ print $$3, $$0 }' $(>) | \
-		$(MAKEDBM) - group.bygid; \
+		$(AWK) -v mingid=${MINGID} -v maxgid=${MAXGID} \
+		'BEGIN { FS=":"; OFS="\t"; } /^[a-zA-Z0-9_]/ \
+		{ if (mingid <= $$3 && maxgid >= $$3) print $$1, $$0 }' $(>) | \
+		${SORT} | $(MAKEDBM) - group.byname; \
+		$(AWK) -v mingid=${MINGID} -v maxgid=${MAXGID} \
+		'BEGIN { FS=":"; OFS="\t"; } /^[a-zA-Z0-9_]/ \
+		{ if (mingid <= $$3 && maxgid >= $$3) print $$3, $$0 }' $(>) | \
+		${SORT} | $(MAKEDBM) - group.bygid; \
 		$(TOUCH) $(@); \
 		$(ECHO) "updated group"; \
 		if [ ! $(NOPUSH) ]; then \