If you use NIS or YP (yellow pages) and want to add your own custom map, here’s how to do it.
First off, edit /var/yp/Makefile to add in the new map. You’ve probably got something like this:
PASSWD = $(YPPWDDIR)/passwd
We need to add a new line for the new map. I want to map usernames between local and central usernames
USERMAP = $(YPSRCDIR)/usermap
YPSRCDIR is /etc in my case, but obviously choose the path that suits you the best.
Now find a line that starts “all: “. This is the list of maps to update. Add your new map to the end, so it’ll be something like
all: auto.home auto.master group hosts netgrp passwd usermap
Further down where there is a group of lines like this:
passwd: passwd.byname passwd.byuid
you should add in your own map:
usermap : usermap.byname
The “byname” part is an indicator for what the map key is and isn’t that important for us.
You now need to add a section to tell the makefile how to update your map:
usermap.byname: $(USERMAP) $(YPDIR)/Makefile
@echo "Updating $@..."
@$(AWK) -F: '!/^[-+#]/ { if ($$1 != "" && $$2 != "" ) \
print $$1"\t"$$2 }' $(USERMAP) \
| $(DBLOAD) -i $(USERMAP) -o $(YPMAPDIR)/$@ - $@
-@$(NOPUSH) || $(YPPUSH) -d $(DOMAIN) $@
This processes the file /etc/usermap and generates the map file. Essentially you just need to print “key\tvalue” into $(DBLOAD) …. This example extracts data from the file assuming it is in the format “key:value”.
Now edit /var/yp/nicknames to add your new map:
usermap usermap.byname
then run make in /var/yp as normal.
If you have a slave server you’ll probably have a timeout with the new map at this point. To get round this, you need to run ypxfr on the slave to get the map first:
/usr/lib/yp/ypxfr -d <yp domain> -h <yp master host> usermap.byname
