I'd like to create a custom NIS map in order to be able to look up my own information using ypmatch and map between local and centralised usernames. How can this be achieved?
1 Answers
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. This is going to be the new username map, so call it usermap.
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
- 156