![]() | ![]() |
Map Name | Nickname | Access By | Contains | Default Integration |
---|---|---|---|---|
auto.* | Map key | /etc/auto_* | Append | |
bootparams | Hostname | /etc/bootparams | Append | |
ethers.byname | ethers | Hostname | /etc/ethers | Replace |
ethers.byaddr | MAC address | /etc/ethers | Replace | |
group.byname | group | Group name | /etc/group | Append |
group.bygid | Group ID | /etc/group | Append | |
hosts.byname | hosts | Hostname | /etc/hosts | Replace |
hosts.byaddr | IP address | /etc/hosts | Replace | |
ipnodes.byname | ipnodes | Hostname | /etc/inet/ipnodes | None; only integrated if IPv6 enabled |
ipnodes.byaddr | IP address | /etc/inet/ipnodes | None; only integrated if IPv6 enabled | |
mail.aliases | aliases | Alias name | /etc/aliases | Append |
mail.byaddr | Expanded alias | /etc/aliases | Append | |
netgroup.byhost | Hostname | /etc/netgroup | Replace | |
netgroup.byuser | Username | /etc/netgroup | Replace | |
netid.byname | Username | UID & GID info | Replace | |
netmasks.byaddr | IP address | /etc/netmasks | Replace | |
networks.byname | Network name | /etc/networks | Replace | |
networks.byaddr | IP address | /etc/networks | Replace | |
passwd.byname | passwd | Username | /etc/passwd /etc/shadow | Append |
passwd.byuid | User ID | /etc/passwd /etc/shadow | Append | |
publickey.byname | Principal name | /etc/publickey | Replace | |
protocols.bynumber | protocols | Port number | /etc/protocols | Replace |
protocols.byname | Protocol name | /etc/protocols | Replace | |
rpc.bynumber | RPC number | /etc/rpc | Replace | |
services.byname | services | Service name | /etc/services | Replace |
ypservers | Hostname | NIS server names | Replace |
It's now time to face up to some distortions we've been making for the sake of simplicity. We've assumed that there's a one-to-one correspondence between files and maps. In fact, there are usually several maps for each file. A map really corresponds to a particular way of accessing a file: for example, the passwd.byname map looks up data in the password database by username. There's also a passwd.byuid that looks up users according to their user ID number. There could be (but there aren't) additional maps that looked up users on the basis of their group ID number, home directory, or even their choice of login shell. To make things a bit easier, the most commonly used maps have "nicknames," which correspond directly to the name of the original file: for example, the nickname for passwd.byname is simply passwd. Using nicknames as if they were map names rarely causes problems -- but it's important to realize that there is a distinction. It's also important to realize that nicknames are recognized by only two NIS utilities: ypmatch and ypcat.
Another distortion: this is the first time we've seen the netid.byname map. On the master NIS server, this map is not based on any single source file, but instead is derived from information in the group, password, and hosts files, via /var/yp/Makefile. It contains one entry for each user in the password file. The data associated with the username is a list of every group to which the user belongs. The netid is used to determine group memberships quickly when a user logs in. Instead of reading the entire group map, searching for the user's name, the login process performs a single map lookup on the netid map. You usually don't have to worry about this map -- it will be built for you as needed -- but you should be aware that it exists. If NIS is not running, and if an NIS client has an /etc/netid file, then the information will be read from /etc/netid.A single netgroup contains one or more of these triples. Host and usernames have their usual meanings, but a domain name in this instance refers to the NIS domain in which the netgroup is valid. If an entry in the triple is left blank, that field becomes a wildcard. If the entry is specified as a dash (-), the field can take no value. Netgroups are typically used to augment other maps and files; for example, adding a selected group of users to the password file. The definitions and behavior of netgroups are confusing because their syntax doesn't exactly match the way the netgroup information is used. Even though the netgroup syntax allows you to specify user and hostnames in the same triple, user and hostnames are rarely used together. For example, when a netgroup is used to add users to an NIS-managed password file, only the usernames are taken from the netgroup. The hostnames are ignored, because hostnames have no place in the password file. Similarly, when using a netgroup to grant filesystem access permissions to a set of NFS clients, only the hostname fields in the netgroup are used. Usernames are ignored in this case, which means a hostname will be included in the list even if - is used as the username in its triple. Some examples are helpful:(hostname, username, domain name)
In the first example, source is a group of three users; in this respect, the netgroup is similar to an entry in /etc/group. The source netgroup in this case grants no specific permissions, although it could be included in the password file for the source archive machine, granting selected users access to that host. The second example shows a definition for a set of hosts, and would be of no use in a password file. In the third example, stern and johnc are members of the trusted-users group when it is parsed for usernames. Hosts bitatron and corvette are members of trusted-users when it is parsed for hostnames. Note that there is no interpretation of the netgroup that associates user stern with host bitatron. In the fourth example, dave and jimc are members of dangerous-users, but no hosts are included in this group. The domain name field is used when multiple NIS domains exist on the same network and it is necessary to create a group that is valid in only one or the other domain. These groups are very different from those in /etc/group. The group file (or equivalent NIS map) explicitly grants permissions to users while the netgroup mechanism simply creates shorthand notations or nicknames. A netgroup can be used in many places where a user or hostname would appear, such as the password file or in the list of hosts that can access an NFS filesystem. You can also build netgroups from other netgroups. For example, you could create the netgroup hosts-n-users from the following entry:source (-,stern,nesales), (-,julie,nesales), (-,peter,nesales) trusted-hosts (bitatron,,), (corvette,,) trusted-users (bitatron,stern,), (corvette,johnc,) dangerous-users (,jimc,), (,dave,)
This netgroup contains all the members of both trusted-hosts and trusted-users. By using netgroups carefully, you can create special-purpose groups that can be managed separately. For example, you could create a group of "administrators" that can easily be added to the password list of every machine, or a group of "visitors" who are only added to the password files of certain machines. A final note about netgroups: they are accessible only through NIS. The library routines that have been modified to use NIS maps have also been educated about the uses of the netgroup map, and use the netgroup, password, and host maps together. If NIS is not running, netgroups are not defined. This implies that any netgroup file on an NIS client is ignored, because the NIS netgroup map replaces the local file. A local netgroup file does nothing at all. The uses of netgroups will be revisited as a security mechanism.hosts-n-users trusted-hosts, trusted-users
The keyword files tells the system to read /etc/passwd first, and if the desired entry is not found, search passwd.byname or passwd.byuid, depending on whether the system is searching by account name or user identifier number. The reason why the passwd file is examined before the NIS map is that some accounts, such as root, are not placed in NIS, for security reasons (see Section 3.2.2, "Installing the NIS master server" in this chapter). If NIS were searched before the local passwd file, and if root were in NIS, then there would effectively be one global password for root. This is not desirable, because once an attacker figured out the root password for one system, he'd know the root password for all systems. Or, even if root were not in NIS, if clients were configured to read NIS before files for passwd information, the attacker that successfully compromised a NIS server, would be able to insert a root entry in the passwd map and gain access to every client.passwd: files nis
TIP: The default files and NIS integration will have your clients getting hostname and address information from NIS. Since you will likely have DNS running, you will find it better to get host informaton from DNS. See Chapter 5, "Living with Multiple Directory Servers ".At this point, we've run through most of what you need to know to get NIS running. With this background out of the way, we'll look at how NIS works. Along the way, we will give more precise definitions of terms that, until now, we have been using fairly loosely. Understanding how NIS works is essential to successful debugging. It is also crucial to planning your NIS network. NIS is built on the RPC protocol, and uses the UDP transport to move requests from the client host to the server. NIS services are integrated into the standard Unix library calls so that they remain transparent to processes that reference NIS-managed files. If you have a process that reads /etc/passwd, most of the queries about that file will be handled by NIS RPC calls to an NIS server. The library calling interface used by the application does not change at all, but the implementations of library routines such as getpwuid( ) that read the /etc/passwd file are modified to refer to NIS or to NIS and local files. The application using getpwuid( ) is oblivious to the change in its implementation. Therefore, when you enable NIS, you don't have to change any existing software. A vendor that supports NIS has already modified all of the relevant library calls to have them make NIS RPC calls in addition to looking at local files where relevant. Any process that used to do lookups in the host table still works; it just does something different in the depths of the library calls.
A complete map contains both files. Consecutive records are not packed in the data file; they are arranged in hashed order and may have empty blocks between them. As a result, the DBM data file may appear to be up to four times as large as the data that it contains. The Unix operating system allows a file to have holes in it that are created when the file's write pointer is advanced beyond the end of the file using lseek( ). Filesystem data blocks are allocated only for those parts of the file containing data. The empty blocks are not allocated, and the file is only as large as the total number of used filesystem blocks and fragments. The holes in DBM files make them difficult to manipulate using standard Unix utilities. If you try to copy an NIS map using cp, or move it across a filesystem boundary with mv, the new file will have the holes expanded into zero-filled disk blocks. When cp reads the file, it doesn't expect to find holes, so it reads sequentially from the first byte until the end-of-file is found. Blocks that are not allocated are read back as zeros, and written to the new file as all zeros as well. This has the unfortunate side effect of making the copied DBM files consume much more disk space than the hole-filled files. Furthermore, NIS maps will not be usable on a machine of another architecture: if you build your maps on a SPARC machine, you can't copy them to an Intel-based machine. Map files are not ASCII files. For the administrator, the practical consequence is that you must always use NIS tools (like ypxfr and yppush, discussed in Section 4.2.1, "Map distribution") to move maps from one machine to another.addresses.dir index file addresses.pag data file
The two NIS maps generated from the password file, for example, are passwd.byname (used by getpwnam( )) and passwd.byuid (used by getpwuid( )). These two maps are stored on disk as four files:filename.bykeyname
The order of the records in the maps will be different because they have different key fields driving the hash algorithm, but they contain exactly the same sets of entries.passwd.byname.dir passwd.byname.pag passwd.byuid.dir passwd.byuid.pag
In this example, ypmatch expands the nickname passwd to the map name passwd.byname, locates the key stern in that map, and prints the data value associated with the key. The library routines that use NIS don't retain any information from the maps. Once a routine looks up a hostname, for example, it passes the data back to the caller and "forgets" about the transaction. On Solaris, if the name service cache daemon (nscd) is running, then the results of queries from the passwd, group, and hosts maps are cached in the nscd daemon. Subsequent queries for the same entry will be satisfied out of the cache. The cache will keep the result of an NIS query until the entry reaches its time to live (ttl) threshold. Each cached NIS map has different time to live values. You can invoke nscd with the -g option to see what the time to live values are.% ypmatch stern passwd stern:passwd:1461:10:Hal Stern:/home/thud/stern:/bin/csh
This usually appears in the boot scripts as:nisclient# domainname nesales
Only the superuser can set or change the default domain. Without an argument, domainname prints the currently set domain name. Library calls that use NIS always request maps from the default domain, so setting the domain name must be the first step in NIS startup. It is possible for an application to request map information from more than one domain, but assume for now that all requests refer to maps in the current default domain. Despite the long introduction, a domain is implemented as nothing more than a subdirectory of the top-level NIS directory, /var/yp. Nothing special is required to create a new domain -- you simply assign it a name and then put maps into it using the server initialization procedures described later. The map files for a domain are placed in its subdirectory:/usr/bin/domainname `cat /etc/defaultdomain`
You can create multiple domains by repeating the initialization using different NIS domain names. Each new domain initialization creates a new subdirectory in the NIS map directory /var/yp. An NIS server provides service for every domain represented by a subdirectory in /var/yp. If multiple subdirectories exist, the NIS server answers binding requests for all of them. You do not have to tell NIS which domains to serve explicitly -- it figures this out by looking at the structure of its map directory. It's possible to treat NIS as another administrative tool. However, it's more flexible than a simple configuration file management system. NIS resembles a database management system with multiple tables. As long as the NIS server can locate map information with well-known file naming and key lookup conventions, the contents of the map files are immaterial to the server. A relational database system such as Oracle provides the framework of schemas and views, but it doesn't care what the schemas look like or what data is in the tables. Similarly, the NIS system provides a framework for locating information in map files, but the information in the files and the existence or lack of map files themselves is not of consequence to the NIS server. There is no minimal set of map files necessary to define a domain. While this places the responsibility for map synchronization on the system manager, it also affords the flexibility of adding locally defined maps to the system that are managed and accessed in a well-known manner./var/yp/domainname/mapname
indicating that it ignored a broadcast request for an unknown domain. If each server handles only its default domain, binding attempts overheard from other domains generate large numbers of these log messages. Running multiple NIS domains on a single IP network is best done if every server can handle every domain, or if you turn off logging. If not, you will be overwhelmed with these informational error messages that do nothing but grow the log file. ypserv keeps the file open while it is running, so a large log file must be cleaned up by truncating it:ypserv: Domain financials not supported (broadcast)
Removing the file with rm clears the directory entry, but does not free the disk space because the ypserv process still has the file open. If you have multiple domains with distinct servers on a single network, you probably shouldn't enable NIS logging.# cat /dev/null > /var/yp/ypserv.log
Here, ypwhich reports the currently bound server for the named domain. If the default or the named domain is not bound, ypwhich reports an error:% domainname nesales % ypwhich wahoo
An NIS client can be put back in standalone operation by modifying /etc/nsswitch.conf:gonzo% ypwhich -d financials Domain financials not bound on gonzo
client# cp /etc/nsswitch.files /etc/nsswitch.conf
![]() | ![]() | ![]() |
3.2. Basics of NIS management | ![]() | 3.4. Trace of a key match |
Copyright © 2002 O'Reilly & Associates. All rights reserved.